:root {
  --bg: #f3f5f7;
  --panel: #ffffff;
  --ink: #17202b;
  --muted: #5f6b79;
  --line: #dde2e8;
  --accent: #0f6b5c;
  --accent-ink: #ffffff;
  --accent-soft: #e3f1ee;
  --bad: #b42318;
  --bad-soft: #fdecea;
  --warn: #9a4a00;
  --warn-soft: #fff4e0;
  --ok: #05603a;
  --ok-soft: #e5f5ec;
  --info: #1d4ed8;
  --info-soft: #e8efff;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --nav-w: 220px;
  --tabbar-h: 62px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1419; --panel: #182029; --ink: #e8edf2; --muted: #9aa6b3; --line: #2a3542;
    --accent: #3fb59f; --accent-ink: #06231d; --accent-soft: #143a33;
    --bad: #ff8a80; --bad-soft: #3a1714; --warn: #ffb44d; --warn-soft: #3a2a10;
    --ok: #6fdba5; --ok-soft: #0f3324; --info: #8fb0ff; --info-soft: #18264a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1419; --panel: #182029; --ink: #e8edf2; --muted: #9aa6b3; --line: #2a3542;
  --accent: #3fb59f; --accent-ink: #06231d; --accent-soft: #143a33;
  --bad: #ff8a80; --bad-soft: #3a1714; --warn: #ffb44d; --warn-soft: #3a2a10;
  --ok: #6fdba5; --ok-soft: #0f3324; --info: #8fb0ff; --info-soft: #18264a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; line-height: 1.2; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 0 0 6px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* ------------------------------------------------------------ layout */

#app { min-height: 100vh; }
#view { padding: 16px; padding-bottom: calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom)); max-width: 1100px; margin: 0 auto; }

#nav {
  position: fixed; z-index: 20; left: 0; right: 0; bottom: 0;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--panel); border-top: 1px solid var(--line);
  display: flex;
}
#nav[hidden] { display: none; }
#nav .brand, #nav .company, #nav .who { display: none; }
#nav .links { display: flex; flex: 1; }
#nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 11px; text-decoration: none; min-width: 0;
}
#nav a svg { width: 22px; height: 22px; }
#nav a.on { color: var(--accent); }
#nav .more-only { display: none; }

@media (min-width: 860px) {
  #nav {
    top: 0; right: auto; width: var(--nav-w); height: auto; flex-direction: column;
    border-top: 0; border-right: 1px solid var(--line); padding: 16px 10px;
  }
  #nav .brand { display: block; font-weight: 800; font-size: 17px; padding: 4px 10px 2px; color: var(--accent); }
  #nav .company { display: block; padding: 0 10px 16px; font-size: 12px; color: var(--muted); }
  #nav .links { flex-direction: column; flex: 0; gap: 2px; }
  #nav a { flex-direction: row; justify-content: flex-start; gap: 10px; font-size: 14px; padding: 9px 10px; border-radius: 8px; color: var(--ink); }
  #nav a svg { width: 18px; height: 18px; color: var(--muted); }
  #nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
  #nav a.on svg { color: var(--accent); }
  #nav .more-only { display: flex; }
  #nav .who { display: block; margin-top: auto; padding: 10px; font-size: 13px; border-top: 1px solid var(--line); }
  #view { margin-left: var(--nav-w); padding: 24px 28px 48px; max-width: none; }
  #view > * { max-width: 1040px; }
  #nav[hidden] + #view { margin-left: 0; }
  #view > .auth { margin: 8vh auto; }
}

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); font-size: 14px; margin-top: 4px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.stack > * + * { margin-top: 12px; }
.grid2 { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 980px) { .grid2 { grid-template-columns: 1.4fr 1fr; align-items: start; } }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 12px; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.card-head h2 { margin: 0; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 12px; }

/* ------------------------------------------------------------- lists */

.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.list a.item, .list .item { display: flex; gap: 12px; align-items: center; padding: 12px 16px; color: inherit; text-decoration: none; }
.list a.item:hover { background: var(--bg); }
.item .main { flex: 1; min-width: 0; }
.item .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .s { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .r { text-align: right; flex-shrink: 0; }
.time { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 64px; }
.empty { padding: 24px 16px; text-align: center; color: var(--muted); }

table.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { padding: 9px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
.tbl td.num, .tbl th.num { text-align: right; }
.tbl tr:last-child td { border-bottom: 0; }
.scroll-x { overflow-x: auto; }

/* ------------------------------------------------------------ badges */

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.badge.requested, .badge.quoted { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge.scheduled { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.in_progress { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.completed, .badge.paid, .badge.available { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.cancelled, .badge.retired { text-decoration: line-through; }
.badge.overdue, .badge.high, .badge.calibration { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.deployed, .badge.medium, .badge.unpaid { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.kind { background: transparent; }

.pci { font-weight: 800; font-variant-numeric: tabular-nums; }
.pci.bad { color: var(--bad); }
.pci.ok { color: var(--ok); }

.banner { border-radius: var(--radius); padding: 14px 16px; display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.banner.bad { background: var(--bad-soft); color: var(--bad); }
.banner.ok { background: var(--ok-soft); color: var(--ok); }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner .big { font-size: 32px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.banner .txt { flex: 1; min-width: 180px; color: var(--ink); }

.fu { display: flex; gap: 12px; padding: 12px 16px; align-items: flex-start; }
.fu .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 7px; flex-shrink: 0; background: var(--muted); }
.fu .dot.high { background: var(--bad); }
.fu .dot.medium { background: var(--warn); }
.fu .dot.low { background: var(--info); }
.fu .main { flex: 1; min-width: 0; }

/* ------------------------------------------------------------- forms */

label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.fields { display: grid; grid-template-columns: 1fr; gap: 0 12px; }
@media (min-width: 600px) { .fields.two { grid-template-columns: 1fr 1fr; } .fields.three { grid-template-columns: 1fr 1fr 1fr; } }
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; /* 16px stops iOS zooming on focus */
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
textarea { min-height: 80px; resize: vertical; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; font-size: 14px; margin: 4px 0 12px; }
.check input { width: 20px; height: 20px; }
.search { max-width: 360px; }

button, .btn {
  font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  text-decoration: none; min-height: 42px; white-space: nowrap;
}
button:hover, .btn:hover { text-decoration: none; filter: brightness(.97); }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.danger { color: var(--bad); }
button.link { border: 0; background: none; color: var(--accent); padding: 4px 6px; min-height: 0; }
button.small, .btn.small { padding: 6px 10px; min-height: 34px; font-size: 13px; }
button:disabled { opacity: .55; cursor: default; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

details.fold { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 12px; }
details.fold summary { cursor: pointer; font-weight: 600; color: var(--accent); list-style: none; }
details.fold summary::-webkit-details-marker { display: none; }
details.fold[open] summary { margin-bottom: 12px; }

.tabs { display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; }
.tabs a { padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); font-size: 13px; white-space: nowrap; }
.tabs a.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.tabs a:hover { text-decoration: none; }

.device { border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
.device + .device { margin-top: 10px; }

.day-h { padding: 10px 16px; background: var(--bg); font-weight: 700; font-size: 13px; border-top: 1px solid var(--line); }
.day-h.today { color: var(--accent); }

.auth { max-width: 400px; margin: 8vh auto; }
.auth .logo { font-weight: 800; font-size: 26px; color: var(--accent); margin-bottom: 4px; }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); z-index: 50;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 14px; max-width: calc(100% - 32px);
  transition: all .2s;
}
#toast.on { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--bad); color: #fff; }

.activity li { padding: 6px 0; font-size: 13px; border-top: 1px solid var(--line); }
.activity li:first-child { border-top: 0; }

/* ------------------------------------------------------- v2 additions */

.card-head.pad { padding: 16px 16px 0; }
.pad-x { margin: 0 16px 16px; }
#nav a.desk-only { display: none; }
#nav a.phone-only { display: flex; }
@media (min-width: 860px) {
  #nav a.desk-only { display: flex; }
  #nav a.phone-only { display: none; }
  #nav .links { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
  #nav .links a { flex: 0 0 auto; }
}
.more-icon svg { width: 20px; height: 20px; color: var(--muted); display: block; }
.link-row { width: 100%; border: 0; border-radius: 0; background: none; text-align: left; font-weight: 400; min-height: 0; justify-content: flex-start; }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.photo-grid figure { margin: 0; }
.photo-grid img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); display: block; background: var(--bg); }
.photo-grid figcaption { font-size: 12px; margin-top: 4px; overflow-wrap: anywhere; }
input[type="file"] { padding: 8px; }

details.card.role > summary { cursor: pointer; list-style: none; }
details.card.role > summary::-webkit-details-marker { display: none; }
details.card.role[open] > summary { margin-bottom: 12px; }
.perm-grid { display: grid; grid-template-columns: 1fr; gap: 12px; margin-bottom: 12px; }
@media (min-width: 760px) { .perm-grid { grid-template-columns: 1fr 1fr; } }
fieldset.perm-group { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px 4px; margin: 0; min-width: 0; }
fieldset.perm-group legend { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 0 4px; }
.check.perm { align-items: flex-start; margin: 6px 0; }
.check.perm input { margin-top: 1px; flex-shrink: 0; }
.check input:disabled + span { opacity: .55; }
.edit-row td { background: var(--bg); }

pre.msg { white-space: pre-wrap; font: inherit; font-size: 13px; background: var(--bg); padding: 10px; border-radius: 8px; margin: 6px 0 0; overflow-wrap: anywhere; }
code { font-size: 12px; overflow-wrap: anywhere; }

/* -------------------------------------------------------- reports / charts
   Colors from the validated reference palette: one series hue, and a
   five-step ordinal ramp (checked light and dark with validate_palette). */

:root {
  --viz-1: #2a78d6;
  --viz-grid: #e1e0d9;
  --viz-axis: #c3c2b7;
  --viz-tick: #898781;
  --viz-track: #eef3fb;
  --viz-r1: #86b6ef; --viz-r2: #5598e7; --viz-r3: #2a78d6; --viz-r4: #1c5cab; --viz-r5: #0d366b;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --viz-1: #3987e5; --viz-grid: #2c2c2a; --viz-axis: #383835; --viz-track: #1f2a38;
    --viz-r1: #b7d3f6; --viz-r2: #6da7ec; --viz-r3: #3987e5; --viz-r4: #256abf; --viz-r5: #184f95;
  }
}
:root[data-theme="dark"] {
  --viz-1: #3987e5; --viz-grid: #2c2c2a; --viz-axis: #383835; --viz-track: #1f2a38;
  --viz-r1: #b7d3f6; --viz-r2: #6da7ec; --viz-r3: #3987e5; --viz-r4: #256abf; --viz-r5: #184f95;
}

.section-h { margin: 28px 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.filters select, .filters input { width: auto; font-size: 15px; padding: 7px 10px; }
.stat .s { color: var(--muted); font-size: 12px; margin-top: 2px; }
.stat .v small { font-size: 13px; font-weight: 500; color: var(--muted); }
.stats .stat .l { margin-bottom: 2px; }
.stats.inner { margin: 0; }
.stats.inner .stat { background: var(--bg); border: 0; }
.viz-row { margin-bottom: 12px; }
.viz-row > .card + .card, .grid2 > .card + .card { margin-top: 0; }
@media (max-width: 979px) { .viz-row > .card + .card { margin-top: 12px; } }
.big-num { font-size: 28px; font-weight: 700; }

svg.viz { width: 100%; height: auto; display: block; overflow: visible; }
svg.viz .grid { stroke: var(--viz-grid); stroke-width: 1; }
svg.viz .axis { stroke: var(--viz-axis); stroke-width: 1; }
svg.viz .tick { fill: var(--viz-tick); font-size: 11px; font-variant-numeric: tabular-nums; }
svg.viz .val { fill: var(--ink); font-size: 12px; font-weight: 600; }
svg.viz .bar { fill: var(--viz-1); }
svg.viz .hit { fill: transparent; cursor: default; outline: none; }
svg.viz .hit:hover, svg.viz .hit:focus-visible { fill: var(--ink); fill-opacity: .05; }

.hbars { display: grid; gap: 10px; }
.hbar { display: grid; grid-template-columns: minmax(110px, 38%) 1fr; gap: 10px; align-items: center; border-radius: 6px; outline: none; padding: 2px 4px; margin: 0 -4px; }
.hbar:hover, .hbar:focus-visible { background: var(--bg); }
.hbar-l { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { display: flex; align-items: center; gap: 8px; min-width: 0; }
.hbar-fill { height: 18px; background: var(--viz-1); border-radius: 0 4px 4px 0; flex: 0 0 auto; max-width: calc(100% - 100px); }
.hbar-fill.r1 { background: var(--viz-r1); } .hbar-fill.r2 { background: var(--viz-r2); } .hbar-fill.r3 { background: var(--viz-r3); }
.hbar-fill.r4 { background: var(--viz-r4); } .hbar-fill.r5 { background: var(--viz-r5); }
.hbar-v { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

.meter { display: inline-block; vertical-align: middle; width: 100px; height: 8px; border-radius: 4px; background: var(--viz-track); margin-right: 8px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--viz-1); border-radius: 4px; }

details.viz-table { margin-top: 10px; }
details.viz-table summary { cursor: pointer; font-size: 13px; color: var(--accent); }

#viz-tip {
  position: fixed; z-index: 60; pointer-events: none; opacity: 0; transition: opacity .1s;
  background: var(--panel); color: var(--ink); border: 1px solid var(--line); box-shadow: 0 4px 14px rgba(0,0,0,.12);
  border-radius: 8px; padding: 6px 10px; font-size: 13px; display: flex; flex-direction: column; max-width: 260px;
}
#viz-tip.on { opacity: 1; }
#viz-tip strong { font-variant-numeric: tabular-nums; }
#viz-tip span { color: var(--muted); font-size: 12px; }
@media (forced-colors: active) { .hbar-fill, svg.viz .bar, .meter span { forced-color-adjust: none; background: CanvasText; fill: CanvasText; } }
.grid3 { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 980px) { .grid3 { grid-template-columns: repeat(3, 1fr); align-items: start; } }
.grid3 > .card + .card { margin-top: 0; }
.grid3 .hbar { grid-template-columns: 1fr; gap: 3px; }
.grid3 .hbars { gap: 8px; }
