@import url("https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600&display=swap");
@import url("./tokens.css");

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--background); color: var(--foreground); font: var(--text-base)/1.5 var(--font-sans); }
button, input, textarea, select { font: inherit; color: inherit; }
button, a, select, label:has(input[type=checkbox]) { touch-action: manipulation; }
button, a, summary, select { cursor: pointer; }
button { border: 0; background: none; }
a { color: var(--primary); }
:focus-visible, .import:focus-within { outline: 2px solid var(--ring); outline-offset: 2px; }
h1, h2, h3, p { margin: 0; }
svg { display: block; flex: none; }
small { display: block; color: var(--muted-foreground); font-size: var(--text-xs); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

.button, .icon-button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--control); padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--card); color: var(--card-foreground); box-shadow: var(--shadow-sm);
  font-size: var(--text-sm); font-weight: var(--weight-medium); line-height: 1.2; text-align: center; text-decoration: none;
}
.button:hover, .icon-button:hover, nav a:hover { background: var(--accent); color: var(--accent-foreground); }
.primary { font-weight: var(--weight-semibold); background: var(--primary); border-color: var(--primary); color: var(--primary-foreground); }
.primary:hover { background: color-mix(in srgb, var(--primary) 90%, var(--background)); color: var(--primary-foreground); }
.square, .bare, .icon-button { min-width: var(--control); padding: 0; flex-shrink: 0; }
.bare, .text-button { background: none; border-color: var(--transparent); box-shadow: none; }
.bare { color: var(--muted-foreground); }
.text-button { min-height: 0; padding: var(--space-1); color: var(--primary); text-decoration: underline; text-underline-offset: 3px; }
.danger { color: var(--destructive); }
.danger:hover { background: color-mix(in srgb, var(--destructive), var(--card) 92%); color: var(--destructive); }
.selected, .favorited, .button[aria-pressed=true] { background: var(--secondary); color: var(--secondary-foreground); border-color: var(--input); }
.favorited svg, .button[aria-pressed=true] svg { fill: currentColor; }
.card, .panel, .recipe-card, .grocery-summary, .day {
  background: var(--card); color: var(--card-foreground);
  border: 1px solid var(--border); border-radius: var(--radius-xl); box-shadow: var(--shadow-sm);
}

.top { border-bottom: 1px solid var(--border); background: var(--card); }
.bar { min-height: 4rem; display: flex; align-items: center; justify-content: space-between; max-width: var(--content); margin: auto; padding: 0 var(--space-4); gap: var(--space-4); }
#page-title { font-size: var(--text-xl); font-weight: var(--weight-semibold); line-height: 1.2; }
.icon-button { background: none; border-color: var(--transparent); box-shadow: none; }
nav {
  position: fixed; inset: auto 0 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-1); z-index: 4;
  padding: var(--space-2) var(--space-2) calc(var(--space-2) + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--border);
}
nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-1); min-height: var(--control); padding: var(--space-1); border-radius: var(--radius-md); color: var(--muted-foreground); font-size: var(--text-xs); font-weight: var(--weight-medium); text-decoration: none; }
nav a[aria-current] { background: var(--secondary); color: var(--secondary-foreground); }

.shell { max-width: var(--content); margin: auto; padding: var(--space-6) var(--space-4) calc(6rem + env(safe-area-inset-bottom)); }
.page-actions { display: flex; flex-direction: column; gap: var(--space-3); margin-bottom: var(--space-4); }
.page-actions p { color: var(--muted-foreground); font-size: var(--text-sm); }
.actions { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2); }
.week-controls { display: flex; flex-direction: column; gap: var(--space-3); justify-content: space-between; margin-bottom: var(--space-4); }
.menu-template { align-self: flex-end; margin-inline-start: auto; }
.week-selector { display: flex; align-items: center; gap: var(--space-3); }
.week-arrows { display: flex; gap: var(--space-1); }
.date-box { display: flex; flex-direction: column; align-items: flex-start; text-align: left; font-size: var(--text-sm); }
.date-box span { color: var(--muted-foreground); font-size: var(--text-xs); }
.native-select { position: relative; display: inline-flex; max-width: 100%; min-width: 0; }
.native-select select {
  appearance: none; display: block; width: 100%; min-width: 0; min-height: var(--control);
  padding: var(--space-2) var(--space-10) var(--space-2) var(--space-3);
  border: 1px solid var(--input); border-radius: var(--radius-md);
  background: var(--field); color: var(--foreground); box-shadow: var(--shadow-sm);
  font-size: var(--text-base); font-weight: var(--weight-regular); text-overflow: ellipsis;
}
/* Some native popups keep a light surface even when the page is dark. */
.native-select option {
  color-scheme: light;
  background: Canvas;
  color: CanvasText;
}
@supports (appearance: base-select) and selector(::picker(select)) {
  .native-select select, .native-select select::picker(select) { appearance: base-select; }
  .native-select select::picker-icon { display: none; }
  .native-select select::picker(select) {
    margin-block: var(--space-1);
    padding: var(--space-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--popover);
    color: var(--popover-foreground);
    box-shadow: var(--shadow-lg);
    max-height: min(20rem, 50dvh);
  }
  .native-select option {
    color-scheme: inherit;
    background: var(--popover);
    color: var(--popover-foreground);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
  }
  .native-select option:is(:hover, :focus-visible, :checked) {
    background: var(--accent);
    color: var(--accent-foreground);
  }
}
.native-select > svg {
  position: absolute; inset-inline-end: var(--space-3); top: 50%; transform: translateY(-50%);
  color: var(--muted-foreground); pointer-events: none;
}
.theme-field { justify-self: start; min-width: 10rem; }
.feature {
  position: relative; isolation: isolate; overflow: hidden; border: 1px solid var(--border);
  border-radius: var(--radius-xl); min-height: 12rem; display: flex; align-items: center;
  background: var(--card); padding: var(--space-6); margin-bottom: var(--space-6);
}
.feature:has(.feature-photo) { color: var(--feature-foreground); background: var(--feature-shade); }
.feature-photo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: -2; }
.feature:has(.feature-photo)::before {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background: linear-gradient(90deg, var(--feature-shade), var(--feature-fade)), var(--feature-fade);
}
.feature-content { min-width: 0; }
.feature h2 { font-weight: var(--weight-semibold); font-size: clamp(1.5rem, 4vw, 2.25rem); line-height: 1.1; letter-spacing: -.035em; overflow-wrap: anywhere; }
.feature p { margin-top: var(--space-1); font-size: var(--text-sm); }
.feature .feature-period { display: flex; align-items: center; gap: var(--space-2); margin: 0 0 var(--space-2); }
.feature-button { margin-top: var(--space-4); }
.feature-button:has(.lucide-arrow-right) { flex-direction: row-reverse; }
.section-title { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-2); margin-bottom: var(--space-3); }
.section-title h2, .grocery-group h2 { font-size: var(--text-xl); font-weight: var(--weight-medium); letter-spacing: -.025em; }
.section-title span { font-size: var(--text-sm); color: var(--muted-foreground); }
.day-grid { display: grid; gap: var(--space-3); }
.day { overflow: hidden; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.day.today { border-color: var(--ring); }
.day-title { grid-column: 1/-1; display: flex; align-items: center; justify-content: space-between; gap: var(--space-1); padding: var(--space-2) var(--space-3); background: var(--muted); }
.today .day-title { background: var(--secondary); color: var(--secondary-foreground); }
.day-title h3 { font-size: var(--text-sm); font-weight: var(--weight-medium); }
.day-title span { font-size: var(--text-xs); font-weight: var(--weight-medium); }
.meal { min-width: 0; min-height: 7.5rem; padding: var(--space-1) var(--space-3) var(--space-3); display: flex; flex-direction: column; align-items: flex-start; }
.meal + .meal { border-left: 1px solid var(--border); }
.meal-head { width: 100%; display: flex; justify-content: space-between; align-items: center; min-height: var(--control); }
.meal-period { display: inline-flex; align-items: center; color: var(--muted-foreground); }
.meal-link, .recipe-title { font-weight: var(--weight-regular); color: var(--foreground); text-align: left; padding: 0; line-height: 1.35; text-decoration: underline; text-decoration-color: var(--input); text-underline-offset: 3px; overflow-wrap: anywhere; }
.meal-link { min-height: 2rem; }
.meal-link:hover, .recipe-title:hover { color: var(--primary); text-decoration-color: currentColor; }
.meal-meta { color: var(--muted-foreground); font-size: var(--text-xs); margin-top: auto; padding-top: var(--space-1); }
.add-meal { align-self: center; }

.filters { display: flex; gap: var(--space-2); margin-bottom: var(--space-4); }
.search { position: relative; display: flex; align-items: center; min-width: 0; width: min(100%, 23rem); }
.search > svg { position: absolute; left: var(--space-3); color: var(--muted-foreground); pointer-events: none; }
.search input { padding-left: var(--space-10); }
.recipe-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr)); gap: var(--space-3); }
.recipe-card { position: relative; overflow: hidden; display: flex; flex-direction: column; }
.recipe-photo { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: var(--muted); }
.recipe-card-body { display: grid; gap: var(--space-2); align-content: space-between; flex: 1; padding: var(--space-4); }
.recipe-card .favorited, .recipe-card .square { position: absolute; top: var(--space-2); right: var(--space-2); }
.recipe-title { min-height: var(--control); }
.recipe-meta, .recipe-info { display: flex; align-items: center; gap: var(--space-2); color: var(--muted-foreground); font-size: var(--text-sm); }
.recipe-grid .empty { grid-column: 1/-1; }

.item-row { display: flex; align-items: center; gap: var(--space-2); min-height: 3.75rem; padding: var(--space-2) var(--space-3); overflow-wrap: anywhere; }
.item-row + .item-row { border-top: 1px solid var(--border); }
.item-row > :first-child { flex: 1; min-width: 0; }
.item-qty { white-space: nowrap; color: var(--muted-foreground); font-variant-numeric: tabular-nums; font-size: var(--text-sm); }
.empty { padding: var(--space-6); color: var(--muted-foreground); }
.grocery-summary { padding: var(--space-3); margin-bottom: var(--space-4); display: flex; gap: var(--space-3); align-items: center; }
.grocery-summary span { display: inline-flex; gap: var(--space-2); align-items: center; font-weight: var(--weight-medium); white-space: nowrap; font-size: var(--text-sm); }
progress { flex: 1; width: 0; min-width: 0; height: .5rem; overflow: hidden; border: 0; border-radius: var(--radius-lg); background: var(--secondary); accent-color: var(--primary); }
progress::-webkit-progress-bar { background: var(--secondary); }
progress::-webkit-progress-value { background: var(--primary); border-radius: var(--radius-lg); }
progress::-moz-progress-bar { background: var(--primary); border-radius: var(--radius-lg); }
.grocery-group { margin-bottom: var(--space-3); overflow: hidden; }
.grocery-group h2 { font-size: var(--text-base); padding: var(--space-3); background: var(--muted); }
.grocery-row label { display: flex; align-items: center; gap: var(--space-2); min-height: var(--control); }
.grocery-row input { margin: 0; width: 1.125rem; height: 1.125rem; accent-color: var(--primary); flex: none; }
.done .item-name, .done .item-qty { text-decoration: line-through; color: var(--muted-foreground); }
.disclosure { padding: var(--space-3); margin-top: var(--space-3); }
.disclosure ul { padding-left: var(--space-6); }
summary { font-weight: var(--weight-medium); }

dialog {
  width: min(36rem, calc(100% - var(--space-6))); max-height: calc(100dvh - var(--space-8));
  overscroll-behavior: contain; padding: 0; border: 1px solid var(--border); border-radius: var(--radius-xl);
  background: var(--popover); color: var(--popover-foreground); box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: var(--backdrop); }
body:has(dialog[open]) { overflow: hidden; }
dialog header { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); padding: var(--space-2) var(--space-4); background: var(--popover); border-bottom: 1px solid var(--border); }
dialog h2 { font-size: var(--text-xl); line-height: 1.25; font-weight: var(--weight-semibold); letter-spacing: -.025em; overflow-wrap: anywhere; }
.dialog-body { padding: var(--space-4); display: grid; gap: var(--space-3); }
.dialog-body form { display: grid; gap: var(--space-3); }
.dialog-body h3 { font-size: var(--text-base); font-weight: var(--weight-medium); margin-top: var(--space-1); }
.dialog-body label:not(.import) { display: grid; gap: var(--space-1); font-size: var(--text-sm); font-weight: var(--weight-medium); min-width: 0; }
:where(.search input, .dialog-body input:not([type=file]), .dialog-body textarea) {
  display: block; width: 100%; min-width: 0; min-height: var(--control); padding: var(--space-2) var(--space-3);
  border: 1px solid var(--input); border-radius: var(--radius-md); background: var(--card);
  box-shadow: var(--shadow-sm); font-size: var(--text-base); font-weight: var(--weight-regular);
}
::placeholder { color: var(--muted-foreground); }
.dialog-body textarea { resize: vertical; }
.dialog-actions, .settings-actions { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.dialog-actions { justify-content: flex-end; margin-top: var(--space-2); }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2); }
.fixed-unit { display: grid; align-content: start; gap: var(--space-2); font-size: var(--text-sm); }
.ingredient-list, .steps { margin: 0; }
.ingredient-list { padding: 0; list-style: none; }
.ingredient-list li { display: flex; justify-content: space-between; gap: var(--space-2); border-bottom: 1px solid var(--border); padding: var(--space-2) 0; }
.steps, .shortcut-help ol { padding-left: var(--space-5); }
.steps li + li, .shortcut-help li + li { margin-top: var(--space-2); }
.hint, .shortcut-help, .storage-note { background: var(--muted); color: var(--muted-foreground); border-radius: var(--radius-md); padding: var(--space-3); font-size: var(--text-sm); }
.recipe-ingredient { display: grid; gap: var(--space-2); padding: var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.recipe-ingredient + .recipe-ingredient { margin-top: var(--space-2); }
.recipe-ingredient button { justify-self: end; }
.import { position: relative; overflow: hidden; }
.import input { position: absolute; opacity: 0; inset: 0; width: 100%; cursor: pointer; }
.storage-note { color: var(--foreground); border: 1px solid var(--border); margin-bottom: var(--space-3); }

.cloud-status { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-xs); color: var(--muted-foreground); margin-top: var(--space-5); }
.cloud-status[data-status=saved] { color: var(--primary); }
.cloud-status[data-status=offline], .cloud-status[data-status=conflict] { color: var(--foreground); }
#toast {
  position: fixed; z-index: 6; bottom: calc(5rem + env(safe-area-inset-bottom)); left: 50%;
  transform: translate(-50%, var(--space-2)); width: max-content; max-width: calc(100% - var(--space-8));
  color: var(--popover-foreground); background: var(--popover); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  border-radius: var(--radius-lg); padding: var(--space-2) var(--space-4);
  opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s; font-size: var(--text-sm);
}
#toast.visible { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 650px) {
  .bar, .shell { padding-inline: var(--space-6); }
  #page-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  nav { position: static; display: flex; padding: 0; border: 0; background: none; }
  nav a { flex-direction: row; padding-inline: var(--space-3); gap: var(--space-2); font-size: var(--text-sm); }
  .shell { padding-block: var(--space-8); }
  .menu-template { align-self: center; }
  .page-actions, .week-controls { flex-wrap: wrap; flex-direction: row; align-items: center; justify-content: space-between; }
  .day-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .feature { padding: var(--space-8); }
  .feature-photo { inset-inline-start: auto; width: 75%; }
  #toast { bottom: var(--space-6); }
}
@media (min-width: 1100px) {
  .bar, .shell { padding-inline: var(--space-8); }
  .day-grid { grid-template-columns: repeat(7, minmax(0, 1fr)); gap: var(--space-2); }
  .day { display: flex; flex-direction: column; }
  .meal + .meal { border: 0; border-top: 1px solid var(--border); }
}
@media (prefers-reduced-motion: reduce) {
  #toast { transition: none; }
}

.breakfast-stock { margin-top: var(--space-4); }

.meal-check { display: inline-flex; align-items: center; gap: var(--space-1); min-height: 2rem; font-size: var(--text-xs); color: var(--muted-foreground); cursor: pointer; }
.meal-check input { margin: 0; accent-color: var(--primary); }

/* Existing neutral shadcn-style tokens and controls retained for shared planning. */
nav { grid-template-columns: repeat(3, 1fr); }
.period-duration { display: flex; align-items: center; gap: var(--space-2); color: var(--muted-foreground); font-size: var(--text-sm); }
.period-duration .native-select { min-width: 6rem; }
.account-panel { max-width: 30rem; margin: var(--space-8) auto; padding: var(--space-6); }
.account-panel h2, .account-panel .hint { margin-bottom: var(--space-4); }
.account-panel form, .account-panel label { display: grid; gap: var(--space-2); }
.account-panel form { gap: var(--space-4); }
#account-error { color: var(--destructive); font-size: var(--text-sm); }
