/* ==========================================================================
   What Are We Cooking — design tokens + shared components.
   Mobile-first. Everything here is shared chrome; view-specific styling for
   the planner and shopping list lives in views.css.
   ========================================================================== */

:root {
  /* Warm, appetising, calm. */
  --bg:          #fbf7f2;
  --bg-tint:     #f4ece2;
  --surface:     #ffffff;
  --surface-2:   #f6efe6;
  --text:        #2a211b;
  --muted:       #7c6f65;
  --border:      #eaded1;
  --accent:      #c4562b;
  --accent-ink:  #ffffff;
  --accent-soft: #fbe6db;
  --danger:      #b3261e;
  --danger-soft: #fbe3e1;
  --ok:          #3c7a52;
  --ok-soft:     #e2f0e6;
  --frost:       #2f6d94;
  --frost-soft:  #e2eff7;

  --radius:      16px;
  --radius-sm:   10px;
  --gap:         14px;

  --shadow:      0 1px 2px rgba(42, 33, 27, .06), 0 6px 20px rgba(42, 33, 27, .07);
  --shadow-lift: 0 -6px 24px rgba(42, 33, 27, .10);

  --tabbar-h:    58px;
  --appbar-h:    54px;
  --tap:         44px;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #17130f;
    --bg-tint:     #1e1813;
    --surface:     #221c17;
    --surface-2:   #2c241d;
    --text:        #f3eae1;
    --muted:       #a89a8c;
    --border:      #382e26;
    --accent:      #f0865a;
    --accent-ink:  #24120a;
    --accent-soft: #3a2318;
    --danger:      #f2726a;
    --danger-soft: #3b1d1b;
    --ok:          #7cc08c;
    --ok-soft:     #1e2f22;
    --frost:       #7cc0e6;
    --frost-soft:  #16262f;

    --shadow:      0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
    --shadow-lift: 0 -8px 28px rgba(0, 0, 0, .45);

    color-scheme: dark;
  }
}

/* ------------------------------------------------------------- base ----- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  min-height: 100dvh;
}

h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 22px; }
h3 { font-size: 17px; }
p  { margin: 0 0 .6em; }
p:last-child { margin-bottom: 0; }

a { color: var(--accent); text-decoration: none; }

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

[hidden] { display: none !important; }

::selection { background: var(--accent-soft); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ------------------------------------------------------------ layout ---- */

.app { min-height: 100dvh; }

.appbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  height: calc(var(--appbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid var(--border);
}

.appbar-mark { font-size: 20px; line-height: 1; }

.appbar-title {
  font-size: 18px;
  font-weight: 680;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  flex: none;
  width: var(--tap);
  height: var(--tap);
  display: grid;
  place-items: center;
  font-size: 19px;
  background: transparent;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:active { background: var(--surface-2); }

.view {
  display: block;
  padding:
    var(--gap)
    max(var(--gap), env(safe-area-inset-right))
    calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 28px)
    max(var(--gap), env(safe-area-inset-left));
  max-width: 720px;
  margin: 0 auto;
  outline: none;
}

/* Re-applied by the router on every navigation. */
.view-enter { animation: view-in .18s ease-out both; }

@keyframes view-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

.stack { display: flex; flex-direction: column; gap: var(--gap); }
.row   { display: flex; align-items: center; gap: 10px; }
.row-wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.spacer { flex: 1; }

.section-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 6px 2px 0;
}

/* ------------------------------------------------------------ tabbar ---- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(16px);
  backdrop-filter: saturate(1.6) blur(16px);
  border-top: 1px solid var(--border);
}

.tab {
  min-height: var(--tabbar-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  transition: color .15s ease;
}

.tab-ico {
  font-size: 20px;
  line-height: 1;
  filter: saturate(.15) opacity(.75);
  transition: filter .15s ease, transform .15s ease;
}

.tab[aria-current="page"] { color: var(--accent); }
.tab[aria-current="page"] .tab-ico { filter: none; transform: translateY(-1px) scale(1.06); }
.tab:active .tab-ico { transform: scale(.92); }

/* ------------------------------------------------------------- cards ---- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--gap);
  box-shadow: var(--shadow);
}
.card + .card { margin-top: var(--gap); }
.card-tight { padding: 0; overflow: hidden; }

/* -------------------------------------------------------------- list ---- */

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 11px var(--gap);
  background: none;
  border: 0;
  border-top: 1px solid var(--border);
  text-align: left;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.list > :first-child > .list-row,
.list > .list-row:first-child { border-top: 0; }
.list-row:active { background: var(--surface-2); }

.list-row-main {
  display: block;
  flex: 1;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}
.list-row-title {
  display: block;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.list-row-sub { display: block; font-size: 13.5px; color: var(--muted); }
.chev { color: var(--muted); font-size: 18px; flex: none; }

/* ----------------------------------------------------------- buttons ---- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 10px 16px;
  font-size: 16px;
  font-weight: 620;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform .1s ease, background .15s ease, opacity .15s ease;
  user-select: none;
}
.btn:active { transform: scale(.975); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .45; pointer-events: none; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  box-shadow: var(--shadow);
}
.btn-ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn-ghost:active { background: var(--accent-soft); }
.btn-danger { background: transparent; border-color: var(--border); color: var(--danger); }
.btn-danger:active { background: var(--danger-soft); }
.btn-soft { background: var(--surface-2); border-color: transparent; }
.btn-block { display: flex; width: 100%; }
/* Visually lighter, but still a full 44px tap target. */
.btn-sm { min-height: var(--tap); padding: 6px 12px; font-size: 14.5px; border-radius: 10px; }

.btn-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

/* ------------------------------------------------------------ badges ---- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex: none;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 650;
  line-height: 1.35;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}
.badge-freezer { background: var(--frost-soft); color: var(--frost); }
.badge-accent  { background: var(--accent-soft); color: var(--accent); }
.badge-ok      { background: var(--ok-soft); color: var(--ok); }

/* ------------------------------------------------------------- forms ---- */

.field { display: block; margin-bottom: var(--gap); }
.field:last-child { margin-bottom: 0; }

.field label,
.field > .field-label {
  display: block;
  font-size: 13px;
  font-weight: 650;
  color: var(--muted);
  margin-bottom: 6px;
}

.field input,
.field select,
.field textarea,
.input {
  display: block;
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  font-size: 16px; /* ≥16px: stops iOS zooming on focus */
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  -webkit-appearance: none;
  appearance: none;
}
.field textarea { min-height: 84px; resize: vertical; line-height: 1.4; }
.field input:focus, .field textarea:focus, .input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field-hint { font-size: 13px; color: var(--muted); margin-top: 6px; }
.field-row { display: flex; gap: 10px; }
.field-row > .field { flex: 1; margin-bottom: var(--gap); }

/* Search box with a leading glyph. */
.search {
  position: relative;
  display: flex;
  align-items: center;
}
.search::before {
  content: "🔍";
  position: absolute;
  left: 13px;
  font-size: 15px;
  opacity: .55;
  pointer-events: none;
}
.search input { padding-left: 38px; border-radius: 999px; background: var(--surface); }

/* Filter chips. */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  min-height: var(--tap);
  padding: 6px 15px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.chip[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
}

/* Stepper: − [ 2 ] + — a 44px-safe number control. */
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper button {
  width: var(--tap);
  height: var(--tap);
  flex: none;
  font-size: 22px;
  line-height: 1;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
}
.stepper button:active { background: var(--surface-2); }
.stepper input { width: 74px; text-align: center; font-weight: 650; }

.muted { color: var(--muted); }
.small { font-size: 13.5px; }
.nowrap { white-space: nowrap; }
.strong { font-weight: 650; }

/* ------------------------------------------------------- empty states --- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  padding: 44px 22px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.empty-ico { font-size: 40px; line-height: 1; filter: saturate(.8); }
.empty-title { font-size: 18px; font-weight: 650; }
.empty p { color: var(--muted); max-width: 34ch; }
.empty .btn { margin-top: 4px; }

/* Skeleton placeholders — keep the layout from jumping while loading. */
.skeleton {
  border-radius: var(--radius);
  background: linear-gradient(100deg, var(--surface-2) 30%, var(--bg-tint) 50%, var(--surface-2) 70%);
  background-size: 300% 100%;
  animation: shimmer 1.2s linear infinite;
}
.skeleton-row { height: 62px; margin-bottom: 10px; }
@keyframes shimmer { from { background-position: 150% 0; } to { background-position: -150% 0; } }

.spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------ sheets / overlays ----- */

.scrim {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(20, 14, 10, .42);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade-in .16s ease-out both;
  /* Lift the sheet clear of the on-screen keyboard. --kb-inset is maintained
     by openSheet() from the visualViewport API, because iOS does not shrink
     the layout viewport when the keyboard opens. */
  padding-bottom: var(--kb-inset, 0px);
  transition: padding-bottom .2s ease-out;
}

.sheet {
  width: 100%;
  max-width: 560px;
  /* Shrink alongside the keyboard so a tall sheet stays scrollable rather
     than pushing its own content off-screen. */
  max-height: calc(88dvh - var(--kb-inset, 0px));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  padding: 8px var(--gap) calc(var(--gap) + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-lift);
  animation: sheet-up .22s cubic-bezier(.22, .9, .3, 1) both;
}
.sheet-grip {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 4px auto 12px;
}
.sheet-title { font-size: 19px; font-weight: 680; margin-bottom: 4px; }
.sheet-body { margin: 12px 0 16px; }
.sheet-actions { display: flex; flex-direction: column; gap: 10px; }
.sheet-actions .btn { width: 100%; }

@media (min-width: 640px) {
  .scrim { align-items: center; }
  .sheet { border-radius: 22px; margin: 0 16px; }
  .sheet-grip { display: none; }
  .sheet-actions { flex-direction: row-reverse; }
  .sheet-actions .btn { flex: 1; }
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheet-up { from { transform: translateY(18px); opacity: .4; } to { transform: none; opacity: 1; } }

/* ------------------------------------------------------------ toasts ---- */

.toasts {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(94vw, 460px);
  pointer-events: none;
}

.toast {
  padding: 11px 15px;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: #2f2721;
  box-shadow: var(--shadow);
  animation: toast-in .18s ease-out both;
}
.toast-error { background: var(--danger); color: #fff; }
.toast-out { animation: toast-out .2s ease-in both; }
@keyframes toast-in  { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

/* --------------------------------------------------------- auth gate ---- */

.gate {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    calc(env(safe-area-inset-top) + 24px)
    max(20px, env(safe-area-inset-left))
    calc(env(safe-area-inset-bottom) + 24px)
    max(20px, env(safe-area-inset-right));
  background:
    radial-gradient(120% 80% at 50% 0%, var(--accent-soft) 0%, transparent 62%),
    var(--bg);
}

.gate-inner {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
  animation: view-in .25s ease-out both;
}

.gate-mark {
  width: 76px;
  height: 76px;
  display: grid;
  place-items: center;
  font-size: 38px;
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.gate h2 { font-size: 25px; }
.gate p  { color: var(--muted); }
.gate .card { width: 100%; text-align: left; }
.gate .btn { width: 100%; }
.gate-foot { font-size: 13px; color: var(--muted); }

/* --------------------------------------------------- misc components ---- */

.inline-error {
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 14.5px;
  font-weight: 600;
}

.copybox {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.copybox input {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.divider { height: 1px; background: var(--border); margin: var(--gap) 0; border: 0; }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; }
.kv + .kv { border-top: 1px solid var(--border); }
.kv dt { color: var(--muted); font-size: 14.5px; }
.kv dd { margin: 0; font-weight: 600; text-align: right; }

/* Ingredient editor rows. */
.ing-row {
  display: grid;
  grid-template-columns: 3.9rem 3.9rem 1fr auto;
  gap: 5px;
  align-items: center;
  margin-bottom: 8px;
}
.ing-row input { min-height: var(--tap); padding: 8px 8px; font-size: 16px; }
.ing-row .ing-tools { display: flex; gap: 0; }
.ing-row .ing-tools button {
  width: 42px;
  height: var(--tap);
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 15px;
  cursor: pointer;
  border-radius: 8px;
}
.ing-row .ing-tools button:active { background: var(--surface-2); }

.ing-line { display: flex; gap: 10px; padding: 8px 0; align-items: baseline; }
.ing-line + .ing-line { border-top: 1px solid var(--border); }
.ing-qty { min-width: 5.2rem; color: var(--muted); font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
