/* ==========================================================================
   Sorenza design system: one stylesheet for every page.
   Dark "noir" by default, light when the phone/laptop is set to light mode.
   Mobile first: bottom tab bar on phones, top bar on bigger screens.
   ========================================================================== */
:root {
  --bg: #0c0c0f;
  --surface: #16161b;
  --surface-2: #1f1f26;
  --surface-3: #2a2a33;
  --border: #2a2a33;
  --text: #eeede8;
  --muted: #9b99a5;
  --faint: #6c6a75;
  --accent: #d9a74f;          /* warm gold, like a jazz club lamp */
  --accent-soft: rgba(217, 167, 79, .14);
  --accent-text: #1b1407;
  --good: #6fcf97;
  --good-soft: rgba(111, 207, 151, .14);
  --bad: #ef8a7d;
  --bad-soft: rgba(239, 138, 125, .14);
  --warn: #f2c94c;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 8px 30px rgba(0, 0, 0, .35);
  --tabbar-h: 64px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f5f0;
    --surface: #ffffff;
    --surface-2: #f0ede6;
    --surface-3: #e6e2d8;
    --border: #e3dfd5;
    --text: #1d1b18;
    --muted: #6b6760;
    --faint: #9a958b;
    --accent: #a8741c;
    --accent-soft: rgba(168, 116, 28, .12);
    --accent-text: #ffffff;
    --good: #1e8a4c;
    --good-soft: rgba(30, 138, 76, .1);
    --bad: #c2412f;
    --bad-soft: rgba(194, 65, 47, .1);
    --warn: #a67c00;
    --shadow: 0 8px 30px rgba(60, 50, 30, .1);
    color-scheme: light;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
h1, h2, h3 { line-height: 1.25; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 13px; }
code { font-family: var(--mono); font-size: .9em; overflow-wrap: anywhere; }   /* long paths wrap instead of widening the page */
main { overflow-wrap: break-word; }
[hidden] { display: none !important; }

/* --- Top bar ----------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.brand-mark {
  width: 30px; height: 30px; border-radius: 50%;
  border: 2.5px solid var(--accent); display: grid; place-items: center; flex: none;
}
.brand-mark::after { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.brand-name { font-weight: 650; letter-spacing: .3px; font-size: 17px; }
.brand-sub { font-size: 12px; color: var(--muted); display: block; margin-top: -2px; }
.topbar .spacer { flex: 1; }
.topnav { display: none; gap: 4px; }

/* --- Bottom tab bar (phones) ------------------------------------------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-top: 1px solid var(--border);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; color: var(--faint); text-decoration: none; font-size: 11px; font-weight: 550;
  min-height: 44px;
}
.tab svg { width: 24px; height: 24px; }
.tab.active { color: var(--accent); }

@media (min-width: 760px) {
  body { padding-bottom: 0; }
  .tabbar { display: none; }
  .topnav { display: flex; }
  .topnav .tab {
    flex-direction: row; gap: 7px; font-size: 14px; padding: 8px 14px; border-radius: 999px;
    color: var(--muted);
  }
  .topnav .tab svg { width: 18px; height: 18px; }
  .topnav .tab:hover { background: var(--surface-2); color: var(--text); }
  .topnav .tab.active { background: var(--accent-soft); color: var(--accent); }
}

/* --- Layout + common pieces --------------------------------------------- */
main { max-width: 760px; margin: 0 auto; padding: 18px 16px 32px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 6px 0 18px; }
.page-head h1 { font-size: 26px; margin: 0; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 999px;
  font: inherit; font-size: 15px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  transition: transform .08s ease, background .15s ease, opacity .15s;
  white-space: nowrap; flex: none;     /* button labels never break mid-word */
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 13px; }
.btn.ghost { background: transparent; }
.btn svg { width: 18px; height: 18px; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; margin-bottom: 14px;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 999px; font-size: 12.5px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.chip.gold { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chip.good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.chip.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.chip svg { width: 13px; height: 13px; }

.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty .big { font-size: 40px; margin-bottom: 8px; }

input[type=text], input[type=password], input[type=url], textarea, select {
  width: 100%; font: inherit; font-size: 16px; color: var(--text);   /* 16px stops iOS zoom */
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 11px 14px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label { font-size: 13px; color: var(--muted); display: block; margin: 12px 0 6px; }

/* Rich text from Claude */
.prose p { margin: 0 0 10px; } .prose p:last-child { margin-bottom: 0; }
.prose ul, .prose ol { margin: 4px 0 10px; padding-left: 22px; }
.prose li { margin: 3px 0; }
.prose h3 { font-size: 15px; margin: 14px 0 6px; color: var(--accent); text-transform: uppercase; letter-spacing: .6px; }
.prose h3:first-child { margin-top: 0; }
.prose code { font-family: var(--mono); font-size: .9em; background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }

/* Skeleton loading shimmer */
.skeleton { position: relative; overflow: hidden; background: var(--surface-2); border-radius: 8px; }
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--text) 6%, transparent), transparent);
  animation: shimmer 1.3s infinite;
}
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
.sk-line { height: 12px; margin: 10px 0; }

/* Toasts */
#toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); z-index: 50; display: grid; gap: 8px; width: min(92vw, 420px); }
@media (min-width: 760px) { #toasts { bottom: 24px; } }
.toast {
  background: var(--surface-3); color: var(--text); border: 1px solid var(--border);
  padding: 12px 16px; border-radius: 14px; box-shadow: var(--shadow); font-size: 14px;
  animation: pop .2s ease;
}
.toast.bad { border-color: var(--bad); }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* --- Chat ---------------------------------------------------------------- */
.chat { display: flex; flex-direction: column; min-height: calc(100dvh - 60px - var(--tabbar-h)); }
@media (min-width: 760px) { .chat { min-height: calc(100dvh - 60px); } }
#messages { flex: 1; max-width: 760px; width: 100%; margin: 0 auto; padding: 16px 16px 8px; }
.msg { display: flex; flex-direction: column; margin: 12px 0; animation: pop .18s ease; }
.msg .bubble { max-width: 86%; padding: 11px 15px; border-radius: 20px; overflow-wrap: anywhere; }
.msg.you { align-items: flex-end; }
.msg.you .bubble { background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 6px; }
.msg.her .bubble { background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 6px; }
.msg .meta { margin-top: 6px; padding: 0 4px; }
.msg.error .bubble { border-color: var(--bad); }
.typing { display: inline-flex; gap: 5px; padding: 4px 2px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .15s; } .typing span:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.welcome { text-align: center; padding: 8vh 8px 12px; }
.welcome .brand-mark { width: 56px; height: 56px; margin: 0 auto 14px; border-width: 4px; }
.welcome .brand-mark::after { width: 16px; height: 16px; }
.welcome h1 { font-size: 24px; margin: 0 0 6px; }
.welcome p { color: var(--muted); margin: 0 0 22px; }
.suggestions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; max-width: 520px; margin: 0 auto; }
.suggestion {
  text-align: left; padding: 12px 14px; border-radius: 14px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); color: var(--text); font: inherit; font-size: 14px;
}
.suggestion:hover { border-color: var(--accent); }
.suggestion b { display: block; font-size: 13px; color: var(--accent); margin-bottom: 2px; font-weight: 600; }

.composer-wrap {
  position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); z-index: 10;
  background: linear-gradient(transparent, var(--bg) 30%); padding: 14px 12px 10px;
}
@media (min-width: 760px) { .composer-wrap { bottom: 0; padding-bottom: 18px; } }
.composer {
  display: flex; gap: 8px; align-items: flex-end; max-width: 760px; margin: 0 auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 26px; padding: 6px 6px 6px 16px;
  box-shadow: var(--shadow);
}
.composer:focus-within { border-color: var(--accent); }
.composer textarea { border: 0; background: transparent; padding: 9px 0; resize: none; max-height: 160px; box-shadow: none; }
.composer .send { width: 44px; height: 44px; min-height: 0; padding: 0; flex: none; }

/* --- Kitchen ------------------------------------------------------------- */
.meal h2 { margin: 0 0 6px; font-size: 19px; }
.meal .why { color: var(--muted); margin: 0 0 12px; font-size: 15px; }
.meal .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.meal .recipe { margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--border); }
.callout { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 14px; background: var(--accent-soft); color: var(--text); margin-bottom: 16px; font-size: 15px; }
.callout svg { width: 20px; height: 20px; color: var(--accent); flex: none; margin-top: 2px; }

/* --- Login --------------------------------------------------------------- */
.login { max-width: 380px; margin: 0 auto; padding: 14vh 20px 40px; text-align: center; }
.login .brand-mark { width: 64px; height: 64px; margin: 0 auto 18px; border-width: 4px; }
.login .brand-mark::after { width: 18px; height: 18px; }
.login h1 { font-size: 30px; margin: 0 0 4px; }
.login form { display: grid; gap: 12px; margin-top: 28px; text-align: left; }
.login .btn { width: 100%; }
.error-text { color: var(--bad); font-size: 14px; min-height: 20px; margin: 0; }

/* --- Dev mode ------------------------------------------------------------ */
.segmented {
  display: flex; gap: 4px; overflow-x: auto; padding: 4px; margin: 0 -4px 18px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  scrollbar-width: none;
}
.segmented::-webkit-scrollbar { display: none; }
.segmented button {
  flex: none; border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 14px;
  padding: 8px 14px; border-radius: 10px; cursor: pointer; min-height: 38px; white-space: nowrap;
}
.segmented button.active { background: var(--surface-3); color: var(--text); font-weight: 600; }
.list { display: grid; gap: 8px; }
.item {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
}
.item .dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 7px; flex: none; background: var(--faint); }
.item .dot.ok { background: var(--good); } .item .dot.fail { background: var(--bad); } .item .dot.run { background: var(--warn); animation: blink 1s infinite; }
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 600; }
.item .detail { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px; }
.stat .v { font-size: 24px; font-weight: 700; }
.stat .l { font-size: 12.5px; color: var(--muted); }
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > div { height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }
pre.code {
  font-family: var(--mono); font-size: 12.5px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere;
  background: var(--surface-2); border-radius: 12px; padding: 12px; margin: 8px 0 0; max-height: 420px; overflow: auto;
}
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12.5px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
table.data td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table-wrap { overflow-x: auto; }
.row-flex { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 600px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.shots { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-top: 10px; }
.shots img { width: 100%; border-radius: 10px; border: 1px solid var(--border); }
details.trace { margin-top: 8px; }
details.trace summary { cursor: pointer; color: var(--muted); font-size: 13px; }

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