/* CostingPro UI — brand colours come from each customer's branding as CSS variables. */
:root {
  --brand: #24445F; --brand-ink: #fff; --brand-soft: #e3eaf0; --brand-dark: #1d3649;
  --accent: #B25A24; --accent-ink: #fff; --accent-soft: #f6e6da;
  --bg: #eef1f4; --panel: #fff; --panel-2: #f6f8fa; --line: #d6dce3; --line-2: #e8ecf0;
  --fg: #17212b; --muted: #5b6876; --faint: #8794a1;
  --up: #b3261e; --up-soft: #fbe4e1; --down: #1d7a46; --down-soft: #ddf2e5; --warn: #8a6100; --warn-soft: #fbf0d2;
  --f-display: "Barlow Semi Condensed", "Arial Narrow", Arial, sans-serif;
  --f-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font: 14px/1.5 var(--f-body); }
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--f-display); font-weight: 600; margin: 0; line-height: 1.15; text-wrap: balance; }
h1 { font-size: 28px; } h2 { font-size: 20px; } h3 { font-size: 16px; }
.num, .mono { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.eyebrow { font: 600 11px/1 var(--f-body); letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.muted { color: var(--muted); } .small { font-size: 12.5px; }
.up { color: var(--up); } .down { color: var(--down); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Shell */
.shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; overflow: auto; padding: 18px 12px; display: flex; flex-direction: column; gap: 14px;
  background: var(--panel); border-right: 1px solid var(--line); }
.side.dark { background: #141c24; border-color: #141c24; --side-fg: #dbe3ea; --side-muted: #8d9aa7; --side-hover: #1f2a35; }
.side.brand { background: var(--brand); border-color: var(--brand); --side-fg: var(--brand-ink); --side-muted: color-mix(in srgb, var(--brand-ink) 65%, transparent); --side-hover: color-mix(in srgb, var(--brand-ink) 12%, transparent); }
.side.dark, .side.brand { color: var(--side-fg); }
.logo { display: flex; align-items: center; gap: 10px; padding: 2px 8px 8px; text-decoration: none; color: inherit; min-width: 0; }
.logo img { max-height: 38px; max-width: 150px; object-fit: contain; }
.logo-mark { width: 34px; height: 34px; border-radius: 8px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font: 700 15px var(--f-display); flex: none; }
.side.brand .logo-mark { background: var(--brand-ink); color: var(--brand); }
.logo b { font: 700 17px/1.1 var(--f-display); display: block; overflow: hidden; text-overflow: ellipsis; }
.logo small { color: var(--muted); font-size: 11.5px; display: block; }
.side.dark .logo small, .side.brand .logo small { color: var(--side-muted); }
.nav { display: flex; flex-direction: column; gap: 1px; }
.nav .grp { margin: 12px 10px 4px; font: 600 10.5px var(--f-body); letter-spacing: .09em; text-transform: uppercase; color: var(--faint); }
.side.dark .nav .grp, .side.brand .nav .grp { color: var(--side-muted); }
.nav a { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 7px; color: inherit; text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--panel-2); }
.side.dark .nav a:hover, .side.brand .nav a:hover { background: var(--side-hover); }
.nav a.on { background: var(--brand-soft); color: var(--brand-dark); }
.side.dark .nav a.on { background: var(--brand); color: var(--brand-ink); }
.side.brand .nav a.on { background: var(--brand-ink); color: var(--brand); }
.nav .badge { background: var(--accent); color: var(--accent-ink); border-radius: 999px; font: 600 11px/1 var(--f-body); padding: 3px 7px; }
.side-foot { margin-top: auto; font-size: 12px; color: var(--muted); padding: 0 8px; }
.side.dark .side-foot, .side.brand .side-foot { color: var(--side-muted); }

.main { min-width: 0; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 28px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; }
.top .who { display: flex; align-items: center; gap: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font: 600 12px var(--f-body); }
.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px; }
.menu > summary::-webkit-details-marker { display: none; }
.menu .drop { position: absolute; right: 0; top: calc(100% + 6px); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(23,33,43,.12); min-width: 200px; padding: 6px; z-index: 10; }
.menu .drop a, .menu .drop button { display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: 6px; border: 0; background: none; color: var(--fg); text-decoration: none; cursor: pointer; }
.menu .drop a:hover, .menu .drop button:hover { background: var(--panel-2); }
.content { padding: 24px 28px 48px; flex: 1; }
.foot { padding: 14px 28px; color: var(--faint); font-size: 12px; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; border-top: 1px solid var(--line-2); }
.banner { background: var(--warn-soft); color: var(--warn); padding: 8px 28px; font-weight: 500; display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.menu-btn { display: none; }

.banner a { color: inherit; font-weight: 600; }
.banner.ann-info { background: var(--brand-soft); color: var(--brand-dark); }
.banner.ann-success { background: var(--down-soft); color: var(--down); }
.banner.ann-warn { background: var(--warn-soft); color: var(--warn); }
.plan-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; }
.plan-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 10px; background: var(--panel); }
.plan-card.current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.plan-card .price { font: 600 26px/1.1 var(--f-display); }
.plan-card ul { margin: 0; padding-left: 18px; color: var(--muted); font-size: 12.5px; }
.gw-list { display: grid; gap: 10px; }
.gw { display: flex; gap: 12px; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; cursor: pointer; background: var(--panel); }
.gw:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.inv { max-width: 860px; }
.inv-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.inv-parties { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.qr { width: 220px; height: 220px; background: #fff; padding: 10px; border-radius: 8px; border: 1px solid var(--line); }
.links-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.link-card { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; text-decoration: none; color: inherit; background: var(--panel); display: flex; flex-direction: column; gap: 4px; }
.link-card:hover { border-color: var(--brand); }

/* Page head */
.head { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: flex-end; justify-content: space-between; margin-bottom: 18px; }
.head p { margin: 6px 0 0; color: var(--muted); max-width: 72ch; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* Surfaces */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.card.pad { padding: 18px; }
.card-h { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; }
.card-b { padding: 18px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.split { display: grid; grid-template-columns: minmax(0, 340px) minmax(0, 1fr); gap: 16px; align-items: start; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 14px 16px; }
.kpi .v { font: 600 26px/1.1 var(--f-display); margin-top: 6px; }
.kpi .s { font-size: 12px; color: var(--muted); }

/* Buttons & forms */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); padding: 7px 13px; border-radius: 7px; cursor: pointer; font-weight: 500; text-decoration: none; color: var(--fg); white-space: nowrap; }
.btn:hover { border-color: var(--faint); }
.btn.pri { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.brand { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.pri:hover, .btn.brand:hover { filter: brightness(1.07); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger { color: var(--up); border-color: var(--up-soft); }
.btn.danger:hover { background: var(--up); color: #fff; }
.btn.sm { padding: 4px 10px; font-size: 12.5px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); font-weight: 500; min-width: 0; }
.in { width: 100%; border: 1px solid var(--line); background: var(--panel); border-radius: 7px; padding: 7px 10px; min-width: 0; }
.in:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.in.num { text-align: right; }
.in[readonly], .in:disabled { background: var(--panel-2); color: var(--muted); }
textarea.in { resize: vertical; }
.frow { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 500; }
.check input { margin-top: 3px; }
.hint { font-size: 12px; color: var(--muted); font-weight: 400; }
.err { color: var(--up); font-size: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 6px 12px; font-weight: 500; color: var(--muted); background: var(--panel); }
.seg input:checked + span { background: var(--brand); color: var(--brand-ink); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar .in { max-width: 280px; }

/* Tables */
.tw { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.t th { font: 600 11px var(--f-body); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); background: var(--panel-2); white-space: nowrap; }
.t td { padding: 9px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.t tr:last-child td { border-bottom: 0; }
.t .r { text-align: right; }
.t tfoot td { font-weight: 600; border-top: 1px solid var(--line); background: var(--panel-2); }
.t tr.link { cursor: pointer; } .t tr.link:hover td { background: var(--panel-2); }
.t a.row-link { color: inherit; text-decoration: none; font-weight: 600; }
.t a.row-link:hover { color: var(--brand); text-decoration: underline; }
.code { font: 500 12px var(--f-mono); color: var(--brand); }
.pill { display: inline-block; font: 600 11px/1 var(--f-body); padding: 4px 8px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--down-soft); color: var(--down); border-color: transparent; }
.pill.bad { background: var(--up-soft); color: var(--up); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.brand { background: var(--brand-soft); color: var(--brand-dark); border-color: transparent; }
.pill.acc { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.delta { font: 500 12px var(--f-mono); padding: 2px 6px; border-radius: 5px; white-space: nowrap; }
.delta.up { background: var(--up-soft); } .delta.down { background: var(--down-soft); }
.empty { padding: 36px 20px; text-align: center; color: var(--muted); }
.empty h3 { color: var(--fg); margin-bottom: 6px; }

/* Alerts */
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-weight: 500; }
.alert.ok { background: var(--down-soft); color: var(--down); }
.alert.bad { background: var(--up-soft); color: var(--up); }
.alert.info { background: var(--brand-soft); color: var(--brand-dark); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert ul { margin: 4px 0 0; padding-left: 18px; font-weight: 400; }

/* Cost sheet */
.sheet-sec { border-bottom: 1px solid var(--line-2); }
.sheet-sec summary { list-style: none; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; padding: 11px 18px; font-weight: 600; }
.sheet-sec summary::-webkit-details-marker { display: none; }
.sheet-sec summary .chev { display: inline-block; transition: transform .15s; color: var(--faint); margin-right: 6px; }
.sheet-sec[open] summary .chev { transform: rotate(90deg); }
.ledger { padding: 6px 18px 16px; }
.ledger .row { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px dashed var(--line-2); }
.ledger .row span:first-child { color: var(--muted); }
.ledger .row.sum { border-bottom: 0; border-top: 2px solid var(--fg); margin-top: 4px; padding-top: 10px; font-weight: 600; }
.ledger .row.sum span:first-child { color: var(--fg); }
.band { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: 1px solid var(--line); }
.band > div { padding: 14px 18px; border-right: 1px solid var(--line); }
.band > div:last-child { border-right: 0; }
.band .v { font: 600 24px/1.1 var(--f-display); margin-top: 4px; }
.band .hl { background: var(--accent-soft); }
.band .hl .v { color: var(--accent); }
.bar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: var(--line-2); margin: 4px 18px 10px; }
.bar i { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 0 18px 14px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

/* BOM editor */
.bom td { padding: 5px 6px; }
.bom .in { padding: 5px 8px; }
.bom select.in { min-width: 240px; }
.bom .in.num { width: 96px; }

/* Permissions matrix */
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.perm-grp { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.perm-grp h3 { margin-bottom: 8px; }
.perm-grp .check { padding: 4px 0; }
.feat-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line-2); }
.feat-row:last-child { border-bottom: 0; }

/* Tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; text-decoration: none; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--fg); border-color: var(--accent); }

/* Branding preview */
.swatch { width: 38px; height: 38px; border-radius: 8px; border: 1px solid var(--line); padding: 0; cursor: pointer; }
.preview { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; display: grid; grid-template-columns: 120px 1fr; min-height: 180px; }
.preview .pv-side { padding: 12px; display: flex; flex-direction: column; gap: 6px; font-size: 12px; }
.preview .pv-main { padding: 14px; background: var(--bg); display: flex; flex-direction: column; gap: 10px; }

/* Auth */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 460px); }
.auth-art { background: var(--brand); color: var(--brand-ink); padding: 48px; display: flex; flex-direction: column; justify-content: space-between; gap: 24px; position: relative; overflow: hidden; }
.auth-art h1 { font-size: 40px; max-width: 16ch; }
.auth-art p { max-width: 46ch; opacity: .85; font-size: 15px; }
.auth-art .rings { position: absolute; right: -120px; bottom: -120px; width: 420px; height: 420px; border-radius: 50%; border: 40px solid color-mix(in srgb, var(--accent) 55%, transparent); opacity: .5; }
.auth-form { background: var(--panel); padding: 48px 40px; display: flex; flex-direction: column; justify-content: center; gap: 18px; }
.auth-form .logo { padding: 0; }

/* Print: a clean costing sheet for quotations */
@media print {
  .side, .top, .foot, .banner, .no-print, .actions { display: none !important; }
  .shell { display: block; } .content { padding: 0; } body { background: #fff; }
  .card { border: 0; } .print-only { display: block !important; }
  .sheet-sec { break-inside: avoid; } details.sheet-sec > *:not(summary) { display: block; }
}
.print-only { display: none; }

@media (max-width: 1100px) { .split { grid-template-columns: minmax(0, 1fr); } .grid3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 30; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .menu-btn { display: inline-flex; }
  .top, .content, .foot, .banner { padding-left: 16px; padding-right: 16px; }
  .grid2, .grid3, .inv-parties { grid-template-columns: minmax(0, 1fr); }
  .band { grid-template-columns: minmax(0, 1fr); } .band > div { border-right: 0; border-bottom: 1px solid var(--line); }
  .auth { grid-template-columns: minmax(0, 1fr); } .auth-art { padding: 28px; } .auth-art h1 { font-size: 28px; }
  .auth-form { padding: 28px 16px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
