:root {
  --bg: #f5f5f7;
  --sidebar-bg: rgba(245, 245, 247, 0.72);
  --surface: #ffffff;
  --surface-raised: #fbfbfd;
  --text-primary: #1d1d1f;
  --text-secondary: #86868b;
  --text-tertiary: #aeaeb2;
  --separator: rgba(60, 60, 67, 0.12);
  --separator-light: rgba(60, 60, 67, 0.06);
  --accent: #007aff;
  --accent-hover: #0062cc;
  --accent-bg: rgba(0, 122, 255, 0.08);
  --green: #34c759;
  --green-dark: #248a3d;
  --green-bg: rgba(52, 199, 89, 0.1);
  --orange: #ff9500;
  --orange-bg: rgba(255, 149, 0, 0.1);
  --red: #ff3b30;
  --red-bg: rgba(255, 59, 48, 0.08);
  --purple: #af52de;
  --fill: rgba(120, 120, 128, 0.08);
  --fill-hover: rgba(120, 120, 128, 0.12);
  --shadow-sm: 0 0.5px 1px rgba(0,0,0,0.04), 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 8px 28px rgba(0,0,0,0.12), 0 2px 4px rgba(0,0,0,0.04);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --sidebar-w: 220px;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', system-ui, sans-serif;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button, input, select, textarea { font: inherit; }

/* ── App Shell ──────────────────────────────────────── */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ── Sidebar ────────────────────────────────────────── */

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  background: var(--sidebar-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid var(--separator);
  overflow-y: auto;
  z-index: 10;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 18px;
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.sidebar-brand svg {
  color: var(--accent);
  flex-shrink: 0;
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
  text-align: left;
}

.nav-item:hover {
  background: var(--fill);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 600;
}

.nav-item.active svg {
  color: var(--accent);
}

.nav-item svg {
  flex-shrink: 0;
  color: var(--text-tertiary);
  transition: color 0.15s var(--ease);
}

.nav-item:hover svg {
  color: var(--text-primary);
}

.nav-logout {
  margin-top: auto;
  color: var(--text-tertiary);
  font-size: 12px;
}

.nav-logout:hover {
  color: var(--red);
}

.nav-logout:hover svg {
  color: var(--red);
}

/* ── Content Area ───────────────────────────────────── */

.content {
  padding: 32px 40px 48px;
  max-width: 960px;
  width: 100%;
  overflow-y: auto;
}

.view {
  display: none;
}

.view.active {
  display: block;
  animation: viewIn 0.28s var(--ease) forwards;
}

@keyframes viewIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

.view-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.view-label {
  margin: 0 0 4px;
  color: var(--text-tertiary);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1.15;
}

h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.2px;
}

/* ── Buttons ────────────────────────────────────────── */

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: white;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s var(--ease), transform 0.1s var(--ease);
  white-space: nowrap;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary:active {
  transform: scale(0.97);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: default;
  transform: none;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--separator);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-primary);
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s var(--ease), transform 0.1s var(--ease);
  white-space: nowrap;
}

.btn-secondary:hover {
  background: var(--fill);
}

.btn-secondary:active {
  transform: scale(0.97);
}

.btn-secondary:disabled {
  opacity: 0.5;
  cursor: default;
  transform: none;
}

.btn-close {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: var(--fill);
  color: var(--text-secondary);
  padding: 0;
  cursor: pointer;
  transition: background 0.15s var(--ease);
  flex-shrink: 0;
}

.btn-close:hover {
  background: var(--fill-hover);
}

.btn-icon {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-tertiary);
  padding: 0;
  cursor: pointer;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}

.btn-icon:hover {
  background: var(--fill);
  color: var(--text-primary);
}

.btn-icon.danger:hover {
  background: var(--red-bg);
  color: var(--red);
}

/* ── Forms & Inputs ─────────────────────────────────── */

.field {
  display: grid;
  gap: 4px;
}

.field span {
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
}

.field input,
.field select {
  width: 100%;
  border: 1px solid var(--separator);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  background: var(--surface);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.field input:focus,
.field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.15);
}

.field input::placeholder {
  color: var(--text-tertiary);
}

.field-compact {
  display: grid;
  gap: 4px;
}

.field-compact span {
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
}

.field-compact input {
  border: 1px solid var(--separator);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  background: var(--surface);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.field-compact input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.15);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.span-2 {
  grid-column: span 2;
}

/* ── Dialog / Sheet ─────────────────────────────────── */

.sheet {
  width: min(520px, calc(100vw - 48px));
  border: 0;
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  padding: 0;
  overflow: hidden;
}

.sheet::backdrop {
  background: rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.sheet[open] {
  animation: sheetIn 0.3s var(--ease) forwards;
}

.sheet[open]::backdrop {
  animation: backdropIn 0.25s var(--ease) forwards;
}

@keyframes sheetIn {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}

@keyframes backdropIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
}

.sheet-header h2 {
  font-size: 17px;
  font-weight: 600;
}

.sheet-body {
  padding: 20px 24px 24px;
}

.sheet-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--separator-light);
}

/* ── Plan View ──────────────────────────────────────── */

.plan-bar {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  padding: 16px 20px;
  margin-bottom: 20px;
  background: var(--surface);
  border: 1px solid var(--separator-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.meal-detail {
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
}

.meal-detail summary {
  padding: 8px 0;
  font-weight: 500;
  user-select: none;
  list-style: none;
}

.meal-detail summary::-webkit-details-marker {
  display: none;
}

.meal-detail summary::before {
  content: '\25B8 ';
  color: var(--text-tertiary);
}

.meal-detail[open] summary::before {
  content: '\25BE ';
}

.meal-counts {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 8px;
}

.meal-counts label {
  display: grid;
  gap: 3px;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
}

.meal-counts select {
  width: 52px;
  border: 1px solid var(--separator);
  border-radius: var(--radius-sm);
  padding: 4px 6px;
  background: var(--surface);
  font-size: 13px;
  outline: none;
}

.meal-counts select:focus {
  border-color: var(--accent);
}

.plan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.day-card {
  border: 1px solid var(--separator-light);
  border-radius: var(--radius-lg);
  background: var(--surface);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s var(--ease), transform 0.2s var(--ease);
}

.day-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.day-card h3 {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.2px;
}

.meal-block {
  padding-top: 12px;
  margin-top: 12px;
  border-top: 1px solid var(--separator-light);
}

.meal-block:first-of-type {
  border-top: 0;
  padding-top: 0;
  margin-top: 0;
}

.meal-label {
  margin: 0 0 4px;
  color: var(--text-tertiary);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.dish {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.reason {
  margin: 0 0 4px;
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.45;
}

.family-fit {
  margin: 0 0 4px;
  color: var(--green-dark);
  font-size: 12px;
  line-height: 1.45;
}

.suggestions {
  margin: 0 0 6px;
  color: var(--text-secondary);
  font-size: 12px;
  font-style: italic;
}

.ingredients {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 10px;
}

.ingredient {
  border-radius: 100px;
  background: var(--orange-bg);
  color: var(--orange);
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
}

/* ── People View ────────────────────────────────────── */

.people-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
}

.person-card {
  border: 1px solid var(--separator-light);
  border-radius: var(--radius-lg);
  background: var(--surface);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s var(--ease);
}

.person-card:hover {
  box-shadow: var(--shadow-md);
}

.person-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.person-card-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.person-card-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.15s var(--ease);
}

.person-card:hover .person-card-actions {
  opacity: 1;
}

.person-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.meta-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 100px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  background: var(--fill);
  color: var(--text-secondary);
}

.meta-badge.likes {
  background: var(--green-bg);
  color: var(--green-dark);
}

.meta-badge.dislikes {
  background: var(--red-bg);
  color: var(--red);
}

.meta-badge.cuisine {
  background: var(--accent-bg);
  color: var(--accent);
}

.person-card-notes {
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.45;
  margin: 0;
}

/* ── History View ───────────────────────────────────── */

.history-list {
  display: grid;
  gap: 0;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--separator-light);
  transition: background 0.1s var(--ease);
}

.history-item:first-child {
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.history-item:last-child {
  border-bottom: 0;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.history-item:only-child {
  border-radius: var(--radius-md);
}

.history-item:hover {
  background: var(--fill);
}

.history-item strong {
  font-size: 14px;
  font-weight: 600;
}

.history-item span {
  color: var(--text-secondary);
  font-size: 13px;
  flex-shrink: 0;
}

.history-wrap {
  background: var(--surface);
  border: 1px solid var(--separator-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

/* ── Shopping View ──────────────────────────────────── */

.shopping-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 0 28px;
}

.shopping-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--separator-light);
  font-size: 14px;
}

.shopping-item strong {
  font-weight: 600;
}

.shopping-item span {
  color: var(--text-secondary);
  font-size: 13px;
  flex-shrink: 0;
}

/* ── Offers View ────────────────────────────────────── */

.offers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}

.offer-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  min-height: 80px;
  border: 1px solid var(--separator-light);
  border-radius: var(--radius-md);
  background: var(--surface);
  padding: 14px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s var(--ease);
}

.offer-item:hover {
  box-shadow: var(--shadow-md);
}

.offer-info {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.offer-info strong {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.offer-info span {
  color: var(--text-secondary);
  font-size: 12px;
}

.offer-price {
  font-size: 15px;
  font-weight: 700;
  color: var(--green-dark);
  white-space: nowrap;
  align-self: flex-start;
}

.scraper-runs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.run-status {
  margin: 0;
  border-radius: 100px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 500;
  background: var(--fill);
  color: var(--text-secondary);
}

.run-success {
  background: var(--green-bg);
  color: var(--green-dark);
}

.run-failed {
  background: var(--red-bg);
  color: var(--red);
}

/* ── Empty State ────────────────────────────────────── */

.empty {
  color: var(--text-tertiary);
  font-size: 14px;
  text-align: center;
  padding: 40px 20px;
}

/* ── Mobile Tab Bar ─────────────────────────────────── */

.tab-bar {
  display: none;
}

/* ── Login Page ─────────────────────────────────────── */

.login-shell {
  display: grid;
  min-height: 100vh;
  min-height: 100dvh;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.login-panel {
  width: min(380px, 100%);
  border: 1px solid var(--separator-light);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  padding: 36px 32px;
  text-align: center;
}

.login-brand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  background: var(--accent-bg);
  color: var(--accent);
  margin-bottom: 16px;
}

.login-panel h1 {
  font-size: 22px;
  margin-bottom: 4px;
}

.login-panel .subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin: 0 0 24px;
}

.login-form {
  display: grid;
  gap: 12px;
  text-align: left;
}

.login-form .field input {
  padding: 10px 12px;
}

.login-form .btn-primary {
  width: 100%;
  justify-content: center;
  padding: 10px;
  margin-top: 4px;
}

.form-error {
  min-height: 18px;
  margin: 0;
  color: var(--red);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
}

.hidden {
  display: none !important;
}

/* ── Responsive ─────────────────────────────────────── */

@media (max-width: 768px) {
  .app {
    grid-template-columns: 1fr;
    padding-bottom: 72px;
  }

  .sidebar {
    display: none;
  }

  .tab-bar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.88);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--separator);
    padding: 6px 8px calc(env(safe-area-inset-bottom, 0px) + 6px);
    z-index: 100;
    justify-content: space-around;
  }

  .tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--text-tertiary);
    padding: 4px 8px;
    font-size: 10px;
    font-weight: 500;
    cursor: pointer;
    transition: color 0.15s var(--ease);
  }

  .tab.active {
    color: var(--accent);
  }

  .tab:hover {
    color: var(--text-primary);
  }

  .content {
    padding: 20px 16px 32px;
  }

  h1 {
    font-size: 24px;
  }

  .view-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .plan-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .plan-grid {
    grid-template-columns: 1fr;
  }

  .people-grid {
    grid-template-columns: 1fr;
  }

  .person-card-actions {
    opacity: 1;
  }

  .offers-grid {
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: span 1;
  }

  .sheet {
    width: calc(100vw - 32px);
    border-radius: var(--radius-lg);
  }

  .shopping-list {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 769px) and (max-width: 1100px) {
  .content {
    padding: 28px 28px 40px;
  }

  .plan-grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  }
}
