/* ============================================================
   RAG Legal Assistant — Modern ChatGPT-style UI
   ============================================================ */

:root {
    --bg-primary: #0f0f11;
    --bg-secondary: #1a1a1f;
    --bg-tertiary: #232329;
    --bg-hover: #2a2a32;
    --bg-active: #35353f;
    --text-primary: #e8e8ed;
    --text-secondary: #a0a0ab;
    --text-muted: #6b6b78;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --accent-light: rgba(99, 102, 241, 0.15);
    --border: #2a2a32;
    --border-light: #35353f;
    --success: #22c55e;
    --error: #ef4444;
    --warning: #f59e0b;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    --transition: all 0.2s ease;
}

* {
    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;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ============================================================
   Auth Screen
   ============================================================ */

.auth-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: var(--bg-primary);
    background-image: 
        radial-gradient(ellipse at 20% 50%, rgba(99, 102, 241, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 50%, rgba(139, 92, 246, 0.06) 0%, transparent 50%);
}

.auth-container {
    text-align: center;
    padding: 48px;
    max-width: 420px;
    width: 100%;
}

.auth-logo {
    margin-bottom: 24px;
    animation: fadeInUp 0.6s ease;
}

.auth-title {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
    background: linear-gradient(135deg, var(--text-primary), var(--accent-hover));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: fadeInUp 0.6s ease 0.1s both;
}

.auth-subtitle {
    color: var(--text-secondary);
    font-size: 15px;
    margin-bottom: 32px;
    animation: fadeInUp 0.6s ease 0.2s both;
}

.auth-form {
    animation: fadeInUp 0.6s ease 0.3s both;
}

.auth-input {
    width: 100%;
    padding: 14px 18px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    outline: none;
    transition: var(--transition);
    margin-bottom: 16px;
}

.auth-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.auth-button {
    width: 100%;
    padding: 14px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
}

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

.auth-error {
    color: var(--error);
    font-size: 13px;
    margin-top: 12px;
}

/* ============================================================
   App Layout
   ============================================================ */

.app {
    display: flex;
    height: 100vh;
}

/* ============================================================
   Sidebar
   ============================================================ */

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

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.new-chat-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
}

.new-chat-btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-light);
}

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

.sidebar-chats::-webkit-scrollbar {
    width: 4px;
}

.sidebar-chats::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.chat-item {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.chat-item.active {
    background: var(--bg-active);
    color: var(--text-primary);
}

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

.sidebar-info {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    font-size: 12px;
    margin-bottom: 12px;
}

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

.logout-btn:hover {
    background: var(--bg-hover);
    color: var(--error);
}

/* ============================================================
   Main Content
   ============================================================ */

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.mobile-header {
    display: none;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

.menu-toggle {
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 4px;
}

.mobile-title {
    font-weight: 600;
    font-size: 16px;
}

/* ============================================================
   Chat Area
   ============================================================ */

.chat-area {
    flex: 1;
    overflow-y: auto;
    scroll-behavior: smooth;
}

.chat-area::-webkit-scrollbar {
    width: 6px;
}

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

/* Welcome */

.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 40px 20px;
    text-align: center;
    animation: fadeIn 0.5s ease;
}

.welcome-icon {
    margin-bottom: 24px;
}

.welcome h2 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 12px;
    background: linear-gradient(135deg, var(--text-primary), var(--accent-hover));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

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

.suggestions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    max-width: 600px;
    width: 100%;
}

.suggestion {
    padding: 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
    text-align: left;
    line-height: 1.5;
}

.suggestion:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent);
    color: var(--text-primary);
}

/* Messages */

.messages {
    max-width: 800px;
    margin: 0 auto;
    padding: 24px 20px 120px;
    width: 100%;
}

.message {
    margin-bottom: 24px;
    animation: fadeInUp 0.3s ease;
}

.message-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
}

.message-avatar.user {
    background: var(--accent);
    color: white;
}

.message-avatar.assistant {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--accent-hover);
}

.message-name {
    font-size: 14px;
    font-weight: 600;
}

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

.message-content p {
    margin-bottom: 12px;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content strong {
    font-weight: 600;
}

.message-content ul, .message-content ol {
    padding-left: 20px;
    margin-bottom: 12px;
}

.message-content li {
    margin-bottom: 4px;
}

.message-content code {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}

/* Sources */

.sources {
    padding-left: 42px;
    margin-top: 16px;
}

.sources-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    padding: 6px 0;
    transition: var(--transition);
}

.sources-toggle:hover {
    color: var(--text-secondary);
}

.sources-toggle svg {
    transition: transform 0.2s ease;
}

.sources-toggle.open svg {
    transform: rotate(180deg);
}

.sources-list {
    display: none;
    margin-top: 8px;
    padding: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.sources-list.open {
    display: block;
}

.source-item {
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
}

.source-item:last-child {
    border-bottom: none;
}

.source-ref {
    color: var(--accent-hover);
    font-weight: 500;
    margin-bottom: 4px;
}

.source-score {
    color: var(--text-muted);
    font-size: 11px;
}

.source-text {
    color: var(--text-secondary);
    line-height: 1.5;
    margin-top: 4px;
    max-height: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Timing info */

.message-meta {
    padding-left: 42px;
    margin-top: 8px;
    display: flex;
    gap: 16px;
    font-size: 11px;
    color: var(--text-muted);
}

/* Loading */

.typing-indicator {
    display: flex;
    gap: 4px;
    padding-left: 42px;
    margin-top: 8px;
}

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

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

/* ============================================================
   Input Area
   ============================================================ */

.input-area {
    padding: 16px 20px 20px;
    background: linear-gradient(to top, var(--bg-primary) 60%, transparent);
    position: relative;
}

.input-container {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 8px 12px;
    transition: var(--transition);
}

.input-container:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.message-input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    line-height: 1.5;
    resize: none;
    outline: none;
    max-height: 200px;
    padding: 6px 4px;
}

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

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

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

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

.input-hint {
    text-align: center;
    color: var(--text-muted);
    font-size: 11px;
    margin-top: 8px;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
}

/* ============================================================
   Animations
   ============================================================ */

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@keyframes typing {
    0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
    30% { opacity: 1; transform: scale(1); }
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
        box-shadow: var(--shadow);
    }

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

    .mobile-header {
        display: flex;
    }

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

    .welcome h2 {
        font-size: 22px;
    }
}

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

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