/* IDC Equipment - styles
   Idea: an equipment status board. Indicator lamps carry status everywhere;
   the "Needs attention" board shows how long each machine has been down. */

:root {
  --ink: #16313a;
  --muted: #5a6e75;
  --line: #d6e0e2;
  --bg: #f2f6f6;
  --surface: #ffffff;
  --accent: #0b6e6e;
  --accent-hover: #095c5c;
  --side-bg: #16313a;
  --side-ink: #dce8ea;
  --side-muted: #8fa9ae;

  --up: #24804f;
  --down: #c0362c;
  --maint: #b7791f;
  --eng: #2b68a8;
  --comm: #6e56a0;

  --radius: 6px;
  --font: 'Public Sans', 'Segoe UI', system-ui, -apple-system, Roboto, Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e3ecee;
    --muted: #93a6ac;
    --line: #2c3c41;
    --bg: #0f1a1d;
    --surface: #152328;
    --accent: #3fb1ad;
    --accent-hover: #5cc4c0;
    --side-bg: #0b1417;
    --side-ink: #d6e3e6;
    --side-muted: #7f979c;
    --up: #46b37a;
    --down: #ec6a5f;
    --maint: #e0a540;
    --eng: #5f9be0;
    --comm: #a68cd8;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}

h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.65rem; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; font-weight: 600; }
p { margin: 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.num, .tally-n, .elapsed { font-variant-numeric: tabular-nums; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Status lamps ---------- */

.s-up    { --c: var(--up); }
.s-down  { --c: var(--down); }
.s-maint { --c: var(--maint); }
.s-eng   { --c: var(--eng); }
.s-comm  { --c: var(--comm); }
.s-na    { --c: var(--muted); }

.lamp {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 22%, transparent);
  flex: none;
}

.status {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 2px 10px 2px 8px;
  border-radius: 999px;
  font-size: 0.82rem; font-weight: 600;
  white-space: nowrap;
  color: color-mix(in srgb, var(--c) 70%, var(--ink));
  background: color-mix(in srgb, var(--c) 11%, var(--surface));
}
.status .lamp { width: 8px; height: 8px; }
.status.big { font-size: 0.95rem; padding: 6px 14px 6px 12px; }
.status.big .lamp { width: 10px; height: 10px; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; font-size: 0.9rem;
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
@media (prefers-color-scheme: dark) { .btn.primary { color: #08201f; } }
.btn.danger { background: var(--down); border-color: var(--down); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); }
.btn.danger-text { color: var(--down); }
.btn.link { background: none; border: 0; padding: 0 4px; color: var(--accent); min-height: 0; font-weight: 500; }
.btn.small { min-height: 30px; padding: 0 10px; font-size: 0.82rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn.busy { cursor: wait; }
.btn.busy::after {
  content: ''; width: 12px; height: 12px;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
button.link { background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

.icon-btn {
  width: 34px; height: 34px; border: 0; border-radius: var(--radius);
  background: transparent; color: var(--muted); font-size: 1.5rem; line-height: 1; cursor: pointer;
}
.icon-btn:hover { background: color-mix(in srgb, var(--ink) 7%, transparent); }

/* ---------- Forms ---------- */

input, select, textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--ink);
  font: inherit;
}
textarea { resize: vertical; min-height: 64px; }
select {
  appearance: none; -webkit-appearance: none; padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' fill='none' stroke='%23808f94' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
input[type=checkbox] { width: 16px; height: 16px; min-height: 0; accent-color: var(--accent); margin: 0; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field-label { font-size: 0.85rem; font-weight: 600; }
.req { color: var(--down); font-style: normal; }
.hint { color: var(--muted); font-size: 0.8rem; }
.check { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; cursor: pointer; }

.form-error {
  padding: 10px 12px; border-radius: var(--radius);
  background: color-mix(in srgb, var(--down) 10%, var(--surface));
  color: color-mix(in srgb, var(--down) 80%, var(--ink));
  font-size: 0.9rem;
}

/* Searchable dropdown */
.combo { position: relative; }
.combo-native { display: none; }
.combo-btn {
  width: 100%; min-height: 40px; padding: 8px 34px 8px 10px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 400; font-size: 0.95rem; text-align: left; cursor: pointer;
  position: relative; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.combo-btn::after {
  content: ''; position: absolute; right: 13px; top: 50%;
  width: 7px; height: 7px; margin-top: -6px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
}
.combo-btn:focus-visible, .combo-btn[aria-expanded=true] { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.filter .combo-btn { font-size: 0.9rem; }
.combo-pop {
  position: fixed; z-index: 50;
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 10px 30px rgba(10, 30, 35, 0.18);
  padding: 6px;
}
.combo-pop[hidden] { display: none; }
.combo-search { min-height: 36px; margin-bottom: 4px; }
.combo-list { list-style: none; margin: 0; padding: 0; max-height: 240px; overflow-y: auto; }
.combo-list li {
  padding: 7px 10px; border-radius: 5px; cursor: pointer;
  font-size: 0.92rem; font-weight: 400; color: var(--ink);
}
.combo-list li.active { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.combo-list li[aria-selected=true] { font-weight: 600; }
.combo-list li[aria-selected=true]::before { content: '\2713'; margin-right: 6px; color: var(--accent); }
.combo-list .combo-add { color: var(--accent); font-weight: 600; border-top: 1px solid var(--line); border-radius: 0 0 5px 5px; }
.combo-list .combo-empty { color: var(--muted); cursor: default; }

.form fieldset { border: 0; padding: 0; margin: 0 0 24px; }
.form legend { font-weight: 600; font-size: 1.05rem; margin-bottom: 12px; padding: 0; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; }
.grid .wide { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; margin-top: 8px; }
.form .form-error { margin-bottom: 16px; }

/* ---------- Login ---------- */

.login {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: var(--side-bg);
}
.login-panel {
  width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 16px;
  padding: 32px; border-radius: 10px; background: var(--surface);
}
.login-panel .brand { color: var(--ink); margin-bottom: 8px; }
.login-panel .brand span { color: var(--muted); }

/* ---------- Layout ---------- */

.shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 28px;
  padding: 22px 16px;
  background: var(--side-bg); color: var(--side-ink);
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.brand strong { display: block; font-size: 1rem; }
.brand span { display: block; font-size: 0.78rem; color: var(--side-muted); }
.brand-mark { width: 32px; height: 32px; flex: none; color: currentColor; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  padding: 9px 12px; border-radius: var(--radius);
  color: var(--side-ink); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: rgba(255, 255, 255, 0.07); }
.nav a.active { background: rgba(255, 255, 255, 0.13); font-weight: 600; box-shadow: inset 3px 0 0 var(--up); }

.me { margin-top: auto; display: flex; flex-direction: column; gap: 2px; font-size: 0.85rem; }
.me span { color: var(--side-muted); }
.me-actions { display: flex; gap: 14px; margin-top: 8px; color: var(--side-ink); }

.view { padding: 32px 40px 64px; max-width: 1240px; width: 100%; outline: none; min-width: 0; }
.topbar, .tabbar { display: none; }
.boot { min-height: 100vh; display: grid; place-items: center; }

.page-head { margin-bottom: 24px; display: flex; flex-direction: column; gap: 4px; }
.page-head.row { flex-direction: row; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.head-actions { display: flex; gap: 8px; }
.back { display: inline-block; margin-bottom: 14px; font-size: 0.9rem; text-decoration: none; }
.back::before { content: '\2039'; margin-right: 6px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 20px 22px; margin-bottom: 20px;
}
.panel > h2 { margin-bottom: 14px; }
.count {
  display: inline-block; min-width: 22px; padding: 0 7px; margin-left: 4px;
  border-radius: 999px; background: color-mix(in srgb, var(--ink) 8%, transparent);
  font-size: 0.78rem; font-weight: 600; text-align: center; vertical-align: 2px;
}

/* ---------- Dashboard ---------- */

.tallies {
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-bottom: 20px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
}
.tally {
  display: flex; flex-direction: column; gap: 6px;
  padding: 16px 18px; text-decoration: none; color: var(--ink);
  border-left: 1px solid var(--line);
}
.tally:first-child { border-left: 0; }
.tally:hover { background: color-mix(in srgb, var(--c) 7%, var(--surface)); }
.tally-n { font-size: 2rem; font-weight: 700; line-height: 1; }
.tally-l { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--muted); font-weight: 500; }

.board { list-style: none; margin: 0; padding: 0; }
.board li + li { border-top: 1px solid var(--line); }
.board-row {
  display: grid; grid-template-columns: 150px minmax(0, 1fr) auto; gap: 20px; align-items: start;
  padding: 14px 4px; color: var(--ink); text-decoration: none;
}
.board-row:hover { background: color-mix(in srgb, var(--c) 5%, transparent); }
.board-time { display: flex; flex-direction: column; border-left: 4px solid var(--c); padding-left: 12px; }
.elapsed { font-size: 1.6rem; font-weight: 700; line-height: 1.1; color: color-mix(in srgb, var(--c) 85%, var(--ink)); }
.board-time small { color: var(--muted); font-size: 0.78rem; }
.board-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.board-main .muted { font-size: 0.85rem; }
.fault { margin-top: 4px; font-size: 0.9rem; }
.board-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; font-size: 0.85rem; }

.uptime { display: flex; align-items: center; gap: 10px; }
.uptime-bar { flex: 1; min-width: 80px; max-width: 220px; height: 8px; border-radius: 4px; background: color-mix(in srgb, var(--down) 25%, var(--line)); overflow: hidden; }
.uptime-bar span { display: block; height: 100%; background: var(--up); }
.uptime .num { font-size: 0.85rem; color: var(--muted); min-width: 38px; }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; margin: 0 -4px; }
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th, .table td { padding: 10px 8px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.table thead th { font-size: 0.8rem; font-weight: 600; color: var(--muted); white-space: nowrap; }
.table tbody tr:last-child > * { border-bottom: 0; }
.table .num { text-align: right; }
.table tr[data-href] { cursor: pointer; }
.table tr[data-href]:hover { background: color-mix(in srgb, var(--accent) 5%, transparent); }
.table tbody th { font-weight: 600; }
.table a { color: var(--ink); font-weight: 600; text-decoration: none; }
.table a:hover { text-decoration: underline; }
.table tr.inactive td { color: var(--muted); }
.table .old { color: var(--muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--muted) 50%, transparent); }
.row-actions { text-align: right; white-space: nowrap; }
.assets .status { font-size: 0.78rem; }

/* ---------- Filters ---------- */

.filters {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end;
  margin-bottom: 16px;
}
.filter { display: flex; flex-direction: column; gap: 4px; font-size: 0.8rem; font-weight: 600; color: var(--muted); min-width: 140px; flex: 1 1 140px; }
.filter.search { flex: 2 1 240px; }
.filter select, .filter input { color: var(--ink); font-weight: 400; font-size: 0.9rem; }
.filter-end { display: flex; align-items: center; gap: 14px; min-height: 40px; }
#results .table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; margin: 0; padding: 0 10px; }

/* ---------- Asset detail ---------- */

.asset-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.asset-head p { margin-top: 4px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.actions:empty { display: none; }

.fault-panel {
  margin-bottom: 20px; padding: 16px 20px;
  border-radius: 10px; border-left: 5px solid var(--c);
  background: color-mix(in srgb, var(--c) 8%, var(--surface));
}
.fault-panel h2 { font-size: 0.9rem; margin-bottom: 6px; color: color-mix(in srgb, var(--c) 75%, var(--ink)); }
.fault-panel p + p { margin-top: 6px; font-size: 0.9rem; }

.banner {
  margin-bottom: 16px; padding: 10px 14px; border-radius: var(--radius);
  background: color-mix(in srgb, var(--maint) 14%, var(--surface));
}

.details { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px 24px; margin: 0; }
.details dt { font-size: 0.8rem; color: var(--muted); margin-bottom: 2px; }
.details dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs [role=tab] {
  border: 0; background: none; font: inherit; font-weight: 600; font-size: 0.9rem;
  color: var(--muted); padding: 10px 12px; cursor: pointer; white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs [role=tab][aria-selected=true] { color: var(--ink); border-bottom-color: var(--accent); }
.pad { padding: 8px 0; }

/* ---------- Admin ---------- */

.section-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.section-head p { max-width: 60ch; font-size: 0.9rem; }
#admin-body > .table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; margin: 0; padding: 0 10px; }
.section-note { margin-bottom: 14px; font-size: 0.9rem; }

.list-tools { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; margin-bottom: 8px; }
.list-tools .filter.search { flex: 1 1 220px; }
.list-add { flex: 1 1 320px; display: flex; }
.list-add[hidden] { display: none; }
.list-add .filter { flex: 1; }
.list-add-row { display: flex; gap: 8px; }
.list-add-row input { flex: 1; }
.list-note { margin: 8px 0 0; font-size: 0.9rem; }
.list-count { margin: 12px 0 4px; font-size: 0.85rem; }
.list-page .table td:first-child { font-weight: 500; }

.checks { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.checks legend { font-size: 0.85rem; font-weight: 600; padding: 0 4px; }

/* ---------- Dialog ---------- */

dialog {
  width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 48px);
  padding: 0; border: 0; border-radius: 12px;
  background: var(--surface); color: var(--ink);
}
dialog::backdrop { background: rgba(10, 25, 30, 0.5); }
.modal { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px 8px; }
.modal-head h2 { font-size: 1.15rem; }
.modal-body { padding: 8px 20px 4px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; }
.modal > .form-error { margin: 10px 20px 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 20px; }

/* ---------- Feedback ---------- */

.loading { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 40px 0; }
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty { padding: 28px 8px; display: flex; flex-direction: column; align-items: flex-start; gap: 12px; color: var(--muted); }
.empty.error p { color: color-mix(in srgb, var(--down) 80%, var(--ink)); }

.toast {
  position: fixed; left: 50%; bottom: 24px; top: auto; right: auto; margin: 0; border: 0; overflow: visible; transform: translate(-50%, 20px);
  max-width: calc(100vw - 32px);
  padding: 10px 16px; border-radius: var(--radius);
  background: var(--side-bg); color: var(--side-ink); font-size: 0.9rem; font-weight: 500;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 100;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--down); color: #fff; }

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}

/* ---------- Login extras ---------- */

.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 64px; }
.pw-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  border: 0; background: none; color: var(--accent); font: inherit; font-size: 0.85rem; font-weight: 600;
  padding: 6px 8px; cursor: pointer; border-radius: 4px;
}

/* ---------- Equipment list controls ---------- */

.list-controls { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; }
.toolbar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.search-box { position: relative; flex: 1 1 280px; display: block; }
.search-box svg {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round;
}
.search-box input { padding-left: 36px; }
.sort { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.sort select { width: auto; min-width: 190px; color: var(--ink); font-weight: 400; }
#toggle-filters[aria-expanded=true] { border-color: var(--accent); color: var(--accent); }

.filter-panel {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px;
  padding: 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
}
.filter-panel[hidden] { display: none; }
.filter-panel .filter-end { grid-column: 1 / -1; justify-content: flex-end; min-height: 0; }
.filter { min-width: 0; }

.status-chips, .active-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.active-chips:empty { display: none; }
.chip {
  --c: var(--accent);
  display: inline-flex; align-items: center; gap: 7px;
  min-height: 34px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink);
  font: inherit; font-size: 0.85rem; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.chip.s-up { --c: var(--up); } .chip.s-down { --c: var(--down); } .chip.s-maint { --c: var(--maint); }
.chip.s-eng { --c: var(--eng); } .chip.s-comm { --c: var(--comm); }
.chip b { font-weight: 700; font-variant-numeric: tabular-nums; }
.chip:hover { border-color: var(--muted); }
.chip.on { border-color: var(--c); background: color-mix(in srgb, var(--c) 12%, var(--surface)); color: color-mix(in srgb, var(--c) 70%, var(--ink)); }
.chip .lamp { width: 8px; height: 8px; }
.chip.removable { background: color-mix(in srgb, var(--accent) 8%, var(--surface)); border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.chip.removable span { font-size: 1.1rem; line-height: 1; color: var(--muted); margin-left: 2px; }

.show-more { display: flex; align-items: center; gap: 14px; justify-content: center; padding: 16px 0; }
.empty-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Export menu */
details.menu { position: relative; }
details.menu > summary { list-style: none; }
details.menu > summary::-webkit-details-marker { display: none; }
details.menu > summary::after {
  content: ''; width: 6px; height: 6px; margin-left: 4px; margin-top: -3px;
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg);
}
.menu-items {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; width: 240px;
  display: flex; flex-direction: column; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 10px 30px rgba(10, 30, 35, 0.18);
}
.menu-items button {
  text-align: left; padding: 9px 10px; border: 0; border-radius: 5px; background: none;
  color: var(--ink); font: inherit; font-size: 0.92rem; cursor: pointer;
}
.menu-items button:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.menu-note { padding: 6px 10px 4px; font-size: 0.78rem; color: var(--muted); border-top: 1px solid var(--line); margin-top: 4px; }

/* ---------- Bulk import ---------- */

.step h2 { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.step-n {
  display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 0.85rem; font-weight: 700; flex: none;
}
@media (prefers-color-scheme: dark) { .step-n { color: #08201f; } }
.step > p { margin-bottom: 14px; max-width: 70ch; }
.step-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 130px; padding: 20px; margin: 6px 0 14px; text-align: center;
  border: 2px dashed var(--line); border-radius: 10px; cursor: pointer;
  background: color-mix(in srgb, var(--accent) 3%, var(--surface));
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dropzone:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.dropzone strong { color: var(--accent); overflow-wrap: anywhere; }
.create-missing { align-items: flex-start; }
.create-missing input { margin-top: 3px; }

.progress { display: flex; flex-direction: column; gap: 8px; padding: 10px 0; }
.progress-text { display: flex; justify-content: space-between; font-size: 0.9rem; }
.progress-bar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.progress-bar span { display: block; height: 100%; background: var(--accent); transition: width 0.3s; }

.check-summary {
  --c: var(--up);
  display: flex; flex-direction: column; gap: 2px; padding: 12px 16px; margin-bottom: 14px;
  border-left: 4px solid var(--c); border-radius: var(--radius);
  background: color-mix(in srgb, var(--c) 9%, var(--surface));
}
.check-summary.bad { --c: var(--down); }
.check-summary span { font-size: 0.85rem; color: var(--muted); overflow-wrap: anywhere; }
.hint-box { padding: 10px 14px; margin-bottom: 14px; border-radius: var(--radius); background: color-mix(in srgb, var(--maint) 12%, var(--surface)); font-size: 0.9rem; }
.new-values { padding: 12px 14px; margin-bottom: 14px; border: 1px solid var(--line); border-radius: var(--radius); }
.new-values p { display: flex; flex-direction: column; gap: 2px; font-size: 0.9rem; }
.new-values ul { margin: 8px 0 0; padding-left: 18px; columns: 2 220px; font-size: 0.9rem; }
.sub { font-size: 0.95rem; margin: 18px 0 8px; }
.err-list { margin: 0; padding-left: 16px; }
.errors td { color: var(--ink); }
.errors .err-list li::marker { color: var(--down); }
.preview { font-size: 0.82rem; }
.preview td { white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Phone menu sheet ---------- */

.sheet-menu .modal-head { align-items: flex-start; }
.sheet-menu .modal-head p { font-size: 0.85rem; margin-top: 2px; }
.sheet-links { display: flex; flex-direction: column; padding: 4px 12px 16px; }
.sheet-links a, .sheet-links button {
  display: block; width: 100%; text-align: left; padding: 14px 10px;
  border: 0; border-top: 1px solid var(--line); background: none;
  color: var(--ink); font: inherit; font-size: 1rem; font-weight: 500; text-decoration: none; cursor: pointer;
}
.sheet-links .danger-text { color: var(--down); }

/* ---------- Medium screens ---------- */

@media (max-width: 1000px) {
  .details { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tallies { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .tally:nth-child(4) { border-left: 0; }
  .tally:nth-child(n+4) { border-top: 1px solid var(--line); }
  .view { padding: 28px 24px 56px; }
}

/* ---------- Phones ---------- */

@media (max-width: 760px) {
  body { font-size: 16px; }
  input, select, textarea, .combo-btn { font-size: 16px; } /* stops iPhone zooming into fields */

  .shell { display: block; padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)); }
  .sidebar { display: none; }

  .topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top, 0px));
    background: var(--side-bg); color: var(--side-ink);
  }
  .topbar .brand { gap: 8px; }
  .topbar .brand-mark { width: 28px; height: 28px; }
  .avatar {
    width: 36px; height: 36px; border-radius: 50%; border: 0; cursor: pointer;
    background: rgba(255, 255, 255, 0.14); color: var(--side-ink); font: inherit; font-weight: 700; font-size: 0.85rem;
  }

  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    display: flex; justify-content: space-around;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--surface); border-top: 1px solid var(--line);
  }
  .tabbar a, .tabbar button {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
    min-height: 60px; padding: 8px 4px 6px; justify-content: center;
    border: 0; background: none; color: var(--muted); font: inherit; font-size: 0.72rem; font-weight: 600;
    text-decoration: none; cursor: pointer;
  }
  .tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
  .tabbar [data-nav=more] svg, .tabbar [data-nav=more] svg circle { fill: currentColor; stroke: none; }
  .tabbar .active { color: var(--accent); }

  .view { padding: 18px 14px 32px; }
  h1 { font-size: 1.4rem; }
  .page-head { margin-bottom: 16px; }
  .page-head.row { align-items: stretch; flex-direction: column; }
  .head-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); gap: 8px; }
  .head-actions .btn, .head-actions summary { width: 100%; }
  .menu-items { left: 0; right: auto; }
  .panel { padding: 16px 14px; border-radius: 10px; }

  /* dashboard */
  .tallies { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tally { border-top: 1px solid var(--line); padding: 14px; }
  .tally:nth-child(-n+2) { border-top: 0; }
  .tally:nth-child(odd) { border-left: 0; }
  .tally:nth-child(even) { border-left: 1px solid var(--line); }
  .tally:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .board-row { grid-template-columns: 1fr; gap: 8px; padding: 14px 2px; }
  .board-side { flex-direction: row; align-items: center; flex-wrap: wrap; }
  .uptime-bar { min-width: 50px; }
  .loc-table th, .loc-table td { padding: 10px 6px; }

  /* list controls */
  .toolbar { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
  .search-box { grid-column: 1 / -1; }
  .sort { min-width: 0; }
  .sort span { display: none; }
  .sort select { min-width: 0; width: 100%; }
  .filter-panel { grid-template-columns: 1fr 1fr; padding: 12px; }
  .status-chips { flex-wrap: nowrap; overflow-x: auto; margin: 0 -14px; padding: 2px 14px; scrollbar-width: none; }
  .status-chips::-webkit-scrollbar { display: none; }

  /* equipment rows become cards */
  #results .table-wrap { border: 0; background: none; padding: 0; overflow: visible; }
  .assets thead { display: none; }
  .assets, .assets tbody { display: block; }
  .assets tr {
    display: flex; flex-wrap: wrap; align-items: flex-start; gap: 4px 12px;
    padding: 12px 14px; margin-bottom: 8px;
    background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  }
  .assets td { border: 0; padding: 0; }
  .assets .c-name { order: 1; flex: 1 1 60%; font-size: 1rem; }
  .assets .c-status { order: 2; margin-left: auto; }
  .assets .c-tag { order: 3; flex-basis: 100%; color: var(--muted); font-size: 0.85rem; }
  .assets .c-meta { order: 4; font-size: 0.85rem; }
  .assets .c-meta::before { content: attr(data-label) ' '; color: var(--muted); }
  .assets .c-meta:empty { display: none; }
  .assets .c-asg { flex-basis: 100%; }
  .assets tr.inactive { opacity: 0.7; }

  /* history and admin tables become stacked cards */
  .table.stack thead { display: none; }
  .table.stack, .table.stack tbody { display: block; }
  .table.stack tr { display: block; padding: 12px 0; border-bottom: 1px solid var(--line); }
  .table.stack tbody tr:last-child { border-bottom: 0; }
  .table.stack td { display: flex; gap: 10px; padding: 3px 0; border: 0; white-space: normal; }
  .table.stack td[data-label]::before { content: attr(data-label); flex: 0 0 92px; color: var(--muted); font-size: 0.85rem; }
  .table.stack td:empty { display: none; }
  .table.stack .stack-head { font-weight: 600; padding-bottom: 6px; }
  .table.stack .row-actions { justify-content: flex-start; padding-top: 8px; }
  .table.stack td.nowrap[data-label] { flex-wrap: wrap; }

  /* detail page */
  .asset-head { flex-direction: column; gap: 10px; }
  .actions { display: grid; grid-template-columns: 1fr 1fr; }
  .actions .btn.primary { grid-column: 1 / -1; min-height: 46px; }
  .actions .btn.ghost { grid-column: 1 / -1; }
  .details { grid-template-columns: 1fr 1fr; gap: 14px 16px; }

  /* forms */
  .grid { grid-template-columns: 1fr; }
  .form-actions {
    position: sticky; bottom: calc(60px + env(safe-area-inset-bottom, 0px));
    margin: 0 -14px -16px; padding: 12px 14px;
    background: var(--surface); border-top: 1px solid var(--line);
  }
  .form-actions .btn { flex: 1; min-height: 46px; }
  .shell.form-page { padding-bottom: 0; }
  .shell.form-page .tabbar { display: none; }
  .shell.form-page .form-actions { bottom: 0; padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
  .shell.form-page .view { padding-bottom: 0; }
  .step .form-actions { position: static; margin: 12px 0 0; padding: 0; border: 0; background: none; }

  /* dialogs become bottom sheets */
  dialog {
    width: 100vw; max-width: 100vw; max-height: 92vh;
    margin: auto 0 0; border-radius: 16px 16px 0 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .modal { max-height: 92vh; }
  .modal-foot .btn { flex: 1; min-height: 46px; }

  .combo-list { max-height: 50vh; }
  .btn { min-height: 42px; }
  .btn.small { min-height: 36px; }
  .list-add-row .btn { min-height: 40px; }
}

@media (max-width: 760px) {
  .toast { bottom: calc(76px + env(safe-area-inset-bottom, 0px)); }
}
