/* ============================================================
   Minali Meal Planner — design system
   Heritage: the family's hand-drawn paper grid (indigo marker
   lines, kanji day headers, 昼/夜 row labels, warm paper).
   ============================================================ */
:root {
  --paper:      #FAF6EF;
  --paper-2:    #F2ECDF;
  --ink:        #26313F;
  --ink-soft:   #5B6675;
  --indigo:     #3D5BA9;   /* grid lines, Xavier */
  --indigo-soft:#C9D3EC;
  --vermilion:  #D9512C;   /* 朱 — primary action, Eri */
  --sun:        #E9B44C;   /* holiday tint */
  --lavender:   #7E6BC9;   /* Sawa */
  --teal:       #0E6F6F;   /* Xavier badge (deep teal, #044B4B family) */
  --holiday:    #FBF0D2;   /* holiday tint */
  --matcha:     #6F8F5A;
  --card:       #FFFFFF;
  --line:       #E3DCCB;
  --radius: 5px;   /* user choice: very subtle */
  --shadow: 0 1px 3px rgba(38,49,63,.08), 0 4px 14px rgba(38,49,63,.06);
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Sans", "Noto Sans JP", sans-serif;
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Hiragino Mincho ProN", serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1C2129; --paper-2: #232A35; --ink: #E8E4DA; --ink-soft: #9AA4B2;
    --indigo: #7C95D6; --indigo-soft: #36446B; --holiday: #3A3422;
    --teal: #1E9494;   /* brightened on dark so X stays visible */
    --card: #262E3A; --line: #36404E;
    --shadow: 0 1px 3px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--font-body); font-size: 15px; line-height: 1.45;
}
a { color: var(--indigo); }
h1 { font-family: var(--font-display); font-weight: 600; font-size: 1.6rem; margin: .2em 0 .5em; }
h2 { font-family: var(--font-display); font-weight: 600; font-size: 1.15rem; margin: 1.4em 0 .5em; }
small { color: var(--ink-soft); }

/* ---------- chrome ---------- */
.topbar {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 10px 18px; background: var(--card); border-bottom: 2px solid var(--indigo);
  position: sticky; top: 0; z-index: 50;
}
.brand { font-family: var(--font-display); font-size: 1.1rem; font-weight: 700; color: var(--ink); text-decoration: none; }
.brand-mark { color: var(--vermilion); margin-right: 2px; }
.mainnav { display: flex; gap: 4px; flex-wrap: wrap; }
.mainnav a {
  text-decoration: none; color: var(--ink-soft); padding: 6px 12px; border-radius: 999px; font-weight: 500;
}
.mainnav a.active, .mainnav a:hover { background: var(--paper-2); color: var(--ink); }
.container { max-width: 1180px; margin: 0 auto; padding: 18px 14px 60px; }
.footer { text-align: center; color: var(--ink-soft); padding: 20px; font-size: .8rem; }

/* ---------- controls ---------- */
.btn {
  border: 1.5px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: var(--radius); padding: 8px 14px; font-size: .9rem; font-weight: 600;
  cursor: pointer; transition: transform .06s ease, background .15s;
  min-height: 40px;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--vermilion); border-color: var(--vermilion); color: #fff; }
.btn-ghost:hover { background: var(--paper-2); }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--card);
  border: 1.5px solid var(--line); border-radius: var(--radius); padding: 8px 10px; min-height: 40px;
  width: 100%; max-width: 100%;
}
textarea { min-height: auto; }
label { display: block; margin: 10px 0; font-size: .88rem; color: var(--ink-soft); font-weight: 500; }
label input, label select, label textarea { margin-top: 4px; }
label.row { display: flex; align-items: center; gap: 8px; }
label.row input { width: auto; min-height: auto; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar label { display: flex; align-items: center; gap: 6px; margin: 0; }
.toolbar input, .toolbar select { width: auto; }
.range { font-family: var(--font-display); }
.count { font-size: .8rem; background: var(--indigo-soft); color: var(--ink); border-radius: 999px; padding: 2px 10px; vertical-align: middle; }
.hint { color: var(--ink-soft); font-size: .82rem; }
.callout { background: var(--holiday); border: 1px solid var(--sun); border-radius: var(--radius); padding: 10px 14px; margin: 12px 0; font-size: .9rem; }
.callout.ok { background: color-mix(in srgb, var(--matcha) 12%, var(--card)); border-color: var(--matcha); }
.empty-state { color: var(--ink-soft); padding: 20px; text-align: center; list-style: none; }

/* ---------- badges (cooks) ---------- */
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 20%; font-size: .75rem; font-weight: 800; color: #fff;
}
.badge-X { background: var(--teal); color: #fff; }
.badge-E { background: var(--vermilion); }
.badge-S { background: var(--lavender); color: #fff; }

/* ---------- planner grid ---------- */
.week-grid {
  display: grid; grid-template-columns: 52px repeat(7, minmax(120px, 1fr));
  gap: 0; margin-bottom: 26px; background: var(--card);
  border: 2px solid var(--indigo); border-radius: var(--radius); overflow-x: auto;
  box-shadow: var(--shadow);
}
@media (max-width: 900px) {
  .week-grid { display: grid; grid-template-columns: 44px repeat(7, minmax(150px, 1fr)); overflow-x: auto; }
  .week-grid-wrap { overflow-x: auto; }
}
.day-head {
  border-left: 1.5px solid var(--indigo-soft); border-bottom: 2px solid var(--indigo);
  padding: 8px 6px; text-align: center; position: relative; background: var(--paper-2);
}
.day-head.today { outline: 2px solid var(--vermilion); outline-offset: -2px; }
.day-head.holiday { background: var(--holiday); }
.kanji { display: block; font-family: var(--font-display); font-size: 1.5rem; line-height: 1.15; color: var(--indigo); }
.day-head.holiday .kanji { color: var(--vermilion); }
.dayname { font-size: .8rem; color: var(--ink-soft); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.event-flag { position: absolute; top: 4px; right: 6px; }
.holiday-dot { position: absolute; top: 8px; left: 8px; width: 8px; height: 8px; border-radius: 20%; background: var(--sun); }
.holiday-dot.inline { position: static; display: inline-block; }
.corner-cell { background: var(--paper-2); border-bottom: 2px solid var(--indigo); }
.meal-label {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-family: var(--font-display); font-size: 1.3rem; color: var(--indigo);
  border-bottom: 1.5px solid var(--indigo-soft); background: var(--paper-2); padding: 6px 2px;
}
.meal-label small { font-size: .6rem; text-transform: uppercase; letter-spacing: .05em; }
.cell {
  border-left: 1.5px solid var(--indigo-soft); border-bottom: 1.5px solid var(--indigo-soft);
  min-height: 96px; padding: 9px 8px; cursor: pointer; position: relative;
}
.cell:hover { background: var(--paper-2); }
.cell.holiday { background: var(--holiday); }
.cell.locked { /* no border — the 🔒 icon is the only indicator */ }
.cell.dinner { min-height: 140px; }
.cell-top { display: flex; justify-content: space-between; min-height: 14px; }
.line { font-size: .92rem; line-height: 1.4; overflow-wrap: anywhere; }
.line.entree { color: var(--ink-soft); font-size: .82rem; }
.line.main { font-weight: 700; font-size: 1rem; margin: 2px 0; }
.line.sides { color: var(--matcha); font-size: .85rem; }
.line.dessert { color: var(--vermilion); font-size: .82rem; }
.line.note { color: var(--ink-soft); font-size: .8rem; font-style: italic; }
.empty { color: var(--line); font-size: 1.2rem; }

/* ---------- modal ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(20,25,32,.45); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 14px;
}
.modal {
  background: var(--card); border-radius: 8px; box-shadow: var(--shadow);
  padding: 18px; width: 100%; max-width: 460px; max-height: 90vh; overflow-y: auto;
}
.modal h3 { margin-top: 0; font-family: var(--font-display); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* ---------- shopping ---------- */
.shop-wrap { max-width: 620px; margin: 0 auto; }
.shop-header { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 8px; }
.shop-total { font-family: var(--font-mono); }
.shop-add { display: flex; gap: 8px; margin: 12px 0; position: sticky; top: 58px; z-index: 40; }
.shop-add input { flex: 1; min-height: 48px; font-size: 1rem; box-shadow: var(--shadow); }
.shop-add .btn { min-width: 56px; min-height: 48px; font-size: 1.4rem; }
.shop-list { list-style: none; margin: 0; padding: 0; }
.shop-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius);
  padding: 6px 8px; margin-bottom: 8px; box-shadow: var(--shadow);
  transition: opacity .2s;
}
.shop-item.done { opacity: .55; }
.shop-item.done .shop-name { text-decoration: line-through; }
.check { background: none; border: none; cursor: pointer; padding: 4px; }
.check .box {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border: 2.5px solid var(--indigo); border-radius: var(--radius);
  font-size: 1.2rem; color: #fff; font-weight: 800; transition: background .12s, transform .12s;
}
.shop-item.done .check .box { background: var(--matcha); border-color: var(--matcha); transform: scale(1.05); }
.shop-name { flex: 1; font-size: .98rem; }
.shop-name .tag, .tag { font-size: .65rem; background: var(--indigo-soft); border-radius: 999px; padding: 1px 7px; margin-left: 4px; vertical-align: middle; }
.shop-name .ts { display: block; font-family: var(--font-mono); font-size: .68rem; }
.price { width: 72px; min-height: 36px; font-family: var(--font-mono); text-align: right; }
.del { background: none; border: none; color: var(--ink-soft); font-size: 1.3rem; cursor: pointer; padding: 4px 8px; }
.shop-tools { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; padding-top: 14px; border-top: 1.5px dashed var(--line); }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form label { display: flex; align-items: center; gap: 6px; margin: 0; }
.inline-form input, .inline-form select { width: auto; }

/* ---------- recipes ---------- */
.recipe-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.recipe-card {
  background: var(--card); border: 1.5px solid var(--line); border-left-width: 5px;
  border-radius: var(--radius); padding: 10px 12px; cursor: pointer; box-shadow: var(--shadow);
}
.recipe-card:hover { transform: translateY(-1px); }
.recipe-card.inactive { opacity: .45; }
.cuisine-french   { border-left-color: var(--indigo); }
.cuisine-japanese { border-left-color: var(--vermilion); }
.cuisine-intl     { border-left-color: var(--matcha); }
.recipe-name { font-weight: 700; }
.recipe-alt { color: var(--ink-soft); font-size: .8rem; }
.recipe-meta { display: flex; gap: 8px; align-items: center; margin-top: 4px; font-size: .8rem; color: var(--ink-soft); }
.planned { font-family: var(--font-mono); }
.recipe-sides { font-size: .76rem; color: var(--matcha); margin-top: 3px; }

/* ---------- tables & stats ---------- */
.table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.table th, .table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); font-size: .9rem; }
.table th { background: var(--paper-2); font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-soft); }
.table input { min-height: 36px; }
.row-actions { white-space: nowrap; }
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin: 14px 0; }
.stat-card { background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.stat-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-soft); }
.stat-value { font-family: var(--font-mono); font-size: 1.7rem; font-weight: 700; color: var(--vermilion); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
@media (max-width: 760px) { .two-col { grid-template-columns: 1fr; } }
.settings-form { max-width: 640px; }

/* ---------- a11y ---------- */
:focus-visible { outline: 3px solid var(--vermilion); outline-offset: 1px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- v1.1: sauce line, inactive rows, ingredient adder ---------- */
.line.sauce { color: var(--vermilion); font-size: .85rem; font-style: italic; }
.inactive-row { opacity: .45; }
.ing-adder { display: flex; gap: 6px; margin: -2px 0 10px; }
.ing-adder input { flex: 1; }
.print-header, .print-footer { display: none; }

/* ============================================================
   Print — faithful to the family paper template:
   A4 landscape, 2 week-grids per page, light paper rendering,
   kanji headers + indigo lines preserved, zero app chrome.
   ============================================================ */
@media print {
  @page { size: A4 landscape; margin: 7mm 7mm 10mm; }
  :root {
    --paper: #fff; --paper-2: #F4F0E6; --ink: #1c2430; --ink-soft: #4c5663;
    --indigo: #3D5BA9; --indigo-soft: #B9C6E6; --holiday: #FBF0D2;
    --card: #fff; --line: #d8d2c2; --shadow: none;
  }
  body { background: #fff; font-size: 15px; }
  /* screen-only chrome AND the on-screen-only legend + lock cues: never on paper */
  .topbar, .toolbar, .footer, .hint, .modal-back, .btn, .banner, .legend { display: none !important; }
  .lock, .cell.lockmode::after { display: none !important; }
  .container { max-width: none; padding: 0; }
  .print-header {
    display: block; font-family: var(--font-display); font-size: 20px;
    margin-bottom: 5mm; color: var(--ink);
  }
  .print-footer {
    display: block; position: fixed; bottom: 0; left: 0; right: 0;
    font-size: 9px; color: var(--ink-soft); text-align: center;
  }
  .week-grid {
    page-break-inside: avoid; break-inside: avoid;
    margin-bottom: 6mm; border-radius: 4px; box-shadow: none;
    grid-template-columns: 42px repeat(7, 1fr); overflow: visible;
  }
  .week-grid:nth-of-type(2n):not(:last-of-type) { page-break-after: always; }
  .kanji { font-size: 24px; }
  .dayname { font-size: 14px; font-weight: 700; }
  .meal-label { font-size: 22px; }
  .meal-label small { font-size: 10px; }
  .day-head { padding: 6px 2px; }
  .day-event { font-size: 11px; color: var(--vermilion); }
  .day-event.ferie { font-size: 10px; }
  .cell { min-height: 20mm; padding: 2.5mm; cursor: default; }
  .cell.dinner { min-height: 46mm; }
  .cell:hover { background: inherit; }
  .cell.holiday { background: var(--holiday) !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .day-head.holiday { background: var(--holiday) !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .day-head.today { outline: none; }
  .line { font-size: 15px; line-height: 1.5; }
  .line.main { font-size: 18px; font-weight: 700; margin: 2px 0; }
  .line.entree, .line.sides, .line.sauce, .line.dessert, .line.note { font-size: 14px; }
  .badge { width: 22px; height: 22px; font-size: 13px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .empty { display: none; }
}
.account-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.account-actions .btn, .account-actions form button { width: 100%; }
.account-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.account-actions .btn, .account-actions form button { width: 100%; }

/* ---------- v1.2.4: named events / fériés in day headers ---------- */
.day-event {
  display: block; max-width: 100%; padding: 1px 3px 0;
  font-size: .7rem; line-height: 1.2; font-weight: 600; color: var(--vermilion);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.day-event.ferie { color: var(--ink-soft); font-weight: 500; font-style: italic; }
@media print {
  .day-event { font-size: 10px; color: var(--vermilion); }
  .day-event.ferie { font-size: 9px; }
}

/* ---------- v1.3: discovery / new tags ---------- */
.tag-new { background: color-mix(in srgb, var(--matcha) 22%, var(--card)); border: 1px solid var(--matcha); color: var(--ink); }

/* ---------- v1.3.2: legend (bigger, explicit) ---------- */
.legend {
  display: flex; flex-wrap: wrap; gap: 10px 22px; margin-top: 16px;
  padding: 14px 16px; background: var(--card); border: 1.5px solid var(--line);
  border-radius: var(--radius); font-size: .95rem; line-height: 1.5;
}
.legend-item { display: flex; align-items: center; gap: 7px; }
.legend-swatch { display: inline-block; width: 20px; height: 20px; border-radius: var(--radius); border: 1px solid var(--line); vertical-align: middle; }
.holiday-swatch { background: var(--holiday); border-color: var(--sun); }
.legend .badge { width: 22px; height: 22px; font-size: .8rem; }

/* ---------- v1.3.2: Lock mode ---------- */
.lockmode-on { background: var(--teal) !important; border-color: var(--teal) !important; color: #fff !important; }
.cell.lockmode { cursor: pointer; }
.cell.lockmode::after {
  content: "🔒"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; background: color-mix(in srgb, var(--teal) 14%, transparent);
  opacity: 0; transition: opacity .12s;
}
.cell.lockmode:hover::after { opacity: 1; }
.cell.lockmode.locked::after { opacity: .35; }

/* ── Dice menu (v1.3.6): varied dinner alternatives in the cell editor ───── */
.main-row { display: flex; gap: 6px; align-items: center; }
.main-row input { flex: 1; }
.dice-menu {
  display: flex; flex-direction: column; gap: 4px;
  margin: 2px 0 4px; padding: 6px;
  background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--radius);
}
.dice-opt {
  display: flex; align-items: center; gap: 8px;
  text-align: left; width: 100%;
  padding: 6px 8px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); color: var(--ink); cursor: pointer; font: inherit;
}
.dice-opt:hover { border-color: var(--teal); }
.dice-tag {
  flex: 0 0 auto; min-width: 92px;
  font-size: .72rem; font-weight: 600; letter-spacing: .02em;
  color: var(--lavender); text-transform: uppercase;
}
.dice-name { color: var(--ink); }

/* ── Auth pages (login / account): re-add the centred card that was lost ──── */
.auth-body {
  min-height: 100vh; margin: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--paper); padding: 24px;
}
.auth-card {
  width: 100%; max-width: 360px;
  background: var(--card); color: var(--ink);
  border: 1.5px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 24px;
}
.auth-brand { font-family: var(--font-display); font-size: 1.3rem; margin-bottom: 16px; }
.auth-card p { margin: 6px 0; }
.auth-card label { display: block; margin-bottom: 12px; }
.auth-card input { width: 100%; box-sizing: border-box; }
.auth-submit, .auth-card form .btn-primary { width: 100%; margin-top: 6px; }
.auth-error {
  background: var(--holiday); color: var(--vermilion);
  border: 1px solid var(--vermilion); border-radius: var(--radius);
  padding: 8px 12px; margin-bottom: 12px; font-size: .9rem;
}
.auth-link { display: inline-block; margin-top: 12px; color: var(--ink-soft); font-size: .9rem; }

/* ── Recipe card badges (v1.3.6): show course + structure at a glance ─────── */
.recipe-legend {
  display: flex; flex-wrap: wrap; gap: 14px; align-items: center;
  margin: 4px 0 12px; font-size: .82rem; color: var(--ink-soft);
}
.recipe-legend .sw { display: inline-block; width: 22px; height: 0; border-top: 3px solid var(--line); vertical-align: middle; margin-right: 4px; border-radius: 2px; }
.recipe-legend .sw.fr { border-top-color: var(--indigo); }
.recipe-legend .sw.jp { border-top-color: var(--vermilion); }
.recipe-legend .sw.in { border-top-color: var(--matcha); }
.r-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.r-badge {
  font-size: .68rem; font-weight: 600; letter-spacing: .02em; text-transform: uppercase;
  padding: 2px 7px; border-radius: var(--radius); border: 1px solid var(--line); color: var(--ink-soft);
}
.r-badge.course   { color: var(--lavender); border-color: var(--lavender); }
.r-badge.complete { color: var(--matcha);   border-color: var(--matcha); }
.r-badge.composed { color: var(--indigo);   border-color: var(--indigo); }

/* ===== v1.4.0 — per-field dice, garbage-in guard, Pools panel (append-only) ===== */
.dice-meta { margin-left: auto; font-size: .78rem; opacity: .75; white-space: nowrap; }
.confirm-add { border: 1px solid var(--lavender); border-radius: var(--radius); padding: .6rem .7rem; margin: .5rem 0; background: rgba(126,107,201,.07); }
.confirm-add p { margin: 0 0 .45rem; }
.hint-inline { font-size: .8rem; opacity: .7; }
.season-picks { display: inline-flex; flex-wrap: wrap; gap: .3rem; margin: .2rem 0; }
.chip { border: 1px solid var(--teal); background: transparent; color: inherit; border-radius: 999px; padding: .15rem .55rem; font-size: .8rem; cursor: pointer; }
.chip.on { background: var(--teal); color: #fff; }
.pool-panel { margin: .8rem 0 1rem; border: 1px solid rgba(14,111,111,.35); border-radius: var(--radius); padding: .5rem .7rem; }
.pool-panel summary { cursor: pointer; }
.pool-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; margin-top: .6rem; }
.pool-col h3 { margin: .2rem 0 .4rem; }
.pool-row { display: flex; align-items: center; gap: .35rem; margin: .2rem 0; flex-wrap: wrap; }
.pool-row input { flex: 1 1 130px; min-width: 110px; }
.pool-row.inactive-row { opacity: .5; }
.plan-it { border-top: 1px dashed rgba(14,111,111,.4); margin-top: .6rem; padding-top: .5rem; font-size: .9rem; }
.plan-it .main-row { display: inline-flex; gap: .35rem; align-items: center; margin-left: .3rem; }
