@import url('https://fonts.googleapis.com/css2?family=Archivo:wdth,wght@75..100,500..800&family=Public+Sans:wght@400;500;600;700&display=swap');

/* Palette: pigment masterbatch colours on a cool mineral ground */
:root {
  --ground: #EEF1F1;
  --surface: #FFFFFF;
  --ink: #17252D;
  --muted: #5A6A72;
  --line: #D3DBDE;
  --line-soft: #E6ECEE;
  --accent: #0B5D6B;
  --accent-ink: #FFFFFF;
  --neg: #B3261E;
  --pos: #1D6B3F;
  --estimate: #FFF1BF;
  /* category pigments */
  --c-equipment_contract: #1F4E9C;  /* phthalo blue */
  --c-equipment_addon: #197A5A;     /* phthalo green */
  --c-shipping: #D9A41A;            /* ochre yellow */
  --c-site: #6A4C93;                /* violet */
  --c-commissioning: #B0336B;       /* magenta */
  --c-labor: #2B2F33;               /* carbon black */
  --c-materials: #E07A1F;           /* orange */
  --display: 'Archivo', 'Arial Narrow', 'Helvetica Neue', Arial, sans-serif;
  --body: 'Public Sans', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --r: 6px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ground: #10181C; --surface: #172227; --ink: #E4ECEE; --muted: #97A7AE;
    --line: #2B3A41; --line-soft: #22313A; --accent: #4FB3C2; --accent-ink: #0B1B20;
    --neg: #FF8A80; --pos: #7FD1A0; --estimate: #4A3F12; --c-labor: #8C959C;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--ground); color: var(--ink); font: 15px/1.5 var(--body); font-variant-numeric: tabular-nums; }
h1, h2, h3 { font-family: var(--display); font-stretch: 85%; line-height: 1.15; margin: 0 0 .4em; }
h1 { font-size: 1.9rem; font-weight: 750; }
h2 { font-size: 1.25rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 700; }
a { color: var(--accent); }
code { background: var(--line-soft); padding: 1px 5px; border-radius: 4px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* pellets — the one decorative device: the category pigments as granules */
.pellets { display: flex; gap: 6px; margin-bottom: 18px; }
.pellets i { width: 16px; height: 11px; border-radius: 50%; display: block; }
.pellets.small { gap: 4px; margin-bottom: 10px; }
.pellets.small i { width: 10px; height: 7px; }
.pellets i:nth-child(1) { background: var(--c-equipment_contract); }
.pellets i:nth-child(2) { background: var(--c-equipment_addon); }
.pellets i:nth-child(3) { background: var(--c-shipping); }
.pellets i:nth-child(4) { background: var(--c-site); }
.pellets i:nth-child(5) { background: var(--c-commissioning); }
.pellets i:nth-child(6) { background: var(--c-labor); }
.pellets i:nth-child(7) { background: var(--c-materials); }
.dot { display: inline-block; width: 12px; height: 8px; border-radius: 50%; margin-right: 8px; vertical-align: middle; }

/* auth */
body.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { background: var(--surface); padding: 36px; border-radius: 10px; width: min(420px, 100%); border: 1px solid var(--line); }
.auth-card p { color: var(--muted); }
.error { color: var(--neg) !important; font-weight: 600; }
.warn-note { background: var(--estimate); color: var(--ink) !important; padding: 8px 12px; border-radius: var(--r); }
.fine { font-size: .82rem; }

/* shell */
.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.rail { background: var(--surface); border-right: 1px solid var(--line); padding: 22px 14px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; }
.brand { padding: 0 10px 18px; }
.brand strong { display: block; font-family: var(--display); font-stretch: 85%; font-size: 1.2rem; }
.brand span { color: var(--muted); font-size: .85rem; }
.rail a { padding: 8px 10px; border-radius: var(--r); text-decoration: none; color: var(--ink); font-weight: 500; }
.rail a:hover { background: var(--line-soft); }
.rail a.active { background: var(--accent); color: var(--accent-ink); }
.me { margin-top: auto; padding: 14px 10px 0; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; font-size: .88rem; }
.me span { font-weight: 600; }
.me a, .link { color: var(--muted); background: none; border: 0; padding: 0; font: inherit; text-align: left; cursor: pointer; text-decoration: underline; }
main#view { padding: 28px 32px 60px; max-width: 1400px; width: 100%; min-width: 0; outline: none; }
.loading { color: var(--muted); }

.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.head p { margin: 0; color: var(--muted); max-width: 70ch; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 20px; margin-bottom: 20px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* overview hero */
.hero { display: grid; grid-template-columns: auto 1fr; gap: 28px; align-items: end; }
.hero .total { font-family: var(--display); font-stretch: 75%; font-weight: 800; font-size: clamp(2.6rem, 6vw, 4.2rem); line-height: 1; letter-spacing: -.01em; }
.hero .sub { color: var(--muted); margin-top: 6px; }
.hero .facts { display: flex; gap: 28px; flex-wrap: wrap; justify-content: flex-end; }
.hero .facts div { text-align: right; }
.hero .facts b { display: block; font-size: 1.25rem; font-family: var(--display); font-stretch: 85%; }
.hero .facts small { color: var(--muted); }

.strip { display: flex; height: 30px; border-radius: 15px; overflow: hidden; margin: 22px 0 8px; background: var(--line-soft); }
.strip > span { position: relative; height: 100%; min-width: 2px; }
.strip > span::after { content: ''; position: absolute; inset: 0; background: repeating-linear-gradient(90deg, transparent 0 10px, rgba(255,255,255,.18) 10px 11px); }
.strip .paid { display: block; position: absolute; left: 0; top: 0; bottom: 0; box-shadow: inset 0 -6px 0 rgba(255,255,255,.55); }
.strip-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: .85rem; color: var(--muted); }

/* tables */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--line); padding: 8px 10px; white-space: nowrap; }
td { border-bottom: 1px solid var(--line-soft); padding: 8px 10px; vertical-align: top; }
td.n, th.n { text-align: right; white-space: nowrap; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--line-soft); }
tr.total td { font-weight: 700; border-top: 2px solid var(--ink); border-bottom: 0; }
tr.cancel td { opacity: .45; text-decoration: line-through; }
td .desc { color: var(--muted); font-size: .82rem; display: block; max-width: 48ch; }
.neg { color: var(--neg); font-weight: 600; }
.est { background: var(--estimate); border-radius: 3px; padding: 0 4px; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: .78rem; font-weight: 600; background: var(--line-soft); white-space: nowrap; }
.badge.Contracted { background: #D7E6F7; color: #1F4E9C; }
.badge.Paid { background: #D5EEDD; color: #1D6B3F; }
.badge.Quoted { background: #F6E8C6; color: #7A5A00; }
.badge.Cancelled { background: #F3D6D4; color: #8E1F18; }
@media (prefers-color-scheme: dark) { .badge.Contracted, .badge.Paid, .badge.Quoted, .badge.Cancelled { background: var(--line); color: var(--ink); } }

/* timeline — key dates are a real sequence */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 10px 1fr auto 70px; gap: 12px; padding: 6px 0; align-items: baseline; }
.timeline li::before { content: ''; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--accent); margin-top: 4px; }
.timeline li.past::before { background: var(--accent); }
.timeline li span:nth-child(2) { white-space: nowrap; }
.timeline li span:last-child { color: var(--muted); font-size: .85rem; white-space: nowrap; text-align: right; }
.timeline li.past { color: var(--muted); }

/* cash-out bars */
.bars { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; align-items: end; height: 180px; padding-top: 10px; }
.bar { display: flex; flex-direction: column; justify-content: flex-end; height: 100%; position: relative; }
.bar .i { background: var(--accent); border-radius: 3px 3px 0 0; }
.bar .p { background: var(--c-labor); }
.bar label { position: absolute; bottom: -22px; left: -4px; right: -4px; text-align: center; font-size: .7rem; white-space: nowrap; color: var(--muted); }
.bar:hover .tip { display: block; }
.tip { display: none; position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--surface); padding: 4px 8px; border-radius: 4px; font-size: .75rem; white-space: nowrap; z-index: 2; }
.bars-legend { margin-top: 30px; font-size: .82rem; color: var(--muted); display: flex; gap: 16px; flex-wrap: wrap; }
.bars-legend i { display: inline-block; width: 10px; height: 10px; margin-right: 5px; vertical-align: -1px; border-radius: 2px; }

/* controls */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: 600 .9rem var(--body); cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--neg); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs button { border: 1px solid var(--line); background: var(--surface); padding: 6px 12px; border-radius: 16px; cursor: pointer; font: 500 .85rem var(--body); color: var(--ink); }
.tabs button[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
input, select, textarea { font: inherit; font-weight: 400; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 7px 10px; width: 100%; }
textarea { min-height: 64px; resize: vertical; }
.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 4px; font-size: .85rem; font-weight: 600; color: var(--muted); }
.form label.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 500; }
.form label.check input { width: auto; margin-top: 4px; }
.form .row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.form .hint { font-weight: 400; font-size: .78rem; }
.search { max-width: 280px; }

dialog { border: 1px solid var(--line); border-radius: 10px; padding: 0; width: min(760px, 94vw); background: var(--surface); color: var(--ink); }
dialog::backdrop { background: rgba(10, 20, 25, .45); }
dialog form { padding: 24px; }
dialog .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
dialog .actions .left { margin-right: auto; }
.computed { background: var(--line-soft); border-radius: var(--r); padding: 10px 12px; font-size: .88rem; }

#toast { position: fixed; bottom: 20px; right: 20px; background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: var(--r); opacity: 0; transform: translateY(8px); transition: .2s; pointer-events: none; max-width: 420px; }
#toast.show { opacity: 1; transform: none; }
#toast.err { background: var(--neg); color: #fff; }

.drop { border: 2px dashed var(--line); border-radius: 10px; padding: 34px; text-align: center; color: var(--muted); cursor: pointer; }
.drop.over { border-color: var(--accent); background: var(--line-soft); }
.drop strong { color: var(--ink); display: block; font-size: 1.05rem; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; font-size: .9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.muted { color: var(--muted); }
ul.plain { margin: 6px 0; padding-left: 18px; }

@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  h1 { font-size: 1.5rem; overflow-wrap: anywhere; }
  td.item { min-width: 200px; }
  .rail { position: static; height: auto; flex-direction: row; flex-wrap: wrap; padding: 12px; }
  .brand { width: 100%; padding-bottom: 8px; }
  .me { width: 100%; flex-direction: row; flex-wrap: wrap; gap: 12px; margin-top: 8px; padding-top: 8px; }
  main#view { padding: 20px 16px 48px; }
  .grid2, .hero { grid-template-columns: 1fr; }
  .hero .facts { justify-content: flex-start; }
  .hero .facts div { text-align: left; }
}
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
@media print { .rail, .toolbar, .tabs { display: none; } .shell { display: block; } .panel { break-inside: avoid; } }

td.id { white-space: nowrap; }
td.item { min-width: 260px; }

/* ---------- operations ---------- */
.navgroup { font-size: .76rem; color: var(--muted); padding: 14px 10px 4px; font-weight: 600; }
.alarm-count { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 6px; border-radius: 10px; background: var(--neg); color: #fff; font-size: .74rem; font-weight: 700; text-align: center; line-height: 18px; }
.rail a.active .alarm-count { background: #fff; color: var(--neg); }
label.inline { display: inline-flex; gap: 8px; align-items: center; font-size: .88rem; color: var(--muted); font-weight: 600; }
label.inline input { width: auto; }
.alarms ul { list-style: none; margin: 0; padding: 0; }
.alarms li { display: grid; grid-template-columns: 12px 150px 1fr auto; gap: 12px; align-items: baseline; padding: 7px 0; border-bottom: 1px solid var(--line-soft); }
.alarms li:last-child { border-bottom: 0; }
.al-dot { width: 10px; height: 10px; border-radius: 50%; display: block; transform: translateY(1px); }
.al-high .al-dot { background: var(--neg); }
.al-medium .al-dot { background: var(--c-shipping); }
.al-low .al-dot { background: var(--muted); }
.al-high b { color: var(--neg); }
tr.lowrow td:first-child { box-shadow: inset 3px 0 0 var(--neg); }
.hero .total.neg { color: var(--neg); }
.trend { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 10px; height: 190px; align-items: end; padding-bottom: 38px; }
.trend .pair { height: 100%; display: flex; flex-direction: column; justify-content: flex-end; position: relative; }
.trend .cols { display: flex; gap: 3px; align-items: flex-end; height: 100%; }
.trend .cols span { flex: 1; border-radius: 3px 3px 0 0; min-height: 1px; }
.trend .c1 { background: var(--accent); }
.trend .c2 { background: var(--c-materials); }
.trend label { position: absolute; bottom: -20px; left: 0; right: 0; text-align: center; font-size: .72rem; color: var(--muted); white-space: nowrap; }
.trend small { position: absolute; bottom: -36px; left: -6px; right: -6px; text-align: center; font-size: .7rem; color: var(--muted); white-space: nowrap; }
.tflow { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; }
.tcol { padding: 0 18px; border-left: 1px solid var(--line); position: relative; }
.tcol:first-child { border-left: 0; padding-left: 0; }
.tcol + .tcol::before { content: '›'; position: absolute; left: -7px; top: 34px; background: var(--surface); color: var(--muted); font-size: 1.2rem; line-height: 1; }
.tcol h3 { color: var(--muted); font-size: .85rem; }
.tlist { list-style: none; margin: 0; padding: 0; }
.tlist li { padding: 8px 0; border-bottom: 1px solid var(--line-soft); display: grid; gap: 2px; font-size: .88rem; }
.tlist li span { color: var(--muted); font-size: .82rem; }
.badge.st-Released, .badge.st-Approved, .badge.st-Shipped, .badge.st-Invoiced { background: #D5EEDD; color: #1D6B3F; }
.badge.st-Quarantine, .badge.st-QC-hold, .badge.st-Draft, .badge.st-Partly-shipped, .badge.st-Quote { background: #F6E8C6; color: #7A5A00; }
.badge.st-Rejected, .badge.st-Cancelled { background: #F3D6D4; color: #8E1F18; }
.badge.st-Planned, .badge.st-Confirmed { background: #D7E6F7; color: #1F4E9C; }
.badge.st-Consumed, .badge.st-Retired { background: var(--line-soft); color: var(--muted); }
@media (prefers-color-scheme: dark) { .badge[class*="st-"] { background: var(--line); color: var(--ink); } }
@media (max-width: 900px) {
  .alarms li { grid-template-columns: 12px 1fr; }
  .alarms li span, .alarms li a { grid-column: 2; }
  .tflow { grid-template-columns: 1fr; }
  .tcol { border-left: 0; padding: 0; border-top: 1px solid var(--line); margin-top: 10px; }
  .tcol + .tcol::before { display: none; }
  .navgroup { width: 100%; padding: 6px 10px 0; }
}
@media print {
  body * { visibility: hidden; }
  dialog[open] .print-area, dialog[open] .print-area * { visibility: visible; }
  dialog[open] { position: absolute; inset: 0; border: 0; width: 100%; max-width: none; }
  dialog[open] .print-area { position: absolute; left: 0; top: 0; width: 100%; }
}

.alarms.folded li:nth-child(n+7) { display: none; }
.alarms #almore { margin-top: 10px; }

/* ---------- setup wizard ---------- */
.auth-card.wide { width: min(640px, 100%); }
.auth-card h2 { margin-top: 22px; }
.steps { list-style: none; display: flex; gap: 8px; padding: 0; margin: 4px 0 18px; counter-reset: s; flex-wrap: wrap; }
.steps li { counter-increment: s; font-size: .85rem; color: var(--muted); padding: 4px 12px 4px 8px; border-radius: 14px; background: var(--line-soft); }
.steps li::before { content: counter(s); display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; margin-right: 6px; background: var(--line); color: var(--ink); font-size: .72rem; font-weight: 700; }
.steps li.now { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.steps li.now::before { background: var(--accent-ink); color: var(--accent); }
.steps li.done::before { content: '✓'; background: var(--pos); color: #fff; }
.checks { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.checks li { display: grid; grid-template-columns: 22px 1fr; gap: 6px; font-size: .9rem; }
.checks li > span { font-weight: 700; }
.checks li.ok > span { color: var(--pos); }
.checks li.bad > span { color: var(--neg); }
.checks small { display: block; color: var(--muted); }
.howto { background: var(--line-soft); border-radius: var(--r); padding: 10px 14px; margin-bottom: 14px; font-size: .9rem; }
.howto summary { cursor: pointer; font-weight: 600; }
.howto ol { margin: 8px 0 2px; padding-left: 20px; }
.howto li { margin: 3px 0; }
fieldset.choice { border: 0; padding: 0; margin: 0; display: grid; gap: 8px; }
.okline { background: #D5EEDD; color: #174f30 !important; padding: 8px 12px; border-radius: var(--r); }
textarea.code { font: .8rem/1.4 ui-monospace, Menlo, Consolas, monospace; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.bootfail h2 { color: var(--neg); }
.bootfail p { max-width: 75ch; }

/* ---------- projects ---------- */
.rail { overflow-y: auto; }
.projectbar { padding: 0 10px 10px; display: flex; flex-direction: column; gap: 4px; }
.projectbar label { font-size: .76rem; color: var(--muted); font-weight: 600; }
.projectbar select { font-weight: 600; text-overflow: ellipsis; border-color: var(--accent); }
@media (max-width: 900px) { .projectbar { width: 100%; } }

/* ---------- categories and key dates ---------- */
.panelhead { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.panelhead h2 { margin: 0; }
.timeline li.click { cursor: pointer; }
.timeline li.click:hover span:first-of-type { text-decoration: underline; }
.catlist { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 6px; }
.catlist li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--line-soft); border-radius: var(--r); }
.catlist .cname { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.catlist .cname small { font-size: .8rem; }
.catlist .btn { padding: 4px 9px; }
.catlist .dot { flex: none; }
input[type="color"] { padding: 2px; height: 36px; width: 64px; cursor: pointer; }
.sched { display: grid; gap: 10px; margin: 16px 0; }
.sched-row { display: grid; grid-template-columns: minmax(200px, 1.8fr) 160px minmax(280px, 2fr) 105px 130px; gap: 10px 12px; align-items: end; padding: 10px 12px; border: 1px solid var(--line-soft); border-radius: var(--r); }
.sched-row label { display: grid; gap: 4px; font-size: .82rem; color: var(--muted); font-weight: 600; }
.sched-row .sc-after { display: grid; grid-template-columns: 90px 1fr; gap: 10px; }
.sched-row .sc-result { display: grid; gap: 4px; align-content: end; }
.sched-row .sc-result small { font-size: .82rem; color: var(--muted); font-weight: 600; }
.sched-row .sc-result b { padding: 7px 0; white-space: nowrap; }
.sched-row .sc-end { text-align: right; align-self: center; }
.sched-row .sc-end small { display: block; line-height: 1.3; text-align: left; }
@media (max-width: 900px) { .sched-row { grid-template-columns: 1fr 1fr; } .sched-row .sc-name, .sched-row .sc-after, .sched-row .sc-date { grid-column: 1 / -1; } .sched-row .sc-end { grid-column: 1 / -1; } }
