:root {
    --navy: #10243e;
    --navy-2: #1b3a63;
    --ink: #172033;
    --muted: #5d6b80;
    --line: #e4eaf2;
    --bg: #f3f6fb;
    --card: #ffffff;
    --accent: #1f6feb;
    --accent-2: #e8f1ff;
    --danger: #b42318;
    --ok: #067647;
    --shadow: 0 12px 40px rgba(16, 36, 62, 0.08);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: "Segoe UI", "Malgun Gothic", sans-serif;
    color: var(--ink);
    background: var(--bg);
}
button, input, textarea { font: inherit; }
a { color: var(--accent); text-decoration: none; }
h1, h2, h3, p { margin: 0; }

.login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background:
        radial-gradient(circle at top left, #d9e8ff, transparent 36%),
        var(--bg);
}
.login-card {
    width: min(440px, calc(100% - 32px));
    background: var(--card);
    border-radius: 20px;
    padding: 32px;
    box-shadow: var(--shadow);
}
.login-card h1 { margin: 6px 0 8px; font-size: 32px; }
.lead, .muted { color: var(--muted); line-height: 1.5; }
.eyebrow { color: var(--accent); font-size: 13px; font-weight: 700; letter-spacing: 0.04em; }
.login-card form, .stack-form, .grid-form { display: grid; gap: 10px; margin-top: 18px; }
label { display: grid; gap: 6px; font-size: 14px; font-weight: 600; }
input, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px;
    background: #fff;
}
button {
    border: 0;
    border-radius: 10px;
    padding: 11px 16px;
    background: var(--navy);
    color: white;
    cursor: pointer;
}
button.secondary { background: var(--navy-2); }
button.danger { background: var(--danger); margin-top: 12px; }
button.text-btn, .text-btn {
    background: transparent;
    color: var(--accent);
    padding: 0;
}
.demo-box {
    margin-top: 18px;
    padding: 12px 14px;
    border-radius: 12px;
    background: var(--accent-2);
    font-size: 13px;
    line-height: 1.55;
}
.flash-list { display: grid; gap: 8px; margin: 12px 0; }
.flash { padding: 10px 12px; border-radius: 10px; background: #eef2f6; }
.flash-error { background: #fee4e2; color: var(--danger); }
.flash-success { background: #dcfae6; color: var(--ok); }

.app-body { min-height: 100vh; display: grid; grid-template-columns: 300px 1fr; }
.sidebar {
    background: var(--navy);
    color: white;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding: 18px 14px;
}
.brand, .brand-mark { display: flex; gap: 10px; align-items: center; }
.brand p, .side-links a { color: #c9d7ea; font-size: 13px; }
.brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    justify-content: center;
    background: #2f6fed;
    font-weight: 800;
}
.side-block { margin-top: 22px; }
.side-grow { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.side-head, .page-head, .admin-top, .chat-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
}
.sidebar h2 { font-size: 13px; color: #9eb4d2; font-weight: 700; }
.subject-list, .session-list { list-style: none; padding: 0; margin: 10px 0 0; overflow: auto; }
.subject-list button, .session-list button {
    width: 100%;
    text-align: left;
    background: transparent;
    color: white;
    border-radius: 12px;
    padding: 10px 12px;
}
.subject-list button.active, .session-list button.active { background: rgba(255,255,255,0.12); }
.subject-list small, .session-list small { display: block; color: #b7c7dc; font-weight: 400; }
.side-links { display: flex; gap: 14px; padding-top: 12px; }

.chat { display: grid; grid-template-rows: auto 1fr auto; min-height: 100vh; }
.chat-head, .composer { padding: 18px 22px; background: white; }
.chat-head { border-bottom: 1px solid var(--line); }
.chat-head h1 { font-size: 22px; margin-top: 4px; }
.messages { padding: 22px; display: flex; flex-direction: column; gap: 12px; overflow: auto; }
.bubble {
    max-width: min(760px, 100%);
    padding: 12px 14px;
    border-radius: 14px;
    line-height: 1.55;
    white-space: pre-wrap;
}
.bubble.user { align-self: flex-end; background: var(--navy); color: white; }
.bubble.assistant { align-self: flex-start; background: white; border: 1px solid var(--line); }
.sources { margin-top: 8px; display: grid; gap: 6px; }
.source {
    font-size: 12px;
    color: var(--muted);
    background: var(--bg);
    border-radius: 8px;
    padding: 6px 8px;
}
.empty { color: var(--muted); margin: auto; text-align: center; }
.composer { display: grid; grid-template-columns: 1fr auto; gap: 10px; border-top: 1px solid var(--line); }
.composer textarea { resize: vertical; }

.admin-top {
    background: white;
    padding: 14px 22px;
    border-bottom: 1px solid var(--line);
}
.admin-top nav { display: flex; gap: 16px; }
.admin-main { width: min(1080px, calc(100% - 32px)); margin: 24px auto 48px; }
.page-head { align-items: end; margin-bottom: 16px; }
.page-head h1, .admin-main h1 { font-size: 28px; }
.panel, .subject-card {
    background: white;
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 18px;
}
.panel + .panel, .card-grid { margin-top: 16px; }
.panel h2 { margin-bottom: 4px; }
.grid-form { grid-template-columns: 1fr 1fr auto; align-items: end; }
.span-2 { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.check input { width: auto; }
.card-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.subject-card h2 { margin: 4px 0 8px; color: var(--ink); }
.subject-card p { color: var(--muted); }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.crumb { margin-bottom: 8px; color: var(--muted); }
.material-list { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 8px; }
.material-list li {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    padding-top: 8px;
    border-top: 1px solid var(--line);
}
.user-table { width: 100%; border-collapse: collapse; background: white; border-radius: 16px; overflow: hidden; }
.user-table th, .user-table td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); }

.channel-toolbar {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 18px;
}
.search-box {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    background: white;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0 14px;
}
.search-box input { border: 0; padding: 10px 0; }
.toolbar-filters { display: flex; gap: 8px; }
.toolbar-filters select {
    border: 1px solid var(--line);
    background: white;
    border-radius: 999px;
    padding: 8px 12px;
}
.create-btn { border-radius: 999px; background: #1c1c1c; white-space: nowrap; }
.create-panel { margin-bottom: 16px; }
.channel-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.channel-card {
    background: white;
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 16px;
    display: grid;
    gap: 8px;
}
.card-top, .pill-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.pill {
    background: #f2f4f7;
    color: #667085;
    border-radius: 999px;
    padding: 3px 8px;
    font-size: 12px;
}
.card-title { display: flex; gap: 10px; align-items: center; min-height: 52px; color: inherit; }
.card-title h2 { font-size: 15px; line-height: 1.35; color: var(--ink); }
.avatar {
    width: 36px; height: 36px; border-radius: 50%;
    display: grid; place-items: center;
    background: #5b4dff; color: white; font-size: 12px; font-weight: 800; flex: none;
}
.avatar.lg { width: 64px; height: 64px; font-size: 18px; }
.outline-btn {
    display: block;
    text-align: center;
    border: 1px solid #c7d2fe;
    color: #3b5bdb;
    border-radius: 12px;
    padding: 8px 10px;
    font-weight: 700;
}
.star { color: #98a2b3; }

.settings-body {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 240px 1fr;
    background: #f6f7fb;
}
.settings-nav {
    position: sticky;
    top: 0;
    height: 100vh;
    background: #f3f4f6;
    border-right: 1px solid #e5e7eb;
    padding: 16px 12px;
}
.settings-back { color: #667085; font-size: 13px; }
.settings-name { margin: 16px 8px 8px; font-weight: 800; }
.settings-nav nav { display: flex; flex-direction: column; gap: 4px; }
.settings-nav nav a {
    color: #1f2937;
    font-weight: 700;
    padding: 10px 12px;
    border-radius: 12px;
}
.settings-nav nav a.on { background: #1f2430; color: white; }
.settings-main { padding: 28px 32px 48px; }
.settings-main h1 { font-size: 26px; margin-bottom: 8px; }
.rag-note {
    background: #eef4ff;
    color: #1d4ed8;
    border-radius: 12px;
    padding: 12px 14px;
    margin: 12px 0;
}
.doc-tabs { display: flex; gap: 8px; margin: 12px 0; }
.doc-tab {
    background: white;
    color: var(--ink);
    border: 1px solid var(--line);
}
.doc-tab.on { background: var(--navy); color: white; }
.profile-card { display: flex; gap: 14px; align-items: center; }
.settings-main .panel { margin-top: 14px; }

@media (max-width: 900px) {
    .app-body, .split, .card-grid, .grid-form, .channel-grid, .settings-body { grid-template-columns: 1fr; }
    .sidebar, .settings-nav { min-height: auto; height: auto; position: static; }
    .chat { min-height: auto; }
}
