/* Jyotishi — warm, quiet reading UI. No build step. */

:root {
  --bg: #f7f4ee;
  --bg-elev: #fffdf9;
  --sidebar: #efebe2;
  --surface: #ece7dc;
  --surface-2: #e4ded1;
  --border: #ddd5c6;
  --border-strong: #c9bfac;
  --text: #2a2622;
  --text-2: #4a443c;
  --muted: #776f63;
  --accent: #b65a26;
  --accent-strong: #97461a;
  --accent-soft: #f3e3d4;
  --on-accent: #fffaf4;
  --ok: #3f7a4a;
  --ok-soft: #e3efe2;
  --warn: #9a6a12;
  --warn-soft: #f6ebcf;
  --err: #b0392f;
  --err-soft: #f6dfdb;
  --user-bubble: #ebe5d9;
  --code-bg: #efe9de;
  --shadow: 0 1px 2px rgba(60, 45, 25, .06), 0 6px 24px rgba(60, 45, 25, .07);
  --shadow-lg: 0 10px 40px rgba(40, 28, 12, .18);
  --chart-line: #8b7f6d;
  --chart-fill: #fbf8f2;
  --chart-lagna: #f6e6d6;

  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-read: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", "URW Palladio L", Georgia, serif;
  --font-mono: ui-monospace, "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;

  --sidebar-w: 272px;
  --panel-w: 440px;
  --column: 760px;
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1d1b18; --bg-elev: #262320; --sidebar: #171512; --surface: #2b2824; --surface-2: #34302b;
    --border: #3a352f; --border-strong: #4d463d; --text: #ece6db; --text-2: #d3ccbf; --muted: #a39a8b;
    --accent: #e08850; --accent-strong: #f0a070; --accent-soft: #3d2c20; --on-accent: #1d1b18;
    --ok: #86c08f; --ok-soft: #22352a; --warn: #e2b55a; --warn-soft: #3a3020; --err: #ee8a7f; --err-soft: #3d2522;
    --user-bubble: #2f2b26; --code-bg: #2a2622;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 24px rgba(0,0,0,.25); --shadow-lg: 0 10px 40px rgba(0,0,0,.5);
    --chart-line: #8d8272; --chart-fill: #24211d; --chart-lagna: #3a2c21;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1d1b18; --bg-elev: #262320; --sidebar: #171512; --surface: #2b2824; --surface-2: #34302b;
  --border: #3a352f; --border-strong: #4d463d; --text: #ece6db; --text-2: #d3ccbf; --muted: #a39a8b;
  --accent: #e08850; --accent-strong: #f0a070; --accent-soft: #3d2c20; --on-accent: #1d1b18;
  --ok: #86c08f; --ok-soft: #22352a; --warn: #e2b55a; --warn-soft: #3a3020; --err: #ee8a7f; --err-soft: #3d2522;
  --user-bubble: #2f2b26; --code-bg: #2a2622;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 24px rgba(0,0,0,.25); --shadow-lg: 0 10px 40px rgba(0,0,0,.5);
  --chart-line: #8d8272; --chart-fill: #24211d; --chart-lagna: #3a2c21;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { flex-shrink: 0; }
.icon-btn svg, .new-chat svg, .ghost-btn svg, .chip-btn svg, .send-btn svg, .msg-actions svg, .conv-item svg {
  width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
}
.send-btn svg .fill { fill: currentColor; stroke: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: -999px; top: 8px; z-index: 100; background: var(--bg-elev); padding: 8px 12px; border-radius: 8px; }
.skip-link:focus { left: 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; font-weight: 400; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------------ layout */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) 0;
  height: 100vh; height: 100dvh;
  transition: grid-template-columns .22s ease;
}
.app[data-sidebar="collapsed"] { grid-template-columns: 0 minmax(0, 1fr) 0; }
.app[data-panel="open"] { grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--panel-w); }
.app[data-sidebar="collapsed"][data-panel="open"] { grid-template-columns: 0 minmax(0, 1fr) var(--panel-w); }

/* ------------------------------------------------------------------ sidebar */
.sidebar { grid-column: 1; grid-row: 1; }
.main { grid-column: 2; grid-row: 1; }
.panel { grid-column: 3; grid-row: 1; }
.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  min-width: 0; overflow: hidden;
  padding: 10px 10px 8px;
}
.app[data-sidebar="collapsed"] .sidebar { border-right: 0; padding: 0; }
.sidebar > * { min-width: calc(var(--sidebar-w) - 20px); }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 10px; }
.brand { display: flex; align-items: center; gap: 9px; color: var(--text); text-decoration: none; font-family: var(--font-read); font-size: 20px; letter-spacing: .2px; }
.brand .mark { width: 26px; height: 26px; color: var(--text-2); }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px; border-radius: 9px;
  border: 0; background: transparent; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.new-chat {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px; margin: 0 2px 12px;
  border-radius: 11px; border: 1px solid var(--border-strong);
  background: var(--bg-elev); color: var(--text); font-weight: 550;
  box-shadow: 0 1px 1px rgba(0,0,0,.03);
}
.new-chat:hover { border-color: var(--accent); }
.new-chat svg { color: var(--accent); }

.eyebrow { display: block; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; margin-bottom: 5px; }
.profile-switcher { padding: 0 4px 12px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.profile-row { display: flex; gap: 4px; align-items: center; }
.profile-row select {
  flex: 1; min-width: 0; padding: 7px 10px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--bg-elev);
}

.conv-list { flex: 1; overflow-y: auto; padding: 2px 0 12px; scrollbar-width: thin; }
.conv-group { margin-top: 10px; }
.conv-group h3 { font-size: 11.5px; font-weight: 600; color: var(--muted); margin: 6px 10px 4px; }
.conv-item {
  position: relative; display: flex; align-items: center;
  border-radius: 9px; margin: 1px 0;
}
.conv-item > a {
  flex: 1; min-width: 0; padding: 7px 10px; color: var(--text-2); text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; border-radius: 9px;
}
.conv-item:hover, .conv-item:focus-within { background: var(--surface-2); }
.conv-item.active { background: var(--surface-2); }
.conv-item.active > a { color: var(--text); font-weight: 550; }
.conv-item .conv-actions { display: none; padding-right: 3px; }
.conv-item:hover .conv-actions, .conv-item:focus-within .conv-actions, .conv-item.active .conv-actions { display: flex; }
.conv-actions .icon-btn { width: 28px; height: 28px; }
.conv-actions .icon-btn svg { width: 15px; height: 15px; }
.conv-item input {
  flex: 1; min-width: 0; margin: 2px; padding: 5px 8px; border-radius: 7px;
  border: 1px solid var(--accent); background: var(--bg-elev); font-size: 14px;
}
.conv-empty { color: var(--muted); font-size: 13px; padding: 10px; }

.sidebar-foot { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 8px 2px 0; border-top: 1px solid var(--border); }
.ghost-btn { display: inline-flex; align-items: center; gap: 7px; border: 0; background: none; color: var(--muted); padding: 6px 8px; border-radius: 8px; font-size: 13px; }
.ghost-btn:hover { background: var(--surface-2); color: var(--text); }
.local-note { font-size: 11.5px; color: var(--muted); padding-right: 6px; }
.scrim { display: none; }

/* ------------------------------------------------------------------ main */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.topbar {
  display: flex; align-items: center; gap: 8px;
  height: 52px; padding: 0 12px; flex-shrink: 0;
}
#sidebar-open { display: none; }
.app[data-sidebar="collapsed"] #sidebar-open { display: inline-grid; }
.conv-title {
  flex: 1; min-width: 0; margin: 0; font-size: 15px; font-weight: 550; color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center;
}
.chip-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 11px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg-elev); color: var(--text-2); font-size: 13.5px;
}
.chip-btn:hover { border-color: var(--border-strong); color: var(--text); }
.chip-btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-strong); }

.thread { flex: 1; overflow-y: auto; min-height: 0; scroll-behavior: auto; }
.column { max-width: var(--column); margin: 0 auto; padding: 8px 24px 40px; }

/* empty state */
.empty { padding: 12vh 0 20px; text-align: center; animation: fadeUp .35s ease both; }
.empty-mark { width: 40px; height: 40px; margin-bottom: 10px; }
.greeting { font-family: var(--font-read); font-weight: 400; font-size: clamp(28px, 4.2vw, 38px); margin: 0 0 6px; letter-spacing: -.2px; }
.empty-sub { color: var(--muted); margin: 0 0 30px; }
.suggestions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; max-width: 620px; margin: 0 auto; text-align: left; }
.suggestion {
  border: 1px solid var(--border); background: var(--bg-elev); border-radius: 12px;
  padding: 12px 14px; color: var(--text-2); font-size: 14px; line-height: 1.4;
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.suggestion:hover { border-color: var(--border-strong); box-shadow: var(--shadow); transform: translateY(-1px); color: var(--text); }
.suggestion .s-kicker { display: block; font-size: 11.5px; color: var(--accent); font-weight: 600; margin-bottom: 3px; letter-spacing: .02em; }
.empty .btn.primary { margin-top: 6px; }

/* messages */
.messages { display: flex; flex-direction: column; gap: 22px; padding-top: 12px; }
.msg { animation: fadeUp .25s ease both; }
.msg.user { align-self: flex-end; max-width: 85%; display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .bubble {
  background: var(--user-bubble); border-radius: 18px 18px 6px 18px;
  padding: 10px 15px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px;
}
.user-actions {
  display: flex; gap: 2px; margin-top: 3px; opacity: 0; transition: opacity .15s;
}
.msg.user:hover .user-actions, .user-actions:focus-within, .msg.user:last-of-type .user-actions { opacity: 1; }
.user-actions .icon-btn { width: 28px; height: 28px; }
.user-actions .icon-btn svg { width: 14px; height: 14px; }
.user-edit-box {
  width: min(560px, 82vw); background: var(--bg-elev); border: 1px solid var(--accent);
  border-radius: 14px; padding: 10px 12px; box-shadow: var(--shadow);
}
.user-edit-input {
  width: 100%; border: 0; outline: 0; resize: vertical; background: transparent;
  font: 15px/1.5 var(--font-ui); color: var(--text); min-height: 54px;
}
.user-edit-actions {
  display: flex; align-items: center; justify-content: flex-end; gap: 6px; margin-top: 8px;
  padding-top: 6px; border-top: 1px solid var(--border);
}
.user-edit-hint { font-size: 12px; color: var(--muted); margin-right: auto; }
.msg.assistant { position: relative; }
.answer {
  font-family: var(--font-read); font-size: 17px; line-height: 1.72; color: var(--text);
  overflow-wrap: anywhere; transition: opacity .18s ease;
}
.answer.replacing { opacity: 0; }
.answer.replaced { animation: softFlash 1.2s ease; }
.answer > :first-child { margin-top: 0; }
.answer > :last-child { margin-bottom: 0; }
.answer p { margin: 0 0 .9em; }
.answer h1, .answer h2, .answer h3, .answer h4 { font-family: var(--font-read); font-weight: 600; line-height: 1.3; margin: 1.3em 0 .5em; }
.answer h1 { font-size: 1.4em; } .answer h2 { font-size: 1.25em; } .answer h3 { font-size: 1.1em; } .answer h4 { font-size: 1em; }
.answer ul, .answer ol { padding-left: 1.4em; margin: 0 0 .9em; }
.answer li { margin: .25em 0; }
.answer li::marker { color: var(--muted); }
.answer strong { font-weight: 650; }
.answer a { color: var(--accent-strong); text-underline-offset: 2px; }
.answer blockquote { margin: 0 0 .9em; padding: .1em 1em; border-left: 3px solid var(--border-strong); color: var(--text-2); font-style: italic; }
.answer code { font-family: var(--font-mono); font-size: .82em; background: var(--code-bg); padding: .12em .35em; border-radius: 5px; }
.answer pre { background: var(--code-bg); padding: 12px 14px; border-radius: 10px; overflow-x: auto; font-size: 14px; line-height: 1.5; }
.answer pre code { background: none; padding: 0; }
.answer hr { border: 0; border-top: 1px solid var(--border); margin: 1.4em 0; }
.answer table { border-collapse: collapse; margin: 0 0 1em; font-family: var(--font-ui); font-size: 14px; display: block; overflow-x: auto; max-width: 100%; }
.answer th, .answer td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; }
.answer th { background: var(--surface); font-weight: 600; }

.cursor {
  display: inline-block; width: .5em; height: 1.05em; margin-left: 2px; vertical-align: -0.15em;
  background: var(--accent); border-radius: 2px; animation: blink 1.05s steps(1) infinite; opacity: .8;
}
.thinking { display: inline-flex; gap: 5px; align-items: center; height: 28px; }
.thinking span { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); opacity: .35; animation: pulse 1.2s ease-in-out infinite; }
.thinking span:nth-child(2) { animation-delay: .15s; } .thinking span:nth-child(3) { animation-delay: .3s; }

/* steps (tool use) */
.steps {
  margin: 0 0 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-elev);
  font-size: 13.5px; max-width: 100%; display: inline-block; min-width: min(360px, 100%);
}
.steps[open] { display: block; }
.steps > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px;
  padding: 7px 12px; color: var(--text-2); user-select: none; border-radius: 12px;
}
.steps > summary::-webkit-details-marker { display: none; }
.steps > summary:hover { color: var(--text); }
.steps > summary .chev { margin-left: auto; transition: transform .15s; width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; }
.steps[open] > summary .chev { transform: rotate(180deg); }
.steps .summary-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.steps ol { list-style: none; margin: 0; padding: 4px 12px 10px; border-top: 1px solid var(--border); }
.step { display: grid; grid-template-columns: 18px minmax(0, 1fr); gap: 8px; padding: 6px 0; align-items: start; }
.step + .step { border-top: 1px dashed var(--border); }
.step .s-label { color: var(--text-2); }
.step .s-tool { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); margin-left: 6px; }
.step .s-detail { grid-column: 2; color: var(--muted); font-size: 12.5px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 9em; overflow: auto; }
.status-icon { width: 16px; height: 16px; display: inline-grid; place-items: center; margin-top: 2px; }
.status-icon svg { width: 16px; height: 16px; fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.status-icon.done svg { stroke: var(--ok); }
.status-icon.error svg { stroke: var(--err); }
.spinner { width: 13px; height: 13px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--accent); animation: spin .8s linear infinite; }

/* verification badge + actions */
.msg-foot { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 12px; min-height: 30px; }
.badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px;
  padding: 3px 10px 3px 8px; border-radius: 999px; border: 1px solid transparent; font-family: var(--font-ui);
}
.badge svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.badge.checking { color: var(--muted); border-color: var(--border); }
.badge.verified { color: var(--ok); background: var(--ok-soft); }
.badge.corrected { color: var(--warn); background: var(--warn-soft); }
.badge.skipped { color: var(--muted); border-color: var(--border); }
details.badge-wrap { display: inline-block; }
details.badge-wrap > summary { list-style: none; cursor: pointer; }
details.badge-wrap > summary::-webkit-details-marker { display: none; }
.issues { margin: 6px 0 0; padding: 8px 12px 8px 26px; background: var(--warn-soft); border-radius: 10px; font-size: 13px; color: var(--text-2); }
.msg-actions { display: flex; gap: 2px; margin-left: auto; opacity: .0; transition: opacity .15s; }
.msg.assistant:hover .msg-actions, .msg-actions:focus-within, .msg.assistant:last-child .msg-actions { opacity: 1; }
.msg-actions .icon-btn { width: 30px; height: 30px; }
.msg-error {
  margin-top: 6px; color: var(--err); background: var(--err-soft);
  border: 1px solid rgba(185, 56, 41, .22); padding: 10px 14px; border-radius: 12px;
  font-size: 13.5px; font-family: var(--font-ui);
}
.msg-error-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.msg-error-icon { width: 18px; height: 18px; display: inline-grid; place-items: center; flex-shrink: 0; }
.msg-error-icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.msg-error-copy { flex: 1; min-width: 180px; display: flex; flex-direction: column; gap: 2px; }
.msg-error-title { font-weight: 600; font-size: 14px; color: var(--err); }
.msg-error-hint { font-size: 12.5px; color: var(--text-2); }
.msg-error-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.msg-error-details { margin-top: 8px; padding-top: 6px; border-top: 1px dashed rgba(185, 56, 41, .25); font-size: 12px; color: var(--text-2); }
.msg-error-details summary { cursor: pointer; user-select: none; color: var(--muted); font-weight: 550; }
.msg-error-details pre {
  margin: 6px 0 0; padding: 8px 10px; border-radius: 8px; background: var(--bg);
  color: var(--text-2); font: 11.5px/1.45 var(--font-mono); white-space: pre-wrap; overflow-wrap: anywhere;
  max-height: 140px; overflow-y: auto;
}
.msg-stopped {
  margin-top: 8px; color: var(--muted); font-size: 13px; font-family: var(--font-ui);
  display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.btn.sm {
  padding: 5px 10px; border-radius: 8px; font-size: 12.5px;
  display: inline-flex; align-items: center; gap: 5px;
}
.btn.sm svg { width: 13.5px; height: 13.5px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* composer */
.composer-wrap { padding: 0 24px 10px; flex-shrink: 0; background: linear-gradient(to bottom, transparent, var(--bg) 22px); }
.composer {
  max-width: var(--column); margin: 0 auto; position: relative;
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--bg-elev); border: 1px solid var(--border-strong); border-radius: 22px;
  padding: 10px 10px 10px 18px; box-shadow: var(--shadow);
  transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within { border-color: var(--accent); box-shadow: var(--shadow), 0 0 0 3px var(--accent-soft); }
.composer textarea {
  flex: 1; border: 0; outline: 0; resize: none; background: transparent;
  font-size: 16px; line-height: 1.5; max-height: 40vh; min-height: 26px; padding: 4px 0;
}
.composer textarea:disabled { color: var(--muted); }
.composer textarea::placeholder { color: var(--muted); }
.composer-actions { display: flex; align-items: center; gap: 6px; }
.lang-controls { display: flex; align-items: center; gap: 6px; }
.lang-field {
  display: inline-flex; align-items: center; height: 32px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  font: 550 12px/1 var(--font-ui); cursor: pointer; overflow: hidden;
}
.lang-field:hover { border-color: var(--border-strong); color: var(--text); }
.lang-field:focus-within { border-color: var(--accent); }
.lang-tag {
  padding: 0 4px 0 9px; font: 600 10.5px/1 var(--font-ui); letter-spacing: .04em;
  text-transform: uppercase; color: var(--text-3, var(--text-2)); opacity: .8;
}
.lang-select {
  height: 100%; padding: 0 6px 0 2px; border: 0; background: transparent; color: inherit;
  font: inherit; cursor: pointer; outline: none;
}
.lang-select.is-set { color: var(--accent-strong); font-weight: 650; }
@media (max-width: 560px) {
  /* Phone: text on its own row, language pickers left and mic/send right on the row below. */
  .composer { flex-wrap: wrap; padding: 10px 10px 8px 14px; }
  .composer textarea { flex: 1 1 100%; min-width: 0; }
  .composer-actions { flex: 1 1 100%; }
  .lang-controls { margin-right: auto; }
}
.mic-btn {
  width: 36px; height: 36px; border-radius: 12px;
  color: var(--text-2); background: var(--surface); border: 1px solid transparent;
  transition: background .15s, color .15s, border-color .15s, transform .12s;
}
.mic-btn:hover { color: var(--text); border-color: var(--border-strong); }
.mic-btn.recording {
  background: var(--err-soft); color: var(--err); border-color: rgba(185, 56, 41, .35);
  animation: mic-pulse 1.4s ease-in-out infinite;
}
.mic-btn.transcribing { opacity: .65; pointer-events: none; }
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(185, 56, 41, .28); }
  50% { box-shadow: 0 0 0 5px rgba(185, 56, 41, 0); }
}
.voice-flow-bar {
  max-width: var(--column); margin: 0 auto 8px;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px; border-radius: 16px;
  background: var(--bg-elev); border: 1px solid var(--accent);
  box-shadow: var(--shadow); font-size: 13px; color: var(--text);
}
.voice-flow-bar[hidden] { display: none; }
.voice-dot {
  width: 9px; height: 9px; border-radius: 50%; background: var(--err); flex-shrink: 0;
  animation: voice-blink 1.1s ease-in-out infinite;
}
@keyframes voice-blink { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }
.voice-bars {
  display: inline-flex; align-items: center; gap: 2.5px; height: 18px;
}
.voice-bars span {
  display: block; width: 3px; height: 4px; border-radius: 2px;
  background: var(--accent-strong); transition: height 80ms ease;
}
.voice-status { flex: 1; font-weight: 550; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.voice-timer { font-variant-numeric: tabular-nums; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.send-btn {
  width: 36px; height: 36px; border-radius: 12px; border: 0;
  background: var(--accent); color: var(--on-accent); display: inline-grid; place-items: center;
  transition: background .15s, opacity .15s;
}
.send-btn svg { stroke-width: 2.2; }
.send-btn:hover { background: var(--accent-strong); }
.send-btn:disabled { opacity: .35; cursor: default; background: var(--accent); }
.send-btn.stop { background: var(--text); color: var(--bg); }
.disclaimer { text-align: center; font-size: 12px; color: var(--muted); margin: 8px 0 0; }

/* ------------------------------------------------------------------ chart panel */
.panel {
  background: var(--bg-elev); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden;
}
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; padding: 14px 14px 8px 18px; border-bottom: 1px solid var(--border); }
.panel-title { font-family: var(--font-read); font-weight: 500; font-size: 20px; margin: 0; }
.panel-sub { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.panel-body { flex: 1; overflow-y: auto; padding: 14px 18px 30px; min-width: calc(var(--panel-w) - 2px); }
.panel-controls { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.segmented { display: inline-flex; background: var(--surface); border-radius: 10px; padding: 3px; gap: 2px; }
.segmented button { border: 0; background: transparent; padding: 5px 11px; border-radius: 8px; font-size: 13px; color: var(--muted); }
.segmented button[aria-selected="true"], .segmented button[aria-pressed="true"] { background: var(--bg-elev); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); font-weight: 550; }
.chart-box { aspect-ratio: 1 / 1; width: 100%; max-width: 400px; margin: 0 auto; display: grid; place-items: center; }
.chart-box svg { width: 100%; height: 100%; display: block; }
.chart-box .placeholder { color: var(--muted); font-size: 14px; text-align: center; padding: 20px; }
.chart-svg .cell { fill: var(--chart-fill); stroke: var(--chart-line); stroke-width: 1.2; }
.chart-svg .cell.lagna { fill: var(--chart-lagna); }
.chart-svg .frame { fill: none; stroke: var(--chart-line); stroke-width: 1.6; }
.chart-svg .line { stroke: var(--chart-line); stroke-width: 1.2; fill: none; }
.chart-svg .sign-no { fill: var(--muted); font: 600 11px var(--font-ui); }
.chart-svg .sign-name { fill: var(--muted); font: 10px var(--font-ui); }
.chart-svg .pl { fill: var(--text); font: 600 13px var(--font-ui); }
.chart-svg .pl.outer { fill: var(--text-2); font-weight: 550; }
.chart-svg .pl.retro { fill: var(--accent-strong); }
.chart-svg .pl-deg { fill: var(--muted); font: 10px var(--font-ui); }
.chart-svg .asc { fill: var(--accent-strong); font: 700 11px var(--font-ui); letter-spacing: .04em; }
.chart-svg .center-title { fill: var(--text-2); font: 500 17px var(--font-read); }
.chart-svg .center-sub { fill: var(--muted); font: 11.5px var(--font-ui); }
.chart-notes { font-size: 12.5px; color: var(--muted); margin: 10px 0 0; width: 100%; }
.chart-warn {
  padding: 8px 11px; margin-bottom: 8px; border-radius: 9px;
  background: var(--warn-soft); color: var(--warn); font-size: 12.5px; line-height: 1.45;
  text-align: left;
}
.chart-notes details {
  border: 1px solid var(--border); border-radius: 9px; padding: 6px 10px;
  background: var(--bg);
}
.chart-notes summary { cursor: pointer; font-weight: 550; color: var(--text-2); user-select: none; }
.chart-notes .notes-list {
  margin: 6px 0 2px; padding: 0 0 0 16px; list-style: disc; text-align: left;
}
.chart-notes .notes-list li { margin: 4px 0; line-height: 1.45; }

.panel-section { margin-top: 22px; }
.panel-section h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 0 0 8px; font-weight: 650; }
.table-wrap { overflow-x: auto; }
.planet-table { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.planet-table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 11.5px; padding: 4px 6px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.planet-table td { padding: 6px 5px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.planet-table tr:last-child td { border-bottom: 0; }
.planet-table td.pname { font-weight: 600; }
.flag { display: inline-block; font-size: 10.5px; font-weight: 700; padding: 0 5px; border-radius: 5px; margin-right: 2px; background: var(--surface); color: var(--text-2); }
.flag.r { background: var(--accent-soft); color: var(--accent-strong); }
.dig { font-size: 12px; color: var(--muted); }
.dig.exalted, .dig.moolatrikona, .dig.own { color: var(--ok); }
.dig.debilitated { color: var(--err); }

.dasha-list { list-style: none; padding: 0; margin: 0; }
.dasha-list li { display: grid; grid-template-columns: 96px 1fr; gap: 2px 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.dasha-list li.list-empty { display: block; grid-template-columns: none; }
.dasha-list li:last-child { border-bottom: 0; }
.dasha-level { font-size: 12px; color: var(--muted); padding-top: 2px; }
.dasha-lord { font-weight: 600; }
.dasha-dates { grid-column: 2; font-size: 12.5px; color: var(--muted); }
.dasha-bar { grid-column: 2; height: 4px; background: var(--surface); border-radius: 4px; overflow: hidden; margin-top: 3px; }
.dasha-bar span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }

.memory-list, .prediction-list { list-style: none; padding: 0; margin: 0; font-size: 14px; }
.memory-list li, .prediction-list li { padding: 9px 0; border-bottom: 1px solid var(--border); }
.memory-list li { display: flex; gap: 8px; align-items: flex-start; }
.memory-list li .m-text { flex: 1; }
.memory-list .m-kind, .prediction-list .p-meta { font-size: 11.5px; color: var(--muted); }
.memory-list .icon-btn { width: 26px; height: 26px; }
.memory-list .icon-btn svg { width: 14px; height: 14px; }
.prediction-list .p-text { margin-bottom: 4px; }
.prediction-list .segmented { margin-top: 6px; }
.prediction-list .segmented button { font-size: 12px; padding: 3px 8px; }
.prediction-list .segmented button[aria-pressed="true"][data-status="happened"] { color: var(--ok); }
.prediction-list .segmented button[aria-pressed="true"][data-status="did_not_happen"] { color: var(--err); }
.list-empty { color: var(--muted); font-size: 13px; padding: 4px 0; border: 0 !important; }

/* ------------------------------------------------------------------ dialog & forms */
.dialog {
  width: min(600px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  border: 1px solid var(--border); border-radius: 18px; padding: 0;
  background: var(--bg-elev); color: var(--text); box-shadow: var(--shadow-lg);
}
.dialog::backdrop { background: rgba(25, 18, 10, .38); backdrop-filter: blur(2px); }
.dialog form { display: flex; flex-direction: column; max-height: calc(100dvh - 26px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px 22px; }
.dialog-head h2 { margin: 0; font-family: var(--font-read); font-weight: 500; font-size: 22px; }
.dialog-body { padding: 6px 22px 10px; overflow-y: auto; }
.dialog-foot { display: flex; align-items: center; gap: 8px; padding: 12px 22px 18px; border-top: 1px solid var(--border); }
.spacer { flex: 1; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; min-width: 0; }
.field.compact { margin: 0; min-width: 150px; }
.field label { font-size: 13px; font-weight: 550; color: var(--text-2); }
.field input, .field select, .field textarea {
  padding: 8px 10px; border-radius: 9px; border: 1px solid var(--border-strong);
  background: var(--bg); min-width: 0; width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field-hint { font-size: 12.5px; color: var(--muted); margin: 2px 0 0; }
.search-row { display: flex; gap: 6px; }
.search-row input { flex: 1; }
.btn {
  padding: 8px 14px; border-radius: 10px; border: 1px solid var(--border-strong);
  background: var(--bg-elev); color: var(--text); font-weight: 550; font-size: 14px; white-space: nowrap;
}
.btn:hover { background: var(--surface); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-strong); }
.btn.primary:disabled { opacity: .5; cursor: default; }
.btn.danger { color: var(--err); border-color: transparent; background: transparent; }
.btn.danger:hover { background: var(--err-soft); }
.place-results { list-style: none; margin: 6px 0 0; padding: 0; border-radius: 10px; overflow: hidden; }
.place-results:not(:empty) { border: 1px solid var(--border); }
.place-results li { padding: 8px 12px; cursor: pointer; font-size: 14px; border-bottom: 1px solid var(--border); }
.place-results li:last-child { border-bottom: 0; }
.place-results li:hover, .place-results li:focus { background: var(--surface); outline: none; }
.place-results li[aria-selected="true"] { background: var(--accent-soft); }
.place-results .pr-meta { display: block; font-size: 12px; color: var(--muted); }
.map-toggle-btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 11px; }
.map-toggle-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.map-toggle-btn[aria-expanded="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-strong); }
.map-box { margin-top: 8px; border: 1px solid var(--border-strong); border-radius: 12px; overflow: hidden; background: var(--surface); }
.map-canvas {
  position: relative; width: 100%; height: 248px; overflow: hidden; cursor: crosshair;
  user-select: none; touch-action: none;
  background-color: var(--surface);
  background-image:
    linear-gradient(to right, var(--border) 1px, transparent 1px),
    linear-gradient(to bottom, var(--border) 1px, transparent 1px);
  background-size: 32px 32px;
}
.map-canvas.dragging { cursor: grabbing; }
.map-tiles { position: absolute; inset: 0; pointer-events: none; }
.map-tile { position: absolute; width: 256px; height: 256px; max-width: none; border: 0; user-select: none; pointer-events: none; }
:root[data-theme="dark"] .map-tile { filter: brightness(.88) contrast(1.05); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .map-tile { filter: brightness(.88) contrast(1.05); }
}
.map-pin {
  position: absolute; width: 28px; height: 36px; transform: translate(-50%, -94%);
  pointer-events: none; z-index: 2; filter: drop-shadow(0 2px 4px rgba(0, 0, 0, .35));
}
.map-pin svg { width: 28px; height: 36px; display: block; }
.map-pin path { fill: var(--accent); stroke: var(--bg-elev); stroke-width: 1.8; }
.map-pin circle { fill: var(--bg-elev); }
.map-controls { position: absolute; top: 8px; right: 8px; display: flex; flex-direction: column; gap: 4px; z-index: 3; }
.map-ctrl-btn {
  width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--bg-elev); color: var(--text); font-weight: 650; font-size: 16px; line-height: 1;
  display: grid; place-items: center; box-shadow: var(--shadow);
}
.map-ctrl-btn:hover { background: var(--surface); }
.map-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 10px; font-size: 12px; color: var(--muted); background: var(--bg-elev);
  border-top: 1px solid var(--border);
}
.map-coords { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-2); }
.map-attr { flex-shrink: 0; font-size: 11px; color: var(--muted); }
.offset-box { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; background: var(--bg); }
.offset-main { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.offset-value { font-family: var(--font-read); font-size: 22px; }
.offset-basis { font-size: 13px; color: var(--muted); }
.warnings { margin: 8px 0 0; padding-left: 18px; font-size: 13px; color: var(--warn); }
.warnings:empty { display: none; }
.confirm-q { margin-top: 10px; padding: 10px 12px; border-radius: 10px; background: var(--warn-soft); font-size: 14px; }
.confirm-q p { margin: 0 0 6px; }
.confirm-options { display: flex; gap: 16px; flex-wrap: wrap; }
.confirm-options label { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.advanced { margin-top: 10px; font-size: 13px; }
.advanced summary { cursor: pointer; color: var(--muted); margin-bottom: 8px; }
.form-error { color: var(--err); font-size: 13.5px; min-height: 1em; margin: 0; }

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 10px; font-size: 13.5px;
  box-shadow: var(--shadow-lg); z-index: 60; animation: fadeUp .2s ease both; max-width: calc(100vw - 32px);
}

/* ------------------------------------------------------------------ animation */
@keyframes blink { 50% { opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: .25; transform: scale(.85); } 50% { opacity: .9; transform: scale(1); } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes softFlash { 0% { background: var(--accent-soft); } 100% { background: transparent; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}

/* ------------------------------------------------------------------ responsive */
@media (max-width: 1180px) {
  .app[data-panel="open"], .app[data-sidebar="collapsed"][data-panel="open"] { grid-template-columns: var(--sidebar-w) minmax(0, 1fr) 0; }
  .app[data-sidebar="collapsed"][data-panel="open"] { grid-template-columns: 0 minmax(0, 1fr) 0; }
  .panel {
    position: fixed; top: 0; right: 0; bottom: 0; width: min(var(--panel-w), 100vw); z-index: 40;
    box-shadow: var(--shadow-lg);
  }
}
@media (max-width: 800px) {
  .app, .app[data-sidebar="collapsed"], .app[data-panel="open"], .app[data-sidebar="collapsed"][data-panel="open"] { grid-template-columns: 0 minmax(0, 1fr) 0; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: min(var(--sidebar-w), 86vw); z-index: 50;
    transform: translateX(-102%); transition: transform .22s ease; box-shadow: var(--shadow-lg);
    padding: 10px 10px 8px !important; border-right: 1px solid var(--border) !important;
  }
  .sidebar > * { min-width: 0; }
  .app[data-drawer="open"] .sidebar { transform: none; }
  .app[data-drawer="open"] .scrim { display: block; position: fixed; inset: 0; background: rgba(20, 14, 8, .35); z-index: 45; }
  #sidebar-open, .app[data-sidebar="collapsed"] #sidebar-open { display: inline-grid; }
  .column { padding: 4px 16px 32px; }
  .composer-wrap { padding: 0 10px 8px; }
  .msg.user { max-width: 92%; }
  .answer { font-size: 16.5px; }
  .suggestions { grid-template-columns: 1fr; }
  .empty { padding-top: 6vh; }
  .panel-body { min-width: 0; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; gap: 0; }
  .dialog { width: 100vw; max-width: 100vw; max-height: 100dvh; border-radius: 0; margin: 0; height: 100dvh; }
  .dialog form { max-height: 100dvh; height: 100%; }
  .dialog-body { flex: 1; }
  .chip-btn span { display: none; }
}

/* Read aloud (shown only when Sarvam TTS is configured) */
.listen-btn { display: none; }
body.tts-on .listen-btn { display: inline-flex; }
.listen-btn.playing { color: var(--accent-strong); }
.listen-btn.loading { animation: listen-pulse 1s ease-in-out infinite; }
@keyframes listen-pulse { 50% { opacity: .45; } }
@media (prefers-reduced-motion: reduce) { .listen-btn.loading { animation: none; } }
.msg-actions:has(.listen-btn.playing), .msg-actions:has(.listen-btn.loading) { opacity: 1; }

/* ------------------------------------------------------------------ multi-user & admin console */
.sidebar-foot { flex-direction: column; align-items: stretch; gap: 6px; padding-top: 8px; }
.sidebar-foot-bottom { display: flex; align-items: center; justify-content: space-between; width: 100%; }
.user-card {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 11px;
  padding: 8px 10px; display: flex; flex-direction: column; gap: 6px;
}
.user-card-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.user-name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-auth-pill {
  font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-strong); white-space: nowrap;
}
.user-auth-pill.warn { background: var(--warn-soft); color: var(--warn); }
.user-card-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.ghost-btn.sm-btn { padding: 4px 7px; font-size: 12px; border: 1px solid var(--border); border-radius: 7px; background: var(--bg); }
.ghost-btn.sm-btn:hover { border-color: var(--border-strong); background: var(--surface); }
.ghost-btn.admin-btn { color: var(--accent-strong); border-color: var(--accent-soft); }

.setup-guide-box {
  background: var(--bg); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; font-size: 13.5px; line-height: 1.5;
}
.setup-guide-box h4 { margin: 0 0 8px; font-size: 14.5px; color: var(--text); }
.setup-steps { margin: 0; padding-left: 20px; }
.setup-steps li { margin: 6px 0; }
.setup-steps code {
  font-family: var(--font-mono); font-size: 12px; background: var(--surface);
  padding: 2px 6px; border-radius: 5px;
}

.dialog.wide-dialog { width: min(920px, calc(100vw - 28px)); }
.admin-tabs { margin-bottom: 14px; }
.admin-create-bar {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  margin-bottom: 12px; padding: 10px 12px; background: var(--bg);
  border: 1px solid var(--border); border-radius: 11px;
}
.admin-create-bar input[type="text"], .admin-create-bar input:not([type]) {
  flex: 1; min-width: 170px; padding: 7px 10px; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--bg-elev);
}
.admin-create-bar select {
  padding: 7px 9px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--bg-elev); font-size: 13px;
}
.admin-check { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--text-2); cursor: pointer; }
.admin-table td, .admin-table th { padding: 8px 8px; vertical-align: middle; }
.invite-code-pill {
  font-family: var(--font-mono); font-size: 12px; background: var(--surface);
  padding: 3px 7px; border-radius: 6px; user-select: all;
}
.admin-chats-layout {
  display: grid; grid-template-columns: 280px 1fr; gap: 12px;
  min-height: 360px; max-height: 58vh;
}
.admin-chats-list {
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg);
  overflow-y: auto; padding: 6px; display: flex; flex-direction: column; gap: 4px;
}
.admin-chat-item {
  text-align: left; border: 1px solid transparent; background: transparent;
  padding: 8px 10px; border-radius: 8px; cursor: pointer; display: flex; flex-direction: column; gap: 2px;
}
.admin-chat-item:hover { background: var(--surface); }
.admin-chat-item.active { background: var(--bg-elev); border-color: var(--accent); }
.admin-chat-item-title { font-weight: 600; font-size: 13px; color: var(--text); }
.admin-chat-item-meta { font-size: 11.5px; color: var(--muted); }
.admin-chat-viewer {
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg);
  overflow-y: auto; padding: 12px 14px; font-size: 14px;
}
.admin-msg { padding: 8px 10px; border-radius: 9px; margin-bottom: 8px; }
.admin-msg.user { background: var(--surface); }
.admin-msg.assistant { background: var(--bg-elev); border: 1px solid var(--border); }
.admin-msg-role { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
@media (max-width: 800px) {
  .admin-chats-layout { grid-template-columns: 1fr; max-height: none; }
}


