:root {
  --bg: #111111;
  --surface: #191a1c;
  --surface-2: #222426;
  --surface-3: #2d3033;
  --text: #f7f4ef;
  --muted: #b4afa7;
  --line: #383a3d;
  --accent: #f59e0b;
  --accent-text: #211403;
  --teal: #14b8a6;
  --blue: #60a5fa;
  --green: #22c55e;
  --red: #ef4444;
  --shadow: 0 18px 42px rgba(0, 0, 0, .28);
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
  scroll-behavior: smooth;
}

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;
  font-size: 16px;
  line-height: 1.5;
  letter-spacing: 0;
}

a {
  color: inherit;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 2rem;
  line-height: 1.12;
}

h2 {
  margin-bottom: .75rem;
  font-size: 1.05rem;
  line-height: 1.25;
}

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

button,
.btn,
.danger {
  min-height: 2.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: .6rem .85rem;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

button:hover,
.btn:hover {
  filter: brightness(1.06);
}

.btn.secondary,
button.secondary {
  background: var(--surface-3);
  border-color: var(--line);
  color: var(--text);
}

.danger {
  background: rgba(239, 68, 68, .16) !important;
  border-color: rgba(239, 68, 68, .42) !important;
  color: #fecaca !important;
}

.small {
  min-height: 2.1rem !important;
  padding: .42rem .62rem !important;
  font-size: .9rem !important;
}

button:disabled {
  opacity: .5;
  cursor: not-allowed;
}

input,
select,
textarea,
.search {
  width: 100%;
  min-height: 2.55rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101112;
  color: var(--text);
  padding: .58rem .7rem;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
.search:focus {
  border-color: rgba(20, 184, 166, .85);
  box-shadow: 0 0 0 3px rgba(20, 184, 166, .16);
}

label {
  display: grid;
  gap: .35rem;
  color: var(--muted);
  font-size: .92rem;
  font-weight: 700;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 4.25rem;
  padding: .7rem clamp(1rem, 3vw, 2rem);
  background: rgba(17, 17, 17, .94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: .7rem;
  color: var(--text);
  text-decoration: none;
}

.brand-icon {
  width: 2.2rem;
  height: 2.2rem;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--teal);
  color: #021f1c;
  font-size: .78rem;
  font-weight: 950;
}

.brand-text {
  display: grid;
  gap: .05rem;
  line-height: 1.1;
}

.brand-text strong {
  font-size: 1rem;
}

.brand-text small {
  color: var(--muted);
  font-size: .78rem;
  font-weight: 650;
}

.app-nav {
  display: flex;
  gap: .35rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.app-nav a {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: .52rem .68rem;
  color: var(--muted);
  text-decoration: none;
  font-size: .94rem;
  font-weight: 760;
  white-space: nowrap;
}

.app-nav a:hover {
  background: var(--surface-2);
  color: var(--text);
}

.app-nav a.active {
  background: rgba(20, 184, 166, .16);
  border-color: rgba(20, 184, 166, .44);
  color: #ccfbf1;
}

.container {
  width: min(1240px, calc(100% - 2rem));
  margin: 1.1rem auto 4rem;
}

.card,
.side-panel,
.plan-card,
.notice,
.status-tile,
.pantry-row,
.empty-list {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: none;
}

.card {
  padding: 1rem;
}

.narrow-form {
  width: min(620px, 100%);
}

.page-headline {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.page-headline .eyebrow {
  margin-bottom: .3rem;
}

.page-actions,
.actions,
.row-actions {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  align-items: center;
}

.page-actions form,
.row-actions form {
  display: inline-flex;
  margin: 0;
}

.eyebrow {
  color: #5eead4;
  font-size: .78rem;
  font-weight: 950;
  letter-spacing: 0;
  text-transform: uppercase;
}

.notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: .85rem;
  padding: .75rem .9rem;
}

.notice.success,
.success {
  border-color: rgba(34, 197, 94, .38);
  background: rgba(34, 197, 94, .11);
}

.notice.danger {
  border-color: rgba(239, 68, 68, .38);
  background: rgba(239, 68, 68, .11);
}

.week-nav {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: .45rem;
  margin: 0 0 1rem;
}

.week-nav-link {
  display: grid;
  gap: .1rem;
  min-height: 3.25rem;
  align-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  text-align: center;
  text-decoration: none;
  font-weight: 820;
}

.week-nav-link small {
  color: var(--muted);
  font-size: .82rem;
  font-weight: 700;
}

.week-nav-link.active {
  border-color: rgba(245, 158, 11, .55);
  background: rgba(245, 158, 11, .15);
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .65rem;
  margin-bottom: 1rem;
}

.status-grid.compact .status-tile {
  min-height: 5rem;
}

.status-tile {
  display: grid;
  gap: .12rem;
  padding: .9rem;
  color: var(--text);
  text-decoration: none;
}

.status-tile span {
  color: var(--muted);
  font-size: .8rem;
  font-weight: 850;
  text-transform: uppercase;
}

.status-tile strong {
  font-size: 1.55rem;
  line-height: 1.15;
}

.planner-summary {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  margin: -.25rem 0 1rem;
}

.planner-summary span {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  min-height: 2rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  padding: .35rem .6rem;
  font-size: .9rem;
  font-weight: 750;
}

.planner-summary b {
  color: var(--text);
}

.pantry-workspace {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.quick-add-card {
  display: grid;
  gap: .8rem;
  margin-bottom: 1rem;
  scroll-margin-top: 5.5rem;
}

.quick-add-form {
  display: grid;
  grid-template-columns: 190px minmax(220px, 1fr) 110px minmax(160px, .7fr) auto;
  gap: .7rem;
  align-items: end;
}

.quick-add-form label {
  min-width: 0;
}

.meal-field {
  min-width: 0;
}

.quick-add-submit {
  min-width: 8.5rem;
}

.planner-week {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: .55rem;
  min-width: 0;
}

.plan-card {
  min-height: 12.5rem;
  display: flex;
  flex-direction: column;
  gap: .7rem;
  padding: .75rem;
  min-width: 0;
  overflow: hidden;
}

.plan-card header {
  display: flex;
  justify-content: space-between;
  gap: .5rem;
  align-items: flex-start;
}

.plan-card header strong {
  display: block;
  font-size: .98rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.plan-card header small {
  color: var(--muted);
  font-size: .84rem;
}

.plan-card.is-empty {
  background: #151617;
}

.plan-card.is-cooked {
  border-color: rgba(34, 197, 94, .42);
  background: rgba(34, 197, 94, .10);
}

.plan-meal {
  display: grid;
  gap: .25rem;
}

.plan-meal b {
  overflow: hidden;
  text-overflow: ellipsis;
}

.plan-meal small {
  color: var(--muted);
  font-size: .84rem;
}

.status-line {
  color: #86efac !important;
}

.empty-action {
  width: 100%;
  margin-top: auto;
  min-height: 3.2rem;
  border: 1px dashed rgba(20, 184, 166, .42);
  background: rgba(20, 184, 166, .09);
  color: #ccfbf1;
  white-space: normal;
}

.side-panel {
  position: sticky;
  top: 5.2rem;
  display: grid;
  gap: 1rem;
  padding: 1rem;
}

.planner-add-card {
  order: 2;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: .75rem;
  align-items: center;
}

.panel-head h2 {
  margin: 0;
}

.panel-head span {
  color: var(--muted);
  font-weight: 800;
}

.stack-form,
.form {
  display: grid;
  gap: .75rem;
}

.split-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 1.6rem;
  border-radius: 999px;
  padding: .2rem .55rem;
  background: var(--surface-3);
  color: var(--text);
  font-size: .76rem;
  font-weight: 850;
}

.success-badge {
  background: rgba(34, 197, 94, .18);
  color: #bbf7d0;
}

.info-badge {
  background: rgba(96, 165, 250, .18);
  color: #bfdbfe;
}

.muted-badge {
  background: var(--surface-3);
  color: var(--muted);
}

.pantry-list {
  display: grid;
  gap: 1rem;
  min-width: 0;
}

.pantry-category {
  display: grid;
  gap: .5rem;
}

.pantry-category h2 {
  margin: 0;
  color: #fde68a;
}

.pantry-rows {
  display: grid;
  gap: .55rem;
}

.pantry-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: .75rem;
  align-items: center;
  padding: .75rem;
  scroll-margin-top: 5.5rem;
}

.pantry-main {
  min-width: 0;
}

.pantry-main strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pantry-main small {
  display: block;
  color: var(--muted);
}

.qty-control {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
}

.qty-btn {
  width: 2.1rem !important;
  height: 2.1rem !important;
  min-height: 2.1rem !important;
  padding: 0 !important;
}

.qty-value {
  min-width: 5rem;
  text-align: center;
  font-weight: 850;
}

.empty-list {
  padding: 1rem;
  color: var(--muted);
}

.login-shell {
  min-height: calc(100vh - 9rem);
  display: grid;
  place-items: center;
}

.login-card {
  width: min(420px, 100%);
}

.login-error {
  justify-content: flex-start;
}

[hidden] {
  display: none !important;
}

@media (max-width: 1120px) {
  .planner-week {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .pantry-workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .quick-add-form {
    grid-template-columns: minmax(180px, .8fr) minmax(260px, 1.2fr) 110px;
  }

  .note-field,
  .quick-add-submit {
    grid-column: span 1;
  }

  .side-panel {
    position: static;
  }

  .planner-add-card,
  .pantry-workspace .side-panel {
    order: -1;
  }
}

@media (max-width: 820px) {
  .topbar {
    position: static;
    align-items: stretch;
    flex-direction: column;
  }

  .app-nav {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
  }

  .app-nav a {
    text-align: center;
  }

  .container {
    width: min(100% - 1rem, 1240px);
    margin-top: .75rem;
  }

  .page-headline {
    align-items: stretch;
    flex-direction: column;
  }

  .page-actions,
  .actions {
    display: grid;
    grid-template-columns: 1fr;
  }

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

  .week-nav-link.active {
    grid-column: span 2;
  }

  .status-grid,
  .planner-week {
    grid-template-columns: 1fr;
  }

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

  .plan-card {
    min-height: auto;
  }

  .row-actions {
    justify-content: stretch;
  }

  .row-actions > *,
  .row-actions form,
  .row-actions .btn {
    flex: 1 1 auto;
  }

  .pantry-row {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .qty-control {
    justify-content: space-between;
  }
}

@media (max-width: 520px) {
  h1 {
    font-size: 1.65rem;
  }

  .split-inputs {
    grid-template-columns: 1fr;
  }

  .app-nav {
    grid-template-columns: 1fr;
  }
}
