:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1d1d1b;
  --muted: #66645e;
  --border: #dedbd3;
  --accent: #2f6b4f;
  --accent-text: #ffffff;
  --ok: #2f6b4f;
  --ok-bg: #e5f1ea;
  --warn: #8a5a00;
  --warn-bg: #fdf0d5;
  --bad: #a3261b;
  --bad-bg: #fbe3e0;
  --frost: #1f5f8b;
  --frost-bg: #e2eff8;
  --radius: 10px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161614;
    --surface: #211f1d;
    --text: #efede8;
    --muted: #a8a59d;
    --border: #3a3834;
    --accent: #6cc59a;
    --accent-text: #0e1f16;
    --ok: #6cc59a;
    --ok-bg: #1c3228;
    --warn: #f0bc5e;
    --warn-bg: #3a2c12;
    --bad: #f28b80;
    --bad-bg: #3d1c19;
    --frost: #8cc8f0;
    --frost-bg: #16293a;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

main { max-width: 860px; margin: 0 auto; padding: 16px; }

h1, h2, h3 { line-height: 1.2; }
h1 { font-size: 1.15rem; margin: 0; }
h2 { font-size: 1.2rem; margin: 0 0 12px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
#user-box { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 0.9rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.narrow { max-width: 420px; margin: 32px auto; }

label { display: block; font-size: 0.9rem; font-weight: 600; margin-bottom: 12px; }
input, select, textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 9px 10px;
  font: inherit;
  /* 16px or more, or iPhones zoom in when you tap the box. */
  font-size: 16px;
  font-weight: 400;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
textarea { resize: vertical; }

button {
  font: inherit;
  font-weight: 600;
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}
button:disabled { opacity: 0.6; cursor: default; }
button.secondary { background: transparent; color: var(--text); border-color: var(--border); }
button.small { padding: 5px 10px; font-size: 0.85rem; }
button.danger { background: transparent; color: var(--bad); border-color: var(--border); }
button.link { background: none; border: none; padding: 0; color: var(--accent); font-weight: 600; }

.hint { color: var(--muted); font-size: 0.88rem; margin: -6px 0 12px; }
.error { color: var(--bad); font-size: 0.9rem; min-height: 1em; margin: 8px 0 0; }
.error:empty { display: none; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs button {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  color: var(--muted);
  padding: 10px 14px;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.badge {
  display: inline-block;
  min-width: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--bad);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  vertical-align: 1px;
}
.badge.warn { background: var(--warn-bg); color: var(--warn); }
/* Fridge/Freezer tabs: item count, with the alert number tucked on its corner. */
.count-badge {
  position: relative;
  display: inline-block;
  min-width: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--border);
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  vertical-align: 1px;
  margin-right: 3px;
}
.count-badge .badge.alert {
  position: absolute;
  top: -9px;
  right: -10px;
  min-width: 16px;
  padding: 0 4px;
  line-height: 16px;
  font-size: 0.65rem;
  box-shadow: 0 0 0 2px var(--bg);
}
.count-badge .badge.alert[hidden] { display: none; }
/* Meals and Messages: the alert number sits on the label's corner so tabs stay narrow. */
.tabs button { position: relative; }
.tabs button > .badge {
  position: absolute;
  top: 2px;
  right: -4px;
  min-width: 16px;
  padding: 0 4px;
  line-height: 16px;
  font-size: 0.65rem;
  box-shadow: 0 0 0 2px var(--bg);
}

.summary { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.pill { padding: 4px 10px; border-radius: 999px; font-size: 0.85rem; font-weight: 600; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.neutral { background: var(--border); color: var(--text); }
.pill.frost { background: var(--frost-bg); color: var(--frost); }
.defrost {
  margin: 8px 0 0;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--frost-bg);
  color: var(--frost);
  font-size: 0.88rem;
  font-weight: 600;
}

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.toolbar select, .toolbar input { width: auto; margin: 0; }
.toolbar input { flex: 1 1 180px; }

.food-list { display: grid; gap: 10px; }
.food {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 6px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.food.ok { border-left-color: var(--ok); }
.food.warn { border-left-color: var(--warn); }
.food.bad { border-left-color: var(--bad); }
.food-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.food-head h3 { margin: 0; font-size: 1.05rem; overflow-wrap: anywhere; }
.food-number {
  display: inline-block;
  margin-right: 6px;
  padding: 0 6px;
  border-radius: 6px;
  background: var(--text);
  color: var(--surface);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}
.food-number.big { font-size: 1.1em; margin: 0 1px; }
.saved-notice {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 0 0 12px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--ok-bg);
  color: var(--ok);
}
.saved-notice[hidden] { display: none; }
.kosher-tag {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 8px;
  border: 2px solid var(--frost);
  border-radius: 6px;
  color: var(--frost);
  background: var(--frost-bg);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  vertical-align: 2px;
}
.tags .kosher-tag { margin-left: 0; }
.pill.todo { background: var(--warn-bg); color: var(--warn); }
.process-flag {
  margin: 8px 0 0;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 0.88rem;
  font-weight: 600;
}
.process-notice { margin-top: 0; }
.field-title { font-weight: 600; margin: 4px 0 6px; }
.bulk-rows { display: grid; gap: 8px; margin-bottom: 8px; }
.bulk-row {
  display: grid;
  grid-template-columns: 1fr 110px 28px;
  gap: 6px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.bulk-row input, .bulk-row select, .bulk-row label { margin: 0; min-width: 0; }
.bulk-row [name=item_name] { grid-row: 1; grid-column: 1 / 3; }
.bulk-row .bulk-remove { grid-row: 1; grid-column: 3; padding: 0; color: var(--muted); }
.bulk-row [name=item_quantity] { grid-row: 2; grid-column: 1; }
.bulk-row [name=item_category] { grid-row: 2; grid-column: 2 / 4; }
.bulk-row .bulk-bad-by { grid-row: 3; grid-column: 1 / 4; display: flex; align-items: center; gap: 8px; font-weight: 400; }
.bulk-row .bulk-bad-by[hidden] { display: none; }
.bulk-row .bulk-bad-by input { flex: 1; }
.food-meta { color: var(--muted); font-size: 0.88rem; margin: 4px 0 0; overflow-wrap: anywhere; }
.food-dates { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 0.88rem; margin: 8px 0 0; }
.food-dates b { font-weight: 600; }
.food-notes { font-size: 0.9rem; margin: 6px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.food-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.empty { color: var(--muted); text-align: center; padding: 32px 0; }

/* Meals */
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 0; }
.tags .pill { font-size: 0.78rem; padding: 2px 8px; }
.muted { color: var(--muted); font-size: 0.85rem; }
.deliveries { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 4px; font-size: 0.9rem; }
.deliveries li { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; overflow-wrap: anywhere; }
button.small-link { font-size: 0.85rem; flex: none; }

fieldset.picker { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px 4px; margin: 0 0 12px; min-width: 0; }
fieldset.picker legend { font-weight: 600; padding: 0 4px; }
fieldset.picker .hint { margin: 0 0 8px; }
.ingredient-list { display: grid; gap: 6px; max-height: 260px; overflow-y: auto; margin: 0 0 10px; }
label.check.ingredient, label.fridge {
  align-items: center;
  margin: 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}
label.check.ingredient:has(input:checked) { border-color: var(--accent); background: var(--ok-bg); }
label.check.ingredient input { margin: 0; flex: none; }
label.check.ingredient > span:nth-child(2), label.fridge > span:first-child { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ingredient-name { font-weight: 600; overflow-wrap: anywhere; }
label.check.ingredient .pill { flex: none; font-size: 0.72rem; padding: 2px 7px; }
.small-empty { padding: 12px 0; }
.picker-group { margin: 6px 0 0; font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }

.reminder {
  margin: 4px 0 10px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 0.9rem;
}
.reminder p { margin: 0 0 4px; }
.reminder ol { margin: 0; padding-left: 20px; }
.hint.warning { color: var(--bad); font-weight: 600; }
.temp-warning { color: var(--bad); font-weight: 600; }

.fridge-list { display: grid; gap: 8px; margin-bottom: 12px; }
a.directions { color: var(--accent); font-weight: 600; white-space: nowrap; }

.week-feed {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 12px;
}
.week-feed summary { cursor: pointer; font-weight: 600; }
.week-feed[open] summary { margin-bottom: 10px; }
.fridge-totals { list-style: none; padding: 0; margin: 0 0 10px; display: grid; gap: 6px; font-size: 0.9rem; }
.fridge-totals li { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: baseline; }
.fridge-totals li > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.fridge-totals .fridge-count { font-weight: 600; }
.fridge-totals li.none-yet .fridge-count { color: var(--warn); }
.week-list li { flex-wrap: wrap; }
label.fridge { display: flex; gap: 10px; font-weight: 400; }
label.fridge input { width: 76px; flex: none; margin: 0; text-align: center; }

.message-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 60vh;
  overflow-y: auto;
  padding: 4px 2px 12px;
}
.message {
  max-width: 85%;
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
}
.message.mine { align-self: flex-end; background: var(--ok-bg); }
.message-who { font-size: 0.8rem; color: var(--muted); margin: 0 0 2px; }
.message-body { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-form { display: flex; gap: 8px; align-items: flex-end; }
.message-form textarea { margin: 0; }

/* iPhone date fields have a wide built-in minimum size; let them fit their column. */
input[type="date"], input[type="datetime-local"] {
  -webkit-appearance: none;
  appearance: none;
  min-width: 0;
  min-height: 42px;
}
input[type="date"]::-webkit-date-and-time-value,
input[type="datetime-local"]::-webkit-date-and-time-value { text-align: left; }

/* Food form: header and Save/Cancel stay put, only the fields scroll. */
dialog {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  overflow: hidden;
}
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
dialog form { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.sheet-header { padding: 18px 20px 8px; border-bottom: 1px solid var(--border); }
.sheet-header h2 { margin: 0 0 8px; }
.sheet-header .hint { margin: 0 0 8px; }
.sheet-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 16px 20px 8px;
}
.sheet-footer { padding: 12px 20px 16px; border-top: 1px solid var(--border); background: var(--surface); }
.sheet-footer .error { margin: 0 0 8px; }
.sheet-footer .actions { margin: 0; }

/* Stop the page behind the form from scrolling while it's open. */
html.modal-open, html.modal-open body { overflow: hidden; overscroll-behavior: none; }

@media (max-width: 600px) {
  /* On phones the form fills the screen, with Save always visible. */
  dialog {
    width: 100%;
    max-width: none;
    height: 100dvh;
    max-height: none;
    margin: 0;
    border: 0;
    border-radius: 0;
  }
  .sheet-header { padding-top: calc(14px + env(safe-area-inset-top)); }
  .sheet-footer { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .sheet-footer .actions button { flex: 1; padding: 12px; }
}
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.banner {
  margin: 0 0 12px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 0.9rem;
  font-weight: 600;
}
.switch { margin: 16px 0 0; font-size: 0.9rem; color: var(--muted); }
.notice { color: var(--ok); font-size: 0.9rem; margin: 8px 0 0; }
.notice:empty { display: none; }

label.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; }
label.check input { width: auto; margin: 3px 0 0; }

.section-title { font-size: 1rem; margin: 20px 0 8px; }
#invite-panel h2 { font-size: 1.05rem; }
.invite-result { border-top: 1px solid var(--border); margin-top: 16px; padding-top: 12px; }
.invite-result p { margin: 0 0 8px; }
.invite-code { font: 700 1.4rem/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0.08em; }
.actions.start { justify-content: flex-start; }

.team-list { display: grid; gap: 8px; }
.person {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
}
.person-name { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.person-sub { margin: 2px 0 0; color: var(--muted); font-size: 0.85rem; overflow-wrap: anywhere; }
.person-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.person .pill { margin-left: 6px; font-size: 0.75rem; padding: 2px 8px; }

/* Fridge / Freezer / Pantry switch at the top of the Food tab. */
.places {
  display: flex; gap: 4px; padding: 4px; margin-bottom: 14px;
  background: var(--border); border-radius: 12px;
}
.places button {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 4px; border: none; border-radius: 9px;
  background: none; color: var(--muted); font-weight: 600; white-space: nowrap;
}
.places button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.places .count-badge { margin: 0; background: var(--bg); }
.places button[aria-selected="true"] .count-badge { background: var(--border); }

@media (max-width: 480px) {
  .tabs { gap: 0; }
  .tabs button { flex: 1 1 0; padding: 10px 2px; font-size: 0.9rem; white-space: nowrap; }
  .places button { font-size: 0.85rem; gap: 4px; }
  .row { grid-template-columns: 1fr; gap: 0; }
  .toolbar input, #add-food-btn { flex: 1 1 100%; }
  .toolbar select { flex: 1 1 auto; }
}
#quantity-hint:empty { display: none; }

/* "Meals in the fridge" box on the Fridge tab. */
.fridge-meals {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 6px solid var(--rose, #cb7c80);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 10px;
}
.fridge-meals[hidden] { display: none; }
.fridge-meals-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.fridge-meals h3 { margin: 0; font-size: 1rem; }
.fridge-meals ul { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 6px; font-size: 0.92rem; }
.fridge-meals li { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.fridge-meals li > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.fridge-meals .pill { flex: none; font-size: 0.75rem; padding: 2px 8px; }

/* Unread chat pop-up: about two thirds of the screen, centred. */
.unread-dialog { width: min(560px, calc(100vw - 32px)); height: 67dvh; max-height: 67dvh; }
.unread-dialog .sheet-body { display: flex; flex-direction: column; gap: 8px; }
.unread-dialog .message { max-width: 100%; align-self: stretch; }
.unread-dialog .message-body { font-size: 1.05rem; }
@media (max-width: 600px) {
  dialog.unread-dialog {
    width: calc(100vw - 24px);
    height: 67dvh;
    max-height: 67dvh;
    margin: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
  }
  .unread-dialog .sheet-header { padding-top: 14px; }
  .unread-dialog .sheet-footer { padding-bottom: 14px; }
  .unread-dialog .actions { flex-wrap: wrap; }
  .unread-dialog .actions button { flex: 1 1 30%; padding: 10px 6px; }
}

/* Shifts: check-in bar (all tabs) and the Shifts tab */
.shift-banner { display: grid; gap: 6px; margin: 0 0 12px; }
.shift-banner[hidden] { display: none; }
.shift-now {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--warn-bg);
  color: var(--text);
  border: 1px solid var(--warn);
  font-size: 0.92rem;
}
.shift-now.in { background: var(--frost-bg); border-color: var(--frost); }
.shift-now > span { min-width: 0; overflow-wrap: anywhere; }
.shift-now button { flex: none; }
.week-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.week-nav h2 { margin: 0; font-size: 1.15rem; }
.week-actions { margin: 0 0 12px; flex-wrap: wrap; }
.shift-list { display: grid; gap: 8px; }
.shift-day { margin: 10px 0 0; font-size: 0.9rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.shift {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 6px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
}
.shift.done { border-left-color: var(--ok); }
.shift.missed { border-left-color: var(--bad); }
.shift.due, .shift.open { border-left-color: var(--warn); }
.shift.in { border-left-color: var(--frost); }
.shift.off, .shift.cancelled { opacity: 0.7; }
.shift h4 { margin: 0; font-size: 1rem; }
.shift-report {
  margin: 8px 0 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--bg);
  font-size: 0.92rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.activity-list { margin: 0 0 14px; padding-left: 20px; font-size: 0.92rem; }
.missed-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; font-size: 0.92rem; }
.break-form { margin-top: 10px; }
.break-form input[name=label] { margin-bottom: 8px; }
.team-heading { margin-top: 32px; padding-top: 16px; border-top: 1px solid var(--border); }
.signups { margin: 6px 0 0; font-size: 0.9rem; overflow-wrap: anywhere; }
.signups .small-link { padding: 0 2px; color: var(--muted); }

/* Label check */
#label-dialog { max-width: 440px; }
label.check.label-step {
  align-items: center; padding: 12px; margin: 8px 0;
  border: 2px solid var(--border); border-radius: 10px; cursor: pointer;
}
label.check.label-step:has(input:checked) { border-color: var(--accent); background: var(--ok-bg); }
label.check.label-step input { margin: 0; width: 22px; height: 22px; flex: none; }
label.check.label-step > span { display: flex; flex-direction: column; gap: 2px; }
label.check.label-step .hint { margin: 0; }
#label-printed { margin-top: 4px; width: 100%; }
