/* =====================================================================
   STOCK & ROLL ERP — theme
   Palette : Black + Dark Orange + Orange + Yellow + White — the same
             token names (--maroon-*) are kept so every existing rule,
             partial, and inline var() reference across the app keeps
             working untouched; only the underlying hex values changed.
             Matches the Possessif layer's palette (see possessif.css)
             so the whole app now shares one accent language.
   Type    : Fraunces (display, ledger/deed feel) + Inter (UI) +
             JetBrains Mono (every number, so columns align).
   Signature : the "stitch rail" — the workflow drawn as a sewn seam.
   ===================================================================== */

/* ---------- tokens ---------- */
:root {
  --maroon-900: #14110F;  /* black */
  --maroon-800: #1C1208;  /* black, warmed toward orange */
  --maroon-700: #C2410C;  /* dark orange */
  --maroon-600: #F97316;  /* orange */
  --maroon-500: #FB923C;  /* orange, lighter */
  --maroon-400: #FBBF24;  /* yellow */
  --maroon-200: #F6D9B4;  /* soft orange border */
  --maroon-050: #FFF4E8;  /* soft orange wash */

  --indigo:  #37456B;
  --ok:      #1B7A57;
  --ok-bg:   #E7F4EE;
  --warn:    #A96A05;
  --warn-bg: #FCF2E1;
  --danger:  #B32B26;
  --danger-bg:#FBEBEA;

  --white:  #FFFFFF;
  --paper:  #FAF9F7;
  --surface:#FFFFFF;
  --raised: #FFFFFF;
  --ink:    #1C1815;
  --ink-2:  #4A4038;
  --muted:  #7C7268;
  --line:   #EAE1D5;
  --line-2: #F3ECE1;

  --radius:   14px;
  --radius-sm: 9px;
  --radius-lg: 20px;
  --shadow-1: 0 1px 2px rgba(20, 17, 15, .05), 0 1px 3px rgba(20, 17, 15, .06);
  --shadow-2: 0 4px 10px rgba(20, 17, 15, .07), 0 12px 28px rgba(20, 17, 15, .08);
  --shadow-up: 0 -6px 24px rgba(20, 17, 15, .10);

  --sidebar-w: 254px;
  --topbar-h: 62px;
  --tabbar-h: 62px;

  --font-display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

[data-theme="dark"] {
  --white:  #14100C;
  --paper:  #110D0A;
  --surface:#1B1510;
  --raised: #221A13;
  --ink:    #F5EDE2;
  --ink-2:  #D8C9B6;
  --muted:  #A69683;
  --line:   #3A2C1E;
  --line-2: #2E2317;
  --maroon-050: #2A1B10;
  --maroon-200: #4A3319;
  --maroon-600: #FB923C;
  --maroon-700: #F97316;
  --ok-bg:   #14291F;
  --warn-bg: #2B2011;
  --danger-bg:#2E1614;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .5);
  --shadow-2: 0 10px 30px rgba(0, 0, 0, .55);
  --shadow-up: 0 -6px 24px rgba(0, 0, 0, .5);
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; overflow-x: clip; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
  overflow-x: clip;
  max-width: 100vw;
}

a { color: var(--maroon-600); text-decoration: none; }
a:hover { color: var(--maroon-700); text-decoration: underline; }

h1, h2, h3, h4, .display {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -.015em;
  color: var(--ink);
  margin: 0 0 .35em;
}
h1 { font-size: 1.65rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.08rem; }

.num, .money, td.num, th.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

.eyebrow {
  font-size: .68rem; font-weight: 600; letter-spacing: .13em;
  text-transform: uppercase; color: var(--muted);
}

::selection { background: var(--maroon-200); color: var(--maroon-900); }

:focus-visible {
  outline: 3px solid var(--maroon-400);
  outline-offset: 2px;
  border-radius: 6px;
}

/* =====================================================================
   LAYOUT
   ===================================================================== */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: linear-gradient(178deg, var(--maroon-800) 0%, var(--maroon-900) 100%);
  color: #F3DDE1;
  position: sticky; top: 0; align-self: flex-start;
  height: 100vh; max-height: 100vh;
  display: flex; flex-direction: column;
  z-index: 40;
}

.brand {
  display: flex; align-items: center; gap: .65rem;
  padding: 1.05rem 1.15rem;
  border-bottom: 1px solid rgba(255, 255, 255, .09);
}
.brand__mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--white); color: var(--maroon-700);
  display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 700; font-size: 1rem;
  flex: 0 0 36px;
}
.brand__name { font-family: var(--font-display); font-size: 1.02rem; color: #fff; line-height: 1.15; }
.brand__sub  { font-size: .68rem; letter-spacing: .1em; text-transform: uppercase; opacity: .62; }

.nav { padding: .7rem .6rem 1.5rem; overflow-y: auto; flex: 1; }
.nav__label {
  font-size: .64rem; letter-spacing: .14em; text-transform: uppercase;
  opacity: .5; padding: 1rem .65rem .35rem;
}
.nav__link {
  display: flex; align-items: center; gap: .7rem;
  padding: .58rem .7rem; margin-bottom: 2px;
  border-radius: var(--radius-sm);
  color: #EBD2D7; font-size: .89rem; font-weight: 500;
  transition: background .15s, color .15s;
}
.nav__link:hover { background: rgba(255, 255, 255, .09); color: #fff; text-decoration: none; }
.nav__link.is-active { background: var(--white); color: var(--maroon-800); font-weight: 600; }
.nav__link.is-active svg { color: var(--maroon-600); }
.nav__link svg { width: 18px; height: 18px; flex: 0 0 18px; }
.nav__badge {
  margin-left: auto; background: var(--maroon-500); color: #fff;
  font-size: .68rem; font-weight: 600; padding: .05rem .4rem; border-radius: 20px;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: .75rem;
  padding: 0 1rem;
  position: sticky; top: 0; z-index: 30;
}
.topbar__title { font-family: var(--font-display); font-size: 1.05rem; margin: 0; }

.search {
  position: relative; flex: 1; max-width: 380px;
}
.search input {
  width: 100%; height: 40px;
  padding: 0 .85rem 0 2.3rem;
  border: 1px solid var(--line); border-radius: 40px;
  background: var(--paper); color: var(--ink); font-size: .88rem;
}
.search input:focus { border-color: var(--maroon-400); background: var(--surface); outline: none; }
.search__icon {
  position: absolute; left: .8rem; top: 50%; transform: translateY(-50%);
  color: var(--muted); width: 16px; height: 16px;
}
.search__results {
  position: absolute; top: 46px; left: 0; right: 0;
  background: var(--raised); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-2);
  overflow: hidden; z-index: 50; display: none;
}
.search__results.is-open { display: block; }
.search__item { display: block; padding: .6rem .85rem; border-bottom: 1px solid var(--line-2); color: var(--ink); }
.search__item:last-child { border-bottom: 0; }
.search__item:hover { background: var(--maroon-050); text-decoration: none; }
.search__item small { color: var(--muted); }

.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  display: grid; place-items: center; cursor: pointer; position: relative;
  flex: 0 0 40px;
}
.icon-btn:hover { background: var(--maroon-050); color: var(--maroon-700); border-color: var(--maroon-200); }
.icon-btn__dot {
  position: absolute; top: 6px; right: 7px;
  min-width: 16px; height: 16px; padding: 0 3px;
  background: var(--maroon-600); color: #fff;
  border-radius: 10px; font-size: .62rem; font-weight: 700;
  display: grid; place-items: center;
}

.avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--maroon-600); color: #fff;
  display: grid; place-items: center; font-weight: 600; font-size: .85rem;
}

.page { padding: 1.15rem 1rem 5.5rem; flex: 1; }
.page__head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1.1rem;
}
.page__head p { color: var(--muted); margin: .1rem 0 0; font-size: .88rem; }

@media (min-width: 992px) {
  .page { padding: 1.5rem 1.6rem 3rem; }
}

/* =====================================================================
   CARDS / PANELS
   ===================================================================== */
.card2 {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
}
.card2__head {
  padding: .85rem 1rem; border-bottom: 1px solid var(--line-2);
  display: flex; align-items: center; justify-content: space-between; gap: .6rem;
}
.card2__head h3 { margin: 0; font-size: .98rem; }
.card2__body { padding: 1rem; }

/* ---------- KPI grid ---------- */
.kpi-grid {
  display: grid; gap: .6rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
@media (min-width: 640px)  { .kpi-grid { grid-template-columns: repeat(3, 1fr); gap: .75rem; } }
@media (min-width: 1200px) { .kpi-grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 1600px) { .kpi-grid { grid-template-columns: repeat(6, 1fr); } }

/* --sm variant: 4-up on tablet, up to 6-up on wide screens — used for the
   Sales & Returns quick-view cards where the values are already labelled. */
.kpi-grid--sm { gap: .45rem; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 640px)  { .kpi-grid--sm { grid-template-columns: repeat(4, 1fr); gap: .55rem; } }
@media (min-width: 1200px) { .kpi-grid--sm { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 1600px) { .kpi-grid--sm { grid-template-columns: repeat(6, 1fr); } }
.kpi-grid--sm .kpi { padding: .6rem .75rem .55rem; }
.kpi-grid--sm .kpi__value { font-size: 1.1rem; }

.kpi {
  display: block; position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .8rem .85rem .75rem;
  color: var(--ink); box-shadow: var(--shadow-1);
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s;
}
.kpi::before {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 3px;
  background: var(--maroon-600); opacity: .85;
}
.kpi:hover, .kpi:focus-visible {
  transform: translateY(-2px); box-shadow: var(--shadow-2);
  border-color: var(--maroon-200); text-decoration: none; color: var(--ink);
}
.kpi:active { transform: translateY(0); }
.kpi__label { font-size: .7rem; color: var(--muted); font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.kpi__value {
  font-family: var(--font-mono); font-size: 1.32rem; font-weight: 600;
  letter-spacing: -.02em; margin-top: .18rem; line-height: 1.15;
  overflow-wrap: anywhere;
}
.kpi__meta { font-size: .72rem; color: var(--muted); margin-top: .1rem; }
.kpi--ok::before     { background: var(--ok); }
.kpi--warn::before   { background: var(--warn); }
.kpi--danger::before { background: var(--danger); }
.kpi--ok .kpi__value     { color: var(--ok); }
.kpi--danger .kpi__value { color: var(--danger); }

/* =====================================================================
   SIGNATURE: the stitch rail
   The workflow as a sewn seam — dashed thread, maroon where the seam is
   finished, hollow where it is not.
   ===================================================================== */
.rail {
  position: relative;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.15rem .5rem .9rem;
  overflow-x: auto; overflow-y: hidden;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.rail::-webkit-scrollbar { display: none; }

.rail__track {
  display: flex; align-items: flex-start;
  min-width: max-content; padding: 0 .5rem;
}
.rail__step {
  position: relative; flex: 0 0 auto;
  width: 96px; text-align: center;
  color: var(--muted); font-size: .72rem; font-weight: 600;
  padding-top: 30px;
}
@media (min-width: 992px) { .rail__step { width: 128px; } }

/* the thread */
.rail__step::before {
  content: ""; position: absolute; top: 13px; left: -50%; width: 100%;
  border-top: 2px dashed var(--line);
}
.rail__step:first-child::before { display: none; }
.rail__step.is-done::before,
.rail__step.is-current::before { border-top-color: var(--maroon-500); }

/* the needle punch */
.rail__step::after {
  content: ""; position: absolute; top: 6px; left: 50%; transform: translateX(-50%);
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--line);
}
.rail__step.is-done::after {
  background: var(--maroon-600); border-color: var(--maroon-600);
  box-shadow: 0 0 0 3px var(--maroon-050);
}
.rail__step.is-current::after {
  background: var(--surface); border-color: var(--maroon-600); border-width: 3px;
  box-shadow: 0 0 0 4px var(--maroon-050);
  animation: pulse 2.1s ease-out infinite;
}
.rail__step.is-done, .rail__step.is-current { color: var(--maroon-700); }
.rail__step.is-current { font-weight: 700; }
.rail__label { display: block; padding: 0 .2rem; line-height: 1.25; }
.rail__index {
  display: block; font-family: var(--font-mono); font-size: .62rem;
  opacity: .6; margin-top: .1rem;
}
a.rail__step:hover { text-decoration: none; color: var(--maroon-600); }

@keyframes pulse {
  0%   { box-shadow: 0 0 0 4px var(--maroon-050); }
  55%  { box-shadow: 0 0 0 9px rgba(249, 115, 22, .10); }
  100% { box-shadow: 0 0 0 4px var(--maroon-050); }
}
@media (prefers-reduced-motion: reduce) {
  .rail__step.is-current::after { animation: none; }
  * { transition-duration: .01ms !important; }
}

/* mobile: rail sticks under the topbar so the operator always sees position */
@media (max-width: 991.98px) {
  .rail--sticky {
    position: sticky; top: var(--topbar-h); z-index: 20;
    border-radius: 0; border-left: 0; border-right: 0;
    margin: -1.15rem -1rem 1rem;
    padding-top: .95rem; padding-bottom: .7rem;
    box-shadow: var(--shadow-1);
  }
}

/* =====================================================================
   FORMS
   ===================================================================== */
.field { margin-bottom: .95rem; }
.field > label, .form-label {
  display: block; font-size: .78rem; font-weight: 600;
  color: var(--ink-2); margin-bottom: .3rem; letter-spacing: .01em;
}
.req { color: var(--maroon-600); }

.input, .form-control, .form-select, select.input, textarea.input {
  width: 100%; min-height: 46px;
  padding: .6rem .8rem;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
  font-size: 16px; /* keeps iOS from zooming on focus */
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
@media (min-width: 992px) { .input, .form-control, .form-select { font-size: .92rem; } }
.input:focus, .form-control:focus, .form-select:focus {
  border-color: var(--maroon-500);
  box-shadow: 0 0 0 3px rgba(249, 115, 22, .18);
  outline: none;
}
.input[readonly], .input:disabled { background: var(--paper); color: var(--muted); cursor: not-allowed; }
textarea.input { min-height: 90px; resize: vertical; }

.input--calc {
  background: var(--maroon-050); border-color: var(--maroon-200);
  color: var(--maroon-800); font-family: var(--font-mono); font-weight: 600;
}
[data-theme="dark"] .input--calc { color: var(--maroon-600); }

.hint  { font-size: .75rem; color: var(--muted); margin-top: .25rem; }
.hint.is-bad { color: var(--danger); }
.error { font-size: .78rem; color: var(--danger); margin-top: .25rem; display: block; }
.input.is-invalid { border-color: var(--danger); background: var(--danger-bg); }

.grid2 { display: grid; gap: 0 .9rem; grid-template-columns: 1fr; }
.grid3 { display: grid; gap: 0 .9rem; grid-template-columns: 1fr; }
@media (min-width: 640px) {
  .grid2 { grid-template-columns: repeat(2, 1fr); }
  .grid3 { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 992px) { .grid3 { grid-template-columns: repeat(3, 1fr); } }

/* number steppers, sized for thumbs on the shop floor */
.stepper { display: flex; align-items: stretch; gap: .4rem; }
.stepper .input { text-align: center; font-family: var(--font-mono); font-weight: 600; font-size: 1.05rem; }
.stepper button {
  flex: 0 0 46px; width: 46px; border: 1px solid var(--line);
  background: var(--surface); color: var(--maroon-700);
  border-radius: var(--radius-sm); font-size: 1.25rem; line-height: 1; cursor: pointer;
}
.stepper button:hover { background: var(--maroon-050); border-color: var(--maroon-200); }
.stepper button:active { background: var(--maroon-200); }

/* file drop */
.drop {
  border: 1.5px dashed var(--maroon-200); border-radius: var(--radius);
  background: var(--maroon-050); padding: 1.1rem; text-align: center;
  cursor: pointer; transition: background .15s, border-color .15s;
}
.drop:hover, .drop.is-over { background: var(--maroon-200); border-color: var(--maroon-500); }
.drop input { display: none; }
.drop__name { font-size: .8rem; color: var(--maroon-800); margin-top: .35rem; word-break: break-all; }

/* signature pad */
.sigpad {
  width: 100%; height: 170px; touch-action: none;
  border: 1.5px dashed var(--line); border-radius: var(--radius);
  background: var(--surface); display: block;
}

/* =====================================================================
   BUTTONS
   ===================================================================== */
.btn2 {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  min-height: 46px; padding: .6rem 1.1rem;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  font-size: .9rem; font-weight: 600; cursor: pointer;
  transition: background .15s, transform .1s, box-shadow .15s;
  text-decoration: none;
}
.btn2:active { transform: translateY(1px); }
.btn2:disabled, .btn2.is-disabled { opacity: .55; pointer-events: none; }
.btn2 svg { width: 17px; height: 17px; }

.btn2--primary { background: var(--maroon-600); color: #fff; box-shadow: var(--shadow-1); }
.btn2--primary:hover { background: var(--maroon-700); color: #fff; text-decoration: none; }
.btn2--ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn2--ghost:hover { background: var(--maroon-050); border-color: var(--maroon-200); color: var(--maroon-800); text-decoration: none; }
.btn2--quiet { background: transparent; color: var(--muted); }
.btn2--quiet:hover { color: var(--maroon-700); text-decoration: none; }
.btn2--danger { background: var(--danger); color: #fff; }
.btn2--danger:hover { background: #9B221E; color: #fff; text-decoration: none; }
.btn2--block { width: 100%; }
.btn2--sm { min-height: 36px; padding: .35rem .7rem; font-size: .8rem; }

/* sticky action bar — always reachable with one thumb */
.actionbar {
  position: sticky; bottom: 0; z-index: 25;
  display: flex; gap: .55rem; align-items: center;
  background: var(--surface); border-top: 1px solid var(--line);
  padding: .7rem 1rem calc(.7rem + env(safe-area-inset-bottom));
  margin: 1.2rem -1rem 0;
  box-shadow: var(--shadow-up);
}
.actionbar .btn2 { flex: 1; }
.actionbar .btn2--icon { flex: 0 0 46px; padding: 0; }
@media (min-width: 992px) {
  .actionbar { margin: 1.4rem 0 0; border-radius: var(--radius); border: 1px solid var(--line); }
  .actionbar .btn2 { flex: 0 0 auto; min-width: 130px; }
  .actionbar .spacer { flex: 1; }
}
@media (max-width: 991.98px) { .actionbar { bottom: var(--tabbar-h); } }

/* floating quick action */
.fab {
  position: fixed; right: 1rem; z-index: 45;
  bottom: calc(var(--tabbar-h) + 1rem + env(safe-area-inset-bottom));
  width: 58px; height: 58px; border-radius: 50%; border: 0;
  background: var(--maroon-600); color: #fff;
  box-shadow: 0 8px 22px rgba(194, 65, 12, .35);
  display: grid; place-items: center; cursor: pointer;
  transition: transform .18s;
}
.fab:hover { background: var(--maroon-700); transform: scale(1.05); }
.fab svg { width: 26px; height: 26px; transition: transform .22s; }
.fab[aria-expanded="true"] svg { transform: rotate(45deg); }
@media (min-width: 992px) { .fab { bottom: 1.6rem; right: 1.6rem; } }

/* On stage and form screens the sticky action bar owns the bottom-right
   corner. Left alone, the floating button sits on top of Save / Next and
   swallows the tap, so it steps aside wherever an action bar is present. */
body.has-actionbar .fab {
  bottom: calc(var(--tabbar-h) + 5.4rem + env(safe-area-inset-bottom));
}
@media (min-width: 992px) {
  body.has-actionbar .fab { bottom: 6.2rem; right: 1.6rem; }
}

/* =====================================================================
   MOBILE TAB BAR
   ===================================================================== */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 44;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
  display: flex; box-shadow: var(--shadow-up);
}
.tabbar__item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--muted); font-size: .64rem; font-weight: 600;
  padding-top: 4px; min-height: 48px;
}
.tabbar__item svg { width: 21px; height: 21px; }
.tabbar__item.is-active { color: var(--maroon-600); }
.tabbar__item:hover { text-decoration: none; color: var(--maroon-600); }
@media (min-width: 992px) { .tabbar { display: none; } }

/* =====================================================================
   TABLES
   ===================================================================== */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data {
  width: 100%; border-collapse: collapse; font-size: .87rem;
}
table.data th {
  text-align: left; font-size: .69rem; letter-spacing: .07em; text-transform: uppercase;
  color: var(--muted); font-weight: 700; padding: .6rem .7rem;
  border-bottom: 1px solid var(--line); white-space: nowrap !important; background: var(--surface);
}
table.data td {
  padding: .68rem .7rem; border-bottom: 1px solid var(--line-2); vertical-align: middle;
}
table.data tbody tr:hover { background: var(--maroon-050); }
tr.clickable-row { transition: background-color .15s ease-in-out; }
tr.clickable-row:hover { background: var(--maroon-050) !important; cursor: pointer; }
tr.clickable-row:hover a { text-decoration: underline !important; }
table.data tfoot td {
  font-weight: 700; border-top: 2px solid var(--maroon-200); background: var(--maroon-050);
  font-family: var(--font-mono);
}
.text-end { text-align: right; }

/* On phones the rolls table becomes a stack of cards */
@media (max-width: 767.98px) {
  table.cards, table.cards thead, table.cards tbody, table.cards tr, table.cards td {
    display: block;
    width: 100% !important;
    box-sizing: border-box;
  }
  table.cards thead { display: none; }
  .table-wrap:has(table.cards) {
    overflow-x: visible !important;
    padding-right: 0 !important;
  }
  table.cards tr {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); margin-bottom: .85rem; padding: 0;
    box-shadow: var(--shadow-1);
    overflow: hidden;
    width: 100% !important;
    box-sizing: border-box;
  }
  table.cards td {
    display: flex; flex-wrap: nowrap; align-items: center; gap: 0;
    justify-content: space-between;
    border-bottom: 1px solid var(--line-2); padding: .55rem .85rem;
    overflow-wrap: break-word; word-break: break-word;
    min-width: 0;
    width: 100% !important;
    box-sizing: border-box;
  }
  table.cards td:last-child { border-bottom: 0; }
  table.cards td::before {
    content: attr(data-label);
    font-size: .72rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
    color: var(--muted); text-align: left;
    flex: 0 0 40%; max-width: 40%; min-width: 0;
    padding-right: .5rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  table.cards td > * {
    flex: 0 1 60%; max-width: 60%; min-width: 0; text-align: right;
    overflow-wrap: break-word; word-break: break-word;
  }
  table.cards td { text-align: right; }
  table.cards td.cards__title {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center;
    width: 100% !important;
    box-sizing: border-box;
    background: var(--maroon-050);
    border-radius: 0;
    padding: .65rem .85rem !important;
    font-family: var(--font-display); font-size: 1rem; font-weight: 700;
  }
  table.cards td.cards__title::before {
    color: var(--maroon-700);
    flex: 0 0 auto;
    max-width: none;
  }
}

table.data td[data-label="Phone"] a {
  color: inherit;
  font-weight: inherit;
  text-decoration: none;
}
table.data td[data-label="Phone"] a:hover,
table.data td[data-label="Phone"] a:focus-visible {
  color: var(--maroon-600);
  text-decoration: underline;
}

/* =====================================================================
   CHIPS / BADGES / ALERTS
   ===================================================================== */
.chip {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .16rem .55rem; border-radius: 30px;
  font-size: .73rem; font-weight: 600;
  background: var(--line-2); color: var(--ink-2); white-space: nowrap;
}
.chip--ok     { background: var(--ok-bg);     color: var(--ok); }
.chip--warn   { background: var(--warn-bg);   color: var(--warn); }
.chip--danger { background: var(--danger-bg); color: var(--danger); }
.chip--maroon { background: var(--maroon-050); color: var(--maroon-700); }
.chip__dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.psf-tabs { display: flex; gap: .4rem; flex-wrap: wrap; border-bottom: 1px solid var(--line); padding: 0 var(--psf-gutter, 16px); }
.psf-tab {
    display: inline-flex; align-items: center; gap: .4rem;
    padding: .55rem .9rem; font-size: .85rem; font-weight: 600;
    color: var(--muted); border-bottom: 2px solid transparent;
    margin-bottom: -1px; text-decoration: none;
}
.psf-tab svg { width: 15px; height: 15px; }
.psf-tab:hover { color: var(--maroon-700); text-decoration: none; }
.psf-tab--active { color: var(--maroon-700); border-bottom-color: var(--maroon-600); }

.swatch {
  width: 13px; height: 13px; border-radius: 4px;
  display: inline-block; vertical-align: -2px; margin-right: .35rem;
  border: 1px solid rgba(0, 0, 0, .18);
}

.alert2 {
  display: flex; gap: .6rem; align-items: flex-start;
  padding: .75rem .9rem; border-radius: var(--radius-sm);
  border: 1px solid; font-size: .87rem; margin-bottom: .9rem;
}
.alert2--success { background: var(--ok-bg);     border-color: #BFE3D2; color: var(--ok); }
.alert2--danger  { background: var(--danger-bg); border-color: #F0C8C6; color: var(--danger); }
.alert2--warning { background: var(--warn-bg);   border-color: #EFD9AE; color: var(--warn); }
.alert2--info    { background: var(--maroon-050); border-color: var(--maroon-200); color: var(--maroon-800); }
.alert2 svg { width: 18px; height: 18px; flex: 0 0 18px; margin-top: 1px; }

/* toast */
.toasts {
  position: fixed; z-index: 90; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + 1rem + env(safe-area-inset-bottom));
  width: min(94vw, 420px); display: flex; flex-direction: column; gap: .5rem;
}
@media (min-width: 992px) { .toasts { left: auto; right: 1.6rem; transform: none; bottom: 1.6rem; } }
.toast2 {
  background: var(--maroon-900); color: #fff;
  padding: .8rem 1rem; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-2); font-size: .88rem;
  display: flex; gap: .6rem; align-items: center;
  animation: rise .22s ease-out;
}
.toast2--danger { background: var(--danger); }
.toast2--ok { background: var(--ok); }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* =====================================================================
   STAGE SCREENS
   ===================================================================== */
.stage-head {
  background: linear-gradient(140deg, var(--maroon-700), var(--maroon-900));
  color: #fff; border-radius: var(--radius-lg);
  padding: 1.1rem 1.15rem; margin-bottom: 1rem;
}
.stage-head h1 { color: #fff; font-size: 1.3rem; margin-bottom: .1rem; }
.stage-head .eyebrow { color: rgba(255, 255, 255, .68); }
.stage-head__meta {
  display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .7rem;
}
.stage-head__meta .chip { background: rgba(255, 255, 255, .16); color: #fff; }

/* read-only trail of what earlier stages recorded */
.trail { display: grid; gap: .5rem; grid-template-columns: repeat(2, 1fr); }
@media (min-width: 640px) { .trail { grid-template-columns: repeat(4, 1fr); } }
.trail__cell {
  background: var(--paper); border: 1px solid var(--line-2);
  border-radius: var(--radius-sm); padding: .5rem .6rem;
}
.trail__k { font-size: .66rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.trail__v { font-family: var(--font-mono); font-size: 1rem; font-weight: 600; }
.trail__v--bad { color: var(--danger); }

/* live math strip */
.calcbar {
  display: grid; gap: .5rem; grid-template-columns: repeat(2, 1fr);
  background: var(--maroon-050); border: 1px solid var(--maroon-200);
  border-radius: var(--radius); padding: .75rem; margin: .2rem 0 1rem;
}
@media (min-width: 768px) { .calcbar { grid-template-columns: repeat(4, 1fr); } }
.calcbar__k { font-size: .66rem; text-transform: uppercase; letter-spacing: .06em; color: var(--maroon-700); font-weight: 700; }
.calcbar__v { font-family: var(--font-mono); font-size: 1.2rem; font-weight: 600; color: var(--maroon-800); }
[data-theme="dark"] .calcbar__v, [data-theme="dark"] .calcbar__k { color: var(--maroon-600); }
.calcbar__v.is-bad { color: var(--danger); }

/* =====================================================================
   AUTOSAVE STATUS
   Stage forms have no Save button. This pill is the only feedback that
   the work is being kept, so it has to be legible without being loud.
   ===================================================================== */
.autosave {
  flex: 0 0 auto;
  display: inline-flex; align-items: center; gap: .4rem;
  font-size: .74rem; font-weight: 600; letter-spacing: .01em;
  color: var(--muted);
  padding: .34rem .6rem;
  border-radius: 999px;
  background: var(--paper);
  border: 1px solid var(--line-2);
  white-space: nowrap;
  transition: color .18s ease, background .18s ease, border-color .18s ease;
}
.autosave__dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: currentColor; opacity: .55; flex: 0 0 7px;
}

.autosave.is-saving {
  color: var(--indigo); background: var(--white); border-color: var(--line);
}
.autosave.is-saving .autosave__dot { opacity: 1; animation: autosave-pulse 1.1s ease-in-out infinite; }

.autosave.is-saved {
  color: var(--ok); background: var(--ok-bg); border-color: transparent;
}
.autosave.is-saved .autosave__dot { opacity: 1; }

.autosave.is-failed {
  color: var(--danger); background: var(--danger-bg); border-color: transparent;
}
.autosave.is-failed .autosave__dot { opacity: 1; }

@keyframes autosave-pulse {
  0%, 100% { transform: scale(1);   opacity: 1;  }
  50%      { transform: scale(.55); opacity: .4; }
}
@media (prefers-reduced-motion: reduce) {
  .autosave.is-saving .autosave__dot { animation: none; }
}

/* On a narrow phone the action bar is already carrying Previous, Share and
   Next. Keep the dot as the signal and drop the words. */
@media (max-width: 479.98px) {
  .autosave { padding: .34rem; }
  .autosave__text { display: none; }
}

/* =====================================================================
   STAGE WINDOW
   The production user's three-stage view: the stage before and the stage
   after, both read-only, bracketing the editable form.
   ===================================================================== */
.stage-window { border-style: dashed; }
.stage-window .card2__head .chip { font-size: .66rem; }
.stage-window .trail__cell { background: var(--white); }

.stage-window--prev { border-left: 3px solid var(--line); }
.stage-window--next { border-left: 3px solid var(--maroon-200); opacity: .92; }
.stage-window--next .trail__v { color: var(--ink-2); }

[data-theme="dark"] .stage-window .trail__cell { background: var(--raised); }

/* =====================================================================
   CHARTS
   ===================================================================== */
.chart-grid { display: grid; gap: .75rem; grid-template-columns: 1fr; }
@media (min-width: 900px)  { .chart-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1500px) { .chart-grid { grid-template-columns: repeat(3, 1fr); } }
.chart-box { position: relative; height: 240px; }
.chart-box canvas { max-height: 240px; }

/* =====================================================================
   AGREEMENT / PRINT
   ===================================================================== */
.deed {
  max-width: 820px; margin: 1.2rem auto; background: #fff; color: #1a1416;
  padding: 2.4rem 2.2rem; border: 1px solid #ddd;
  box-shadow: var(--shadow-2); position: relative;
  font-family: var(--font-display); font-size: 14px; line-height: 1.75;
}
.deed::before {
  content: ""; position: absolute; inset: 10px;
  border: 2px double #C2410C; pointer-events: none;
}
.deed__inner { position: relative; padding: .6rem; }
.deed__stamp {
  border: 1.5px solid #C2410C; padding: .6rem .8rem; margin-bottom: 1.4rem;
  display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  font-family: var(--font-mono); font-size: 11px; letter-spacing: .04em; color: #C2410C;
}
.deed h1 {
  text-align: center; font-size: 1.35rem; letter-spacing: .06em;
  text-transform: uppercase; color: #9A3412; margin: 0 0 .2rem;
}
.deed__rule { text-align: center; color: #C2410C; letter-spacing: .5em; margin-bottom: 1.4rem; }
.deed table { width: 100%; border-collapse: collapse; margin: 1rem 0; font-family: var(--font-ui); font-size: 12.5px; }
.deed table th, .deed table td { border: 1px solid #c9b7ba; padding: .45rem .6rem; }
.deed table th { background: #f7eef0; text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.deed__terms { font-size: 12.5px; }
.deed__terms li { margin-bottom: .45rem; }
.deed__signs { display: flex; justify-content: space-between; gap: 2rem; margin-top: 2.6rem; flex-wrap: wrap; }
.deed__sign { flex: 1 1 240px; text-align: center; }
.deed__sign img { max-height: 74px; max-width: 100%; }
.deed__signline { border-top: 1px solid #4a3a3d; margin-top: 62px; padding-top: .3rem; font-size: 11.5px; }
.deed__stampbox {
  width: 128px; height: 128px; border: 1.5px dashed #a8848a; border-radius: 50%;
  display: grid; place-items: center; margin: 0 auto;
  font-size: 10px; color: #a8848a; text-align: center; letter-spacing: .08em;
}

@media print {
  .no-print, .tabbar, .fab, .sidebar, .topbar, .actionbar { display: none !important; }
  body { background: #fff; padding: 0; }
  .deed { box-shadow: none; border: 0; margin: 0; max-width: none; padding: 12mm; }
  @page { size: A4; margin: 8mm; }
}

/* =====================================================================
   AUTH SCREEN
   ===================================================================== */
.auth {
  min-height: 100vh; display: grid;
  grid-template-columns: 1fr;
  background: var(--paper);
}
@media (min-width: 992px) { .auth { grid-template-columns: 1.05fr .95fr; } }

.auth__art {
  display: none; position: relative; overflow: hidden;
  background: linear-gradient(150deg, var(--maroon-700), var(--maroon-900) 70%);
  color: #fff; padding: 3rem;
  flex-direction: column; justify-content: space-between;
}
@media (min-width: 992px) { .auth__art { display: flex; } }
.auth__art h2 { color: #fff; font-size: 2.05rem; max-width: 13ch; line-height: 1.15; }
.auth__art p { color: rgba(255, 255, 255, .74); max-width: 42ch; }
/* woven selvedge pattern, drawn not imaged */
.auth__weave {
  position: absolute; inset: 0; opacity: .13; pointer-events: none;
  background-image:
    repeating-linear-gradient(90deg, #fff 0 1px, transparent 1px 11px),
    repeating-linear-gradient(0deg, #fff 0 1px, transparent 1px 11px);
}
.auth__form { display: grid; place-items: center; padding: 2rem 1.15rem; }
.auth__card { width: 100%; max-width: 400px; }

.demo-key {
  background: var(--maroon-050); border: 1px dashed var(--maroon-200);
  border-radius: var(--radius-sm); padding: .65rem .8rem;
  font-size: .78rem; color: var(--maroon-800);
}
.demo-key code { font-family: var(--font-mono); color: var(--maroon-700); }

/* =====================================================================
   SHARE-LINK SCREEN (single stage, no navigation)
   ===================================================================== */
.share-shell { max-width: 720px; margin: 0 auto; padding: 0 0 3rem; }
.share-bar {
  background: var(--maroon-900); color: #fff;
  padding: .7rem 1rem; display: flex; align-items: center; gap: .6rem;
  position: sticky; top: 0; z-index: 30;
}
.share-bar__tag {
  margin-left: auto; font-size: .68rem; letter-spacing: .1em; text-transform: uppercase;
  background: rgba(255, 255, 255, .16); padding: .18rem .55rem; border-radius: 20px;
}

/* =====================================================================
   MISC
   ===================================================================== */
.empty { text-align: center; padding: 2.6rem 1rem; color: var(--muted); }
.empty svg { width: 42px; height: 42px; color: var(--maroon-200); margin-bottom: .6rem; }
.empty h3 { color: var(--ink); }

.divider { height: 1px; background: var(--line); margin: 1rem 0; border: 0; }

.list-reset { list-style: none; padding: 0; margin: 0; }

.feed__item { display: flex; gap: .65rem; padding: .55rem 0; border-bottom: 1px solid var(--line-2); font-size: .85rem; }
.feed__item:last-child { border-bottom: 0; }
.feed__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--maroon-400); margin-top: .45rem; flex: 0 0 8px; }
.feed__when { margin-left: auto; color: var(--muted); font-size: .74rem; white-space: nowrap; }

.progress-line { height: 7px; border-radius: 6px; background: var(--line-2); overflow: hidden; }
.progress-line > span { display: block; height: 100%; background: var(--maroon-600); border-radius: 6px; }

/* offcanvas + modal skins over Bootstrap */
.offcanvas, .modal-content {
  background: var(--surface); color: var(--ink); border-color: var(--line);
}
.modal-content { border-radius: var(--radius-lg); }
.modal-header, .modal-footer { border-color: var(--line-2); }
.dropdown-menu {
  background: var(--raised); border-color: var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-2); padding: .35rem;
}
.dropdown-item { color: var(--ink); border-radius: var(--radius-sm); padding: .55rem .7rem; font-size: .88rem; }
.dropdown-item:hover, .dropdown-item:focus { background: var(--maroon-050); color: var(--maroon-800); }

/* DataTables skin */
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: .35rem .6rem; background: var(--surface); color: var(--ink);
}
.dataTables_wrapper .dataTables_paginate .paginate_button {
  border-radius: var(--radius-sm) !important; border: 0 !important; color: var(--ink) !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current {
  background: var(--maroon-600) !important; color: #fff !important;
}
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter { color: var(--muted); font-size: .82rem; }
/* Ghost buttons sitting on the dark hero banners (.psf-head__actions) are
   given inline color:#fff / border-color for contrast against the dark
   gradient — but .btn2--ghost's own background is var(--surface), which is
   white in light mode. That left white text on a white button. Force a
   transparent/dark-friendly background here so they stay readable in both
   themes, regardless of any inline style on the element. */
.psf-head__actions .btn2--ghost {
  background: rgba(255, 255, 255, .1) !important;
  border-color: rgba(255, 255, 255, .35) !important;
  color: #fff !important;
}
.psf-head__actions .btn2--ghost:hover {
  background: rgba(255, 255, 255, .2) !important;
  border-color: rgba(255, 255, 255, .55) !important;
  color: #fff !important;
}