/* ═══════════════════════════════════════════════════════════════════════
   EMBERFAST — Modern Light Interface
   ═══════════════════════════════════════════════════════════════════════ */

:root {
  --bg: #f0f4f8;
  --panel: #ffffff;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --text: #0f172a;
  --text-dim: #64748b;
  --text-faint: #94a3b8;
  --accent: #e8622a;
  --accent-hot: #c84f1a;
  --accent-soft: #f4a259;
  --accent-bg: #fff7ed;
  --accent-border: #fed7aa;
  --green: #059669;
  --green-bg: #ecfdf5;
  --gold: #f6b73c;
  --gold-deep: #d98a12;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(15,23,42,.05);
  --shadow: 0 1px 3px rgba(15,23,42,.08), 0 1px 2px rgba(15,23,42,.04);
  --shadow-md: 0 4px 16px rgba(15,23,42,.08), 0 2px 4px rgba(15,23,42,.04);
  --font-body: "Inter", system-ui, -apple-system, sans-serif;
  --font-mono: "Spline Sans Mono", ui-monospace, monospace;
  --sidebar-w: 240px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100dvh;
  overflow-x: hidden;
}

/* ── app shell ────────────────────────────────────────────────────────────── */
.app-shell {
  display: flex;
  min-height: 100dvh;
}

/* ── sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 12px 16px;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 50;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 8px 18px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border-light);
}
.sidebar-brand img { width: 30px; height: 30px; border-radius: 8px; }
.sidebar-brand-name {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text);
}
.sidebar-brand-name em { font-style: normal; color: var(--accent); }

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: 8px;
}

.snav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: 10px;
  border: none;
  background: none;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-dim);
  text-align: left;
  width: 100%;
  transition: background .12s ease, color .12s ease;
}
.snav-item:hover { background: var(--bg); color: var(--text); }
.snav-item.active {
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 600;
}
.snav-ic {
  width: 20px;
  font-size: 16px;
  line-height: 1;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  gap: 8px;
}


.sidebar-level-pill {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12.5px;
  font-family: var(--font-mono);
  color: var(--text-dim);
  cursor: pointer;
  transition: border-color .12s, color .12s;
}
.sidebar-level-pill:hover { border-color: var(--accent-border); color: var(--accent); }

/* ── main area ────────────────────────────────────────────────────────────── */
.main-area {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ── top bar (mobile only) ────────────────────────────────────────────────── */
.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand-mark { width: 28px; height: 28px; }
.brand-name {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.2px;
  color: var(--text);
}
.brand-name em { font-style: normal; color: var(--accent); }

.chips { display: flex; gap: 7px; }
.chip {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 11px;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.chip:hover { background: var(--accent-bg); color: var(--accent); border-color: var(--accent-border); }

/* ── views ────────────────────────────────────────────────────────────────── */
#views {
  flex: 1;
  max-width: 680px;
  margin: 0 auto;
  padding: 28px 28px 48px;
  width: 100%;
}
.view { display: none; }
.view.active { display: block; animation: rise .35s cubic-bezier(.2,.7,.2,1) both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.view-title {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.5px;
  margin: 0 0 4px;
  color: var(--text);
}
.view-title em { font-style: normal; color: var(--accent); }
.view-sub { color: var(--text-dim); margin: 0 0 20px; font-size: 14px; max-width: 52ch; }
.section-h { font-size: 16px; font-weight: 700; margin: 26px 0 12px; color: var(--text); }

/* ── card ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}
.muted { color: var(--text-dim); }
.tiny { font-size: 12.5px; }
code { font-family: var(--font-mono); color: var(--accent); font-size: 0.88em; }

/* ── the ring ─────────────────────────────────────────────────────────────── */
.ring-wrap {
  position: relative;
  width: min(272px, 80vw);
  margin: 10px auto 8px;
}
#ring { width: 100%; height: auto; display: block; }
.ring-track { fill: none; stroke: var(--border); stroke-width: 13; }
#ring-progress {
  fill: none;
  stroke: url(#emberGrad);
  stroke-width: 13;
  stroke-linecap: round;
  transition: stroke-dashoffset .8s cubic-bezier(.2,.7,.2,1);
  filter: drop-shadow(0 0 6px rgba(232,98,42,.28));
}
#ring-markers line { stroke: var(--text-faint); stroke-width: 2; }
#ring-markers text { fill: var(--text-faint); font-family: var(--font-mono); font-size: 9.5px; }
#ring-dot { filter: drop-shadow(0 0 4px rgba(232,98,42,.5)); }

/* ── extended / past-goal overflow arc ─────────────────────────────────────
   A second arc that grows clockwise from the goal point (top) in a richer
   gold, sitting on top of the now-full ember ring. Hidden until the fast
   passes its goal window. */
#ring-overflow {
  fill: none;
  stroke: url(#overflowGrad);
  stroke-width: 13;
  stroke-linecap: round;
  opacity: 0;
  pointer-events: none;
  transition: stroke-dashoffset .8s cubic-bezier(.2,.7,.2,1), opacity .5s ease;
  filter: drop-shadow(0 0 7px rgba(246,183,60,.45));
}
#ring.extended #ring-overflow { opacity: 1; }
#ring.extended #ring-dot {
  fill: var(--gold);
  filter: drop-shadow(0 0 6px rgba(246,183,60,.7));
}
.ring-state.extended { color: var(--gold-deep); }

/* Reward the user for beating the goal with a gentle pulse/glow — but only
   when the user hasn't asked the system to reduce motion. */
@media (prefers-reduced-motion: no-preference) {
  #ring.extended #ring-overflow { animation: overflowPulse 2.6s ease-in-out infinite; }
  #ring.extended #ring-dot { animation: dotPulse 2.6s ease-in-out infinite; }
}
@keyframes overflowPulse {
  0%, 100% { filter: drop-shadow(0 0 5px rgba(246,183,60,.35)); }
  50%      { filter: drop-shadow(0 0 12px rgba(246,183,60,.75)); }
}
@keyframes dotPulse {
  0%, 100% { filter: drop-shadow(0 0 5px rgba(246,183,60,.55)); opacity: .92; }
  50%      { filter: drop-shadow(0 0 13px rgba(246,183,60,.95)); opacity: 1; }
}

.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 2px;
  /* 18% each side → 64% available ≈ 174px at 272px container.
     Inner clear diameter is 195px (259/360 of container), so this leaves
     ~10px of visual gap between the longest text line and the ring stroke.
     Scales proportionally as ring-wrap shrinks on narrow viewports. */
  padding: 0 18%;
  box-sizing: border-box;
}
.ring-state {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 3.5px;
  color: var(--accent);
  font-weight: 700;
  text-transform: uppercase;
}
.ring-state.eating { color: var(--green); }
.ring-time {
  font-family: var(--font-mono);
  font-weight: 700;
  /* ceiling 30px: "17:07:28" (8 mono chars × 18px) = 144px — 15px gap inside 174px box */
  font-size: clamp(22px, 7vw, 30px);
  letter-spacing: 0;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.ring-sub { color: var(--text-dim); font-size: 11px; line-height: 1.4; }

/* ── countdown ────────────────────────────────────────────────────────────── */
.countdown {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 14px 20px;
}
.countdown-label { color: var(--text-dim); font-size: 14px; }
.countdown-time {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

/* ── actions & buttons ────────────────────────────────────────────────────── */
.actions { display: flex; gap: 10px; margin: 4px 0 12px; flex-wrap: wrap; }
.btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 18px;
  cursor: pointer;
  flex: 1;
  min-width: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .12s ease, transform .1s ease, box-shadow .12s ease;
  box-shadow: var(--shadow-sm);
}
.btn:hover { background: var(--bg); }
.btn:active { transform: scale(.98); }
.btn-primary {
  background: var(--accent);
  color: #ffffff;
  border: none;
  box-shadow: 0 4px 14px rgba(232,98,42,.28);
}
.btn-primary:hover { background: var(--accent-hot); box-shadow: 0 4px 18px rgba(232,98,42,.38); }
.btn-small { flex: 0 0 auto; min-width: 0; padding: 7px 14px; font-size: 13px; white-space: nowrap; }
.btn[disabled] { opacity: .5; cursor: wait; }
.btn-row { display: flex; gap: 10px; margin-top: 12px; }

/* ── stage card ───────────────────────────────────────────────────────────── */
.stage-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 10px; }
.stage-dot {
  width: 12px; height: 12px; border-radius: 50%; margin-top: 6px; flex-shrink: 0;
  background: var(--accent);
  box-shadow: 0 0 8px rgba(232,98,42,.45);
}
.stage-kicker {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 2px;
  color: var(--text-faint);
  text-transform: uppercase;
}
.stage-name {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin: 3px 0 0;
  letter-spacing: -0.3px;
}
.stage-benefits { margin: 8px 0 14px; padding: 0; list-style: none; }
.stage-benefits li {
  padding: 6px 0 6px 24px;
  position: relative;
  color: var(--text-dim);
  font-size: 14px;
}
.stage-benefits li::before {
  content: "✦";
  position: absolute;
  left: 2px;
  top: 8px;
  color: var(--accent);
  font-size: 10px;
}
.next-tip {
  border-left: 3px solid var(--accent);
  background: var(--accent-bg);
  border-radius: 0 8px 8px 0;
  padding: 10px 14px;
  font-size: 14px;
  color: var(--text-dim);
}
.next-tip strong { color: var(--accent); }

/* ── plan ─────────────────────────────────────────────────────────────────── */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
}
.toggle-row input { display: none; }
.switch {
  width: 44px; height: 24px;
  border-radius: 999px;
  background: var(--border);
  position: relative;
  transition: background .2s;
  flex-shrink: 0;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.15);
  transition: transform .2s;
}
.toggle-row input:checked + .switch { background: var(--accent); }
.toggle-row input:checked + .switch::after { transform: translateX(20px); }

.day-editor {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 10px;
  align-items: center;
  padding: 12px 16px;
  margin-bottom: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.day-editor .day-name { font-weight: 600; font-size: 14px; }
.day-editor .fast-len { font-family: var(--font-mono); font-size: 11px; color: var(--text-faint); grid-column: 1; }
.day-editor input[type="time"] {
  font-family: var(--font-mono);
  font-size: 13.5px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  outline: none;
  transition: border-color .12s;
}
.day-editor input[type="time"]:focus { border-color: var(--accent); }
.day-editor .arrow { color: var(--text-faint); }
.goal-row { display: flex; align-items: center; gap: 14px; margin-top: 8px; }
.goal-row input[type="range"] { flex: 1; accent-color: var(--accent); }
.goal-value { font-family: var(--font-mono); font-weight: 700; color: var(--accent); }
.sync-card h3, .sync-card-h { margin: 0 0 4px; font-size: 16px; font-weight: 700; }
.sync-status { font-family: var(--font-mono); font-size: 12.5px; color: var(--green); margin: 8px 0 2px; }
.sync-status.dirty { color: var(--accent); }

/* ── tier selector (experience level) ─────────────────────────────────────── */
.tier-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.tier-btn {
  text-align: left;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  transition: border-color .12s, background .12s;
  font-family: var(--font-body);
  width: 100%;
}
.tier-btn:hover { border-color: var(--accent-border); background: var(--accent-bg); }
.tier-btn.selected { border-color: var(--accent); background: var(--accent-bg); }
.tier-btn .tier-name { font-size: 13px; font-weight: 700; color: var(--text); line-height: 1.3; }
.tier-btn.selected .tier-name { color: var(--accent); }
.tier-btn .tier-range { font-family: var(--font-mono); font-size: 10px; color: var(--text-faint); margin-top: 3px; }
.tier-btn.selected .tier-range { color: var(--accent-soft); }
.tier-btn .tier-desc { font-size: 11.5px; color: var(--text-dim); margin-top: 5px; line-height: 1.4; }

/* ── journey ──────────────────────────────────────────────────────────────── */
.level-row { display: flex; justify-content: space-between; align-items: flex-end; }
.level-kicker {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 2.5px;
  color: var(--text-faint);
  text-transform: uppercase;
}
.level-name {
  font-size: 24px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.4px;
  margin-top: 2px;
}
.level-xp { font-family: var(--font-mono); font-size: 13px; color: var(--text-dim); }
.xp-bar { height: 6px; border-radius: 99px; background: var(--bg); margin: 12px 0 6px; overflow: hidden; border: 1px solid var(--border-light); }
.xp-fill {
  height: 100%;
  border-radius: 99px;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-soft), var(--accent));
  transition: width .6s ease;
}
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}
.stat .v {
  font-family: var(--font-mono);
  font-size: 21px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.stat .k { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.stat.sage .v { color: var(--green); }

.summary-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.summary-head h3 { margin: 0; font-size: 15px; font-weight: 700; }
.ai-summary { white-space: pre-wrap; color: var(--text-dim); font-size: 14px; line-height: 1.65; }
.ai-summary.loading { animation: pulse 1.2s ease infinite; }
@keyframes pulse { 50% { opacity: .4; } }

.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 10px; }
.badge {
  text-align: center;
  padding: 14px 8px 12px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.badge .ic {
  width: 42px; height: 42px;
  margin: 0 auto 8px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 18px;
  background: var(--bg);
  color: var(--text-faint);
  border: 1px solid var(--border);
}
.badge.earned .ic {
  background: linear-gradient(135deg, var(--accent-soft), var(--accent));
  color: #fff;
  box-shadow: 0 4px 12px rgba(232,98,42,.3);
  border: none;
}
.badge .n { font-size: 11.5px; font-weight: 700; color: var(--text); }
.badge .d { font-size: 10px; color: var(--text-faint); }
.badge.earned .n { color: var(--accent); }

.fast-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 16px;
  margin-bottom: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  font-size: 14px;
}
.fast-row .dur { font-family: var(--font-mono); font-weight: 700; color: var(--accent); flex-shrink: 0; }
.fast-row .when {
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
  min-width: 0;
  font-size: 12px;
  margin: 0 6px;
}
.fast-row .when span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fast-row .del { background: none; border: none; color: var(--text-faint); cursor: pointer; font-size: 15px; padding: 4px; }
.fast-row .del:hover { color: var(--red); }
.fast-row .edit { background: none; border: none; color: var(--text-faint); cursor: pointer; font-size: 14px; padding: 4px; }
.fast-row .edit:hover { color: var(--accent); }
.dialog-field-label { margin: 8px 0 0; font-size: 12px; font-weight: 600; color: var(--text-dim); }

/* ── learn ────────────────────────────────────────────────────────────────── */
.guide { margin-bottom: 10px; }
.guide summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 15.5px;
}
.guide summary::-webkit-details-marker { display: none; }
.guide summary::after { content: "+"; color: var(--accent); font-size: 20px; transition: transform .2s; font-weight: 400; }
.guide[open] summary::after { transform: rotate(45deg); }
.guide .intro { color: var(--text-dim); font-size: 14px; margin: 10px 0; }
.food-list { margin: 0; padding: 0; list-style: none; }
.food-list li { padding: 7px 0; border-top: 1px solid var(--border-light); font-size: 14px; }
.food-list b { color: var(--accent); }
.food-list span { color: var(--text-dim); }
.guide .avoid {
  margin-top: 12px;
  padding: 10px 13px;
  border-radius: 8px;
  font-size: 13.5px;
  background: var(--red-bg);
  border-left: 3px solid var(--red);
  color: var(--red);
}
.recipe-steps { margin: 0; padding-left: 20px; }
.recipe-steps li { padding: 4px 0; color: var(--text-dim); font-size: 14px; }
.guide .why { margin-top: 12px; font-size: 14px; color: var(--green); }
.learn-stage {
  display: flex;
  gap: 14px;
  padding: 13px 0;
  border-bottom: 1px solid var(--border-light);
}
.learn-stage .hours {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  min-width: 58px;
  padding-top: 3px;
  color: var(--accent);
}
.learn-stage h4 { margin: 0; font-size: 15px; font-weight: 700; color: var(--text); }
.learn-stage p { margin: 3px 0 0; font-size: 13.5px; color: var(--text-dim); }

/* ── inline link button ───────────────────────────────────────────────────── */
.btn-link {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font-family: var(--font-body);
  font-size: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.btn-link:hover { color: var(--accent-hot); }
.fast-log-more { text-align: center; margin-top: 6px; }

/* ── chat ─────────────────────────────────────────────────────────────────── */
.chat-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.chat-log { display: flex; flex-direction: column; gap: 10px; margin: 14px 0; min-height: 200px; }
.msg {
  max-width: 85%;
  padding: 11px 15px;
  border-radius: 14px;
  font-size: 14.5px;
  white-space: pre-wrap;
  animation: rise .3s ease both;
  line-height: 1.55;
}
.msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.assistant {
  align-self: flex-start;
  background: var(--panel);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
.msg.thinking { color: var(--text-faint); animation: pulse 1.2s ease infinite; }
.msg.error { background: var(--red-bg); border-color: var(--red); color: var(--red); }
.msg-journey-req { font-size: 13px; opacity: .8; }
.chat-form {
  display: flex;
  gap: 8px;
  position: sticky;
  bottom: calc(72px + env(safe-area-inset-bottom));
  background: var(--bg);
}
.chat-form input {
  flex: 1;
  min-width: 0;
  font-family: var(--font-body);
  font-size: 14.5px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 16px;
  outline: none;
  box-shadow: var(--shadow-sm);
  transition: border-color .12s, box-shadow .12s;
}
.chat-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(232,98,42,.1);
}
.chat-form .btn { flex: 0; min-width: 56px; display: flex; align-items: center; justify-content: center; }
.btn-attach {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 17px;
  cursor: pointer;
  background: var(--panel);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  flex-shrink: 0;
  transition: border-color .12s;
}
.btn-attach:hover { border-color: var(--accent); }
.chat-attach-preview {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
  padding: 8px;
  background: var(--panel);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
}
.chat-attach-preview img {
  max-width: 120px;
  max-height: 80px;
  border-radius: 6px;
  object-fit: cover;
}
.btn-remove-attach {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 18px;
  line-height: 1;
  padding: 0 2px;
  transition: color .12s;
}
.btn-remove-attach:hover { color: var(--red); }
.msg-with-image {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-self: flex-end;
  max-width: 85%;
  background: var(--accent);
  color: #fff;
  border-radius: 16px;
  border-bottom-right-radius: 4px;
  padding: 8px;
}
.msg-image {
  max-width: 200px;
  max-height: 150px;
  border-radius: 8px;
  object-fit: cover;
  display: block;
}
.msg-text {
  padding: 3px 7px 3px;
  font-size: 14px;
  line-height: 1.55;
}

/* ── bottom nav (mobile only) ─────────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 50;
  display: flex;
  justify-content: space-around;
  background: rgba(255,255,255,.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 8px 4px calc(8px + env(safe-area-inset-bottom));
}
.bottom-nav button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-faint);
  padding: 5px 12px;
  border-radius: 10px;
  transition: color .12s;
}
.bottom-nav button .nav-ic { font-size: 17px; line-height: 1; }
.bottom-nav button.active { color: var(--accent); }

/* ── toast & dialog ───────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: #fff;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: all .3s ease;
  z-index: 60;
  box-shadow: var(--shadow-md);
  max-width: 88vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.toast--update { pointer-events: auto; cursor: pointer; }

.dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 360px;
  width: 88vw;
  box-shadow: var(--shadow-md);
}
.dialog::backdrop { background: rgba(15,23,42,.35); backdrop-filter: blur(4px); }
.dialog h3 { margin: 0 0 6px; font-size: 17px; font-weight: 700; }
.dialog input[type="datetime-local"] {
  width: 100%;
  font-family: var(--font-mono);
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  margin-top: 10px;
  font-size: 14px;
  outline: none;
  transition: border-color .12s;
}
.dialog input[type="datetime-local"]:focus { border-color: var(--accent); }

/* ── responsive ───────────────────────────────────────────────────────────── */
@media (min-width: 700px) {
  body { padding-bottom: 0; }
  .sidebar { display: flex; }
  .topbar { display: none; }
  .bottom-nav { display: none; }
  .chat-form { bottom: 24px; }
  .toast { bottom: 24px; }
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  #views { padding: 30px 36px 52px; }
}

@media (max-width: 699px) {
  .sidebar { display: none; }
  .main-area { margin-left: 0; }
  body { padding-bottom: calc(70px + env(safe-area-inset-bottom)); }
  .topbar { display: flex; }
  .bottom-nav { display: flex; }
  #views { padding: 16px 16px 32px; }
  .chat-form { margin: 0 -16px; padding: 8px 16px; }
}

/* ── dark theme ────────────────────────────────────────────────────────────── */
html[data-theme="dark"] {
  --bg: #0f172a;
  --panel: #1e293b;
  --border: #334155;
  --border-light: #243046;
  --text: #f1f5f9;
  --text-dim: #94a3b8;
  --text-faint: #64748b;
  --accent-bg: #2d1a0e;
  --accent-border: #7c3a1c;
  --green-bg: #022c22;
  --red-bg: #2d0a0a;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.25);
  --shadow-md: 0 4px 16px rgba(0,0,0,.5), 0 2px 4px rgba(0,0,0,.3);
}
/* Elements with hard-coded colours that need dark-mode overrides */
html[data-theme="dark"] .bottom-nav { background: rgba(15,23,42,.95); }
html[data-theme="dark"] .toast { background: #e2e8f0; color: #0f172a; }

/* ── version string ────────────────────────────────────────────────────────── */
.version-str {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  text-align: center;
  padding: 6px 0 0;
  letter-spacing: 0.02em;
  min-height: 1em;
}
.version-str-mobile {
  padding: 20px 0 8px;
}

/* ── environment badge ─────────────────────────────────────────────────────── */
.env-badge {
  position: fixed;
  bottom: calc(70px + env(safe-area-inset-bottom) + 8px); /* above bottom-nav on mobile */
  right: 10px;
  z-index: 9999;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 3px 8px 4px;
  border-radius: 5px;
  pointer-events: none;
  text-transform: uppercase;
  display: none; /* shown only when env is dev or staging */
}
.env-badge[data-env="dev"] {
  background: #4f46e5; /* indigo */
  color: #ffffff;
  outline: 2px dashed #a5b4fc; /* dashed outline — distinct texture from staging */
  outline-offset: -3px;
}
.env-badge[data-env="staging"] {
  background: #0369a1; /* sky blue */
  color: #ffffff;
  outline: 2px solid #7dd3fc; /* solid outline — distinct from dev */
  outline-offset: -3px;
}
@media (min-width: 700px) {
  .env-badge {
    bottom: auto;
    top: 10px;
    right: 10px;
  }
}
