/* Deen — Apple-style design system (same tokens as Assan Health), deep green accent.
 * Light/dark follow the device. Built for a phone first: one column, composer at the bottom. */

:root {
  color-scheme: light dark;
  --bg: #f2f2f7;
  --surface-1: #ffffff;
  --surface-2: #f2f2f7;
  --fill: rgba(120, 120, 128, 0.12);
  --border: rgba(60, 60, 67, 0.12);
  --text-primary: #000000;
  --text-secondary: rgba(60, 60, 67, 0.72);
  --text-muted: rgba(60, 60, 67, 0.5);
  --accent: #0e6b55;
  --accent-ink: #ffffff;
  --accent-soft: rgba(14, 107, 85, 0.12);
  --gold: #a87b22;
  --warning: #c77800;
  --critical: #ff3b30;
  --radius: 16px;
  --bar-bg: rgba(249, 249, 249, 0.86);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface-1: #1c1c1e;
    --surface-2: #2c2c2e;
    --fill: rgba(118, 118, 128, 0.24);
    --border: rgba(84, 84, 88, 0.6);
    --text-primary: #ffffff;
    --text-secondary: rgba(235, 235, 245, 0.7);
    --text-muted: rgba(235, 235, 245, 0.45);
    --accent: #3cc59e;
    --accent-ink: #00241b;
    --accent-soft: rgba(60, 197, 158, 0.16);
    --gold: #e0b45c;
    --warning: #ffb340;
    --critical: #ff453a;
    --bar-bg: rgba(22, 22, 24, 0.86);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text-primary);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 4px; }
.sub { color: var(--text-secondary); margin: 0 0 12px; }
.muted { color: var(--text-muted); }
.small { font-size: 13px; }

.btn {
  appearance: none; border: 0; border-radius: 12px; padding: 10px 16px; font: inherit; font-size: 16px; font-weight: 600;
  background: var(--fill); color: var(--text-primary); cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; color: var(--accent); padding: 8px 10px; }
.btn.danger { color: var(--critical); }
.btn:active { opacity: 0.7; }
.btn[disabled] { opacity: 0.45; }
input, textarea, select {
  width: 100%; font: inherit; font-size: 17px; color: var(--text-primary); background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 12px; padding: 11px 13px; outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }

/* ---------- layout ---------- */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 4px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px; background: var(--bar-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--border);
}
.top .title { flex: 1; font-weight: 700; font-size: 19px; display: flex; align-items: center; gap: 8px; }
.top .title img { width: 26px; height: 26px; border-radius: 7px; }
.icon-btn { appearance: none; border: 0; background: transparent; color: var(--accent); width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; cursor: pointer; }
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn:active { background: var(--fill); }

main { max-width: 760px; margin: 0 auto; padding: 16px 16px 150px; }

/* ---------- chat ---------- */
.msg-user {
  margin: 18px 0 8px auto; max-width: 85%; width: fit-content; background: var(--accent); color: var(--accent-ink);
  padding: 9px 14px; border-radius: 18px 18px 4px 18px; white-space: pre-wrap;
}
.msg-assistant { margin: 8px 0 22px; line-height: 1.5; overflow-wrap: anywhere; }
.msg-assistant h1, .msg-assistant h2, .msg-assistant h3 { font-size: 18px; margin: 16px 0 6px; }
.msg-assistant p { margin: 0 0 10px; }
.msg-assistant ul, .msg-assistant ol { margin: 0 0 10px; padding-left: 22px; }
.msg-assistant li { margin: 3px 0; }
.msg-assistant blockquote {
  margin: 8px 0 10px; padding: 8px 12px; border-left: 3px solid var(--gold); background: var(--surface-1); border-radius: 0 10px 10px 0;
}
.msg-assistant blockquote p { margin: 0; }
.cite {
  display: inline; padding: 1px 7px; border-radius: 7px; background: var(--accent-soft); color: var(--accent);
  font-size: 0.9em; font-weight: 600; text-decoration: none; white-space: normal;
}
.cite.unread { background: rgba(255, 159, 10, 0.16); color: var(--warning); }
.cite.unread::after { content: " ⚠"; }
.checks { margin-top: 10px; padding: 10px 12px; border-radius: 12px; background: rgba(255, 159, 10, 0.12); color: var(--warning); font-size: 14px; }
.checks.ok { background: var(--accent-soft); color: var(--accent); }
.msg-actions { display: flex; gap: 6px; margin-top: 6px; }
.msg-actions button { appearance: none; border: 0; background: var(--fill); color: var(--text-secondary); border-radius: 9px; padding: 5px 10px; font: inherit; font-size: 13px; }
.steps { font-size: 13px; color: var(--text-muted); margin: 6px 0 10px; }
.steps summary { cursor: pointer; list-style: none; }
.steps summary::-webkit-details-marker { display: none; }
.steps ol { margin: 6px 0 0; padding-left: 18px; }
.working { display: flex; align-items: center; gap: 8px; color: var(--text-secondary); font-size: 15px; margin: 8px 0; }
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--fill); border-top-color: var(--accent); animation: spin 0.8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.err { color: var(--critical); }

.welcome { text-align: center; padding: 28px 8px 8px; }
.welcome img { width: 72px; height: 72px; border-radius: 17px; }
.starters { display: grid; gap: 8px; margin-top: 18px; text-align: left; }
.starter { appearance: none; border: 0; text-align: left; font: inherit; font-size: 16px; color: var(--text-primary); background: var(--surface-1); border-radius: 14px; padding: 12px 14px; cursor: pointer; }
.starter:active { background: var(--fill); }

/* ---------- composer ---------- */
.composer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--bar-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--border); padding: 8px 12px calc(env(safe-area-inset-bottom) + 8px);
}
.composer form { max-width: 760px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { resize: none; min-height: 44px; max-height: 140px; border-radius: 22px; padding: 10px 16px; line-height: 1.35; }
.round { flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0; display: grid; place-items: center; cursor: pointer; background: var(--fill); color: var(--accent); }
.round svg { width: 22px; height: 22px; }
.round.send { background: var(--accent); color: var(--accent-ink); }
.round.live { background: var(--critical); color: #fff; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(255, 59, 48, 0.18); } }
.live-text { max-width: 760px; margin: 0 auto 6px; color: var(--text-secondary); font-size: 15px; font-style: italic; }
.voice-row { max-width: 760px; margin: 0 auto 6px; display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-secondary); }
.toggle { appearance: none; border: 0; background: var(--fill); color: var(--text-secondary); border-radius: 999px; padding: 4px 10px; font: inherit; font-size: 13px; }
.toggle.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ---------- sheets ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, 0.32); opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: 88vh; display: flex; flex-direction: column;
  background: var(--bg); border-radius: 14px 14px 0 0; transform: translateY(100%); transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet.open { transform: none; }
@media (min-width: 761px) { .sheet { left: 50%; right: auto; width: 720px; margin-left: -360px; } }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px 10px; border-bottom: 0.5px solid var(--border); }
.sheet-head b { flex: 1; font-size: 17px; }
.sheet-body { overflow-y: auto; padding: 14px 16px 24px; -webkit-overflow-scrolling: touch; }

.passage-ref { font-weight: 700; font-size: 18px; margin-bottom: 2px; }
.passage-title { color: var(--text-secondary); font-size: 14px; margin-bottom: 12px; }
.passage-text { line-height: 1.6; }
.passage-text p { unicode-bidi: plaintext; }
.passage-nav { display: flex; justify-content: space-between; margin-top: 14px; }
.passage-path { margin-top: 10px; font-size: 12px; color: var(--text-muted); word-break: break-all; }

.list { background: var(--surface-1); border-radius: 12px; overflow: hidden; }
.list .item { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 0.5px solid var(--border); cursor: pointer; }
.list .item:last-child { border-bottom: 0; }
.list .item:active { background: var(--fill); }
.list .item .grow { flex: 1; min-width: 0; }
.list .item small { display: block; color: var(--text-secondary); font-size: 13px; overflow-wrap: anywhere; }
.group-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.02em; color: var(--text-secondary); margin: 18px 4px 6px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 10px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { appearance: none; border: 0; flex: none; background: var(--fill); color: var(--text-primary); border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 14px; }
.chip.on { background: var(--accent); color: var(--accent-ink); }
.token-box { font-family: ui-monospace, Menlo, monospace; font-size: 13px; word-break: break-all; background: var(--surface-1); border-radius: 10px; padding: 10px; user-select: all; }

/* sign-in page */
.msg { min-height: 20px; margin-top: 14px; font-size: 13px; color: var(--text-secondary); }
.msg.err { color: var(--critical); }
