/* Mobile-first: this gets used one-handed, in a store, sometimes in a hurry.
   Tap targets are deliberately large and the type is deliberately big. */

:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #f0f0ee;
  --border: #dcdcd6;
  /* Stronger than --border: these two rules separate the controls from the list
     and are meant to be seen, not merely felt. */
  --divider: #b9b9b0;
  --text: #1a1c1e;
  --muted: #6b6f76;
  --accent: #2f6f4f;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --radius: 12px;
  --tap: 48px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111417;
    --surface: #1a1e22;
    --surface-2: #23282d;
    --border: #313840;
    --divider: rgba(255, 255, 255, 0.3);
    --text: #e8eaed;
    --muted: #9aa2ac;
    --accent: #4c9d74;
    --accent-text: #08130d;
    --danger: #f2b8b5;
  }
}

* {
  box-sizing: border-box;
}

/* The `hidden` attribute has to win over any author `display` declaration below.
   Author styles beat the UA sheet's `[hidden] { display: none }` no matter the
   specificity, so a plain rule like `.gate { display: grid }` would keep a hidden
   element on screen. That is exactly what kept the login panel visible after
   signing in. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-text-size-adjust: 100%;
}

h1 {
  font-size: 1.15rem;
  margin: 0;
}

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

/* ------------------------------------------------------------------ controls */

input,
select,
button {
  font: inherit;
  color: inherit;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  min-height: var(--tap);
  padding: 0 12px;
}

input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button.primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
  font-weight: 600;
  padding: 0 18px;
}

button.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  min-height: auto;
  padding: 8px;
}

button.danger-soft {
  background: transparent;
  border-color: var(--border);
  color: var(--danger);
  width: 100%;
  font-weight: 600;
}

/* ---------------------------------------------------------------- lock screen */

.gate {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

.gate-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 360px;
  display: grid;
  gap: 12px;
}

/* ----------------------------------------------------------------- app chrome */

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 12px 96px;
}

/* Title, add form and tabs stick as one block, so the tabs stay reachable while
   scrolling a long list. Keeping them in one element rather than stacking three
   separately positioned sticky bars is what stops them hardcoding each other's
   heights — the old arrangement clipped the add field's focus ring along its top
   edge and overlapped on scroll. */
.sticky-head {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 4px 10px;
}

/* Two rows on a phone: the item name takes the full width, with the category and
   Add button beneath it. All three side by side cannot fit at 375px without
   pushing the button off-screen. Back to one row once there is room for it. */
.add-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--divider);
}

/* Grid items size to their content by default, and a text input's intrinsic width
   is wide enough to overflow the row. */
.add-row input,
.add-row select {
  min-width: 0;
}

#add-name {
  grid-column: 1 / -1;
}

@media (min-width: 560px) {
  .add-row {
    grid-template-columns: 1fr auto auto;
  }

  #add-name {
    grid-column: auto;
  }
}

.tabs {
  display: flex;
  gap: 6px;
  padding: 10px 0;
  border-bottom: 1px solid var(--divider);
}

.view {
  padding-top: 14px;
}

.tab {
  flex: 1;
  background: var(--surface-2);
  border-color: transparent;
  color: var(--muted);
  font-weight: 600;
  min-height: 42px;
}

.tab.active {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-text);
}

.pill {
  display: inline-block;
  min-width: 1.5em;
  padding: 0 6px;
  margin-left: 4px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  font-size: 0.78rem;
}

/* Tinting from the label colour rather than a fixed value means the count badge
   stays legible in both themes: the accent is dark green with white text in light
   mode, and light green with near-black text in dark mode. */
.tab.active .pill {
  background: color-mix(in srgb, var(--accent-text) 24%, transparent);
  color: var(--accent-text);
}

/* ---------------------------------------------------------------------- lists */

.group {
  margin-bottom: 18px;
}

.group-head {
  font-size: 0.72rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 4px 6px;
  font-weight: 700;
}

.rows {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px 4px 4px;
  border-top: 1px solid var(--border);
}

.row:first-child {
  border-top: none;
}

.row .check {
  appearance: none;
  flex: none;
  width: 26px;
  height: 26px;
  margin: 11px;
  border: 2px solid var(--muted);
  border-radius: 7px;
  background: transparent;
  min-height: auto;
  padding: 0;
  position: relative;
}

.row .check:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.row .check:checked::after {
  content: '';
  position: absolute;
  inset: 4px 5px 7px 5px;
  border: solid var(--accent-text);
  border-width: 0 0 3px 3px;
  transform: rotate(-45deg);
}

.row .label {
  flex: 1;
  min-width: 0;
  padding: 12px 0;
  overflow-wrap: anywhere;
  cursor: pointer;
}

.row.done .label {
  text-decoration: line-through;
  color: var(--muted);
}

.icon-btn {
  flex: none;
  background: transparent;
  border-color: transparent;
  width: 42px;
  min-height: 42px;
  padding: 0;
  font-size: 1.05rem;
  line-height: 1;
  color: var(--muted);
}

.icon-btn.on {
  color: #d9a319;
}

.icon-btn.trash:hover,
.icon-btn.trash:focus-visible {
  color: var(--danger);
}

.staple-add {
  flex: none;
  background: var(--surface-2);
  border-color: transparent;
  min-height: 38px;
  padding: 0 14px;
  font-size: 0.85rem;
  font-weight: 600;
  margin-right: 4px;
}

.staple-add[disabled] {
  opacity: 0.45;
  cursor: default;
}

.staples-hint {
  padding: 0 4px 10px;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 32px 16px;
}

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

.footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
}

.footer > button {
  max-width: 720px;
  margin: 0 auto;
  display: block;
}

/* --------------------------------------------------------------------- errors */

.error {
  color: var(--danger);
  font-size: 0.9rem;
  margin: 0;
}

.error.floating {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(76px + env(safe-area-inset-bottom));
  background: var(--surface);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
  z-index: 5;
}
