/* ─────────────────────────────────────────────
   SIFT — Design tokens
   ───────────────────────────────────────────── */
:root {
  --sage-900: #2B3428;
  --sage-700: #3F4B3B;
  --sage-500: #5B6B54;
  --sage-300: #8A9484;
  --sage-100: #DCE3D5;
  --cream:    #F7F0E1;
  --cream-2:  #FFFDF8;
  --gold:     #C9A05B;
  --gold-dark:#A9803F;
  --rust:     #B5533C;
  --ink:      #2B2B26;
  --ink-soft: #5B584F;

  --bg: var(--cream);
  --surface: var(--cream-2);
  --border: #E3D9C4;
  --text: var(--ink);
  --text-soft: var(--ink-soft);
  --accent: var(--sage-700);
  --accent-contrast: var(--cream);

  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(43,52,40,0.08);
  --shadow-md: 0 6px 20px rgba(43,52,40,0.12);
  --shadow-lg: 0 16px 40px rgba(43,52,40,0.18);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1C211B;
    --surface: #262D24;
    --border: #38402F;
    --text: #EFE9DA;
    --text-soft: #B4AC98;
    --accent: #C9A05B;
    --accent-contrast: #1C211B;
    --sage-100: #313A2C;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }
ul, ol { margin: 0; padding: 0; list-style: none; }
a { color: inherit; }

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ─────────────────────────────────────────────
   Buttons & small controls
   ───────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-weight: 600; font-size: 15px;
  transition: transform .12s ease, box-shadow .12s ease, background .15s ease;
}
.btn:active { transform: scale(0.97); }
.btn--primary { background: var(--sage-700); color: var(--cream); box-shadow: var(--shadow-sm); }
.btn--primary:hover { background: var(--sage-900); }
.btn--ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn--ghost:hover { background: var(--sage-100); }
.btn--wide { width: 100%; }
.btn--sm { min-height: 40px; padding: 0 14px; font-size: 14px; }

.text-btn {
  background: none; border: none; color: var(--sage-700); font-weight: 600;
  font-size: 14px; padding: 8px 4px; text-align: left; min-height: 44px;
}
@media (prefers-color-scheme: dark) { .text-btn { color: var(--gold); } }
.text-btn--danger { color: var(--rust); }

.icon-btn {
  width: 48px; height: 48px; display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; border-radius: 50%; font-size: 18px; color: var(--text);
}
.icon-btn:hover { background: var(--sage-100); }
.icon-btn--danger:hover { background: #F3DFDA; color: var(--rust); }

.badge {
  display: inline-block; background: var(--sage-100); color: var(--sage-700);
  font-size: 12px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase;
  padding: 4px 10px; border-radius: 999px;
}

/* ─────────────────────────────────────────────
   Login screen — signature: the app IS a recipe card
   ───────────────────────────────────────────── */
.view-login {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: 24px; background:
    radial-gradient(circle at 15% 10%, rgba(201,160,91,0.15), transparent 45%),
    var(--bg);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  overflow: hidden; border: 1px solid var(--border);
}
.login-card__stripe { height: 10px; background: linear-gradient(90deg, var(--gold), var(--sage-700)); }
.login-card__body { padding: 40px 32px 32px; text-align: center; }
.login-mark { margin-bottom: 18px; }
.login-title {
  font-family: var(--font-display); font-size: 40px; font-weight: 600;
  margin: 0 0 8px; color: var(--sage-900);
}
@media (prefers-color-scheme: dark) { .login-title { color: var(--text); } }
.login-tagline { color: var(--text-soft); font-size: 15px; line-height: 1.5; margin: 0 0 28px; }
.login-fineprint { color: var(--text-soft); font-size: 12px; margin-top: 16px; }

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

.sidebar {
  width: 264px; flex-shrink: 0; background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 20px 16px;
  gap: 20px;
}
.sidebar__brand {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-display); font-weight: 600; font-size: 20px;
}
.sidebar__brand .drawer-only { margin-left: auto; }
.sidebar__search input {
  width: 100%; min-height: 44px; border-radius: var(--radius-md);
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  padding: 0 14px; font-size: 14px;
}
.sidebar__section { display: flex; flex-direction: column; gap: 4px; }
.sidebar__section-head {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-soft); padding: 0 4px;
}
.sidebar__categories { flex: 1; overflow-y: auto; }

.nav-item {
  display: flex; align-items: center; gap: 10px; min-height: 44px;
  background: none; border: none; border-radius: var(--radius-md);
  padding: 0 10px; font-size: 15px; font-weight: 600; color: var(--text); text-align: left;
}
.nav-item:hover { background: var(--sage-100); }
.nav-item--active { background: var(--sage-700); color: var(--cream); }
.nav-item__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--sage-500); }
.nav-item--active .nav-item__dot { background: var(--cream); }
.nav-item__dot--gold { background: var(--gold); }

.category-list { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.category-list .nav-item { font-weight: 500; font-size: 14px; }

.sidebar__footer { border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: none; align-items: center; gap: 10px; padding: 10px 12px;
  padding-top: calc(10px + var(--safe-top));
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar__search {
  flex: 1; min-height: 44px; border-radius: var(--radius-md);
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  padding: 0 14px; font-size: 14px;
}

.filter-chips { display: none; gap: 8px; padding: 10px 12px; overflow-x: auto; }
.chip {
  flex-shrink: 0; min-height: 40px; padding: 0 16px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 14px; font-weight: 600; white-space: nowrap;
}
.chip--active { background: var(--sage-700); border-color: var(--sage-700); color: var(--cream); }

.recipe-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 20px; padding: 24px 28px 60px;
}

.empty-state {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: 8px; padding: 80px 24px; color: var(--text-soft);
}
.empty-state h3 { font-family: var(--font-display); font-size: 22px; color: var(--text); margin: 8px 0 0; }
.empty-state .btn { margin-top: 12px; }

/* Recipe card */
.recipe-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  overflow: hidden; cursor: pointer; box-shadow: var(--shadow-sm);
  transition: transform .15s ease, box-shadow .15s ease;
  display: flex; flex-direction: column;
}
.recipe-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.recipe-card__img-wrap {
  aspect-ratio: 4/3; background: var(--sage-100); position: relative; overflow: hidden;
}
.recipe-card__img-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.recipe-card__fallback {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font-size: 36px;
}
.recipe-card__fav {
  position: absolute; top: 8px; right: 8px; width: 32px; height: 32px; border-radius: 50%;
  background: rgba(255,253,248,0.9); border: none; display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: var(--gold-dark);
}
.recipe-card__body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 6px; }
.recipe-card__cat { font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--sage-500); }
.recipe-card__title { font-family: var(--font-display); font-size: 18px; font-weight: 600; margin: 0; line-height: 1.25; }

/* ─────────────────────────────────────────────
   Drawer (mobile sidebar)
   ───────────────────────────────────────────── */
.drawer-only { display: none; }
.drawer-scrim {
  position: fixed; inset: 0; background: rgba(20,24,17,0.45); z-index: 30;
}

/* ─────────────────────────────────────────────
   Detail view
   ───────────────────────────────────────────── */
.view-detail { min-height: 100dvh; background: var(--bg); }
.detail-topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; padding-top: calc(10px + var(--safe-top));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.detail-topbar__actions { display: flex; gap: 2px; }
.detail-hero { width: 100%; aspect-ratio: 16/9; background: var(--sage-100); position: relative; }
.detail-hero__img { width: 100%; height: 100%; object-fit: cover; }
.detail-hero__fallback { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 56px; }
.detail-body { max-width: 900px; margin: 0 auto; padding: 24px 20px 80px; }
.detail-title { font-family: var(--font-display); font-size: 32px; margin: 8px 0 20px; }
.detail-columns { display: grid; grid-template-columns: 1fr; gap: 32px; margin-top: 24px; }
.detail-section-head { display: flex; align-items: center; justify-content: space-between; }
.detail-ingredients h2, .detail-steps h2 { font-family: var(--font-display); font-size: 20px; margin: 0 0 12px; }

.scale-toggle { display: flex; gap: 4px; background: var(--sage-100); border-radius: 999px; padding: 3px; }
.scale-toggle button {
  border: none; background: none; padding: 6px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; color: var(--sage-700);
}
.scale-toggle button.scale-active { background: var(--sage-700); color: var(--cream); }

.ingredient-list li {
  display: flex; gap: 10px; align-items: baseline; padding: 10px 0; border-bottom: 1px dashed var(--border);
  font-size: 15px;
}
.ingredient-list li .qty { font-family: var(--font-mono); font-weight: 500; color: var(--sage-700); min-width: 64px; }
.ingredient-list li.checked { opacity: .45; text-decoration: line-through; }
.ingredient-list--cook li { min-height: 48px; align-items: center; }

.step-list { counter-reset: step; display: flex; flex-direction: column; gap: 18px; }
.step-list li { counter-increment: step; display: flex; gap: 14px; }
.step-list li::before {
  content: counter(step); flex-shrink: 0; width: 28px; height: 28px; border-radius: 50%;
  background: var(--sage-700); color: var(--cream); font-size: 13px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.step-list li p { margin: 4px 0 0; line-height: 1.55; }

/* ─────────────────────────────────────────────
   Cook mode
   ───────────────────────────────────────────── */
.view-cook { min-height: 100dvh; background: var(--sage-900); color: var(--cream); }
.cook-topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  padding-top: calc(10px + var(--safe-top));
}
.cook-topbar .icon-btn { color: var(--cream); }
.cook-title { font-family: var(--font-display); font-size: 17px; flex: 1; }
.cook-body { padding: 0 20px 60px; max-width: 720px; margin: 0 auto; }
.cook-ingredients { margin-bottom: 28px; }
.cook-ingredients h3, .cook-steps h3 { font-family: var(--font-display); font-weight: 500; color: var(--gold); }
.cook-ingredients .ingredient-list li { border-bottom-color: rgba(247,240,225,0.15); }
.cook-ingredients .ingredient-list li .qty { color: var(--gold); }

.cook-step {
  padding: 22px 0; border-bottom: 1px solid rgba(247,240,225,0.12);
  opacity: 0.4; transition: opacity .2s ease;
}
.cook-step--active { opacity: 1; }
.cook-step__num { font-family: var(--font-mono); color: var(--gold); font-size: 13px; }
.cook-step__text { font-size: 19px; line-height: 1.5; margin-top: 6px; }

/* ─────────────────────────────────────────────
   Modals
   ───────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; background: rgba(20,24,17,0.5); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal__panel {
  background: var(--surface); width: 100%; max-width: 560px; max-height: 92dvh;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0; display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg); overflow: hidden;
}
.modal__panel--large { max-width: 640px; }
.modal__header {
  display: flex; align-items: center; justify-content: space-between; padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal__header h2 { font-family: var(--font-display); font-size: 20px; margin: 0; }
.modal__body { padding: 20px; overflow-y: auto; flex: 1; }
.modal__footer { display: flex; gap: 10px; padding: 16px 20px; border-top: 1px solid var(--border); }
.modal__footer .btn { flex: 1; }

@media (min-width: 640px) {
  .modal { align-items: center; }
  .modal__panel { border-radius: var(--radius-lg); }
}

/* Form fields */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; }
.field__label { font-size: 13px; font-weight: 700; color: var(--text-soft); }
.field input[type="text"], .field input[type="number"], .field select, .field textarea {
  min-height: 48px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg); color: var(--text); padding: 0 14px; font-size: 15px;
}
.field--row { flex-direction: row; align-items: center; gap: 10px; }
.field--row input[type="checkbox"] { width: 20px; height: 20px; }

.image-drop {
  border: 2px dashed var(--border); border-radius: var(--radius-md); min-height: 140px;
  display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text-soft);
  overflow: hidden; position: relative;
}
.image-preview { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }

.dynamic-rows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.ingredient-row { display: grid; grid-template-columns: 70px 90px 1fr 40px; gap: 6px; }
.ingredient-row input, .ingredient-row select {
  min-height: 44px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg); color: var(--text); padding: 0 8px; font-size: 14px;
}
.step-row { display: flex; gap: 6px; align-items: flex-start; }
.step-row textarea {
  flex: 1; min-height: 60px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg); color: var(--text); padding: 10px; font-size: 14px; resize: vertical;
  font-family: inherit;
}
.row-remove {
  width: 40px; height: 44px; border: none; background: var(--sage-100); border-radius: var(--radius-sm);
  color: var(--rust); font-size: 16px; flex-shrink: 0;
}

.new-category-row { display: flex; gap: 8px; margin-bottom: 16px; }
.new-category-row input {
  flex: 1; min-height: 44px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg); color: var(--text); padding: 0 12px;
}
.category-manage-list { display: flex; flex-direction: column; gap: 8px; }
.category-manage-row {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--bg);
}
.category-manage-row input { flex: 1; border: none; background: none; color: var(--text); font-size: 14px; min-height: 36px; }
.category-manage-row button { background: none; border: none; color: var(--rust); font-size: 15px; padding: 8px; }

/* Toast */
.toast {
  position: fixed; bottom: calc(20px + var(--safe-bottom)); left: 50%; transform: translateX(-50%);
  background: var(--sage-900); color: var(--cream); padding: 12px 20px; border-radius: 999px;
  font-size: 14px; font-weight: 600; z-index: 100; box-shadow: var(--shadow-md);
}

/* ─────────────────────────────────────────────
   Responsive: mobile layout
   ───────────────────────────────────────────── */
@media (max-width: 880px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 40; width: 280px;
    transform: translateX(-100%); transition: transform .25s ease;
    padding-top: calc(20px + var(--safe-top));
  }
  .sidebar.drawer-open { transform: translateX(0); }
  .drawer-only { display: flex; }
  .sidebar__search { display: none; } /* mobile uses topbar search instead */
  .topbar { display: flex; }
  .filter-chips { display: flex; }
  .recipe-grid { grid-template-columns: 1fr; padding: 16px; gap: 14px; }
  .detail-columns { grid-template-columns: 1fr; }
  .ingredient-row { grid-template-columns: 60px 76px 1fr 36px; }
}

@media (min-width: 881px) {
  .drawer-scrim { display: none !important; }
}

/* ─────────────────────────────────────────────
   Print styles (for detail view)
   ───────────────────────────────────────────── */
@media print {
  body * { visibility: hidden; }
  .view-detail, .view-detail * { visibility: visible; }
  .view-detail { position: absolute; inset: 0; background: #fff; color: #000; }
  .detail-topbar, .btn { display: none !important; }
  .detail-hero { aspect-ratio: auto; max-height: 260px; }
}
