/* ============================================================
   Atlas AI — Midnight Design System
   Dark-only, permanently. Built from scratch.

   Loaded after tokens.css and shell.css, which provide the
   updated palette and the new sidebar / topbar / drawer shell.
   This file still owns the legacy component styles
   (cards, buttons, forms, page-specific layouts) and will be
   broken out into smaller modules in a follow-up PR.
   ============================================================ */

/* ── Tokens ──────────────────────────────────────────────── */
:root {
  --bg:        #060b15;
  --bg-alt:    #0a1020;
  --surface:   #0d1628;
  --surface-2: #122033;
  --card:      #111d30;
  --card-2:    #172438;
  --elevated:  #1e2d42;

  --border:    rgba(90,120,195,.08);
  --border-2:  rgba(90,120,195,.16);
  --border-hi: rgba(124,133,245,.45);

  --text:    #dde5f3;
  --text-2:  #b4c0d8;
  --muted:   #566080;
  --muted-hi: #7a8aaa;
  --text-muted: #566080;

  --primary:       #7c85f5;
  --primary-light: #a5aef8;
  --primary-dim:   rgba(124,133,245,.12);
  --primary-glow:  rgba(124,133,245,.28);

  --success:  #3dd68c;
  --danger:   #f56565;
  --warning:  #f6ad55;
  --info:     #4fb3e8;
  --purple:   #b57bee;
  --cyan:     #2dd4bf;

  --hover:   rgba(255,255,255,.045);
  --hover-2: rgba(255,255,255,.075);

  --radius:    12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --radius-lg: 16px;
  --radius-xl: 22px;

  --shadow:    0 2px 8px rgba(0,0,0,.45), 0 4px 20px rgba(0,0,0,.25);
  --shadow-lg: 0 8px 30px rgba(0,0,0,.55), 0 16px 50px rgba(0,0,0,.3);
  --shadow-xl: 0 20px 60px rgba(0,0,0,.65), 0 40px 80px rgba(0,0,0,.3);

  --trans:      .15s ease;
  --trans-slow: .25s ease;
}

/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: var(--primary); text-decoration: none; transition: opacity var(--trans); }
a:hover { opacity: .8; }

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(90,120,195,.25); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(90,120,195,.45); }

/* ── Navbar ──────────────────────────────────────────────── */
.navbar {
  background: rgba(6,11,21,.88);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-bottom: 1px solid var(--border-2);
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 200;
  gap: 16px;
}

.brand {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -.02em;
  background: linear-gradient(135deg, var(--primary-light) 0%, var(--purple) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
  flex-shrink: 0;
}

.nav-links {
  display: flex;
  gap: 2px;
  flex: 1;
  justify-content: center;
  flex-wrap: wrap;
}

.nav-links a, .nav-right a.nav-icon {
  color: var(--muted-hi);
  padding: 6px 12px;
  border-radius: 8px;
  transition: all var(--trans);
  font-size: .84rem;
  font-weight: 500;
  letter-spacing: .005em;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.nav-links a:hover { color: var(--text-2); background: var(--hover); opacity: 1; }
.nav-right a.nav-icon:hover { color: var(--text-2); background: var(--hover); opacity: 1; }
.nav-links a.active { color: var(--primary-light); background: var(--primary-dim); }
.nav-right a.nav-icon.active { color: var(--primary-light); background: var(--primary-dim); }

.nav-right {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  flex-shrink: 0;
}

.nav-user {
  font-size: .8rem;
  color: var(--muted);
  font-weight: 500;
}

.nav-pending {
  font-size: .78rem;
  color: var(--warning);
  padding: 4px 10px;
  background: rgba(246,173,85,.1);
  border-radius: 20px;
  border: 1px solid rgba(246,173,85,.2);
}

.nav-icon {
  font-size: 1rem;
  width: 34px;
  height: 34px;
  padding: 0 !important;
  justify-content: center;
  border-radius: 8px;
}

.nav-logout {
  color: var(--muted-hi);
  padding: 6px 12px;
  border-radius: 8px;
  transition: all var(--trans);
  font-size: .84rem;
  font-weight: 500;
  letter-spacing: .005em;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  white-space: nowrap;
}
.nav-logout:hover { color: var(--danger); background: rgba(245,101,101,.08); opacity: 1; }

.nav-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border-2);
  color: var(--muted-hi);
  cursor: pointer;
  font-size: 1rem;
  padding: 7px 9px;
  border-radius: 8px;
  transition: all var(--trans);
  line-height: 1;
  flex-shrink: 0;
}
.nav-toggle:hover { color: var(--text); border-color: var(--border-hi); background: var(--hover); }

/* ── Layout ──────────────────────────────────────────────── */
.container { max-width: 1400px; margin: 0 auto; padding: 28px 24px; }
main.container { min-height: calc(100vh - 60px); }

.page-header { margin-bottom: 28px; }
.page-header h1 {
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -.025em;
  margin-bottom: 4px;
}

.two-col      { display: grid; grid-template-columns: 1fr 1fr;       gap: 20px; }
.two-col--lead { grid-template-columns: 1.6fr 1fr; align-items: start; }
.three-col    { display: grid; grid-template-columns: repeat(3,1fr); gap: 16px; }
.four-col     { display: grid; grid-template-columns: repeat(4,1fr); gap: 12px; }
.two-col-form { display: grid; grid-template-columns: 1fr 1fr;       gap: 14px; }

@media (max-width: 900px) {
  .two-col, .three-col, .four-col, .two-col-form { grid-template-columns: 1fr; }
}

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color var(--trans);
}
.card-title {
  font-size: .93rem;
  font-weight: 700;
  letter-spacing: -.01em;
  margin-bottom: 16px;
  color: var(--text);
}
.card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 8px;
}
.card-header-row .card-title { margin-bottom: 0; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  font-size: .84rem;
  font-weight: 600;
  font-family: inherit;
  letter-spacing: .01em;
  transition: all var(--trans);
  text-decoration: none;
  white-space: nowrap;
  line-height: 1;
}
.btn:disabled { opacity: .38; cursor: not-allowed; transform: none !important; }
.btn:not(:disabled):hover { transform: translateY(-1px); opacity: 1; }
.btn:active { transform: translateY(0) !important; }

.btn-sm   { padding: 6px 13px; font-size: .79rem; }
.btn-full { width: 100%; }

.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, #646bd6 100%);
  color: #fff;
  box-shadow: 0 2px 12px rgba(124,133,245,.3);
}
.btn-primary:not(:disabled):hover { box-shadow: 0 4px 22px rgba(124,133,245,.48); }

.btn-success { background: var(--success); color: #061a0e; }
.btn-danger  { background: var(--danger);  color: #fff; }
.btn-info    { background: var(--info);    color: #04192b; }
.btn-purple  { background: var(--purple);  color: #190b2d; }
.btn-cyan    { background: var(--cyan);    color: #041f1c; }

.btn-warning {
  background: rgba(246,173,85,.14);
  color: var(--warning);
  border: 1px solid rgba(246,173,85,.28);
}
.btn-warning:not(:disabled):hover { background: rgba(246,173,85,.25) !important; }

.btn-ghost {
  background: transparent;
  color: var(--muted-hi);
  border: 1px solid var(--border-2);
}
.btn-ghost:not(:disabled):hover {
  color: var(--text);
  border-color: var(--border-hi);
  background: var(--hover);
}

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ── Forms ───────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  margin-bottom: 7px;
  font-size: .76rem;
  color: var(--muted-hi);
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.form-group label small {
  font-weight: 400;
  font-size: .78rem;
  text-transform: none;
  letter-spacing: 0;
  color: var(--muted);
}

.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--text-2) !important;
  font-size: .87rem !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
  font-weight: 400 !important;
}
.checkbox-label input[type=checkbox] {
  width: 15px;
  height: 15px;
  cursor: pointer;
  accent-color: var(--primary);
}

input[type=text], input[type=email], input[type=password],
input[type=number], input[type=url], select, textarea {
  width: 100%;
  padding: 10px 14px;
  background: rgba(5,9,18,.75);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: .87rem;
  font-family: inherit;
  transition: border-color var(--trans), box-shadow var(--trans);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-dim);
}
textarea { resize: vertical; line-height: 1.65; }
select { cursor: pointer; }
.select-inline { width: auto; padding: 6px 10px; font-size: .85rem; }

.input-with-toggle { position: relative; }
.input-with-toggle input { padding-right: 42px; }
.toggle-vis {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: .9rem;
  padding: 4px;
  transition: color var(--trans);
}
.toggle-vis:hover { color: var(--text-2); }

/* ── Alerts & Notices ────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: .87rem;
  line-height: 1.55;
}
.alert-error   { background: rgba(245,101,101,.1); border: 1px solid rgba(245,101,101,.24); color: #fca5a5; }
.alert-success { background: rgba(61,214,140,.1);  border: 1px solid rgba(61,214,140,.24);  color: #6ee7b7; }
.alert-warning { background: rgba(246,173,85,.1);  border: 1px solid rgba(246,173,85,.24);  color: #fcd34d; }
.alert-info    { background: rgba(79,179,232,.1);  border: 1px solid rgba(79,179,232,.24);  color: #93c5fd; }

.notice { padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 12px; font-size: .87rem; }
.notice-warning { background: rgba(246,173,85,.08); border: 1px solid rgba(246,173,85,.2); color: #fcd34d; }
.notice-info    { background: rgba(79,179,232,.08); border: 1px solid rgba(79,179,232,.2); color: #93c5fd; }
.notice-info code {
  background: rgba(79,179,232,.15);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: 'Consolas', 'Courier New', monospace;
}

/* ── Site Footer ─────────────────────────────────────────── */
.site-footer {
  margin-top: 52px;
  border-top: 1px solid var(--border);
  padding: 0 24px 28px;
}
.footer-notice {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-top: 14px;
  font-size: .79rem;
  line-height: 1.6;
}
.footer-notice--warning { background: rgba(246,173,85,.05); border: 1px solid rgba(246,173,85,.14); color: #a89060; }
.footer-notice--info    { background: rgba(79,179,232,.05); border: 1px solid rgba(79,179,232,.14); color: #6a8caa; }

/* ── Progress ────────────────────────────────────────────── */
.progress-bar {
  background: var(--border-2);
  border-radius: 99px;
  height: 5px;
  overflow: hidden;
}
.progress-fill {
  background: linear-gradient(90deg, var(--primary), var(--cyan));
  height: 100%;
  width: 0%;
  transition: width .4s ease;
  border-radius: 99px;
}

/* ── Item List ───────────────────────────────────────────── */
.item-list { display: flex; flex-direction: column; gap: 3px; max-height: 400px; overflow-y: auto; }

.item-list-entry {
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: transparent;
  border: 1px solid transparent;
  transition: all var(--trans);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.item-list-entry:hover { background: var(--hover); border-color: var(--border); }
.item-list-entry.active { background: var(--primary-dim); border-color: rgba(124,133,245,.28); }

.item-list-entry__title {
  font-size: .85rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  color: var(--text-2);
}
.item-list-entry.active .item-list-entry__title { color: var(--primary-light); }
.item-list-entry__meta  { font-size: .72rem; color: var(--muted); white-space: nowrap; }
.item-list-entry__del {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: .88rem;
  transition: all var(--trans);
}
.item-list-entry__del:hover { color: var(--danger); background: rgba(245,101,101,.1); }

/* ── Badges ──────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 99px;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.badge-blue   { background: rgba(79,179,232,.14);  color: #7dd3fc; }
.badge-green  { background: rgba(61,214,140,.14);  color: #6ee7b7; }
.badge-orange { background: rgba(246,173,85,.14);  color: #fcd34d; }
.badge-purple { background: rgba(181,123,238,.14); color: #d8b4fe; }
.badge-red    { background: rgba(245,101,101,.14); color: #fca5a5; }
.badge-grey   { background: rgba(255,255,255,.06); color: #8090aa; }

/* ── Admin Table ─────────────────────────────────────────── */
.admin-table { width: 100%; border-collapse: collapse; font-size: .86rem; }
.admin-table th {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-2);
  color: var(--muted-hi);
  font-weight: 700;
  font-size: .69rem;
  text-transform: uppercase;
  letter-spacing: .07em;
}
.admin-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr.row-disabled td { opacity: .38; }
.admin-table tr.row-pending { background: rgba(246,173,85,.03); }
.admin-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── Auth Pages ──────────────────────────────────────────── */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 70% 45% at 50% -5%, rgba(124,133,245,.1), transparent),
    radial-gradient(ellipse 45% 35% at 85% 105%, rgba(181,123,238,.07), transparent);
}

.auth-card {
  background: var(--card);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-xl);
  padding: 44px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg), 0 0 80px rgba(124,133,245,.06);
}

.auth-logo {
  font-size: 2.2rem;
  text-align: center;
  margin-bottom: 12px;
  background: linear-gradient(135deg, var(--primary-light), var(--purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.auth-title {
  font-size: 1.4rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 5px;
  letter-spacing: -.025em;
}

.auth-subtitle {
  color: var(--muted);
  text-align: center;
  margin-bottom: 28px;
  font-size: .88rem;
}

.auth-form .btn-full { margin-top: 8px; padding: 13px; font-size: .94rem; }
.auth-switch { text-align: center; margin-top: 22px; font-size: .87rem; color: var(--muted); }

/* ── Dashboard ───────────────────────────────────────────── */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}
@media (max-width: 800px) { .dashboard-grid { grid-template-columns: 1fr; } }

.dash-card {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 26px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  text-decoration: none;
  color: var(--text);
  transition: all var(--trans-slow);
  overflow: hidden;
}

/* Subtle glowing top-edge gradient on hover */
.dash-card::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  opacity: 0;
  transition: opacity var(--trans-slow);
}
.dash-card:hover { transform: translateY(-2px); border-color: var(--border-2); box-shadow: 0 8px 32px rgba(0,0,0,.45); }
.dash-card:hover::after { opacity: 1; }

.dash-card--green::after  { background: linear-gradient(90deg, transparent, var(--success), transparent); }
.dash-card--orange::after { background: linear-gradient(90deg, transparent, var(--warning), transparent); }
.dash-card--blue::after   { background: linear-gradient(90deg, transparent, var(--info),    transparent); }
.dash-card--purple::after { background: linear-gradient(90deg, transparent, var(--purple),  transparent); }

.dash-card__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  font-size: 1.35rem;
  margin-bottom: 18px;
  flex-shrink: 0;
}
.dash-card--green  .dash-card__icon { background: rgba(61,214,140,.12);  color: var(--success); }
.dash-card--orange .dash-card__icon { background: rgba(246,173,85,.12);  color: var(--warning); }
.dash-card--blue   .dash-card__icon { background: rgba(79,179,232,.12);  color: var(--info);    }
.dash-card--purple .dash-card__icon { background: rgba(181,123,238,.12); color: var(--purple);  }

.dash-card__body { flex: 1; }
.dash-card h2 { font-size: .98rem; font-weight: 700; margin-bottom: 8px; letter-spacing: -.01em; }
.dash-card p  { color: var(--muted); font-size: .83rem; line-height: 1.6; margin-bottom: 16px; }

.dash-card__stat {
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
}
.dash-card--green  .dash-card__stat { color: var(--success); }
.dash-card--orange .dash-card__stat { color: var(--warning); }
.dash-card--blue   .dash-card__stat { color: var(--info);    }
.dash-card--purple .dash-card__stat { color: var(--purple);  }

/* ── Dropzone ────────────────────────────────────────────── */
.dropzone {
  border: 2px dashed var(--border-2);
  border-radius: var(--radius);
  padding: 32px 24px;
  text-align: center;
  cursor: pointer;
  transition: all var(--trans);
  background: rgba(6,11,21,.5);
}
.dropzone:hover, .dropzone.drag-over {
  border-color: var(--primary);
  background: var(--primary-dim);
}
.dropzone__icon { font-size: 2rem; margin-bottom: 10px; color: var(--muted-hi); }
.dropzone:hover .dropzone__icon,
.dropzone.drag-over .dropzone__icon { color: var(--primary-light); }
.dropzone p { color: var(--muted); font-size: .86rem; margin: 3px 0; }
.dropzone .link { color: var(--primary); }

/* ── Meta Tags ───────────────────────────────────────────── */
.meta-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.meta-tag {
  padding: 3px 10px;
  border-radius: 99px;
  font-size: .7rem;
  font-weight: 600;
  background: rgba(79,179,232,.1);
  color: #7dd3fc;
  border: 1px solid rgba(79,179,232,.2);
  letter-spacing: .02em;
  text-transform: uppercase;
}

/* ── Char Count ──────────────────────────────────────────── */
.char-count { font-size: .74rem; color: var(--muted); text-align: right; margin-top: 5px; }

/* ── Modals ──────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(3,6,14,.78);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.modal-box {
  position: relative;
  background: var(--card-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  z-index: 1;
}
.modal-box--sm { max-width: 420px; }
.modal-box--lg { max-width: 860px; }
.modal-header  {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.modal-header h3 { font-size: .98rem; font-weight: 700; letter-spacing: -.01em; }
.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.2rem;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all var(--trans);
}
.modal-close:hover { color: var(--text); background: var(--hover-2); }

details { margin-top: 4px; }

/* ── Sections List (TTS) ─────────────────────────────────── */
.sections-list { display: flex; flex-direction: column; gap: 6px; }
.section-item {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: all var(--trans);
}
.section-item:hover { border-color: var(--border-2); background: var(--hover); }
.section-item__drag    { color: var(--muted); cursor: grab; font-size: 1rem; }
.section-item__body    { flex: 1; overflow: hidden; }
.section-item__title   { font-size: .84rem; font-weight: 600; color: var(--text-2); }
.section-item__meta    { font-size: .72rem; color: var(--muted); margin-top: 2px; }
.section-item__preview {
  font-size: .76rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 4px;
}

/* ── Chat ────────────────────────────────────────────────── */
body.page-chat {
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
body.page-chat main.container {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding-top: 12px;
  padding-bottom: 8px;
  max-width: none;
  width: 100%;
}
body.page-chat .chat-layout { flex: 1; min-height: 0; grid-template-rows: minmax(0,1fr); }
body.page-chat .chat-main,
body.page-chat .chat-sidebar { display: flex; flex-direction: column; min-height: 0; }
body.page-chat .chat-main .card,
body.page-chat .chat-sidebar .card { flex: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
body.page-chat .navbar      { flex-shrink: 0; }
body.page-chat .site-footer {
  flex-shrink: 0;
  margin-top: 0;
  padding: 6px 24px 10px;
  border-top: 1px solid var(--border);
}
body.page-chat .site-footer .footer-notice {
  margin-top: 6px;
  padding: 7px 12px;
  font-size: .75rem;
}

.chat-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 16px;
  height: calc(100vh - 100px);
}
@media (max-width: 900px) { .chat-layout { grid-template-columns: 1fr; height: auto; } }
.chat-sidebar .card { height: 100%; display: flex; flex-direction: column; }
.chat-main    .card { height: 100%; display: flex; flex-direction: column; }

.messages-area {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message { display: flex; gap: 8px; min-width: 0; }
.message.user { flex-direction: row-reverse; }

.message__bubble {
  max-width: 78%;
  min-width: 0;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: .87rem;
  line-height: 1.65;
  word-break: break-word;
  overflow-wrap: break-word;
  overflow-x: hidden;
}
.message.user      .message__bubble { background: var(--primary-dim); border: 1px solid rgba(124,133,245,.22); }
.message.assistant .message__bubble { background: var(--surface);     border: 1px solid var(--border); }

.message__bubble h1 { font-size: 1.1rem; font-weight: 700; margin: 8px 0 4px; line-height: 1.3; }
.message__bubble h2 { font-size: 1rem;   font-weight: 700; margin: 6px 0 3px; line-height: 1.3; }
.message__bubble h3 { font-size: .95rem; font-weight: 700; margin: 6px 0 3px; line-height: 1.3; }
.message__bubble pre {
  background: var(--bg);
  border: 1px solid var(--border-2);
  border-radius: 6px;
  padding: 10px 12px;
  overflow-x: auto;
  white-space: pre;
  margin: 6px 0;
  font-size: .82rem;
  max-width: 100%;
  box-sizing: border-box;
}
.message__bubble code {
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: .85em;
  background: rgba(124,133,245,.1);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--primary-light);
}
.message__bubble pre code { background: none; padding: 0; color: var(--text-2); }

.message__avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .84rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

@keyframes chat-blink { 0%,100% { opacity: 1; } 50% { opacity: 0; } }
.message__bubble.streaming::after {
  content: '▋';
  display: inline;
  color: var(--primary);
  animation: chat-blink .7s step-end infinite;
  margin-left: 1px;
}

.chat-error {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  color: var(--danger);
  font-size: .87rem;
  line-height: 1.5;
}
.chat-error i { margin-top: 2px; flex-shrink: 0; }

.chat-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.chat-input-row textarea { flex: 1; resize: none; max-height: 120px; }

/* ── Settings ────────────────────────────────────────────── */
.settings-section { margin-bottom: 20px; }
.settings-heading { font-size: .92rem; font-weight: 700; margin-bottom: 6px; letter-spacing: -.01em; }
.settings-desc { color: var(--muted); font-size: .83rem; margin-bottom: 14px; line-height: 1.55; }

/* ── Utilities ───────────────────────────────────────────── */
.text-muted  { color: var(--muted) !important; }
.text-center { text-align: center; }
.quick-settings-notice { margin-top: 24px; }

/* ── AI Thinking ─────────────────────────────────────────── */
@keyframes ss-spin  { to { transform: rotate(360deg); } }
@keyframes ss-pulse { 0%,100% { opacity: .22; } 50% { opacity: 1; } }
.ai-thinking {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--primary-light);
  font-size: .84rem;
  font-weight: 500;
}
.ai-thinking__spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--primary-dim);
  border-top-color: var(--primary);
  animation: ss-spin .65s linear infinite;
  flex-shrink: 0;
}
.ai-thinking__dots span {
  display: inline-block;
  animation: ss-pulse 1.2s ease-in-out infinite;
}
.ai-thinking__dots span:nth-child(2) { animation-delay: .2s; }
.ai-thinking__dots span:nth-child(3) { animation-delay: .4s; }
.ai-thinking__timer  { font-size: .74rem; font-weight: 400; opacity: .5; margin-left: 2px; }
.ai-thinking__meta   { display: block; font-size: .71rem; color: var(--muted); margin-top: 4px; padding-left: 22px; }

/* ── Shared Markdown ─────────────────────────────────────── */
.stream-output em, .chapter-preview em,
.reading-mode__chapter-body em, .output-reading__body em, .message__bubble em { font-style: italic; }

.stream-output del, .chapter-preview del,
.reading-mode__chapter-body del, .output-reading__body del, .message__bubble del { text-decoration: line-through; opacity: .6; }

.stream-output a, .chapter-preview a,
.reading-mode__chapter-body a, .output-reading__body a, .message__bubble a {
  color: var(--primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.stream-output a:hover, .chapter-preview a:hover,
.reading-mode__chapter-body a:hover, .output-reading__body a:hover, .message__bubble a:hover { opacity: .8; }

.stream-output ul, .stream-output ol,
.chapter-preview ul, .chapter-preview ol,
.reading-mode__chapter-body ul, .reading-mode__chapter-body ol,
.output-reading__body ul, .output-reading__body ol,
.message__bubble ul, .message__bubble ol { padding-left: 1.6em; margin: 5px 0; }

.stream-output li, .chapter-preview li,
.reading-mode__chapter-body li, .output-reading__body li,
.message__bubble li { margin: 4px 0; }

.stream-output blockquote, .chapter-preview blockquote,
.reading-mode__chapter-body blockquote, .output-reading__body blockquote,
.message__bubble blockquote {
  border-left: 3px solid var(--primary-dim);
  padding: 4px 14px;
  color: var(--muted-hi);
  margin: 8px 0;
}

.stream-output hr, .chapter-preview hr,
.reading-mode__chapter-body hr, .output-reading__body hr, .message__bubble hr {
  border: none;
  border-top: 1px solid var(--border-2);
  margin: 14px 0;
}

/* ── Text colour utilities ───────────────────────────────── */
.text-danger  { color: var(--danger)  !important; }
.text-success { color: var(--success) !important; }
.text-warning { color: var(--warning) !important; }
.text-info    { color: var(--info)    !important; }
.text-primary { color: var(--primary) !important; }

/* ── Pre block used inside Atlas.Modal confirm bodies ────── */
.ss-confirm-pre {
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-xs);
  padding: 10px 12px;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: .8rem;
  overflow-x: auto;
  white-space: pre;
  margin-top: 8px;
  max-height: 160px;
  overflow-y: auto;
}

/* ── Mobile Logout (hidden on desktop; specificity must beat .nav-links a) ── */
.nav-links a.nav-mobile-logout { display: none; }

/* ── Mobile ──────────────────────────────────────────────── */
@media (max-width: 768px) {
  .navbar { flex-wrap: wrap; padding: 0 14px; gap: 0; }
  .brand  { padding: 14px 0; flex: 1; }
  .nav-right  { gap: 4px; padding: 7px 0; }
  .nav-user    { display: none; }
  .nav-logout  { display: none; }
  .nav-toggle  { display: flex; align-items: center; justify-content: center; }

  .nav-links {
    display: none;
    width: 100%;
    flex-direction: column;
    flex: none;
    justify-content: flex-start;
    border-top: 1px solid var(--border);
    padding: 6px 0 10px;
    gap: 2px;
  }
  .navbar.nav-open .nav-links { display: flex; }
  .nav-links a { padding: 10px; border-radius: var(--radius-sm); font-size: .9rem; }
  .nav-pending  { padding: 10px; border-radius: 0; background: none; border: none; }

  .nav-links a.nav-mobile-logout {
    display: flex;
    margin-top: 6px;
    border-top: 1px solid var(--border);
    padding-top: 10px;
    color: var(--muted);
  }
  .nav-links a.nav-mobile-logout:hover { color: var(--danger) !important; background: rgba(245,101,101,.08) !important; }

  .container { padding: 18px 14px; }
  .auth-body  { align-items: flex-start; padding: 32px 14px; }
  .auth-card  { padding: 28px 20px; }
  .tab-bar    { overflow-x: auto; flex-wrap: nowrap; width: 100%; }
  .tab-bar::-webkit-scrollbar { height: 3px; }
  .dash-card  { padding: 20px; }
  .modal-box  { padding: 20px 16px; }
  .modal      { padding: 12px; }
}

/* ── Custom Audio Player ─────────────────────────────────── */
.audio-player {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: linear-gradient(135deg, var(--surface-2) 0%, var(--card) 100%);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.02), 0 2px 10px rgba(0,0,0,.25);
}
.audio-player__native { display: none; }

.audio-player__play {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  color: #fff;
  background: linear-gradient(135deg, var(--primary) 0%, #646bd6 100%);
  box-shadow: 0 2px 12px rgba(124,133,245,.3);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--trans), box-shadow var(--trans);
}
.audio-player__play:hover  { transform: translateY(-1px); box-shadow: 0 4px 22px rgba(124,133,245,.48); }
.audio-player__play:active { transform: translateY(0); }
.audio-player__play.is-playing { background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary) 100%); }
.audio-player__play i { line-height: 1; transform: translateX(0); }
.audio-player__play:not(.is-playing) i { transform: translateX(1px); } /* nudge play triangle */

.audio-player__skip {
  flex: none;
  position: relative;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border-2);
  background: transparent;
  color: var(--muted-hi);
  cursor: pointer;
  font-size: .82rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--trans);
}
.audio-player__skip:hover { color: var(--text); border-color: var(--border-hi); background: var(--hover); }
.audio-player__skip-num {
  position: absolute;
  font-size: .52rem;
  font-weight: 700;
  letter-spacing: -.02em;
  pointer-events: none;
}

.audio-player__center {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.audio-player__progress {
  flex: 1;
  min-width: 0;
  height: 18px;
  display: flex;
  align-items: center;
  cursor: pointer;
  outline: none;
  position: relative;
  padding: 0 6px;
  margin: 0 -6px;
}
.audio-player__progress:focus-visible .audio-player__progress-track { box-shadow: 0 0 0 2px var(--primary-glow); }
.audio-player__progress-track {
  position: relative;
  width: 100%;
  height: 5px;
  background: rgba(255,255,255,.06);
  border-radius: 999px;
  overflow: visible;
  transition: height var(--trans);
}
.audio-player__progress:hover .audio-player__progress-track { height: 7px; }
.audio-player__progress-buffered {
  position: absolute;
  top: 0; left: 0;
  height: 100%;
  width: 0;
  background: rgba(255,255,255,.08);
  border-radius: 999px;
}
.audio-player__progress-fill {
  position: absolute;
  top: 0; left: 0;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--primary) 0%, var(--primary-light) 100%);
  border-radius: 999px;
}
.audio-player__progress-thumb {
  position: absolute;
  top: 50%;
  left: 0;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--primary-light);
  border: 2px solid var(--bg);
  transform: translate(-50%, -50%);
  box-shadow: 0 2px 6px rgba(0,0,0,.4), 0 0 0 0 var(--primary-glow);
  transition: box-shadow var(--trans), transform var(--trans);
  pointer-events: none;
}
.audio-player__progress:hover .audio-player__progress-thumb,
.audio-player__progress:focus-visible .audio-player__progress-thumb {
  box-shadow: 0 2px 6px rgba(0,0,0,.4), 0 0 0 6px var(--primary-glow);
}

.audio-player__time {
  flex: none;
  font-variant-numeric: tabular-nums;
  font-size: .78rem;
  color: var(--muted-hi);
  letter-spacing: .01em;
  white-space: nowrap;
}
.audio-player__time-current { color: var(--text-2); }
.audio-player__time-sep     { margin: 0 4px; opacity: .55; }

.audio-player__volume {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
.audio-player__mute {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-xs);
  border: none;
  background: transparent;
  color: var(--muted-hi);
  cursor: pointer;
  font-size: .85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color var(--trans), background var(--trans);
}
.audio-player__mute:hover { color: var(--text); background: var(--hover); }
.audio-player__volume-bar {
  width: 70px;
  height: 18px;
  display: flex;
  align-items: center;
  cursor: pointer;
  outline: none;
  position: relative;
}
.audio-player__volume-track {
  position: relative;
  width: 100%;
  height: 4px;
  background: rgba(255,255,255,.06);
  border-radius: 999px;
}
.audio-player__volume-fill {
  position: absolute;
  top: 0; left: 0;
  height: 100%;
  width: 100%;
  background: var(--primary);
  border-radius: 999px;
}
.audio-player__volume-thumb {
  position: absolute;
  top: 50%;
  left: 100%;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary-light);
  border: 2px solid var(--bg);
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--trans);
}
.audio-player__volume:hover .audio-player__volume-thumb,
.audio-player__volume-bar:focus-visible .audio-player__volume-thumb { opacity: 1; }

.audio-player__speed {
  flex: none;
  min-width: 42px;
  height: 30px;
  padding: 0 8px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-2);
  background: transparent;
  color: var(--muted-hi);
  cursor: pointer;
  font-family: inherit;
  font-size: .75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: .01em;
  transition: all var(--trans);
}
.audio-player__speed:hover { color: var(--text); border-color: var(--border-hi); background: var(--hover); }

@media (max-width: 600px) {
  .audio-player { flex-wrap: wrap; gap: 8px; padding: 10px; }
  .audio-player__center { order: 5; flex: 1 1 100%; }
  .audio-player__volume-bar { width: 50px; }
  .audio-player__skip-num   { font-size: .48rem; }
}

/* ── Profile page ────────────────────────────────────────── */
.profile-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  max-width: 820px;
}

.profile-avatar-row {
  display: flex;
  align-items: center;
  gap: 22px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.profile-avatar-preview {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.4rem;
  color: var(--muted-hi);
  flex-shrink: 0;
  overflow: hidden;
}
.profile-avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.profile-avatar-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.profile-meta {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: center;
  font-size: .8rem;
  color: var(--muted);
  padding-top: 4px;
}
.profile-meta i { margin-right: 6px; opacity: .7; }

/* ── Navbar avatar (used in nav-right + chat ident) ──────── */
.nav-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted-hi);
  font-size: .82rem;
  flex-shrink: 0;
  transition: border-color var(--trans);
}
.nav-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.nav-avatar:hover { border-color: var(--border-hi); color: var(--text-2); opacity: 1; }
.nav-avatar.active { border-color: rgba(124,133,245,.45); color: var(--primary-light); }

/* Chat message avatars: replace icon with image when present */
.message__avatar {
  overflow: hidden;
}
.message__avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* end */
