/* ---------- Palette ---------- */

/* Grays: shadcn neutral (light) and Material 3 (dark, as in Gmail). Accents: Catppuccin hues, used only by tag colors.
   html.dark is set in index.html from the Settings theme or the system. */
:root {
  color-scheme: light;
  --ctp-rosewater: #dc8a78; --ctp-flamingo: #dd7878; --ctp-pink: #ea76cb; --ctp-mauve: #8839ef;
  --ctp-red: #d20f39; --ctp-maroon: #e64553; --ctp-peach: #fe640b; --ctp-yellow: #df8e1d;
  --ctp-green: #40a02b; --ctp-teal: #179299; --ctp-sky: #04a5e5; --ctp-sapphire: #209fb5;
  --ctp-blue: #1e66f5; --ctp-lavender: #7287fd;
  --ctp-text: #0a0a0a; --ctp-subtext1: #404040; --ctp-subtext0: #737373; --ctp-overlay2: #737373;
  --ctp-overlay1: #a3a3a3; --ctp-overlay0: #a3a3a3; --ctp-surface2: #a3a3a3; --ctp-surface1: #d4d4d4;
  --ctp-surface0: #e5e5e5; --ctp-base: #ffffff; --ctp-mantle: #ffffff; --ctp-crust: #f5f5f5;
}
:root.dark {
  color-scheme: dark;
  --ctp-rosewater: #f4dbd6; --ctp-flamingo: #f0c6c6; --ctp-pink: #f5bde6; --ctp-mauve: #c6a0f6;
  --ctp-red: #ed8796; --ctp-maroon: #ee99a0; --ctp-peach: #f5a97f; --ctp-yellow: #eed49f;
  --ctp-green: #a6da95; --ctp-teal: #8bd5ca; --ctp-sky: #91d7e3; --ctp-sapphire: #7dc4e4;
  --ctp-blue: #8aadf4; --ctp-lavender: #b7bdf8;
  --ctp-text: #e3e3e3; --ctp-subtext1: #c4c7c5; --ctp-subtext0: #a8aba9; --ctp-overlay2: #a8aba9;
  --ctp-overlay1: #8e918f; --ctp-overlay0: #5e6160; --ctp-surface2: #5e6160; --ctp-surface1: #444746;
  --ctp-surface0: #282a2c; --ctp-base: #131314; --ctp-mantle: #1e1f20; --ctp-crust: #1e1f20;
}

/* shadcn/Basecoat tokens, mapped once. :root.dark beats Basecoat's own .dark block. */
:root, :root.dark {
  --background: var(--ctp-base);     --foreground: var(--ctp-text);
  --card: var(--ctp-mantle);         --card-foreground: var(--ctp-text);
  --popover: var(--ctp-mantle);      --popover-foreground: var(--ctp-text);
  --secondary: var(--ctp-surface0);  --secondary-foreground: var(--ctp-text);
  --muted: var(--ctp-surface0);      --muted-foreground: var(--ctp-subtext0);
  --accent: var(--ctp-surface0);     --accent-foreground: var(--ctp-text);
  --destructive: var(--ctp-red);
  --radius: .75rem;
  interpolate-size: allow-keywords; /* lets <details> animate to height: auto */
}
/* Google blue accent (title, buttons, edit accents): light #0b57d0, dark #a8c7fa. */
:root { --primary: #0b57d0; --primary-foreground: #ffffff; --border: #e5e5e5; --input: #e5e5e5; --ring: #0b57d0; --ink: #0b57d0; }
:root.dark { --primary: #a8c7fa; --primary-foreground: #062e6f; --border: #ffffff1a; --input: #ffffff26; --ring: #a8c7fa; --ink: #a8c7fa; }

/* ---------- Base (mobile first) ---------- */

body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
svg:has(> use) { width: 1.25rem; height: 1.25rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* 16px stops iOS Safari zooming into focused inputs. */
.input { font-size: 16px; }

.app {
  max-width: 40rem;
  margin-inline: auto;
  min-height: 100dvh;
  padding: 0 max(1rem, env(safe-area-inset-right)) calc(2rem + env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
}

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(0, 1fr); /* long tag rows scroll instead of widening the page */
  gap: .75rem;
  padding: calc(.75rem + env(safe-area-inset-top)) 0 .75rem;
  background: color-mix(in oklab, var(--background) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.bar { display: flex; align-items: center; gap: .25rem; margin-bottom: .5rem; }
.bar h1 { flex: 1; margin: 0; font: 500 2rem/1.1 "Bricolage Grotesque", system-ui, sans-serif; letter-spacing: -.01em; color: var(--ink); }
#edit-btn { color: var(--ink); }
#edit-btn[aria-pressed="true"] { font-weight: 700; }
#settings-btn { border-radius: 50%; color: var(--ink); background: color-mix(in oklab, var(--ink) 14%, transparent); }

.searchbar { display: flex; gap: .5rem; }
.search-field { position: relative; flex: 1; }
.search-field > svg { position: absolute; left: .75rem; top: 50%; translate: 0 -50%; width: 1rem; height: 1rem; color: var(--muted-foreground); pointer-events: none; }
.search-field .input { width: 100%; padding-left: 2.25rem; padding-right: 2.75rem; height: 2.75rem; }
.search-field .input::-webkit-search-cancel-button { display: none; }
/* Clear button shows only with text: an empty field shows its placeholder. */
.search-field .clear { position: absolute; right: 0; top: 0; width: 2.75rem; height: 2.75rem; display: grid; place-items: center; border: 0; background: none; color: var(--muted-foreground); }
.search-field .clear svg { width: 1.125rem; height: 1.125rem; }
.search-field .input:placeholder-shown + .clear { display: none; }
.searchbar .btn { width: 2.75rem; height: 2.75rem; }

.segment {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 3px;
  border-radius: var(--radius);
  background: var(--muted);
}
.segment button {
  border: 0;
  padding: .45rem;
  border-radius: calc(var(--radius) - 3px);
  background: transparent;
  color: var(--muted-foreground);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background-color .2s, color .2s;
}
.segment button[aria-pressed="true"] { background: var(--background); color: var(--foreground); box-shadow: 0 1px 2px rgb(0 0 0 / .15); }

/* One filter row: a compact Pending/All segment, then tag chips that scroll sideways. */
.filters { display: flex; align-items: center; gap: .4rem; }
.filters .segment { flex: none; padding: 2px; background: var(--ctp-crust); border-radius: .6rem; }
.filters .segment button { padding: .3rem .75rem; font-size: .875rem; font-weight: 600; border-radius: .45rem; }

/* ---------- Tags ---------- */
/* --c is a palette color (set inline). Mixing toward the page keeps text readable in both themes. */

.tag {
  --c: var(--ctp-blue);
  display: inline-flex;
  align-items: center;
  padding: .05rem .45rem;
  border: 1px solid color-mix(in oklab, var(--c) 45%, transparent);
  border-radius: 99px;
  background: color-mix(in oklab, var(--c) 16%, var(--background));
  color: color-mix(in oklab, var(--c) 70%, var(--foreground));
  font: inherit;
  font-size: .75rem;
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
  vertical-align: .1em;
}
button.tag { min-height: 2rem; padding: .25rem .8rem; font-size: .875rem; cursor: pointer; transition: background-color .2s, color .2s; }
button.tag[aria-pressed="true"] { background: var(--c); border-color: var(--c); color: var(--background); }
.tag.add-tag { --c: var(--ctp-overlay1); border-style: dashed; background: none; }

/* Filter bar: one line, swipe sideways when there are many. */
.tagbar { flex: 1; min-width: 0; display: flex; gap: .4rem; overflow-x: auto; scrollbar-width: none; }
.tagbar::-webkit-scrollbar { display: none; }
.tagbar[hidden] { display: none; }

.dialog .chips { display: flex; flex-direction: row; flex-wrap: wrap; gap: .4rem; } /* Basecoat stacks dialog flex rows */
.new-tag { display: grid; gap: .6rem; }
.new-tag[hidden] { display: none; }
.tag-list { display: grid; gap: .25rem; margin: 0; padding: 0; list-style: none; }
.tag-list li { display: flex; align-items: center; justify-content: space-between; min-height: 2.25rem; }
.tag-list .edit { color: var(--muted-foreground); }
.tag-list .edit svg { width: 1rem; height: 1rem; }
.tag-list .actions { display: flex; }
.tag-list .edit:disabled { opacity: .3; }
.tag-list .up { rotate: 180deg; }
.tag-list .none { color: var(--muted-foreground); font-size: .875rem; }
.dialog .swatches { display: flex; flex-direction: row; flex-wrap: wrap; gap: .5rem; }
.swatches input { appearance: none; width: 1.75rem; height: 1.75rem; margin: 0; border-radius: 50%; background: var(--c); cursor: pointer; }
.swatches input:checked { outline: 2px solid var(--foreground); outline-offset: 2px; }

/* ---------- List ---------- */

.group + .group { border-top: 1px solid color-mix(in oklab, var(--border) 70%, transparent); padding-top: .25rem; }
.group > summary {
  display: flex;
  align-items: center;
  gap: .5rem;
  min-height: 2.75rem;
  list-style: none;
  font-weight: 500;
  font-size: .9375rem; /* same size as tiles; muted color keeps headers quiet, the divider does the separating */
  color: var(--muted-foreground);
  cursor: pointer;
  user-select: none;
}
.group > summary::-webkit-details-marker { display: none; }
.group > summary .title { flex: 1; min-width: 0; display: flex; align-items: center; gap: .5rem; }
.group > summary .emoji { display: grid; place-items: center; width: 1.6rem; height: 1.6rem; flex: none; border-radius: .45rem; font-size: .9rem; background: color-mix(in oklab, var(--foreground) 8%, transparent); }
.group > summary .chevron { color: var(--muted-foreground); transition: rotate .2s ease; }
.group[open] > summary .chevron { rotate: 180deg; }
.group .edit { display: none; color: var(--muted-foreground); }
.group .edit svg { width: 1rem; height: 1rem; }
.editing .group .edit { display: inline-flex; }
.group .edit:disabled { opacity: .3; }
.group .up { rotate: 180deg; }

.count { color: var(--muted-foreground); font-size: .8125rem; font-weight: 600; font-variant-numeric: tabular-nums; }

/* Toggle tiles: on = filled surface, off = dashed outline (All view). They wrap, so a whole store fits on screen. */
.tiles { list-style: none; margin: 0; padding: 0 0 .75rem; display: flex; flex-wrap: wrap; gap: .4rem; }
.tiles li { display: contents; }
.tile {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  max-width: 100%;
  min-height: 2.25rem;
  padding: .3rem .65rem;
  border: 1px solid var(--ctp-surface0);
  border-radius: .6rem;
  background: var(--ctp-mantle);
  box-shadow: 0 1px 0 var(--ctp-crust);
  color: var(--foreground);
  font: inherit;
  font-size: .9375rem; /* 15px: a step below the category headers, still readable at arm's length */
  font-weight: 500; /* same weight on and off, so a toggle never reflows the row */
  text-align: left;
  cursor: pointer;
  /* Long-press edits: no iOS callout or text selection. */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  transition: background-color .2s, border-color .2s, color .2s, scale .12s ease;
}
:root.dark .tile { background: var(--ctp-mantle); border-color: var(--ctp-surface1); box-shadow: none; }
.tile[aria-pressed="false"] { background: transparent; border-style: dashed; border-color: var(--ctp-surface1); color: var(--ctp-overlay1); box-shadow: none; }
:root.dark .tile[aria-pressed="false"] { background: transparent; border-color: var(--ctp-surface1); }
.tile:active { scale: .95; }
.tile .name { overflow-wrap: anywhere; }
.tile .qty { padding: 0 .35rem; border-radius: 99px; background: var(--ctp-crust); color: var(--ctp-subtext0); font-size: .75rem; font-weight: 700; font-variant-numeric: tabular-nums; }
:root.dark .tile .qty { background: var(--ctp-surface1); }
.tile[aria-pressed="false"] .qty { background: none; }
.tile .important { width: .45rem; height: .45rem; border-radius: 50%; background: var(--ctp-red); flex: none; }
.tile .once { width: .9rem; height: .9rem; color: var(--ctp-subtext0); }
.tile .tag.mini { padding: 0 .4rem; border: 0; font-size: .6875rem; font-weight: 700; vertical-align: 0; }
.tile[aria-pressed="false"] :is(.important, .tag.mini) { opacity: .6; }
.tile .pencil { display: none; width: .85rem; height: .85rem; color: var(--ink); }
.editing .tile .pencil { display: block; }
.editing .tile { border-color: color-mix(in oklab, var(--ink) 45%, transparent); }

.empty { padding: 3rem 1rem; text-align: center; color: var(--muted-foreground); }
.empty strong { display: block; margin-bottom: .25rem; color: var(--foreground); font-size: 1.1rem; }

/* ---------- Dialogs ---------- */

.stack { display: grid; gap: 1rem; }
.field { display: grid; gap: .4rem; }
.field .select { width: 100%; height: 2.75rem; font-size: 16px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 2.5rem; cursor: pointer; }
.switch-row small { display: block; color: var(--muted-foreground); font-size: .8rem; }
.error { margin: 0; color: var(--destructive); font-size: .875rem; }
.error:empty { display: none; }
.dialog footer { display: flex; flex-wrap: wrap; gap: .5rem; }
.dialog footer .spacer { flex: 1; }
.dialog footer [hidden] { display: none; }

.facts { display: grid; grid-template-columns: auto 1fr; gap: .4rem 1rem; margin: 0; font-size: .9rem; }
.facts dt { color: var(--muted-foreground); }
.facts dd { margin: 0; text-align: right; }

/* ---------- Wider screens ---------- */

@media (min-width: 40rem) {
  .app { padding-inline: 2rem; }
  .top { padding-top: 2rem; }
  .bar h1 { font-size: 2rem; }
}

/* ---------- Motion ---------- */
/* Basecoat animates dialogs and toasts. The rest is ours. */

/* Section expand/collapse. Browsers without ::details-content just snap open. */
.group::details-content {
  block-size: 0;
  overflow: clip;
  transition: block-size .25s ease, content-visibility .25s allow-discrete;
}
.group[open]::details-content { block-size: auto; }

/* Switch thumb slide. */
.input[type="checkbox"][role="switch"],
.input[type="checkbox"][role="switch"]::before { transition: background-color .2s, translate .2s ease, transform .2s ease; }

/* Rows move/fade via document.startViewTransition (app.js). */
::view-transition-group(*) { animation-duration: .25s; animation-timing-function: ease; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
  /* Separate rule: an unknown pseudo-element would void the whole selector list. */
  .group::details-content { transition: none !important; }
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}
