/* --------------------------------------------------------------------------
   MealPlanner — mobile-first styling. Designed to feel like a native app:
   fixed top bar, bottom tab bar, card lists, and a slide-up modal sheet.
   Works in light and dark mode.
   -------------------------------------------------------------------------- */

:root {
  --brand: #c2410c;      /* warm terracotta */
  --brand-600: #9a3412;
  --brand-tint: #fff2ea;
  --weekend: #7c3aed;
  --fixed: #0e7490;
  --bg: #f5f5f4;
  --surface: #ffffff;
  --text: #1c1917;
  --muted: #78716c;
  --border: #e7e5e4;
  --danger: #dc2626;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --appbar-h: 52px;
  --tabbar-h: 60px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand: #fb923c;
    --brand-600: #f97316;
    --brand-tint: #2a1a10;
    --weekend: #a78bfa;
    --fixed: #22d3ee;
    --bg: #1c1917;
    --surface: #292524;
    --text: #f5f5f4;
    --muted: #a8a29e;
    --border: #44403c;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica,
    Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  overscroll-behavior-y: none;
}

/* ---- App bar ---- */
.appbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  background: var(--brand);
  color: #fff;
  padding-top: var(--safe-top);
  box-shadow: var(--shadow);
}
.appbar-inner {
  height: var(--appbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  max-width: 720px;
  margin: 0 auto;
}
.brand {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 0.2px;
}
.appbar .icon-btn {
  color: #fff;
  font-size: 1.2rem;
}

/* ---- Main scroll area ---- */
.app {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(var(--appbar-h) + var(--safe-top) + 12px) 16px
    calc(var(--tabbar-h) + var(--safe-bottom) + 24px);
}

.view-head h1 {
  margin: 4px 0 2px;
  font-size: 1.55rem;
}
.sub {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

/* ---- Buttons ---- */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 11px 16px;
  border-radius: 12px;
  font-size: 0.98rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: transform 0.05s ease, background 0.15s ease;
}
.btn:active {
  transform: scale(0.98);
}
.btn.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.btn.ghost {
  background: transparent;
}
.btn.danger {
  color: var(--danger);
  border-color: transparent;
  background: transparent;
}
.row-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}
.row-actions .btn {
  width: auto;
  flex: 1;
}

.icon-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 1.15rem;
  cursor: pointer;
  padding: 8px;
  border-radius: 10px;
  line-height: 1;
}
.icon-btn:disabled {
  opacity: 0.3;
}

.link {
  background: none;
  border: none;
  color: var(--brand);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  text-decoration: none;
  text-align: left;
}

/* ---- Cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 10px;
}

/* ---- Menu day cards ---- */
.day-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.day-card {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: 'head controls' 'body controls';
  align-items: center;
  gap: 2px 8px;
  border-left: 4px solid var(--border);
}
.day-card.weekend {
  border-left-color: var(--weekend);
}
.day-card.locked {
  background: var(--brand-tint);
}
.day-head {
  grid-area: head;
  display: flex;
  align-items: center;
  gap: 8px;
}
.day-name {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.day-body {
  grid-area: body;
}
.meal-name {
  font-size: 1.12rem;
  font-weight: 600;
}
.recipe-link {
  display: inline-block;
  margin-top: 3px;
  font-size: 0.9rem;
}
.day-controls {
  grid-area: controls;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* ---- Pills ---- */
.pill {
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
}
.weekend-pill {
  background: color-mix(in srgb, var(--weekend) 15%, transparent);
  color: var(--weekend);
}
.fixed-pill {
  background: color-mix(in srgb, var(--fixed) 15%, transparent);
  color: var(--fixed);
}
.recipe-pill {
  background: color-mix(in srgb, var(--brand) 15%, transparent);
  color: var(--brand);
}

/* ---- List rows (meals / recipes) ---- */
.card-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  padding: 13px 14px;
}
.list-row:active {
  background: var(--brand-tint);
}
.list-main {
  min-width: 0;
}
.list-title {
  font-weight: 600;
  font-size: 1.02rem;
}
.list-desc {
  color: var(--muted);
  font-size: 0.86rem;
  margin-top: 2px;
}
.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
}
.chevron {
  color: var(--muted);
  font-size: 1.4rem;
  flex-shrink: 0;
}

.search {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 12px;
}

/* ---- Empty states ---- */
.empty {
  text-align: center;
  padding: 40px 16px;
}
.empty p {
  margin: 4px 0;
}
.muted {
  color: var(--muted);
}

/* ---- Modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade 0.15s ease;
}
@keyframes fade {
  from {
    opacity: 0;
  }
}
.modal-sheet {
  background: var(--bg);
  width: 100%;
  max-width: 720px;
  max-height: 92vh;
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  animation: slideup 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
  padding-bottom: var(--safe-bottom);
}
@keyframes slideup {
  from {
    transform: translateY(100%);
  }
}
.modal-content {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
}
.modal-head h2 {
  margin: 0;
  font-size: 1.15rem;
}
.modal-body {
  padding: 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.modal-foot {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.modal-foot .btn {
  flex: 1;
}
.modal-foot span {
  flex: 1;
}

/* ---- Forms ---- */
.form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.field-label {
  font-weight: 600;
  font-size: 0.9rem;
}
.field-hint {
  color: var(--muted);
  font-size: 0.78rem;
}
.input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}
textarea.input {
  resize: vertical;
  line-height: 1.5;
}
.input.err {
  border-color: var(--danger);
}
.modal-body .btn {
  margin-bottom: 10px;
}
.modal-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 8px 0;
}

/* ---- Recipe reader ---- */
.recipe-desc {
  color: var(--muted);
  font-style: italic;
}
.recipe-view h3 {
  margin: 18px 0 6px;
  font-size: 1rem;
  color: var(--brand);
}
.ingredients,
.steps {
  padding-left: 20px;
  margin: 0;
}
.ingredients li,
.steps li {
  margin-bottom: 7px;
}
.recipe-notes {
  background: var(--brand-tint);
  padding: 12px;
  border-radius: 10px;
  font-size: 0.92rem;
}

/* ---- Shopping list ---- */
.add-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.add-row .search {
  margin-bottom: 0;
  flex: 1;
}
.add-row .add-btn {
  width: auto;
  flex: 0 0 auto;
  padding: 0 18px;
  font-size: 1.3rem;
}
.shop-group {
  padding: 12px 14px;
}
.shop-group-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}
.shop-meal {
  font-weight: 700;
  font-size: 1.02rem;
}
.shop-items {
  list-style: none;
  margin: 0;
  padding: 0;
}
.shop-row {
  display: flex;
  align-items: center;
  gap: 6px;
  border-top: 1px solid var(--border);
}
.shop-row:first-child {
  border-top: none;
}
.shop-check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 2px;
  flex: 1;
  cursor: pointer;
  min-width: 0;
}
.shop-check input {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  accent-color: var(--brand);
  margin-top: 1px;
}
.shop-text {
  line-height: 1.4;
}
.shop-row.checked .shop-text {
  text-decoration: line-through;
  color: var(--muted);
}
.shop-del {
  font-size: 0.9rem;
  color: var(--muted);
  flex-shrink: 0;
}
.shop-missing {
  border: 1px dashed var(--border);
  background: transparent;
  box-shadow: none;
}
.shop-missing-head {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 8px;
}
.shop-missing-row {
  padding: 3px 0;
  font-size: 0.95rem;
}

/* ---- Segmented tabs (Pick / List) ---- */
.seg-tabs {
  display: flex;
  background: var(--surface-2, #eeeae4);
  border-radius: 999px;
  padding: 4px;
  margin: 0 0 12px 0;
  gap: 2px;
}
.seg-tab {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.seg-tab.active {
  background: var(--bg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.seg-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  padding: 0 6px;
  height: 20px;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
}

/* ---- List mode extras ---- */
.shop-mult {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  vertical-align: 1px;
}
.shop-src {
  flex-shrink: 0;
  padding: 0 8px 0 4px;
  font-size: 0.75rem;
  color: var(--muted);
  align-self: center;
  max-width: 45%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.empty-list {
  padding: 24px 12px;
  text-align: center;
}

/* ---- Toast ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  transform: translate(-50%, 12px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 60;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---- Bottom tab bar ---- */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.05);
}
.tabbar button {
  flex: 1;
  appearance: none;
  border: none;
  background: none;
  color: var(--muted);
  height: var(--tabbar-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  font: inherit;
}
.tabbar button.active {
  color: var(--brand);
}
.tab-ico {
  font-size: 1.35rem;
  line-height: 1;
}
.tab-lbl {
  font-size: 0.7rem;
  font-weight: 600;
}
