:root {
  color-scheme: light dark;
  --bg: #faf7f2;
  --fg: #241f19;
  --muted: #6b6259;
  --border: #e4dcd0;
  --surface: #f1e9dc;
  --bubble-user: #efe2cf;
  --accent: #a8461c;
  --accent-contrast: #fff8f2;
  --danger: #b3261e;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1712;
    --fg: #f3ece1;
    --muted: #b7aa98;
    --border: #3a332a;
    --surface: #2a241d;
    --bubble-user: #3a2f22;
    --accent: #ff9a5c;
    --accent-contrast: #1b1712;
    --danger: #ff8a80;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.45;
}

.page {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 1rem 1.25rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 0;
}

.brand { font-size: 1.05rem; font-weight: 600; color: inherit; text-decoration: none; }

.header-actions { display: flex; align-items: center; gap: .75rem; }

.text-btn {
  background: none; border: none; color: var(--muted);
  font: inherit; cursor: pointer; padding: .25rem .4rem;
}
.text-btn:hover { color: var(--fg); }

.text-btn.small { font-size: .78rem; padding: .1rem .2rem; }

.history { position: relative; }

.history-panel {
  position: absolute; left: 0; top: 2.5rem; z-index: 10;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: .5rem; padding: .6rem; width: 17rem; max-width: 80vw;
  box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .15);
}

.history-panel-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 0 0 .4rem; font-size: .85rem; font-weight: 600;
}

.history-list {
  list-style: none; margin: 0; padding: 0;
  max-height: 16rem; overflow-y: auto;
  display: flex; flex-direction: column; gap: .2rem;
}

.history-item { display: flex; align-items: stretch; gap: .25rem; }

.history-item-open {
  flex: 1; min-width: 0; text-align: left;
  background: none; border: none; border-radius: .4rem;
  color: var(--fg); font: inherit; cursor: pointer;
  padding: .35rem .4rem; display: flex; flex-direction: column; gap: .05rem;
}
.history-item-open:hover, .history-item.active .history-item-open { background: var(--bubble-user); }

.history-item-title {
  font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.history-item-date { font-size: .72rem; color: var(--muted); }

.history-item-delete {
  background: none; border: none; color: var(--muted);
  font: inherit; font-size: 1rem; line-height: 1; cursor: pointer;
  padding: 0 .3rem; border-radius: .3rem;
}
.history-item-delete:hover { color: var(--danger); }

.history-empty { color: var(--muted); font-size: .82rem; margin: .25rem .2rem; }

.account { position: relative; }

.initials-btn {
  width: 2rem; height: 2rem; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--fg); font: inherit; font-size: .8rem; font-weight: 600;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}

.account-menu {
  position: absolute; right: 0; top: 2.5rem; z-index: 10;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: .5rem; padding: .6rem .75rem; min-width: 12rem;
  box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .15);
}

.account-email { margin: 0 0 .5rem; font-size: .85rem; color: var(--muted); word-break: break-all; }
.sign-out-link { color: var(--accent); font-size: .85rem; text-decoration: none; }
.sign-out-link:hover { text-decoration: underline; }

.signin-screen, .chat-screen { flex: 1; display: flex; flex-direction: column; }
.signin-screen { align-items: center; justify-content: center; text-align: center; }

.signin-title { font-size: 1.5rem; margin: 0 0 .5rem; }
.signin-copy { color: var(--muted); margin: 0 0 1.25rem; }

.primary-btn {
  background: var(--accent); color: var(--accent-contrast);
  border: none; border-radius: .5rem; padding: .65rem 1.25rem;
  font: inherit; font-weight: 600; cursor: pointer;
}
.primary-btn:hover { filter: brightness(1.05); }

.thread-wrap { flex: 1; position: relative; overflow-y: auto; padding-bottom: 1rem; }

.empty-state { text-align: center; padding: 3rem 1rem; }
.empty-title { font-size: 1.4rem; margin: 0 0 .4rem; }
.empty-copy { color: var(--muted); margin: 0; }

.thread { display: flex; flex-direction: column; gap: 1.25rem; }

.turn { display: flex; flex-direction: column; gap: .5rem; }

.msg-user {
  align-self: flex-end; max-width: 85%;
  background: var(--bubble-user); border-radius: .9rem .9rem .2rem .9rem;
  padding: .55rem .85rem; white-space: pre-wrap;
}

.reply { max-width: 100%; }
.reply-label { font-size: .8rem; font-weight: 600; color: var(--muted); margin: 0 0 .3rem; }
.reply-status { font-size: .85rem; color: var(--muted); margin: 0 0 .3rem; }
.reply-text { white-space: pre-wrap; }
.reply-error { color: var(--danger); }
.reply-error a { color: var(--accent); margin-left: .3rem; }

.feedback-controls { display: flex; gap: .3rem; margin: .4rem 0 0; }

.feedback-btn {
  background: none; border: none; color: var(--muted);
  display: inline-flex; align-items: center; line-height: 0; cursor: pointer;
  padding: .25rem .35rem; border-radius: .3rem;
}
.feedback-btn svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.feedback-btn:hover { color: var(--fg); }
.feedback-btn[aria-pressed="true"] { color: var(--accent); }
.feedback-btn[aria-pressed="true"] svg { fill: currentColor; }

.jump-latest {
  position: sticky; bottom: .5rem; left: 50%; transform: translateX(-50%);
  display: block; margin: 0 auto; background: var(--surface); color: var(--fg);
  border: 1px solid var(--border); border-radius: 999px; padding: .35rem .9rem;
  font: inherit; font-size: .8rem; cursor: pointer;
  box-shadow: 0 .2rem .6rem rgba(0, 0, 0, .15);
}

.composer {
  display: flex; align-items: flex-end; gap: .5rem;
  border: 1px solid var(--border); border-radius: 1rem;
  background: var(--surface); padding: .5rem;
}

.composer-input {
  flex: 1; resize: none; border: none; background: none; color: var(--fg);
  font: inherit; line-height: 1.4; padding: .5rem .4rem;
  max-height: calc(1.4em * 8 + 1rem); overflow-y: auto;
}
.composer-input:focus { outline: none; }

.send-btn {
  width: 2.25rem; height: 2.25rem; border-radius: 50%; border: none;
  background: var(--accent); color: var(--accent-contrast);
  font-size: 1.1rem; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.send-btn:disabled { opacity: .4; cursor: default; }

.hint { color: var(--muted); font-size: .78rem; margin: .5rem 0 0; text-align: center; }

.signin-links, .legal-links { color: var(--muted); font-size: .8rem; margin: .75rem 0 0; }
.signin-links a, .legal-links a { color: var(--muted); }
.signin-links a:hover, .legal-links a:hover { color: var(--fg); }

.legal {
  max-width: 42rem;
  margin: 0 auto;
  padding: 0 0 2rem;
  line-height: 1.6;
}
.legal h1 { font-size: 1.6rem; margin: 0 0 .5rem; }
.legal h2 { font-size: 1.05rem; margin: 1.75rem 0 .4rem; }
.legal p { margin: 0 0 .9rem; }
.legal-dates { color: var(--muted); font-size: .85rem; }

.flags {
  max-width: 42rem;
  margin: 0 auto;
  padding: 0 0 2rem;
}
.flags-note { color: var(--muted); font-size: .85rem; margin: 0 0 1.5rem; }

.flags-list { display: flex; flex-direction: column; gap: .75rem; margin: 0 0 1.5rem; }

.flag-row {
  border: 1px solid var(--border); border-radius: .6rem;
  padding: .75rem 1rem; background: var(--surface);
}
.flag-row-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 1rem; margin: 0 0 .5rem;
}
.flag-name { font-weight: 600; }
.flag-effective { color: var(--muted); font-size: .82rem; }

.flag-control { border: none; margin: 0; padding: 0; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.flag-control legend { width: 100%; color: var(--muted); font-size: .78rem; margin: 0 0 .35rem; padding: 0; }
.flag-control label { display: inline-flex; align-items: center; gap: .3rem; font-size: .88rem; cursor: pointer; }

.flags-operational { border-top: 1px solid var(--border); padding-top: 1rem; margin: 0 0 1.5rem; }
.flags-operational h2 { font-size: 1rem; margin: 0 0 .35rem; }
.flags-operational-note { color: var(--muted); font-size: .82rem; margin: 0 0 1rem; }

[hidden] { display: none !important; }
