* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --secondary: #8b5cf6;
    --success: #10b981;
    --error: #ef4444;
    --bg: #ffffff;
    --bg-secondary: #f8fafc;
    --text: #0f172a;
    --text-secondary: #475569;
    --border: #e2e8f0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow-x: hidden;
}

.screen {
    display: none;
    width: 100%;
    max-width: 440px;
    margin: 0 auto;
}

.screen.active {
    display: block;
    animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.auth-card {
    background: white;
    border-radius: 24px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    overflow: hidden;
}

.auth-header {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    padding: 40px 32px;
    text-align: center;
    color: white;
}

.logo {
    width: 80px;
    height: 80px;
    background: rgba(255,255,255,0.2);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    margin: 0 auto 20px;
}

.auth-title {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
}

.auth-subtitle {
    font-size: 15px;
    opacity: 0.9;
}

.auth-body {
    padding: 32px;
}

.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
}

.required {
    color: var(--error);
}

.form-input,
.form-select {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: 12px;
    font-size: 15px;
    font-family: inherit;
    transition: all 0.3s;
    background: var(--bg-secondary);
}

.form-input:focus,
.form-select:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

.phone-group {
    display: flex;
    gap: 8px;
}

.country-code {
    flex: 0 0 120px;
}

.phone-input {
    flex: 1;
    min-width: 0;
}

.custom-input {
    display: none;
    margin-top: 8px;
}

.custom-input.show {
    display: block;
}

.country-code {
    flex: 0 0 110px;
}

.phone-input {
    flex: 1;
    min-width: 0;
}

.btn {
    width: 100%;
    padding: 16px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.5);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text);
    border: 2px solid var(--border);
}

.divider {
    display: flex;
    align-items: center;
    gap: 16px;
    margin: 24px 0;
    color: var(--text-secondary);
    font-size: 14px;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

.link-text {
    text-align: center;
    margin-top: 20px;
    color: var(--text-secondary);
    font-size: 14px;
}

.link-text a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    cursor: pointer;
}

.verification-code {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin: 24px 0;
}

.code-input {
    width: 50px;
    height: 60px;
    text-align: center;
    font-size: 24px;
    font-weight: 700;
    border: 2px solid var(--border);
    border-radius: 12px;
    background: var(--bg-secondary);
    transition: all 0.3s;
}

.code-input:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

.alert {
    padding: 12px 16px;
    border-radius: 12px;
    margin-bottom: 20px;
    font-size: 14px;
    display: none;
}

.alert.show {
    display: block;
}

.alert-success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #6ee7b7;
}

.alert-error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}

.resend-code {
    text-align: center;
    margin-top: 20px;
    font-size: 14px;
    color: var(--text-secondary);
}

.resend-code button {
    background: none;
    border: none;
    color: var(--primary);
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
}

.resend-code button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.custom-input {
    display: none;
    margin-top: 8px;
}

.custom-input.show {
    display: block;
}

/* KaTeX Styling */
.katex-display {
    margin: 16px 0;
    overflow-x: auto;
    overflow-y: hidden;
}

.katex {
    font-size: 1.1em;
}

.message-content .katex-display {
    background: rgba(99, 102, 241, 0.05);
    padding: 12px;
    border-radius: 8px;
    border-left: 3px solid var(--primary);
}

.message.user .message-content .katex-display {
    background: rgba(255, 255, 255, 0.1);
    border-left: 3px solid rgba(255, 255, 255, 0.3);
}

.message.user .message-content .katex {
    color: white;
}

/* Chemical formulas styling */
.katex .mhchem {
    font-family: 'Times New Roman', serif;
}

/* Fraction styling */
.katex .frac-line {
    border-bottom-width: 0.06em;
}

/* Matrix/Array styling */
.katex .arraycolsep {
    width: 0.5em;
}

/* Chat App */
.app-container {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-secondary);
    flex-direction: column;
}

.app-container.active {
    display: flex;
}

.header {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.header-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-logo {
    width: 40px;
    height: 40px;
    background: rgba(255,255,255,0.2);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.header-title {
    font-size: 20px;
    font-weight: 700;
}

.logout-btn {
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
    padding: 8px 16px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.welcome-box {
    text-align: center;
    padding: 40px 20px;
}

.welcome-icon {
    font-size: 60px;
    margin-bottom: 20px;
}

.welcome-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 10px;
}

.welcome-text {
    color: var(--text-secondary);
    margin-bottom: 30px;
}

.quick-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    max-width: 400px;
    margin: 0 auto;
}

.quick-btn {
    padding: 20px;
    background: white;
    border: 2px solid var(--border);
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.3s;
}

.quick-btn:hover {
    border-color: var(--primary);
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(99, 102, 241, 0.15);
}

.quick-icon {
    font-size: 32px;
    margin-bottom: 10px;
}

.quick-text {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.message {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
}

.message.bot .message-avatar {
    background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
}

.message-content {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 16px;
    line-height: 1.5;
    font-size: 15px;
}

.message.user .message-content {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.bot .message-content {
    background: white;
    color: var(--text);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border);
}

.typing {
    display: none;
    padding: 12px 16px;
    background: white;
    border-radius: 16px;
    width: 60px;
    border: 1px solid var(--border);
}

.typing.show {
    display: block;
}

.typing span {
    height: 8px;
    width: 8px;
    background: var(--primary);
    border-radius: 50%;
    display: inline-block;
    margin: 0 2px;
    animation: bounce 1.4s infinite;
}

.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-10px); }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.05); opacity: 0.8; }
}

.message-image {
    max-width: 100%;
    border-radius: 12px;
    margin-top: 8px;
    cursor: pointer;
}

.message-audio {
    margin-top: 8px;
    width: 100%;
    max-width: 300px;
}

.input-area {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.input-wrapper {
    flex: 1;
}

.chat-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: 16px;
    font-size: 15px;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    background: var(--bg-secondary);
}

.chat-input:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
}

.input-actions {
    display: flex;
    gap: 8px;
}

.action-btn {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--bg-secondary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    transition: all 0.3s;
}

.action-btn:hover {
    background: var(--border);
}

.send-btn {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
}

/* Mobile Responsive */
@media (max-width: 600px) {
.app-container {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-secondary);
    flex-direction: column;
}

.app-container.active {
    display: flex;
}

.header {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.header-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-logo {
    width: 40px;
    height: 40px;
    background: rgba(255,255,255,0.2);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.header-title {
    font-size: 20px;
    font-weight: 700;
}

.logout-btn {
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
    padding: 8px 16px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.welcome-box {
    text-align: center;
    padding: 40px 20px;
}

.welcome-icon {
    font-size: 60px;
    margin-bottom: 20px;
}

.welcome-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 10px;
}

.welcome-text {
    color: var(--text-secondary);
    margin-bottom: 30px;
}

.quick-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    max-width: 400px;
    margin: 0 auto;
}

.quick-btn {
    padding: 20px;
    background: white;
    border: 2px solid var(--border);
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.3s;
}

.quick-btn:hover {
    border-color: var(--primary);
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(99, 102, 241, 0.15);
}

.quick-icon {
    font-size: 32px;
    margin-bottom: 10px;
}

.quick-text {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.message {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
}

.message.bot .message-avatar {
    background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
}

.message-content {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 16px;
    line-height: 1.5;
    font-size: 15px;
}

.message.user .message-content {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.bot .message-content {
    background: white;
    color: var(--text);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border);
}

.typing {
    display: none;
    padding: 12px 16px;
    background: white;
    border-radius: 16px;
    width: 60px;
    border: 1px solid var(--border);
}

.typing.show {
    display: block;
}

.typing span {
    height: 8px;
    width: 8px;
    background: var(--primary);
    border-radius: 50%;
    display: inline-block;
    margin: 0 2px;
    animation: bounce 1.4s infinite;
}

.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-10px); }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.05); opacity: 0.8; }
}

.message-image {
    max-width: 100%;
    border-radius: 12px;
    margin-top: 8px;
    cursor: pointer;
}

.message-audio {
    margin-top: 8px;
    width: 100%;
    max-width: 300px;
}

.input-area {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.input-wrapper {
    flex: 1;
}

.chat-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: 16px;
    font-size: 15px;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    background: var(--bg-secondary);
}

.chat-input:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
}

.input-actions {
    display: flex;
    gap: 8px;
}

.action-btn {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--bg-secondary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    transition: all 0.3s;
}

.action-btn:hover {
    background: var(--border);
}

.send-btn {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
}

/* Mobile Responsive */
@media (max-width: 600px) {
    body {
        padding: 0;
    }
    
    .auth-card {
        border-radius: 0;
        min-height: 100vh;
    }
    
    .auth-header {
        padding: 30px 24px;
    }
    
    .logo {
        width: 70px;
        height: 70px;
        font-size: 35px;
    }
    
    .auth-title {
        font-size: 24px;
    }
    
    .auth-body {
        padding: 24px;
    }
    
    .phone-group {
        flex-direction: column;
    }
    
    .country-code {
        flex: 1;
    }
    
    #imageCaptionModal > div {
        max-width: 90%;
        padding: 20px;
    }
    
    #previewImage {
        max-height: 200px;
        object-fit: contain;
    }
    
    .verification-code {
        gap: 8px;
    }
    
    .code-input {
        width: 45px;
        height: 55px;
        font-size: 20px;
    }
    
    .welcome-title {
        font-size: 24px;
    }
    
    .message-content {
        max-width: 80%;
        font-size: 14px;
    }
    
    .quick-actions {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 400px) {
    .verification-code {
        gap: 6px;
    }
    
    .code-input {
        width: 40px;
        height: 50px;
        font-size: 18px;
    }
}
