  :root {
    --bg: #f6f5f0;
    --surface: #ffffff;
    --surface-alt: #efede4;
    --text: #1f2a1d;
    --text-muted: #6e7566;
    --text-faint: #9a9d8f;
    --accent: #3f6349;
    --accent-strong: #2c4a34;
    --accent-soft-bg: #e4ede0;
    --brand-yellow: #f4c025;
    --brand-yellow-soft: #fdf1cf;
    --brand-yellow-ink: #7a5c0a;
    --border: #dedacc;
    --badge-ne-bg: #f3e3d2;
    --badge-ne-fg: #8a5223;
    --badge-south-bg: #dce7f2;
    --badge-south-fg: #2c5680;
    --wrong-bg: #f5ded6;
    --wrong-fg: #a14a2f;
    --focus: #3f6349;
    --shadow: 0 1px 2px rgba(31, 42, 29, 0.06), 0 8px 24px rgba(31, 42, 29, 0.06);
  }

  :root[data-theme="dark"] {
    --bg: #14180f;
    --surface: #1b2117;
    --surface-alt: #222a1c;
    --text: #eceee6;
    --text-muted: #a3ab97;
    --text-faint: #6f7864;
    --accent: #7fae83;
    --accent-strong: #a3cba6;
    --accent-soft-bg: #26331f;
    --brand-yellow: #e8b93a;
    --brand-yellow-soft: #3a3218;
    --brand-yellow-ink: #f2d27e;
    --border: #333b2b;
    --badge-ne-bg: #3a2f1e;
    --badge-ne-fg: #e2b485;
    --badge-south-bg: #1f2c39;
    --badge-south-fg: #9cc2e6;
    --wrong-bg: #3a241c;
    --wrong-fg: #e3a086;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
  }

  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --bg: #14180f;
      --surface: #1b2117;
      --surface-alt: #222a1c;
      --text: #eceee6;
      --text-muted: #a3ab97;
      --text-faint: #6f7864;
      --accent: #7fae83;
      --accent-strong: #a3cba6;
      --accent-soft-bg: #26331f;
      --brand-yellow: #e8b93a;
      --brand-yellow-soft: #3a3218;
      --brand-yellow-ink: #f2d27e;
      --border: #333b2b;
      --badge-ne-bg: #3a2f1e;
      --badge-ne-fg: #e2b485;
      --badge-south-bg: #1f2c39;
      --badge-south-fg: #9cc2e6;
      --wrong-bg: #3a241c;
      --wrong-fg: #e3a086;
      --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
    }
  }

  * { box-sizing: border-box; }

  body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
  }

  .serif {
    font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  }

  button, input {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
  }

  /* ---------- Login view ---------- */
  .page-login {
    display: flex;
    min-height: 100vh;
    align-items: center;
    justify-content: center;
    padding: 24px;
  }
  .login-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 36px 32px;
    box-shadow: var(--shadow);
  }
  .login-mark {
    margin-bottom: 10px;
    display: flex;
    justify-content: center;
  }
  .login-mark .wordmark {
    height: 40px;
    width: auto;
    display: block;
  }
  .login-tool-label {
    font-size: 12.5px;
    color: var(--text-muted);
    margin-bottom: 26px;
    text-align: center;
  }
  h1.login-h {
    font-size: 20px;
    margin: 0 0 6px;
  }
  .login-lead {
    color: var(--text-muted);
    font-size: 13.5px;
    margin: 0 0 26px;
  }
  label {
    display: block;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }
  .field { margin-bottom: 18px; }
  .field input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    outline: none;
  }
  .field input:focus {
    border-color: var(--focus);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 20%, transparent);
  }
  .btn-primary {
    width: 100%;
    padding: 11px 14px;
    border: none;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease;
  }
  .btn-primary:hover { background: var(--accent-strong); }
  .login-foot {
    margin-top: 20px;
    font-size: 12.5px;
    color: var(--text-faint);
    text-align: center;
  }

  /* ---------- Chat view ---------- */
  .page-chat {
    display: flex;
    flex-direction: row;
    min-height: 100vh;
    width: 100%;
  }

  /* ---------- Sidebar ---------- */
  .sidebar {
    width: 264px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 16px 12px;
    gap: 4px;
  }
  .sidebar-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 4px 12px;
  }
  .sidebar-logo { width: 28px; height: 28px; object-fit: contain; }
  .sidebar-close { display: none; border: none; background: none; font-size: 22px; line-height: 1; color: var(--text-muted); cursor: pointer; }
  .new-chat-btn {
    display: block;
    text-align: center;
    text-decoration: none;
    border: 1px solid var(--border);
    background: var(--accent-soft-bg);
    color: var(--accent-strong);
    font-weight: 600;
    font-size: 13.5px;
    padding: 9px;
    border-radius: 9px;
    margin-bottom: 18px;
  }
  .new-chat-btn:hover { border-color: var(--accent); }
  .sidebar-label {
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-faint);
    padding: 0 4px 8px;
  }
  .conversation-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
  .conversation-empty { font-size: 12.5px; color: var(--text-faint); padding: 8px 4px; }
  .conversation-item {
    display: flex;
    align-items: center;
    gap: 4px;
    border-radius: 8px;
  }
  .conversation-item:hover { background: var(--surface-alt); }
  .conversation-item.active { background: var(--accent-soft-bg); }
  .conversation-link {
    flex: 1;
    min-width: 0;
    text-decoration: none;
    color: var(--text);
    padding: 8px 8px;
  }
  .conv-title {
    font-size: 12.5px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .conversation-item.active .conv-title { color: var(--accent-strong); }
  .conv-meta { font-size: 10.5px; color: var(--text-faint); margin-top: 2px; }
  .conv-delete {
    flex-shrink: 0;
    border: none;
    background: none;
    color: var(--text-faint);
    padding: 6px;
    margin-right: 4px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
  }
  .conv-delete svg { width: 14px; height: 14px; }
  .conv-delete:hover { color: var(--wrong-fg); background: var(--wrong-bg); }
  .sidebar-backdrop { display: none; }

  .main-area {
    flex: 1;
    min-width: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
  }
  .hamburger {
    display: none;
    border: none;
    background: none;
    color: var(--text);
    padding: 4px;
    margin-right: 4px;
    cursor: pointer;
  }
  .hamburger svg { width: 20px; height: 20px; }

  @media (max-width: 860px) {
    .sidebar {
      position: fixed;
      top: 0;
      left: 0;
      bottom: 0;
      z-index: 40;
      transform: translateX(-100%);
      transition: transform 0.18s ease;
      box-shadow: var(--shadow);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-close { display: block; }
    .hamburger { display: inline-flex; align-items: center; }
    .sidebar-backdrop {
      display: block;
      position: fixed;
      inset: 0;
      background: rgba(0, 0, 0, 0.35);
      z-index: 30;
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.18s ease;
    }
    .sidebar-backdrop.show { opacity: 1; pointer-events: auto; }
  }

  @media (max-width: 480px) {
    .brand .name { font-size: 11px; }
    .brand .wordmark-sm { height: 22px; }
    .brand-divider { display: none; }
    .topbar { padding: 12px 16px; }
  }
  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 22px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    position: sticky;
    top: 0;
    z-index: 10;
  }
  .brand {
    display: flex;
    align-items: center;
    gap: 10px;
  }
  .brand .wordmark-sm {
    height: 26px;
    width: auto;
    display: block;
    flex-shrink: 0;
  }
  .brand-divider {
    width: 1px;
    height: 22px;
    background: var(--border);
    flex-shrink: 0;
  }
  .brand .name { font-size: 13px; font-weight: 600; }
  .brand .tagline { font-size: 12px; color: var(--text-muted); }
  .topbar-right { display: flex; align-items: center; gap: 14px; }
  .profile-menu { position: relative; }
  .avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--surface-alt);
    color: var(--accent-strong);
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
  }
  .avatar:hover {
    border-color: var(--accent);
    background: var(--accent-soft-bg);
  }
  .profile-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 200px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
    z-index: 50;
  }
  .profile-dropdown.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
  }
  .profile-email {
    padding: 10px 14px;
    font-size: 12px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    word-break: break-word;
  }
  .dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    font-size: 13.5px;
    color: var(--text);
    text-decoration: none;
    transition: background 0.12s ease;
  }
  .dropdown-item:first-of-type {
    border-radius: 10px 10px 0 0;
  }
  .dropdown-item:last-of-type {
    border-radius: 0 0 10px 10px;
  }
  .dropdown-item:hover {
    background: var(--surface-alt);
  }
  .dropdown-item svg {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    flex-shrink: 0;
  }

  .chat-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 28px 20px 140px;
  }
  .chat-col {
    max-width: 720px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 26px;
  }

  .msg-user {
    align-self: flex-end;
    max-width: 78%;
    background: var(--accent-soft-bg);
    color: var(--accent-strong);
    padding: 10px 16px;
    border-radius: 14px 14px 3px 14px;
    font-size: 14.5px;
  }

  .msg-assistant { max-width: 100%; }
  .answer-block {
    border-left: 3px solid var(--accent);
    padding: 2px 0 2px 16px;
  }
  .answer-block p { margin: 0 0 10px; }
  .answer-block p:last-child { margin-bottom: 0; }
  .answer-block ul { margin: 8px 0; padding-left: 20px; }
  .answer-block li { margin-bottom: 4px; }
  .answer-block strong { font-weight: 650; }

  .region-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11.5px;
    font-weight: 600;
    padding: 2px 8px 2px 7px;
    border-radius: 999px;
    margin-right: 8px;
    letter-spacing: 0.01em;
  }
  .region-badge.ne { background: var(--badge-ne-bg); color: var(--badge-ne-fg); }
  .region-badge.south { background: var(--badge-south-bg); color: var(--badge-south-fg); }
  .region-badge svg { width: 8px; height: 8px; }

  .figure {
    background: linear-gradient(transparent 62%, var(--brand-yellow-soft) 62%);
    color: var(--brand-yellow-ink);
    font-weight: 700;
    padding: 0 1px;
  }

  .sources {
    margin-top: 12px;
    padding-left: 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }
  .source-chip {
    display: inline-flex;
    align-items: baseline;
    gap: 5px;
    font-size: 12px;
    color: var(--text-muted);
    background: var(--surface-alt);
    border: 1px solid var(--border);
    padding: 4px 9px;
    border-radius: 7px;
    max-width: 340px;
  }
  .source-chip .src-type {
    font-size: 9.5px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
    color: var(--accent);
    flex-shrink: 0;
  }
  .source-chip .src-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .not-covered {
    border-left: 3px solid var(--text-faint);
    padding: 2px 0 2px 16px;
    color: var(--text-muted);
    font-size: 14px;
    font-style: italic;
  }

  .feedback-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 12px;
    padding-left: 16px;
  }
  .fb-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    border-radius: 7px;
    padding: 5px 9px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
  }
  .fb-btn svg { width: 13px; height: 13px; flex-shrink: 0; }
  .fb-btn:hover { border-color: var(--accent); color: var(--accent-strong); }
  .fb-btn.correct.active {
    background: var(--accent-soft-bg);
    border-color: var(--accent);
    color: var(--accent-strong);
    font-weight: 600;
  }
  .fb-btn.wrong.active {
    background: var(--wrong-bg);
    border-color: var(--wrong-fg);
    color: var(--wrong-fg);
    font-weight: 600;
  }
  .fb-confirm {
    font-size: 12px;
    color: var(--accent-strong);
    opacity: 0;
    transition: opacity 0.2s ease;
  }
  .fb-confirm.show { opacity: 1; }

  .fb-remark-box {
    margin: 8px 0 0 16px;
    display: flex;
    gap: 6px;
  }
  .fb-remark-box[hidden] { display: none; }
  .fb-remark-box textarea {
    flex: 1;
    resize: none;
    min-height: 40px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    padding: 8px 10px;
    font-family: inherit;
    font-size: 12.5px;
    color: var(--text);
    outline: none;
  }
  .fb-remark-box textarea:focus {
    border-color: var(--focus);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 20%, transparent);
  }
  .fb-remark-send {
    align-self: flex-end;
    border: none;
    background: var(--accent);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
  }
  .fb-remark-send:hover { background: var(--accent-strong); }

  .typing-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding-left: 16px;
    color: var(--text-faint);
    font-size: 13px;
  }
  .typing-dots { display: inline-flex; gap: 3px; }
  .typing-dots span {
    width: 5px; height: 5px; border-radius: 50%;
    background: var(--text-faint);
    animation: bounce 1.1s infinite ease-in-out;
  }
  .typing-dots span:nth-child(2) { animation-delay: 0.15s; }
  .typing-dots span:nth-child(3) { animation-delay: 0.3s; }
  @media (prefers-reduced-motion: reduce) {
    .typing-dots span { animation: none; }
  }
  @keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-3px); opacity: 1; }
  }

  .empty-state {
    max-width: 720px;
    margin: 20px auto 0;
    text-align: center;
  }
  .empty-hint {
    color: var(--text-muted);
    font-size: 13px;
    margin: 0 0 12px;
  }
  .suggestion-chips {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 7px;
  }
  .suggestion-chip {
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 999px;
    padding: 7px 14px;
    font-size: 12.5px;
    cursor: pointer;
    color: var(--text-muted);
    font-family: inherit;
  }
  .suggestion-chip:hover { border-color: var(--accent); color: var(--accent-strong); background: var(--accent-soft-bg); }

  .composer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 16px 20px 20px;
    background: linear-gradient(to top, var(--bg) 60%, transparent);
  }
  .composer-inner {
    max-width: 720px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 8px 8px 8px 16px;
    box-shadow: var(--shadow);
  }
  .composer-inner input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    padding: 8px 0;
  }
  .send-btn {
    width: 36px; height: 36px;
    border-radius: 10px;
    border: none;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
  }
  .send-btn:hover { background: var(--accent-strong); }
  .composer-hint {
    text-align: center;
    font-size: 11px;
    color: var(--text-faint);
    margin-top: 8px;
  }

  ::-webkit-scrollbar { width: 10px; }
  ::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }

  /* ---------- Real-app additions (not in the original mockup) ---------- */
  .composer-inner.disabled { opacity: 0.6; pointer-events: none; }
  .send-btn:disabled { background: var(--text-faint); cursor: default; }

  .error-banner {
    max-width: 720px;
    margin: 0 auto 16px;
    background: var(--wrong-bg);
    color: var(--wrong-fg);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 13px;
  }

  /* ---------- Admin users page ---------- */
  .admin-wrap { max-width: 680px; margin: 40px auto; padding: 0 20px; }
  .admin-wrap h1 { font-size: 20px; margin: 0 0 4px; }
  .admin-wrap .lead { color: var(--text-muted); font-size: 13.5px; margin: 0 0 28px; }
  .admin-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 22px 24px;
    margin-bottom: 24px;
    box-shadow: var(--shadow);
  }
  .admin-card h2 { font-size: 15px; margin: 0 0 16px; }
  .admin-form-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
  .admin-form-row .field { flex: 1; min-width: 160px; margin-bottom: 0; }
  .admin-form-row select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
  }
  .admin-form-row .btn-primary { width: auto; padding: 11px 18px; }
  table.user-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
  table.user-table th {
    text-align: left;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
  }
  table.user-table td { padding: 9px 8px; border-bottom: 1px solid var(--border); }
  table.user-table tr:last-child td { border-bottom: none; }
  .role-pill {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 999px;
  }
  .role-pill.admin { background: var(--brand-yellow-soft); color: var(--brand-yellow-ink); }
  .role-pill.user { background: var(--surface-alt); color: var(--text-muted); }
  .back-link { font-size: 13px; color: var(--text-muted); text-decoration: none; }
  .back-link:hover { color: var(--accent-strong); }

