/* Grocery List — mobile-first design system with light/dark themes. */

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

:root {
  color-scheme: light;
  --bg: #eef3ea;
  --bg-top: #e3ecdc;
  --surface: #ffffff;
  --surface-2: #f3f7f0;
  --text: #1b2a20;
  --text-muted: #5f7163;
  --border: #dce5d8;
  --border-strong: #b3c4ac;
  --primary: #2f8f57;
  --primary-hover: #267447;
  --primary-glow: #4fae7d;
  --primary-soft: #e1f0e6;
  --primary-contrast: #ffffff;
  --danger: #b23b2e;
  --danger-soft: #f8e9e6;
  --button-hover: #e8efe6;
  --focus-color: #2f8f57;
  --focus-ring: rgba(47, 143, 87, 0.25);
  --shadow: 0 1px 2px rgba(24, 44, 30, 0.05), 0 12px 32px rgba(24, 44, 30, 0.08);
  --radius: 16px;
  --radius-small: 10px;
}

[data-theme='dark'] {
  color-scheme: dark;
  --bg: #131a12;
  --bg-top: #1b241a;
  --surface: #1c261b;
  --surface-2: #243123;
  --text: #e7eee5;
  --text-muted: #a2b3a1;
  --border: #2e3a2c;
  --border-strong: #49594b;
  --primary: #46b17c;
  --primary-hover: #59c28d;
  --primary-glow: #57c68f;
  --primary-soft: #223526;
  --primary-contrast: #08130b;
  --danger: #e28373;
  --danger-soft: #3c2721;
  --button-hover: #2a3728;
  --focus-color: #57c68f;
  --focus-ring: rgba(70, 177, 124, 0.3);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 12px 32px rgba(0, 0, 0, 0.4);
}

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg) 360px) var(--bg);
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 680px;
  margin: 0 auto;
  padding: 28px 20px 110px;
}

/* ---------------------------------------------------------------- header */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.brand { display: flex; align-items: center; gap: 14px; }

.brand-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  font-size: 26px;
  background: var(--primary-soft);
  border: 1px solid var(--border);
  border-radius: 14px;
}

.brand-text h1 { margin: 0; font-size: 1.45rem; letter-spacing: -0.02em; line-height: 1.2; }

.tagline { margin: 2px 0 0; color: var(--text-muted); font-size: 0.9rem; }

/* ---------------------------------------------------------------- progress */

.progress-card {
  padding: 16px 18px;
  margin-bottom: 18px;
  background: linear-gradient(135deg, var(--primary-soft), var(--surface) 65%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.progress-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }

.progress-summary { margin: 0; font-weight: 600; }

.progress-percent {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.progress-track {
  margin-top: 10px;
  height: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-glow));
  border-radius: 999px;
  transition: width 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ---------------------------------------------------------------- forms */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.add-form { padding: 18px; margin-bottom: 20px; }

.add-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 0.8fr) minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
}

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }

.field-label {
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.field-input {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-small);
}

.field-input::placeholder { color: var(--text-muted); opacity: 0.75; }

/* Custom dropdown arrow so the select always reads as a select. */
select.field-input {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%235f7163' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}

[data-theme='dark'] select.field-input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23a2b3a1' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

.field-error { margin: 0; min-height: 1.15em; font-size: 0.8rem; color: var(--danger); }

.add-button { margin-top: 24px; }

.form-hint { margin: 12px 0 0; font-size: 0.8rem; color: var(--text-muted); }

kbd {
  padding: 1px 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
}

/* ---------------------------------------------------------------- buttons */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-small);
  cursor: pointer;
}

.button:hover { background: var(--button-hover); }
.button:active { transform: translateY(1px); }

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

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

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-small);
  cursor: pointer;
}

.icon-button:hover {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--border);
}

.icon-button.danger:hover {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: transparent;
}

a:focus-visible, button:focus-visible, .item-toggle:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 2px;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

/* ---------------------------------------------------------------- toolbar */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.filters {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.filter-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 13px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
}

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

.filter-button[aria-pressed='true'] {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.14);
}

.filter-count {
  min-width: 1.5em;
  padding: 1px 7px;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: var(--text-muted);
  background: var(--bg);
  border-radius: 999px;
}

.filter-button[aria-pressed='true'] .filter-count { color: var(--primary); background: var(--primary-soft); }

.clear-button { padding: 8px 14px; font-size: 0.9rem; }

.clear-button:hover {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: var(--danger);
}

/* ---------------------------------------------------------------- item list */

.item-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(24, 44, 30, 0.04);
}

.item-body { flex: 1 1 auto; display: flex; flex-direction: column; gap: 3px; min-width: 0; }

.item-name { margin: 0; font-weight: 600; overflow-wrap: anywhere; }

.item-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: 0; }

.item-quantity { color: var(--text-muted); font-size: 0.9rem; }

.item-category {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.item-actions { display: flex; gap: 4px; }

.item.is-purchased .item-name {
  color: var(--text-muted);
  text-decoration: line-through;
  text-decoration-thickness: 2px;
}

.item.is-purchased .item-quantity,
.item.is-purchased .item-category { opacity: 0.7; }

/* custom checkbox: native semantics, grocery-green styling */
.item-toggle {
  flex: none;
  appearance: none;
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  background: var(--surface);
  border: 2px solid var(--border-strong);
  border-radius: 8px;
  cursor: pointer;
}

.item-toggle:hover { border-color: var(--primary); }

.item-toggle:checked {
  background: var(--primary);
  border-color: var(--primary);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4.5 12.5l5 5 10-11'/%3E%3C/svg%3E");
  background-size: 78%;
  background-position: center;
  background-repeat: no-repeat;
}

/* ---------------------------------------------------------------- edit mode */

.item.is-editing { border-color: var(--primary); }

.edit-form {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 0.8fr) minmax(0, 1fr) auto;
  gap: 12px;
  width: 100%;
  align-items: start;
}

.edit-actions { display: flex; gap: 8px; margin-top: 24px; }

/* ---------------------------------------------------------------- empty state */

.empty-state {
  padding: 46px 20px;
  text-align: center;
  background: transparent;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}

.empty-icon { margin: 0; font-size: 40px; }

.empty-title { margin: 10px 0 4px; font-size: 1.05rem; font-weight: 700; }

.empty-text { max-width: 380px; margin: 0 auto; color: var(--text-muted); font-size: 0.92rem; }

/* ---------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: min(92vw, 480px);
  padding: 12px 16px;
  background: #1f2b22;
  color: #eef4ee;
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  transform: translateX(-50%);
  animation: toast-in 180ms ease-out;
}

[data-theme='dark'] .toast { background: #edf3ec; color: #1c2a20; }

.toast[hidden] { display: none; }

.toast-message { font-size: 0.92rem; }

.toast-undo {
  flex: none;
  padding: 6px 12px;
  font: inherit;
  font-weight: 700;
  color: #7ed3a4;
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

[data-theme='dark'] .toast-undo { color: #217048; }

.toast-undo:hover { opacity: 0.8; }

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------------------------------------------------------------- footer */

.app-footer { margin-top: 30px; text-align: center; color: var(--text-muted); font-size: 0.82rem; }
.app-footer p { margin: 0; }

/* ---------------------------------------------------------------- misc */

.skip-link {
  position: absolute;
  left: 12px;
  top: -52px;
  z-index: 60;
  padding: 10px 16px;
  font-weight: 600;
  color: #fff;
  background: var(--primary);
  border-radius: 8px;
  text-decoration: none;
  transition: top 150ms ease;
}

.skip-link:focus { top: 12px; }

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

/* ---------------------------------------------------------------- responsive */

@media (max-width: 640px) {
  .app { padding: 20px 16px 104px; }

  .brand-icon { width: 42px; height: 42px; font-size: 22px; }

  .add-grid { grid-template-columns: 1fr 1fr; }
  .add-grid .field-name { grid-column: 1 / -1; }
  .add-grid .add-button { grid-column: 1 / -1; margin-top: 2px; }

  .edit-form { grid-template-columns: 1fr 1fr; }
  .edit-form .field-name { grid-column: 1 / -1; }
  .edit-form .edit-actions { grid-column: 1 / -1; margin-top: 0; }
  .edit-actions .button { flex: 1; }

  .toolbar { justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
}