:root {
    --navy: #0c1829;
    --navy-light: #132238;
    --navy-mid: #1a2d45;
    --accent: #c49a6c;
    --accent-hover: #d4aa7c;
    --warm-white: #f8f6f3;
    --warm-gray: #eae7e2;
    --text: #2a2a2a;
    --text-light: #6b6b6b;
    --text-muted: #999;
    --white: #ffffff;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 20px rgba(0,0,0,0.08);
    --shadow-lg: 0 12px 48px rgba(0,0,0,0.12);
}

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

body {
    font-family: 'Inter', sans-serif;
    background: var(--warm-white);
    height: 100vh;
    overflow: hidden;
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

.screen { height: 100vh; display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* ═══════════════════════════════════════
   LOGIN
   ═══════════════════════════════════════ */

.login-backdrop {
    position: relative;
    width: 100%;
    height: 100vh;
    background: var(--navy);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.login-backdrop::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(ellipse at 30% 50%, rgba(196, 154, 108, 0.08) 0%, transparent 50%),
                radial-gradient(ellipse at 70% 20%, rgba(19, 34, 56, 0.6) 0%, transparent 50%);
    animation: ambientShift 20s ease-in-out infinite alternate;
}

@keyframes ambientShift {
    0% { transform: translate(0, 0); }
    100% { transform: translate(-2%, 1%); }
}

.login-overlay {
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(255,255,255,0.01) 2px,
        rgba(255,255,255,0.01) 4px
    );
}

.login-content {
    position: relative;
    z-index: 1;
    text-align: center;
}

.login-logo {
    width: 220px;
    margin-bottom: 24px;
}

.login-content h1 {
    font-family: 'Playfair Display', serif;
    font-size: 48px;
    font-weight: 700;
    color: var(--white);
    letter-spacing: -1px;
    margin-bottom: 0;
}

.brand-divider {
    width: 40px;
    height: 2px;
    background: var(--accent);
    margin: 20px auto;
}

.login-content p {
    font-size: 13px;
    font-weight: 300;
    color: rgba(255,255,255,0.5);
    letter-spacing: 3px;
    text-transform: uppercase;
    margin-bottom: 48px;
}

#login-btn {
    background: transparent;
    color: var(--white);
    border: 1px solid rgba(255,255,255,0.25);
    padding: 16px 36px;
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
}

#login-btn:hover {
    background: rgba(255,255,255,0.08);
    border-color: rgba(255,255,255,0.5);
    transform: translateY(-1px);
}

/* ═══════════════════════════════════════
   CHAT LAYOUT
   ═══════════════════════════════════════ */

#chat-layout {
    display: flex;
    height: 100vh;
}

/* ─── Sidebar ─── */
#sidebar {
    width: 280px;
    background: var(--navy);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 24px 20px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-logo {
    width: 160px;
}

#new-chat-btn {
    margin: 16px 16px 8px;
    padding: 11px 16px;
    background: rgba(196, 154, 108, 0.1);
    color: var(--accent);
    border: 1px solid rgba(196, 154, 108, 0.25);
    border-radius: 0;
    font-family: 'Inter', sans-serif;
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-icon {
    font-size: 16px;
    font-weight: 300;
    line-height: 1;
}

#new-chat-btn:hover {
    background: rgba(196, 154, 108, 0.18);
    border-color: rgba(196, 154, 108, 0.4);
}

#conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
}

.conv-item {
    padding: 10px 12px;
    margin: 1px 0;
    cursor: pointer;
    color: rgba(255,255,255,0.4);
    font-size: 13px;
    font-weight: 400;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: all 0.15s ease;
    border-left: 2px solid transparent;
}

.conv-item:hover {
    background: rgba(255,255,255,0.04);
    color: rgba(255,255,255,0.7);
}

.conv-item.active {
    background: rgba(255,255,255,0.06);
    color: var(--white);
    border-left-color: var(--accent);
}

.conv-item .conv-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-item .conv-delete {
    display: none;
    background: none;
    border: none;
    color: rgba(255,255,255,0.3);
    cursor: pointer;
    font-size: 14px;
    padding: 0 4px;
    margin-left: 4px;
}

.conv-item:hover .conv-delete { display: inline; }
.conv-item .conv-delete:hover { color: #e55; }

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,0.06);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-footer #user-name {
    color: rgba(255,255,255,0.4);
    font-size: 12px;
    font-weight: 400;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 160px;
}

.sidebar-footer #logout-btn {
    background: none;
    border: none;
    color: rgba(255,255,255,0.3);
    font-family: 'Inter', sans-serif;
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    cursor: pointer;
    padding: 4px 0;
    transition: color 0.2s;
}

.sidebar-footer #logout-btn:hover {
    color: rgba(255,255,255,0.7);
}

/* ─── Main Chat ─── */
#chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--warm-white);
}

/* ─── Messages ─── */
#messages {
    flex: 1;
    overflow-y: auto;
    padding: 40px 32px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* ─── Welcome ─── */
#welcome-message {
    text-align: center;
    padding: 80px 20px;
    color: var(--text-light);
    position: relative;
}

.welcome-logo {
    width: 200px;
    margin-bottom: 24px;
    transition: opacity 0.3s ease, filter 0.3s ease, transform 0.3s ease;
}

#welcome-message h2 {
    font-family: 'Playfair Display', serif;
    font-size: 28px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
    letter-spacing: -0.5px;
    transition: opacity 0.3s ease, filter 0.3s ease, transform 0.3s ease;
}

#welcome-message p {
    font-size: 14px;
    color: var(--text-muted);
    font-weight: 300;
    margin-bottom: 40px;
    transition: opacity 0.3s ease, filter 0.3s ease, transform 0.3s ease;
}

.prompt-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    max-width: 720px;
    margin: 0 auto;
}

.prompt-card {
    background: var(--white);
    border: 1px solid var(--warm-gray);
    border-radius: 8px;
    padding: 18px 16px;
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    font-weight: 400;
    color: var(--text-light);
    line-height: 1.5;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

.prompt-card:hover {
    border-color: var(--accent);
    color: var(--text);
    box-shadow: 0 4px 16px rgba(196, 154, 108, 0.12);
    transform: translateY(-2px);
}

/* ─── Department Tiles ─── */
.dept-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    max-width: 780px;
    margin: 0 auto;
}

.dept-tile {
    background: var(--white);
    border: 1px solid var(--warm-gray);
    border-radius: 8px;
    padding: 22px 18px;
    cursor: pointer;
    text-align: left;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.dept-tile:hover {
    border-color: var(--accent);
    box-shadow: 0 4px 16px rgba(196, 154, 108, 0.15);
    transform: translateY(-2px);
}

.dept-name {
    font-family: 'Playfair Display', serif;
    font-size: 16px;
    font-weight: 600;
    color: var(--navy);
    line-height: 1.3;
}

.dept-desc {
    font-family: 'Inter', sans-serif;
    font-size: 11px;
    font-weight: 400;
    color: var(--text-light);
    line-height: 1.6;
    list-style: disc;
    padding-left: 16px;
}

.dept-desc li {
    margin-bottom: 2px;
}

/* Bottom row: 3 tiles centered */
.dept-grid .dept-tile:nth-child(5),
.dept-grid .dept-tile:nth-child(6),
.dept-grid .dept-tile:nth-child(7) {
    /* nothing special needed — grid auto-places them */
}

/* Faded state for header elements when department is expanded */
#welcome-message.dept-header-faded > .welcome-logo,
#welcome-message.dept-header-faded > h2,
#welcome-message.dept-header-faded > p {
    opacity: 0.1;
    filter: blur(3px);
    transform: scale(0.98);
    transition: all 0.3s ease;
}

/* Faded state for non-selected tiles */
.dept-tile.dept-faded {
    opacity: 0.12;
    transform: scale(0.95);
    filter: blur(2px);
    pointer-events: none;
}

/* Selected tile */
.dept-tile.dept-selected {
    opacity: 0;
    transform: scale(0.95);
    pointer-events: none;
}

/* Expanded department view */
.dept-expanded {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 20px;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.dept-expanded-visible {
    opacity: 1;
    transform: translateY(0);
}

.dept-back {
    background: none;
    border: none;
    color: var(--accent);
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    padding: 6px 12px;
    margin-bottom: 12px;
    transition: color 0.2s ease;
    align-self: flex-start;
    margin-left: calc((100% - 720px) / 2);
}

.dept-back:hover {
    color: var(--text);
}

.dept-expanded-title {
    font-family: 'Playfair Display', serif;
    font-size: 24px;
    font-weight: 600;
    color: var(--navy);
    margin-bottom: 24px;
}

/* Question cards animate in with stagger */
.dept-questions .prompt-card.dept-question {
    opacity: 0;
    transform: translateY(16px);
    animation: deptQuestionIn 0.35s ease forwards;
}

@keyframes deptQuestionIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ─── Message Bubbles ─── */
.message {
    max-width: 960px;
    width: 80%;
    margin: 0 auto;
    display: flex;
    gap: 12px;
}

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

.message-bubble {
    padding: 16px 22px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
}

.message.user .message-bubble {
    white-space: pre-wrap;
}

.message.assistant .message-bubble {
    line-height: 1.35;
}

.message.user .message-bubble {
    background: var(--navy);
    color: rgba(255,255,255,0.92);
    border-radius: 20px 20px 4px 20px;
}

.message.assistant .message-bubble {
    background: var(--white);
    color: var(--text);
    border: 1px solid var(--warm-gray);
    border-radius: 20px 20px 20px 4px;
    box-shadow: var(--shadow-sm);
}

.message.assistant .message-bubble a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 3px;
}

/* ─── Markdown Content ─── */
.message.assistant .message-bubble table {
    border-collapse: collapse;
    width: 100%;
    margin: 12px 0;
    font-size: 13px;
    border: 1px solid var(--warm-gray);
    border-radius: 6px;
    overflow: hidden;
}

.message.assistant .message-bubble th,
.message.assistant .message-bubble td {
    border: 1px solid var(--warm-gray);
    padding: 8px 14px;
    text-align: left;
    line-height: 1.4;
}

.message.assistant .message-bubble th {
    background: var(--navy);
    color: rgba(255,255,255,0.9);
    font-weight: 500;
    font-size: 12px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    border-color: var(--navy-mid);
}

.message.assistant .message-bubble tr:nth-child(even) {
    background: #f5f3ef;
}

.message.assistant .message-bubble tr:hover {
    background: #edeae4;
}

.message.assistant .message-bubble ul,
.message.assistant .message-bubble ol {
    margin: 1px 0;
    padding-left: 20px;
}

.message.assistant .message-bubble p { margin: 2px 0; }

.message.assistant .message-bubble code {
    background: #f3f1ed;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 13px;
}

.message.assistant .message-bubble pre {
    background: #f3f1ed;
    padding: 16px;
    border-radius: 4px;
    overflow-x: auto;
    margin: 12px 0;
}

.message.assistant .message-bubble pre code {
    background: none;
    padding: 0;
}

.message.assistant .message-bubble h1,
.message.assistant .message-bubble h2,
.message.assistant .message-bubble h3 {
    font-family: 'Playfair Display', serif;
    margin: 4px 0 2px;
    font-size: 15px;
    font-weight: 600;
    color: var(--navy);
}

.message.assistant .message-bubble strong {
    font-weight: 500;
}

.message.assistant .message-bubble li {
    margin-bottom: 1px;
}

.message-bubble .citation {
    display: block;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--warm-gray);
    font-size: 12px;
    color: var(--text-muted);
}

/* ─── Typing Indicator ─── */
.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 16px 22px;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background: var(--accent);
    border-radius: 50%;
    animation: bounce 1.4s infinite;
}

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

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

/* ─── Input Area ─── */
#chat-input-area {
    padding: 20px 32px 28px;
    background: var(--warm-white);
    display: flex;
    justify-content: center;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 0;
    width: 80%;
    max-width: 960px;
    background: var(--white);
    border: 1px solid var(--warm-gray);
    border-radius: 12px;
    padding: 6px 6px 6px 0;
    box-shadow: var(--shadow-md);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 4px 24px rgba(196, 154, 108, 0.12);
}

#user-input {
    flex: 1;
    border: none;
    padding: 12px 18px;
    font-size: 14px;
    font-family: 'Inter', sans-serif;
    resize: none;
    min-height: 96px;
    max-height: 240px;
    outline: none;
    color: var(--text);
    background: transparent;
    line-height: 1.5;
}

#user-input::placeholder {
    color: #bbb;
    font-weight: 300;
    text-align: left;
}

#send-btn {
    background: var(--navy);
    color: var(--white);
    border: none;
    width: 42px;
    height: 42px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

#send-btn:disabled {
    background: #d5d3cf;
    cursor: not-allowed;
}

#send-btn:not(:disabled):hover {
    background: var(--navy-mid);
    transform: scale(1.05);
}


/* ─── Error ─── */
.error-banner {
    background: #fff5f5;
    color: #c62828;
    padding: 12px 32px;
    font-size: 13px;
    text-align: center;
    border-bottom: 1px solid #fecdd3;
}

/* ─── Scrollbars ─── */
#messages::-webkit-scrollbar,
#conversation-list::-webkit-scrollbar {
    width: 5px;
}

#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb { background: #ddd; border-radius: 3px; }
#messages::-webkit-scrollbar-thumb:hover { background: #ccc; }

#conversation-list::-webkit-scrollbar-track { background: transparent; }
#conversation-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 3px; }
