:root {
  --bg: #f5f7f6;
  --surface: #ffffff;
  --surface-2: #eef3f1;
  --surface-3: #fbfcfb;
  --text: #17201b;
  --muted: #64746c;
  --line: #d8e0dc;
  --primary: #116b52;
  --primary-dark: #0b4d3c;
  --accent: #2c6fbb;
  --accent-soft: #e7f0fa;
  --holiday: #9b2f49;
  --holiday-soft: #fae8ee;
  --warning: #8a5c00;
  --shadow: 0 12px 32px rgba(23, 32, 27, 0.09);
  --radius: 8px;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #111614;
  --surface: #1b211e;
  --surface-2: #242c28;
  --surface-3: #171d1a;
  --text: #eef5f1;
  --muted: #a8b7af;
  --line: #33413a;
  --primary: #2ea77f;
  --primary-dark: #1f8061;
  --accent: #7db7f0;
  --accent-soft: #23364a;
  --holiday: #ff9ab2;
  --holiday-soft: #412331;
  --warning: #f0c66c;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

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

button,
.import-button {
  border: 0;
  cursor: pointer;
}

textarea {
  resize: vertical;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px clamp(16px, 4vw, 40px);
  background: rgba(245, 247, 246, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

[data-theme="dark"] .topbar {
  background: rgba(17, 22, 20, 0.94);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 220px;
}

.brand-mark {
  display: inline-grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: var(--radius);
  background: var(--primary);
  color: #fff;
}

.brand h1,
.planner-toolbar h2,
.side-title h2,
.drawer-header h2 {
  margin: 0;
  letter-spacing: 0;
}

.brand h1 {
  font-size: 1.32rem;
  line-height: 1.1;
}

.brand p,
.planner-toolbar p,
.drawer-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.top-actions,
.toolbar-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.date-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.9rem;
}

.date-picker input {
  width: 142px;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
}

.icon-button,
.text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border-radius: var(--radius);
  transition:
    transform 120ms ease,
    background 120ms ease,
    color 120ms ease,
    box-shadow 120ms ease;
}

.icon-button {
  width: 42px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
}

.icon-button.small {
  width: 34px;
  min-height: 34px;
}

.text-button {
  padding: 0 14px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}

.icon-button:hover,
.text-button:hover,
.import-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(23, 32, 27, 0.12);
}

.icon-button:focus-visible,
.text-button:focus-visible,
input:focus-visible,
textarea:focus-visible,
.import-button:focus-visible {
  outline: 3px solid rgba(44, 111, 187, 0.3);
  outline-offset: 2px;
}

.text-button svg,
.icon-button svg,
.brand-mark svg,
.side-title svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.main-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  padding: 18px clamp(16px, 4vw, 40px) 32px;
}

.planner-panel,
.side-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.planner-panel,
.side-panel {
  min-width: 0;
}

.planner-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.planner-toolbar h2,
.side-title h2 {
  font-size: 1rem;
}

.toolbar-actions .text-button {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
}

.theme-toggle {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
}

.toolbar-actions .text-button:first-child {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.week-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(150px, 1fr));
  gap: 10px;
  padding: 16px;
  overflow-x: auto;
  align-items: stretch;
}

.day-card {
  min-width: 150px;
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.day-card.has-holiday {
  border-color: rgba(155, 47, 73, 0.45);
  box-shadow: inset 0 4px 0 var(--holiday);
}

.day-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  min-height: 74px;
  padding: 12px 12px 10px;
  background: var(--surface-2);
}

.day-name {
  margin: 0 0 4px;
  font-size: 1.02rem;
  letter-spacing: 0;
}

.day-date {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
}

.holiday-badge {
  max-width: 112px;
  padding: 5px 7px;
  border-radius: 999px;
  background: var(--holiday-soft);
  color: var(--holiday);
  font-size: 0.76rem;
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
}

.meal-stack {
  display: grid;
  gap: 10px;
  padding: 10px;
}

.meal-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: transparent;
  border: 0;
  border-radius: 0;
}

.meal-heading {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.meal-actions {
  display: flex;
  align-items: center;
  gap: 5px;
}

.favorite-meal.is-active {
  border-color: rgba(138, 92, 0, 0.32);
  background: #fff4cf;
  color: var(--warning);
}

[data-theme="dark"] .favorite-meal.is-active {
  border-color: rgba(240, 198, 108, 0.42);
  background: #3a3019;
}

.meal-card input,
.meal-card select,
.meal-card textarea,
.side-section textarea,
.drawer-search input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  outline: 0;
}

.meal-card input,
.meal-card select,
.drawer-search input {
  height: 40px;
  padding: 0 10px;
}

.meal-meta-grid {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 8px;
}

.meal-meta-grid label,
.serving-pill {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.serving-pill {
  min-height: 40px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.serving-pill strong {
  color: var(--text);
  font-size: 0.96rem;
  line-height: 1;
}

.done-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: max-content;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 800;
}

.done-toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

.dinner-card.is-done {
  background: #f4faf6;
}

[data-theme="dark"] .dinner-card.is-done {
  background: #1f2b25;
}

.meal-card textarea,
.side-section textarea {
  padding: 9px 10px;
  line-height: 1.35;
}

.image-tools {
  display: flex;
  justify-content: flex-end;
  margin-bottom: -4px;
}

.image-tools .icon-button {
  width: 38px;
  min-height: 38px;
}

.image-preview {
  position: relative;
  display: grid;
  width: 100%;
  aspect-ratio: 4 / 3;
  place-items: center;
  overflow: hidden;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.88rem;
}

.image-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-preview a {
  position: absolute;
  right: 6px;
  bottom: 6px;
  padding: 4px 6px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  text-decoration: none;
}

[data-theme="dark"] .image-preview a {
  background: rgba(17, 22, 20, 0.88);
}

.side-panel {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-content: start;
  gap: 14px;
}

.side-section {
  padding: 14px;
}

.side-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.side-title span {
  display: inline-grid;
  min-width: 30px;
  height: 26px;
  place-items: center;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.saved-list,
.favorite-list,
.holiday-list {
  display: grid;
  gap: 8px;
}

.saved-item,
.favorite-item,
.holiday-item {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-3);
}

.saved-item {
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
}

.favorite-item {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.saved-item button,
.favorite-item button {
  align-self: center;
}

.saved-title,
.holiday-name {
  margin: 0;
  font-weight: 800;
}

.saved-meta,
.holiday-date {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.empty-state,
.error-state {
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.error-state {
  color: var(--warning);
  border-color: rgba(138, 92, 0, 0.35);
  background: #fff8e5;
}

[data-theme="dark"] .error-state {
  background: #3a2d16;
}

.image-drawer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: end center;
  padding: 18px;
  background: rgba(13, 20, 17, 0.45);
}

.image-drawer[hidden] {
  display: none;
}

.drawer-panel {
  display: grid;
  gap: 14px;
  width: min(960px, 100%);
  max-height: min(720px, calc(100vh - 36px));
  overflow: hidden;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.24);
}

.drawer-header,
.drawer-search {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.drawer-search {
  align-items: stretch;
}

.drawer-search input {
  height: 42px;
}

.image-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  min-height: 180px;
  overflow: auto;
  padding-right: 2px;
}

.image-choice {
  display: grid;
  gap: 7px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-3);
  color: var(--text);
  text-align: left;
}

.image-choice img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 6px;
  background: var(--surface-2);
}

.image-choice span {
  min-height: 2.5em;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.25;
}

@media (max-width: 1160px) {
  .side-panel {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 840px) {
  .topbar,
  .planner-toolbar,
  .drawer-header,
  .drawer-search {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .toolbar-actions {
    justify-content: flex-start;
  }

  .side-panel {
    grid-template-columns: 1fr;
  }

  .week-grid {
    grid-template-columns: 1fr;
    overflow-x: visible;
  }

  .day-card {
    min-width: 0;
  }

  .toolbar-actions .text-button,
  .toolbar-actions .import-button {
    flex: 1 1 150px;
  }

  .date-picker {
    width: 100%;
  }

  .date-picker input {
    width: 100%;
  }

  .meal-meta-grid {
    grid-template-columns: 1fr;
  }
}

@media print {
  body {
    background: #fff;
  }

  .topbar,
  .side-panel,
  .planner-toolbar,
  .meal-card .image-tools,
  .clear-meal,
  .favorite-meal,
  .image-search {
    display: none !important;
  }

  .main-layout,
  .week-grid {
    display: block;
    padding: 0;
  }

  .planner-panel,
  .day-card,
  .meal-card {
    box-shadow: none;
    break-inside: avoid;
  }

  .day-card {
    margin-bottom: 12px;
  }
}
