/* ============================================================
   Orion — Paper edition
   Warm light editorial. Serif prose, ink on paper, hairlines
   instead of boxes. One blue accent, used sparingly.
   ============================================================ */
:root {
  --paper: #faf7f0;
  --paper-2: #f1ece0;
  --paper-3: #e6ddc9;
  --lift: #fffdf8;
  --ink: #1c1813;
  --ink-2: #57503f;
  --ink-3: #8d8474;
  --hairline: rgba(28, 24, 19, .13);
  --accent: #2e3fb8;
  --accent-soft: rgba(46, 63, 184, .07);
  --danger: #a83226;
  --danger-soft: rgba(168, 50, 38, .07);
  --success: #2f7a4d;
  --success-soft: rgba(47, 122, 77, .09);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Inter", "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --ease: cubic-bezier(.2, .7, .3, 1);
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
}
::selection { background: rgba(46, 63, 184, .16); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--paper-3); border-radius: 8px; border: 3px solid var(--paper); }
::-webkit-scrollbar-track { background: transparent; }

#app { height: 100dvh; }
.view { height: 100%; }
.view[hidden] { display: none !important; }
#view-auth[hidden] { display: none !important; }

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.015em; }
p { margin: 0; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.mono { font-family: var(--mono) !important; font-size: .92em; }
a { color: var(--accent); }

/* ============================================================
   Logo — Orion's belt, in ink
   ============================================================ */
.orion-mark { display: flex; align-items: center; gap: 11px; }
.orion-mark svg { display: block; overflow: visible; }
.orion-mark svg circle {
  fill: var(--ink);
  transform-box: fill-box;
  transform-origin: center;
  animation: dot-drift 6s ease-in-out infinite alternate;
}
.orion-mark svg circle:nth-child(2) { fill: var(--accent); animation-delay: -2s; }
.orion-mark svg circle:nth-child(3) { animation-delay: -4s; }
@keyframes dot-drift {
  from { transform: translate(0, 0) scale(1); opacity: 1; }
  to   { transform: translate(1.8px, -1.8px) scale(.86); opacity: .78; }
}
.orion-mark.sm svg { width: 26px; height: 26px; }
.orion-mark.lg { justify-content: center; }
.orion-mark.lg svg { width: 44px; height: 44px; }
.orion-mark.xl svg { width: 64px; height: 64px; }
.wordmark { font-weight: 700; font-size: 17px; letter-spacing: -.02em; }
.wordmark.sm { font-size: 15px; }

/* ============================================================
   Starfield — a faint warm dot texture, one layer.
   Login screen and empty states only.
   ============================================================ */
.starfield { position: relative; isolation: isolate; }
.starfield::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image: radial-gradient(rgba(122, 104, 80, .5) 1px, transparent 1.6px);
  background-size: 30px 30px;
  -webkit-mask-image: radial-gradient(ellipse 95% 85% at 50% 42%, transparent 30%, black 100%);
  mask-image: radial-gradient(ellipse 95% 85% at 50% 42%, transparent 30%, black 100%);
  animation:
    star-drift 120s linear infinite,
    star-breathe 12s ease-in-out infinite alternate;
}
@keyframes star-drift { to { background-position: 60px 30px; } }
@keyframes star-breathe { from { opacity: .07; } to { opacity: .16; } }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 14px;
  border: 1px solid var(--hairline);
  background: transparent;
  color: var(--ink);
  border-radius: 99px;
  padding: 10px 22px;
  cursor: pointer;
  min-height: 44px;
  transition: background .12s, border-color .12s, transform .12s var(--ease);
}
.btn:hover { background: var(--paper-2); }
.btn:active { transform: scale(.98); }
.btn.primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}
.btn.primary:hover { background: #33302a; border-color: #33302a; }
.btn.primary:disabled { opacity: .35; cursor: default; transform: none; }
.btn.block { display: block; width: 100%; }
.btn.danger-ghost { color: var(--danger); border-color: transparent; }
.btn.danger-ghost:hover { background: var(--danger-soft); }
.btn.small { padding: 8px 16px; font-size: 13px; min-height: 40px; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { background: #8f2b20; border-color: #8f2b20; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  border: none; border-radius: 50%;
  background: transparent; color: var(--ink-2);
  font-size: 17px; cursor: pointer;
  transition: background .12s, color .12s, transform .12s var(--ease);
}
.icon-btn:hover { background: var(--paper-2); color: var(--ink); }
.icon-btn:active { transform: scale(.94); }

/* ============================================================
   Fields — editorial underline inputs
   ============================================================ */
.field { display: block; margin: 0 0 18px; }
.field > span {
  display: block;
  font-family: var(--sans);
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .09em;
  color: var(--ink-3); margin-bottom: 2px;
}
.field input,
.input, .field select, .field textarea {
  width: 100%;
  font-family: var(--serif);
  font-size: 17px;
  color: var(--ink);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--hairline);
  border-radius: 0;
  padding: 9px 2px;
  outline: none;
  transition: border-color .15s;
}
.field input:focus,
.input:focus, .field select:focus, .field textarea:focus { border-bottom-color: var(--ink); }
.field input::placeholder, .input::placeholder { color: var(--ink-3); font-style: italic; }
.field select option { background: var(--paper); }
textarea.input, .field textarea { resize: vertical; min-height: 84px; line-height: 1.55; }
.form-error {
  color: var(--danger); font-size: 14px; font-style: italic;
  background: var(--danger-soft);
  border-radius: var(--radius-sm);
  padding: 10px 14px; margin: 0 0 14px;
}
.form-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.saved-note { color: var(--success); font-size: 13px; font-weight: 600; font-family: var(--sans); }

/* Toggle switch */
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 20px; font-size: 15px; min-height: 44px; }
.toggle { position: relative; display: inline-block; width: 50px; height: 29px; cursor: pointer; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .knob {
  position: absolute; inset: 0; border-radius: 99px;
  background: var(--paper-3);
  transition: background .18s;
}
.toggle .knob::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 23px; height: 23px; border-radius: 50%;
  background: var(--lift);
  border: 1px solid var(--hairline);
  transition: transform .18s var(--ease), background .18s;
}
.toggle input:checked + .knob { background: var(--ink); }
.toggle input:checked + .knob::after { transform: translateX(21px); background: var(--paper); border-color: var(--ink); }

/* ============================================================
   Auth view
   ============================================================ */
#view-auth {
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  overflow-y: auto;
}
.auth-wrap {
  width: 100%; max-width: 380px;
  position: relative; z-index: 1;
  animation: rise .4s var(--ease);
  margin: auto 0;
}
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }
.auth-card { padding: 10px 6px; }
.auth-card .orion-mark.lg { flex-direction: column; gap: 14px; margin-bottom: 6px; }
.auth-card .wordmark { font-size: 26px; }
.auth-sub {
  text-align: center; color: var(--ink-2);
  font-size: 16px; font-style: italic;
  margin: 10px 0 28px;
}
.auth-tabs {
  display: flex; gap: 26px;
  border-bottom: 1px solid var(--hairline);
  margin-bottom: 28px;
}
.auth-tab {
  border: none; background: transparent;
  color: var(--ink-3);
  font-family: var(--sans); font-size: 14px; font-weight: 600;
  padding: 10px 2px; cursor: pointer;
  min-height: 44px;
  box-shadow: inset 0 -2px 0 transparent;
  transition: color .15s, box-shadow .15s;
}
.auth-tab:hover { color: var(--ink); }
.auth-tab.active { color: var(--ink); box-shadow: inset 0 -2px 0 var(--ink); }
#auth-form .btn { margin-top: 6px; }
#passkey-btn { margin-top: 10px; }
#passkey-btn[hidden] { display: none; }

/* ============================================================
   Chat view
   ============================================================ */
#view-chat { display: flex; }
#view-chat[hidden] { display: none !important; }

.conv-empty { color: var(--ink-3); font-size: 14px; font-style: italic; text-align: center; padding: 28px 12px; line-height: 1.7; }
.skel {
  height: 40px; border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--paper-2) 25%, var(--paper-3) 50%, var(--paper-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--ink);
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--serif); font-weight: 700; font-size: 14px; color: var(--paper); flex-shrink: 0;
}
/* ---------- Main column ---------- */
#chat-main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
#chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  border-bottom: 1px solid var(--hairline);
}
/* Account menu anchored in the header (the only chat chrome now). */
.head-user { position: relative; display: flex; }
.avatar-btn {
  background: transparent; border: none; padding: 4px; margin: -4px;
  border-radius: 50%; cursor: pointer; line-height: 0;
}
.avatar-btn .avatar { transition: transform .15s var(--ease); }
.avatar-btn:hover .avatar { transform: scale(1.06); }
.head-user .menu {
  top: calc(100% + 10px); bottom: auto; left: -4px; right: auto;
  min-width: 228px;
}
.head-spacer { width: 42px; } /* balances the avatar so the wordmark stays centered */
.messages {
  flex: 1; overflow-y: auto;
  padding: 34px 26px 18px;
  display: flex; flex-direction: column; gap: 28px;
  scroll-behavior: smooth;
  scrollbar-width: thin;
}
.msg { display: flex; animation: rise .25s var(--ease); max-width: 720px; width: 100%; margin: 0 auto; }
.msg.user { justify-content: flex-end; }
.msg .bubble {
  background: var(--ink);
  color: var(--paper);
  border-radius: 18px 18px 6px 18px;
  padding: 10px 17px;
  max-width: min(80%, 560px);
  font-size: 15.5px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}
.msg.assistant { gap: 0; }
.a-avatar { display: none; }
.a-body { flex: 1; min-width: 0; }
.a-body .content { font-size: 16.5px; line-height: 1.72; overflow-wrap: anywhere; }
.a-body .content > *:first-child { margin-top: 0; }
.a-body p { margin: 0 0 14px; }
.a-body p:last-child { margin-bottom: 0; }
.a-body a { color: var(--accent); }
.a-body code {
  font-family: var(--mono); font-size: 13.5px;
  background: var(--paper-2);
  border-radius: 6px; padding: 2px 7px;
}
.codeblock { margin: 14px 0; border-radius: var(--radius); overflow: hidden; background: var(--paper-2); border: 1px solid var(--hairline); }
.codeblock-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 14px;
  border-bottom: 1px solid var(--hairline);
  font-size: 12px; color: var(--ink-3); font-family: var(--mono);
}
.copybtn {
  border: 1px solid var(--hairline); background: transparent; color: var(--ink-2);
  font-family: var(--sans); font-size: 12px; font-weight: 600;
  border-radius: 99px; padding: 5px 14px; cursor: pointer;
  min-height: 32px;
}
.copybtn:hover { color: var(--ink); border-color: var(--ink-3); }
.codeblock pre { margin: 0; padding: 14px 16px; overflow-x: auto; }
.codeblock pre code { background: none; padding: 0; font-size: 13.5px; line-height: 1.65; }

/* streaming caret */
.caret::after {
  content: "▍"; color: var(--accent);
  animation: blink 1s steps(1) infinite;
  margin-left: 1px;
}
@keyframes blink { 50% { opacity: 0; } }

/* typing indicator — three dots while waiting for the first token */
.typing-dots { display: inline-flex; align-items: center; gap: 7px; padding: 12px 4px; }
.typing-dots span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ink-2);
  animation: typing-bounce 1.25s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .16s; }
.typing-dots span:nth-child(3) { animation-delay: .32s; }
@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .45; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* tool rows — whisper-quiet collapsible rows */
.tool-row {
  margin: 0 0 10px;
  font-family: var(--sans);
  font-size: 13px;
  border-radius: var(--radius-sm);
}
.tool-row.open { background: var(--paper-2); }
.tool-head {
  display: flex; align-items: center; gap: 9px; width: 100%;
  background: transparent; border: none; color: var(--ink-2);
  font: inherit; padding: 7px 4px; cursor: pointer; text-align: left;
  min-height: 40px; border-radius: var(--radius-sm);
}
.tool-head:hover { color: var(--ink); }
.tool-head .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex-shrink: 0; }
.tool-head .dot.running { animation: blink 1s steps(1) infinite; }
.tool-head .dot.done { background: var(--success); animation: none; }
.tool-head .tname { font-family: var(--mono); font-size: 12.5px; }
.tool-head .tsummary { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink-3); }
.tool-head .tchev { font-size: 10px; color: var(--ink-3); transition: transform .15s; }
.tool-row.open .tool-head .tchev { transform: rotate(180deg); }
.tool-detail {
  display: none; padding: 2px 8px 10px 23px;
  color: var(--ink-3); font-size: 12.5px; font-family: var(--mono);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.tool-row.open .tool-detail { display: block; }

/* images in chat */
.msg-img {
  max-width: 320px; border-radius: var(--radius);
  border: 1px solid var(--hairline);
  cursor: zoom-in; margin-top: 10px; display: block;
  transition: transform .15s var(--ease);
}
.msg-img:hover { transform: scale(1.015); }
.msg-error {
  color: var(--danger); font-size: 14.5px; font-style: italic;
  background: var(--danger-soft);
  border-radius: var(--radius-sm); padding: 12px 16px;
}

/* ---------- Empty state ---------- */
.empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; padding: 28px 22px; gap: 10px;
  animation: rise .4s var(--ease);
  overflow-y: auto;
}
.empty-state[hidden] { display: none !important; }
.empty-state > * { position: relative; z-index: 1; }
.empty-state h1 { font-size: 32px; margin: 18px 0 4px; letter-spacing: -.02em; font-weight: 600; }
.empty-state .muted { font-size: 16px; font-style: italic; line-height: 1.65; max-width: 400px; }

/* ---------- Composer ---------- */
.composer-wrap { padding: 10px 26px calc(16px + env(safe-area-inset-bottom)); max-width: 800px; width: 100%; margin: 0 auto; }
.composer {
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--lift);
  border: 1px solid var(--hairline);
  border-radius: 18px;
  padding: 8px 8px 8px 20px;
  transition: border-color .15s, background .15s;
}
.composer:focus-within { border-color: var(--ink-2); }
.composer textarea {
  flex: 1; border: none; background: transparent; resize: none;
  color: var(--ink); font-family: var(--serif); font-size: 16.5px; line-height: 1.5;
  max-height: 180px; outline: none; padding: 8px 0;
}
.composer textarea::placeholder { color: var(--ink-3); font-style: italic; }
.send-btn, .stop-btn {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform .12s var(--ease), opacity .12s, background .12s;
}
.send-btn[hidden], .stop-btn[hidden] { display: none !important; }
.send-btn { background: var(--ink); color: var(--paper); }
.send-btn:hover:not(:disabled) { transform: scale(1.07); background: #33302a; }
.send-btn:active:not(:disabled) { transform: scale(.96); }
.send-btn:disabled { opacity: .25; cursor: default; }
.stop-btn { background: var(--danger-soft); color: var(--danger); }
.stop-btn:hover { background: rgba(168, 50, 38, .14); }
.composer-hint { text-align: center; color: var(--ink-3); font-size: 11.5px; font-family: var(--sans); margin-top: 9px; }

/* ============================================================
   Admin + Settings views
   ============================================================ */
#view-admin, #view-settings { overflow-y: auto; }
.admin-wrap { max-width: 720px; margin: 0 auto; padding: 44px 26px 80px; animation: rise .3s var(--ease); }
.admin-head { margin-bottom: 30px; }
.back-link { color: var(--ink-2); text-decoration: none; font-size: 14px; font-family: var(--sans); font-weight: 600; display: inline-flex; align-items: center; min-height: 44px; }
.back-link:hover { color: var(--ink); }
.admin-head h1 { font-size: 32px; margin-top: 8px; letter-spacing: -.02em; font-weight: 600; }
.card {
  background: transparent;
  border-radius: 0;
  padding: 28px 0 0;
  margin-bottom: 44px;
  border-top: 1px solid var(--hairline);
}
.admin-head + .card, .card:first-of-type { border-top: none; padding-top: 0; }
.card h2 { font-size: 21px; margin-bottom: 6px; }
.card > .muted { margin-bottom: 24px; font-size: 14.5px; font-style: italic; }
.danger-zone h2 { color: var(--danger); }
.danger-zone .muted { margin-bottom: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }

.table-wrap { overflow-x: auto; margin: 0 -6px; padding: 0 6px; }
.users-table { width: 100%; border-collapse: collapse; font-size: 14px; font-family: var(--sans); }
.users-table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--ink-3); font-weight: 700; padding: 10px;
  border-bottom: 1px solid var(--hairline);
}
.users-table td { padding: 13px 10px; border-top: 1px solid var(--hairline); vertical-align: middle; }
.users-table tbody tr:first-child td { border-top: none; }
.u-name { font-weight: 600; display: flex; align-items: center; gap: 10px; font-family: var(--serif); font-size: 15px; }
.u-name .avatar { width: 28px; height: 28px; font-size: 12px; }
.u-disabled { color: var(--ink-3); }
.pill {
  font-family: var(--sans);
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  border: 1px solid var(--hairline);
  border-radius: 99px; padding: 4px 11px; white-space: nowrap;
  color: var(--ink-2);
}
.pill.admin { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.pill.user { background: transparent; }
.pill.off, .pill.danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.u-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.link-btn {
  background: transparent;
  border: 1px solid var(--hairline);
  color: var(--ink-2);
  font-family: var(--sans); font-size: 12.5px; font-weight: 600;
  border-radius: 99px; padding: 8px 15px; cursor: pointer; white-space: nowrap;
  min-height: 36px;
  transition: color .12s, border-color .12s, background .12s;
}
.link-btn:hover { color: var(--ink); border-color: var(--ink-3); background: var(--paper-2); }
.link-btn.danger { color: var(--danger); }
.link-btn.danger:hover { background: var(--danger-soft); border-color: transparent; }
.link-btn:disabled { opacity: .35; cursor: default; }
.th-actions { text-align: right; }

/* ============================================================
   Modals, toasts, lightbox
   ============================================================ */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(28, 24, 19, .45);
  display: flex; align-items: center; justify-content: center;
  padding: 22px;
  animation: fade .16s var(--ease);
}
@keyframes fade { from { opacity: 0; } }
.modal {
  width: 100%; max-width: 400px;
  background: var(--lift);
  border: 1px solid var(--hairline);
  border-radius: 16px; padding: 30px 28px;
  animation: pop .2s var(--ease);
  max-height: calc(100dvh - 60px);
  overflow-y: auto;
}
.modal h3 { font-size: 20px; margin-bottom: 8px; }
.modal .muted { font-size: 14.5px; font-style: italic; margin-bottom: 20px; line-height: 1.6; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; flex-wrap: wrap; }

#toasts {
  position: fixed; bottom: calc(22px + env(safe-area-inset-bottom)); left: 50%;
  transform: translateX(-50%); z-index: 200;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; width: max-content; max-width: 92vw;
}
.toast {
  background: var(--ink);
  color: var(--paper);
  font-family: var(--sans); font-size: 14px; font-weight: 500;
  border-radius: 99px; padding: 11px 22px;
  animation: toast-in .28s var(--ease);
  max-width: 92vw;
}
.toast.error { background: var(--danger); }
.toast.out { opacity: 0; transform: translateY(8px); transition: all .25s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(.97); } }

#lightbox {
  position: fixed; inset: 0; z-index: 150;
  background: rgba(28, 24, 19, .94);
  display: flex; align-items: center; justify-content: center;
  animation: fade .16s var(--ease);
}
#lightbox[hidden] { display: none !important; }
#lightbox img { max-width: 94vw; max-height: 92vh; border-radius: 12px; }
#lightbox-close {
  position: absolute; top: calc(16px + env(safe-area-inset-top)); right: 16px;
  background: rgba(250, 247, 240, .14); color: var(--paper); width: 44px; height: 44px;
}
#lightbox-close:hover { background: rgba(250, 247, 240, .24); color: var(--paper); }

/* ============================================================
   Settings
   ============================================================ */
.settings-tabs { display: flex; gap: 24px; margin-bottom: 26px; border-bottom: 1px solid var(--hairline); flex-wrap: wrap; }
.settings-tab {
  padding: 10px 2px; border: none;
  background: transparent; color: var(--ink-3);
  font-family: var(--sans); font-size: 13.5px; font-weight: 600; cursor: pointer; min-height: 44px;
  box-shadow: inset 0 -2px 0 transparent;
  transition: color .15s, box-shadow .15s; white-space: nowrap;
}
.settings-tab:hover { color: var(--ink); }
.settings-tab.active { color: var(--ink); box-shadow: inset 0 -2px 0 var(--ink); }
.settings-panel { display: flex; flex-direction: column; gap: 12px; }
.settings-panel[hidden] { display: none; }
.set-h {
  font-family: var(--sans); font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .09em;
  color: var(--ink-2); margin: 16px 0 2px;
}
.set-h:first-child { margin-top: 0; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  font-family: var(--sans); font-size: 13.5px; font-weight: 500; color: var(--ink);
  background: transparent;
  border: 1px solid var(--hairline);
  border-radius: 99px; padding: 11px 20px; cursor: pointer;
  min-height: 44px;
  transition: border-color .15s, background .15s;
}
.chip:hover { border-color: var(--ink-3); background: var(--paper-2); }
.chip.sm { padding: 8px 15px; font-size: 12.5px; min-height: 40px; }
.chip.sm.active { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.status-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.badge {
  display: inline-block; padding: 4px 12px; border-radius: 999px;
  font-family: var(--sans); font-size: 12px; font-weight: 600;
  border: 1px solid var(--hairline); color: var(--ink-2);
}
.badge.ok { background: var(--success-soft); border-color: transparent; color: var(--success); }
.secret-row { display: flex; gap: 8px; align-items: center; margin: 10px 0; flex-wrap: wrap; }
.secret {
  display: inline-block; padding: 10px 14px;
  background: var(--paper-2);
  border: 1px dashed var(--ink-3);
  border-radius: var(--radius-sm);
  font-size: 14px; letter-spacing: 1px; word-break: break-all; font-family: var(--mono);
}
.row-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row-item { display: flex; align-items: center; gap: 12px; padding: 14px 2px; border-top: 1px solid var(--hairline); }
.row-item:first-child { border-top: none; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.row-title { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.row-sub { font-size: 13px; font-family: var(--sans); color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-row.disabled .row-title { opacity: .45; }
.radio-row { display: flex; gap: 8px 18px; flex-wrap: wrap; }
.radio-row label, .check-row label, .cron-presets label { display: flex; align-items: center; gap: 9px; font-size: 15px; cursor: pointer; min-height: 44px; }
.cron-presets { display: flex; flex-direction: column; gap: 4px; }
.cron-custom { display: flex; align-items: center; gap: 8px; }
.cron-custom input { flex: 1; }
.check-row { display: flex; align-items: center; gap: 9px; font-size: 15px; min-height: 44px; cursor: pointer; }
input[type="checkbox"], input[type="radio"] { width: 19px; height: 19px; accent-color: var(--accent); flex-shrink: 0; cursor: pointer; }
.backup-codes { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
#backup-codes-wrap .secret { font-size: 13px; }
.modal-form { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }

/* conversation rename */
.conv-rename {
  flex: 1; min-width: 0;
  background: transparent;
  border: none; border-bottom: 1px solid var(--ink);
  border-radius: 0;
  color: var(--ink); font-size: 14.5px; padding: 8px 2px; font-family: var(--serif);
  outline: none; min-height: 38px;
}

/* ============================================================
   Responsive — mobile-first refinements
   ============================================================ */
.only-mobile { display: none !important; }

@media (max-width: 760px) {
  .only-mobile { display: inline-flex !important; }
  #chat-header { display: flex; }
  #chat-header .icon-btn { width: 44px; height: 44px; }
  #chat-header .wordmark { font-size: 16px; }

  .messages { padding: 22px 16px 14px; gap: 24px; }
  .msg .bubble { max-width: 88%; font-size: 15px; }
  .a-body .content { font-size: 16px; }

  .composer-wrap { padding: 8px 14px calc(10px + env(safe-area-inset-bottom)); }
  .composer { border-radius: 20px; }
  .composer-hint { display: none; }

  .grid2 { grid-template-columns: 1fr; }
  .admin-wrap { padding: 28px 18px 64px; }
  .admin-head h1 { font-size: 28px; }

  .auth-card { padding: 6px 2px; }
  .empty-state h1 { font-size: 26px; }
  .empty-state .muted { font-size: 15px; }

  .settings-tab { font-size: 12.5px; }
  .row-item { flex-wrap: wrap; }
  .row-main { flex: 1 1 100%; }
  .task-row .btn { flex: 1 1 40%; }
  .menu button { padding: 13px 12px; }

  .u-actions .link-btn { min-height: 44px; padding: 10px 16px; }
  .modal { padding: 26px 22px; }
  .modal-actions .btn { flex: 1; }
}

/* Larger phones / small tablets */
@media (min-width: 761px) {
  .messages { padding-left: max(26px, calc((100% - 800px) / 2)); padding-right: max(26px, calc((100% - 800px) / 2)); }
}

/* Motion preferences — calm mode */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .starfield::before { display: none; }
  .orion-mark svg circle { animation: none; }
}

/* ============================================================
   Dark mode — warm ink. All components read from the tokens
   above, so this is just a palette swap plus a few
   hardcoded overlays.
   ============================================================ */
:root { color-scheme: light; }
[data-theme="dark"] {
  color-scheme: dark;
  --paper: #171310;
  --paper-2: #221c15;
  --paper-3: #322a1f;
  --lift: #1e1a14;
  --ink: #ece4d3;
  --ink-2: #b0a48c;
  --ink-3: #776d5b;
  --hairline: rgba(236, 228, 211, .14);
  --accent: #8b9bff;
  --accent-soft: rgba(139, 155, 255, .1);
  --danger: #d9705f;
  --danger-soft: rgba(217, 112, 95, .12);
  --success: #63bd82;
  --success-soft: rgba(99, 189, 130, .12);
}
[data-theme="dark"] ::selection { background: rgba(139, 155, 255, .28); }
[data-theme="dark"] .starfield::before {
  background-image: radial-gradient(rgba(210, 190, 150, .5) 1px, transparent 1.6px);
}
[data-theme="dark"] .btn.primary:hover { background: #d8cdb4; border-color: #d8cdb4; }
[data-theme="dark"] .send-btn:hover:not(:disabled) { background: #d8cdb4; }
[data-theme="dark"] .modal-backdrop { background: rgba(0, 0, 0, .6); }
[data-theme="dark"] #lightbox { background: rgba(8, 6, 4, .96); }
