:root {
  --ink: #1b1f24;
  --bg: #f6f7f8;
  --card: #ffffff;
  --accent: #005f73;
  --accent-2: #0a9396;
  --line: #d6dce1;
  --muted: #53636f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 0% 0%, #d8f3dc 0%, transparent 38%),
    radial-gradient(circle at 100% 0%, #d7e3fc 0%, transparent 42%),
    var(--bg);
  overscroll-behavior: auto;
}

body.prevent-refresh {
  overscroll-behavior: none;
}

.wrap {
  width: min(1100px, 92vw);
  margin: 0 auto;
}

.app-shell {
  padding-bottom: 3rem;
}

.site-header {
  padding: 2rem 0 1.2rem;
}

.site-header h1 {
  margin: 0;
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.site-header p {
  margin: 0.5rem 0 0;
  color: var(--muted);
}

.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.tab-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.55rem 1rem;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 500;
}

.tab-button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.screen {
  display: none;
  gap: 1rem;
}

.screen.active {
  display: grid;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.04);
}

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

.combobox-field {
  position: relative;
}

.autocomplete-panel {
  position: absolute;
  top: calc(100% - 0.1rem);
  left: 0;
  right: 0;
  z-index: 20;
  max-height: 11rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.3rem;
  background: #fff;
  border: 1px solid var(--accent);
  border-top: none;
  border-radius: 0 0 10px 10px;
  box-shadow: 0 12px 24px rgba(0,0,0,0.10);
}

/* override display:flex so hidden attribute works */
.autocomplete-panel[hidden] {
  display: none;
}

.autocomplete-option {
  width: 100%;
  border: none;
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.autocomplete-option:hover,
.autocomplete-option.is-active {
  background: var(--accent);
  color: #fff;
}

label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.95rem;
}

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

input,
textarea,
select {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
  background: #fff;
}

button {
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 0.6rem 0.9rem;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

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

.dish-selector-label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.95rem;
  margin-bottom: 1rem;
}

.dish-selector-label select {
  width: 100%;
}

.dish-list {
  display: grid;
  gap: 1rem;
}

.dish-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.9rem;
  background: #fcfdfd;
}

.dish-top {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: start;
}

.dish-title {
  margin: 0;
  font-size: 1.05rem;
}

.dish-description {
  margin: 0.4rem 0 0;
  color: var(--muted);
}

.inline-actions {
  display: flex;
  gap: 0.4rem;
}

.inline-actions button {
  padding: 0.35rem 0.55rem;
  font-size: 0.85rem;
}

.ingredient-list {
  width: 100%;
  margin: 0.8rem 0;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.ingredient-list thead {
  background: var(--surface);
  border-bottom: 2px solid var(--line);
}

.ingredient-list th {
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.5rem;
  text-align: left;
}

.ingredient-list th:nth-child(1),
.ingredient-list th:nth-child(2),
.ingredient-list th:nth-child(3) {
  width: calc(33.333% - 0.167rem);
}

.ingredient-list th:nth-child(4) {
  width: auto;
  text-align: right;
}

.ingredient-list tbody tr {
  border-bottom: 1px solid var(--line);
}

.ingredient-list tbody tr:last-child {
  border-bottom: none;
}

.ingredient-list td {
  padding: 0.5rem;
  vertical-align: middle;
}

.ingredient-list td:nth-child(1),
.ingredient-list td:nth-child(2),
.ingredient-list td:nth-child(3) {
  width: calc(33.333% - 0.167rem);
}

.ingredient-list td:nth-child(4) {
  width: auto;
  text-align: right;
}

.ingredient-list .ing-action {
  text-align: right;
  padding: 0.2rem 0.5rem;
}

.ingredient-list .ing-action button {
  padding: 0.15rem 0.45rem;
  font-size: 0.8rem;
  line-height: 1.3;
}

.ing-category {
  color: var(--muted);
  font-size: 0.85rem;
}

.muted-label {
  color: var(--muted);
  font-size: 0.85rem;
}

.ing-amount {
  text-align: left;
  font-variant-numeric: tabular-nums;
}

.compact {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  align-items: end;
  overflow: visible;
}

.compact label {
  font-size: 0.85rem;
}

.week-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  overflow-x: auto;
  padding-bottom: 0.3rem;
}

.day-column {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem;
  background: #fff;
}

.day-column h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

.meal-slot {
  margin-bottom: 0.6rem;
}

.meal-slot h4 {
  margin: 0 0 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.meal-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 0.4rem;
  min-height: 0;
}

.meal-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  font-size: 0.82rem;
  line-height: 1.4;
}

.meal-tag button {
  background: none;
  border: none;
  color: inherit;
  padding: 0 0.1rem;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.75;
}

.meal-tag button:hover {
  opacity: 1;
  background: none;
  border: none;
}

.meal-select {
  width: 100%;
}

.actions-row {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.6rem;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.card-header h2 {
  margin: 0;
}

.btn-secondary {
  background: #fff;
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 0.35rem 0.75rem;
  font-size: 0.875rem;
  border-radius: 8px;
  cursor: pointer;
}

.btn-secondary:hover {
  background: var(--accent);
  color: #fff;
}

#shopping-list {
  display: grid;
  gap: 0.8rem;
}

.category-block {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem;
  background: #fff;
}

.category-block h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

.category-block ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.35rem;
}

.category-block li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.amount-controls {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.amount-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 0.25rem 0.5rem;
  font-size: 0.85rem;
  cursor: pointer;
}

.amount-btn:hover {
  opacity: 0.9;
}

.day-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.day-header h3 {
  margin: 0;
}

.btn-small {
  padding: 0.35rem 0.55rem;
  font-size: 0.8rem;
}

#week-summary {
  display: grid;
  gap: 0.8rem;
}

.summary-day {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem;
  background: #fff;
}

.summary-day h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

.summary-day dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.2rem 0.75rem;
  font-size: 0.9rem;
}

.summary-day dt {
  color: var(--muted);
  font-weight: 500;
  text-transform: capitalize;
}

.summary-day dd {
  margin: 0;
}

.login-card {
  max-width: 360px;
  margin: 4rem auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 2rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
}

.login-card h2 {
  margin: 0 0 1.25rem;
}

.site-header .wrap {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.error {
  border: 1px solid #ca3e47;
  color: #8c2028;
  background: #fff4f5;
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
}

@media (max-width: 900px) {
  .compact {
    grid-template-columns: 1fr 1fr;
  }

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

@media (max-width: 620px) {
  .tabs {
    flex-wrap: wrap;
  }
}
