:root {
  --brand: #2457d6;
  --bg: #f4f5f7; --surface: #fff; --line: #e1e4ea; --line-strong: #cdd2db;
  --ink: #1b2330; --ink-2: #4b5565; --ink-3: #7a8494;
  --side: #161c27; --side-ink: #aab3c2; --side-hover: #222b3a;
  --good: #1a7f4b; --good-bg: #e3f4ea; --warn: #9a6200; --warn-bg: #fdf0d3; --bad: #b3261e; --bad-bg: #fbe6e4;
  --info-bg: #e6edfb; --mute-bg: #eceef2;
  --radius: 8px; --shadow: 0 1px 2px rgba(20, 28, 45, .06), 0 1px 1px rgba(20, 28, 45, .04);
  font: 14px/1.45 Inter, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 21px; } h2 { font-size: 15px; } h3 { font-size: 13px; }
.muted { color: var(--ink-3); } .small { font-size: 12px; } .r { text-align: right; } .nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.hidden { display: none !important; }

/* ---- Shell ---- */
.shell { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 16px 16px 12px; color: #fff; font-weight: 700; font-size: 15px; }
.brand .logo { width: 28px; height: 28px; border-radius: 7px; background: var(--brand); display: grid; place-items: center; }
.brand .logo svg { width: 16px; height: 16px; stroke: #fff; }
.nav-group { padding: 10px 16px 4px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em; color: #6d788a; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 7px 12px; margin: 1px 8px; border-radius: 6px; color: var(--side-ink); font-weight: 500; }
.nav a:hover { background: var(--side-hover); color: #fff; text-decoration: none; }
.nav a.active { background: var(--brand); color: #fff; }
.nav svg, .btn svg, .topbar svg { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.side-foot { margin-top: auto; padding: 12px 16px; font-size: 12px; border-top: 1px solid #252e3d; }
.side-foot b { color: #fff; display: block; }
.side-foot a { color: var(--side-ink); cursor: pointer; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar .loc { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.topbar .loc select { font-weight: 600; border-color: var(--line-strong); min-width: 190px; }
.topbar .spacer { flex: 1; }
.view { padding: 22px 24px 60px; max-width: 1440px; width: 100%; }
.page-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .titles { flex: 1; min-width: 200px; }
.page-head .sub { color: var(--ink-3); margin-top: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---- Controls ---- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 6px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f7f8fa; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); background: var(--brand); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 8px; font-size: 12.5px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; color: inherit; padding: 7px 9px; border: 1px solid var(--line-strong); border-radius: 6px; background: #fff; width: 100%; }
input[type=checkbox], input[type=radio] { width: auto; }
input[type=color] { padding: 2px; height: 34px; width: 60px; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid color-mix(in srgb, var(--brand) 45%, transparent); outline-offset: 1px; border-color: var(--brand); }
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; align-items: center; }
.toolbar input[type=search] { max-width: 280px; }
.toolbar select { width: auto; }

/* ---- Surfaces ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card > .card-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.card > .card-head h2 { flex: 1; }
.card > .card-body { padding: 14px 16px; }
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); }
.cols-eq { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); align-items: start; }
.stack > * + * { margin-top: 16px; }
table.data { width: 100%; border-collapse: collapse; }
table.data th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); font-weight: 600; padding: 9px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #fafbfc; }
table.data td { padding: 9px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr.click { cursor: pointer; }
table.data tbody tr.click:hover { background: #f6f8fc; }
table.data th.r, table.data td.r { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.r:last-child { white-space: nowrap; }
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
.empty { padding: 34px 16px; text-align: center; color: var(--ink-3); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--mute-bg); color: var(--ink-2); white-space: nowrap; }
.badge.good { background: var(--good-bg); color: var(--good); } .badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); } .badge.info { background: var(--info-bg); color: var(--brand); }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; }
.kv dt { color: var(--ink-3); } .kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.banner { padding: 10px 14px; border-radius: var(--radius); background: var(--warn-bg); color: #6b4500; margin-bottom: 14px; border: 1px solid #f1dca6; }
.banner.info { background: var(--info-bg); color: #1d3f94; border-color: #c9d8f7; }

/* ---- Forms / modal ---- */
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.field { grid-column: span 2; min-width: 0; } .field.half { grid-column: span 1; }
.field > label { display: block; font-weight: 600; font-size: 12.5px; margin-bottom: 4px; }
.field .help { color: var(--ink-3); font-size: 12px; margin-top: 3px; }
.field .check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.field .checks { display: grid; gap: 4px; }
.form .section { grid-column: span 2; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); border-bottom: 1px solid var(--line); padding-bottom: 4px; margin-top: 6px; }
.overlay { position: fixed; inset: 0; background: rgba(15, 20, 30, .45); display: grid; place-items: start center; padding: 6vh 16px; overflow-y: auto; z-index: 50; }
.modal { background: var(--surface); border-radius: 10px; width: min(620px, 100%); box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.modal.wide { width: min(960px, 100%); }
.modal-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { flex: 1; font-size: 16px; }
.modal-body { padding: 16px 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); background: #fafbfc; border-radius: 0 0 10px 10px; }
.toasts { position: fixed; bottom: 18px; right: 18px; display: grid; gap: 8px; z-index: 100; }
.toast { background: #1b2330; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); max-width: 380px; }
.toast.error { background: var(--bad); }

/* ---- Line items ---- */
.items td { padding: 6px 6px; } .items td:first-child { padding-left: 14px; }
.items input, .items select { padding: 5px 7px; }
.items .num { width: 92px; text-align: right; }
.items .opts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.items .opts select { width: auto; font-size: 12.5px; }
.totals { margin-left: auto; width: 300px; display: grid; grid-template-columns: 1fr auto; gap: 5px 16px; padding: 12px 16px; font-variant-numeric: tabular-nums; }
.totals .grand { font-weight: 700; font-size: 16px; border-top: 1px solid var(--line-strong); padding-top: 6px; }
.totals input { width: 90px; text-align: right; padding: 3px 6px; }

/* ---- Workflow tracker ---- */
.track { display: flex; gap: 4px; margin: 4px 0 18px; flex-wrap: wrap; }
.track .step { flex: 1; min-width: 110px; padding: 8px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; position: relative; }
.track .step .lbl { font-weight: 600; font-size: 13px; } .track .step .st { font-size: 11.5px; color: var(--ink-3); }
.track .step.done { background: var(--good-bg); border-color: #bfe3cd; } .track .step.done .st { color: var(--good); }
.track .step.current { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); background: var(--info-bg); } .track .step.current .st { color: var(--brand); font-weight: 600; }
.track .step.skipped { background: repeating-linear-gradient(135deg, #f4f5f7, #f4f5f7 6px, #eceef2 6px, #eceef2 12px); color: var(--ink-3); }
.track .step.skipped .lbl { text-decoration: line-through; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 8px 0 8px 16px; border-left: 2px solid var(--line); margin-left: 4px; position: relative; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: 14px; width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); }
.timeline li.stage::before { background: var(--brand); } .timeline li.skip::before { background: var(--warn); }

/* ---- Board ---- */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(230px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; align-items: start; }
.lane { background: #e9ecf1; border-radius: var(--radius); padding: 8px; min-height: 220px; }
.lane.over { outline: 2px dashed var(--brand); }
.lane-head { display: flex; justify-content: space-between; padding: 4px 6px 8px; font-weight: 650; }
.ticket { background: var(--surface); border-radius: 6px; padding: 10px; margin-bottom: 8px; box-shadow: var(--shadow); border-left: 3px solid var(--line-strong); cursor: grab; }
.ticket.in_progress { border-left-color: var(--brand); } .ticket.late { border-left-color: var(--bad); }
.ticket .t-top { display: flex; justify-content: space-between; gap: 6px; font-weight: 650; }
.ticket .t-actions { display: flex; gap: 6px; margin-top: 8px; }

/* ---- Dashboard ---- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { padding: 14px 16px; } .tile .lbl { color: var(--ink-3); font-size: 12.5px; font-weight: 550; }
.tile .val { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .note { font-size: 12px; color: var(--ink-3); } .tile .note.bad { color: var(--bad); font-weight: 600; }
.hbar { display: grid; grid-template-columns: 120px 1fr 40px; gap: 10px; align-items: center; padding: 5px 0; }
.hbar .bar { height: 12px; background: var(--brand); border-radius: 0 4px 4px 0; min-width: 2px; }
.chart { position: relative; } .chart svg { display: block; width: 100%; height: 180px; }
.chart .tip { position: absolute; pointer-events: none; background: #1b2330; color: #fff; padding: 5px 8px; border-radius: 6px; font-size: 12px; white-space: nowrap; transform: translate(-50%, -110%); }

/* ---- Modules admin ---- */
.mod { padding: 14px 16px; display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; }
.mod .locs { grid-column: span 2; display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.pill { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-strong); border-radius: 999px; padding: 3px 10px; font-size: 12px; background: #fff; cursor: pointer; font: inherit; font-size: 12px; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); }
.pill.on .dot { background: var(--good); } .pill.off { color: var(--ink-3); background: var(--mute-bg); } .pill.off .dot { background: var(--bad); }
.pill.override { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.switch { position: relative; width: 40px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; background: var(--line-strong); border-radius: 999px; transition: .15s; }
.switch span::after { content: ""; position: absolute; width: 18px; height: 18px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--good); } .switch input:checked + span::after { left: 20px; }
.switch input:disabled { cursor: not-allowed; } .switch input:disabled + span { opacity: .5; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 8px 12px; color: var(--ink-2); font-weight: 550; border-bottom: 2px solid transparent; margin-bottom: -1px; cursor: pointer; }
.tabs a.active { color: var(--brand); border-color: var(--brand); } .tabs a:hover { text-decoration: none; color: var(--ink); }

/* ---- Login / portal ---- */
.center { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login { width: min(380px, 100%); padding: 26px; }
.portal { max-width: 860px; margin: 0 auto; padding: 24px 16px 60px; }
.portal iframe { width: 100%; height: 70vh; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .nav { display: flex; flex-wrap: wrap; } .nav-group, .side-foot { display: none; }
  .cols-2 { grid-template-columns: 1fr; }
  .view { padding: 16px 12px 40px; }
}
