/* ============================================================
   Kitchen App — Editorial Kitchen × Mesa Built
   Per spec Section 10.3.
   ============================================================ */

/* Self-hosted fonts (downloaded at deploy time). Graceful Georgia fallback. */
@font-face {
  font-family: 'Libre Baskerville';
  src: url('/fonts/libre-baskerville-regular.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Libre Baskerville';
  src: url('/fonts/libre-baskerville-italic.woff2') format('woff2');
  font-weight: 400; font-style: italic; font-display: swap;
}
@font-face {
  font-family: 'Libre Baskerville';
  src: url('/fonts/libre-baskerville-bold.woff2') format('woff2');
  font-weight: 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Jost';
  src: url('/fonts/jost-regular.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Jost';
  src: url('/fonts/jost-medium.woff2') format('woff2');
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Jost';
  src: url('/fonts/jost-semibold.woff2') format('woff2');
  font-weight: 600; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Lora';
  src: url('/fonts/lora-italic.woff2') format('woff2');
  font-weight: 400; font-style: italic; font-display: swap;
}

/* ===================== TOKENS — Light (hero) ===================== */
:root {
  /* Palette per spec 10.3 */
  --paper:        #F7F1E6;
  --surface:      #FFFDF8;
  --surface-edge: #E8DFCB;
  --ink:          #1F1B17;
  --ink-soft:     #3a342d;
  --muted:        #8A8174;
  --olive:        #4F775A;
  --pine:         #2E4633;
  --oxblood:      #7A2E2E;
  --gold:         #B08D57;
  --navy:         #0F2238;
  --leaf:         #5A8A4A;   /* have-green */
  --orange:       #C8741F;   /* need / use-soon */
  --honey:        #C99A2E;   /* low */

  /* Type */
  --serif:        'Libre Baskerville', Georgia, 'Times New Roman', serif;
  --serif-italic: 'Lora', 'Libre Baskerville', Georgia, serif;
  --sans:         'Jost', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;

  /* Rhythm */
  --r-xs: 6px; --r-sm: 12px; --r-md: 20px; --r-lg: 32px; --r-xl: 48px;
  --radius: 6px;
  --hairline: 1px solid var(--surface-edge);
  --shadow: 0 1px 0 rgba(31,27,23,0.04), 0 2px 8px rgba(31,27,23,0.05);
  --shadow-sm: 0 1px 0 rgba(31,27,23,0.05);
  --tap-target: 44px;
}

/* ===================== TOKENS — Dark ===================== */
@media (prefers-color-scheme: dark) {
  :root {
    --paper:        #1A1814;
    --surface:      #2A2620;
    --surface-edge: #3a342d;
    --ink:          #EDE6D8;
    --ink-soft:     #C9C0B0;
    --muted:        #8A8174;
    --olive:        #7AA77E;
    --pine:         #466A52;
    --oxblood:      #B85A5A;
    --gold:         #D6B47A;
    --navy:         #14304E;
    --leaf:         #7DB46A;
    --orange:       #E08B3F;
    --honey:        #DBB252;
    --hairline:     1px solid #3a342d;
    --shadow:       0 1px 0 rgba(0,0,0,0.3), 0 2px 8px rgba(0,0,0,0.3);
  }
}

/* ===================== Base ===================== */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--paper);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--olive); text-decoration: none; border-bottom: 1px solid currentColor; }
a:hover { color: var(--pine); }

button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; }

img { max-width: 100%; height: auto; display: block; }

[hidden] { display: none !important; }

/* ===================== Buttons ===================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap-target);
  padding: 12px 20px;
  border-radius: var(--radius);
  font-family: var(--sans);
  font-weight: 500;
  font-size: 15px;
  letter-spacing: 0.01em;
  border: 1px solid transparent;
  background: transparent;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}
.btn-primary {
  background: var(--olive); color: #fff; border-color: var(--olive);
}
.btn-primary:hover { background: var(--pine); border-color: var(--pine); }
.btn-primary:disabled { background: var(--muted); border-color: var(--muted); cursor: not-allowed; }

.btn-outline {
  background: var(--surface); color: var(--ink); border-color: var(--surface-edge);
}
.btn-outline:hover { border-color: var(--olive); color: var(--olive); }

.btn-ghost {
  background: transparent; color: var(--ink-soft); border: 1px solid transparent;
}
.btn-ghost:hover { color: var(--olive); }
.btn-ghost.btn-danger:hover { color: var(--oxblood); }

.btn-sm { min-height: 36px; padding: 8px 14px; font-size: 13px; }
.btn-large {
  width: 100%; min-height: 56px; font-size: 17px; letter-spacing: 0.02em;
  margin: var(--r-md) 0;
}

/* ===================== Forms ===================== */
.field-label {
  display: block;
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
  margin: var(--r-md) 0 var(--r-xs);
}
.field-input {
  display: block;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--surface-edge);
  border-radius: var(--radius);
  padding: 12px 14px;
  min-height: var(--tap-target);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px; /* >= 16px keeps iOS from auto-zooming on focus */
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.field-input:focus {
  border-color: var(--olive);
  box-shadow: 0 0 0 3px rgba(79,119,90,0.18);
}
.field-inline { display: inline-block; width: auto; margin-right: var(--r-xs); }

.code-input {
  text-align: center;
  font-family: var(--sans);
  font-size: 28px;
  letter-spacing: 0.22em;
  font-weight: 600;
}

.checkbox-row {
  display: inline-flex; align-items: center; gap: var(--r-xs);
  font-family: var(--sans); font-size: 14px; color: var(--ink-soft);
  margin-right: var(--r-md);
  min-height: var(--tap-target);
}
.checkbox-row input { width: 20px; height: 20px; accent-color: var(--olive); }

.flag-row { display: flex; flex-wrap: wrap; gap: var(--r-sm); margin-top: var(--r-sm); }

/* ===================== Auth view ===================== */
.auth {
  min-height: 100dvh;
  display: flex; flex-direction: column;
  background:
    radial-gradient(120% 60% at 50% -10%, rgba(176,141,87,0.10) 0%, transparent 60%),
    var(--paper);
  padding: max(env(safe-area-inset-top), 16px) var(--r-md) max(env(safe-area-inset-bottom), 16px);
}
.auth-card {
  width: 100%; max-width: 480px; margin: 0 auto;
  padding: var(--r-lg) var(--r-md);
  background: var(--surface);
  border: 1px solid var(--surface-edge);
  border-radius: 10px;
  box-shadow: var(--shadow);
  flex: 1 0 auto;
}
.auth-brand {
  display: flex; align-items: center; gap: var(--r-sm);
  padding: 0 0 var(--r-md);
  border-bottom: 1px solid var(--surface-edge);
  margin-bottom: var(--r-lg);
}
.cap-mark { display: block; flex-shrink: 0; }
.brand-words { display: flex; flex-direction: column; line-height: 1.1; }
.brand-wordmark {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.01em;
  color: var(--navy);
}
.brand-tagline {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 2px;
}

.auth-title {
  font-family: var(--serif);
  font-size: clamp(28px, 7vw, 36px);
  font-weight: 700;
  line-height: 1.15;
  margin: 0 0 var(--r-sm);
  color: var(--ink);
}
.auth-lede {
  font-family: var(--serif);
  font-size: 15.5px;
  line-height: 1.65;
  color: var(--ink-soft);
  margin: 0 0 var(--r-lg);
}
.auth-form { display: flex; flex-direction: column; }
.auth-form .btn { margin-top: var(--r-md); }
.auth-note { font-family: var(--sans); font-size: 13px; color: var(--muted); margin: var(--r-sm) 0 0; min-height: 1.2em; }
.auth-foot {
  font-family: var(--sans); font-size: 12px;
  color: var(--muted);
  margin: var(--r-lg) 0 0; text-align: center;
}
.brand-foot-auth {
  margin: var(--r-md) auto 0;
  padding: var(--r-sm) 0 max(env(safe-area-inset-bottom), 0px);
  text-align: center;
}

/* ===================== App shell ===================== */
.app {
  min-height: 100dvh;
  display: flex; flex-direction: column;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
.app-header {
  position: sticky; top: 0; z-index: 10;
  background: var(--paper);
  border-bottom: 1px solid var(--surface-edge);
  padding: max(env(safe-area-inset-top), 12px) var(--r-md) 12px;
}
.app-header-inner { display: flex; align-items: center; justify-content: space-between; }
.app-eyebrow {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
}

.tab-panel { padding: var(--r-md); }
.panel-eyebrow {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 0 0 var(--r-xs);
  font-weight: 500;
}
.panel-title {
  font-family: var(--serif);
  font-size: clamp(26px, 6.5vw, 32px);
  font-weight: 700;
  line-height: 1.1;
  margin: 0 0 var(--r-sm);
  color: var(--ink);
}
.hero-title { color: var(--olive); }
.panel-lede {
  font-family: var(--serif-italic);
  font-size: 15px;
  color: var(--muted);
  margin: 0 0 var(--r-md);
}

/* ===================== Tab bar ===================== */
.tab-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  background: var(--surface);
  border-top: 1px solid var(--surface-edge);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
  box-shadow: 0 -1px 0 rgba(31,27,23,0.04);
}
.tab {
  background: transparent;
  border: 0;
  padding: 6px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-family: var(--sans);
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  min-height: var(--tap-target);
  position: relative;
}
.tab-glyph { font-size: 22px; line-height: 1; font-family: var(--serif); }
.tab[aria-selected="true"] { color: var(--olive); }
.tab[aria-selected="true"]::after {
  content: '';
  position: absolute;
  bottom: -6px; left: 30%; right: 30%;
  height: 2px; background: var(--gold);
}

/* ===================== Inventory ===================== */
.inventory-toolbar, .dish-toolbar { display: flex; gap: var(--r-sm); margin: 0 0 var(--r-md); flex-wrap: wrap; }
.inventory-group { margin: var(--r-md) 0 var(--r-lg); }
.inventory-group-head {
  display: flex; align-items: baseline; gap: var(--r-sm);
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
  border-bottom: 1px solid var(--gold);
  padding-bottom: 4px;
  margin: 0 0 var(--r-sm);
}
.inventory-group-head .count { color: var(--muted); }
.inventory-item {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--surface-edge);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  box-shadow: var(--shadow-sm);
}
.inventory-item-main {
  display: flex; flex-direction: column; gap: 2px; flex: 1 1 auto;
}
.inventory-item-name {
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
}
.inventory-item-qty { font-family: var(--sans); font-size: 13px; color: var(--muted); }
.inventory-item-flags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.flag {
  display: inline-block;
  font-family: var(--sans);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 12px;
  border: 1px solid currentColor;
}
.flag-staple { color: var(--olive); }
.flag-low { color: var(--honey); }
.flag-use-soon { color: var(--orange); }
.inventory-item-actions { display: flex; gap: 4px; flex-shrink: 0; }
.icon-btn {
  background: transparent; border: 0; padding: 8px;
  color: var(--muted);
  min-width: 40px; min-height: 40px;
  font-family: var(--sans); font-size: 13px;
}
.icon-btn:hover { color: var(--olive); }
.icon-btn.icon-btn-danger:hover { color: var(--oxblood); }

/* ===================== Dishes ===================== */
.dish-item {
  background: var(--surface);
  border: 1px solid var(--surface-edge);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: var(--shadow-sm);
}
.dish-name {
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
}
.dish-meta {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
  margin-top: 2px;
}

/* ===================== Suggest ===================== */
.filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: var(--r-sm); align-items: center; }
.chip {
  background: transparent;
  border: 1px solid var(--surface-edge);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 6px 14px;
  font-family: var(--sans); font-size: 13px;
  min-height: 36px;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.chip[aria-pressed="true"], .chip.active {
  background: var(--olive); color: #fff; border-color: var(--olive);
}
.suggest-note { font-family: var(--sans); font-size: 13px; color: var(--muted); min-height: 1.2em; margin: 0; }
.suggest-results { display: flex; flex-direction: column; gap: var(--r-md); margin-top: var(--r-md); }
.option-card {
  background: var(--surface);
  border: 1px solid var(--surface-edge);
  border-radius: 8px;
  padding: var(--r-md);
  box-shadow: var(--shadow);
}
.option-eyebrow {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 6px;
}
.option-name {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
  margin: 0 0 var(--r-sm);
  color: var(--ink);
}
.option-method {
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink-soft);
  margin: var(--r-sm) 0 0;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: var(--r-xs) 0; }
.have-chip, .need-chip {
  display: inline-block;
  font-family: var(--sans);
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 12px;
}
.have-chip { background: rgba(90,138,74,0.14); color: var(--leaf); }
.need-chip { background: rgba(200,116,31,0.14); color: var(--orange); }

/* ===================== Shopping ===================== */
.shopping-item {
  display: flex; align-items: center; gap: var(--r-sm);
  background: var(--surface);
  border: 1px solid var(--surface-edge);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  box-shadow: var(--shadow-sm);
}
.shopping-checkbox { width: 22px; height: 22px; accent-color: var(--olive); }
.shopping-item-main { flex: 1 1 auto; display: flex; flex-direction: column; }
.shopping-name {
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
}
.shopping-item.checked .shopping-name {
  text-decoration: line-through;
  color: var(--muted);
}
.shopping-meta {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ===================== Modals ===================== */
.modal {
  border: 0;
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  padding: 0;
  max-width: 92vw;
  width: 420px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.18);
}
.modal::backdrop { background: rgba(31,27,23,0.55); backdrop-filter: blur(2px); }
.modal-wide { width: 92vw; max-width: 560px; }
.modal-form { padding: var(--r-md); display: flex; flex-direction: column; }
.modal-title {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 var(--r-sm);
  color: var(--ink);
}
.modal-actions {
  display: flex; gap: var(--r-sm); justify-content: flex-end;
  margin-top: var(--r-md);
  flex-wrap: wrap;
}
.modal-actions-stack { flex-direction: column; align-items: stretch; }
.modal-actions-stack .btn { width: 100%; }

.muted { color: var(--muted); font-family: var(--sans); font-size: 13px; }

/* ===================== Scan ===================== */
.scan-kind { display: flex; gap: var(--r-md); margin-bottom: var(--r-sm); }
.scan-preview {
  width: 100%; max-height: 240px; object-fit: contain;
  border-radius: 6px; margin: var(--r-sm) 0;
  background: var(--paper);
  border: 1px solid var(--surface-edge);
}
.scan-review { display: flex; flex-direction: column; gap: 6px; margin-top: var(--r-sm); }
.scan-row {
  display: grid;
  grid-template-columns: auto 1fr 88px 110px auto;
  gap: 8px;
  align-items: center;
  background: var(--paper);
  padding: 8px;
  border-radius: 6px;
  border: 1px solid var(--surface-edge);
}
.scan-row input, .scan-row select {
  width: 100%; min-height: 36px; font-size: 14px; padding: 6px 8px;
}

.dish-gap-result {
  margin-top: var(--r-md);
  display: flex; flex-direction: column; gap: var(--r-sm);
}
.dish-gap-section .field-label { margin-top: 0; }

/* ===================== Brand attribution footer ===================== */
.brand-foot {
  display: flex; align-items: center; gap: 6px; justify-content: center;
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  padding: var(--r-sm) var(--r-md) max(env(safe-area-inset-bottom), 0px);
  background: var(--paper);
}
.brand-foot a { color: var(--muted); border-bottom-color: transparent; }
.brand-foot a:hover { color: var(--olive); }

/* ===================== Toast ===================== */
.toast {
  position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink); color: var(--paper);
  padding: 10px 16px; border-radius: 999px;
  font-family: var(--sans); font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 50;
  max-width: 90vw;
}

/* ===================== Empty states ===================== */
.empty {
  text-align: center;
  padding: var(--r-lg) var(--r-md);
  border: 1px dashed var(--surface-edge);
  border-radius: 8px;
  color: var(--muted);
  font-family: var(--serif-italic);
}

/* ===================== Print / reduce motion / focus ===================== */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
:focus-visible {
  outline: 2px solid var(--olive);
  outline-offset: 2px;
}
