:root {
  --bg: #FBF9F6;
  --surface: #FFFFFF;
  --ink: #1E1B16;
  --ink-soft: #6B6459;
  --ink-faint: #A39C8F;
  --line: #EDE7DD;
  --accent: #C9722B;
  --accent-soft: #F3E3D3;
  --good: #3E7A5C;
  --good-soft: #E4F0EA;
  --warn: #B4552F;
  --warn-soft: #FBE9E0;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(30,27,22,0.04), 0 8px 24px rgba(30,27,22,0.06);
  --nav-h: 68px;
  --max-w: 480px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16140F;
    --surface: #211E18;
    --ink: #F3EEE5;
    --ink-soft: #B5AC9C;
    --ink-faint: #7A7266;
    --line: #322D24;
    --accent: #E08A47;
    --accent-soft: #3A2A1B;
    --good: #6FBF95;
    --good-soft: #1E2E26;
    --warn: #E08A6E;
    --warn-soft: #362119;
    --shadow: 0 1px 2px rgba(0,0,0,0.2), 0 8px 24px rgba(0,0,0,0.35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

.app {
  max-width: var(--max-w);
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  position: relative;
  padding-bottom: calc(var(--nav-h) + 24px);
}

.app.no-nav { padding-bottom: 24px; }

a { color: inherit; text-decoration: none; }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 8px;
}
.topbar .brand {
  font-family: var(--serif);
  font-size: 19px;
  letter-spacing: 0.02em;
}
.topbar .back {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 16px;
}
.topbar h1 {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 600;
  margin: 0;
}
.topbar .spacer { width: 34px; }

.screen-title {
  padding: 4px 20px 18px;
}
.screen-title h1 {
  font-family: var(--serif);
  font-size: 26px;
  margin: 0 0 4px;
  font-weight: 600;
}
.screen-title p { margin: 0; color: var(--ink-soft); font-size: 14px; }

.content { padding: 0 20px; }

/* Cards */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 14px;
}
.card.flat { box-shadow: none; border: 1px solid var(--line); }
.card-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 2px;
  border-bottom: 1px solid var(--line);
}
.card-row:last-child { border-bottom: none; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px;
  padding: 14px 20px;
  border-radius: 999px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--sans);
  transition: transform .12s ease, opacity .12s ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--ink); color: var(--bg); width: 100%; }
.btn-secondary { background: var(--surface); color: var(--ink); border: 1px solid var(--line); width: 100%; }
.btn-accent { background: var(--accent); color: #fff; width: 100%; }
.btn-ghost { background: transparent; color: var(--ink-soft); font-weight: 500; }
.btn-sm { padding: 9px 14px; font-size: 13px; width: auto; }

/* Chips */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 9px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 13.5px;
  cursor: pointer;
  color: var(--ink);
}
.chip:hover { border-color: var(--accent); }
.chip.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* Tabs */
.tabs { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px; margin-bottom: 18px; }
.tab { flex: 1; text-align: center; padding: 9px 8px; border-radius: 999px; font-size: 13.5px; font-weight: 600; color: var(--ink-soft); cursor: pointer; }
.tab.active { background: var(--ink); color: var(--bg); }

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  max-width: var(--max-w);
  margin: 0 auto;
  height: var(--nav-h);
  background: var(--surface);
  border-top: 1px solid var(--line);
  display: flex;
  z-index: 50;
}
.bottom-nav a {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px;
  font-size: 11px;
  color: var(--ink-faint);
  font-weight: 600;
}
.bottom-nav a.active { color: var(--ink); }
.bottom-nav .icon { font-size: 20px; line-height: 1; }

/* Badges / tags */
.tag { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; letter-spacing: 0.02em; }
.tag-good { background: var(--good-soft); color: var(--good); }
.tag-warn { background: var(--warn-soft); color: var(--warn); }
.tag-accent { background: var(--accent-soft); color: var(--accent); }
.tag-muted { background: var(--line); color: var(--ink-soft); }

.muted { color: var(--ink-soft); }
.faint { color: var(--ink-faint); }
.small { font-size: 12.5px; }
.divider { height: 1px; background: var(--line); margin: 16px 0; }

/* Conversation surface */
.thread { display: flex; flex-direction: column; gap: 16px; padding: 4px 20px 16px; }
.msg-user {
  align-self: flex-end;
  background: var(--ink);
  color: var(--bg);
  padding: 12px 16px;
  border-radius: 16px 16px 4px 16px;
  max-width: 82%;
  font-size: 14.5px;
}
.msg-ai {
  align-self: flex-start;
  max-width: 92%;
  font-size: 14.5px;
  line-height: 1.5;
}
.rec-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-top: 10px;
}
.rec-card h3 { margin: 0 0 2px; font-family: var(--serif); font-size: 17px; }
.rec-why { color: var(--accent); font-size: 13px; font-weight: 600; margin: 4px 0 10px; }
.rec-price { font-size: 20px; font-weight: 700; }
.rec-meta { color: var(--ink-soft); font-size: 12.5px; margin-top: 2px; }
.reasoning {
  display: none;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.6;
}
.reasoning.open { display: block; }
.reasoning strong { color: var(--ink); }
.rec-actions { display: flex; gap: 8px; margin-top: 14px; }

.composer {
  position: sticky;
  bottom: calc(var(--nav-h) + 12px);
  padding: 10px 20px 0;
}
.composer-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 6px 6px 16px;
  box-shadow: var(--shadow);
}
.composer-box input {
  flex: 1; border: none; outline: none; background: transparent;
  font-size: 14.5px; font-family: var(--sans); color: var(--ink);
}
.composer-send {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--ink); color: var(--bg);
  border: none; font-size: 16px; cursor: pointer;
}

/* Toggle switch */
.switch { position: relative; width: 44px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; background: var(--line); border-radius: 999px; cursor: pointer; transition: background .15s;
}
.switch .track::before {
  content: ""; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.switch input:checked + .track { background: var(--good); }
.switch input:checked + .track::before { transform: translateX(18px); }

/* Empty state */
.empty { text-align: center; padding: 40px 20px; color: var(--ink-soft); }
.empty .glyph { font-size: 34px; margin-bottom: 10px; }

/* Section label */
.section-label { font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-faint); margin: 22px 0 10px; }
.section-label:first-child { margin-top: 0; }

/* Confidence dot */
.conf { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; }
.conf .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--good); }
.conf.est .dot { background: var(--ink-faint); }
.conf.est { color: var(--ink-faint); }
.conf.live { color: var(--good); }

.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; flex-shrink: 0;
}

.hero {
  height: 220px;
  border-radius: 0 0 32px 32px;
  background: linear-gradient(160deg, #E9C9A0 0%, #D98A5E 45%, #C9722B 100%);
  display: flex; align-items: flex-end;
  padding: 24px;
  color: #fff;
  margin-bottom: -30px;
}
