:root {
  /* Brand */
  --saffron:        #d99a05;
  --saffron-strong: #b87900;
  --saffron-soft:   #fff4d6;
  --maroon:         #940f2f;
  --maroon-strong:  #6f0a25;
  --maroon-soft:    #fce8ee;
  --green:          #18733e;
  --green-soft:     #e9f6ee;
  --red:            #b91c2f;
  --red-soft:       #fde8eb;
  --blue:           #245a8f;
  --blue-soft:      #e8f0f8;

  /* Neutrals */
  --bg:        #f5f6f8;
  --surface:   #ffffff;
  --surface-2: #fafbfc;
  --surface-3: #f0f2f5;
  --line:      #e5e7eb;
  --line-2:    #cfd5dd;
  --nav:       #090d12;
  --nav-2:     #111821;
  --nav-line:  rgba(255,255,255,.1);

  /* Text */
  --ink:       #111418;
  --ink-2:     #505a66;
  --ink-3:     #88919e;

  /* Type scale */
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Aptos", "Helvetica Neue", Arial, sans-serif;
  --t-xs:  0.75rem;
  --t-sm:  0.8125rem;
  --t-base: 0.9375rem;
  --t-md:  1.0625rem;
  --t-lg:  1.375rem;
  --t-xl:  1.875rem;

  /* Spacing */
  --s-1: 0.25rem;
  --s-2: 0.5rem;
  --s-3: 0.75rem;
  --s-4: 1rem;
  --s-5: 1.5rem;
  --s-6: 2rem;
  --s-7: 3rem;

  /* Radius + elevation (small steps create card/control hierarchy) */
  --r-sm: 8px;
  --r-md: 10px;
  --r-lg: 12px;
  --r-pill: 999px;
  --shadow-1: 0 1px 2px rgba(17,20,24,.05);
  --shadow-2: 0 8px 24px rgba(17,20,24,.08);
  --shadow-3: 0 18px 48px rgba(17,20,24,.16);

  --tap: 44px;
  --maxw: 1180px;
  --sidebar: 232px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

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

body {
  font-family: var(--font);
  font-size: var(--t-base);
  line-height: 1.5;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255,255,255,.92) 0%, rgba(245,246,248,.98) 42%, var(--bg) 100%),
    var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--saffron-strong); }

::selection { background: var(--saffron-soft); }

/* ---- App shell ---------------------------------------------------------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255,255,255,.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: saturate(1.15) blur(12px);
}
.app-header__inner {
  max-width: var(--maxw);
  margin: 0 auto;
  min-height: 62px;
  padding: 0 var(--s-4);
  display: flex;
  align-items: center;
  gap: var(--s-3);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--s-3);
  text-decoration: none;
  color: var(--ink);
  font-weight: 700;
  letter-spacing: 0;
}
.brand__mark {
  width: 34px; height: 34px;
  flex: 0 0 34px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #171005;
  font-weight: 800;
  font-size: 0.9rem;
  background: linear-gradient(155deg, #ffd66b 0%, var(--saffron) 110%);
  box-shadow: var(--shadow-1);
}
.brand__text { display: flex; flex-direction: column; line-height: 1.05; }
.brand__text b { font-size: var(--t-base); white-space: nowrap; }
.brand__text span { font-size: var(--t-xs); color: var(--ink-3); font-weight: 500; }
/* Phones: the full mandir name wraps the top bar to 4 lines — drop it. */
@media (max-width: 480px) {
  .brand__text span { display: none; }
}
.app-header__spacer { flex: 1; }
.desktop-nav { display: none; }
.desktop-nav__item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  min-height: 40px;
  padding: 0 var(--s-3);
  border-radius: var(--r-sm);
  color: rgba(255,255,255,.72);
  text-decoration: none;
  font-size: var(--t-sm);
  font-weight: 700;
}
.desktop-nav__item svg { width: 18px; height: 18px; }
.desktop-nav__item:hover { color: #fff; background: rgba(255,255,255,.07); }
.desktop-nav__item.is-active {
  color: #fff;
  background: linear-gradient(135deg, var(--maroon) 0%, var(--maroon-strong) 100%);
  box-shadow: 0 8px 20px rgba(148,15,47,.28);
}
.header-link {
  font-size: var(--t-sm);
  font-weight: 600;
  color: var(--ink-2);
  text-decoration: none;
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
}
.header-link:hover { background: var(--surface-2); color: var(--ink); }
.header-user {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  max-width: 180px;
  padding: var(--s-1) var(--s-3);
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  background: var(--surface-2);
  color: var(--ink-2);
  font: inherit;
  font-size: var(--t-sm);
  font-weight: 600;
  cursor: pointer;
}
.header-user:hover { border-color: var(--line-2); color: var(--ink); }
.header-user[hidden] { display: none; }
.header-user__dot {
  width: 8px; height: 8px;
  flex: 0 0 8px;
  border-radius: 50%;
  background: var(--green);
}
.header-user__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: var(--s-6) var(--s-5) var(--s-7);
}

@media (min-width: 860px) {
  .app-header {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar);
    background:
      radial-gradient(110% 64% at 20% 0%, rgba(217,154,5,.18), transparent 48%),
      linear-gradient(180deg, var(--nav) 0%, #0c1118 100%);
    border-right: 1px solid rgba(255,255,255,.08);
    border-bottom: none;
    box-shadow: 14px 0 40px rgba(17,20,24,.08);
  }
  .app-header__inner {
    height: 100%;
    min-height: 100vh;
    padding: var(--s-5) var(--s-4);
    flex-direction: column;
    align-items: stretch;
    gap: var(--s-5);
  }
  .app-header .brand { color: #fff; }
  .app-header .brand__text span { color: rgba(255,255,255,.56); }
  .desktop-nav {
    display: flex;
    flex-direction: column;
    gap: var(--s-1);
  }
  .app-header__spacer { flex: 1; }
  .header-link {
    min-height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255,255,255,.72);
    border: 1px solid var(--nav-line);
    background: rgba(255,255,255,.04);
  }
  .header-link:hover { background: rgba(255,255,255,.08); color: #fff; }
  .header-user {
    justify-content: center;
    max-width: none;
    min-height: 40px;
    background: rgba(255,255,255,.05);
    border-color: var(--nav-line);
    color: rgba(255,255,255,.82);
  }
  .header-user:hover { background: rgba(255,255,255,.1); color: #fff; }
  main {
    margin-left: var(--sidebar);
    padding: var(--s-6) var(--s-6) var(--s-7);
  }
}

/* ---- Headings ----------------------------------------------------------- */
.page-title { font-size: clamp(1.7rem, 2vw, 2.35rem); font-weight: 850; letter-spacing: 0; line-height: 1.08; }
.page-sub   { color: var(--ink-2); margin-top: var(--s-1); font-size: var(--t-base); }
.section-title { font-size: var(--t-md); font-weight: 700; margin: var(--s-5) 0 var(--s-3); }
.eyebrow {
  text-transform: uppercase;
  letter-spacing: .12em;
  font-size: var(--t-xs);
  font-weight: 800;
  color: var(--maroon);
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--s-4);
  margin-bottom: var(--s-5);
}
.page-actions { display: flex; gap: var(--s-2); flex-wrap: wrap; justify-content: flex-end; }
.command-date {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: 0 var(--s-3);
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--r-sm);
  color: var(--ink-2);
  font-size: var(--t-sm);
  font-weight: 700;
}
.command-date svg { width: 16px; height: 16px; color: var(--ink-3); }
@media (max-width: 640px) {
  .page-head { display: block; }
  .page-actions { justify-content: stretch; margin-top: var(--s-4); }
  .page-actions .btn, .page-actions .command-date { flex: 1; }
}

/* ---- Cards (home nav) --------------------------------------------------- */
.nav-grid {
  margin-top: var(--s-5);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--s-4);
}
@media (max-width: 980px) { .nav-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 560px) { .nav-grid { grid-template-columns: 1fr; } }

.nav-card {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  text-decoration: none;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  min-height: 154px;
  box-shadow: var(--shadow-1);
  position: relative;
  overflow: hidden;
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease, background .16s ease;
}
.nav-card::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 3px;
  background: var(--line);
}
.nav-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); border-color: var(--line-2); background: #fff; }
.nav-card:active { transform: translateY(0); }
.nav-card__icon {
  width: 42px; height: 42px;
  border-radius: var(--r-sm);
  display: grid; place-items: center;
  color: #fff;
}
.nav-card__icon svg { width: 22px; height: 22px; }
.nav-card h2 { font-size: var(--t-md); font-weight: 800; line-height: 1.2; }
.nav-card p  { color: var(--ink-2); font-size: var(--t-sm); max-width: 28ch; }
.nav-card--scan,
.nav-card--in,
.nav-card--out { min-height: 210px; justify-content: space-between; }
.nav-card--scan { background: linear-gradient(135deg, #fff9e8 0%, #fff 64%); border-color: #f0cf7b; }
.nav-card--in { background: linear-gradient(135deg, #f1fbf4 0%, #fff 64%); border-color: #ccebd7; }
.nav-card--out { background: linear-gradient(135deg, #fff3f4 0%, #fff 64%); border-color: #f3c8cf; }
.nav-card--scan::after { background: var(--saffron); }
.nav-card--in::after { background: var(--green); }
.nav-card--out::after { background: var(--red); }
.nav-card--data::after,
.nav-card--reports::after,
.nav-card--verify::after,
.nav-card--ai::after,
.nav-card--insights::after,
.nav-card--qr::after { background: var(--maroon); opacity: .65; }
.nav-card--in  .nav-card__icon { background: linear-gradient(150deg, var(--green) 0%, #11572d 120%); }
.nav-card--out .nav-card__icon { background: linear-gradient(150deg, var(--red) 0%, #7f1020 120%); }
.nav-card--data .nav-card__icon { background: linear-gradient(150deg, #2b3440 0%, #111418 120%); }
.nav-card--reports .nav-card__icon { background: linear-gradient(150deg, #475569 0%, #1f2937 120%); }
.nav-card--verify .nav-card__icon { background: linear-gradient(150deg, var(--green) 0%, #14532d 120%); }
.nav-card--ai  .nav-card__icon { background: linear-gradient(150deg, var(--blue) 0%, #173a5d 120%); }
.nav-card--insights .nav-card__icon { background: linear-gradient(150deg, var(--saffron) 0%, #8a5e0f 120%); color: #14100a; }
.nav-card--scan .nav-card__icon { background: linear-gradient(150deg, var(--saffron) 0%, var(--maroon) 130%); }
.nav-card--qr .nav-card__icon { background: linear-gradient(150deg, #0f766e 0%, #134e4a 120%); }

.command-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: var(--s-5);
  align-items: start;
}
.command-main { min-width: 0; }
.command-rail { display: grid; gap: var(--s-4); }
.command-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  padding: var(--s-4);
}
.command-panel h2 {
  font-size: var(--t-base);
  font-weight: 850;
  margin-bottom: var(--s-3);
}
.activity-list { list-style: none; display: grid; gap: var(--s-3); }
.activity-list li {
  display: grid;
  grid-template-columns: 10px 1fr;
  gap: var(--s-2);
  color: var(--ink-2);
  font-size: var(--t-sm);
}
.activity-dot { width: 7px; height: 7px; border-radius: 50%; margin-top: 7px; background: var(--green); }
.activity-dot.warn { background: var(--saffron); }
.activity-dot.danger { background: var(--red); }
.activity-list b { display: block; color: var(--ink); font-size: var(--t-sm); }
.home-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--s-3);
  margin: var(--s-5) 0;
}
.summary-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  padding: var(--s-4);
  min-height: 100px;
}
.summary-card span { color: var(--ink-3); font-size: var(--t-xs); font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.summary-card b { display: block; margin-top: var(--s-2); font-size: 1.35rem; line-height: 1; }
.summary-card b.is-warn { color: var(--red); }
.summary-card small { display: block; color: var(--ink-2); margin-top: var(--s-2); font-size: var(--t-xs); }
@media (max-width: 1120px) {
  .command-layout { grid-template-columns: 1fr; }
  .command-rail { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .home-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .command-rail { grid-template-columns: 1fr; }
}
@media (max-width: 460px) {
  .home-summary { grid-template-columns: 1fr; }
}

/* ---- Buttons ------------------------------------------------------------ */
.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: var(--tap);
  padding: 0 var(--s-5);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  font: inherit;
  font-weight: 700;
  font-size: var(--t-base);
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  transition: background .14s ease, transform .08s ease, box-shadow .14s ease, opacity .14s ease;
  user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn--block { width: 100%; }
.btn--primary { background: var(--maroon); color: #fff; box-shadow: 0 8px 18px rgba(148,15,47,.2); }
.btn--primary:hover:not(:disabled) { background: var(--maroon-strong); }
.btn--secondary { background: var(--surface); color: var(--ink); border-color: var(--line-2); }
.btn--secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn--ghost { background: transparent; color: var(--ink-2); }
.btn--ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
.btn--danger { background: transparent; color: var(--red); border-color: var(--red-soft); }
.btn--danger:hover:not(:disabled) { background: var(--red-soft); }
.btn--sm { min-height: 36px; padding: 0 var(--s-3); font-size: var(--t-sm); border-radius: var(--r-sm); }

.btn-row { display: flex; gap: var(--s-3); margin-top: var(--s-4); }
.btn-row .btn { flex: 1; }
.btn-row--wrap { flex-wrap: wrap; }
.btn-row--wrap .btn { flex: 1 1 30%; min-width: 120px; }

/* ---- Capture: multi-photo tray + review radios -------------------------- */
.capture-actions { display: flex; gap: var(--s-3); margin-top: var(--s-3); }
.capture-pick { display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2); flex: 1; cursor: pointer; }
.capture-pick svg { width: 18px; height: 18px; }
@media (max-width: 480px) { .capture-actions { flex-direction: column; } }
.capture-hint { text-align: center; margin-top: var(--s-2); font-size: var(--t-sm); }
.photo-strip { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-top: var(--s-3); }
.photo-thumb { position: relative; width: 76px; height: 76px; border-radius: var(--r-sm); overflow: hidden; border: 1px solid var(--line); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-thumb__rm {
  position: absolute; top: 2px; right: 2px; width: 22px; height: 22px;
  border: none; border-radius: 50%; background: rgba(17,20,24,.72); color: #fff;
  font-size: 16px; line-height: 1; cursor: pointer; display: grid; place-items: center;
}
.cap-field { display: flex; flex-direction: column; gap: var(--s-1); margin-bottom: var(--s-3); }
.cap-field > label { margin-bottom: 2px; }
.choice-group { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.choice-group button {
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-2);
  font: inherit; font-size: var(--t-sm); font-weight: 600; padding: var(--s-2) var(--s-3);
  border-radius: var(--r-pill); cursor: pointer; min-height: 38px;
}
.choice-group button[aria-pressed="true"] { background: var(--maroon); color: #fff; border-color: var(--maroon); }

/* ---- Forms -------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: var(--s-1); margin-bottom: var(--s-3); }
.field > label, .label {
  font-size: var(--t-xs);
  font-weight: 700;
  letter-spacing: .02em;
  color: var(--ink-2);
  text-transform: uppercase;
}
.input, .select, .textarea {
  width: 100%;
  min-height: var(--tap);
  padding: var(--s-3);
  font: inherit;
  font-size: var(--t-base);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  transition: border-color .14s ease, box-shadow .14s ease;
}
.textarea { min-height: 84px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--maroon);
  box-shadow: 0 0 0 3px var(--maroon-soft);
}
.select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%238a8073' d='M1 1l5 5 5-5'/></svg>");
  background-repeat: no-repeat;
  background-position: right var(--s-3) center;
  padding-right: var(--s-6);
}
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-3); }

/* iOS does not zoom on focus when the control font-size is >= 16px.
   Force every editable text/select control to at least 16px on touch screens. */
@media (max-width: 760px) {
  .input, .select, .textarea, .input--sm, .cell-input,
  .map-row .input, .share-link-row .input,
  input[type="text"], input[type="date"], input[type="password"],
  input[inputmode="decimal"], input[inputmode="numeric"], select, textarea {
    font-size: 16px;
  }
}

/* ---- Panels / cards ----------------------------------------------------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  box-shadow: var(--shadow-1);
}

/* ---- Mode banner (capture) --------------------------------------------- */
.mode-banner {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  border-radius: var(--r-lg);
  padding: var(--s-4);
  margin-bottom: var(--s-5);
  font-weight: 700;
  border: 1px solid transparent;
  box-shadow: var(--shadow-1);
}
.mode-banner .dot { width: 10px; height: 10px; border-radius: var(--r-pill); flex: 0 0 10px; }
.mode-banner small { display: block; font-weight: 500; font-size: var(--t-xs); opacity: .8; }
.mode-banner.incoming { background: linear-gradient(135deg, var(--green-soft) 0%, #fff 100%); color: #14532d; border-color: #cfe6d8; }
.mode-banner.incoming .dot { background: var(--green); }
.mode-banner.outgoing { background: linear-gradient(135deg, var(--red-soft) 0%, #fff 100%); color: var(--red); border-color: #f3c8cf; }
.mode-banner.outgoing .dot { background: var(--red); }

/* ---- Dropzone / capture ------------------------------------------------- */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-7) var(--s-5);
  text-align: center;
  background:
    linear-gradient(180deg, rgba(255,255,255,.88), rgba(255,255,255,.96)),
    repeating-linear-gradient(135deg, rgba(148,15,47,.05) 0, rgba(148,15,47,.05) 1px, transparent 1px, transparent 14px);
  border: 1px dashed var(--line-2);
  border-radius: var(--r-lg);
  cursor: pointer;
  color: var(--ink-2);
  transition: border-color .14s ease, background .14s ease;
}
.dropzone:hover { border-color: var(--maroon); background: #fff; }
.dropzone__icon {
  width: 52px; height: 52px;
  display: grid; place-items: center;
  border-radius: var(--r-sm);
  background: var(--maroon-soft);
  color: var(--maroon);
  margin-bottom: var(--s-1);
}
.dropzone__icon svg { width: 26px; height: 26px; }
.dropzone strong { color: var(--ink); font-size: var(--t-md); }
.dropzone span { font-size: var(--t-sm); }

.preview {
  margin-top: var(--s-4);
  border-radius: var(--r-md);
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-1);
}
.preview img { display: block; width: 100%; max-height: 360px; object-fit: contain; background: var(--surface-2); }

/* ---- Review item cards -------------------------------------------------- */
.item-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--s-4);
  box-shadow: var(--shadow-1);
}
.item-card + .item-card { margin-top: var(--s-3); }
.item-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--s-3);
}
.item-card__num {
  font-size: var(--t-xs);
  font-weight: 800;
  letter-spacing: .06em;
  color: var(--maroon);
  text-transform: uppercase;
}
.icon-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--ink-3);
  width: 34px; height: 34px;
  border-radius: var(--r-sm);
  display: grid; place-items: center;
  cursor: pointer;
  transition: background .14s ease, color .14s ease;
}
.icon-btn:hover { background: var(--red-soft); color: var(--red); }
.icon-btn svg { width: 18px; height: 18px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-3); }
.col-span { grid-column: 1 / -1; }
.mini-label { font-size: var(--t-xs); font-weight: 700; color: var(--ink-3); text-transform: uppercase; }
.input--sm { min-height: 40px; padding: var(--s-2) var(--s-3); font-size: var(--t-base); }

/* ---- Tabs --------------------------------------------------------------- */
.tabs {
  display: flex;
  gap: var(--s-1);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s-1);
  margin-top: var(--s-4);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  /* Subtle right-edge fade hints there are more tabs to scroll to. */
  -webkit-mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 22px), transparent 100%);
  mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 22px), transparent 100%);
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
/* When tabs fit (wide screens) drop the fade so nothing looks cut off. */
@media (min-width: 620px) {
  .tabs { -webkit-mask-image: none; mask-image: none; }
}
.tab {
  flex: 1;
  white-space: nowrap;
  appearance: none;
  border: none;
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-weight: 700;
  font-size: var(--t-sm);
  padding: var(--s-2) var(--s-4);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background .14s ease, color .14s ease, box-shadow .14s ease;
}
.tab[aria-selected="true"] {
  background: var(--maroon);
  color: #fff;
  box-shadow: 0 8px 18px rgba(148,15,47,.18);
}
.tab:focus-visible { outline: 2px solid var(--maroon); outline-offset: 2px; }
@media (max-width: 520px) {
  .tabs { gap: var(--s-1); }
  .tab { flex: 0 0 auto; min-height: var(--tap); padding: var(--s-2) var(--s-4); font-size: var(--t-base); }
}

/* ---- Data toolbar + table ---------------------------------------------- */
.toolbar { display: flex; align-items: center; gap: var(--s-3); margin: var(--s-4) 0; flex-wrap: wrap; }
.toolbar .grow { flex: 1; }
/* Spreadsheet-style search box above the grid. */
.grid-search { width: 100%; margin: 0 0 var(--s-2); }
.grid-search[hidden] { display: none; }
/* On phones the small toolbar buttons must still meet the 44px tap minimum. */
@media (max-width: 600px) {
  .toolbar .btn--sm { min-height: var(--tap); }
}

/* Share is a primary action — give it an obvious link/share affordance. */
.btn--share { gap: var(--s-2); }
.btn--share svg { width: 16px; height: 16px; }

.table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  box-shadow: var(--shadow-1);
}
table.grid { border-collapse: collapse; width: 100%; font-size: var(--t-sm); }
table.grid th, table.grid td {
  padding: var(--s-2) var(--s-3);
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
table.grid thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: var(--t-xs);
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
  z-index: 1;
}
table.grid tbody tr:last-child td { border-bottom: none; }
table.grid tbody tr:hover { background: var(--surface-2); }
.cell-input {
  width: 100%;
  min-width: 90px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 6px;
  padding: var(--s-1) var(--s-2);
  font: inherit;
  font-size: var(--t-sm);
  color: var(--ink);
}
.cell-input:hover { border-color: var(--line); }
.cell-input:focus { outline: none; border-color: var(--maroon); background: var(--surface); box-shadow: 0 0 0 2px var(--maroon-soft); }
.cell-input.saved { animation: flash-save .8s ease; }
@keyframes flash-save { 0% { background: var(--green-soft); } 100% { background: transparent; } }
.cell-num { text-align: right; }
.cell-id { color: var(--ink-3); font-variant-numeric: tabular-nums; }
.row-del {
  appearance: none; border: none; background: transparent;
  color: var(--ink-3); cursor: pointer; padding: var(--s-1) var(--s-2);
  border-radius: 6px;
  display: inline-grid; place-items: center;
  min-width: var(--tap); min-height: var(--tap);
}
.row-del:hover { color: var(--red); background: var(--red-soft); }

.stock-pill {
  display: inline-block;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 2px var(--s-2);
  border-radius: var(--r-pill);
  font-size: var(--t-xs);
}
.stock-pill.pos { background: var(--green-soft); color: #14532d; }
.stock-pill.zero { background: var(--surface-2); color: var(--ink-3); }
.stock-pill.neg { background: var(--red-soft); color: var(--red); }

/* ---- Chat --------------------------------------------------------------- */
.chat-page { display: flex; flex-direction: column; height: calc(100dvh - 62px); }
@media (min-width: 860px) { .chat-page { height: 100dvh; } }
.chat-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--s-5) var(--s-4);
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}
.chat-empty {
  margin: auto;
  text-align: center;
  color: var(--ink-2);
  max-width: 340px;
}
.chat-empty .dropzone__icon { margin: 0 auto var(--s-3); }
.chip-row { display: flex; flex-wrap: wrap; gap: var(--s-2); justify-content: center; margin-top: var(--s-4); }
.chip {
  appearance: none;
  border: 1px solid var(--line-2);
  background: var(--surface);
  color: var(--ink-2);
  font: inherit;
  font-size: var(--t-sm);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-pill);
  cursor: pointer;
}
.chip:hover { border-color: var(--maroon); color: var(--maroon); background: var(--maroon-soft); }
/* Suggestion chips docked above the composer — always reachable. */
.chip-row--dock {
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  justify-content: flex-start;
  margin: 0;
  padding: var(--s-2) var(--s-4);
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.chip-row--dock::-webkit-scrollbar { display: none; }
.chip-row--dock .chip { flex: 0 0 auto; }

.bubble {
  max-width: 84%;
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-lg);
  font-size: var(--t-base);
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
  box-shadow: var(--shadow-1);
}
/* Restored-history container: children lay out as direct flex items of the
   scroll, so restored bubbles align exactly like live ones. */
.chat-history { display: contents; }
/* Markdown inside bot bubbles (chat.js renders model replies safely). */
.bubble .md { white-space: normal; display: grid; gap: var(--s-2); }
.bubble .md p { margin: 0; }
.bubble .md .md-h { font-weight: 800; }
.bubble .md .md-list { margin: 0; padding-left: 1.2em; display: grid; gap: 2px; }
.bubble .md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85em;
  background: var(--surface-3);
  border-radius: 4px;
  padding: 1px 4px;
}
.bubble .md .md-tablewrap { overflow-x: auto; max-width: 100%; }
.bubble .md .md-table {
  border-collapse: collapse;
  font-size: var(--t-sm);
  min-width: 240px;
}
.bubble .md .md-table th,
.bubble .md .md-table td {
  border: 1px solid var(--line);
  padding: var(--s-1) var(--s-2);
  text-align: left;
  white-space: nowrap;
}
.bubble .md .md-table th { background: var(--surface-2); font-weight: 700; }
.bubble .md .md-table td:last-child,
.bubble .md .md-table th:last-child { text-align: right; }
.bubble--err { border-color: var(--red); background: var(--red-soft); display: grid; gap: var(--s-2); }
.bubble--err p { margin: 0; color: var(--ink); }
.typing__note { color: var(--ink-3); font-size: var(--t-xs); align-self: center; margin-left: var(--s-2); }
.bubble.user {
  align-self: flex-end;
  background: var(--maroon);
  color: #fff;
  border-bottom-right-radius: var(--r-sm);
}
.bubble.bot {
  align-self: flex-start;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-bottom-left-radius: var(--r-sm);
}
.typing { align-self: flex-start; display: inline-flex; gap: 5px; padding: var(--s-3) var(--s-4); }
.typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ink-3);
  animation: bounce 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-5px); opacity: 1; } }

.chat-input {
  display: flex;
  gap: var(--s-2);
  align-items: flex-end;
  padding: var(--s-3) var(--s-4) calc(var(--s-3) + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.chat-input textarea {
  flex: 1;
  min-height: var(--tap);
  max-height: 140px;
  resize: none;
  padding: var(--s-3);
  font: inherit;
  font-size: var(--t-base);
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  background: var(--surface-2);
}
.chat-input textarea:focus { outline: none; border-color: var(--maroon); box-shadow: 0 0 0 3px var(--maroon-soft); }
.send-btn {
  flex: 0 0 var(--tap);
  width: var(--tap); height: var(--tap);
  border-radius: var(--r-md);
  border: none;
  background: var(--maroon);
  color: #fff;
  cursor: pointer;
  display: grid; place-items: center;
}
.send-btn:hover:not(:disabled) { background: var(--maroon-strong); }
.send-btn:disabled { opacity: .45; cursor: not-allowed; }
.send-btn svg { width: 20px; height: 20px; }

/* ---- Login -------------------------------------------------------------- */
.login-wrap {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--s-5);
  background:
    radial-gradient(90% 70% at 52% -12%, rgba(148,15,47,.16) 0%, transparent 56%),
    linear-gradient(135deg, #0b1017 0%, #151922 42%, var(--bg) 42.1%, var(--bg) 100%);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s-6) var(--s-5);
  box-shadow: var(--shadow-3);
  text-align: center;
}
.login-card .brand__mark { width: 46px; height: 46px; font-size: 1.25rem; border-radius: 13px; margin: 0 auto var(--s-4); }
.login-card h1 { font-size: var(--t-lg); font-weight: 800; }
.login-card .page-sub { margin-bottom: var(--s-5); }
.login-card .field { text-align: left; }
.clerk-panel {
  margin: var(--s-5) 0;
  display: grid;
  gap: var(--s-3);
}
.clerk-mount {
  min-height: 230px;
  display: grid;
  place-items: center;
}
.clerk-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  color: var(--ink-2);
  font-size: var(--t-sm);
}
.pin-login[hidden],
.clerk-panel[hidden] { display: none; }
.pin-input { text-align: center; letter-spacing: .35em; font-size: var(--t-lg); font-weight: 700; }
.login-foot { margin-top: var(--s-5); font-size: var(--t-sm); color: var(--ink-3); }

/* ---- Auth / sign-in — devotional three.js backdrop ---------------------- */
.auth {
  position: relative;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--s-5);
  overflow: hidden;
  isolation: isolate;
  background: radial-gradient(135% 120% at 50% 4%, #350f1f 0%, #1c0814 42%, #090207 100%);
}
.auth__canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
  pointer-events: none;
}
/* vignette + a maroon glow rising from the base, layered over the canvas */
.auth::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(120% 78% at 50% 44%, transparent 48%, rgba(6,2,5,.62) 100%),
    radial-gradient(95% 55% at 50% 122%, rgba(148,15,47,.30) 0%, transparent 60%);
}
.auth__inner {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 410px;
  display: grid;
  gap: var(--s-4);
  justify-items: center;
  text-align: center;
  animation: authRise .85s cubic-bezier(.2,.75,.2,1) both;
}
@keyframes authRise {
  from { opacity: 0; transform: translateY(16px) scale(.985); }
  to   { opacity: 1; transform: none; }
}
.auth__crest {
  width: 58px; height: 58px;
  border-radius: 17px;
  display: grid; place-items: center;
  font-size: 1.5rem; font-weight: 800; letter-spacing: .01em;
  color: #2a1c02;
  background: linear-gradient(155deg, #ffe39a 0%, #e7a90b 58%, #c98a00 112%);
  box-shadow:
    0 0 0 1px rgba(255,255,255,.28) inset,
    0 10px 30px -6px rgba(217,154,5,.65),
    0 0 58px -4px rgba(217,154,5,.5);
  animation: crestGlow 4.5s ease-in-out infinite;
}
@keyframes crestGlow {
  0%,100% { box-shadow: 0 0 0 1px rgba(255,255,255,.28) inset, 0 10px 30px -6px rgba(217,154,5,.6), 0 0 50px -6px rgba(217,154,5,.42); }
  50%     { box-shadow: 0 0 0 1px rgba(255,255,255,.34) inset, 0 12px 34px -4px rgba(217,154,5,.78), 0 0 80px -2px rgba(217,154,5,.6); }
}
.auth__eyebrow {
  margin-top: calc(var(--s-1) * -1);
  color: #f6c75a;
  font-size: var(--t-xs);
  font-weight: 800;
  letter-spacing: .26em;
  text-transform: uppercase;
  text-shadow: 0 1px 18px rgba(217,154,5,.35);
}
.auth-card {
  width: 100%;
  background: linear-gradient(180deg, rgba(255,255,255,.985) 0%, rgba(255,249,239,.96) 100%);
  border: 1px solid rgba(255,255,255,.65);
  border-radius: 22px;
  padding: var(--s-6) var(--s-5) var(--s-5);
  box-shadow:
    0 1px 0 rgba(255,255,255,.7) inset,
    0 40px 90px -28px rgba(0,0,0,.72),
    0 12px 30px -16px rgba(0,0,0,.5);
  -webkit-backdrop-filter: blur(6px) saturate(1.2);
  backdrop-filter: blur(6px) saturate(1.2);
}
.auth-card h1 {
  font-size: var(--t-lg);
  font-weight: 800;
  letter-spacing: -.01em;
  color: var(--ink);
}
.auth-card .page-sub {
  color: var(--ink-2);
  margin: var(--s-1) 0 0;
  font-size: var(--t-base);
}
.auth-card .field { text-align: left; }
.auth-card .pin-login { margin-top: var(--s-4); display: grid; gap: var(--s-3); }
.auth-card .login-foot { margin-top: var(--s-4); }
.auth__legal {
  z-index: 2;
  color: rgba(255,255,255,.5);
  font-size: var(--t-xs);
  letter-spacing: .02em;
}
.auth__legal b { color: rgba(255,255,255,.74); font-weight: 600; }

/* Blend Clerk's mounted widget into the card: strip its nested-card chrome
   and hide its internal header so our "Sign in to Kothar" is the only one.
   (Also requested via the Clerk appearance API in login.js; these are the
   defensive CSS fallbacks in case class names shift across Clerk versions.) */
.auth-card .clerk-panel { margin: var(--s-4) 0 0; }
.auth-card .clerk-mount { min-height: 200px; }
.clerk-mount .cl-rootBox,
.clerk-mount .cl-cardBox { width: 100% !important; }
.clerk-mount .cl-card,
.clerk-mount .cl-cardBox {
  box-shadow: none !important;
  border: none !important;
  background: transparent !important;
}
.clerk-mount .cl-card { padding: 0 !important; }
.clerk-mount .cl-header { display: none !important; }
.clerk-mount .cl-footer,
.clerk-mount .cl-footerAction { background: transparent !important; }

@media (max-width: 480px) {
  .auth { padding: var(--s-4); }
  .auth-card { padding: var(--s-5) var(--s-4); border-radius: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  .auth__inner { animation: none; }
  .auth__crest { animation: none; }
}

/* ---- States / utilities ------------------------------------------------- */
.btn:focus-visible, .chip:focus-visible, .nav-card:focus-visible,
.item-row:focus-visible, .hub-btn:focus-visible, .botnav__item:focus-visible,
.header-user:focus-visible, .linklike:focus-visible, .grid-act:focus-visible {
  outline: 2px solid var(--saffron-strong);
  outline-offset: 2px;
}
.linklike {
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  font-size: var(--t-sm);
  font-weight: 700;
  color: var(--saffron-strong);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.actor-line {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  margin: var(--s-3) 0;
  padding: var(--s-2) var(--s-3);
  border: 1px dashed var(--line-2);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: var(--t-sm);
}
.actor-line b { color: var(--ink); }
.match-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--s-2);
  margin-top: var(--s-1);
  font-size: var(--t-xs);
  color: var(--ink-2);
}
.match-line--ok { color: var(--green); }
.match-line--ok b { color: var(--green); }
.match-line--new { color: var(--saffron-strong); }
.spinner {
  width: 22px; height: 22px;
  border: 3px solid var(--saffron-soft);
  border-top-color: var(--saffron);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.loading-block { display: flex; flex-direction: column; align-items: center; gap: var(--s-3); padding: var(--s-7) 0; color: var(--ink-2); }
.loading-block .spinner { width: 38px; height: 38px; border-width: 4px; }
@keyframes spin { to { transform: rotate(360deg); } }

.success-block { text-align: center; padding: var(--s-6) 0; }
.success-block .check {
  width: 64px; height: 64px;
  margin: 0 auto var(--s-3);
  border-radius: 50%;
  background: var(--green-soft);
  color: var(--green);
  display: grid; place-items: center;
}
.success-block .check svg { width: 34px; height: 34px; }
.success-block h2 { font-size: var(--t-lg); color: #1f5c39; margin-bottom: var(--s-2); }

.empty-state { text-align: center; color: var(--ink-3); padding: var(--s-6) var(--s-4); font-size: var(--t-sm); }
.muted { color: var(--ink-3); }
.error-text { color: var(--red); font-size: var(--t-sm); }
.hide { display: none !important; }
[hidden] { display: none !important; }

/* ---- Toasts ------------------------------------------------------------- */
.toast-host {
  position: fixed;
  left: 50%;
  bottom: calc(var(--s-5) + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  width: calc(100% - var(--s-6));
  max-width: 420px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--ink);
  color: #fff;
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
  font-size: var(--t-sm);
  font-weight: 600;
  box-shadow: var(--shadow-3);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.ok { background: #1f5c39; }
.toast.err { background: var(--red); }

/* ---- Explainer line (plain-language hint above a view) ----------------- */
.explainer {
  display: flex;
  align-items: flex-start;
  gap: var(--s-2);
  background: var(--saffron-soft);
  border: 1px solid #f3dcc4;
  color: var(--maroon);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
  margin: var(--s-4) 0;
  font-size: var(--t-sm);
  line-height: 1.45;
}
.explainer b { color: var(--ink); }

/* ---- Share panel -------------------------------------------------------- */
.share-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-2);
  padding: var(--s-4);
  margin: var(--s-4) 0;
}
.share-panel h3 { font-size: var(--t-base); font-weight: 800; margin-bottom: var(--s-1); }
.share-panel .share-note { color: var(--ink-2); font-size: var(--t-xs); margin-bottom: var(--s-3); }
.share-link-row { display: flex; gap: var(--s-2); align-items: stretch; flex-wrap: wrap; }
.share-link-row .input { flex: 1; min-width: 180px; font-size: var(--t-sm); }
@media (max-width: 480px) { .share-link-row .btn { width: 100%; } }

/* ---- Consolidate banner + numbers -------------------------------------- */
.consolidate-bar {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  flex-wrap: wrap;
  margin: var(--s-4) 0;
}
.consolidate-bar .grow { flex: 1; }
.consolidate-progress {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  color: var(--ink-2);
  font-size: var(--t-sm);
  margin: var(--s-2) 0 var(--s-4);
}
.consolidate-progress .spinner { width: 16px; height: 16px; border-width: 2px; flex: 0 0 16px; }
.num-big {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: var(--t-md);
}
.raw-items {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-1);
  max-width: 220px;
}
.raw-chip {
  display: inline-block;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink-2);
  border-radius: var(--r-pill);
  padding: 2px var(--s-2);
  font-size: var(--t-xs);
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Collapsed: keep the row compact so the On-hand number stays the hero. */
.raw-items.is-collapsed .raw-chip.is-hidden { display: none; }
.raw-chip--more {
  appearance: none;
  cursor: pointer;
  font-weight: 700;
  color: var(--saffron-strong);
  background: var(--saffron-soft);
  border-color: #f3dcc4;
  min-height: 24px;
}
.raw-chip--more:hover { background: #f7e2cb; }
/* Keep the On-hand pill big and unmissable in the consolidated table. */
.consolidated-table td[data-label="On hand"] .stock-pill { font-size: var(--t-base); }

/* ---- Item map editor (grouping corrections) ---------------------------- */
.map-list { display: flex; flex-direction: column; gap: var(--s-2); margin-top: var(--s-3); }
.map-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--s-2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--s-2) var(--s-3);
  box-shadow: var(--shadow-1);
}
.map-row .raw-name { font-weight: 700; font-size: var(--t-sm); word-break: break-word; }
.map-row .arrow { color: var(--ink-3); }
.map-row .input { min-height: 40px; font-size: var(--t-sm); }
@media (max-width: 520px) {
  .map-row { grid-template-columns: 1fr; gap: var(--s-1); }
  .map-row .arrow { display: none; }
  .map-row .raw-name::after { content: " →"; color: var(--ink-3); font-weight: 400; }
}

/* ---- Sheet behavior: a real spreadsheet on every screen ----------------- */
/* The grid scrolls horizontally inside .table-wrap (like Google Sheets) on
   phones instead of folding into cards. The header row (sticky top, set above)
   and the first column (sticky left) stay frozen while you scroll. */
table.grid th:first-child,
table.grid td:first-child {
  position: sticky;
  left: 0;
  background: var(--surface);
  z-index: 1;
}
table.grid tbody tr:hover td:first-child { background: var(--surface-2); }
table.grid thead th:first-child { z-index: 3; background: var(--surface-2); }
@media (max-width: 600px) { .table-wrap { border-radius: var(--r-sm); } }

/* ---- Shared public read-only page -------------------------------------- */
.shared-doc { max-width: var(--maxw); margin: 0 auto; padding: var(--s-5) var(--s-4) var(--s-7); }
.shared-head {
  text-align: center;
  padding: var(--s-5) 0 var(--s-4);
  border-bottom: 1px solid var(--line);
  margin-bottom: var(--s-5);
}
.shared-head .brand__mark { width: 46px; height: 46px; font-size: 1.25rem; border-radius: 13px; margin: 0 auto var(--s-3); }
.shared-head h1 { font-size: var(--t-lg); font-weight: 800; }
.shared-head p { color: var(--ink-2); margin-top: var(--s-1); font-size: var(--t-sm); }
.read-only-note {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  margin-top: var(--s-3);
  background: var(--saffron-soft);
  color: var(--saffron-strong);
  border-radius: var(--r-pill);
  padding: var(--s-1) var(--s-3);
  font-size: var(--t-xs);
  font-weight: 700;
}
.shared-section { margin-bottom: var(--s-6); }
.shared-section h2 { font-size: var(--t-md); font-weight: 800; margin-bottom: var(--s-3); }
.shared-foot { text-align: center; color: var(--ink-3); font-size: var(--t-xs); margin-top: var(--s-6); }

/* ---- Expired / not-found public page ----------------------------------- */
.expired-wrap {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--s-5);
  background:
    radial-gradient(120% 80% at 50% -10%, var(--saffron-soft) 0%, transparent 55%),
    var(--bg);
}
.expired-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s-6) var(--s-5);
  box-shadow: var(--shadow-3);
  text-align: center;
}
.expired-card .brand__mark { width: 46px; height: 46px; font-size: 1.25rem; border-radius: 13px; margin: 0 auto var(--s-4); }
.expired-card h1 { font-size: var(--t-lg); font-weight: 800; margin-bottom: var(--s-2); }

/* ---- Tabulator overrides: make the grid look like the rest of the app ---- */
/* Loaded only on the Data page and the public shared page (Tabulator CDN +
   tabulator_simple theme). These rules recolor it to the cream/saffron palette
   and keep the header looking like the old <thead>. */
.tabulator {
  font-family: var(--font);
  font-size: var(--t-sm);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}
.tabulator .tabulator-header {
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  color: var(--ink-2);
  font-weight: 700;
}
.tabulator .tabulator-header .tabulator-col {
  background: var(--surface-2);
  border-right: 1px solid var(--line);
}
.tabulator .tabulator-header .tabulator-col .tabulator-col-title {
  font-size: var(--t-xs);
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-2);
}
/* Frozen header + first column tint so they read as "stuck". */
.tabulator .tabulator-header .tabulator-frozen,
.tabulator .tabulator-row .tabulator-frozen {
  background: var(--surface);
}
.tabulator .tabulator-header .tabulator-frozen { background: var(--surface-2); }
.tabulator .tabulator-row {
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}
.tabulator .tabulator-row.tabulator-row-even { background: var(--surface); }
.tabulator .tabulator-row:hover,
.tabulator .tabulator-row:hover .tabulator-frozen {
  background: var(--surface-2);
}
.tabulator .tabulator-cell {
  border-right: 1px solid var(--line);
  padding: var(--s-2) var(--s-3);
}
/* Resize handles get a touch of saffron on hover/drag. */
.tabulator .tabulator-col-resize-handle:hover,
.tabulator .tabulator-col-resize-handle.tabulator-col-resize-handle-active {
  background: var(--maroon);
}
/* Cell that is being edited / focused. */
.tabulator .tabulator-cell.tabulator-editing {
  border: 1px solid var(--maroon);
  box-shadow: inset 0 0 0 2px var(--maroon-soft);
  padding: 0;
}
.tabulator .tabulator-cell.tabulator-editing input,
.tabulator .tabulator-cell.tabulator-editing select {
  font-family: var(--font);
  /* >= 16px so iOS Safari does not zoom when an editor opens. */
  font-size: 16px;
  color: var(--ink);
  background: var(--surface);
  border: none;
  padding: var(--s-2) var(--s-3);
}
.tabulator .tabulator-cell.tabulator-editable:hover {
  box-shadow: inset 0 0 0 1px var(--line-2);
}
/* Trash button used in the row-action delete column. */
.tabulator .grid-del {
  appearance: none; border: none; background: transparent;
  color: var(--ink-3); cursor: pointer;
  border-radius: 6px; padding: 4px 6px;
  display: inline-grid; place-items: center;
}
.tabulator .grid-del:hover { color: var(--red); background: var(--red-soft); }
.tabulator .grid-del svg { width: 16px; height: 16px; display: block; }
/* Read-only stock pill inside a Tabulator cell. */
.tabulator .stock-pill { white-space: nowrap; }
/* Placeholder ("no data") text. */
.tabulator .tabulator-placeholder .tabulator-placeholder-contents {
  color: var(--ink-3);
  font-size: var(--t-sm);
  font-weight: 600;
}
/* The grid host gets the same rounded frame the old .table-wrap had. */
.grid-tabulator { margin-top: var(--s-2); }

/* Per-row edit + delete actions (replaces the lone trash column). */
.tabulator .grid-actions { display: inline-flex; gap: 2px; justify-content: center; }
.tabulator .grid-act {
  appearance: none; border: none; background: transparent;
  color: var(--ink-3); cursor: pointer;
  border-radius: 6px; padding: 4px 6px;
  display: inline-grid; place-items: center;
}
.tabulator .grid-act svg { width: 16px; height: 16px; display: block; }
.tabulator .grid-act.edit:hover { color: var(--maroon); background: var(--maroon-soft); }
.tabulator .grid-act.del:hover { color: var(--red); background: var(--red-soft); }

/* One-line muted note under the toolbar (e.g. why Stock has no edit controls). */
.tab-note { margin: var(--s-2) 0 0; font-size: var(--t-sm); color: var(--ink-3); }

/* ---- Bottom-sheet modal (mobile row editing + confirmations) ---- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(8, 13, 18, .58);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; transition: opacity .2s ease;
}
.modal-overlay.show { opacity: 1; }
@media (min-width: 600px) { .modal-overlay { align-items: center; padding: var(--s-4); } }
.sheet {
  background: var(--surface); color: var(--ink);
  width: 100%; max-width: 560px;
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  box-shadow: var(--shadow-3);
  max-height: 92vh; display: flex; flex-direction: column;
  transform: translateY(18px); transition: transform .2s ease;
  padding-bottom: env(safe-area-inset-bottom);
}
@media (min-width: 600px) { .sheet { border-radius: var(--r-lg); } }
.modal-overlay.show .sheet { transform: translateY(0); }
.sheet__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-3); padding: var(--s-4) var(--s-4) var(--s-3);
  border-bottom: 1px solid var(--line);
}
.sheet__title { margin: 0; font-size: var(--t-md); font-weight: 700; }
.sheet__close {
  appearance: none; border: none; background: transparent; cursor: pointer;
  color: var(--ink-3); border-radius: 8px; min-width: var(--tap); min-height: var(--tap);
  display: inline-grid; place-items: center;
}
.sheet__close:hover { background: var(--surface-2); color: var(--ink); }
.sheet__close svg { width: 20px; height: 20px; }
.sheet__body { padding: var(--s-4); overflow-y: auto; }
.sheet__msg { margin: 0; color: var(--ink-2); font-size: var(--t-base); line-height: 1.5; }
.sheet__foot {
  display: flex; gap: var(--s-3); padding: var(--s-3) var(--s-4) var(--s-4);
  border-top: 1px solid var(--line);
}
.sheet__foot .btn { flex: 1; }
.edit-field { margin-bottom: var(--s-3); }
.edit-field label { display: block; font-size: var(--t-sm); font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
.edit-field .input, .edit-field .select { width: 100%; }

/* ---- Persistent bottom navigation (mobile/tablet) ---- */
.botnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 90;
  display: flex; background: rgba(255,255,255,.96);
  border-top: 1px solid var(--line);
  box-shadow: 0 -2px 12px rgba(36, 31, 26, .06);
  padding-bottom: env(safe-area-inset-bottom);
}
.botnav__item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; min-height: 56px; text-decoration: none;
  color: var(--ink-3); font-size: 11px; font-weight: 600;
}
.botnav__item svg { width: 22px; height: 22px; }
.botnav__item.is-active { color: var(--maroon); }
.botnav__item:active { background: var(--surface-2); }
body.has-bottomnav { padding-bottom: calc(58px + env(safe-area-inset-bottom)); }
@media (min-width: 860px) {
  .botnav { display: none; }
  body.has-bottomnav { padding-bottom: 0; }
}

/* ---- Insights dashboard ---- */
#dashRoot {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 34%);
  gap: var(--s-4);
  align-items: start;
}
.kpi-grid {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--s-3);
  margin-top: var(--s-4);
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s-4);
  box-shadow: var(--shadow-1);
  min-height: 118px;
  position: relative;
  overflow: hidden;
}
.kpi-card::after {
  content: "";
  position: absolute;
  inset: auto var(--s-4) 0 var(--s-4);
  height: 3px;
  border-radius: var(--r-pill) var(--r-pill) 0 0;
  background: var(--saffron);
  opacity: .8;
}
.kpi-card__label { font-size: var(--t-xs); font-weight: 800; color: var(--ink-3); text-transform: uppercase; letter-spacing: .08em; }
.kpi-card__value { font-size: 2rem; font-weight: 850; color: var(--ink); margin-top: var(--s-2); line-height: 1.05; }
.kpi-card.warn .kpi-card__value { color: var(--red); }
.kpi-card.warn::after { background: var(--red); }
.chart-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s-4);
  box-shadow: var(--shadow-1);
  margin-top: 0;
}
.chart-card h2 { font-size: var(--t-base); margin: 0 0 var(--s-3); font-weight: 850; letter-spacing: 0; }
.chart-wrap { position: relative; height: 240px; }
.lowstock-list { list-style: none; margin: var(--s-2) 0 0; padding: 0; }
.lowstock-list li { display: flex; justify-content: space-between; gap: var(--s-3); padding: var(--s-2) 0; border-bottom: 1px solid var(--line); font-size: var(--t-base); }
.lowstock-list li:last-child { border-bottom: none; }
.lowstock-list .name { color: var(--ink); font-weight: 600; }
.lowstock-list .name small { color: var(--ink-3); font-weight: 500; }
.lowstock-list .qty { color: var(--red); font-weight: 700; white-space: nowrap; }
.dash-empty { color: var(--ink-3); font-size: var(--t-sm); padding: var(--s-3) 0; }
#dashRoot > .tab-note {
  grid-column: 1 / -1;
  margin: 0;
  padding: var(--s-3) var(--s-4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}
@media (max-width: 980px) {
  #dashRoot { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 520px) {
  .kpi-grid { grid-template-columns: 1fr; }
}

/* ---- QR add/scan/log + labels ---- */
.item-list { margin-top: var(--s-2); display: flex; flex-direction: column; gap: var(--s-2); }
.item-row {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  width: 100%; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4); min-height: var(--tap); color: var(--ink);
}
.item-row:hover { border-color: var(--line-2); background: var(--surface-2); }
.item-row__name { font-weight: 600; }
.item-row__unit { color: var(--ink-3); font-size: var(--t-sm); }
.scan-region { margin-bottom: var(--s-3); }
.scan-region #scanView { width: 100%; border-radius: var(--r-md); overflow: hidden; background: #000; }
.scan-region .btn { margin-top: var(--s-2); width: 100%; }

/* In/Out toggle on the quick-log screen. */
.dir-toggle { display: flex; gap: var(--s-2); margin: var(--s-4) 0; }
.dir-btn {
  flex: 1; min-height: var(--tap); border-radius: var(--r-md); cursor: pointer;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-2);
  font-weight: 700; font-size: var(--t-base);
}
.dir-btn[aria-pressed="true"] { background: var(--maroon-soft); border-color: var(--maroon); color: var(--maroon); }
.log-done { text-align: center; padding: var(--s-6) 0; }
.log-done__check {
  width: 64px; height: 64px; margin: 0 auto var(--s-3); border-radius: 50%;
  background: var(--green-soft); color: var(--green);
  display: grid; place-items: center; font-size: 34px; font-weight: 800;
}

/* Printable QR-label grid. */
.qr-find {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  margin-top: var(--s-4);
}
.qr-find .input { max-width: 420px; }
.qr-find__count { color: var(--ink-3); font-size: var(--t-sm); white-space: nowrap; }
.qr-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: var(--s-3); margin-top: var(--s-4); }
.qr-grid [hidden] { display: none !important; }
.qr-cat {
  grid-column: 1 / -1;
  margin-top: var(--s-3);
  padding-bottom: var(--s-1);
  border-bottom: 2px solid var(--line-2);
  font-weight: 800;
  font-size: var(--t-sm);
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ink-2);
}
.qr-label {
  border: 1px dashed var(--line-2); border-radius: var(--r-sm);
  padding: var(--s-3); text-align: center; background: #fff;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.qr-label__img { width: 150px; height: 150px; }
.qr-label__img svg { display: block; width: 100%; height: 100%; }
.qr-label__code { font-weight: 800; font-size: var(--t-xs); color: #000; letter-spacing: .04em; }
.qr-label__name { font-weight: 700; font-size: var(--t-sm); color: #000; word-break: break-word; }
.qr-label__unit { font-size: var(--t-xs); color: #444; }
/* Live catalog item not yet on the saved sheet. */
.qr-label--new { position: relative; border-color: var(--saffron-strong); border-style: solid; }
.qr-label--new::after {
  content: "NEW";
  position: absolute; top: 6px; right: 6px;
  font-size: 9px; font-weight: 800; letter-spacing: .08em;
  background: var(--saffron-soft); color: var(--saffron-strong);
  border-radius: var(--r-pill); padding: 2px 6px;
}
@media print { .qr-label--new { border-color: #999; } .qr-label--new::after { display: none; } }
.qr-tools { margin: var(--s-4) 0; padding: var(--s-4) 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.qr-tools .field-grid { align-items: end; }
.qr-list-text { min-height: 140px; font-family: var(--font); }
@media print {
  @page { size: letter; margin: .25in; }
  .app-header, .botnav, .no-print { display: none !important; }
  body.has-bottomnav { padding-bottom: 0; }
  main { padding: 0 !important; }
  .qr-grid { grid-template-columns: repeat(3, 1fr); margin: 0; gap: .12in; }
  .qr-cat { border-bottom-color: #999; color: #000; page-break-after: avoid; }
  .qr-label { min-height: 1.9in; border-color: #999; break-inside: avoid; page-break-inside: avoid; padding: .08in; }
  .qr-label__img { width: 1.18in; height: 1.18in; }
  .qr-label__name { font-size: 10px; line-height: 1.15; }
  .qr-label__code, .qr-label__unit { font-size: 8px; line-height: 1.1; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
/* ---- Item hub (QR target) ---- */
.hub-stat { display:flex; align-items:baseline; gap: var(--s-2); margin: var(--s-4) 0 var(--s-2); }
.hub-stat__num { font-size: 2.7rem; font-weight: 850; letter-spacing: 0; }
.hub-stat__unit { color: var(--ink-2); font-weight: 700; }
.hub-meta { color: var(--ink-2); font-size: var(--t-sm); margin-bottom: var(--s-4); }
.hub-actions { display:grid; grid-template-columns: 1fr 1fr; gap: var(--s-3); margin: var(--s-4) 0; }
.hub-btn {
  display:flex; flex-direction:column; align-items:center; gap: var(--s-1);
  min-height: 112px; justify-content:center; border-radius: var(--r-lg);
  font-weight: 800; font-size: var(--t-md); text-decoration:none; color:#fff;
  box-shadow: var(--shadow-2); border: none; cursor: pointer;
}
.hub-btn small { font-weight: 500; font-size: var(--t-xs); opacity:.85; }
.hub-btn--deposit { background: linear-gradient(150deg, var(--green) 0%, #14532d 120%); }
.hub-btn--checkout { background: linear-gradient(150deg, var(--red) 0%, #7f1020 120%); }
.hub-btn:active { transform: translateY(1px); }

/* ---- Lot cards (checkout) ---- */
.lot-card {
  display:block; width:100%; text-align:left; cursor:pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4); margin-bottom: var(--s-2); box-shadow: var(--shadow-1);
}
.lot-card.is-selected { border-color: var(--maroon); box-shadow: 0 0 0 2px var(--maroon-soft); }
.lot-card__row { display:flex; align-items:center; justify-content:space-between; gap: var(--s-3); }
.lot-card__main { font-weight: 700; }
.lot-card__sub { color: var(--ink-2); font-size: var(--t-sm); margin-top: 2px; }
.lot-card__qty { display:flex; align-items:center; gap: var(--s-2); margin-top: var(--s-3); }
.lot-card__qty .input { max-width: 130px; }
.exp-badge {
  display:inline-block; font-size: var(--t-xs); font-weight: 700;
  border-radius: var(--r-pill); padding: 2px var(--s-2); margin-left: var(--s-2);
}
.exp-badge.expired { background: var(--red-soft); color: var(--red); }
.exp-badge.soon { background: var(--saffron-soft); color: var(--saffron-strong); }

/* ---- Sticky checkout summary ---- */
.co-bar {
  /* 58px = the bottom tab bar's body padding (see .has-bottomnav). */
  position: sticky; bottom: calc(58px + env(safe-area-inset-bottom, 0px));
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  box-shadow: var(--shadow-2); padding: var(--s-3) var(--s-4);
  display:flex; align-items:center; gap: var(--s-3); margin-top: var(--s-4);
}
@media (min-width: 860px) { .co-bar { bottom: var(--s-3); } }
.co-bar__total { font-weight: 800; flex: 1; }

/* ---- Segmented source control ---- */
.seg { display:flex; gap: var(--s-1); background: var(--surface-2); border:1px solid var(--line);
  border-radius: var(--r-pill); padding: var(--s-1); }
.seg button {
  flex:1; border:none; background:transparent; color: var(--ink-2); font:inherit; font-weight:700;
  font-size: var(--t-sm); padding: var(--s-2) var(--s-2); border-radius: var(--r-pill); cursor:pointer;
  min-height: 38px;
}
.seg button[aria-pressed="true"] { background: var(--maroon); color:#fff; box-shadow: var(--shadow-1); }

/* ---- Reports ---- */
.report-controls { display:flex; gap: var(--s-3); align-items:center; flex-wrap:wrap; margin: var(--s-4) 0; }
.report-controls .input { max-width: 190px; }
.totals-chips { display:flex; flex-wrap:wrap; gap: var(--s-2); margin: var(--s-2) 0 var(--s-3); }
.totals-chip { background: var(--surface); border:1px solid var(--line); border-radius: var(--r-pill);
  padding: var(--s-1) var(--s-3); font-size: var(--t-sm); }
.totals-chip b { font-variant-numeric: tabular-nums; }
.report-charts { display:grid; grid-template-columns: 1fr; gap: var(--s-4); margin-bottom: var(--s-5); }
@media (min-width: 860px) { .report-charts { grid-template-columns: 1fr 1fr; } }
@media print { .report-controls, .tabs { display:none !important; } }

/* ---- Verify ---- */
.verify-row { display:grid; grid-template-columns: 1fr 110px; gap: var(--s-3); align-items:center;
  padding: var(--s-2) 0; border-bottom: 1px solid var(--line); }
.verify-row .name { font-weight: 600; }
.verify-row .name small { color: var(--ink-3); font-weight: 500; }
.verify-row .expected { color: var(--ink-2); font-size: var(--t-sm); }
.verify-row .input { min-height: 40px; text-align: right; }
.delta-pos { color: var(--green); font-weight: 700; }
.delta-neg { color: var(--red); font-weight: 700; }