/* IBD Buddy — sleek modern interface, ChatGPT-inspired. */
:root {
  --bg: #ffffff;
  --sidebar: #f9f9f9;
  --ink: #0d0d0d;
  --muted: #676767;
  --faint: #a0a0a0;
  --line: #e9e9e9;
  --line-soft: #f1f1f1;
  --bubble: #f4f4f4;
  --brand: #0d0d0d;
  --accent: #147a55;
  --danger: #d92d20;
  --warn-bg: #fff8e6;
  --warn-line: #f0dfa8;
  --warn-ink: #7a5c00;
  --ok-bg: #e9f7ef;
  --ok-line: #bfe6cd;
  --radius: 10px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
.wrap { max-width: 1080px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
.narrow { max-width: 680px; margin: 0 auto; }
.wide { max-width: 960px; margin: 0 auto; }
a { color: var(--ink); }
h1 { font-size: 2rem; line-height: 1.2; margin: 0.5em 0; letter-spacing: -0.02em; font-weight: 650; }
h2 { font-size: 1.25rem; margin: 1.8em 0 0.6em; letter-spacing: -0.01em; font-weight: 650; }
.lede { font-size: 1.08rem; color: var(--muted); }
.fineprint, .hint { font-size: 0.85rem; color: var(--muted); }

/* header */
.site-header {
  display: flex; align-items: center; justify-content: space-between;
  height: 57px; padding: 0 1.25rem;
  background: rgba(255,255,255,0.85); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 50;
}
.brand { font-weight: 700; font-size: 1.05rem; text-decoration: none; color: var(--ink); letter-spacing: -0.01em; white-space: nowrap; flex-shrink: 0; }
.site-nav { display: flex; align-items: center; gap: 1.1rem; flex-wrap: nowrap; }
.site-nav a { text-decoration: none; font-size: 0.9rem; font-weight: 500; color: var(--ink); white-space: nowrap; }
.site-nav a:hover { color: var(--muted); }
.site-nav .btn { color: #fff; }
.site-nav .btn:hover { color: #fff; }
.admin-link { color: var(--accent) !important; }
.inline-form { display: inline; }
.linklike { background: none; border: none; color: var(--ink); cursor: pointer; font: inherit; font-size: 0.9rem; padding: 0; text-decoration: underline; text-underline-offset: 3px; }
.linklike.danger { color: var(--danger); }

/* buttons + forms */
.btn {
  display: inline-block; background: var(--brand); color: #fff; border: none;
  padding: 0.6rem 1.2rem; border-radius: var(--radius); font-weight: 600;
  cursor: pointer; text-decoration: none; font-size: 0.95rem; transition: background 0.15s;
}
.btn:hover { background: #2b2b2b; }
.btn-large { font-size: 1.05rem; padding: 0.85rem 2rem; border-radius: 999px; }
.btn-small { font-size: 0.85rem; padding: 0.45rem 0.9rem; }
.btn-ghost { background: #fff; color: var(--ink); border: 1px solid #d9d9d9; }
.btn-ghost:hover { background: var(--sidebar); }
.btn-danger { background: var(--danger); }
.btn-block { display: block; width: 100%; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
label { display: block; margin: 0.9rem 0; font-weight: 600; font-size: 0.95rem; }
input[type="text"], input[type="email"], input[type="password"], select, textarea {
  display: block; width: 100%; margin-top: 0.35rem; padding: 0.65rem 0.8rem;
  border: 1px solid #d9d9d9; border-radius: 8px; font: inherit; font-size: 0.95rem; background: #fff;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink); }
textarea.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; }
.field-error { border-color: var(--danger) !important; }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 1.25rem; margin: 1rem 0; background: #fff; }
legend { font-weight: 700; padding: 0 0.5rem; }

/* alerts + notices */
.alert { border-radius: var(--radius); padding: 0.8rem 1rem; margin: 1rem 0; font-size: 0.92rem; }
.alert-error { background: #fef1f0; border: 1px solid #f5c6c0; color: #912018; }
.alert-info { background: var(--ok-bg); border: 1px solid var(--ok-line); color: #14532d; }
.notice { color: var(--muted); font-style: italic; }
.draft-banner { background: var(--warn-bg); border: 1px solid var(--warn-line); color: var(--warn-ink); border-radius: 8px; padding: 0.6rem 0.8rem; font-size: 0.88rem; }
.demo-notice { background: var(--warn-bg); border: 1px solid var(--warn-line); color: var(--warn-ink); border-radius: 10px; padding: 0.55rem 0.9rem; font-size: 0.83rem; max-width: 768px; margin: 0.8rem auto 0; width: calc(100% - 2rem); }

/* hero */
.hero { text-align: center; padding: 4.5rem 1.5rem 2.5rem; max-width: 760px; margin: 0 auto; }
.hero h1 { font-size: 2.6rem; letter-spacing: -0.03em; }
.cta-row { display: flex; gap: 0.8rem; justify-content: center; margin-top: 1.8rem; flex-wrap: wrap; }
.pillars { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 1rem; margin: 3rem 0; }
.pillar { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 1.5rem; text-align: left; box-shadow: 0 1px 3px rgba(0,0,0,0.04); }
.pillar h3 { margin: 0.6rem 0 0.5rem; font-size: 1.05rem; letter-spacing: -0.01em; }
.pillar p { margin: 0; color: var(--muted); font-size: 0.95rem; }
.how { max-width: 680px; margin: 0 auto; }
.how ol { padding-left: 1.3rem; color: var(--muted); }
.how li { margin: 0.4rem 0; }

/* auth */
.auth-card { max-width: 440px; margin: 3rem auto; background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 2.25rem; box-shadow: 0 12px 40px rgba(0,0,0,0.07); }
.auth-card h1 { font-size: 1.5rem; margin-top: 0; }

/* legal */
.legal-doc { background: #fff; border: 1px solid var(--line); border-radius: 12px; margin: 1rem 0; padding: 0.4rem 1.1rem; }
.legal-doc summary { cursor: pointer; font-weight: 650; padding: 0.7rem 0; font-size: 0.95rem; }
.doc-body { max-height: 320px; overflow-y: auto; border-top: 1px solid var(--line-soft); padding: 0.9rem 0; font-size: 0.92rem; color: #333; }
.accept-line { display: flex; gap: 0.65rem; align-items: flex-start; font-weight: 600; margin: 0.9rem 0; font-size: 0.95rem; }
.accept-line input { width: auto; margin-top: 0.3rem; }

/* steps */
.steps-indicator { display: flex; gap: 0.6rem; margin: 1.2rem 0; }
.step-dot { width: 2.1rem; height: 2.1rem; border-radius: 50%; border: 2px solid var(--line); display: flex; align-items: center; justify-content: center; font-weight: 700; color: var(--faint); cursor: pointer; background: #fff; font-size: 0.9rem; }
.step-dot.active { border-color: var(--ink); color: var(--ink); }
.step-nav { display: flex; gap: 0.8rem; margin-top: 1.2rem; }

/* chat — full-bleed app */
.wrap:has(.chat-shell) { max-width: none; padding: 0; }
.wrap:has(.chat-shell) + .site-footer { display: none; }
.chat-shell { display: flex; height: calc(100dvh - 57px); min-height: 480px; background: #fff; }
.sidebar { width: 260px; flex-shrink: 0; padding: 0.85rem; display: flex; flex-direction: column; background: var(--sidebar); }
.sidebar .btn { background: #fff; color: var(--ink); border: 1px solid #e2e2e2; box-shadow: 0 1px 2px rgba(0,0,0,0.05); font-weight: 600; }
.sidebar .btn:hover { background: #f0f0f0; }
.conv-list { flex: 1; overflow-y: auto; margin-top: 0.9rem; display: flex; flex-direction: column; gap: 2px; }
.conv-row { display: flex; align-items: center; gap: 2px; }
.conv-item { flex: 1; min-width: 0; text-align: left; background: transparent; border: none; border-radius: 8px; padding: 0.55rem 0.65rem; cursor: pointer; font: inherit; font-size: 0.88rem; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item:hover { background: #ececec; }
.conv-item.active { background: #ececec; }
.conv-del { color: var(--faint); font-size: 1.05rem; padding: 0 0.2rem; background: none; border: none; cursor: pointer; }
.conv-del:hover { color: var(--danger); }
.sidebar-foot { margin-top: 0.8rem; font-size: 0.82rem; color: var(--muted); padding: 0 0.3rem; }
.sidebar-foot a { color: var(--muted); text-decoration: none; }
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: #fff; position: relative; }
.messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 1.1rem; padding: 1.5rem 1rem 1rem; max-width: 768px; width: 100%; margin: 0 auto; }
.msg { max-width: 100%; font-size: 0.98rem; }
.msg-user { display: flex; justify-content: flex-end; }
.msg-user .msg-body { background: var(--bubble); border-radius: 20px; padding: 0.6rem 1.1rem; max-width: 78%; }
.msg-assistant .msg-body { padding: 0.2rem 0; }
.msg-body p { margin: 0.45em 0; }
.msg-body p:first-child { margin-top: 0; }
.msg-body p:last-child { margin-bottom: 0; }
.msg-body img.md-img { display: block; max-width: 100%; height: auto; border-radius: 12px; margin: 0.6em auto; }
.msg-body ul, .msg-body ol { margin: 0.45em 0; padding-left: 1.35rem; }
.msg-body li { margin: 0.25em 0; }
.citations { font-size: 0.76rem; color: var(--faint); margin-top: 0.45rem; }
.typing { color: var(--faint); }
.typing::after { content: "●●●"; letter-spacing: 2px; animation: blink 1.2s infinite; font-size: 0.7em; }
@keyframes blink { 50% { opacity: 0.25; } }
.safe-tag { display: inline-block; font-size: 0.72rem; font-weight: 700; background: #fef1f0; color: var(--danger); border-radius: 6px; padding: 0.15rem 0.5rem; margin-bottom: 0.4rem; letter-spacing: 0.02em; }
.composer { display: flex; gap: 0.5rem; align-items: center; max-width: 768px; width: calc(100% - 2rem); margin: 0 auto 0.6rem; background: var(--bubble); border-radius: 28px; padding: 0.45rem 0.45rem 0.45rem 1rem; border: 1px solid transparent; transition: background 0.15s, border-color 0.15s; }
.composer:focus-within { background: #fff; border-color: #d9d9d9; box-shadow: 0 2px 12px rgba(0,0,0,0.06); }
.composer textarea { flex: 1; resize: none; margin: 0; border: none; background: transparent; padding: 0.55rem 0; font-size: 1rem; line-height: 1.5; max-height: 160px; overflow-y: auto; }
.composer textarea:focus { border: none; }
.photo-btn, .mic-btn { display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; cursor: pointer; padding: 0.45rem; border: none; background: transparent; color: var(--muted); border-radius: 50%; }
.photo-btn:hover, .mic-btn:hover { color: var(--ink); background: rgba(0,0,0,0.05); }
.photo-btn svg, .mic-btn svg { display: block; }
.mic-btn.recording { color: var(--danger); }
.mic-btn.recording svg { animation: mic-pulse 1.2s ease-in-out infinite; }
@keyframes mic-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
.no-mic .mic-btn { display: none; }
.send-btn { width: 38px; height: 38px; flex-shrink: 0; border-radius: 50%; background: var(--ink); color: #fff; border: none; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: opacity 0.15s, background 0.15s; }
.send-btn:hover { background: #2b2b2b; }
.send-btn:disabled { background: #d9d9d9; cursor: not-allowed; }
.thumb { max-width: 220px; border-radius: 12px; }
/* Read-aloud (TTS) button on assistant messages */
.msg-actions { display: none; gap: 2px; margin-top: 2px; }
.msg-complete .msg-actions { display: flex; }
.tts-btn { display: inline-flex; align-items: center; justify-content: center; padding: 6px; border: none; background: transparent; color: var(--faint); border-radius: 50%; cursor: pointer; }
.tts-btn:hover { color: var(--ink); background: rgba(0,0,0,0.05); }
.tts-btn.speaking { color: var(--accent); }
.no-tts .tts-btn { display: none; }
.usage-meter { font-size: 0.76rem; color: var(--faint); text-align: center; padding-bottom: 0.9rem; }
.usage-meter.meter-low { color: var(--danger); font-weight: 700; }
.path-strip { display: block; padding: 0.5rem 1rem; background: #eef6f2; font-size: 0.9rem; line-height: 1.5; text-align: left; text-decoration: none; border-bottom: 1px solid #dcebe3; }
.path-strip .path-main { display: block; color: inherit; text-decoration: none; }
.path-strip .care-row { cursor: pointer; }
.path-strip .care-dot { display: inline-flex; align-items: center; justify-content: center; width: 1.12rem; height: 1.12rem; margin-left: 0.5rem; border: 1.5px solid #a9c6b6; border-radius: 50%; color: transparent; font-size: 0.72rem; line-height: 1; vertical-align: -0.22rem; }
.path-strip .care-dot.done { background: var(--accent); border-color: var(--accent); color: #fff; }
.path-strip .care-hint { margin-left: 0.45rem; color: var(--muted); font-size: 0.78rem; }
.path-strip .ps-row { display: block; }
.path-strip .ps-label { color: var(--accent); font-weight: 700; }
.checkin-banner { display: flex; align-items: center; gap: 0.7rem; background: var(--ok-bg); border: 1px solid var(--ok-line); color: #14532d; border-radius: 10px; padding: 0.6rem 0.9rem; margin: 0.8rem auto 0; font-size: 0.88rem; flex-wrap: wrap; max-width: 768px; width: calc(100% - 2rem); }
.checkin-banner .btn { background: var(--ink); }
.meal-pop { max-width: 768px; width: calc(100% - 2rem); margin: 0.8rem auto 0; background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 10px 30px rgba(0,0,0,0.10); padding: 1rem 1.1rem; }
.meal-pop-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.6rem; }
.meal-pop-head strong { font-size: 1rem; }
.meal-pop-close { background: none; border: none; font-size: 1.35rem; line-height: 1; cursor: pointer; color: var(--faint); padding: 0.1rem 0.35rem; }
.meal-pills { display: flex; gap: 0.45rem; flex-wrap: wrap; margin-bottom: 0.8rem; }
.meal-pills button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 0.38rem 0.85rem; font: inherit; font-size: 0.88rem; cursor: pointer; }
.meal-pills button.selected { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.meal-pop-label { display: block; font-size: 0.88rem; font-weight: 600; margin-bottom: 0.35rem; }
.meal-pop input[type="text"] { width: 100%; border: 1px solid #d9d9d9; border-radius: 8px; padding: 0.55rem 0.7rem; font: inherit; font-size: 0.95rem; box-sizing: border-box; }
.meal-pop-hint { color: #912018; font-size: 0.85rem; margin: 0.45rem 0 0; }
.meal-pop-actions { display: flex; justify-content: flex-end; align-items: center; gap: 0.9rem; margin-top: 0.85rem; }
.meal-pop-note { color: var(--faint); font-size: 0.8rem; margin: 0.6rem 0 0; }
.log-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.drawer-toggle { display: none; }

/* pricing */
.tiers { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 1rem; margin: 1.8rem 0; }
.tier { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 1.6rem; }
.tier-current { border: 2px solid var(--ink); }
.tier ul { padding-left: 1.2rem; color: var(--muted); font-size: 0.93rem; }
.price { font-size: 2.1rem; font-weight: 700; margin: 0.3em 0; letter-spacing: -0.02em; }
.price span { font-size: 1rem; font-weight: 400; color: var(--muted); }
.current-badge { display: inline-block; background: var(--ink); color: #fff; border-radius: 999px; padding: 0.2rem 0.7rem; font-size: 0.78rem; font-weight: 650; }
.tier-intent { border: 2px solid var(--accent); }
.intent-badge { display: inline-block; background: var(--accent); color: #fff; border-radius: 999px; padding: 0.2rem 0.7rem; font-size: 0.78rem; font-weight: 650; }

/* admin */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 0.8rem; margin: 1.2rem 0; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 1rem; text-align: center; }
.stat-num { display: block; font-size: 1.8rem; font-weight: 700; letter-spacing: -0.02em; }
.stat-label { font-size: 0.83rem; color: var(--muted); }
.admin-table { width: 100%; border-collapse: collapse; margin: 1rem 0; font-size: 0.9rem; }
.admin-table th, .admin-table td { text-align: left; padding: 0.65rem 0.5rem; border-bottom: 1px solid var(--line-soft); }
.admin-table th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 650; }
.pill { display: inline-block; border-radius: 999px; padding: 0.12rem 0.65rem; font-size: 0.76rem; font-weight: 650; }
.pill-draft { background: #f4f4f4; color: var(--muted); }
.pill-published { background: var(--ok-bg); color: #14532d; }
.section-h { margin-top: 2.2rem; border-bottom: 1px solid var(--line); padding-bottom: 0.4rem; font-size: 1.15rem; }
.row-actions { white-space: nowrap; }
.row-actions > * { margin-right: 0.7rem; font-size: 0.88rem; }
.version-list { list-style: none; padding: 0; }
.version-list li { display: flex; justify-content: space-between; align-items: center; padding: 0.65rem 0.2rem; border-bottom: 1px solid var(--line-soft); font-size: 0.92rem; }

/* footer */
.site-footer { text-align: center; color: var(--muted); font-size: 0.83rem; padding: 2.5rem 1.25rem; border-top: 1px solid var(--line); margin-top: 2.5rem; }
.site-footer a { color: var(--muted); }

/* markdown bits */
.md-h { margin: 0.8em 0 0.4em; }

/* mobile */
@media (max-width: 820px) {
  .chat-shell { height: calc(100dvh - 57px); position: relative; }
  .sidebar {
    position: absolute; left: 0; top: 0; bottom: 0; z-index: 20;
    transform: translateX(-105%); transition: transform 0.25s ease;
    box-shadow: 2px 0 16px rgba(0,0,0,0.1); border-right: 1px solid var(--line);
  }
  .sidebar.open { transform: translateX(0); }
  .drawer-toggle {
    display: flex; align-items: center; justify-content: center;
    position: absolute; left: 0.7rem; top: 0.7rem; z-index: 30;
    width: 38px; height: 38px; background: #fff; border: 1px solid var(--line); border-radius: 10px;
    font-size: 1.15rem; cursor: pointer; color: var(--ink);
  }
  /* The toggle floats over the path strip's top-left corner — indent the
     strip on mobile so its labels are never clipped by the button. */
  .path-strip { padding-left: 3.6rem; }
  .messages { padding-top: 3rem; }
  .msg-user .msg-body { max-width: 88%; }
  .hero { padding: 3rem 1.25rem 2rem; }
  .hero h1 { font-size: 2rem; }
  .site-header { padding: 0 0.75rem; }
  .site-nav { gap: 0.7rem; }
  .site-nav a { font-size: 0.85rem; }
  .auth-card { margin: 1.5rem auto; padding: 1.75rem; }
}

/* Checkbox rows (consent opt-in) */
label.check { display: flex; gap: 0.75rem; align-items: flex-start; cursor: pointer; }
.pw-show { margin-top: 0.4rem; font-size: 0.88rem; color: var(--muted); }
label.check input[type="checkbox"] { width: 1.15rem; height: 1.15rem; margin-top: 0.15rem; flex-shrink: 0; accent-color: #111; }
label.check .hint { display: block; margin-top: 0.25rem; font-weight: normal; }

/* Food tests */
.test-list { list-style: none; padding: 0; margin: 1.5rem 0; display: flex; flex-direction: column; gap: 1rem; }
.test-card { border: 1px solid #e5e5e5; border-radius: 12px; padding: 1rem 1.25rem; background: #fff; }
.test-card .test-head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; margin-bottom: 0.5rem; }
.test-card .test-food { font-weight: 600; font-size: 1.05rem; }
.test-card .test-date { color: #666; font-size: 0.85rem; }
.pill { display: inline-block; padding: 0.2rem 0.7rem; border-radius: 999px; font-size: 0.8rem; font-weight: 600; }
.pill-testing { background: #eef2ff; color: #3730a3; }
.pill-pass { background: #ecfdf5; color: #047857; }
.pill-fail { background: #fef2f2; color: #b91c1c; }
.pill-ambiguous { background: #fffbeb; color: #b45309; }
.test-card form { margin-top: 0.75rem; }
.test-card .row { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: flex-end; }
.test-card select, .test-card textarea { font: inherit; }
.test-card textarea { width: 100%; margin-top: 0.5rem; }
.inline-form { display: inline; }

/* Plate risk card (personal, per-photo) */
.risk-card { border: 1px solid #e5e5e5; border-radius: 10px; padding: 0.7rem 0.9rem; margin-top: 0.6rem; font-size: 0.88rem; background: #fafafa; }
.risk-card .risk-head { font-size: 0.95rem; margin-bottom: 0.4rem; }
.risk-card ul { margin: 0.3rem 0; padding-left: 1.1rem; }
.risk-card li { margin: 0.15rem 0; }
.risk-card .risk-num { font-variant-numeric: tabular-nums; }
.risk-low { border-left: 4px solid #16a34a; }
.risk-moderate { border-left: 4px solid #d97706; }
.risk-high { border-left: 4px solid #dc2626; }

/* Log-a-meal shortcut button */
.log-btn { border: 1px solid #ddd; background: #fff; border-radius: 999px; padding: 0.3rem 0.6rem; font-size: 0.78rem; color: #444; cursor: pointer; }
.log-btn:hover { background: #f4f4f4; }

/* Gut check (one-tap status before plate risk score) */
.gut-check { border: 1px solid #e5e5e5; border-radius: 10px; padding: 0.7rem 0.9rem; margin-top: 0.5rem; }
.gut-check p { margin: 0 0 0.5rem; }
.gut-btns { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.gut-btn { border: 1px solid #ccc; background: #fff; border-radius: 999px; padding: 0.35rem 0.9rem; cursor: pointer; font-size: 0.9rem; }
.gut-btn:hover { background: #f4f4f4; }
.gut-skip { border-style: dashed; color: #666; }
