/* Shamaaya — mobile-first styles */

:root {
  --bg: #fbf6ee;
  --surface: #ffffff;
  --surface-2: #f4ebdd;
  --text: #2b2118;
  --muted: #76675a;
  --border: #e8dcc8;
  --accent: #a8561a;        /* buttons (white text passes contrast) */
  --on-accent: #ffffff;
  --accent-text: #a8561a;   /* accent-coloured text and icons */
  --accent-soft: #f9e3c6;
  --glow: rgba(240, 160, 75, 0.22);
  --mic-ring: rgba(168, 86, 26, 0.22);
  --user-bubble: #f5e2c6;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --shadow: 0 12px 32px rgba(70, 45, 15, 0.14);
  --font-serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16120e;
    --surface: #201a14;
    --surface-2: #2b231a;
    --text: #f2e8da;
    --muted: #ab9b8b;
    --border: #3a3027;
    --accent: #f0a04b;
    --on-accent: #1d140b;
    --accent-text: #f3b06a;
    --accent-soft: #3b2a17;
    --glow: rgba(240, 160, 75, 0.12);
    --mic-ring: rgba(240, 160, 75, 0.25);
    --user-bubble: #3a2b1b;
    --danger: #f2b8b5;
    --danger-soft: #3a1f1c;
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; -webkit-user-select: none; user-select: none; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }

.logo, .brand svg { fill: currentColor; color: var(--accent-text); }

/* ---------- Unlock screen ---------- */
.lock {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: radial-gradient(120% 60% at 50% 0%, var(--glow), transparent 70%), var(--bg);
}
.lock-card { width: 100%; max-width: 380px; text-align: center; }
.lock-card .logo { width: 72px; height: 72px; }
.lock-card h1 { font: 600 2.75rem/1.1 var(--font-serif); margin: 8px 0 6px; }
.name-meaning { margin: 0 0 10px; color: var(--accent-text); font-size: 1rem; letter-spacing: 0.03em; }
.tagline { color: var(--muted); margin: 0 0 32px; }
.lock-card form { display: grid; gap: 10px; text-align: left; }
.lock-card label { font-size: 0.875rem; color: var(--muted); }
.lock-card input {
  min-height: 48px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}
.lock-card input:focus { outline: none; border-color: var(--accent-text); box-shadow: 0 0 0 3px var(--accent-soft); }
.primary {
  min-height: 48px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}
.primary:disabled { opacity: 0.6; }
.form-error { color: var(--danger); min-height: 1.5em; margin: 0; font-size: 0.9rem; }

/* ---------- Consent screen ---------- */
.consent-card { width: 100%; max-width: 480px; }
.consent-card .logo { display: block; width: 56px; height: 56px; margin: 0 auto; }
.consent-card h1 { font: 600 2.2rem/1.1 var(--font-serif); text-align: center; margin: 8px 0 18px; }
.consent-points { list-style: none; margin: 0 0 18px; padding: 0; display: grid; gap: 10px; }
.consent-points li {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  font-size: 0.92rem;
  line-height: 1.5;
}
.consent-points a, .consent-checks a { color: var(--accent-text); }
.consent-checks { display: grid; gap: 10px; }
.consent-checks label {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 10px;
  align-items: start;
  font-size: 0.92rem;
  line-height: 1.45;
  cursor: pointer;
}
.consent-checks input { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--accent); }
.consent-checks .primary { margin-top: 8px; }

/* ---------- App shell ---------- */
.app { display: flex; height: 100dvh; overflow: hidden; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  width: min(85vw, 300px);
  display: flex;
  flex-direction: column;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: var(--surface);
  border-right: 1px solid var(--border);
  transform: translateX(-102%);
  transition: transform 0.25s ease;
}
body.sidebar-open .sidebar { transform: none; box-shadow: var(--shadow); }
.scrim {
  position: fixed;
  inset: 0;
  z-index: 15;
  background: rgba(20, 12, 4, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
body.sidebar-open .scrim { opacity: 1; pointer-events: auto; }

.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 14px; }
.brand { display: flex; align-items: center; gap: 8px; font: 600 1.6rem/1 var(--font-serif); color: var(--accent-text); }
.brand svg { width: 30px; height: 30px; }

.new-chat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}
.new-chat svg { width: 18px; height: 18px; }
.new-chat:disabled { opacity: 0.6; }

.chat-nav { flex: 1; min-height: 0; overflow-y: auto; margin: 14px -4px 0; padding: 0 4px; }
.chat-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; }
.chat-item { display: flex; align-items: center; border-radius: 10px; }
.chat-item:hover { background: var(--surface-2); }
.chat-item.active { background: var(--accent-soft); }
.chat-open {
  flex: 1;
  min-width: 0;
  min-height: 48px;
  padding: 8px 10px;
  border: 0;
  background: transparent;
  text-align: left;
}
.chat-open .t { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.95rem; }
.chat-open .d { display: block; font-size: 0.75rem; color: var(--muted); }
.chat-del { width: 40px; height: 40px; flex-shrink: 0; color: var(--muted); }
.chat-del svg { width: 18px; height: 18px; }
.chat-del:hover { color: var(--danger); }
.empty-list { color: var(--muted); font-size: 0.9rem; padding: 10px; }
.sidebar-foot { display: grid; justify-items: start; gap: 2px; padding: 10px 4px 0; font-size: 0.75rem; color: var(--muted); border-top: 1px solid var(--border); }
.sidebar-foot p { margin: 0 0 4px; }
.sidebar-foot .legal-links { margin: 6px 0 0; }
.text-btn {
  min-height: 32px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.text-btn:hover { color: var(--danger); }
.text-btn:disabled { opacity: 0.5; }
.legal-links { margin: 20px 0 0; font-size: 0.8rem; color: var(--muted); }
.legal-links a, .disclaimer a { color: inherit; text-underline-offset: 2px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100dvh; }

.topbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) 6px max(8px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.chat-title {
  flex: 1;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
  font: 600 1.3rem/1.2 var(--font-serif);
}
.icon-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:disabled { opacity: 0.4; }

@media (min-width: 900px) {
  .sidebar { position: static; width: 280px; flex-shrink: 0; transform: none; transition: none; }
  .only-mobile, .scrim { display: none !important; }
  .chat-title { text-align: left; padding-left: 12px; }
}

/* ---------- Thread ---------- */
.thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
}
.messages, .welcome { max-width: 720px; margin: 0 auto; }

.welcome {
  text-align: center;
  padding: clamp(16px, 7vh, 72px) 0 16px;
  background: radial-gradient(60% 40% at 50% 8%, var(--glow), transparent 70%);
}
.welcome .logo { width: 60px; height: 60px; }
.welcome h1 { font: 600 clamp(1.9rem, 6vw, 2.5rem)/1.15 var(--font-serif); margin: 10px 0; }
.welcome p { color: var(--muted); max-width: 40ch; margin: 0 auto 28px; }
.starters { display: grid; grid-template-columns: 1fr; gap: 10px; max-width: 560px; margin: 0 auto; }
@media (min-width: 600px) { .starters { grid-template-columns: 1fr 1fr; } }
.starter {
  min-height: 48px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  text-align: left;
  font-size: 0.95rem;
  line-height: 1.4;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.starter:hover { border-color: var(--accent-text); background: var(--accent-soft); }

.msg { margin: 0 0 22px; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .bubble {
  max-width: 85%;
  padding: 10px 15px;
  border-radius: 18px 18px 6px 18px;
  background: var(--user-bubble);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.assistant .who {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  color: var(--accent-text);
  font: 600 1.05rem/1 var(--font-serif);
}
.msg.assistant .who svg { width: 20px; height: 20px; fill: currentColor; }
.ai-badge {
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font: 600 0.65rem/1.2 var(--font-sans);
  letter-spacing: 0.04em;
}
.msg.assistant .body { overflow-wrap: anywhere; }
.body > :first-child { margin-top: 0; }
.body > :last-child { margin-bottom: 0; }
.body p { margin: 0 0 0.85em; }
.body ul, .body ol { margin: 0 0 0.85em; padding-left: 1.3em; }
.body li { margin: 0.2em 0; }
.body h1, .body h2, .body h3, .body h4 { font-family: var(--font-serif); line-height: 1.25; margin: 1em 0 0.4em; }
.body a { color: var(--accent-text); }
.body blockquote {
  margin: 1em 0;
  padding: 0.35em 0 0.35em 1em;
  border-left: 3px solid var(--accent-text);
  font-family: var(--font-serif);
  font-size: 1.22rem;
  line-height: 1.45;
  font-style: italic;
}
.body blockquote p { margin: 0.25em 0; }
.body code { font-size: 0.9em; background: var(--surface-2); padding: 0.1em 0.3em; border-radius: 4px; }
.body hr { border: 0; border-top: 1px solid var(--border); margin: 1.2em 0; }
.msg-actions { display: flex; gap: 8px; margin: 6px 0 0 -8px; }
.action-btn {
  position: relative;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
}
.action-btn::after { content: ""; position: absolute; inset: -4px; } /* 44px tap area */
.action-btn:hover { background: var(--surface-2); color: var(--accent-text); }
.action-btn svg { width: 18px; height: 18px; }
.action-btn .icon-alt { display: none; }
.action-btn.copied .icon-main, .action-btn[aria-pressed="true"] .icon-main { display: none; }
.action-btn.copied .icon-alt, .action-btn[aria-pressed="true"] .icon-alt { display: block; }
.action-btn.copied, .action-btn[aria-pressed="true"] { color: var(--accent-text); }
.action-btn[aria-pressed="true"] { background: var(--accent-soft); animation: speak-pulse 1.6s ease-in-out infinite; }
@keyframes speak-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }
.note { margin-top: 8px; color: var(--muted); font-size: 0.85rem; font-style: italic; }

.reflecting { display: inline-flex; align-items: center; gap: 10px; color: var(--muted); font-style: italic; }
.reflecting .dots { display: inline-flex; gap: 4px; }
.reflecting .dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-text);
  animation: breathe 1.4s ease-in-out infinite;
}
.reflecting .dots i:nth-child(2) { animation-delay: 0.2s; }
.reflecting .dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes breathe { 0%, 100% { opacity: 0.25; transform: scale(0.8); } 50% { opacity: 1; transform: scale(1); } }

.error-box {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-top: 8px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--danger-soft);
  color: var(--text);
  font-size: 0.95rem;
}
.error-box button {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 0.9rem;
  font-weight: 600;
}

/* ---------- Composer ---------- */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  width: 100%;
  max-width: 752px;
  margin: 0 auto;
  padding: 8px max(16px, env(safe-area-inset-right)) 4px max(16px, env(safe-area-inset-left));
}
.composer textarea {
  flex: 1;
  min-width: 0;
  min-height: 48px;
  max-height: 40dvh;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* 16px stops iOS zooming on focus */
  line-height: 1.4;
  resize: none;
  overflow-y: hidden;
}
.composer textarea::placeholder { color: var(--muted); }
.composer textarea:focus { outline: none; border-color: var(--accent-text); box-shadow: 0 0 0 3px var(--accent-soft); }
.send {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  transition: opacity 0.15s ease;
}
.send svg { width: 22px; height: 22px; }
.mic {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--accent-text);
  transition: background 0.15s ease, border-color 0.15s ease;
}
.mic svg { width: 22px; height: 22px; }
.mic .icon-stop { display: none; }
.mic:hover { border-color: var(--accent-text); }
.mic[aria-pressed="true"] { border-color: var(--accent-text); background: var(--accent-soft); animation: mic-pulse 1.6s ease-in-out infinite; }
.mic[aria-pressed="true"] .icon-mic { display: none; }
.mic[aria-pressed="true"] .icon-stop { display: block; }
@keyframes mic-pulse { 0%, 100% { box-shadow: 0 0 0 0 var(--mic-ring); } 50% { box-shadow: 0 0 0 6px var(--mic-ring); } }
.send:disabled { opacity: 0.4; }
.disclaimer {
  margin: 0;
  padding: 2px 16px max(10px, env(safe-area-inset-bottom));
  text-align: center;
  color: var(--muted);
  font-size: 0.75rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  z-index: 50;
  max-width: calc(100vw - 32px);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.9rem;
  transform: translateX(-50%);
  box-shadow: var(--shadow);
}

/* ---------- Terms & Privacy pages ---------- */
.doc-page { background: var(--bg); }
.doc {
  max-width: 720px;
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 16px max(40px, env(safe-area-inset-bottom));
  overflow-wrap: anywhere;
}
.doc-back { display: inline-block; margin-bottom: 16px; color: var(--accent-text); text-decoration: none; font-weight: 500; }
.doc h1 { font: 600 2.4rem/1.1 var(--font-serif); margin: 0 0 4px; }
.doc h2 { font: 600 1.45rem/1.25 var(--font-serif); margin: 1.6em 0 0.4em; }
.doc-meta { color: var(--muted); font-size: 0.85rem; margin: 0 0 1.4em; }
.doc p, .doc li { font-size: 0.97rem; }
.doc ul { padding-left: 1.2em; }
.doc li { margin: 0.4em 0; }
.doc a { color: var(--accent-text); }
.doc-callout { margin: 1.4em 0; padding: 4px 18px 8px; border: 1px solid var(--border); border-left: 4px solid var(--accent-text); border-radius: 12px; background: var(--surface); }
.doc-callout h2 { margin-top: 0.8em; }
.doc-foot { margin-top: 2.4em; padding-top: 1em; border-top: 1px solid var(--border); color: var(--muted); font-size: 0.9rem; }

/* ---------- Usage dashboard (/stats) ---------- */
:root { --chart-bar: #a8561a; --grid: #ece3d4; }
@media (prefers-color-scheme: dark) { :root { --chart-bar: #c97a2c; --grid: #332a21; } }
.stats-page { background: var(--bg); }
.stats-page .lock-card h1 { margin-bottom: 28px; }
.dash {
  max-width: 1040px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px max(40px, env(safe-area-inset-bottom));
}
.dash-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.dash-head h1 { font: 600 2.2rem/1.1 var(--font-serif); margin: 0; }
.dash-meta { margin: 4px 0 0; color: var(--muted); font-size: 0.85rem; }
.dash-actions { display: flex; gap: 16px; padding-top: 6px; white-space: nowrap; }
.range { display: flex; flex-wrap: wrap; gap: 8px; margin: 20px 0 4px; }
.range button {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 0.9rem;
}
.range button[aria-checked="true"] { border-color: var(--accent-text); background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
#content { transition: opacity 0.15s ease; }
#content.loading { opacity: 0.5; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 12px 0 16px; }
.tile { padding: 14px 16px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); }
.tile p { margin: 0; }
.tile-label { color: var(--muted); font-size: 0.82rem; }
.tile-value { margin-top: 2px !important; font-size: 1.7rem; font-weight: 600; line-height: 1.2; }
.tile-sub { margin-top: 2px !important; color: var(--muted); font-size: 0.78rem; }
.chart-card { position: relative; margin: 0 0 16px; padding: 16px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); }
.chart-card h2 { margin: 0; font-size: 1rem; font-weight: 600; }
.chart-sub { margin: 2px 0 0; color: var(--muted); font-size: 0.8rem; }
.chart { position: relative; margin-top: 10px; }
.chart svg { display: block; max-width: 100%; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .bar path { fill: var(--chart-bar); transition: opacity 0.1s ease; }
.chart .bar.on path { opacity: 0.72; }
.chart .hit { fill: transparent; cursor: default; outline: none; }
.chart .hit:focus-visible { stroke: var(--accent-text); stroke-width: 1.5; }
.tip {
  position: absolute;
  z-index: 2;
  display: grid;
  gap: 1px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 0.8rem;
  white-space: nowrap;
  pointer-events: none;
  transform: translate(-50%, -100%);
}
.tip strong { font-size: 0.95rem; }
.tip span { color: var(--muted); }
.outcomes { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 2px; }
.outcome { display: grid; grid-template-columns: 24px 1fr auto; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--grid); font-size: 0.92rem; }
.outcome:last-child { border-bottom: 0; }
.outcome-icon { color: var(--muted); text-align: center; }
.outcome.bad .outcome-icon { color: var(--danger); }
.outcome strong { font-variant-numeric: tabular-nums; }
.table-card summary { cursor: pointer; font-weight: 600; }
.table-wrap { overflow-x: auto; margin-top: 10px; }
.table-card table { width: 100%; border-collapse: collapse; font-size: 0.88rem; font-variant-numeric: tabular-nums; }
.table-card th, .table-card td { padding: 6px 8px; border-bottom: 1px solid var(--grid); text-align: right; white-space: nowrap; }
.table-card th:first-child, .table-card td:first-child { text-align: left; }
.table-card th { color: var(--muted); font-weight: 500; }
.dash-foot { color: var(--muted); font-size: 0.8rem; margin: 8px 0 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
