/* ===================================================================
   Club Citrine — Ingredient Tracker  ·  brand-matched utility UI
   =================================================================== */
:root {
  --teal: #2C4A4A; --teal-deep: #213838; --green: #1C6150;
  --citrine: #F39C36; --mint: #78CABF; --black: #140C0C; --offwhite: #F2F2F2;
  --ink: #F4F1EA; --ink-soft: #C9D3D0;
  --card: rgba(244,241,234,.05); --card-2: rgba(244,241,234,.08);
  --line: rgba(244,241,234,.14); --line-gold: rgba(243,156,54,.45);
  --danger: #ff8a6e;
  --radius: 14px; --radius-sm: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --ease: cubic-bezier(.22,.61,.36,1);
}
* { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font); color: var(--ink); line-height: 1.5;
  background:
    radial-gradient(120% 80% at 80% 0%, rgba(28,97,80,.5), transparent 55%),
    linear-gradient(170deg, var(--teal) 0%, var(--teal-deep) 60%, var(--black) 140%);
  background-attachment: fixed; min-height: 100vh; min-height: 100dvh;
  -webkit-font-smoothing: antialiased; padding-bottom: env(safe-area-inset-bottom);
}
:where(button, input, select):focus-visible { outline: 3px solid var(--mint); outline-offset: 2px; }
.skip-link { position: absolute; left: 8px; top: -60px; background: var(--citrine); color: var(--black); padding: .6rem 1rem; border-radius: 0 0 8px 8px; font-weight: 700; z-index: 50; }
.skip-link:focus { top: 0; }

/* ---- Header ---- */
.app-header {
  position: sticky; top: 0; z-index: 20;
  background: rgba(20,12,12,.78); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  padding: calc(env(safe-area-inset-top) + .7rem) clamp(.8rem, 3vw, 1.4rem) .7rem;
}
.app-header__bar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; max-width: 1100px; margin-inline: auto; }
.brand { display: flex; align-items: center; gap: .6rem; }
.brand img { border-radius: 9px; }
.brand__txt { display: flex; flex-direction: column; line-height: 1.1; }
.brand__txt strong { font-size: 1.02rem; letter-spacing: .01em; }
.brand__txt span { font-size: .72rem; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-soft); }
.sync-pill { font-size: .68rem; letter-spacing: .08em; text-transform: uppercase; color: var(--mint); border: 1px solid var(--line); border-radius: 50px; padding: .3rem .7rem; white-space: nowrap; }

.toolbar { display: flex; gap: .55rem; align-items: center; max-width: 1100px; margin: .85rem auto 0; }
.search { position: relative; flex: 1; min-width: 0; }
.search svg { position: absolute; left: .8rem; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--ink-soft); pointer-events: none; }
.search input {
  width: 100%; font: inherit; font-size: 1rem; color: var(--ink);
  background: rgba(20,12,12,.5); border: 1.5px solid var(--line); border-radius: 50px;
  padding: .7rem 1rem .7rem 2.5rem; min-height: 46px;
}
.search input::placeholder { color: rgba(244,241,234,.45); }
.search input:focus { border-color: var(--citrine); outline: none; }

.btn { font: inherit; font-weight: 700; font-size: .9rem; border: 1.5px solid transparent; border-radius: 50px; padding: .6rem 1rem; min-height: 46px; cursor: pointer; white-space: nowrap; transition: transform .2s var(--ease), background .2s var(--ease); }
.btn:active { transform: scale(.96); }
.btn--primary { background: var(--citrine); color: var(--black); }
.btn--ghost { background: transparent; color: var(--ink); border-color: var(--line-gold); }
.btn--danger { background: transparent; color: var(--danger); border-color: rgba(255,138,110,.5); }

/* ---- Category chips ---- */
.chips { display: flex; gap: .5rem; overflow-x: auto; padding: .9rem 0 .2rem; max-width: 1100px; margin-inline: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  font: inherit; font-size: .82rem; font-weight: 600; white-space: nowrap; cursor: pointer;
  background: var(--card); color: var(--ink-soft); border: 1px solid var(--line);
  border-radius: 50px; padding: .5rem .9rem; min-height: 40px; display: inline-flex; align-items: center; gap: .4rem;
}
.chip.is-active { background: var(--citrine); color: var(--black); border-color: var(--citrine); }
.chip__n { font-size: .72rem; opacity: .8; background: rgba(0,0,0,.16); border-radius: 50px; padding: .05rem .4rem; }
.chip.is-active .chip__n { background: rgba(0,0,0,.18); }

/* ---- Item list ---- */
.list {
  max-width: 1100px; margin: 1rem auto; padding: 0 clamp(.8rem, 3vw, 1.4rem) 4rem;
  display: grid; gap: .7rem;
}
@media (min-width: 720px) { .list { grid-template-columns: 1fr 1fr; align-items: start; } }
@media (min-width: 1040px) { .list { grid-template-columns: 1fr 1fr 1fr; } }

.item {
  display: flex; align-items: stretch; gap: .6rem;
  background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--mint);
  border-radius: var(--radius); overflow: hidden;
}
.item.is-low { border-left-color: var(--citrine); }
.item.is-out { border-left-color: var(--danger); }
.item__main { flex: 1; min-width: 0; text-align: left; background: none; border: 0; color: inherit; font: inherit; cursor: pointer; padding: .85rem .9rem; display: flex; flex-direction: column; gap: .35rem; }
.item__main:active { background: var(--card-2); }
.item__name { font-size: 1.04rem; font-weight: 600; overflow-wrap: anywhere; }
.item__meta { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.tag { font-size: .68rem; letter-spacing: .04em; text-transform: uppercase; color: var(--mint); border: 1px solid var(--line-gold); border-radius: 50px; padding: .12rem .55rem; }
.src { font-size: .82rem; color: var(--ink-soft); }

/* ---- Stepper (the McDonald's-style counter) ---- */
.stepper { display: flex; align-items: center; gap: .15rem; padding: .5rem .55rem .5rem 0; }
.step {
  width: 46px; height: 46px; flex: 0 0 auto; border-radius: 50%; cursor: pointer;
  font-size: 1.6rem; line-height: 1; font-weight: 600; font-family: var(--font);
  display: inline-flex; align-items: center; justify-content: center;
  border: 1.5px solid var(--line-gold); background: rgba(243,156,54,.08); color: var(--citrine);
  transition: transform .12s var(--ease), background .2s var(--ease);
}
.step--plus { background: var(--citrine); color: var(--black); border-color: var(--citrine); }
.step:active { transform: scale(.9); }
.step:disabled { opacity: .35; cursor: not-allowed; }
.count { min-width: 2.6ch; text-align: center; font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.is-low .count { color: var(--citrine); }
.is-out .count { color: var(--danger); }

/* ---- Empty state ---- */
.empty { grid-column: 1 / -1; text-align: center; color: var(--ink-soft); padding: 3.5rem 1rem; }
.empty svg { width: 52px; height: 52px; color: var(--citrine); opacity: .7; margin: 0 auto 1rem; }
.empty h2 { font-size: 1.2rem; color: var(--ink); margin-bottom: .4rem; }

/* ---- Dialogs ---- */
.dialog { width: min(94vw, 440px); border: 1px solid var(--line-gold); border-radius: var(--radius); padding: 0; background: var(--teal-deep); color: var(--ink); box-shadow: 0 30px 80px -20px rgba(0,0,0,.7); }
.dialog::backdrop { background: rgba(12,8,8,.65); backdrop-filter: blur(3px); }
.form { padding: clamp(1.2rem, 4vw, 1.7rem); display: flex; flex-direction: column; gap: 1rem; }
.form h2 { font-size: 1.25rem; }
.field { display: flex; flex-direction: column; gap: .4rem; }
.field > span { font-size: .78rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-soft); }
.field em { color: var(--citrine); font-style: normal; }
.field small { text-transform: none; letter-spacing: 0; font-weight: 400; opacity: .8; }
.field input, .field select { font: inherit; font-size: 1rem; color: var(--ink); background: rgba(20,12,12,.5); border: 1.5px solid var(--line); border-radius: var(--radius-sm); padding: .75rem .85rem; min-height: 48px; }
.field input:focus, .field select:focus { border-color: var(--citrine); outline: none; }
.form-err { color: var(--danger); font-size: .85rem; min-height: 1em; margin: -.4rem 0 0; }
.form-actions { display: flex; align-items: center; gap: .5rem; }
.form-actions .spacer { flex: 1; }

/* ---- Header right + sign-out ---- */
.header-right { display: flex; align-items: center; gap: .5rem; }
.signout { font: inherit; font-size: .72rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-soft); background: transparent; border: 1px solid var(--line); border-radius: 50px; padding: .35rem .7rem; min-height: 36px; cursor: pointer; }
.signout:active { transform: scale(.96); }

/* ---- Summary + sort ---- */
.summary { display: flex; align-items: center; justify-content: space-between; gap: 1rem; max-width: 1100px; margin: .6rem auto 0; padding: 0 .1rem; }
.summary__text { font-size: .82rem; color: var(--ink-soft); }
.sort-toggle { font: inherit; font-size: .76rem; font-weight: 600; color: var(--ink-soft); background: var(--card); border: 1px solid var(--line); border-radius: 50px; padding: .4rem .8rem; min-height: 38px; cursor: pointer; white-space: nowrap; }
.sort-toggle[aria-pressed="true"] { color: var(--citrine); border-color: var(--line-gold); }
.chip--alert { border-color: rgba(255,138,110,.5); color: var(--danger); }
.chip--alert.is-active { background: var(--danger); color: var(--black); border-color: var(--danger); }

/* The count is now a button (tap to set exact) */
.count { background: none; border: 0; font-family: var(--font); cursor: pointer; padding: 0 .2rem; }
.count:active { transform: scale(.92); }

/* ---- Sign-in screen ---- */
.auth { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; padding: 1.4rem; padding-top: calc(env(safe-area-inset-top) + 1.4rem); background: linear-gradient(170deg, var(--teal) 0%, var(--teal-deep) 60%, var(--black) 140%); }
.auth__card { width: min(100%, 380px); display: flex; flex-direction: column; gap: .9rem; background: var(--card); border: 1px solid var(--line-gold); border-radius: var(--radius); padding: clamp(1.4rem, 5vw, 2.1rem); text-align: center; box-shadow: 0 30px 80px -20px rgba(0,0,0,.7); }
.auth__card img { border-radius: 12px; margin: 0 auto .2rem; }
.auth__card h1 { font-size: 1.3rem; }
.auth__sub { font-size: .9rem; color: var(--ink-soft); margin-bottom: .4rem; }
.auth__card .field { text-align: left; }
.auth__card .btn { margin-top: .3rem; justify-content: center; }
body.signed-out .app-header, body.signed-out .list { display: none; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } .btn:active, .step:active, .count:active { transform: none; } }
