/* CSS Variables */
:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --bg-chat: #1a1a2e;
    --bg-sidebar: #0d1117;
    --bg-input: #2d2d44;
    --bg-message-user: #3b82f6;
    --bg-message-assistant: #2d2d44;
    --text-primary: #e4e4e7;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --border: #2d2d44;
    --success: #22c55e;
    --error: #ef4444;
    --warning: #f59e0b;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --transition: all 0.2s ease;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Screens */
.screen {
    display: none;
    height: 100vh;
    height: 100dvh;
}

.screen.active {
    display: flex;
}

/* Auth Screen */
#auth-screen {
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 50%, var(--bg-tertiary) 100%);
    padding: 20px;
}

.auth-container {
    width: 100%;
    max-width: 420px;
    background: rgba(22, 33, 62, 0.8);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 40px 32px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.auth-logo {
    text-align: center;
    margin-bottom: 32px;
}

.logo-icon {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    font-size: 28px;
    color: white;
}

.auth-logo h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 4px;
}

.auth-subtitle {
    color: var(--text-secondary);
    font-size: 14px;
}

/* Forms */
.auth-form {
    display: none;
}

.auth-form.active {
    display: block;
}

.auth-form h2 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 20px;
    text-align: center;
}

.form-info {
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: var(--radius-sm);
    padding: 12px;
    font-size: 13px;
    color: var(--accent);
    margin-bottom: 20px;
    text-align: center;
}

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

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: var(--transition);
    outline: none;
}

.form-group input:focus,
.form-group select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-group select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23a1a1aa' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.btn-primary {
    width: 100%;
    padding: 14px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    margin-top: 8px;
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    width: 100%;
    padding: 12px;
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    margin-top: 8px;
}

.btn-secondary:hover {
    background: rgba(59, 130, 246, 0.1);
}

.auth-links {
    margin-top: 20px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.auth-links a {
    color: var(--accent);
    text-decoration: none;
    font-size: 13px;
    transition: var(--transition);
}

.auth-links a:hover {
    color: var(--accent-hover);
}

/* Recovery Tabs */
.recover-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

.tab-btn {
    flex: 1;
    padding: 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: var(--transition);
}

.tab-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.recover-tab {
    display: none;
}

.recover-tab.active {
    display: block;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 40px 32px;
    max-width: 440px;
    width: 100%;
    text-align: center;
}

.modal-large {
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    text-align: left;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.modal-icon {
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, var(--success), #16a34a);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    font-size: 24px;
    color: white;
}

.modal-warning {
    color: var(--warning);
    font-size: 14px;
    margin-bottom: 20px;
}

.recovery-code-display {
    background: var(--bg-input);
    border: 2px dashed var(--accent);
    border-radius: var(--radius-sm);
    padding: 16px;
    font-family: 'Courier New', monospace;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 2px;
    margin-bottom: 20px;
    word-break: break-all;
    color: var(--accent);
}

/* App Layout */
#app-screen {
    flex-direction: row;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    z-index: 100;
}

.sidebar-header {
    display: flex;
    align-items: center;
    padding: 16px;
    gap: 12px;
    border-bottom: 1px solid var(--border);
}

.sidebar-title {
    flex: 1;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
}

.sidebar-close {
    display: none;
}

.sidebar-conversations {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.conversation-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    gap: 10px;
    margin-bottom: 2px;
}

.conversation-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.conversation-item.active {
    background: rgba(59, 130, 246, 0.15);
}

.conversation-item i {
    color: var(--text-muted);
    font-size: 14px;
}

.conversation-item span {
    flex: 1;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-item .btn-delete {
    opacity: 0;
    background: none;
    border: none;
    color: var(--error);
    cursor: pointer;
    padding: 4px;
    transition: var(--transition);
}

.conversation-item:hover .btn-delete {
    opacity: 1;
}

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border);
}

.btn-sidebar {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 16px;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: var(--transition);
}

.btn-sidebar:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

/* Chat Main */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
    background: rgba(13, 17, 23, 0.5);
    backdrop-filter: blur(10px);
}

.chat-header-title {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 15px;
}

.alex-avatar-small {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

/* Welcome Screen */
.welcome-screen {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
}

.welcome-content {
    text-align: center;
    max-width: 600px;
}

.welcome-logo {
    width: 72px;
    height: 72px;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    border-radius: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 24px;
    font-size: 32px;
    color: white;
}

.welcome-content h2 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
}

.welcome-content p {
    color: var(--text-secondary);
    font-size: 15px;
    margin-bottom: 32px;
}

.welcome-suggestions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.suggestion-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
    transition: var(--transition);
    text-align: left;
}

.suggestion-btn:hover {
    border-color: var(--accent);
    background: rgba(59, 130, 246, 0.05);
}

.suggestion-btn i {
    color: var(--accent);
    font-size: 16px;
    flex-shrink: 0;
}

/* Messages */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    scroll-behavior: smooth;
}

.message {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
}

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

.message-avatar.assistant {
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    color: white;
}

.message-avatar.user {
    background: var(--bg-input);
    color: var(--text-secondary);
}

.message-content {
    flex: 1;
    min-width: 0;
}

.message-content p {
    font-size: 15px;
    line-height: 1.7;
    color: var(--text-primary);
}

.message-content img {
    max-width: 300px;
    border-radius: var(--radius-sm);
    margin-top: 8px;
}

.message-typing {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}

.message-typing span {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

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

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* Input Area */
.input-area {
    padding: 12px 20px 20px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.image-preview {
    position: relative;
    display: inline-block;
    margin-bottom: 8px;
}

.image-preview img {
    max-height: 100px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.btn-remove-image {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 24px;
    height: 24px;
    background: var(--error);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 8px 12px;
    transition: var(--transition);
}

.input-row:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

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

.input-wrapper textarea {
    width: 100%;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 200px;
    line-height: 1.5;
    padding: 4px 0;
}

.input-wrapper textarea::placeholder {
    color: var(--text-muted);
}

.btn-icon {
    width: 36px;
    height: 36px;
    background: none;
    border: none;
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.input-btn {
    width: 32px;
    height: 32px;
}

.btn-send {
    width: 32px;
    height: 32px;
    background: var(--accent);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
}

.btn-send:hover {
    background: var(--accent-hover);
}

.btn-send:disabled {
    background: var(--bg-input);
    color: var(--text-muted);
    cursor: not-allowed;
}

.input-disclaimer {
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 8px;
}

/* Recording state */
.recording .fa-microphone {
    color: var(--error);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Profile */
.profile-form h3 {
    font-size: 16px;
    font-weight: 600;
    margin: 16px 0 12px;
}

.profile-form hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 20px 0;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 24px;
    font-size: 14px;
    z-index: 2000;
    transition: transform 0.3s ease;
    box-shadow: var(--shadow);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

.toast.success { border-color: var(--success); color: var(--success); }
.toast.error { border-color: var(--error); color: var(--error); }

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
        width: 280px;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.5);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-close {
        display: flex;
    }

    .welcome-suggestions {
        grid-template-columns: 1fr;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .auth-container {
        padding: 32px 24px;
    }

    .input-area {
        padding: 8px 12px 12px;
    }

    .messages-container {
        padding: 12px;
    }
}

/* Overlay for mobile sidebar */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
}

.sidebar-overlay.active {
    display: block;
}
