/* Recipe & Meal Planner web UI. Mobile first; the planner grid widens on tablets and desktops. */
:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --surface-2: #f3eee6;
  --text: #1f1b16;
  --muted: #6b6259;
  --line: #e4ddd2;
  --accent: #c2410c;
  --accent-soft: #fde9dc;
  --accent-text: #ffffff;
  --good: #15803d;
  --warn: #b45309;
  --danger: #b91c1c;
  --star: #d97706;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.05);
  --nav-h: 60px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17140f;
    --surface: #211d17;
    --surface-2: #2a251e;
    --text: #f1ebe2;
    --muted: #a69c90;
    --line: #3a332a;
    --accent: #f97316;
    --accent-soft: #3b2415;
    --accent-text: #1a0e05;
    --good: #4ade80;
    --warn: #fbbf24;
    --danger: #f87171;
    --star: #fbbf24;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.5 var(--font); color: var(--text); background: var(--bg); min-height: 100dvh; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
label { display: block; font-size: .9rem; color: var(--muted); margin-bottom: .75rem; }
label > input, label > select, label > textarea { display: block; width: 100%; margin-top: .25rem; color: var(--text); }
input, select, textarea {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .55rem .7rem; min-height: 42px;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { min-height: 110px; resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: auto; min-height: 0; display: inline-block; margin-right: .4rem; accent-color: var(--accent); }
label.inline { display: flex; align-items: center; gap: .4rem; color: var(--text); }
label.inline input { margin: 0; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--danger); }
.warn { color: var(--warn); }
.hidden { display: none !important; }
.right { text-align: right; }

/* ---- buttons -------------------------------------------------------------------------- */
.btn, button {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: .5rem .9rem; min-height: 42px; text-decoration: none; white-space: nowrap;
}
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.btn-primary:hover { filter: brightness(1.05); background: var(--accent); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.btn-sm { min-height: 34px; padding: .3rem .65rem; font-size: .9rem; }
.btn-icon { min-width: 42px; padding: .4rem; }
.btn-link { border: 0; background: none; color: var(--accent); padding: 0; min-height: 0; }
.btn-link:hover { background: none; text-decoration: underline; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; margin: .75rem 0; }

/* ---- layout --------------------------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  padding: 0 1rem; height: 56px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 1.15rem; color: var(--text); }
.nav { display: flex; gap: .25rem; }
.nav a { display: flex; align-items: center; gap: .4rem; padding: .45rem .75rem; border-radius: 8px; color: var(--muted); }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { color: var(--accent); background: var(--accent-soft); }
.nav .ico { display: none; }
.app { max-width: 1100px; margin: 0 auto; padding: 1rem; padding-bottom: 2rem; }

@media (max-width: 720px) {
  .topbar { height: 48px; }
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; height: var(--nav-h); z-index: 10; background: var(--surface);
    border-top: 1px solid var(--line); justify-content: space-around; padding-bottom: env(safe-area-inset-bottom);
  }
  .nav a { flex-direction: column; gap: 0; font-size: .7rem; padding: .35rem .5rem; flex: 1; border-radius: 0; }
  .nav a.active { background: none; }
  .nav .ico { display: block; font-size: 1.25rem; }
  .app { padding-bottom: calc(var(--nav-h) + 1.5rem); }
}

/* ---- cards and chips ------------------------------------------------------------------ */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.grid { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.recipe-card { padding: 0; overflow: hidden; display: flex; flex-direction: column; color: inherit; }
.recipe-card:hover { text-decoration: none; border-color: var(--accent); }
.recipe-card .thumb { aspect-ratio: 16 / 10; background: var(--surface-2); object-fit: cover; width: 100%; }
.recipe-card .thumb.placeholder { display: flex; align-items: center; justify-content: center; font-size: 2rem; color: var(--muted); }
.recipe-card .body { padding: .75rem .9rem .9rem; display: flex; flex-direction: column; gap: .35rem; flex: 1; }
.recipe-card h3 { font-size: 1.02rem; margin: 0; }
.meta { display: flex; flex-wrap: wrap; gap: .35rem .75rem; color: var(--muted); font-size: .85rem; align-items: center; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip {
  display: inline-flex; align-items: center; gap: .3rem; padding: .15rem .6rem; border-radius: 999px; font-size: .8rem;
  background: var(--surface-2); color: var(--text); border: 1px solid transparent; min-height: 0; cursor: default;
}
.chip.cuisine { background: #e0f2fe; color: #0c4a6e; } .chip.diet { background: #dcfce7; color: #14532d; }
.chip.meal_type { background: #fef3c7; color: #78350f; }
@media (prefers-color-scheme: dark) {
  .chip.cuisine { background: #0c3a52; color: #bae6fd; } .chip.diet { background: #14402a; color: #bbf7d0; } .chip.meal_type { background: #4a3410; color: #fde68a; }
}
button.chip { cursor: pointer; border-color: var(--line); background: var(--surface); }
button.chip:hover { background: var(--surface-2); }
button.chip.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.chip .x { opacity: .6; margin-left: .1rem; }
.stars { color: var(--star); letter-spacing: .05em; white-space: nowrap; }
.stars.dim { color: var(--line); }
.star-input { display: inline-flex; gap: .1rem; }
.star-input button { border: 0; background: none; padding: .1rem; min-height: 0; font-size: 1.6rem; color: var(--line); cursor: pointer; line-height: 1; }
.star-input button.on { color: var(--star); }
.fav { color: var(--accent); }
.badge { display: inline-block; padding: .05rem .5rem; border-radius: 6px; font-size: .75rem; font-weight: 600; background: var(--surface-2); }
.badge.cooked { background: color-mix(in srgb, var(--good) 20%, transparent); color: var(--good); }
.badge.skipped { background: color-mix(in srgb, var(--muted) 20%, transparent); color: var(--muted); }
.badge.untried { background: var(--accent-soft); color: var(--accent); }

/* ---- toolbar ---------------------------------------------------------------------------- */
.toolbar { display: flex; flex-direction: column; gap: .6rem; margin-bottom: 1rem; }
.toolbar .search { display: flex; gap: .5rem; }
.toolbar .search input { flex: 1; }
.toolbar select { min-height: 36px; padding: .3rem .5rem; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 1rem; gap: .5rem; }
.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }

/* ---- recipe page ----------------------------------------------------------------------- */
.recipe-head { display: grid; gap: 1rem; grid-template-columns: 1fr; margin-bottom: 1rem; }
@media (min-width: 720px) { .recipe-head.with-photo { grid-template-columns: 320px 1fr; } }
.recipe-head img { border-radius: var(--radius); width: 100%; aspect-ratio: 4/3; object-fit: cover; }
.recipe-body { display: grid; gap: 1.25rem; grid-template-columns: 1fr; }
@media (min-width: 900px) { .recipe-body { grid-template-columns: 1fr 1.6fr; } }
.ingredients { list-style: none; padding: 0; margin: 0; }
.ingredients li { padding: .45rem 0; border-bottom: 1px solid var(--line); display: flex; gap: .6rem; align-items: flex-start; }
.ingredients li input { margin-top: .3rem; }
.ingredients li.done span { text-decoration: line-through; color: var(--muted); }
.steps { padding-left: 1.4rem; margin: 0; }
.steps li { padding: .4rem 0; border-bottom: 1px solid var(--line); }
.cook-mode { font-size: 1.3rem; }
.cook-mode .ingredients li, .cook-mode .steps li { padding: .7rem 0; }
.cook-mode .steps li { font-size: 1.35rem; line-height: 1.55; }
.history li { display: flex; justify-content: space-between; gap: .5rem; padding: .35rem 0; border-bottom: 1px solid var(--line); }
.history ul { list-style: none; padding: 0; margin: 0; }

/* ---- forms ------------------------------------------------------------------------------ */
.form-grid { display: grid; gap: 0 1rem; grid-template-columns: 1fr; }
@media (min-width: 640px) { .form-grid { grid-template-columns: 1fr 1fr; } .form-grid .span2 { grid-column: span 2; } }
.form-grid.cols4 { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 640px) { .form-grid.cols4 { grid-template-columns: repeat(4, 1fr); } }
.import-box { display: flex; gap: .5rem; flex-wrap: wrap; }
.import-box input { flex: 1; min-width: 200px; }
.notes-list { margin: .5rem 0; padding-left: 1.2rem; }

/* ---- planner ----------------------------------------------------------------------------- */
.week-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; flex-wrap: wrap; margin-bottom: .75rem; }
.week-head .row:first-child { flex-wrap: nowrap; }
@media (max-width: 720px) { .week-head h1 { font-size: 1.2rem; } }
.week-grid { display: grid; gap: .6rem; grid-template-columns: 1fr; }
@media (min-width: 720px) { .week-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1000px) { .week-grid { grid-template-columns: repeat(7, 1fr); } }
.day { padding: .75rem; display: flex; flex-direction: column; gap: .5rem; min-height: 120px; }
.day.today { border-color: var(--accent); }
.day .dname { font-weight: 700; display: flex; justify-content: space-between; align-items: baseline; }
.day .dname small { color: var(--muted); font-weight: 400; }
.day .entry { flex: 1; }
.day .entry .title { font-weight: 600; }
.day .entry.note .title { font-style: italic; color: var(--muted); }
.day .day-actions { display: flex; gap: .35rem; flex-wrap: wrap; }
.day .day-actions button { min-height: 32px; padding: .2rem .5rem; font-size: .82rem; }
.warnings { margin: .75rem 0; padding: .6rem .8rem; border-radius: 8px; background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }

/* ---- picker ------------------------------------------------------------------------------- */
.picker-results { list-style: none; padding: 0; margin: .5rem 0 0; max-height: 40vh; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.picker-results li { padding: .5rem .7rem; border-bottom: 1px solid var(--line); cursor: pointer; display: flex; justify-content: space-between; gap: .5rem; }
.picker-results li:hover, .picker-results li.sel { background: var(--surface-2); }

/* ---- tables ------------------------------------------------------------------------------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .5rem .4rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: .85rem; }
td select { min-height: 34px; padding: .25rem .4rem; }
.table-wrap { overflow-x: auto; }

/* ---- photo crop ---------------------------------------------------------------------------- */
.crop-wrap { position: relative; display: inline-block; max-width: 100%; touch-action: none; cursor: crosshair; user-select: none; line-height: 0; }
.crop-wrap img { display: block; max-width: 100%; max-height: 60vh; -webkit-user-drag: none; pointer-events: none; }
.crop-box { position: absolute; border: 2px dashed #fff; box-shadow: 0 0 0 9999px rgba(0,0,0,.5); pointer-events: none; }

/* ---- modal and toast --------------------------------------------------------------------- */
.modal { border: 0; border-radius: var(--radius); padding: 0; background: var(--surface); color: var(--text); max-width: min(560px, calc(100vw - 2rem)); width: 100%; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal::backdrop { background: rgba(0,0,0,.45); }
.modal .modal-body { padding: 1.25rem; }
.modal h2 { margin-bottom: .75rem; }
.modal .modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }
.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 1rem); transform: translateX(-50%) translateY(20px); opacity: 0; transition: .25s; background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 8px; z-index: 50; max-width: calc(100vw - 2rem); pointer-events: none; }
@media (min-width: 721px) { .toast { bottom: 1.5rem; } }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); color: #fff; }

/* ---- auth pages ---------------------------------------------------------------------------- */
body.auth { display: grid; place-items: center; padding: 1rem; }
body.auth .card { width: 100%; max-width: 380px; padding: 1.5rem; }
body.auth button { width: 100%; }
body.auth h1 { margin-bottom: 1rem; }
