:root {
  color-scheme: dark;
  font-family: ui-rounded, "SF Pro Rounded", "PingFang SC", system-ui, sans-serif;
  background: #0d0b0a;
  color: #f7eee7;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 15% 10%, rgba(229, 139, 78, .16), transparent 32rem),
    radial-gradient(circle at 85% 85%, rgba(141, 80, 51, .18), transparent 28rem),
    #0d0b0a;
}
button, textarea, select { font: inherit; }
button { cursor: pointer; }

.shell {
  width: min(920px, 100%);
  min-height: 100vh;
  margin: auto;
  padding: 28px 22px 18px;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  gap: 18px;
}
header { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
h1 { margin: 3px 0 5px; font-size: clamp(27px, 5vw, 42px); letter-spacing: -.04em; }
.eyebrow { margin: 0; color: #d7996f; font-size: 11px; letter-spacing: .15em; }
.status { margin: 0; color: #897c74; font-size: 13px; }
.status.ok { color: #8dc89a; }
.header-actions { display: flex; flex-wrap: wrap; justify-content: end; gap: 8px; }
button {
  border: 0;
  border-radius: 999px;
  padding: 10px 15px;
  background: #e58b4e;
  color: #1e1008;
  font-weight: 700;
}
button:disabled { opacity: .55; cursor: wait; }
.ghost { color: #dbcfc7; background: #201b18; border: 1px solid #332b27; }
.danger { color: #e4b1a6; background: transparent; border: 1px solid #5b322b; }

.messages {
  min-height: 58vh;
  max-height: calc(100vh - 250px);
  overflow-y: auto;
  padding: 24px 4px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.empty { margin: auto; color: #97877e; text-align: center; line-height: 1.7; }
.empty span { display: block; color: #e58b4e; font-size: 34px; }
.message { max-width: 82%; line-height: 1.65; white-space: pre-wrap; }
.message small { display: block; margin-bottom: 5px; color: #967f71; }
.message > div { padding: 14px 17px; border-radius: 20px; }
.message.user { align-self: flex-end; }
.message.user small { text-align: right; }
.message.user > div { background: #e58b4e; color: #1d1009; border-bottom-right-radius: 6px; }
.message.assistant { align-self: flex-start; }
.message.assistant > div { background: #211c19; border: 1px solid #352c27; border-bottom-left-radius: 6px; }

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 8px;
  background: #181411;
  border: 1px solid #342b26;
  border-radius: 22px;
  box-shadow: 0 18px 50px rgba(0,0,0,.25);
}
.composer textarea {
  resize: none;
  border: 0;
  outline: 0;
  padding: 11px 12px;
  background: transparent;
  color: #f7eee7;
}
.composer button { align-self: end; }
.footnote { margin: -8px 4px 0; color: #6f625b; font-size: 11px; text-align: center; }

dialog { width: min(680px, calc(100% - 30px)); border: 1px solid #4a3930; border-radius: 22px; padding: 0; background: #171310; color: #f7eee7; }
dialog::backdrop { background: rgba(0,0,0,.72); backdrop-filter: blur(8px); }
.settings-card { padding: 22px; }
.dialog-title { display: flex; justify-content: space-between; align-items: center; }
.dialog-title h2 { margin: 0; }
.icon { padding: 3px 10px; color: #baa89e; background: transparent; font-size: 26px; }
label { display: grid; gap: 8px; margin-top: 18px; color: #b8a79d; font-size: 13px; }
label textarea, label select { width: 100%; border: 1px solid #3c302a; border-radius: 14px; padding: 12px; background: #0e0c0b; color: #f7eee7; line-height: 1.55; }
.dialog-actions { display: flex; justify-content: end; margin-top: 16px; }

/* v0.5 recall badge and details */
.recall { margin-top: 6px; white-space: normal; }
.recall-badge { padding: 3px 10px; font-size: 11px; font-weight: 500; color: #a8968b; background: transparent; border: 1px solid #352c27; }
.recall-badge:disabled { cursor: default; opacity: .8; }
.recall-details { margin-top: 8px; padding: 10px 12px; font-size: 12px; color: #c9b9ae; background: #16120f; border: 1px solid #2e2622; border-radius: 12px; }
.recall-details p { margin: 4px 0; }
.recall-details h4 { margin: 10px 0 4px; font-size: 12px; color: #d7996f; }
.recall-details ul { margin: 0; padding-left: 18px; }
.recall-details pre { max-height: 320px; overflow: auto; white-space: pre-wrap; word-break: break-word; font: inherit; padding: 8px; background: #0e0c0b; border-radius: 8px; }
.recall-settings { margin-top: 18px; border: 1px solid #3c302a; border-radius: 14px; padding: 4px 14px 14px; color: #b8a79d; }
.recall-settings legend { padding: 0 6px; font-size: 13px; }
.recall-settings label.inline { display: flex; align-items: center; gap: 8px; }
.recall-settings input[type=number] { width: 140px; border: 1px solid #3c302a; border-radius: 10px; padding: 8px; background: #0e0c0b; color: #f7eee7; }
.recall-settings .ghost { margin-top: 12px; font-size: 12px; padding: 6px 12px; }
.recall-note { margin: 8px 0 0; font-size: 12px; color: #d7996f; min-height: 1em; }

/* v0.6.0 continuity */
.private-toggle { grid-column: 1 / -1; display: flex; align-items: center; gap: 6px; margin: 0; font-size: 12px; color: #8f7f76; }
.sync-line { margin: -10px 4px 0; min-height: 1em; color: #8f7f76; font-size: 11px; }
.sync-line .ghost { padding: 2px 10px; font-size: 11px; }
.context-line { margin: 4px 0 0; font-size: 11px; color: #7d6f67; white-space: normal; }
.pending-banner { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 12px; font-size: 12px; color: #e4c7a6; background: #241b15; border: 1px solid #4a3930; border-radius: 12px; }
.pending-banner[hidden] { display: none; }
#persistentMemory { width: 100%; border: 1px solid #3c302a; border-radius: 12px; padding: 10px; background: #0e0c0b; color: #f7eee7; font: inherit; line-height: 1.55; }
.counter { margin: 6px 0 0; font-size: 12px; color: #8f7f76; }
.counter.over { color: #e4826e; }
.recall-note a { color: #d7996f; }

.trim-text { white-space: pre-line; line-height: 1.6; color: #d9c9be; font-size: 14px; }
.dialog-actions.wrap { flex-wrap: wrap; gap: 8px; }

@media (max-width: 650px) {
  .shell { padding: 20px 14px 12px; }
  header { align-items: flex-start; flex-direction: column; }
  .header-actions { justify-content: start; }
  .message { max-width: 92%; }
  .messages { max-height: calc(100vh - 330px); }
  .composer { grid-template-columns: 1fr; }
  .composer button { width: 100%; }
}

/* ---------- v0.7.0 ---------- */
.status { display: inline-flex; align-items: center; gap: 6px; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: #6f625b; flex: none; }
.status[data-state="ok"] { color: #8dc89a; }
.status[data-state="ok"] .dot { background: #6fc184; }
.status[data-state="busy"] { color: #e9b779; }
.status[data-state="busy"] .dot { background: #e9a95a; animation: pulse 1s ease-in-out infinite; }
.status[data-state="offline"] { color: #d98572; }
.status[data-state="offline"] .dot { background: #d06a55; }
@keyframes pulse { 50% { opacity: 0.35; } }
.composer .stop { background: #3a2a24; color: #f3d9cb; border: 1px solid #6b4a3c; }

/* Markdown inside assistant replies */
.message.assistant .content { white-space: normal; }
.message.assistant .content > :first-child { margin-top: 0; }
.message.assistant .content > :last-child { margin-bottom: 0; }
.content p { margin: 0 0 0.7em; }
.content h1, .content h2, .content h3, .content h4, .content h5, .content h6 { margin: 0.8em 0 0.4em; line-height: 1.35; }
.content h1 { font-size: 1.3em; } .content h2 { font-size: 1.2em; } .content h3 { font-size: 1.1em; }
.content h4, .content h5, .content h6 { font-size: 1em; }
.content ul, .content ol { margin: 0 0 0.7em; padding-left: 1.4em; }
.content li { margin: 0.15em 0; }
.content blockquote { margin: 0 0 0.7em; padding: 2px 12px; border-left: 3px solid #5a4a41; color: #cdbfb6; }
.content hr { border: 0; border-top: 1px solid #3a302b; margin: 1em 0; }
.content a { color: #f0a46e; }
.content code { font: 0.92em ui-monospace, SFMono-Regular, Menlo, monospace; background: #2c2521; padding: 1px 5px; border-radius: 5px; }
.content .codeblock { margin: 0 0 0.7em; border: 1px solid #3a302b; border-radius: 10px; overflow: hidden; background: #171310; }
.content .codebar { display: flex; justify-content: space-between; align-items: center; padding: 4px 10px; font-size: 12px; color: #9d8d83; background: #221c19; }
.content .codebar .copy { font-size: 12px; padding: 2px 10px; background: #2c2521; color: #dbcfc7; border: 1px solid #3a302b; border-radius: 6px; }
.content pre { margin: 0; padding: 10px 12px; overflow-x: auto; white-space: pre; }
.content pre code { background: none; padding: 0; }
.content .table-wrap { overflow-x: auto; margin: 0 0 0.7em; }
.content table { border-collapse: collapse; font-size: 0.95em; }
.content th, .content td { border: 1px solid #3a302b; padding: 4px 10px; }
.content th { background: #262019; }
.content .align-right { text-align: right; } .content .align-center { text-align: center; }

/* Incomplete replies and error cards */
.message.incomplete .content { border-style: dashed; }
.incomplete-flag { margin: 6px 2px 0; font-size: 12px; color: #e9a95a; }
.regenerate { margin-top: 6px; font-size: 12px; padding: 4px 12px; }
.error-card strong { display: block; color: #f0b49a; margin-bottom: 4px; }
.error-card p { margin: 0 0 6px; }
.error-card details { font-size: 12px; color: #a99a90; }
.error-card pre { white-space: pre-wrap; word-break: break-word; margin: 6px 0 0; font: 12px ui-monospace, Menlo, monospace; }
.settings-card input[type="text"] { width: 100%; box-sizing: border-box; }

/* ---------- v0.8.0: header links, login page, phones ---------- */
html { -webkit-text-size-adjust: 100%; }
a.pill { display: inline-flex; align-items: center; border-radius: 999px; padding: 10px 15px; font-weight: 700; text-decoration: none; }
.header-actions [hidden] { display: none; }
.login-card { width: min(380px, calc(100% - 32px)); margin: 18vh auto 0; padding: 26px 22px; background: #171310; border: 1px solid #4a3930; border-radius: 22px; }
.login-card h1 { font-size: 30px; }
.login-card input { width: 100%; margin-top: 8px; padding: 12px; font-size: 16px; color: #f7eee7; background: #0e0c0b; border: 1px solid #3c302a; border-radius: 12px; }
.login-card button { width: 100%; margin-top: 14px; }
.login-msg { min-height: 1.4em; margin: 12px 0 0; font-size: 13px; color: #e4a58f; }

/* Phones (≤430px): nothing may need horizontal scrolling; the composer stays above the keyboard.
   --app-height is set from window.visualViewport (iOS Safari shrinks it when the keyboard opens). */
@media (max-width: 430px) {
  html, body { overflow-x: hidden; }
  body { overflow-wrap: anywhere; }
  .shell {
    height: var(--app-height, 100dvh);
    min-height: 0;
    padding: max(10px, env(safe-area-inset-top)) 10px max(6px, env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow: hidden;
  }
  header { flex-direction: column; align-items: stretch; gap: 6px; }
  h1 { font-size: 22px; margin: 0; }
  .eyebrow { font-size: 9px; letter-spacing: .08em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .status { font-size: 12px; }
  .header-actions { justify-content: start; gap: 6px; }
  .header-actions button, .header-actions a.pill { padding: 6px 11px; font-size: 13px; }
  .pending-banner { font-size: 12px; padding: 6px 10px; }
  .messages { flex: 1 1 auto; min-height: 0; max-height: none; padding: 6px 0; gap: 12px; }
  .message { max-width: 100%; }
  .message > div { padding: 11px 13px; border-radius: 16px; }
  .composer { grid-template-columns: 1fr auto; gap: 6px; padding: 6px; border-radius: 18px; flex: none; }
  .composer textarea { font-size: 16px; padding: 8px; min-width: 0; } /* 16px: iOS does not zoom on focus */
  .composer button { width: auto; padding: 9px 14px; }
  .sync-line { margin: 0 4px; flex: none; }
  .footnote { display: none; }
  dialog { width: 100vw; max-width: 100vw; max-height: var(--app-height, 100dvh); margin: 0; border-radius: 0; border-width: 0; }
  .settings-card { padding: 14px 12px max(14px, env(safe-area-inset-bottom)); }
  label textarea, label select, label input, .settings-card input[type="text"], .recall-settings input[type=number] { font-size: 16px; max-width: 100%; }
  .dialog-actions { flex-wrap: wrap; gap: 8px; }
  .content .codeblock, .content .table-wrap { max-width: 100%; }
  .recall-details pre { max-height: 240px; }
}
