/* ==========================================================================
   TGTG Bag Manager — Material Design 3 token system
   Font stack uses system fonts (not a web font) so the app renders
   correctly offline on first load, before the service worker has
   cached anything else.
   ========================================================================== */

:root {
  /* Core palette — food-rescue green, kept out of TGTG's own brand colour */
  --md-primary: #2E7D5B;
  --md-primary-container: #B7F0CF;
  --md-on-primary: #FFFFFF;
  --md-on-primary-container: #002114;

  --md-secondary: #4F6354;
  --md-secondary-container: #D2E8D5;
  --md-on-secondary-container: #0C1F14;

  --md-tertiary: #3B5FA6;
  --md-tertiary-container: #D9E2FF;
  --md-on-tertiary-container: #001A41;

  --md-error: #BA1A1A;
  --md-error-container: #FFDAD6;
  --md-on-error: #FFFFFF;
  --md-on-error-container: #410002;

  --md-surface: #FBFDF8;
  --md-surface-dim: #DBE5DD;
  --md-surface-container: #EFF3ED;
  --md-surface-container-high: #E3E8E1;
  --md-surface-variant: #DDE5DB;
  --md-on-surface: #191C1A;
  --md-on-surface-variant: #414942;
  --md-outline: #71796F;
  --md-outline-variant: #C1C9BE;

  /* Category accents */
  --cat-chilled: #3B5FA6;
  --cat-chilled-bg: #D9E2FF;
  --cat-bakery: #8A5B00;
  --cat-bakery-bg: #FFDDAE;
  --cat-impulse: #6B4EA6;
  --cat-impulse-bg: #E9DDFF;

  /* Status accents */
  --status-unassigned: #71796F;
  --status-unassigned-bg: #DDE5DB;
  --status-madeup: #8A5B00;
  --status-madeup-bg: #FFDDAE;
  --status-onpos: #3B5FA6;
  --status-onpos-bg: #D9E2FF;
  --status-collected: #2E7D5B;
  --status-collected-bg: #B7F0CF;
  --status-wasted: #BA1A1A;
  --status-wasted-bg: #FFDAD6;

  --shape-xs: 8px;
  --shape-sm: 12px;
  --shape-md: 16px;
  --shape-lg: 24px;
  --shape-full: 999px;

  --elev-1: 0 1px 2px rgba(0,0,0,.10), 0 1px 3px rgba(0,0,0,.08);
  --elev-2: 0 2px 4px rgba(0,0,0,.10), 0 3px 6px rgba(0,0,0,.08);
  --elev-3: 0 4px 8px rgba(0,0,0,.12), 0 6px 12px rgba(0,0,0,.10);

  --font: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  background: var(--md-surface-dim);
  color: var(--md-on-surface);
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  flex-direction: column;
  overscroll-behavior-y: contain;
}

h1, h2, h3, h4 { margin: 0 0 4px; font-weight: 600; letter-spacing: -0.01em; }
p { margin: 0; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}
button:focus-visible, a:focus-visible, [tabindex]:focus-visible, input:focus-visible {
  outline: 3px solid var(--md-tertiary);
  outline-offset: 2px;
}

/* ---------- App shell ---------- */
#app-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--md-primary);
  color: var(--md-on-primary);
  box-shadow: var(--elev-2);
  position: sticky;
  top: 0;
  z-index: 20;
}
#app-bar .menu-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: var(--shape-full);
  color: var(--md-on-primary);
  font-size: 20px;
}
#app-bar .menu-btn:active { background: rgba(255,255,255,.18); }
#app-bar h1 { font-size: 18px; margin: 0; flex: 1; }
#offline-pill {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: var(--shape-full);
  background: rgba(255,255,255,.18);
}

#main-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 96px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

/* ---------- Nav drawer ---------- */
#nav-scrim {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  z-index: 30; opacity: 0; pointer-events: none; transition: opacity .18s;
}
#nav-scrim.open { opacity: 1; pointer-events: auto; }

#nav-drawer {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: 280px;
  background: var(--md-surface);
  z-index: 31;
  transform: translateX(-100%);
  transition: transform .2s ease;
  box-shadow: var(--elev-3);
  display: flex; flex-direction: column;
  padding: 16px 8px;
  overflow-y: auto;
}
#nav-drawer.open { transform: translateX(0); }
.nav-header { padding: 12px 12px 20px; }
.nav-header .brand { font-size: 20px; font-weight: 700; color: var(--md-primary); }
.nav-header .sub { font-size: 12px; color: var(--md-on-surface-variant); margin-top: 2px; }

.nav-item {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 14px;
  border-radius: var(--shape-full);
  font-size: 14px; font-weight: 500;
  color: var(--md-on-surface-variant);
  margin-bottom: 2px;
}
.nav-item .ic { font-size: 18px; width: 22px; text-align: center; }
.nav-item.active { background: var(--md-secondary-container); color: var(--md-on-secondary-container); }
.nav-item[disabled] { opacity: .4; pointer-events: none; }
.nav-section-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--md-outline); padding: 16px 14px 6px; }

/* ---------- Cards ---------- */
.card {
  background: var(--md-surface-container);
  border-radius: var(--shape-md);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--elev-1);
}
.card-title { font-size: 15px; font-weight: 700; margin-bottom: 8px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 20px;
  border-radius: var(--shape-full);
  font-size: 14px; font-weight: 600;
  min-height: 44px;
}
.btn-filled { background: var(--md-primary); color: var(--md-on-primary); box-shadow: var(--elev-1); }
.btn-filled:active { background: #23684A; }
.btn-tonal { background: var(--md-secondary-container); color: var(--md-on-secondary-container); }
.btn-outline { border: 1px solid var(--md-outline); color: var(--md-primary); }
.btn-error { background: var(--md-error); color: var(--md-on-error); }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn-sm { padding: 8px 14px; min-height: 34px; font-size: 13px; }

.fab {
  position: fixed; right: 20px; bottom: 84px;
  width: 56px; height: 56px; border-radius: var(--shape-lg);
  background: var(--md-primary); color: var(--md-on-primary);
  display: grid; place-items: center; font-size: 24px;
  box-shadow: var(--elev-3); z-index: 15;
}

/* ---------- Bottom nav (quick access) ---------- */
#bottom-nav {
  position: sticky; bottom: 0;
  display: flex;
  background: var(--md-surface-container-high);
  box-shadow: 0 -1px 4px rgba(0,0,0,.10);
  z-index: 20;
}
.bn-item {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px 10px;
  font-size: 11px; font-weight: 500;
  color: var(--md-on-surface-variant);
}
.bn-item .ic { font-size: 20px; }
.bn-item.active { color: var(--md-primary); }

/* ---------- Chips / badges ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600;
  padding: 4px 10px; border-radius: var(--shape-full);
}
.chip-chilled { background: var(--cat-chilled-bg); color: var(--cat-chilled); }
.chip-bakery { background: var(--cat-bakery-bg); color: var(--cat-bakery); }
.chip-impulse { background: var(--cat-impulse-bg); color: var(--cat-impulse); }
.chip-unassigned { background: var(--status-unassigned-bg); color: var(--status-unassigned); }
.chip-madeup { background: var(--status-madeup-bg); color: var(--status-madeup); }
.chip-onpos { background: var(--status-onpos-bg); color: var(--status-onpos); }
.chip-collected { background: var(--status-collected-bg); color: var(--status-collected); }
.chip-wasted { background: var(--status-wasted-bg); color: var(--status-wasted); }

/* ---------- Item row / stepper ---------- */
.item-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--md-outline-variant);
}
.item-row:last-child { border-bottom: none; }
.item-thumb {
  width: 48px; height: 48px; border-radius: var(--shape-sm);
  object-fit: cover; background: var(--md-surface-variant); flex-shrink: 0;
}
.item-info { flex: 1; min-width: 0; }
.item-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-meta { font-size: 12px; color: var(--md-on-surface-variant); margin-top: 2px; }

.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button {
  width: 34px; height: 34px; border-radius: var(--shape-full);
  background: var(--md-surface-variant); font-size: 18px; font-weight: 700;
  display: grid; place-items: center;
}
.stepper button:active { background: var(--md-outline-variant); }
.stepper .count { min-width: 28px; text-align: center; font-size: 15px; font-weight: 700; }
.lock-note { font-size: 11px; color: var(--md-outline); display: flex; align-items: center; gap: 4px; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 6px; margin-bottom: 14px; overflow-x: auto; }
.tab {
  padding: 8px 16px; border-radius: var(--shape-full);
  font-size: 13px; font-weight: 600; white-space: nowrap;
  background: var(--md-surface-container-high); color: var(--md-on-surface-variant);
}
.tab.active { background: var(--md-primary); color: var(--md-on-primary); }

/* ---------- Status banner ---------- */
.banner {
  border-radius: var(--shape-md);
  padding: 14px 16px;
  margin-bottom: 12px;
  display: flex; gap: 12px; align-items: flex-start;
}
.banner-urgent { background: var(--status-wasted-bg); color: var(--md-on-error-container); }
.banner-warn { background: var(--status-madeup-bg); color: #4A2E00; }
.banner-ok { background: var(--status-collected-bg); color: var(--md-on-primary-container); }
.banner .ic { font-size: 20px; margin-top: 1px; }
.banner-title { font-weight: 700; font-size: 14px; }
.banner-body { font-size: 13px; margin-top: 2px; opacity: .9; }

/* ---------- Progress ---------- */
.progress-track {
  height: 8px; border-radius: var(--shape-full);
  background: var(--md-surface-variant); overflow: hidden; margin-top: 6px;
}
.progress-fill { height: 100%; background: var(--md-primary); border-radius: var(--shape-full); transition: width .3s; }

/* ---------- Bag board (kanban) ---------- */
.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.board-col { min-width: 240px; flex: 1; }
.board-col-head { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 8px; display: flex; justify-content: space-between; }
.bag-card {
  background: var(--md-surface-container);
  border-radius: var(--shape-sm);
  padding: 12px; margin-bottom: 10px;
  box-shadow: var(--elev-1);
}
.bag-card .code { font-weight: 800; font-size: 15px; }
.bag-card .meta { font-size: 12px; color: var(--md-on-surface-variant); margin: 4px 0 8px; }
.bag-card .actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--md-on-surface-variant); margin-bottom: 6px; }
.field input, .field select {
  width: 100%; padding: 12px 14px;
  border-radius: var(--shape-sm);
  border: 1px solid var(--md-outline);
  background: var(--md-surface);
  font-size: 14px; color: var(--md-on-surface);
  font-family: inherit;
}
.field .hint { font-size: 11px; color: var(--md-outline); margin-top: 4px; }
.row-split { display: flex; gap: 12px; }
.row-split .field { flex: 1; }

/* ---------- Empty state ---------- */
.empty-state { text-align: center; padding: 48px 16px; color: var(--md-on-surface-variant); }
.empty-state .ic { font-size: 40px; margin-bottom: 10px; }
.empty-state .title { font-weight: 700; color: var(--md-on-surface); margin-bottom: 4px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #2A2E29; color: #fff;
  padding: 12px 20px; border-radius: var(--shape-sm);
  font-size: 13px; z-index: 50; opacity: 0; pointer-events: none;
  transition: all .2s; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Misc ---------- */
.muted { color: var(--md-on-surface-variant); font-size: 13px; }
.section-gap { margin-top: 22px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-box { background: var(--md-surface-container); border-radius: var(--shape-sm); padding: 12px; text-align: center; }
.stat-box .num { font-size: 22px; font-weight: 800; color: var(--md-primary); }
.stat-box .lbl { font-size: 11px; color: var(--md-on-surface-variant); margin-top: 2px; }

@media (max-width: 380px) {
  .board-col { min-width: 200px; }
}
