/* ── tokens ───────────────────────────────────────────────────────────────
   Warm terracotta accent — this is Serene's fragrance workshop, not a Dovetailed
   admin. good/warn/bad keep the house meanings: good / watch / broken, with
   "broken" reserved for negative stock and destructive actions. */
:root {
  --bg: #FAF7F4;
  --card: #FFFFFF;
  --sunk: #F3EEE9;
  --ink: #221D1A;
  --muted: #6E635C;
  --faint: #99908A;
  --line: #E8E0D8;
  --line2: #D5C9BE;
  --accent: #B4552D;
  --accent-soft: #F7E8E0;
  --on-accent: #FFFFFF;
  --good-bg: #E6F3EC; --good-fg: #0F7346;
  --warn-bg: #FBF1DF; --warn-fg: #8A5709;
  --info-bg: #EAEEFB; --info-fg: #2447C9;
  --bad-bg:  #FBEAE8; --bad-fg:  #B02A20;
  --neutral-bg: #EFEAE4; --neutral-fg: #7A716A;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17130F; --card: #211B16; --sunk: #1B1611;
    --ink: #EFE8E2; --muted: #A99C92; --faint: #7D726A;
    --line: #332A23; --line2: #4A3E34;
    --accent: #E8916B; --accent-soft: #3A251B; --on-accent: #17130F;
    --good-bg:#0F2A20; --good-fg:#4ED598;
    --warn-bg:#2E2411; --warn-fg:#E8B45C;
    --info-bg:#1B2440; --info-fg:#8AA4FF;
    --bad-bg:#2E1715;  --bad-fg:#F0918A;
    --neutral-bg:#2A231D; --neutral-fg:#A2968D;
  }
}

* { box-sizing: border-box; min-width: 0; -webkit-tap-highlight-color: transparent; }
/* `hidden` is only a display:none in the UA sheet, so ANY later `display:`
   rule beats it. Forced here, once — the link-outreach scar. */
[hidden] { display: none !important; }
html { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  /* 16px base: iOS zooms any focused input under 16px, and every input
     inherits this size. Do not shrink it. */
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100%;
}

/* ── frame: brand bar on top, five tabs on the bottom (thumb reach) ──────── */
main {
  max-width: 640px; margin: 0 auto;
  /* bottom padding = tab bar + safe area, or the last row hides behind the bar */
  padding: 0 16px calc(86px + env(safe-area-inset-bottom));
}
.ms-brandbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg); border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.ms-brandbar .ms-wrap {
  max-width: 640px; margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; gap: 10px; height: 52px;
}
.ms-brand { font-weight: 700; font-size: 17px; letter-spacing: -0.02em; color: var(--ink); text-decoration: none; }
.ms-brand span { color: var(--accent); }
.ms-sp { flex: 1; }
.ms-gear { color: var(--muted); text-decoration: none; display: flex; padding: 8px; margin: -8px; }
.ms-gear:active { color: var(--accent); }

.ms-tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 30;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.ms-tabbar .ms-wrap {
  max-width: 640px; margin: 0 auto;
  display: grid; grid-template-columns: repeat(5, 1fr);
}
.ms-tab {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 0 7px; min-height: 54px;
  font-size: 11px; font-weight: 600; color: var(--muted); text-decoration: none;
}
.ms-tab svg { width: 22px; height: 22px; }
.ms-tab.active { color: var(--accent); }
.ms-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 8px; }

h1 { font-size: 24px; letter-spacing: -0.5px; margin: 20px 0 4px; }
h2 { font-size: 16px; font-weight: 650; margin: 22px 0 8px; }
.ms-sub { color: var(--muted); margin: 0 0 16px; font-size: 14px; }

/* ── cards, rows, lists ─────────────────────────────────────────────────── */
.ms-panel { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 12px; }
.ms-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ms-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.ms-card .n { font-size: 22px; font-weight: 700; letter-spacing: -0.4px; }
.ms-card .l { color: var(--muted); font-size: 12.5px; margin-top: 2px; }

.ms-list { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin-bottom: 12px; }
.ms-row {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 12px 14px; min-height: 56px;
  border: 0; border-bottom: 1px solid var(--line); background: none;
  font: inherit; color: inherit; text-align: left; cursor: pointer;
}
.ms-row:last-child, .ms-list > :last-child .ms-row { border-bottom: none; }
.ms-row .grow { flex: 1; min-width: 0; }
.ms-row .t { font-weight: 600; font-size: 15px; }
.ms-row .s { color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.ms-row .qty { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.ms-row .qty .c { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }
.ms-row:active { background: var(--sunk); }
a.ms-row { text-decoration: none; color: inherit; }
a { color: var(--accent); }
.ms-rowdetail { padding: 4px 14px 14px; border-bottom: 1px solid var(--line); background: var(--sunk); }
.ms-rowdetail:last-child { border-bottom: none; }

.ms-empty { color: var(--muted); padding: 26px 14px; text-align: center; }

/* ── pills, banners ─────────────────────────────────────────────────────── */
.ms-pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.ms-good { background: var(--good-bg); color: var(--good-fg); }
.ms-warn { background: var(--warn-bg); color: var(--warn-fg); }
.ms-info { background: var(--info-bg); color: var(--info-fg); }
.ms-bad  { background: var(--bad-bg);  color: var(--bad-fg); }
.ms-neutral { background: var(--neutral-bg); color: var(--neutral-fg); }

.ms-banner { border-radius: 12px; padding: 12px 14px; margin: 0 0 14px; font-size: 14px; }
.ms-banner.bad { background: var(--bad-bg); color: var(--bad-fg); }
.ms-banner.warn { background: var(--warn-bg); color: var(--warn-fg); }
.ms-banner strong { display: block; margin-bottom: 2px; }

/* An absent value must never look like a value (house honesty primitive). */
.ms-unknown {
  font-style: italic; color: var(--muted); opacity: 0.8;
  font-size: 0.92em; border-bottom: 1px dotted var(--line2);
}

/* ── buttons, forms ─────────────────────────────────────────────────────── */
.ms-btn {
  font: inherit; font-size: 15px; font-weight: 600; padding: 11px 16px; min-height: 44px;
  border-radius: 10px; cursor: pointer; border: 1px solid var(--line2);
  background: var(--card); color: var(--ink); text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
}
.ms-btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.ms-btn.danger { color: var(--bad-fg); border-color: var(--bad-fg); background: var(--card); }
.ms-btn.sm { font-size: 13px; padding: 6px 12px; min-height: 34px; border-radius: 8px; }
.ms-btn:disabled { opacity: .45; cursor: not-allowed; }
.ms-btn:active:not(:disabled) { filter: brightness(0.95); }
.ms-btn.block { width: 100%; }

.ms-actionbar { display: flex; gap: 8px; align-items: center; margin: 0 0 12px; flex-wrap: wrap; }
.ms-actionbar input[type="search"], .ms-actionbar select {
  flex: 1; min-width: 120px;
}

input, select, textarea {
  font: inherit; font-size: 16px; /* never below 16px: iOS zoom */
  padding: 10px 12px; min-height: 44px; border-radius: 10px;
  border: 1px solid var(--line2); background: var(--card); color: var(--ink);
  width: 100%;
}
textarea { min-height: 64px; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .ms-btn:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
label { display: block; color: var(--muted); font-size: 13px; font-weight: 600; margin: 12px 0 4px; }
.ms-field-hint { color: var(--faint); font-size: 12.5px; margin-top: 3px; }
.ms-form-err { color: var(--bad-fg); font-size: 14px; margin-top: 10px; min-height: 1em; }
.ms-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }

.ms-seg { display: flex; background: var(--sunk); border-radius: 10px; padding: 3px; gap: 3px; }
.ms-seg button {
  flex: 1; font: inherit; font-size: 13.5px; font-weight: 600; border: 0; border-radius: 8px;
  padding: 8px 6px; min-height: 38px; background: none; color: var(--muted); cursor: pointer;
}
.ms-seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* ── bottom sheet ───────────────────────────────────────────────────────── */
.ms-overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.42);
  display: flex; align-items: flex-end; justify-content: center;
}
.ms-sheet {
  background: var(--bg); width: 100%; max-width: 640px;
  border-radius: 16px 16px 0 0; max-height: 88dvh; overflow-y: auto;
  padding: 6px 16px calc(16px + env(safe-area-inset-bottom));
  animation: ms-up .18s ease-out;
}
@keyframes ms-up { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.ms-sheet-head { display: flex; align-items: center; gap: 10px; padding: 10px 0 2px; }
.ms-sheet-head h3 { margin: 0; font-size: 17px; flex: 1; }
.ms-x {
  border: 0; background: var(--sunk); color: var(--muted); font-size: 20px; line-height: 1;
  width: 36px; height: 36px; border-radius: 999px; cursor: pointer;
}
.ms-sheet .ms-btnrow { display: flex; gap: 8px; margin-top: 18px; }
.ms-sheet .ms-btnrow .ms-btn { flex: 1; }

/* ── tables (small, data-dense views) ───────────────────────────────────── */
.ms-scroll { min-width: 0; }
table { width: 100%; border-collapse: collapse; font-size: 14px; table-layout: fixed; }
th, td { text-align: left; padding: 8px 8px; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ── recipe editor ──────────────────────────────────────────────────────── */
.ms-line {
  display: grid; grid-template-columns: 1fr 92px; gap: 6px 8px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.ms-line .full { grid-column: 1 / -1; display: flex; gap: 8px; align-items: center; }
.ms-line .full .ms-field-hint { flex: 1; }
.ms-line select.mode { font-size: 13.5px; min-height: 38px; padding: 6px 8px; }
.ms-carrier-flag { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: 13px; }
.ms-carrier-flag input { width: 18px; height: 18px; min-height: 0; margin: 0; }

.ms-preview {
  position: sticky; bottom: calc(70px + env(safe-area-inset-bottom)); z-index: 10;
  background: var(--card); border: 1px solid var(--line2); border-radius: 12px;
  padding: 10px 14px 12px; margin-top: 14px;
  box-shadow: 0 -4px 18px rgba(0,0,0,.10);
}
.ms-preview h3 { margin: 2px 0 6px; font-size: 14px; }
.ms-preview .rowline { display: flex; justify-content: space-between; gap: 10px; font-size: 13.5px; padding: 2px 0; }
.ms-preview .rowline .v { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.ms-preview .total { border-top: 1px solid var(--line); margin-top: 5px; padding-top: 5px; font-weight: 700; }
.ms-preview .warn { color: var(--warn-fg); font-size: 12.5px; margin-top: 4px; }

/* big tap targets on the home screen */
.ms-bigbtns { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin: 14px 0 6px; }
.ms-bigbtns .ms-btn { flex-direction: column; gap: 6px; padding: 14px 6px; font-size: 13px; }
.ms-bigbtns svg { width: 24px; height: 24px; }

@media (min-width: 700px) {
  .ms-cards { grid-template-columns: repeat(4, 1fr); }
}
