/* ── Light theme (default) ── */
:root {
  --bg:           #f5f5f7;
  --surface:      #ffffff;
  --surface-2:    #f0f0f5;
  --surface-hover:#e8e8f0;
  --border:       #d8d8e0;
  --border-strong:#a0a0b0;
  --text:         #1a1a2e;
  --text-muted:   #606080;
  --text-dim:     #a0a0b8;
  --accent:       #6366f1;
  --accent-bg:    rgba(99,102,241,0.1);
  --accent-hover: #4f46e5;
  --danger:       #dc2626;
  --danger-bg:    rgba(220,38,38,0.08);
  --success:      #16a34a;
  --checked-text: #a0a0b8;
  --nav-height:   52px;
  --radius:       8px;
  --radius-sm:    5px;
  --shadow:       0 1px 4px rgba(0,0,0,0.08);
  --shadow-md:    0 4px 16px rgba(0,0,0,0.1);
}

/* ── Dark theme ── */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:           #0f1117;
    --surface:      #1a1d27;
    --surface-2:    #22263a;
    --surface-hover:#2a2f45;
    --border:       #2e3347;
    --border-strong:#424868;
    --text:         #e2e4f0;
    --text-muted:   #7b819e;
    --text-dim:     #454c6b;
    --accent:       #818cf8;
    --accent-bg:    rgba(129,140,248,0.12);
    --accent-hover: #6366f1;
    --danger:       #f87171;
    --danger-bg:    rgba(248,113,113,0.1);
    --success:      #4ade80;
    --checked-text: #454c6b;
    --shadow:       0 1px 4px rgba(0,0,0,0.3);
    --shadow-md:    0 4px 16px rgba(0,0,0,0.4);
  }
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

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

body.center-page {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

/* ── Nav ── */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  gap: 0.5rem;
  box-shadow: var(--shadow);
}

.nav-brand {
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
  color: var(--text);
  text-decoration: none;
  flex-shrink: 0;
}
.nav-brand .dot { color: var(--accent); }

.nav-links {
  display: flex;
  gap: 0.15rem;
  margin-left: auto;
  align-items: center;
}

.nav-link {
  padding: 0.35rem 0.7rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s, background 0.15s;
  white-space: nowrap;
}
.nav-link:hover { color: var(--text); background: var(--surface-2); }
.nav-link.active { color: var(--accent); background: var(--accent-bg); }

.nav-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--border);
  object-fit: cover;
  flex-shrink: 0;
  margin-left: 0.5rem;
}

/* ── Mobile nav toggle ── */
.nav-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  padding: 0.4rem;
  border-radius: var(--radius-sm);
  margin-left: auto;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
}
.nav-toggle:hover { background: var(--surface-2); }

@media (max-width: 640px) {
  .nav-toggle { display: flex; }
  .nav-links {
    display: none;
    position: absolute;
    top: 100%;
    left: 0; right: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    padding: 0.4rem;
    flex-direction: column;
    z-index: 99;
    gap: 0;
    margin-left: 0;
  }
  .nav-links.open { display: flex; }
  .nav-links .nav-link { padding: 0.75rem 1rem; font-size: 0.9rem; }
  .nav-avatar { display: none; }
}

/* ── Page containers ── */
.page     { max-width: 800px;  margin: 0 auto; padding: 1.5rem 1.25rem; }
.page-lg  { max-width: 1060px; margin: 0 auto; padding: 1.5rem 1.25rem; }

/* ── Typography ── */
h1 { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1.05rem; font-weight: 600; }
h3 { font-size: 0.9rem;  font-weight: 600; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s, border-color 0.15s;
  text-decoration: none;
  white-space: nowrap;
  font-family: inherit;
}
.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost    { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
.btn-danger   { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-icon     { background: transparent; color: var(--text-muted); border: none; padding: 0.35rem; border-radius: var(--radius-sm); }
.btn-icon:hover { background: var(--surface-2); color: var(--text); }
.btn-sm       { padding: 0.3rem 0.65rem; font-size: 0.8rem; }
.btn:disabled { opacity: 0.4; pointer-events: none; }

/* ── Inputs ── */
.input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
.input:focus { border-color: var(--accent); }
.input::placeholder { color: var(--text-dim); }
.input-sm { padding: 0.35rem 0.6rem; font-size: 0.85rem; }

/* Combobox wrapper */
.combo-wrap { position: relative; }
.combo-dropdown {
  position: absolute;
  top: calc(100% + 3px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  z-index: 50;
  max-height: 200px;
  overflow-y: auto;
}
.combo-option {
  padding: 0.45rem 0.75rem;
  font-size: 0.875rem;
  cursor: pointer;
  color: var(--text);
  transition: background 0.1s;
}
.combo-option:hover, .combo-option.focused { background: var(--surface-2); }
.combo-option.create { color: var(--accent); font-style: italic; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

/* ── Section headers ── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

/* ── List rows ── */
.row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius-sm);
  transition: background 0.1s;
}
.row:hover { background: var(--surface-2); }
.row + .row { border-top: 1px solid var(--border); }
.row-name    { flex: 1; min-width: 0; font-size: 0.9rem; }
.row-actions { display: flex; gap: 0.15rem; flex-shrink: 0; margin-left: auto; }

/* Shopping list item — checked state */
.row.checked {
  opacity: 0.45;
}
.row.checked .row-name {
  text-decoration: line-through;
  color: var(--checked-text);
}

/* ── Add row (shared across stores, aisles, items) ── */
.add-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding: 0.6rem 0 0.9rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.5rem;
  flex-wrap: nowrap;
}
.add-row > .input     { flex: 1; width: auto; min-width: 0; }
.add-row .btn         { flex-shrink: 0; }
.add-row .combo-wrap  { flex: 1; min-width: 0; }
.add-row .combo-wrap .input { width: 100%; }
.add-row select       { flex-shrink: 0; }

/* ── Drag handle ── */
.drag-handle {
  cursor: grab;
  color: var(--text-dim);
  font-size: 1rem;
  padding: 0 0.15rem;
  flex-shrink: 0;
  user-select: none;
}
.drag-handle:active { cursor: grabbing; }

/* ── Search bar ── */
.search-wrap {
  position: relative;
  margin-bottom: 1rem;
}
.search-icon {
  position: absolute;
  left: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  pointer-events: none;
  font-size: 0.9rem;
}
.search-wrap .input { padding-left: 2rem; }

/* ── Store group header ── */
.store-group { margin-bottom: 1.5rem; }
.store-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 0 0.1rem 0.4rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.25rem;
}

/* ── Aisle subheader (in shopping list) ── */
.aisle-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  padding: 0.6rem 0.75rem 0.2rem;
}

/* ── Quantity badge ── */
.qty-badge {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 0.4rem;
  min-width: 24px;
  text-align: center;
  flex-shrink: 0;
}

/* ── Empty state ── */
.empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.empty-icon { font-size: 2rem; margin-bottom: 0.5rem; }

/* ── Toast notifications ── */
.toast-container {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 999;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 1rem;
  font-size: 0.875rem;
  box-shadow: var(--shadow-md);
  animation: toastIn 0.2s ease;
}
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.success { border-color: var(--success); color: var(--success); }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* ── Modal ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-md);
}
.modal-title { font-size: 1rem; font-weight: 600; margin-bottom: 1rem; }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1.25rem; }

/* ── Utilities ── */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.gap-sm { gap: 0.5rem; }
.gap-md { gap: 1rem; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.ml-auto  { margin-left: auto; }
.flex-1   { flex: 1; min-width: 0; }
.mt-sm { margin-top: 0.5rem; }
.mt-md { margin-top: 1rem; }
.mt-lg { margin-top: 1.5rem; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.775rem; }
.hidden { display: none !important; }
