/* ============================================================================
   KUNDAN TRADERS — Windows & Fittings Suite
   Design world: "ANODISED"

   The palette is the material. Mill-finish aluminium is a cool grey with a
   faint blue cast; anodised champagne gold is the premium finish this shop
   actually sells. So the interface is machined graphite, and gold appears in
   exactly one place — money. Nowhere else. A tool you look at for eight hours
   earns its quality from restraint, not decoration.

   Type: Archivo (variable width — expanded reads like a machine nameplate)
         IBM Plex Mono for every number, code and dimension. Measurement, not
         costume.

   Elevation: hairline borders on the page, shadow only on things that float.
   Never both on the same element.
   ========================================================================== */
@import url('https://fonts.googleapis.com/css2?family=Archivo:wdth,wght@85..125,400..800&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

/* ------------------------------------------------------------- tokens -- */
:root {
  /* mill finish — cool greys with a blue cast */
  --bg:          #E8EAEE;
  --surface:     #FFFFFF;
  --surface-2:   #F4F6F8;
  --surface-3:   #E7EAEF;
  --surface-4:   #DBE0E7;

  /* Every tier below clears 4.5:1 on both --surface and --surface-2.
     A work tool is read for eight hours; "muted" must not mean "faint". */
  --fg:          #12151A;
  --fg-2:        #454E5A;
  --fg-3:        #626B79;
  --fg-4:        #6E7784;

  --line:        #DDE1E7;
  --line-2:      #C6CCD5;
  --line-3:      #AEB6C1;

  /* graphite — the interactive colour. Deliberately not blue. */
  --ink:         #1B1F26;
  --ink-hover:   #2C323C;
  --on-ink:      #FFFFFF;
  --ink-wash:    #EAECF0;

  /* anodised champagne — MONEY ONLY */
  --gold:        #7F6329;
  --gold-mid:    #B4924B;
  --gold-bright: #C9A961;
  --gold-wash:   #F8F3E7;
  --gold-line:   #E7DBBE;

  --danger:      #A32222;
  --danger-bg:   #FBE9E9;
  --danger-line: #F0C9C9;
  --ok:          #1F6B4B;
  --ok-bg:       #E4F3EC;
  --ok-line:     #C2E3D3;
  --warn:        #7A5510;
  --warn-bg:     #FBF2DF;
  --warn-line:   #EEDCB4;
  --info-bg:     #EDEFF3;

  --focus:       #1B1F26;
  --focus-ring:  0 0 0 2px var(--surface), 0 0 0 4px var(--focus);

  /* things that float get shadow, and no border */
  --lift-1: 0 1px 2px rgba(18,21,26,.07), 0 2px 6px rgba(18,21,26,.05);
  --lift-2: 0 4px 10px rgba(18,21,26,.08), 0 12px 32px rgba(18,21,26,.10);
  --lift-3: 0 12px 28px rgba(18,21,26,.14), 0 40px 80px rgba(18,21,26,.16);

  --r-xs: 3px; --r-sm: 5px; --r: 8px; --r-lg: 12px; --r-pill: 100px;

  --font: 'Archivo', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Consolas, monospace;

  --sidebar-w: 224px;
  --topbar-h: 56px;

  --z-nav: 40; --z-sticky: 60; --z-drawer: 200; --z-modal: 300; --z-toast: 400;

  --ease: cubic-bezier(.22,.61,.36,1);
  --ease-out: cubic-bezier(.16,1,.3,1);
}

:root[data-theme="dark"] {
  --bg:          #0C0E11;
  --surface:     #14171C;
  --surface-2:   #1A1E24;
  --surface-3:   #22272F;
  --surface-4:   #2B313A;

  --fg:          #E9ECF0;
  --fg-2:        #AEB6C2;
  --fg-3:        #8A93A1;
  --fg-4:        #79828F;

  --line:        #242A32;
  --line-2:      #313842;
  --line-3:      #414957;

  --ink:         #E9ECF0;
  --ink-hover:   #FFFFFF;
  --on-ink:      #0C0E11;
  --ink-wash:    #22272F;

  --gold:        #D4B36A;
  --gold-mid:    #C9A961;
  --gold-bright: #E0C685;
  --gold-wash:   #241E10;
  --gold-line:   #3B331E;

  --danger:      #F08A8A;
  --danger-bg:   #2C1516;
  --danger-line: #4A2224;
  --ok:          #63D3A4;
  --ok-bg:       #0F2B21;
  --ok-line:     #1C4736;
  --warn:        #E8C173;
  --warn-bg:     #2A2211;
  --warn-line:   #453820;
  --info-bg:     #1A1E24;

  --focus:       #D4B36A;
  --focus-ring:  0 0 0 2px var(--surface), 0 0 0 4px var(--focus);

  --lift-1: 0 1px 2px rgba(0,0,0,.5);
  --lift-2: 0 4px 12px rgba(0,0,0,.5);
  --lift-3: 0 16px 48px rgba(0,0,0,.66);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  font-variation-settings: 'wdth' 100;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Every figure in this product is a measurement or a price. */
.num, .mono, table.sg td.num, .kpi-value, kbd,
input[inputmode="decimal"], .input.num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1, "zero" 1;
  letter-spacing: -.01em;
}

::selection { background: color-mix(in srgb, var(--gold-mid) 30%, transparent); }

::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 6px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--line-3); background-clip: content-box; }

/* --------------------------------------------------------------- app --- */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; height: 100vh; height: 100dvh; }

/* ------------------------------------------------------------ sidebar -- */
.side {
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  z-index: var(--z-nav);
}

.brand {
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 10px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.brand-mark {
  width: 30px; height: 30px; border-radius: var(--r-sm);
  background: var(--ink); color: var(--on-ink);
  display: grid; place-items: center; flex: 0 0 auto;
}
.brand-mark svg { width: 30px; height: 30px; }
.brand-name {
  font-weight: 700; font-size: 13.5px; line-height: 1.15;
  font-variation-settings: 'wdth' 112;
  letter-spacing: -.008em;
}
.brand-sub {
  font-family: var(--mono);
  font-size: 8.5px; font-weight: 500; color: var(--fg-3);
  letter-spacing: .13em; text-transform: uppercase; margin-top: 1px;
}

.nav { flex: 1 1 auto; overflow-y: auto; padding: 14px 10px; }
.nav-group { margin-bottom: 20px; }
.nav-group-label {
  font-family: var(--mono);
  font-size: 9px; font-weight: 500; letter-spacing: .16em; text-transform: uppercase;
  color: var(--fg-4); padding: 0 8px 8px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  padding: 7px 8px;
  border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--fg-2);
  font: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer; position: relative;
  transition: background .18s var(--ease), color .18s var(--ease);
}
.nav-item svg { width: 15px; height: 15px; flex: 0 0 auto; opacity: .7; transition: opacity .18s; }
.nav-item:hover { background: var(--surface-2); color: var(--fg); }
.nav-item:hover svg { opacity: 1; }
.nav-item.active { background: var(--ink-wash); color: var(--fg); font-weight: 600; }
.nav-item.active svg { opacity: 1; }
.nav-item.active::before {
  content: ''; position: absolute; left: -10px; top: 7px; bottom: 7px;
  width: 2px; background: var(--ink);
  animation: railIn .28s var(--ease-out);
}
@keyframes railIn { from { transform: scaleY(0) } to { transform: none } }
.nav-item:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.nav-badge {
  margin-left: auto; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: var(--r-pill); background: var(--danger); color: #fff;
  font-family: var(--mono); font-size: 10px; font-weight: 600;
  display: grid; place-items: center;
}
:root[data-theme="dark"] .nav-badge { color: #2C1516; }

.side-foot { flex: 0 0 auto; padding: 12px 14px; border-top: 1px solid var(--line); }
.save-chip { display: flex; align-items: center; gap: 7px; font-size: 11px; color: var(--fg-3); }
.save-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); flex: 0 0 auto; transition: background .2s; }
.save-dot.dirty { background: var(--gold-mid); }
.save-dot.err { background: var(--danger); }

/* ------------------------------------------------------------- topbar -- */
.main { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.topbar {
  height: var(--topbar-h); flex: 0 0 auto;
  background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px;
  padding: 0 18px;
  z-index: var(--z-sticky);
}
.page-title {
  font-size: 15px; font-weight: 700; letter-spacing: -.015em;
  font-variation-settings: 'wdth' 106;
}
.page-sub { font-size: 11.5px; color: var(--fg-3); margin-top: 1px; }
.topbar-spacer { flex: 1 1 auto; }

/* the one gold thing in the chrome: the price of the raw material */
.rate-chip {
  display: flex; align-items: center; gap: 7px;
  background: var(--gold-wash); border: 1px solid var(--gold-line);
  border-radius: var(--r-sm); padding: 5px 10px; cursor: pointer;
  font-size: 11.5px; color: var(--gold); font-weight: 500;
  transition: border-color .18s var(--ease), background .18s var(--ease);
}
.rate-chip:hover { border-color: var(--gold-mid); }
.rate-chip:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.rate-chip b { font-family: var(--mono); font-weight: 600; letter-spacing: -.02em; }
.rate-chip svg { opacity: .75; }

/* --------------------------------------------------------------- view -- */
.view { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; padding: 22px; }
.view.flush { padding: 0; display: flex; flex-direction: column; }

/* ------------------------------------------------------------ buttons -- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 32px; padding: 0 12px;
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  background: var(--surface); color: var(--fg);
  font: inherit; font-size: 12.5px; font-weight: 500;
  cursor: pointer; white-space: nowrap;
  transition: background .16s var(--ease), border-color .16s var(--ease), color .16s var(--ease);
}
.btn svg { width: 14px; height: 14px; opacity: .8; }
.btn:hover { background: var(--surface-2); border-color: var(--line-3); }
.btn:active { background: var(--surface-3); }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.btn[disabled] { opacity: .4; cursor: not-allowed; pointer-events: none; }

.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--on-ink); font-weight: 600; }
.btn.primary:hover { background: var(--ink-hover); border-color: var(--ink-hover); }
.btn.primary svg { opacity: .9; }
.btn.accent { background: var(--gold-wash); border-color: var(--gold-line); color: var(--gold); font-weight: 600; }
.btn.accent:hover { border-color: var(--gold-mid); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--fg-2); }
.btn.ghost:hover { background: var(--surface-3); color: var(--fg); }
.btn.danger { color: var(--danger); border-color: var(--danger-line); background: var(--surface); }
.btn.danger:hover { background: var(--danger-bg); border-color: var(--danger); }
.btn.sm { min-height: 27px; padding: 0 9px; font-size: 12px; }
.btn.sm svg { width: 13px; height: 13px; }
.btn.icon { padding: 0; width: 32px; }
.btn.icon.sm { width: 27px; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* -------------------------------------------------------------- cards -- */
/* Hairline only. A border under a soft shadow is the ghost card. */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}
.card-head {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
}
.card-title { font-size: 12.5px; font-weight: 700; letter-spacing: -.005em; }
.card-title .hint { font-weight: 400; color: var(--fg-3); font-size: 11.5px; margin-left: 7px; letter-spacing: 0; }
.card-body { padding: 16px; }
/* rows that run edge to edge must still respect the card's corners */
.card-body.flush { padding: 0; overflow: hidden; border-radius: 0 0 var(--r-lg) var(--r-lg); }
.card > .card-body.flush:first-child { border-radius: var(--r-lg); }
/* a card inside a card is always wrong */
.card .card { border: 0; border-radius: 0; background: transparent; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 14px; }
@media (max-width: 1200px) { .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 900px)  { .grid-3, .grid-2 { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- kpi -- */
.kpi { padding: 15px 16px; }
.kpi-label {
  font-family: var(--mono);
  font-size: 9.5px; font-weight: 500; letter-spacing: .13em; text-transform: uppercase;
  color: var(--fg-3);
}
.kpi-value {
  font-size: 25px; font-weight: 600; letter-spacing: -.035em;
  margin-top: 7px; line-height: 1.05; color: var(--fg);
}
.kpi-value.sm { font-size: 17px; letter-spacing: -.02em; }
.kpi-foot { font-size: 11.5px; color: var(--fg-3); margin-top: 6px; display: flex; align-items: center; gap: 5px; }
.kpi-foot .up { color: var(--ok); } .kpi-foot .down { color: var(--danger); }

/* --------------------------------------------------------------- pill -- */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: var(--r-pill);
  font-size: 10.5px; font-weight: 600; letter-spacing: .01em;
  background: var(--surface-3); color: var(--fg-2);
  border: 1px solid transparent; white-space: nowrap;
}
.pill svg { width: 10px; height: 10px; }
.pill.slate  { background: var(--surface-3); color: var(--fg-2); }
.pill.indigo,
.pill.blue   { background: var(--ink-wash); color: var(--fg); }
.pill.amber  { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-line); }
.pill.green  { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-line); }
.pill.red    { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-line); }
.pill.zinc   { background: var(--surface-3); color: var(--fg-3); }
.pill.gold   { background: var(--gold-wash); color: var(--gold); border-color: var(--gold-line); }
.pill.dot::before { content:''; width:5px; height:5px; border-radius:50%; background: currentColor; }

/* -------------------------------------------------------------- forms -- */
.field { display: flex; flex-direction: column; gap: 5px; }
.field > label { font-size: 11.5px; font-weight: 600; color: var(--fg-2); letter-spacing: .002em; }
.field .req { color: var(--danger); }
.field .help { font-size: 11px; color: var(--fg-3); line-height: 1.45; }
.field .err { font-size: 11px; color: var(--danger); }

.input, .select, .textarea {
  width: 100%; min-height: 32px;
  padding: 5px 9px;
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  background: var(--surface); color: var(--fg);
  font: inherit; font-size: 13px;
  transition: border-color .16s var(--ease), box-shadow .16s var(--ease);
}
.textarea { min-height: 70px; resize: vertical; line-height: 1.55; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--line-3); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--focus); box-shadow: var(--focus-ring);
}
.input.num { text-align: right; }
.input[readonly] { background: var(--surface-2); color: var(--fg-2); }
.input::placeholder, .textarea::placeholder { color: var(--fg-3); }

.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 13px 16px; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-all { grid-column: 1 / -1; }

.inline-check { display: flex; align-items: center; gap: 8px; font-size: 12.5px; cursor: pointer; min-height: 32px; }
.inline-check input { width: 15px; height: 15px; accent-color: var(--ink); cursor: pointer; flex: 0 0 auto; }

/* -------------------------------------------------------------- table -- */
.tbl { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12.5px; }
.tbl th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-2); color: var(--fg-3);
  font-family: var(--mono);
  font-size: 9.5px; font-weight: 500; letter-spacing: .12em; text-transform: uppercase;
  text-align: left; padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tbody tr { transition: background .12s var(--ease); }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr.clickable { cursor: pointer; }
.tbl .ta-r, .tbl th.ta-r { text-align: right; }
.tbl tr.total-row td { font-weight: 600; background: var(--surface-2); }
.tbl-wrap { overflow: auto; max-height: 100%; }

.ta-r { text-align: right; } .ta-c { text-align: center; }
.muted { color: var(--fg-3); }
.small { font-size: 12px; } .xsmall { font-size: 10.5px; }
.strong { font-weight: 600; }
.mt-2{margin-top:8px} .mt-3{margin-top:12px} .mt-4{margin-top:16px}
.mb-3{margin-bottom:12px} .mb-4{margin-bottom:16px}
.pos { color: var(--ok); } .neg { color: var(--danger); }
.nowrap { white-space: nowrap; }
.gold { color: var(--gold); }

/* ============================================================ SheetGrid = */
.sg-host { position: relative; }
.sg-wrap {
  overflow: auto; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r);
  outline: none; max-height: 100%;
  transition: border-color .18s var(--ease);
}
.sg-wrap:focus-visible { border-color: var(--line-3); }
table.sg { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 12.5px; }

table.sg th.sg-th {
  position: sticky; top: 0; z-index: 3;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line-2);
  border-right: 1px solid var(--line);
  padding: 7px 9px; text-align: left;
  font-family: var(--mono);
  font-size: 10px; font-weight: 500; letter-spacing: .09em; text-transform: uppercase;
  color: var(--fg-2); white-space: nowrap;
}
table.sg th.sg-th.sg-calc { background: var(--surface-3); color: var(--fg-2); }
table.sg th.sg-th.ta-r { text-align: right; }
.sg-th-label { display: block; }
.sg-th-sub {
  display: block; font-family: var(--font); font-size: 9.5px; font-weight: 400;
  letter-spacing: .01em; text-transform: none; color: var(--fg-3); margin-top: 1px;
}

table.sg th.sg-rowhead {
  position: sticky; left: 0; z-index: 4;
  background: var(--surface-2); color: var(--fg-4);
  font-family: var(--mono); font-size: 10px; font-weight: 500;
  width: 32px; min-width: 32px; text-align: center;
  padding: 4px; border-right: 1px solid var(--line-2); border-bottom: 1px solid var(--line);
  user-select: none; cursor: pointer;
  transition: color .15s, background .15s;
}
tbody th.sg-rowhead:hover { background: var(--ink-wash); color: var(--fg); }
table.sg thead th.sg-rowhead { z-index: 5; cursor: default; }

table.sg td {
  padding: 4px 9px; height: 31px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 320px; position: relative;
  cursor: cell;
}
table.sg td.num { text-align: right; }
table.sg td.sg-calc { background: var(--surface-2); color: var(--fg-2); cursor: default; }
table.sg tbody tr:hover td { background: var(--surface-2); }
table.sg tbody tr:hover td.sg-calc { background: var(--surface-3); }

table.sg td.sg-sel { background: var(--ink-wash) !important; }
table.sg td.sg-active {
  box-shadow: inset 0 0 0 1.5px var(--ink);
  background: var(--surface) !important;
  z-index: 1; border-radius: 1px;
}
table.sg td.sg-active.sg-calc { background: var(--surface-2) !important; }
table.sg td.sg-editing { padding: 0; box-shadow: inset 0 0 0 1.5px var(--ink); }
table.sg td.sg-nope { animation: sgNope .26s var(--ease); }
@keyframes sgNope { 0%,100%{background:var(--surface-2)} 50%{background:var(--danger-bg)} }

table.sg td.warn-cell { background: var(--warn-bg) !important; color: var(--warn); }
table.sg td.err-cell  { background: var(--danger-bg) !important; color: var(--danger); }
table.sg tr.row-warn th.sg-rowhead { background: var(--warn-bg); color: var(--warn); }
table.sg tr.row-err  th.sg-rowhead { background: var(--danger-bg); color: var(--danger); }

.sg-input {
  width: 100%; height: 31px; border: 0; outline: none;
  padding: 4px 8px; background: var(--surface); color: var(--fg);
  font: inherit; font-size: 12.5px;
}
input.sg-input[inputmode="decimal"] {
  font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right;
}
select.sg-input { cursor: pointer; font-family: var(--font); }

.sg-del { width: 30px; min-width: 30px; text-align: center; padding: 0 !important; border-right: 0 !important; }
.sg-delbtn {
  width: 22px; height: 22px; border: 0; border-radius: var(--r-xs);
  background: transparent; color: var(--fg-4); cursor: pointer;
  display: inline-grid; place-items: center;
  transition: background .15s, color .15s, opacity .15s; opacity: 0;
}
table.sg tbody tr:hover .sg-delbtn { opacity: 1; }
.sg-delbtn:hover { background: var(--danger-bg); color: var(--danger); }
.sg-delbtn:focus-visible { opacity: 1; outline: none; box-shadow: var(--focus-ring); }

.sg-empty { text-align: center; color: var(--fg-3); padding: 34px 24px !important; font-size: 12.5px; }
.sg-add {
  margin-top: 8px; width: 100%;
  padding: 8px; border: 1px dashed var(--line-2); border-radius: var(--r-sm);
  background: transparent; color: var(--fg-2);
  font: inherit; font-size: 12px; cursor: pointer;
  transition: border-color .16s var(--ease), color .16s var(--ease), background .16s var(--ease);
}
.sg-add:hover { border-color: var(--line-3); color: var(--fg); background: var(--surface-2); }
.sg-add:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.sg-toast {
  position: absolute; bottom: 46px; left: 50%; transform: translate(-50%, 6px);
  background: var(--ink); color: var(--on-ink);
  padding: 5px 12px; border-radius: var(--r-pill); font-size: 11.5px; font-weight: 500;
  opacity: 0; pointer-events: none;
  transition: opacity .18s var(--ease), transform .18s var(--ease);
  z-index: var(--z-toast); white-space: nowrap; box-shadow: var(--lift-2);
}
.sg-toast.on { opacity: 1; transform: translate(-50%, 0); }

/* keyboard legend */
.keys { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 11px; color: var(--fg-2); align-items: center; }
.keys span { display: inline-flex; align-items: center; gap: 5px; }
kbd {
  font-size: 9.5px; font-weight: 500;
  background: var(--surface); border: 1px solid var(--line-2);
  border-bottom-width: 2px; border-radius: var(--r-xs);
  padding: 1px 5px; color: var(--fg-2);
}

/* ----------------------------------------------------------- toolbar --- */
.toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 11px 18px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.toolbar .sep { width: 1px; height: 18px; background: var(--line-2); margin: 0 3px; }

.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--line); padding: 0 16px; background: var(--surface); }
.tab {
  padding: 11px 14px; border: 0; background: transparent;
  font: inherit; font-size: 12.5px; font-weight: 500; color: var(--fg-3);
  cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: color .16s var(--ease), border-color .16s var(--ease);
}
.tab:hover { color: var(--fg); }
.tab.active { color: var(--fg); border-bottom-color: var(--ink); font-weight: 600; }
.tab:focus-visible { outline: none; box-shadow: inset var(--focus-ring); }

/* ------------------------------------------------------------ banners -- */
.banner {
  display: flex; align-items: flex-start; gap: 9px;
  padding: 10px 13px; border-radius: var(--r-sm); font-size: 12px;
  border: 1px solid transparent; line-height: 1.5;
}
.banner svg { width: 14px; height: 14px; flex: 0 0 auto; margin-top: 1.5px; opacity: .9; }
.banner.warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-line); }
.banner.err  { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-line); }
.banner.ok   { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-line); }
.banner.info { background: var(--surface-2); color: var(--fg-2); border-color: var(--line); }
.banner.info svg { color: var(--fg-3); }
.banner b { color: var(--fg); }
.banner.warn b { color: var(--warn); } .banner.err b { color: var(--danger); }

/* ------------------------------------------------- dropdown menu ------- */
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px);
  min-width: 210px; padding: 5px;
  background: var(--surface); border-radius: var(--r);
  box-shadow: var(--lift-3);
  z-index: var(--z-sticky);
  animation: menuIn .16s var(--ease-out);
  transform-origin: top right;
}
:root[data-theme="dark"] .menu { border: 1px solid var(--line-2); }
@keyframes menuIn { from { opacity: 0; transform: scale(.97) translateY(-3px) } to { opacity: 1; transform: none } }
.menu[hidden] { display: none; }
.menu button {
  display: flex; align-items: center; gap: 9px;
  width: 100%; text-align: left;
  padding: 7px 9px; border: 0; border-radius: var(--r-xs);
  background: transparent; color: var(--fg);
  font: inherit; font-size: 12.5px; cursor: pointer;
  transition: background .13s var(--ease);
}
.menu button svg { width: 14px; height: 14px; opacity: .65; flex: 0 0 auto; }
.menu button:hover { background: var(--surface-2); }
.menu button:focus-visible { outline: none; box-shadow: inset var(--focus-ring); }
.menu button.danger { color: var(--danger); }
.menu button.danger:hover { background: var(--danger-bg); }
.menu-sep { height: 1px; background: var(--line); margin: 4px 0; }

/* collapsible warning */
.warn-toggle {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 0; border: 0; background: transparent;
  color: inherit; font: inherit; font-size: 12px; cursor: pointer; text-align: left;
}
.warn-toggle .muted { margin-left: auto; color: inherit; opacity: .7; text-decoration: underline; text-underline-offset: 2px; }
.warn-toggle:focus-visible { outline: 1.5px solid currentColor; outline-offset: 2px; border-radius: 2px; }

.select.sm { font-size: 12px; }

/* ------------------------------------------------------------- modal --- */
.scrim {
  position: fixed; inset: 0;
  background: color-mix(in srgb, var(--fg) 42%, transparent);
  backdrop-filter: blur(3px) saturate(.9);
  z-index: var(--z-modal); display: grid; place-items: center;
  padding: 20px;
  animation: fadeIn .18s var(--ease);
}
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
.modal {
  background: var(--surface); border-radius: var(--r-lg);
  box-shadow: var(--lift-3);
  width: min(740px, 100%); max-height: 88vh; display: flex; flex-direction: column;
  animation: modalIn .24s var(--ease-out);
}
:root[data-theme="dark"] .modal, :root[data-theme="dark"] .drawer { border: 1px solid var(--line-2); }
.modal.wide { width: min(1160px, 100%); }
.modal.narrow { width: min(440px, 100%); }
@keyframes modalIn { from { opacity: 0; transform: translateY(10px) scale(.985) } to { opacity: 1; transform: none } }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-title { font-size: 14.5px; font-weight: 700; letter-spacing: -.012em; flex: 1 1 auto; }
.modal-body { padding: 18px; overflow-y: auto; flex: 1 1 auto; }
.modal-foot {
  display: flex; align-items: center; gap: 8px; justify-content: flex-end;
  padding: 13px 18px; border-top: 1px solid var(--line); background: var(--surface-2);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
}

/* ------------------------------------------------------------ drawer --- */
.drawer-scrim {
  position: fixed; inset: 0;
  background: color-mix(in srgb, var(--fg) 38%, transparent);
  backdrop-filter: blur(2px);
  z-index: var(--z-drawer); animation: fadeIn .18s var(--ease);
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(700px, 96vw);
  background: var(--surface);
  box-shadow: var(--lift-3); z-index: calc(var(--z-drawer) + 1);
  display: flex; flex-direction: column;
  animation: drawerIn .26s var(--ease-out);
}
@keyframes drawerIn { from { transform: translateX(28px); opacity: .3 } to { transform: none; opacity: 1 } }
.drawer-head { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.drawer-body { flex: 1 1 auto; overflow-y: auto; padding: 18px; }
.drawer-foot { padding: 13px 18px; border-top: 1px solid var(--line); background: var(--surface-2); display: flex; gap: 8px; justify-content: flex-end; }

/* ------------------------------------------------------------- toast --- */
.toaster { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: var(--z-toast); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.tmsg {
  background: var(--ink); color: var(--on-ink);
  padding: 9px 15px; border-radius: var(--r-pill); font-size: 12.5px; font-weight: 500;
  box-shadow: var(--lift-3); display: flex; align-items: center; gap: 8px;
  animation: toastIn .24s var(--ease-out);
  pointer-events: auto; max-width: 90vw;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(8px) } to { opacity: 1; transform: none } }
.tmsg.err { background: var(--danger); color: #fff; }
.tmsg.ok  { background: var(--ok); color: #fff; }
:root[data-theme="dark"] .tmsg.err, :root[data-theme="dark"] .tmsg.ok { color: #0C0E11; }
.tmsg svg { width: 14px; height: 14px; }

/* --------------------------------------------------------- empty state - */
.empty { text-align: center; padding: 44px 24px; color: var(--fg-3); }
.empty > svg { width: 30px; height: 30px; opacity: .3; margin-bottom: 14px; }
.empty h3 { font-size: 13.5px; font-weight: 700; color: var(--fg-2); margin: 0 0 5px; letter-spacing: -.01em; }
.empty p { font-size: 12.5px; margin: 0 auto 16px; max-width: 46ch; line-height: 1.55; }

/* ----------------------------------------------------------- summary --- */
.sumbar {
  display: flex; align-items: stretch;
  border-top: 1px solid var(--line); background: var(--surface);
  flex: 0 0 auto; overflow-x: auto;
}
.sumcell { padding: 10px 18px; border-right: 1px solid var(--line); min-width: 108px; }
.sumcell:last-child { border-right: 0; }
.sumcell .l {
  font-family: var(--mono);
  font-size: 9px; font-weight: 500; letter-spacing: .13em; text-transform: uppercase; color: var(--fg-3);
}
.sumcell .v {
  font-family: var(--mono); font-variant-numeric: tabular-nums;
  font-size: 15px; font-weight: 600; margin-top: 3px; letter-spacing: -.025em;
}
.sumcell.hero { background: var(--gold-wash); border-left: 1px solid var(--gold-line); }
.sumcell.hero .l { color: var(--gold); }
.sumcell.hero .v { color: var(--gold); font-size: 19px; }
.sumcell.grow { flex: 1 1 auto; min-width: 0; }

/* the one authored moment: money moved */
.sumcell.hero .v.changed { animation: valueLand .5s var(--ease-out); }
@keyframes valueLand {
  0%   { color: var(--gold-bright); transform: translateY(-2px); }
  100% { color: var(--gold); transform: none; }
}

/* ------------------------------------------------------------ pipeline - */
.pipe { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.pipe-col { flex: 1 1 0; min-width: 122px; background: var(--surface-2); border-radius: var(--r-sm); padding: 11px 12px; }
.pipe-col .h { font-family: var(--mono); font-size: 9px; font-weight: 500; text-transform: uppercase; letter-spacing: .12em; color: var(--fg-3); }
.pipe-col .n { font-family: var(--mono); font-size: 21px; font-weight: 600; margin-top: 5px; letter-spacing: -.03em; line-height: 1; }
.pipe-col .a { font-family: var(--mono); font-size: 11px; color: var(--fg-3); margin-top: 3px; }
.pipe-bar { height: 2px; border-radius: 1px; margin-top: 9px; background: var(--line-2); overflow: hidden; }
.pipe-bar i { display: block; height: 100%; background: var(--ink); transition: width .4s var(--ease-out); }

/* --------------------------------------------------------- follow-ups -- */
.fu { display: flex; align-items: flex-start; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line); transition: background .14s var(--ease); }
.fu:last-child { border-bottom: 0; }
.fu:hover { background: var(--surface-2); }
.fu.overdue { box-shadow: inset 2px 0 0 var(--danger); }
.fu.today   { box-shadow: inset 2px 0 0 var(--gold-mid); }
.fu.done    { opacity: .45; }
.fu-check {
  width: 19px; height: 19px; border-radius: 50%; border: 1.5px solid var(--line-3);
  background: transparent; cursor: pointer; flex: 0 0 auto; margin-top: 2px;
  display: grid; place-items: center; color: transparent;
  transition: border-color .16s var(--ease), background .16s var(--ease), color .16s var(--ease);
}
.fu-check:hover { border-color: var(--ok); }
.fu-check.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.fu-check:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.fu-check svg { width: 11px; height: 11px; }
.fu-main { flex: 1 1 auto; min-width: 0; }
.fu-title { font-size: 12.5px; font-weight: 600; }
.fu-meta { font-size: 11.5px; color: var(--fg-3); display: flex; gap: 12px; flex-wrap: wrap; margin-top: 3px; align-items: center; }
.fu-meta svg { width: 11px; height: 11px; opacity: .7; }
.fu-note { font-size: 12px; color: var(--fg-2); margin-top: 5px; }
.fu-actions { display: flex; gap: 3px; flex: 0 0 auto; }

/* --------------------------------------------------------------- misc -- */
.split { display: grid; grid-template-columns: 1fr 330px; gap: 14px; align-items: start; }
@media (max-width: 1100px) { .split { grid-template-columns: 1fr; } }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 7px 14px; font-size: 12.5px; align-items: center; }
.kv dt { color: var(--fg-3); }
.kv dd { margin: 0; text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -.015em; }
.kv dd.txt { font-family: var(--font); letter-spacing: 0; }
.kv .hr { grid-column: 1 / -1; height: 1px; background: var(--line); margin: 3px 0; }
.kv .big { font-size: 16px; font-weight: 700; color: var(--gold); letter-spacing: -.03em; }
.kv dt.big { font-family: var(--font); letter-spacing: -.01em; }

.chipset { display: flex; gap: 5px; flex-wrap: wrap; }
.chip {
  padding: 4px 11px; border-radius: var(--r-pill); border: 1px solid var(--line-2);
  background: var(--surface); color: var(--fg-2);
  font: inherit; font-size: 11.5px; font-weight: 500; cursor: pointer;
  transition: border-color .16s var(--ease), color .16s var(--ease), background .16s var(--ease);
}
.chip:hover { border-color: var(--line-3); color: var(--fg); }
.chip.on { background: var(--ink); border-color: var(--ink); color: var(--on-ink); font-weight: 600; }
.chip:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.search { position: relative; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 14px; height: 14px; color: var(--fg-4); pointer-events: none; }
.search .input { padding-left: 31px; }

.bom-tbl td.lvl2 { padding-left: 28px; color: var(--fg-3); font-size: 11.5px; }
.bom-tbl tr.ovr td { background: var(--warn-bg); }
.bom-tbl td:first-child { white-space: nowrap; width: 1%; padding-right: 6px; }
.bom-tbl td:first-child .sect { margin: -2px 0; }

.progress { height: 4px; border-radius: 2px; background: var(--surface-3); overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--ink); transition: width .4s var(--ease-out); }

.scrap-bar { display: flex; height: 16px; border-radius: var(--r-xs); overflow: hidden; background: var(--surface-3); }
.scrap-bar i { display: block; height: 100%; }
.scrap-bar .used { background: var(--ink); }
.scrap-bar .scrap { background: repeating-linear-gradient(135deg, var(--line-2) 0 4px, var(--surface-3) 4px 8px); }

/* ------------------------------------------------- section drawings ---- */
/* The signature. Every catalogue in this trade is pages of extrusion
   cross-sections; the rate book should look like one. */
.sect {
  display: block; width: 46px; height: 30px; flex: 0 0 auto;
  color: var(--fg-3);
}
.sect .fill { fill: currentColor; opacity: .13; }
.sect .cut  { fill: none; stroke: currentColor; stroke-width: 1.35; stroke-linejoin: round; opacity: .85; }
.sect-cell { display: flex; align-items: center; gap: 10px; }
td .sect { width: 40px; height: 26px; }
.sect-lg { width: 96px; height: 62px; }
.sect-plate {
  display: inline-grid; place-items: center;
  width: 54px; height: 36px; border-radius: var(--r-xs);
  background: var(--surface-2); border: 1px solid var(--line);
  flex: 0 0 auto;
}
.sect-plate .sect { width: 42px; height: 28px; }

/* --------------------------------------------------------------- print - */
@media print {
  body { overflow: visible; background: #fff; }
  .side, .topbar, .toolbar, .no-print, .sg-add, .toaster, .sumbar { display: none !important; }
  .app { display: block; height: auto; }
  .view { overflow: visible; padding: 0; }
  .card { border: 0; }
  .print-only { display: block !important; }
}
.print-only { display: none; }

/* -------------------------------------------------------------- motion - */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important; scroll-behavior: auto !important;
  }
}

/* ------------------------------------------------------------ responsive */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side {
    position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar-w);
    transform: translateX(-100%); transition: transform .24s var(--ease-out);
  }
  .side.open { transform: none; box-shadow: var(--lift-3); }
  .view { padding: 14px; }
  .split { grid-template-columns: 1fr; }
  .toolbar { padding: 10px 14px; }
}

/* The topbar is a fixed-height rail. On narrow screens the strap line and the
   full rate label would wrap it open, so both step down instead. */
@media (max-width: 640px) {
  .topbar { padding: 0 12px; gap: 8px; }
  .page-title { font-size: 14px; }
  .page-sub { display: none; }
  .rate-chip { padding: 5px 8px; }
  .rate-chip .rate-word { display: none; }   /* "/kg" stays — a bare number means nothing */
  .sumcell { padding: 9px 13px; min-width: 92px; }
  .sumcell .v { font-size: 14px; }
  .sumcell.hero .v { font-size: 16px; }
  .fu { padding: 12px 14px; }
  .fu-actions { flex-wrap: wrap; justify-content: flex-end; max-width: 60px; }
  .modal-foot, .drawer-foot { flex-wrap: wrap; }
}
.menu-btn { display: none; }
@media (max-width: 860px) { .menu-btn { display: inline-flex; } }
