/* ==========================================================================
   Winery Cork Rewards - style.css
   Look: venec.mk - white pages, serif headings, bordeaux + brass.

   Sections: 1 tokens - 2 base - 3 shell - 4 sidebar - 5 core components - 6 page heading - 7 home
   - 8 mobile shell - 9 logo - 10 forms - 11 tables + row actions - 12 modal - 13 finance/report widgets
   - 14 filter bar / sub-nav - 15 login, TOTP, error pages - 16 mobile (all pages) - 17 print.
   One small vocabulary of classes is reused on every screen (spec 14b). Brand colours: edit ONLY the
   :root block below.
   ========================================================================== */

/* ---------- 1. Brand tokens ----------
   These are the spec's stand-in palette (Task 14a). I could not read venec.mk's own CSS/logo, so
   to match the site exactly, change ONLY the values in this block - nothing below hard-codes a colour. */
:root {
  --wine:        #5b1a2c;   /* primary: deep bordeaux (sidebar, headings, links) */
  --wine-deep:   #431220;   /* headings, pressed states */
  --wine-soft:   #7a2b40;   /* hover on wine */
  --brass:       #b08a4a;   /* secondary accent: rules, focus ring, active marker */
  --brass-soft:  #dcc79e;   /* brass tint that is readable on wine */

  --paper:       #ffffff;   /* page background (venec.mk is plain white) */
  --linen:       #f8f5f1;   /* barely-warm surface for cards/tiles */
  --line:        #e8e1da;   /* hairlines */
  --cream:       #faf6f0;   /* text on wine */

  --ink:         #2b2422;   /* body text */
  --ink-soft:    #6b5f59;   /* secondary text */

  --ok:          #2f6b4a;
  --warn:        #8f6410;
  --bad:         #9b2226;

  --font-display: "Cormorant Garamond", "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --font-body:    system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --sidebar-w: 248px;
  --radius: 6px;
  --touch: 44px;            /* minimum tappable size (spec 4.1) */
}

/* ---------- 2. Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.55;
}
h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 500;
  color: var(--wine-deep);
  line-height: 1.12;
  margin: 0;
}
h1 { font-size: clamp(2rem, 1.4rem + 2.4vw, 3.1rem); letter-spacing: -0.01em; }
h2 { font-size: 1.55rem; }
h3 { font-size: 1.2rem; }
p  { margin: 0 0 1em; }
a  { color: var(--wine); }
.icon { width: 1.25rem; height: 1.25rem; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

:focus-visible { outline: 3px solid var(--brass); outline-offset: 2px; border-radius: 3px; }

.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 100;
  background: var(--paper); color: var(--wine-deep);
  padding: 10px 14px; border-radius: var(--radius); border: 1px solid var(--line);
}
.skip-link:focus { top: 8px; }

/* ---------- 3. App shell ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}
.main {
  padding: 44px clamp(20px, 4vw, 56px) 72px;
  max-width: 1180px;
  width: 100%;
}

/* ---------- 4. Sidebar ---------- */
.sidebar {
  position: sticky; top: 0;
  height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column;
  background: var(--wine);
  color: var(--cream);
  padding: 28px 14px 18px;
}

.brand {
  display: block;
  text-decoration: none;
  padding: 2px 12px 22px;
  margin-bottom: 14px;
  border-bottom: 1px solid rgba(220, 199, 158, 0.35);   /* brass hairline */
}
.brand-mark {
  display: block;
  font-family: var(--font-display);
  font-size: 2rem; font-weight: 600;
  letter-spacing: 0.24em; text-transform: uppercase;
  color: var(--cream);
  line-height: 1;
}
.brand-sub {
  display: block; margin-top: 8px;
  font-size: 0.8rem; letter-spacing: 0.04em;
  color: var(--brass-soft);
}

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-link {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  min-height: var(--touch);
  padding: 8px 12px;
  border-radius: var(--radius);
  color: rgba(250, 246, 240, 0.86);
  text-decoration: none;
  font-size: 0.97rem;
}
.nav-link:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.nav-link.active {
  background: rgba(255, 255, 255, 0.14);
  color: #fff; font-weight: 600;
}
.nav-link.active::before {            /* brass marker for the current tab */
  content: ""; position: absolute; left: 0; top: 9px; bottom: 9px;
  width: 3px; border-radius: 2px; background: var(--brass-soft);
}
.nav-label {
  margin: 20px 12px 6px;
  font-family: var(--font-display);
  font-size: 1.05rem; font-style: italic;
  color: var(--brass-soft);
}
.nav-label::after {                   /* rule that continues the label across the sidebar */
  content: ""; display: block; margin-top: 6px;
  height: 1px; background: rgba(220, 199, 158, 0.3);
}

.sidebar-foot {
  margin-top: auto;                   /* pinned to the bottom */
  padding: 18px 12px 0;
  display: flex; flex-direction: column; gap: 14px;
  border-top: 1px solid rgba(220, 199, 158, 0.25);
}
.lang-pill {
  display: inline-flex; align-self: flex-start;
  border: 1px solid rgba(250, 246, 240, 0.35);
  border-radius: 999px; overflow: hidden;
}
.lang-pill a {
  min-width: 48px; min-height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  color: rgba(250, 246, 240, 0.8); text-decoration: none;
  font-size: 0.8rem; font-weight: 600; letter-spacing: 0.06em;
}
.lang-pill a.active { background: var(--cream); color: var(--wine-deep); }
.lang-pill a:not(.active):hover { background: rgba(255, 255, 255, 0.1); color: #fff; }

.whoami {
  display: flex; flex-direction: column;
  min-height: var(--touch); justify-content: center;
  color: var(--cream); text-decoration: none; line-height: 1.25;
}
.whoami strong { font-weight: 600; overflow-wrap: anywhere; }
.whoami span { font-size: 0.82rem; color: var(--brass-soft); }
.whoami:hover strong { text-decoration: underline; }

/* Mobile-only chrome: hidden on desktop */
.topbar, .sidebar-backdrop { display: none; }

/* ---------- 5. Shared components (small vocabulary, reused everywhere) ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--touch); padding: 8px 18px;
  font: inherit; font-weight: 600; font-size: 0.95rem;
  color: var(--wine); background: var(--paper);
  border: 1px solid var(--wine); border-radius: var(--radius);
  cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--linen); }
.btn-primary { background: var(--wine); color: var(--cream); }
.btn-primary:hover { background: var(--wine-soft); }
.btn-sm { min-height: var(--touch); padding: 6px 14px; font-size: 0.88rem; }
.btn-onwine { color: var(--cream); background: transparent; border-color: rgba(250, 246, 240, 0.45); width: 100%; }
.btn-onwine:hover { background: rgba(255, 255, 255, 0.1); border-color: var(--cream); }

.flash {
  margin: 0 0 24px; padding: 12px 16px;
  border: 1px solid var(--line); border-left-width: 4px; border-radius: var(--radius);
  background: var(--linen);
}
.flash-success { border-left-color: var(--ok); }
.flash-error   { border-left-color: var(--bad); }

.card { background: var(--linen); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }

.table-wrap {                          /* every data table sits in one of these (spec 4.1, scroll approach) */
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line); border-radius: var(--radius);
}
.table-wrap table { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
.table-wrap th, .table-wrap td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table-wrap th { font-weight: 600; color: var(--wine-deep); background: var(--linen); }
.table-wrap tr:last-child td { border-bottom: 0; }

.chip {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 0.8rem; font-weight: 600;
  border: 1px solid var(--line); background: var(--linen); color: var(--ink-soft);
}
.chip-ok   { color: var(--ok);   border-color: currentColor; background: #eef6f1; }
.chip-warn { color: var(--warn); border-color: currentColor; background: #fbf4e4; }
.chip-bad  { color: var(--bad);  border-color: currentColor; background: #fbeced; }

/* ---------- 6. Page heading used by every tab ---------- */
.main > h1 { margin-bottom: 28px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }

/* ---------- 7. Home page (index.ejs) ---------- */
.home-hero { padding: 6px 0 40px; max-width: 46rem; }
.home-hero h1 { margin: 0; }
.home-tagline {
  margin: 14px 0 18px;
  font-family: var(--font-display); font-style: italic;
  font-size: clamp(1.3rem, 1.1rem + 1vw, 1.7rem);
  color: var(--brass);
}
.home-hero .lede { margin: 0; color: var(--ink-soft); max-width: 36rem; }

.tile-section { margin-top: 34px; }
.tile-section > h2 {
  display: flex; align-items: center; gap: 18px;
  margin-bottom: 18px;
}
.tile-section > h2::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.tile-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.tile {
  display: flex; align-items: flex-start; gap: 16px;
  padding: 20px;
  background: var(--linen);
  border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--ink); text-decoration: none;
  min-height: var(--touch);
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.tile:hover { background: var(--paper); border-color: var(--brass); }
.tile-icon {
  flex: none; width: 46px; height: 46px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--wine); color: var(--cream);
}
.tile-icon .icon { width: 1.45rem; height: 1.45rem; }
.tile-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.tile-title { font-family: var(--font-display); font-size: 1.4rem; font-weight: 600; color: var(--wine-deep); line-height: 1.15; }
.tile-desc { font-size: 0.9rem; color: var(--ink-soft); line-height: 1.45; }

/* Admin tiles: same markup, quieter - the daily-work row is the one that should be noticed first. */
.tile-section-admin .tile { padding: 14px 16px; gap: 14px; }
.tile-section-admin .tile-icon { width: 38px; height: 38px; background: transparent; color: var(--wine); border: 1px solid var(--wine); }
.tile-section-admin .tile-icon .icon { width: 1.2rem; height: 1.2rem; }
.tile-section-admin .tile-title { font-size: 1.2rem; }
.tile-section-admin .tile-grid { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }

/* ---------- 8. Mobile shell (spec 4.1) ---------- */
@media (max-width: 760px) {
  .app { display: block; }

  .topbar {
    display: flex; align-items: center; gap: 6px;
    position: sticky; top: 0; z-index: 30;
    height: 56px; padding: 0 8px;
    background: var(--wine); color: var(--cream);
  }
  .sidebar-toggle {
    width: var(--touch); height: var(--touch);
    display: inline-flex; align-items: center; justify-content: center;
    background: transparent; color: var(--cream);
    border: 0; border-radius: var(--radius); cursor: pointer;
  }
  .sidebar-toggle .icon { width: 1.6rem; height: 1.6rem; }
  .sidebar-toggle:hover { background: rgba(255, 255, 255, 0.1); }
  .topbar-brand {
    font-family: var(--font-display); font-size: 1.35rem; font-weight: 600;
    letter-spacing: 0.22em; text-transform: uppercase;
    color: var(--cream); text-decoration: none;
  }

  .sidebar {
    position: fixed; z-index: 50; top: 0; left: 0; bottom: 0;
    width: min(84vw, 300px); height: 100%;
    transform: translateX(-102%);
    transition: transform 0.22s ease;
    box-shadow: none;
  }
  body.sidebar-open .sidebar { transform: none; box-shadow: 8px 0 28px rgba(0, 0, 0, 0.3); }

  .sidebar-backdrop {
    display: block; position: fixed; inset: 0; z-index: 40;
    background: rgba(30, 10, 16, 0.5);
    opacity: 0; visibility: hidden;
    transition: opacity 0.22s ease, visibility 0.22s ease;
  }
  body.sidebar-open .sidebar-backdrop { opacity: 1; visibility: visible; }
  body.sidebar-open { overflow: hidden; }

  .main { padding: 28px 18px 56px; }
  .home-hero { padding-bottom: 24px; }
  .tile-grid, .tile-section-admin .tile-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .sidebar-backdrop, .tile { transition: none; }
}

/* ---------- 9. Logo (public/img/logo.svg = white, for the wine sidebar; logo-wine.svg = bordeaux, for white) ---------- */
[hidden] { display: none !important; }
.brand-logo { display: block; width: 156px; max-width: 100%; height: auto; }
.brand-sub { margin-top: 10px; }
.topbar-brand { display: inline-flex; align-items: center; min-height: var(--touch); }
.topbar-logo { display: block; height: 32px; width: auto; }
.auth-brand { display: block; width: 190px; max-width: 70%; margin: 0 auto 22px; }
.auth-brand img { display: block; width: 100%; height: auto; }

/* ---------- 10. Forms ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 14px 20px; margin-bottom: 28px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.page-head h1 { margin: 0; }
.page-lede { margin: 8px 0 0; max-width: 42rem; color: var(--ink-soft); }
.crumb { display: inline-flex; align-items: center; gap: 6px; min-height: var(--touch); margin: -10px 0 6px; font-size: 0.92rem; text-decoration: none; }
.crumb:hover { text-decoration: underline; }

.section { margin-top: 44px; }
.section:first-of-type { margin-top: 0; }
.section > h2 { display: flex; align-items: center; gap: 18px; margin-bottom: 16px; }
.section > h2::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.section-note { margin: -6px 0 16px; color: var(--ink-soft); font-size: 0.93rem; }

.form-card { background: var(--linen); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin-bottom: 8px; }
.form-card > h2, .form-card > h3 { margin-bottom: 16px; }
.form-card.is-editing { border-color: var(--brass); box-shadow: 0 0 0 2px rgba(176, 138, 74, 0.25); }
.form-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.form-grid + .form-grid, .form-grid + .field, .field + .form-grid, .form-block + .form-block { margin-top: 18px; }
.span-all { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field-label { font-weight: 600; font-size: 0.9rem; color: var(--wine-deep); }
.field .req { color: var(--bad); }
.hint { font-size: 0.82rem; color: var(--ink-soft); }
.field input:not([type="checkbox"]):not([type="radio"]), .field select, .field textarea, .input {
  width: 100%; min-height: var(--touch); padding: 9px 12px;
  font: inherit; color: var(--ink); background: #fff;
  border: 1px solid #cdbfb3; border-radius: var(--radius);
}
.field textarea { min-height: 88px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 3px solid var(--brass); outline-offset: 0; border-color: var(--brass); }
.field input[readonly], .field input:disabled, .field select:disabled { background: #f1ece6; color: var(--ink-soft); }
.field .invalid, .field input:user-invalid { border-color: var(--bad); }
.form-block > h3 { margin-bottom: 12px; font-size: 1.1rem; }
.form-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 22px; }

.qty-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.qty-item { display: flex; flex-direction: column; gap: 5px; padding: 12px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.qty-item label { font-weight: 600; font-size: 0.9rem; color: var(--wine-deep); }
.qty-item input { width: 100%; min-height: var(--touch); padding: 8px 10px; font: inherit; text-align: right; border: 1px solid #cdbfb3; border-radius: var(--radius); }
.qty-price { font-size: 0.8rem; color: var(--ink-soft); }

.live-total { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-top: 18px; padding: 14px 18px; background: #fff; border: 1px dashed var(--brass); border-radius: var(--radius); }
.live-total .label { font-weight: 600; color: var(--wine-deep); }
.live-total .amount { font-family: var(--font-display); font-size: 2rem; font-weight: 600; color: var(--wine-deep); line-height: 1; }
.live-total .amount small { font-family: var(--font-body); font-size: 0.9rem; font-weight: 400; color: var(--ink-soft); }
.net-preview { display: flex; flex-wrap: wrap; gap: 6px 22px; margin-top: 14px; padding: 12px 16px; background: #fff; border: 1px dashed var(--brass); border-radius: var(--radius); font-size: 0.95rem; }
.net-preview strong { font-variant-numeric: tabular-nums; }

.check-row { display: flex; align-items: center; gap: 12px; min-height: var(--touch); cursor: pointer; }
.check-row input[type="checkbox"], .check-row input[type="radio"] { width: 22px; height: 22px; margin: 0; flex: none; accent-color: var(--wine); }
.check-group { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 16px 10px; }
.check-group + .check-group { margin-top: 10px; }
.check-group-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-top: 6px; }
.check-group-head strong { font-family: var(--font-display); font-size: 1.15rem; color: var(--wine-deep); }
.check-cols { display: grid; gap: 0 20px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }

.stack-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.stack-form .field { flex: 1 1 220px; }
.inline-form { display: inline; margin: 0; }

.pick-bar { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); align-items: end; }

/* ---------- 11. Tables, row actions, chips, empty states ---------- */
.table-wrap + .table-wrap { margin-top: 18px; }
.table-wrap table caption { text-align: left; padding: 12px 14px; font-weight: 600; color: var(--wine-deep); }
.table-wrap td.num, .table-wrap th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap td.wrap { white-space: normal; min-width: 200px; }
.table-wrap tbody tr:hover { background: #fdfbf8; }
.table-wrap tfoot td, .table-wrap tr.subtotal td { font-weight: 600; background: var(--linen); }
.table-wrap tr.grand td { font-weight: 700; background: #efe6dc; color: var(--wine-deep); }
.table-wrap tr.is-editing td { background: #fbf4e4; }
.row-sub { display: block; font-size: 0.82rem; color: var(--ink-soft); }
.amount-neg { color: var(--bad); }
.amount-pos { color: var(--ok); }

.row-actions { display: flex; align-items: center; justify-content: flex-end; gap: 2px; }
.icon-btn { width: var(--touch); height: var(--touch); display: inline-flex; align-items: center; justify-content: center; padding: 0; color: var(--wine); background: transparent; border: 1px solid transparent; border-radius: var(--radius); cursor: pointer; text-decoration: none; }
.icon-btn:hover { background: #fff; border-color: var(--line); }
.icon-btn-danger { color: var(--bad); }
.icon-btn[aria-disabled="true"], .icon-btn:disabled { opacity: 0.3; cursor: not-allowed; pointer-events: none; }
.countdown { min-width: 2.6em; text-align: right; font-size: 0.8rem; color: var(--warn); font-variant-numeric: tabular-nums; }

.chip-muted { color: var(--ink-soft); }
.chip .icon { width: 0.85rem; height: 0.85rem; vertical-align: -1px; margin-right: 2px; }
.chip-wine { color: var(--cream); background: var(--wine); border-color: var(--wine); }

.empty { padding: 34px 20px; text-align: center; color: var(--ink-soft); background: var(--paper); border: 1px dashed #d5c9be; border-radius: var(--radius); }
.empty strong { display: block; margin-bottom: 4px; font-family: var(--font-display); font-size: 1.25rem; font-weight: 500; color: var(--wine-deep); }

.item-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.item-list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 4px 6px 4px 14px; min-height: 52px; border-bottom: 1px solid var(--line); }
.item-list li:last-child { border-bottom: 0; }
.item-list .name { overflow-wrap: anywhere; }
.item-list form.rename { display: flex; flex: 1; gap: 8px; align-items: center; }
.item-list form.rename input { flex: 1; min-width: 0; min-height: var(--touch); padding: 6px 10px; font: inherit; border: 1px solid #cdbfb3; border-radius: var(--radius); }

.two-col { display: grid; gap: 24px; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }

/* ---------- 12. Modal (native <dialog>; backdrop pattern from the reference console) ---------- */
dialog.modal { width: min(92vw, 480px); padding: 0; color: var(--ink); background: var(--paper); border: 0; border-radius: 8px; box-shadow: 0 24px 70px rgba(30, 10, 16, 0.4); }
dialog.modal::backdrop { background: rgba(30, 10, 16, 0.55); }
.modal-body { padding: 26px 26px 8px; }
.modal-body h2 { margin-bottom: 10px; font-size: 1.5rem; }
.modal-body p { color: var(--ink-soft); }
.modal-warn { padding: 10px 14px; border-left: 4px solid var(--bad); background: #fbeced; border-radius: 0 var(--radius) var(--radius) 0; color: var(--ink); }
.modal-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; padding: 16px 26px 24px; }
.btn-danger { color: #fff; background: var(--bad); border-color: var(--bad); }
.btn-danger:hover { background: #7d1a1e; }

/* ---------- 13. Finance / report widgets ---------- */
.stat-hero { padding: 28px clamp(20px, 3vw, 34px); background: var(--wine); color: var(--cream); border-radius: 8px; border-bottom: 4px solid var(--brass); }
.stat-hero .stat-label { font-family: var(--font-display); font-style: italic; font-size: 1.2rem; color: var(--brass-soft); }
.stat-hero .stat-value { margin-top: 6px; font-family: var(--font-display); font-size: clamp(2.4rem, 1.6rem + 3.5vw, 4rem); font-weight: 600; line-height: 1.05; font-variant-numeric: tabular-nums; }
.stat-hero .stat-value small { font-size: 0.4em; font-weight: 400; letter-spacing: 0.08em; color: var(--brass-soft); }
.stat-hero .stat-sub { margin-top: 8px; font-size: 0.9rem; color: rgba(250, 246, 240, 0.8); }
.stat-row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin: 18px 0; }
.stat { padding: 14px 16px; background: var(--linen); border: 1px solid var(--line); border-radius: var(--radius); }
.stat-label { font-size: 0.82rem; color: var(--ink-soft); }
.stat-value { margin-top: 2px; font-family: var(--font-display); font-size: 1.7rem; font-weight: 600; color: var(--wine-deep); font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat-value.is-due { color: var(--bad); }
.stat small { font-family: var(--font-body); font-size: 0.78rem; font-weight: 400; color: var(--ink-soft); }
.tile-grid.hub { margin-top: 26px; }

/* ---------- 14. Filter bar, sub-navigation ---------- */
.filter-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 14px; margin-bottom: 20px; padding: 16px; background: var(--linen); border: 1px solid var(--line); border-radius: var(--radius); }
.filter-bar .field { flex: 1 1 170px; }
.filter-bar .btn { flex: none; }
.subnav { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 24px; }
.subnav a { display: inline-flex; align-items: center; min-height: var(--touch); padding: 6px 16px; color: var(--wine); text-decoration: none; border: 1px solid var(--line); border-radius: 999px; background: var(--paper); font-size: 0.93rem; }
.subnav a:hover { border-color: var(--brass); }
.subnav a.active { color: var(--cream); background: var(--wine); border-color: var(--wine); font-weight: 600; }

/* ---------- 15. Login, TOTP, recovery codes, reauth, error pages ---------- */
body.auth { min-height: 100vh; background: var(--linen); }
.login-container { width: min(100% - 32px, 440px); margin: clamp(20px, 7vh, 72px) auto; padding: 32px clamp(20px, 5vw, 34px) 28px; background: var(--paper); border: 1px solid var(--line); border-top: 4px solid var(--brass); border-radius: 8px; box-shadow: 0 14px 44px rgba(67, 18, 32, 0.09); }
.login-container h2 { margin-bottom: 10px; text-align: center; font-size: 1.9rem; }
.welcome-message { margin: 0 0 20px; text-align: center; color: var(--ink-soft); font-size: 0.95rem; }
.input-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.input-group > .welcome-message { margin-bottom: 8px; }
.input-group label { font-weight: 600; font-size: 0.9rem; color: var(--wine-deep); }
.login-input { width: 100%; min-height: 48px; padding: 10px 14px; font: inherit; color: var(--ink); background: #fff; border: 1px solid #cdbfb3; border-radius: var(--radius); }
.login-input:focus { outline: 3px solid var(--brass); outline-offset: 0; border-color: var(--brass); }
.error-message { margin: 0 0 14px; padding: 10px 14px; color: var(--bad); background: #fbeced; border: 1px solid #e7b9bb; border-radius: var(--radius); font-size: 0.93rem; }
.error-message + br { display: none; }
.login-button, .button.inverted { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 48px; padding: 10px 18px; font: inherit; font-weight: 600; color: var(--cream); background: var(--wine); border: 1px solid var(--wine); border-radius: var(--radius); cursor: pointer; text-decoration: none; }
.login-button:hover, .button.inverted:hover { background: var(--wine-soft); }
.login-container .lang-pill { display: flex; width: max-content; margin: 24px auto 0; border-color: var(--line); }
.login-container .lang-pill a { color: var(--ink-soft); }
.login-container .lang-pill a.active { color: var(--cream); background: var(--wine); }
.login-container .lang-pill a:not(.active):hover { color: var(--wine); background: var(--linen); }

.totp-container { width: min(100% - 32px, 460px); }
.totp-qr-wrapper { margin: 0 0 14px; text-align: center; }
.totp-qr { display: inline-block; width: 100%; max-width: 240px; height: auto; padding: 8px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.totp-hint { margin: 0 0 14px; text-align: center; font-size: 0.88rem; color: var(--ink-soft); }
.totp-hint a { display: inline-flex; align-items: center; min-height: var(--touch); }
.totp-secret { margin: 0 0 20px; padding: 12px; text-align: center; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 1.05rem; letter-spacing: 0.08em; overflow-wrap: anywhere; user-select: all; background: var(--linen); border: 1px solid var(--line); border-radius: var(--radius); }
.totp-digit-container { display: flex; justify-content: center; gap: clamp(5px, 2vw, 10px); }
.totp-digit-input { flex: 1 1 0; min-width: 0; max-width: 56px; height: 56px; padding: 0; text-align: center; font: inherit; font-size: 1.5rem; font-weight: 600; color: var(--wine-deep); background: #fff; border: 1px solid #cdbfb3; border-radius: var(--radius); }
.totp-digit-input:focus { outline: 3px solid var(--brass); outline-offset: 0; border-color: var(--brass); }
.recovery-codes { list-style: none; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 0 0 18px; padding: 16px; background: var(--linen); border: 1px dashed var(--brass); border-radius: var(--radius); }
.recovery-codes li { text-align: center; }
.recovery-codes code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 1rem; letter-spacing: 0.06em; user-select: all; }
.reauth-summary { margin: 0 0 20px; padding: 12px 14px; background: var(--linen); border-left: 4px solid var(--brass); border-radius: 0 var(--radius) var(--radius) 0; font-size: 0.95rem; }
.reauth-summary strong { display: block; color: var(--wine-deep); }

.error-container { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--linen); }
.error-card { width: min(100%, 480px); padding: 34px 28px; text-align: center; background: var(--paper); border: 1px solid var(--line); border-top: 4px solid var(--brass); border-radius: 8px; box-shadow: 0 14px 44px rgba(67, 18, 32, 0.09); }
.error-code { font-family: var(--font-display); font-size: 5.5rem; font-weight: 500; line-height: 1; color: var(--brass-soft); }
.error-title { margin: 6px 0 10px; font-size: 1.9rem; }
.error-blurb { color: var(--ink-soft); }
.error-detail { padding: 10px 14px; text-align: left; font-size: 0.9rem; background: var(--linen); border-radius: var(--radius); }
.error-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 22px; }
.error-btn { display: inline-flex; align-items: center; justify-content: center; min-height: var(--touch); padding: 8px 20px; font: inherit; font-weight: 600; text-decoration: none; border-radius: var(--radius); cursor: pointer; }
.error-btn-primary { color: var(--cream); background: var(--wine); border: 1px solid var(--wine); }
.error-btn-secondary { color: var(--wine); background: var(--paper); border: 1px solid var(--wine); }

/* ---------- 16. Mobile (every page, spec 4.1) ---------- */
@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .topbar-brand { font-size: 0; }               /* the logo image replaces the old text brand */
  .page-head { margin-bottom: 22px; }
  .form-card { padding: 16px; }
  .section { margin-top: 36px; }
}
@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }     /* forms: one column on phones */
  .qty-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-bar .field { flex: 1 1 100%; }
  .filter-bar .btn, .form-actions .btn, .stack-form .btn { flex: 1 1 100%; }
  .stack-form .field { flex-basis: 100%; }
  .live-total .amount { font-size: 1.7rem; }
  .check-cols { grid-template-columns: 1fr; }
  dialog.modal { width: calc(100vw - 24px); }
  .modal-actions .btn { flex: 1 1 100%; }
  .recovery-codes { gap: 6px; padding: 12px; }
  .recovery-codes code { font-size: 0.92rem; }
}

/* ---------- 17. Print (reports use the browser's print-to-PDF, spec Task 10) ---------- */
@media print {
  .sidebar, .topbar, .sidebar-backdrop, .filter-bar, .subnav, .no-print, .skip-link { display: none !important; }
  .app { display: block; }
  .main { max-width: none; padding: 0; }
  .table-wrap { overflow: visible; border-color: #999; }
  .table-wrap th, .table-wrap td { white-space: normal; }
}

