@import url('https://fonts.googleapis.com/css2?family=Jost:wght@400;500;600;700&family=Sarabun:wght@400;500;600;700&family=Caveat:wght@500&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── Brand tokens (light theme = default) ──
   Dark theme lives in the :root[data-theme="dark"] block below. Rules:
   · never hardcode a colour in a stylesheet or a template style="" — use a token
   · --ink / --ink-soft / --muted are TEXT roles (they invert in dark mode).
     For a dark-filled chip/button use --ink-fill + --ink-fill-fg instead.
   · pale status surfaces use the --tint-*-bg / -fg / -line trio                */
:root {
  color-scheme: light;

  --dang-red:        #FF3131;
  --dang-red-dark:   #B32222;
  --dang-red-deep:   #801919;   /* fill role only (chevron pattern) */
  --dang-coral:      #FF6F6F;
  --dang-coral-soft: #FFD5D5;
  --ink:             #1A1410;
  --ink-soft:        #3E3632;
  --muted:           #8A7F78;
  --line:            #E6E2DC;
  --line-strong:     #2A2320;
  --paper:           #FFFFFF;
  --paper-warm:      #FBF7F2;
  --concrete:        #F4EFE9;
  --concrete-2:      #EAE3DB;
  --wash:            #FAF7F4;
  --success:         #1F7A4C;
  --warn:            #B86B0B;
  --danger:          var(--dang-red);

  /* high-emphasis dark fill (inverts to a light fill in dark mode) */
  --ink-fill:        #1A1410;
  --ink-fill-soft:   #3E3632;
  --ink-fill-fg:     #FFFFFF;
  /* text/icon colour on a saturated brand fill — stays white in both themes */
  --on-accent:       #FFFFFF;

  /* pale status surfaces */
  --tint-green-bg:   #DCF2E6;
  --tint-green-fg:   #1F7A4C;
  --tint-green-line: #81C784;
  --tint-green-wash: #F1F8E9;
  --tint-amber-bg:   #FBE8CE;
  --tint-amber-fg:   #B86B0B;
  --tint-amber-line: #F0C97A;
  --tint-amber-wash: #FFF8E1;
  --tint-red-bg:     #FDECEA;
  --tint-red-fg:     #B32222;
  --tint-red-line:   #F5C0BC;
  --tint-blue-bg:    #EEF4FF;
  --tint-blue-fg:    #1565C0;
  --tint-blue-line:  #BCCFF5;
  --tint-teal-bg:    #D4ECE9;
  --tint-teal-fg:    #1F5E5A;
  --tint-pink-bg:    #FCE4EC;
  --tint-pink-fg:    #880E4F;
  /* solid accent fills — always carry --on-accent text */
  --gold-fill:       #C0A060;
  --success-fill:    #1F7A4C;
  --warn-fill:       #B86B0B;
  --amber-fill:      #E0A800;
  --amber-fill-dark: #C69500;

  /* categorical chart series — a FIXED slot order, validated for colour-vision
     deficiency against the card surface (--paper) in both themes.
     Rules: assign slots in order and never cycle past 8 (fold the tail into
     "อื่นๆ" or facet instead); the slot follows the entity, never its rank, so
     filtering a series never repaints the survivors. Slots 3/4/5 sit below 3:1
     on the light surface by design — any chart using them ships a table view. */
  --series-1: #2A78D6;   /* blue    */
  --series-2: #EB6834;   /* orange  */
  --series-3: #1BAF7A;   /* aqua    */
  --series-4: #EDA100;   /* yellow  */
  --series-5: #E87BA4;   /* magenta */
  --series-6: #008300;   /* green   */
  --series-7: #4A3AA7;   /* violet  */
  --series-8: #E34948;   /* red     */

  /* sequential ramp (magnitude — heatmap cells). ONE hue, monotone lightness,
     five ordinal steps; light end still clears 2:1 on --paper. Never a rainbow. */
  --seq-1: #86B6EF;
  --seq-2: #5598E7;
  --seq-3: #2A78D6;
  --seq-4: #1C5CAB;
  --seq-5: #0D366B;
  --seq-fg-lo: #0B2440;   /* text on steps 1–2 */
  --seq-fg-hi: #FFFFFF;   /* text on steps 3–5 */

  /* dashboard icon palette (dashcfg.ICON_PALETTE references these by name) */
  --pal-purple-bg:  #F3E5F5;  --pal-purple-fg:  #6A1B9A;
  --pal-dpurple-bg: #EDE7F6;  --pal-dpurple-fg: #4527A0;
  --pal-indigo-bg:  #E8EAF6;  --pal-indigo-fg:  #283593;
  --pal-cyan-bg:    #E0F7FA;  --pal-cyan-fg:    #006064;
  --pal-orange-bg:  #FFF3E0;  --pal-orange-fg:  #E65100;

  /* closed / disabled day surfaces (shop + revenue calendars) */
  --closed-bg:       #E7E1DB;
  --closed-bg-soft:  #EFEAE5;
  --closed-line:     #A89E96;

  --overlay:         rgba(26,20,16,.5);
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238A7F78' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");

  --r-sm:  8px;
  --r-md:  12px;
  --r-lg:  20px;
  --r-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(26,20,16,.06), 0 1px 1px rgba(26,20,16,.04);
  --shadow-md: 0 6px 18px rgba(26,20,16,.08), 0 2px 4px rgba(26,20,16,.05);
  --shadow-lg: 0 20px 40px rgba(128,25,25,.15), 0 4px 8px rgba(26,20,16,.06);
  --shadow-red: 0 10px 24px rgba(255,49,49,.28);
}

/* ── Dark theme ──
   Applied by the boot script in hr/base.html, which always writes an explicit
   data-theme on <html> (resolving "auto" through prefers-color-scheme), so this
   single block is the only place dark values are declared.                    */
:root[data-theme="dark"] {
  color-scheme: dark;

  --dang-red:        #FF4747;
  --dang-red-dark:   #D93A3A;
  --dang-red-deep:   #6E1414;
  --dang-coral:      #FF8A8A;
  --dang-coral-soft: #4A2320;
  --ink:             #F1EBE4;
  --ink-soft:        #C6BDB4;
  --muted:           #8F857C;
  --line:            #332C27;
  --line-strong:     #4C433B;
  --paper:           #1D1916;
  --paper-warm:      #141110;
  --concrete:        #272220;
  --concrete-2:      #332C28;
  --wash:            #221E1B;
  --success:         #4ECB8B;
  --warn:            #E5A648;

  --ink-fill:        #EFE8E1;
  --ink-fill-soft:   #CFC5BB;
  --ink-fill-fg:     #17130F;

  --tint-green-bg:   #17362A;
  --tint-green-fg:   #6FDCA6;
  --tint-green-line: #2E6B4E;
  --tint-green-wash: #1A2E22;
  --tint-amber-bg:   #3A2B14;
  --tint-amber-fg:   #F0BC6A;
  --tint-amber-line: #6B5222;
  --tint-amber-wash: #2E2416;
  --tint-red-bg:     #3D1F1C;
  --tint-red-fg:     #FF9C93;
  --tint-red-line:   #7A3A34;
  --tint-blue-bg:    #16263D;
  --tint-blue-fg:    #8CBBF0;
  --tint-blue-line:  #2F4C74;
  --tint-teal-bg:    #14332F;
  --tint-teal-fg:    #74CFC6;
  --tint-pink-bg:    #3B1A28;
  --tint-pink-fg:    #F09CC0;
  --gold-fill:       #8F6F33;
  --success-fill:    #2E7D52;
  --warn-fill:       #8A5A16;
  --amber-fill:      #8A6A18;
  --amber-fill-dark: #6E5412;

  /* same eight hues, re-stepped for the dark surface (not an automatic flip) */
  --series-1: #3987E5;  --series-2: #D95926;  --series-3: #199E70;  --series-4: #C98500;
  --series-5: #D55181;  --series-6: #008300;  --series-7: #9085E9;  --series-8: #E66767;

  /* sequential ramp re-anchored for the dark surface: the step nearest the
     surface is the DARKEST, and still clears 2:1 against --paper */
  --seq-1: #184F95;
  --seq-2: #256ABF;
  --seq-3: #3987E5;
  --seq-4: #6DA7EC;
  --seq-5: #9EC5F4;
  --seq-fg-lo: #EAF2FD;
  --seq-fg-hi: #0B2440;

  --pal-purple-bg:  #2A1B33;  --pal-purple-fg:  #D3A6E8;
  --pal-dpurple-bg: #241E3D;  --pal-dpurple-fg: #B6ABE8;
  --pal-indigo-bg:  #1B1F3D;  --pal-indigo-fg:  #A8B2E8;
  --pal-cyan-bg:    #123033;  --pal-cyan-fg:    #6FD4DC;
  --pal-orange-bg:  #3A2415;  --pal-orange-fg:  #F5A86B;

  --closed-bg:       #2C2521;
  --closed-bg-soft:  #241F1C;
  --closed-line:     #574C44;

  --overlay:         rgba(0,0,0,.66);
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23A79C92' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");

  --shadow-sm: 0 1px 2px rgba(0,0,0,.5), 0 1px 1px rgba(0,0,0,.4);
  --shadow-md: 0 6px 18px rgba(0,0,0,.55), 0 2px 4px rgba(0,0,0,.4);
  --shadow-lg: 0 20px 40px rgba(0,0,0,.6), 0 4px 8px rgba(0,0,0,.45);
  --shadow-red: 0 10px 24px rgba(255,49,49,.35);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  font-family: 'Sarabun', 'Jost', sans-serif;
  background: var(--paper-warm);
  color: var(--ink);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* ── Utility ── */
.mono { font-family: 'JetBrains Mono', monospace; font-size: 11px; letter-spacing: .04em; }
.hand { font-family: 'Caveat', cursive; font-weight: 500; }
.text-muted { color: var(--muted); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 11px; }
.fw-700 { font-weight: 700; }
.fw-600 { font-weight: 600; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ── Layout ── */
.page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.page-centered {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--paper-warm);
  padding: 24px;
}
.container {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ── Top bar ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-title {
  font-weight: 700;
  font-size: 15px;
}

/* Admin branch switcher */
.branch-switcher {
  height: 28px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-sm);
  padding: 0 6px;
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--ink);
  background: var(--paper);
  cursor: pointer;
  max-width: 130px;
  outline: none;
}
.branch-switcher:focus { border-color: var(--ink); }
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--ink-soft);
  background: none;
  border: none;
  padding: 4px 0;
}
.back-btn:hover { color: var(--ink); }

/* ── Logo ── */
.logo-wrap { display: inline-flex; align-items: flex-start; gap: 2px; }
.logo-dang {
  font-family: 'Jost', sans-serif;
  font-weight: 700;
  font-size: 38px;
  letter-spacing: -.04em;
  color: var(--dang-red);
  line-height: 1;
  position: relative;
  display: inline-block;
}
.logo-dang::before {
  content: '';
  position: absolute;
  left: 10px; top: -16px;
  width: 13px; height: 18px;
  border: 3px solid var(--dang-red);
  border-bottom: none; border-right: none;
  border-top-left-radius: 4px;
  transform: rotate(25deg);
}
.logo-sub {
  font-size: 9px; font-weight: 500;
  letter-spacing: .18em; color: var(--ink);
  text-transform: uppercase;
  text-align: center; margin-top: 2px;
  font-family: 'Jost', sans-serif;
}
.logo-sm {
  font-family: 'Jost', sans-serif;
  font-weight: 700; font-size: 20px;
  letter-spacing: -.04em; color: var(--dang-red);
  position: relative; display: inline-block;
}
.logo-sm::before {
  content: '';
  position: absolute;
  left: 6px; top: -9px;
  width: 8px; height: 10px;
  border: 2px solid var(--dang-red);
  border-bottom: none; border-right: none;
  border-top-left-radius: 3px;
  transform: rotate(25deg);
}

/* ── Chevron pattern ── */
.chevron-bg {
  background-image:
    linear-gradient(135deg, var(--dang-red-deep) 25%, transparent 25%),
    linear-gradient(225deg, var(--dang-red-deep) 25%, transparent 25%),
    linear-gradient(315deg, var(--dang-red-deep) 25%, transparent 25%),
    linear-gradient(45deg,  var(--dang-red-deep) 25%, transparent 25%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 22px;
  border-radius: var(--r-md);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .02em;
  border: none;
  cursor: pointer;
  transition: transform .06s, background .15s, box-shadow .15s;
  width: 100%;
}
.btn:active { transform: translateY(1px); }

.btn-red {
  background: var(--dang-red);
  color: var(--on-accent);
  box-shadow: var(--shadow-red);
}
.btn-red:hover { background: var(--dang-red-dark); }

.btn-dark {
  background: var(--ink-fill);
  color: var(--ink-fill-fg);
  box-shadow: var(--shadow-md);
}
.btn-dark:hover { background: var(--ink-fill-soft); }

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 1.5px solid var(--line);
  box-shadow: none;
  padding: 12px 18px;
}
.btn-ghost:hover { background: var(--concrete); border-color: var(--ink-soft); }

.btn-sm {
  padding: 8px 14px;
  font-size: 13px;
  border-radius: var(--r-sm);
}

/* ── Form inputs ── */
.field { display: flex; flex-direction: column; gap: 6px; }
.label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  letter-spacing: .04em;
  text-transform: uppercase;
}
.input {
  height: 52px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  padding: 0 16px;
  font-size: 15px;
  background: var(--paper);
  color: var(--ink);
  outline: none;
  transition: border-color .15s;
  width: 100%;
}
.input::placeholder { color: var(--muted); }
.input:focus { border-color: var(--dang-red); box-shadow: 0 0 0 3px rgba(255,49,49,.15); }
textarea.input { height: auto; padding: 12px 16px; resize: vertical; }
select.input { appearance: none; background-image: var(--select-arrow); background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }

.check-label {
  display: inline-flex; align-items: center; gap: 10px;
  font-size: 14px; color: var(--ink-soft); cursor: pointer; user-select: none;
}
.check-box {
  width: 20px; height: 20px;
  border: 1.5px solid var(--line);
  border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--paper); flex-shrink: 0;
  transition: background .15s, border-color .15s;
}
input[type="checkbox"]:checked + .check-box,
.check-box.checked {
  background: var(--dang-red);
  border-color: var(--dang-red);
}

/* ── Cards / surfaces ── */
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}
.card-soft {
  background: var(--concrete);
  border-radius: var(--r-lg);
  padding: 18px;
}
.card-red {
  background: linear-gradient(160deg, var(--dang-red) 0%, var(--dang-red-dark) 100%);
  color: var(--on-accent);
  border-radius: var(--r-lg);
  padding: 20px;
  box-shadow: var(--shadow-lg);
}
.card-red .text-muted { color: rgba(255,255,255,.75); }

/* ── Module rows ── */
.mod-row {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: border-color .15s, transform .06s;
  text-decoration: none; color: inherit;
}
.mod-row:hover { border-color: var(--ink-soft); }
.mod-row:active { transform: translateY(1px); }
.mod-icon {
  width: 44px; height: 44px;
  border-radius: var(--r-md);
  background: var(--tint-red-bg);
  color: var(--tint-red-fg);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 18px; flex-shrink: 0;
}
.mod-icon.dark { background: var(--ink-fill); color: var(--ink-fill-fg); }
.mod-icon.admin-icon { background: var(--concrete-2); color: var(--ink-soft); }
.mod-body { flex: 1; min-width: 0; }
.mod-title { font-size: 15px; font-weight: 600; }
.mod-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.mod-chev { color: var(--muted); font-size: 22px; }

/* ── Pills / badges ── */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: var(--r-pill);
  font-size: 11px; font-weight: 600; letter-spacing: .04em;
  background: var(--concrete); color: var(--ink-soft);
}
.pill-red   { background: var(--tint-red-bg); color: var(--tint-red-fg); }
.pill-dark  { background: var(--ink-fill); color: var(--ink-fill-fg); }
.pill-green { background: var(--tint-green-bg); color: var(--tint-green-fg); }
.pill-warn  { background: var(--tint-amber-bg); color: var(--tint-amber-fg); }
.pill-late  { background: var(--tint-amber-bg); color: var(--tint-amber-fg); }

/* ── Avatar ── */
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--ink-fill); color: var(--ink-fill-fg);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 13px; flex-shrink: 0;
}
.avatar-lg { width: 48px; height: 48px; font-size: 16px; }

/* ── Type scale ── */
.h1 { font-size: 28px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.h2 { font-size: 22px; font-weight: 700; letter-spacing: -.01em; line-height: 1.2; }
.h3 { font-size: 17px; font-weight: 600; }
.eyebrow { font-size: 11px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.sub { color: var(--ink-soft); font-size: 14px; }

/* ── Stat cards ── */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 12px;
  text-align: center;
}
.stat-card .stat-value { font-size: 22px; font-weight: 700; margin-top: 4px; }
.stat-card .stat-label { font-size: 11px; color: var(--muted); }

/* ── Live status dot ── */
.dot-live {
  display: inline-block; width: 8px; height: 8px;
  border-radius: 50%; background: var(--dang-red);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,49,49,.5); }
  50%       { box-shadow: 0 0 0 6px rgba(255,49,49,0); }
}

/* ── Bottom nav ── */
.bottom-nav {
  display: flex; justify-content: space-around;
  border-top: 1px solid var(--line);
  padding: 8px 10px 12px;
  background: var(--paper);
  position: sticky; bottom: 0; z-index: 100;
}
.bn-item {
  display: flex; flex-direction: column;
  align-items: center; gap: 4px;
  padding: 6px 10px;
  font-size: 10px; color: var(--muted); font-weight: 500;
  text-decoration: none; border-radius: var(--r-sm);
  transition: color .15s;
}
.bn-item.active { color: var(--dang-red); }
.bn-dot {
  width: 24px; height: 24px; border-radius: 7px;
  background: var(--concrete); display: flex;
  align-items: center; justify-content: center; font-size: 14px;
}
.bn-item.active .bn-dot { background: var(--dang-red); color: var(--on-accent); }

/* ── Divider ── */
.divider { height: 1px; background: var(--line); width: 100%; }

/* ── Scroll area ── */
.scroll-area { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 16px; }

/* ── Section label ── */
.section-label {
  font-size: 12px; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted);
}

/* ── QR display ── */
.qr-wrap {
  /* intentionally always white in both themes — a dark QR field will not scan */
  background: #fff; border-radius: var(--r-lg);
  padding: 20px; display: flex; align-items: center;
  justify-content: center; box-shadow: var(--shadow-md);
}
.qr-wrap img { width: 220px; height: 220px; display: block; }

/* ── Countdown ── */
.countdown-ring {
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 4px;
  background: var(--concrete); border-radius: var(--r-lg);
  padding: 16px; text-align: center;
}
.countdown-num { font-size: 32px; font-weight: 700; letter-spacing: -.02em; }
.countdown-num.urgent { color: var(--dang-red); }

/* ── Scanner ── */
.scanner-bg {
  background: #111;   /* camera viewport — always dark */
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
#qr-reader { width: 100%; }
#qr-reader video { border-radius: 0; }

/* ── Clock record row ── */
.record-row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}
.record-time { font-family: 'JetBrains Mono', monospace; font-size: 13px; width: 50px; color: var(--ink-soft); }

/* ── Success / Error centered ── */
.result-icon {
  width: 80px; height: 80px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 36px;
}
.result-icon.ok { background: var(--tint-green-bg); color: var(--tint-green-fg); }
.result-icon.err { background: var(--tint-red-bg); color: var(--dang-red); }

/* ── Info row in cards ── */
.info-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.info-row:last-child { border-bottom: none; }
.info-key { font-size: 12px; color: var(--muted); }
.info-val { font-size: 14px; font-weight: 600; }

/* ── Table ── */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); }
.tbl th { font-weight: 600; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); background: var(--concrete); }
.tbl tr:hover td { background: var(--wash); }

/* ── Messages (Django) ── */
.messages { list-style: none; }
.messages li {
  padding: 12px 16px; border-radius: var(--r-md);
  margin-bottom: 10px; font-size: 14px;
}
.messages .success { background: var(--tint-green-bg); color: var(--tint-green-fg); }
.messages .error   { background: var(--tint-red-bg); color: var(--tint-red-fg); }
.messages .warning { background: var(--tint-amber-bg); color: var(--tint-amber-fg); }
.messages .info    { background: var(--concrete); color: var(--ink-soft); }

/* ── Dashboard columns (mobile: grouped sections, desktop: grid) ── */
.dash-cols {
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.dash-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.dash-col-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  padding-bottom: 8px;
  border-bottom: 1.5px solid var(--line);
}
.mobile-only { display: block; }

/* ── Responsive ── */
@media (min-width: 640px) {
  .container { max-width: 560px; }
  .stat-grid { gap: 14px; }
}
@media (min-width: 900px) {
  .container { max-width: 760px; }

  /* Centre content column on all scroll-area pages (except the dashboard which self-manages) */
  .scroll-area:not(.dash-scroll) {
    align-items: center;
  }
  .scroll-area:not(.dash-scroll) > * {
    width: 100%;
    max-width: 1100px;
    flex-shrink: 0;
  }

  /* Dashboard: widen and centre scroll area */
  .dash-scroll {
    max-width: 1160px;
    margin: 0 auto;
    padding: 32px 48px;
  }

  /* Hide mobile-only labels, show per-column labels */
  .mobile-only { display: none !important; }
  .dash-col-label {
    display: block;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--muted);
    padding-bottom: 10px;
    border-bottom: 1.5px solid var(--line);
  }

  /* Column containers become grid cells */
  .dash-cols-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    align-items: start;
  }
  .dash-cols-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    align-items: start;
  }
  .dash-cols-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    align-items: start;
  }
  .dash-col {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  /* Slightly larger heading on desktop */
  .dash-scroll .h2 { font-size: 26px; }
}

/* ── Admin summary cards ── */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.summary-card {
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: var(--r-lg);
  padding: 16px 16px 20px;
  position: relative;
  overflow: hidden;
  text-align: left;
  color: inherit;
  text-decoration: none;
  display: block;
}
button.summary-card {
  cursor: pointer;
  width: 100%;
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s, transform .06s;
}
button.summary-card:hover,
a.summary-card:hover { border-color: var(--ink-soft); box-shadow: var(--shadow-md); }
button.summary-card:active,
a.summary-card:active { transform: translateY(1px); }
.summary-card .sc-eyebrow {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
.summary-card .sc-value {
  font-size: 38px;
  font-weight: 700;
  letter-spacing: -.03em;
  line-height: 1;
  margin-bottom: 6px;
}
.summary-card .sc-sub {
  font-size: 12px;
  color: var(--muted);
}
.summary-card .sc-icon {
  position: absolute;
  top: 14px;
  right: 14px;
  font-size: 20px;
  opacity: .45;
}
.summary-card.clickable .sc-chev {
  position: absolute;
  bottom: 12px;
  right: 16px;
  font-size: 18px;
  color: var(--muted);
}
.summary-card-red {
  background: linear-gradient(160deg, var(--dang-red) 0%, var(--dang-red-dark) 100%);
  border-color: transparent;
  color: var(--on-accent);
  box-shadow: var(--shadow-red);
}
.summary-card-red .sc-eyebrow { color: rgba(255,255,255,.7); }
.summary-card-red .sc-sub { color: rgba(255,255,255,.75); }
.summary-card-red .sc-icon { opacity: .35; }
.summary-card-red .sc-chev { color: rgba(255,255,255,.6); }
.summary-card-blue {
  border-color: var(--tint-blue-line);
  background: var(--tint-blue-bg);
}
.summary-card-blue .sc-value { color: var(--tint-blue-fg); }
.summary-card-orange {
  border-color: var(--tint-amber-line);
  background: var(--tint-amber-wash);
}
.summary-card-orange .sc-value { color: var(--tint-amber-fg); }
.summary-card-warn {
  border-color: var(--tint-amber-line);
  background: var(--tint-amber-wash);
}
.summary-card-warn .sc-value { color: var(--warn); }
.summary-card-wide { grid-column: 1 / -1; }
@media (min-width: 900px) {
  .summary-grid { grid-template-columns: repeat(5, 1fr); gap: 14px; }
  .summary-card-wide { grid-column: auto; }
  .summary-card .sc-value { font-size: 36px; }
}

/* ── Dashboard modals ── */
.dash-modal {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 300;
  display: none;
  align-items: flex-end;
  justify-content: center;
  backdrop-filter: blur(2px);
}
.dash-modal.open {
  display: flex;
  animation: dmFadeIn .15s ease;
}
.dash-modal-sheet {
  background: var(--paper);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  width: 100%;
  max-width: 640px;
  max-height: 82vh;
  overflow-y: auto;
  padding: 20px 20px 32px;
  animation: dmSlideUp .2s ease;
}
.dash-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1.5px solid var(--line);
}
.dash-modal-close {
  width: 30px; height: 30px;
  border: 1.5px solid var(--line);
  border-radius: 50%;
  background: none;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--muted);
  flex-shrink: 0;
}
.dash-modal-close:hover { background: var(--concrete); border-color: var(--ink-soft); }
.dm-branch-header {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
  padding: 10px 0 6px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 2px;
}
.dm-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  gap: 12px;
}
.dm-rev-card {
  background: var(--concrete);
  border-radius: var(--r-md);
  padding: 14px;
  margin-bottom: 10px;
}
.dm-rev-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 5px 16px;
  font-size: 13px;
  margin: 8px 0;
}
.dm-rev-line {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.dm-rev-total {
  background: var(--ink-fill);
  color: var(--ink-fill-fg);
  border-radius: var(--r-md);
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 15px;
  margin-top: 4px;
}
@media (min-width: 900px) {
  .dash-modal { align-items: center; padding: 24px; }
  .dash-modal-sheet {
    border-radius: var(--r-lg);
    max-height: 72vh;
  }
}
@keyframes dmFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes dmSlideUp { from { transform: translateY(32px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ── Theme toggle ──
   Injected into .topbar by static/js/theme.js (falls back to a fixed pill on
   pages without a topbar, e.g. the login screen).                            */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px; height: 30px;
  flex-shrink: 0;
  border: 1.5px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--paper);
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1;
  padding: 0;
  transition: background .15s, border-color .15s, color .15s;
}
.theme-toggle:hover { background: var(--concrete); border-color: var(--ink-soft); color: var(--ink); }
.theme-toggle:focus-visible { outline: 2px solid var(--dang-red); outline-offset: 2px; }
.theme-toggle--floating {
  position: fixed;
  top: 14px; right: 14px;
  z-index: 250;
  box-shadow: var(--shadow-sm);
}
/* trailing topbar cell holding the toggle — keeps the page title centred */
.theme-toggle-slot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

/* ── Print ──
   Paper is always white: force the light token set even when dark is active. */
@media print {
  :root, :root[data-theme="dark"] {
    color-scheme: light;
    --dang-red: #FF3131; --dang-red-dark: #B32222; --dang-red-deep: #801919;
    --dang-coral: #FF6F6F; --dang-coral-soft: #FFD5D5;
    --ink: #1A1410; --ink-soft: #3E3632; --muted: #8A7F78;
    --line: #E6E2DC; --line-strong: #2A2320;
    --paper: #FFFFFF; --paper-warm: #FFFFFF;
    --concrete: #F4EFE9; --concrete-2: #EAE3DB; --wash: #FAF7F4;
    --success: #1F7A4C; --warn: #B86B0B;
    --ink-fill: #1A1410; --ink-fill-soft: #3E3632; --ink-fill-fg: #FFFFFF;
    --tint-green-bg: #DCF2E6; --tint-green-fg: #1F7A4C; --tint-green-line: #81C784; --tint-green-wash: #F1F8E9;
    --tint-amber-bg: #FBE8CE; --tint-amber-fg: #B86B0B; --tint-amber-line: #F0C97A; --tint-amber-wash: #FFF8E1;
    --tint-red-bg: #FDECEA; --tint-red-fg: #B32222; --tint-red-line: #F5C0BC;
    --tint-blue-bg: #EEF4FF; --tint-blue-fg: #1565C0; --tint-blue-line: #BCCFF5;
    --tint-teal-bg: #D4ECE9; --tint-teal-fg: #1F5E5A;
    --tint-pink-bg: #FCE4EC; --tint-pink-fg: #880E4F;
    --gold-fill: #C0A060; --success-fill: #1F7A4C; --warn-fill: #B86B0B;
    --amber-fill: #E0A800; --amber-fill-dark: #C69500;
    --series-1: #2A78D6; --series-2: #EB6834; --series-3: #1BAF7A; --series-4: #EDA100;
    --series-5: #E87BA4; --series-6: #008300; --series-7: #4A3AA7; --series-8: #E34948;
    --seq-1: #86B6EF; --seq-2: #5598E7; --seq-3: #2A78D6; --seq-4: #1C5CAB; --seq-5: #0D366B;
    --seq-fg-lo: #0B2440; --seq-fg-hi: #FFFFFF;
    --pal-purple-bg: #F3E5F5; --pal-purple-fg: #6A1B9A;
    --pal-dpurple-bg: #EDE7F6; --pal-dpurple-fg: #4527A0;
    --pal-indigo-bg: #E8EAF6; --pal-indigo-fg: #283593;
    --pal-cyan-bg: #E0F7FA; --pal-cyan-fg: #006064;
    --pal-orange-bg: #FFF3E0; --pal-orange-fg: #E65100;
    --closed-bg: #E7E1DB; --closed-bg-soft: #EFEAE5; --closed-line: #A89E96;
    --overlay: rgba(26,20,16,.5);
    --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238A7F78' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
    --shadow-sm: 0 1px 2px rgba(26,20,16,.06), 0 1px 1px rgba(26,20,16,.04);
    --shadow-md: 0 6px 18px rgba(26,20,16,.08), 0 2px 4px rgba(26,20,16,.05);
    --shadow-lg: 0 20px 40px rgba(128,25,25,.15), 0 4px 8px rgba(26,20,16,.06);
    --shadow-red: 0 10px 24px rgba(255,49,49,.28);
  }
  body { background: #fff; color: #1A1410; }
  .theme-toggle { display: none !important; }
}
