/* Groceries — single stylesheet. Tokens and rules per DESIGN.md §10. */

@font-face {
  font-family: "Bricolage Grotesque";
  src: url("/fonts/bricolage-grotesque-latin-500.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Bricolage Grotesque";
  src: url("/fonts/bricolage-grotesque-latin-600.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Bricolage Grotesque";
  src: url("/fonts/bricolage-grotesque-latin-700.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light dark;
  --paper: #FBFAF7;
  --card: #FFFFFF;
  --ink: #20241F;
  --muted: #6E7568;
  --leaf: #2E7D46;
  --leaf-deep: #226336;
  --leaf-tint: #EAF4EC;
  --line: #E4E2DA;
  --danger: #B3392E;
  /* text/glyph color on a --leaf fill */
  --on-leaf: #FFFFFF;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / .06);
  --display: "Bricolage Grotesque", system-ui, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #171A16;
    --card: #1E221D;
    --ink: #ECEEE8;
    --muted: #9AA294;
    --leaf: #5CBE7E;
    --leaf-deep: #79D19A;
    --leaf-tint: #1F2B22;
    --line: #2A2E28;
    --danger: #E07A6F;
    /* dark theme's green is light, so ink-on-leaf keeps ≥3:1 contrast */
    --on-leaf: #171A16;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.5;
  background: var(--paper);
  color: var(--ink);
}

button, input { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--leaf);
  outline-offset: 2px;
}

.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;
}

.shell {
  max-width: 34rem;
  margin-inline: auto;
  padding-inline: 16px;
}

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

.site-header { padding: 14px 0 4px; }

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 40px;
}

.wordmark {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.375rem;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
}

a.wordmark:hover { color: var(--leaf-deep); }

.chip {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--leaf);
  color: var(--on-leaf);
  font-family: var(--display);
  font-weight: 600;
  font-size: 1rem;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.chip:hover { background: var(--leaf-deep); }

.menu-wrap { position: relative; }

.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 30;
  min-width: 11.5rem;
  padding: 4px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.menu-item {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--ink);
  text-align: left;
  text-decoration: none;
  font-family: var(--display);
  font-weight: 500;
  font-size: .9375rem;
  cursor: pointer;
}

.menu-item:hover { background: var(--leaf-tint); }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: none;
  color: var(--ink);
  font-family: var(--display);
  font-weight: 600;
  font-size: .9375rem;
  cursor: pointer;
}

.btn:disabled { opacity: .55; cursor: default; }

.btn-primary {
  background: var(--leaf);
  border-color: var(--leaf);
  color: var(--on-leaf);
}

.btn-primary:hover:not(:disabled) {
  background: var(--leaf-deep);
  border-color: var(--leaf-deep);
}

.btn-ghost { border-color: var(--line); }

.btn-ghost:hover:not(:disabled) { background: var(--leaf-tint); }

.btn-small {
  height: 32px;
  padding: 0 12px;
  border-radius: 8px;
  font-size: .8125rem;
}

.btn-wide { width: 100%; }

.btn-danger { color: var(--danger); }

/* ---------- add bar ---------- */

.add-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  gap: 8px;
  background: var(--paper);
  padding: 10px 0 12px;
  margin: 0;
}

.add-bar input {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.add-bar input::placeholder { color: var(--muted); }

/* ---------- password fallback: link toggle, stacked form, dialog ---------- */

.link-btn {
  display: block;
  width: 100%;
  margin-top: 18px;
  padding: 6px;
  background: none;
  border: 0;
  color: var(--muted);
  font: inherit;
  font-size: .875rem;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.link-btn:hover { color: var(--ink); }

.stack-form {
  margin-top: 12px;
  text-align: left;
}

.field-label {
  display: block;
  margin-bottom: 6px;
  font-family: var(--display);
  font-weight: 600;
  font-size: .8125rem;
  color: var(--muted);
}

.stack-form input {
  display: block;
  width: 100%;
  height: 44px;
  margin-bottom: 14px;
  padding: 0 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  font: inherit;
}

.stack-form .meta { margin: -6px 0 14px; }

#password-dialog {
  width: min(24rem, calc(100vw - 32px));
  padding: 24px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
}

#password-dialog::backdrop { background: rgb(0 0 0 / .45); }

.dialog-title {
  margin: 0 0 4px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.125rem;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ---------- list items ---------- */

.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 6px 2px;
  border-bottom: 1px solid var(--line);
}

.item.pending { opacity: .55; }

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

.item-name {
  position: relative;
  align-self: flex-start; /* strike spans the text, not the row */
  max-width: 100%;
  font-size: 1.0625rem;
  overflow-wrap: anywhere;
}

/* the signature moment: an ink line drawn left-to-right across the name */
.item-name::after {
  content: "";
  position: absolute;
  left: -2px;
  right: -2px;
  top: calc(50% - 1px);
  height: 2px;
  border-radius: 1px;
  background: currentColor;
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 240ms cubic-bezier(.25, .6, .3, 1);
  pointer-events: none;
}

.item.checked .item-name::after,
.item.done .item-name::after { transform: scaleX(1); }

.item.done .item-name { color: var(--muted); }

.item-by {
  font-size: .8125rem;
  color: var(--muted);
}

.check {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 28px;
  height: 28px;
  margin: 0;
  border: 2px solid var(--muted);
  border-radius: 50%;
  background: transparent;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease;
}

.check:hover:not(:disabled) { border-color: var(--leaf); }

.check::after {
  content: "";
  width: 11px;
  height: 6px;
  margin-top: -3px;
  border-left: 2.5px solid var(--on-leaf);
  border-bottom: 2.5px solid var(--on-leaf);
  transform: rotate(-45deg);
  opacity: 0;
}

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

.check:checked::after { opacity: 1; }

.check:disabled { cursor: default; }

.item-delete {
  flex: none;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.item-delete:hover:not(:disabled) { color: var(--danger); }

.empty {
  margin: 0;
  padding: 40px 8px;
  text-align: center;
  color: var(--muted);
}

/* ---------- done section ---------- */

.done { margin-top: 8px; }

.done > summary {
  display: flex;
  align-items: center;
  padding: 14px 2px 10px;
  list-style: none;
  cursor: pointer;
  font-family: var(--display);
  font-weight: 600;
  font-size: .9375rem;
  color: var(--muted);
  -webkit-user-select: none;
  user-select: none;
}

.done > summary::-webkit-details-marker { display: none; }

.done > summary::before {
  content: "";
  flex: none;
  width: 0;
  height: 0;
  margin-right: 10px;
  border-left: 6px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 150ms ease;
}

.done[open] > summary::before { transform: rotate(90deg); }

.done-actions {
  display: flex;
  justify-content: flex-end;
  padding: 12px 0 24px;
}

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

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 40;
  max-width: min(92vw, 30rem);
  padding: 10px 16px;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--paper);
  font-size: .875rem;
  text-align: center;
  box-shadow: var(--shadow);
}

/* ---------- auth pages (login / enroll) ---------- */

.auth-main {
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.auth-card {
  width: 100%;
  max-width: 22.5rem;
  padding: 36px 28px 28px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
}

.auth-card .wordmark { display: block; margin: 0 0 4px; }

.tagline {
  margin: 0 0 24px;
  color: var(--muted);
}

.invite-heading {
  margin: 16px 0 8px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.375rem;
}

.form-error {
  min-height: 1.375rem;
  margin: 14px 0 0;
  color: var(--danger);
  font-size: .875rem;
}

/* ---------- admin ---------- */

.page-title {
  margin: 18px 0 12px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.5rem;
}

.user-card {
  margin-bottom: 12px;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.user-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.user-name {
  margin: 0;
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.125rem;
}

.badge {
  padding: 2px 8px;
  border-radius: 999px;
  font-family: var(--display);
  font-weight: 600;
  font-size: .6875rem;
}

.badge-admin {
  background: var(--leaf-tint);
  color: var(--leaf-deep);
}

.badge-disabled {
  border: 1px solid var(--line);
  color: var(--muted);
}

.meta {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: .8125rem;
}

.cred-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
}

.cred {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 0;
}

.cred + .cred { border-top: 1px solid var(--line); }

.invite {
  margin-top: 12px;
  padding: 12px;
  background: var(--leaf-tint);
  border-radius: 8px;
}

.invite-row {
  display: flex;
  gap: 8px;
}

.invite-row .btn { height: 36px; }

.invite-url {
  flex: 1;
  min-width: 0;
  height: 36px;
  padding: 0 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .8125rem;
}

.invite .meta { margin-top: 8px; }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

/* ---------- reduced motion ---------- */

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