:root {
  color-scheme: dark;
  --background: #09090b;
  --surface: #0f1013;
  --surface-raised: #141519;
  --surface-hover: #18151a;
  --text: #eeeae4;
  --text-secondary: #92929b;
  --border: #28292f;
  --border-strong: #3a3b43;
  --accent: #a94458;
  --accent-hover: #bd5267;
  --accent-soft: rgba(169, 68, 88, .13);
  --ready: #a8b67a;
  --danger: #db6b78;
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  background: var(--background);
}

body {
  min-width: 320px;
  margin: 0;
  overflow-x: hidden;
  color: var(--text);
  background: var(--background);
  font-family: Inter, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

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

button { color: inherit; }

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent-hover);
  outline-offset: 3px;
}

svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-layout {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: 66px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: 66px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: clamp(22px, 4vw, 60px);
  padding: 0 clamp(18px, 3vw, 42px);
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  background: rgba(9, 9, 11, .97);
  backdrop-filter: blur(12px);
}

.brand {
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -.025em;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
}

.tabs {
  align-self: stretch;
  display: flex;
  align-items: stretch;
  gap: 4px;
}

.tab {
  position: relative;
  min-width: 0;
  padding: 0 13px;
  border: 0;
  color: var(--text-secondary);
  background: transparent;
  cursor: pointer;
  font-size: .875rem;
  font-weight: 560;
  white-space: nowrap;
}

.tab::after {
  content: "";
  position: absolute;
  right: 13px;
  bottom: -1px;
  left: 13px;
  height: 2px;
  background: transparent;
}

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

.tab.active {
  color: var(--text);
  background: transparent;
}

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

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mcp-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-right: 6px;
  color: var(--text-secondary);
  font-size: .75rem;
  white-space: nowrap;
}

.mcp-pill::before {
  content: "";
  width: 6px;
  height: 6px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #64656d;
}

.mcp-pill.ready { color: #cbd4b0; }
.mcp-pill.ready::before { background: var(--ready); }

.workspace {
  min-width: 0;
  min-height: 0;
}

.workspace > main {
  width: min(100%, 1600px);
  min-height: 100%;
  margin: 0 auto;
  padding: 28px clamp(18px, 3vw, 42px) 48px;
}

.panel {
  display: none;
  min-width: 0;
}

.panel.active { display: block; }

[data-panel="recipes"],
[data-panel="pantry"],
[data-panel="shopping"] {
  width: min(100%, 1040px);
  margin-inline: auto;
}

.section-head {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.section-head h2,
.dialog-head h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.58rem;
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: -.035em;
}

.button,
.icon-button {
  min-height: 38px;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  background: transparent;
  cursor: pointer;
  transition: border-color .14s ease, color .14s ease, background-color .14s ease;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 13px;
  font-size: .875rem;
  font-weight: 600;
  white-space: nowrap;
}

.button svg {
  width: 16px;
  height: 16px;
}

.button:hover,
.icon-button:hover {
  border-color: #55565f;
  background: var(--surface-raised);
}

.button.primary {
  color: #fff8f7;
  border-color: var(--accent);
  background: var(--accent);
}

.button.primary:hover {
  border-color: var(--accent-hover);
  background: var(--accent-hover);
}

.agent-prompt {
  width: auto;
  margin: 0;
  color: var(--text);
}

.icon-button {
  width: 38px;
  display: grid;
  place-items: center;
  padding: 0;
}

.icon-button svg {
  width: 17px;
  height: 17px;
}

.week-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.planner-grid {
  min-height: clamp(410px, calc(100dvh - 178px), 620px);
  display: grid;
  grid-template-columns: repeat(7, minmax(132px, 1fr));
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--surface);
}

.day-card {
  min-width: 0;
  display: grid;
  grid-template-rows: 52px repeat(3, minmax(112px, 1fr));
  border-right: 1px solid var(--border);
}

.day-card:last-child { border-right: 0; }

.day-head {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-raised);
}

.day-name {
  font-size: .875rem;
  font-weight: 650;
}

.day-date {
  color: var(--text-secondary);
  font-size: .75rem;
}

.day-card.today .day-head {
  color: var(--text);
  background: var(--accent-soft);
  box-shadow: inset 0 2px 0 var(--accent);
}

.day-card.today .day-date { color: #d18a98; }

.meal-slot {
  position: relative;
  width: 100%;
  min-height: 112px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 12px;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  transition: background-color .14s ease, box-shadow .14s ease;
}

.meal-slot:last-child { border-bottom: 0; }

.meal-slot:hover {
  background: var(--surface-hover);
  box-shadow: inset 2px 0 0 var(--accent);
}

.meal-type {
  color: var(--text-secondary);
  font-size: .68rem;
  font-weight: 650;
  letter-spacing: .075em;
  text-transform: uppercase;
}

.meal-title {
  display: -webkit-box;
  margin-top: auto;
  overflow: hidden;
  font-size: .9rem;
  font-weight: 620;
  line-height: 1.3;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.meal-meta {
  margin-top: 4px;
  color: var(--text-secondary);
  font-size: .75rem;
}

.meal-empty {
  margin-top: auto;
  color: #b8b5b1;
  font-size: .875rem;
  font-weight: 540;
}

.meal-slot:hover .meal-empty { color: #dc93a1; }

.recipe-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.recipe-grid > .empty-state {
  width: min(100%, 480px);
  grid-column: 1 / -1;
  justify-self: center;
}

.recipe-card {
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 17px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
}

.recipe-card h3 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.08rem;
  font-weight: 500;
}

.recipe-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin-top: 8px;
  color: var(--text-secondary);
  font-size: .75rem;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
}

.tag {
  padding: 3px 7px;
  border: 1px solid var(--border);
  border-radius: 2px;
  color: var(--text-secondary);
  background: transparent;
  font-size: .75rem;
}

.recipe-actions {
  display: flex;
  gap: 7px;
  margin-top: auto;
  padding-top: 18px;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 110px 120px auto;
  gap: 8px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  color: var(--text);
  background: #0c0d10;
}

input,
select {
  min-height: 40px;
  padding: 0 11px;
}

textarea {
  min-height: 110px;
  padding: 10px 11px;
  line-height: 1.5;
  resize: vertical;
}

input::placeholder,
textarea::placeholder { color: #797a83; }

.simple-list {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
}

.list-row {
  min-height: 62px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(90px, auto) 72px;
  align-items: center;
  gap: 16px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.list-row:last-child { border-bottom: 0; }

.list-row strong {
  display: block;
  font-size: .875rem;
  font-weight: 650;
}

.list-row small {
  display: block;
  margin-top: 3px;
  color: var(--text-secondary);
  font-size: .75rem;
}

.quantity {
  font-size: .875rem;
  font-weight: 600;
}

.text-button {
  padding: 0;
  border: 0;
  color: var(--danger);
  background: none;
  cursor: pointer;
  font-size: .875rem;
  font-weight: 550;
}

.text-button:hover { text-decoration: underline; }

.empty-state {
  min-height: 160px;
  display: grid;
  place-items: center;
  padding: 32px 18px;
  border: 1px dashed var(--border-strong);
  border-radius: 4px;
  color: var(--text-secondary);
  background: var(--surface);
  font-size: .875rem;
  line-height: 1.45;
  text-align: center;
}

.empty-state strong {
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1rem;
  font-weight: 500;
}

dialog {
  width: min(680px, calc(100vw - 32px));
  max-height: calc(100vh - 38px);
  padding: 0;
  overflow: auto;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 22px 70px rgba(0, 0, 0, .62);
}

dialog::backdrop { background: rgba(0, 0, 0, .76); }

.dialog-form {
  display: grid;
  gap: 15px;
  padding: 22px;
}

.dialog-form.compact { width: min(100%, 480px); }

.dialog-head {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 13px;
  border-bottom: 1px solid var(--border);
}

.dialog-form label {
  display: grid;
  gap: 7px;
  color: var(--text);
  font-size: .875rem;
  font-weight: 600;
}

.label-note {
  color: var(--text-secondary);
  font-size: .75rem;
  font-weight: 400;
}

.form-grid.two {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.toast {
  position: fixed;
  z-index: 100;
  right: 20px;
  bottom: 20px;
  max-width: min(390px, calc(100vw - 32px));
  padding: 12px 14px;
  border: 1px solid #cb6377;
  border-radius: 3px;
  color: #fff8f7;
  background: #7f3040;
  font-size: .875rem;
  line-height: 1.4;
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity .16s ease, transform .16s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.muted { color: var(--text-secondary); }

@media (max-width: 1180px) {
  .sidebar { gap: 18px; }
  .tab { padding-inline: 10px; }
  .tab::after {
    right: 10px;
    left: 10px;
  }
  .mcp-pill { display: none; }

  .planner-grid {
    grid-template-columns: repeat(7, 150px);
    overflow-x: auto;
  }

  .recipe-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
  .app-layout {
    grid-template-rows: 58px minmax(0, 1fr);
  }

  .sidebar {
    height: 58px;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    padding: 0 16px;
  }

  .tabs {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 60;
    height: 64px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0;
    border-top: 1px solid var(--border-strong);
    background: rgba(9, 9, 11, .98);
    backdrop-filter: blur(12px);
  }

  .tab {
    min-height: 64px;
    padding: 0 5px;
    border-right: 1px solid var(--border);
    font-size: .75rem;
  }

  .tab:last-child { border-right: 0; }

  .tab::after {
    top: 0;
    right: 18px;
    bottom: auto;
    left: 18px;
  }

  .topbar-actions { gap: 6px; }

  .workspace { padding-bottom: 64px; }

  .workspace > main {
    padding: 22px 16px 34px;
  }

  .planner-grid {
    min-height: calc(100dvh - 166px);
    grid-template-columns: repeat(7, minmax(260px, 82vw));
    overflow-x: auto;
    scroll-snap-type: x proximity;
  }

  .day-card { scroll-snap-align: start; }

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

@media (max-width: 560px) {
  .brand { font-size: 1.08rem; }

  .topbar-actions .button {
    width: 38px;
    padding: 0;
  }

  .topbar-actions .button span { display: none; }

  .section-head {
    gap: 12px;
    margin-bottom: 16px;
  }

  .section-head h2 { font-size: 1.3rem; }

  .week-controls { flex: 0 0 auto; }

  .week-controls .button {
    min-width: 62px;
    padding-inline: 10px;
  }

  .planner-grid {
    grid-template-columns: repeat(7, minmax(256px, 86vw));
  }

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

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

  .inline-form input:first-of-type,
  .inline-form .button { grid-column: 1 / -1; }

  .list-row {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px 12px;
  }

  .list-row .text-button { grid-column: 2; }

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

  .dialog-form { padding: 18px; }

  .dialog-actions .button { flex: 1; }

  .toast {
    right: 16px;
    bottom: 80px;
  }
}

@media (max-width: 390px) {
  .section-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .week-controls { width: 100%; }

  .week-controls .button { flex: 1; }

  [data-panel="recipes"] .section-head > .button,
  [data-panel="shopping"] .section-head > .button {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
  }
}
