/* M2T, in the Utileyes visual language: Inter, Tailwind gray and neutral
   scales, green primary actions, blue focus, sage as the brand accent.
   Light by default; html.dark switches every token (same toggle as Utileyes). */

[hidden] { display: none !important; }

:root {
  --bg: #f9fafb;            /* gray-50: page */
  --surface: #ffffff;       /* cards, panels, sidebar */
  --surface-2: #f3f4f6;     /* gray-100: table heads, hovers */
  --ink: #1f2937;           /* gray-800 */
  --muted: #6b7280;         /* gray-500 */
  --rule: #e5e7eb;          /* gray-200 */
  --rule-strong: #d1d5db;   /* gray-300 */
  --primary: #16a34a;       /* green-600 */
  --primary-hover: #15803d; /* green-700 */
  --primary-soft: #dcfce7;  /* green-100 */
  --link: #2563eb;          /* blue-600 */
  --focus: #3b82f6;         /* blue-500 */
  --brand: #566456;         /* Utileyes sage */
  --brand-soft: #e9ede8;
  --p1: #b91c1c; --p1-soft: #fee2e2;
  --p2: #b45309; --p2-soft: #fef3c7;
  --p3: #1d4ed8; --p3-soft: #dbeafe;
  --p4: #4b5563; --p4-soft: #e5e7eb;
  --ok: #15803d; --ok-soft: #dcfce7;
  --warn: #a16207; --warn-soft: #fef9c3;
  --shadow: 0 1px 2px #0000000d, 0 1px 3px #0000001a;
  --shade: #11182766;
  --logo-filter: none;
  color-scheme: light;
}
html.dark {
  --bg: #171717;            /* neutral-900 */
  --surface: #262626;       /* neutral-800 */
  --surface-2: #2f2f2f;
  --ink: #e5e5e5;           /* neutral-200 */
  --muted: #a3a3a3;         /* neutral-400 */
  --rule: #404040;          /* neutral-700 */
  --rule-strong: #525252;
  --primary: #22c55e;
  --primary-hover: #16a34a;
  --primary-soft: #14532d;
  --link: #60a5fa;
  --focus: #60a5fa;
  --brand: #9fb59f;
  --brand-soft: #2a312a;
  --p1: #fca5a5; --p1-soft: #450a0a;
  --p2: #fcd34d; --p2-soft: #451a03;
  --p3: #93c5fd; --p3-soft: #172554;
  --p4: #d4d4d4; --p4-soft: #3f3f46;
  --ok: #86efac; --ok-soft: #14532d;
  --warn: #fde047; --warn-soft: #422006;
  --shadow: 0 1px 3px #00000066;
  --shade: #000000a0;
  --logo-filter: invert(1) hue-rotate(180deg) brightness(1.4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 14px/1.5 "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--link); text-decoration: none; } a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1, h2, h3, h4 { color: var(--ink); text-wrap: balance; letter-spacing: -0.01em; }
h1 { font-size: 22px; font-weight: 600; margin: 0 0 4px; }
h2 { font-size: 16px; font-weight: 600; margin: 26px 0 10px; }
h3 { font-size: 15px; font-weight: 600; }
.sub { color: var(--muted); margin: 0 0 18px; max-width: 80ch; }
.muted { color: var(--muted); } .small { font-size: 12px; }
code { font: 12px ui-monospace, Consolas, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* Layout: sidebar + content. */
.shell { display: flex; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; width: 232px; flex: none; display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--rule); padding: 16px 12px; gap: 14px; z-index: 20; }
.sidebar .brand { display: flex; flex-direction: column; gap: 6px; padding: 2px 8px 10px; border-bottom: 1px solid var(--rule); }
.sidebar .brand img { width: 150px; height: auto; filter: var(--logo-filter); }
.sidebar .product { font-size: 12px; font-weight: 600; color: var(--brand); letter-spacing: .06em; text-transform: uppercase; }
#nav { display: flex; flex-direction: column; gap: 2px; }
#nav a { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 8px; color: var(--ink); font-size: 14px; }
#nav a:hover { background: var(--surface-2); text-decoration: none; }
#nav a.active { background: var(--brand-soft); color: var(--ink); font-weight: 600; }
#nav a svg { width: 18px; height: 18px; flex: none; color: var(--muted); }
#nav a.active svg { color: var(--brand); }
.sidebar .workspace { display: flex; flex-direction: column; gap: 4px; padding: 0 8px; font-size: 12px; color: var(--muted); }
.sidebar .workspace select { width: 100%; }
.sidebar .spacer { flex: 1; }
.sidebar .foot { display: flex; flex-direction: column; gap: 8px; padding: 10px 8px 0; border-top: 1px solid var(--rule); font-size: 13px; }
#who a { color: var(--ink); font-weight: 500; overflow-wrap: anywhere; }
.sidebar .foot .row { gap: 6px; align-items: center; }
.icon-btn { display: inline-flex; align-items: center; gap: 6px; background: none; border: 1px solid var(--rule); color: var(--ink);
  padding: 5px 9px; border-radius: 8px; font-size: 13px; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 16px; height: 16px; }
main#view { flex: 1; min-width: 0; padding: 28px 32px 48px; }
main#view > * { max-width: 1280px; }
main#view.full { padding: 0; }
main#view.full > * { max-width: none; }
body.signed-out .sidebar { display: none; }

/* Surfaces. */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); }
.card .k { font-size: 12px; color: var(--muted); font-weight: 500; }
.card .v { font-size: 24px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.card .n { font-size: 12px; color: var(--muted); margin-top: 2px; }
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; padding: 16px 18px; box-shadow: var(--shadow); margin: 14px 0; }
.panel h2 { margin-top: 0; }
.panel.narrow { max-width: 480px; }

/* Tables. */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--rule); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
th { font-weight: 600; font-size: 12px; color: var(--muted); background: var(--surface-2); position: sticky; top: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions-cell { white-space: nowrap; }
.pager { display: flex; gap: 8px; align-items: center; margin: 10px 0; }

/* Status pills. */
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap;
  background: var(--surface-2); color: var(--ink); }
.pill.p1 { background: var(--p1-soft); color: var(--p1); } .pill.p2 { background: var(--p2-soft); color: var(--p2); }
.pill.p3 { background: var(--p3-soft); color: var(--p3); } .pill.p4 { background: var(--p4-soft); color: var(--p4); }
.pill.done, .pill.loaded, .pill.applied { background: var(--ok-soft); color: var(--ok); }
.pill.held, .pill.queued, .pill.running, .pill.processing, .pill.received { background: var(--warn-soft); color: var(--warn); }
.pill.failed, .pill.late { background: var(--p1-soft); color: var(--p1); }

/* Controls. */
button, .btn { background: var(--primary); color: #fff; border: 1px solid transparent; border-radius: 8px; padding: 8px 14px;
  font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; display: inline-block; }
button:hover, .btn:hover { background: var(--primary-hover); text-decoration: none; }
button.secondary, .btn.secondary { background: var(--surface); color: var(--ink); border-color: var(--rule-strong); }
button.secondary:hover, .btn.secondary:hover { background: var(--surface-2); }
button:disabled { opacity: .5; cursor: default; }
button.small-btn { padding: 4px 10px; font-size: 13px; }
input, select, textarea { font: inherit; padding: 7px 10px; border: 1px solid var(--rule-strong); border-radius: 8px;
  background: var(--surface); color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
form.row, .row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row.tight { gap: 8px; align-items: center; margin-bottom: 6px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 500; }
label.inline { flex-direction: row; align-items: center; gap: 6px; color: var(--ink); font-weight: 400; }
form.stack { display: flex; flex-direction: column; gap: 12px; }
details summary { cursor: pointer; color: var(--link); }
pre { background: var(--surface-2); padding: 8px; border-radius: 8px; overflow-x: auto; font-size: 12px; }
.notice { padding: 10px 14px; border-radius: 10px; background: var(--brand-soft); margin: 12px 0; }
.notice.error { background: var(--p1-soft); color: var(--p1); }

/* Sign-in. */
.login { max-width: 380px; margin: 12vh auto; display: flex; flex-direction: column; gap: 14px; background: var(--surface);
  border: 1px solid var(--rule); border-radius: 14px; padding: 28px 28px 24px; box-shadow: var(--shadow); }
.login img { width: 170px; filter: var(--logo-filter); }
.login .product { font-size: 12px; font-weight: 600; color: var(--brand); letter-spacing: .06em; text-transform: uppercase; margin-top: -6px; }

/* Map. */
#map { position: relative; height: 100vh; overflow: hidden; }
#basemap { position: absolute; inset: 0; }
.map-panel { position: absolute; top: 12px; left: 12px; z-index: 2; width: 300px; max-height: calc(100% - 48px); overflow-y: auto;
  background: color-mix(in srgb, var(--surface) 96%, transparent); border: 1px solid var(--rule); border-radius: 12px;
  padding: 12px 14px; font-size: 13px; box-shadow: var(--shadow); }
.map-panel .legend div { display: flex; align-items: center; gap: 6px; margin: 2px 0; }
.map-panel details.legend summary { margin-top: 6px; }
.map-panel .toggles { margin-top: 8px; display: flex; flex-direction: column; gap: 2px; }
.map-panel .toggles label { flex-direction: row; gap: 6px; align-items: center; color: var(--ink); font-weight: 400; }
.map-panel .basemap-pick { flex-direction: row; align-items: center; gap: 6px; margin-top: 8px; color: var(--ink); }
.map-search { position: relative; margin-bottom: 8px; }
.map-search input { width: 100%; }
.search-results { position: absolute; left: 0; right: 0; top: calc(100% + 2px); z-index: 5; background: var(--surface);
  border: 1px solid var(--rule); border-radius: 8px; box-shadow: 0 6px 18px #0002; max-height: 320px; overflow-y: auto; }
.search-results button { display: flex; gap: 8px; align-items: center; width: 100%; text-align: left; background: none;
  color: var(--ink); border-radius: 0; padding: 7px 9px; font-size: 13px; font-weight: 400; }
.search-results button:hover, .search-results button:focus { background: var(--surface-2); }
.search-results .kind { font-size: 11px; color: var(--muted); min-width: 78px; text-transform: uppercase; letter-spacing: .04em; }
.filter-pane { border: 1px solid var(--rule); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; display: flex; flex-direction: column; gap: 3px; }
.swatch { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.swatch.sq { border-radius: 2px; border: 1.5px solid #1e1e23; }
.legend .line { width: 18px; height: 3px; display: inline-block; border-radius: 1px; }
.legend .line.dashed { background: repeating-linear-gradient(90deg, #8a6fb0 0 4px, transparent 4px 7px); height: 2px; }
.side-panel { position: absolute; top: 12px; right: 56px; bottom: 36px; z-index: 2; width: 340px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; padding: 14px 16px; font-size: 13px; box-shadow: 0 4px 16px #0003; }
.side-panel h3 { margin: 0 24px 2px 0; }
.side-panel .close { position: absolute; top: 6px; right: 8px; background: none; color: var(--muted); font-size: 20px; padding: 0 6px; }
.side-panel .actions { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.side-panel label { margin-top: 10px; }
.kv { margin-top: 8px; } .kv th { background: none; position: static; width: 42%; color: var(--muted); font-weight: 500; }
.verdict { margin: 10px 0 4px; padding: 7px 10px; border-radius: 8px; background: var(--surface-2); }
.verdict.good { background: var(--ok-soft); color: var(--ok); } .verdict.bad { background: var(--p1-soft); color: var(--p1); }
/* Map controls stay light in both themes: the base maps are light, and the
   control icons are dark images that vanish on a dark button. */
.maplibregl-ctrl { color-scheme: light; }
.maplibregl-ctrl-group { background: #fff !important; }
.maplibregl-ctrl-group button { background-color: #fff !important; color: #1f2937; border-radius: 0; padding: 0; }
.maplibregl-ctrl-group button:hover { background-color: #f3f4f6 !important; }
.maplibregl-ctrl-group button:first-child { border-radius: 4px 4px 0 0; }
.maplibregl-ctrl-group button:last-child { border-radius: 0 0 4px 4px; }
.maplibregl-ctrl-group button:only-child { border-radius: 4px; }

/* Overlay (voltage viewer) and drawer (side edits). */
.overlay { position: fixed; inset: 0; z-index: 50; background: var(--shade); display: flex; align-items: flex-start; justify-content: center;
  padding: max(24px, env(safe-area-inset-top, 0px)) 16px 24px; overflow-y: auto; }
.overlay-card { position: relative; background: var(--surface); color: var(--ink); border-radius: 14px; padding: 20px 22px; width: 100%;
  max-width: 640px; box-shadow: 0 10px 40px #0004; }
.overlay-card.wide { max-width: 1160px; }
.overlay-card h3 { margin: 0 28px 6px 0; }
.overlay-card .close { position: absolute; top: 8px; right: 10px; background: none; color: var(--muted); font-size: 22px; padding: 0 6px; }
#v-chart { min-height: 330px; }
#v-chart .u-legend { font-size: 12px; color: var(--ink); }
.drawer-shade { position: fixed; inset: 0; z-index: 60; background: var(--shade); }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; z-index: 61; width: min(460px, 100vw); background: var(--surface);
  box-shadow: -8px 0 30px #0003; display: flex; flex-direction: column; transform: translateX(100%); transition: transform .18s ease; }
.drawer.open { transform: none; }
.drawer header { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--rule); }
.drawer header h3 { margin: 0; }
.drawer header .close { background: none; color: var(--muted); font-size: 22px; padding: 0 6px; }
.drawer-body { padding: 16px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.drawer fieldset { border: 1px solid var(--rule); border-radius: 10px; padding: 10px 12px; margin: 0; }
.drawer legend { font-weight: 600; padding: 0 4px; }
dl.facts-list { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
dl.facts-list dt { color: var(--muted); } dl.facts-list dd { margin: 0; }

/* Data quality cards act as filters. */
button.card.flag-card { text-align: left; color: var(--ink); cursor: pointer; font: inherit; background: var(--surface); }
button.card.flag-card:hover { border-color: var(--brand); background: var(--surface); }
button.card.flag-card.zero { opacity: .55; }

/* Narrow screens: the sidebar becomes a slim top bar; the menu opens below it. */
.menu { display: contents; }
.menu-btn { display: none; }
@media (max-width: 900px) {
  .shell { flex-direction: column; min-height: 100dvh; }
  .sidebar { position: sticky; top: 0; height: auto; width: auto; flex-direction: column; gap: 0;
    padding: max(8px, env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) 8px max(12px, env(safe-area-inset-left, 0px));
    border-right: 0; border-bottom: 1px solid var(--rule); }
  .sidebar .brand-row { align-items: center; border: 0; }
  .sidebar .brand { border: 0; padding: 0; flex-direction: row; align-items: center; gap: 10px; min-width: 0; }
  .sidebar .brand img { width: 104px; }
  .sidebar .product { font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .menu-btn { display: inline-flex; background: none; color: var(--ink); border: 1px solid var(--rule); padding: 8px; border-radius: 10px; }
  .menu-btn:hover { background: var(--surface-2); }
  .menu-btn svg { width: 22px; height: 22px; }
  .menu { display: none; }
  html.menu-open .menu { display: flex; flex-direction: column; gap: 14px; padding: 12px 0 6px; max-height: calc(100dvh - 64px); overflow-y: auto; }
  #nav a { padding: 11px 10px; font-size: 15px; }
  .sidebar .spacer { display: none; }
  .sidebar .workspace { padding: 0 10px; }
  .sidebar .foot { padding: 12px 10px 0; }
  .sidebar .foot .row { justify-content: flex-start; }
  .sidebar .foot .icon-btn { padding: 8px 12px; }
  main#view { padding: 18px max(16px, env(safe-area-inset-left, 0px)) calc(40px + env(safe-area-inset-bottom, 0px)); }
  #map { height: calc(100dvh - 61px); }
  .side-panel { left: 12px; right: 12px; width: auto; top: auto; max-height: 55vh; }
  .map-panel { width: min(300px, 70vw); }
  /* The collapsed desktop menu has no meaning here. */
  html.nav-collapsed .sidebar { width: auto; padding-left: max(12px, env(safe-area-inset-left, 0px)); padding-right: max(12px, env(safe-area-inset-right, 0px)); }
  html.nav-collapsed .sidebar .brand-row { flex-direction: row; padding-bottom: 0; }
  html.nav-collapsed .sidebar .logo-full { display: block; }
  html.nav-collapsed .sidebar .product { display: inline; }
  html.nav-collapsed .sidebar .logo-mark { display: none; }
  html.nav-collapsed #nav a { justify-content: flex-start; padding: 11px 10px; }
  html.nav-collapsed #nav a span, html.nav-collapsed .sidebar .foot .icon-btn span { display: inline; }
  html.nav-collapsed .sidebar .workspace, html.nav-collapsed #who { display: flex; }
  html.nav-collapsed .sidebar .foot { align-items: stretch; padding: 12px 10px 0; }
  html.nav-collapsed .sidebar .foot .row { flex-direction: row; }
}
@media (prefers-reduced-motion: reduce) { .drawer { transition: none; } }

/* Collapsible menu. */
.sidebar .brand-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 6px; border-bottom: 1px solid var(--rule); }
.sidebar .brand-row .brand { border: 0; }
.sidebar .logo-mark { display: none; width: 30px; }
.collapse-btn { background: none; color: var(--muted); border: 1px solid transparent; padding: 4px; border-radius: 8px; margin-top: 2px; }
.collapse-btn:hover { background: var(--surface-2); color: var(--ink); }
.collapse-btn svg { width: 18px; height: 18px; display: block; transition: transform .15s ease; }
html.nav-collapsed .sidebar { width: 68px; padding-left: 10px; padding-right: 10px; }
html.nav-collapsed .sidebar .brand-row { flex-direction: column; align-items: center; padding-bottom: 8px; }
html.nav-collapsed .sidebar .logo-full, html.nav-collapsed .sidebar .product { display: none; }
html.nav-collapsed .sidebar .logo-mark { display: block; }
html.nav-collapsed .sidebar .brand { padding: 0; }
html.nav-collapsed .collapse-btn svg { transform: rotate(180deg); }
html.nav-collapsed #nav a { justify-content: center; padding: 9px 0; }
html.nav-collapsed #nav a span, html.nav-collapsed .sidebar .workspace, html.nav-collapsed #who,
html.nav-collapsed .sidebar .foot .icon-btn span { display: none; }
html.nav-collapsed .sidebar .foot { align-items: center; padding-left: 0; padding-right: 0; }
html.nav-collapsed .sidebar .foot .row { flex-direction: column; }
html.nav-collapsed #signout { padding: 5px 6px; font-size: 11px; }
@media (max-width: 900px) {
  .collapse-btn { display: none !important; }
  .sidebar .brand-row { border: 0; }
}

/* Voltage evidence. */
.overlay-card.voltage { padding: 18px 20px 20px; }
.v-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.v-head h3 { margin: 0 0 2px; display: flex; gap: 8px; align-items: center; }
.overlay-card.voltage .close { position: static; }
.v-summary { margin: 12px 0 14px; padding: 10px 14px; border-radius: 10px; background: var(--surface-2); max-width: none; line-height: 1.6; }
.key { display: inline-block; width: 18px; height: 3px; border-radius: 2px; background: var(--c); vertical-align: middle; margin: 0 4px 0 2px; }
.key.thick { height: 5px; }
.key-row { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); }
.v-body { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; align-items: start; }
.v-main { min-width: 0; }
.v-controls { justify-content: space-between; margin-bottom: 6px; }
.seg { display: inline-flex; border: 1px solid var(--rule-strong); border-radius: 8px; overflow: hidden; }
.seg button { background: var(--surface); color: var(--ink); border: 0; border-radius: 0; padding: 5px 12px; font-size: 13px; font-weight: 500; }
.seg button + button { border-left: 1px solid var(--rule-strong); }
.seg button.on { background: var(--brand-soft); color: var(--ink); }
.seg button:hover { background: var(--surface-2); }
.v-details { margin-top: 12px; }
.v-details summary { font-size: 13px; }
.v-side { border: 1px solid var(--rule); border-radius: 12px; padding: 10px; max-height: 560px; overflow-y: auto; background: var(--surface); }
.v-side-head { display: flex; justify-content: space-between; align-items: baseline; padding: 2px 4px 8px; }
.v-group { border-top: 1px solid var(--rule); padding: 8px 0 4px; }
.v-group-head { display: flex; justify-content: space-between; align-items: center; padding: 0 4px 4px; font-size: 12px; font-weight: 600; }
.v-meter { display: grid; grid-template-columns: 18px 1fr auto; grid-template-areas: "box id r" "box dist dist"; gap: 0 8px;
  align-items: center; padding: 5px 6px; border-radius: 8px; color: var(--ink); font-size: 13px; font-weight: 400; cursor: pointer; }
.v-meter:hover { background: var(--surface-2); }
.v-meter input { grid-area: box; margin: 0; }
.v-meter .v-id { grid-area: id; }
.v-meter .v-r { grid-area: r; font-size: 12px; font-variant-numeric: tabular-nums; }
.v-meter .v-r.ok { color: var(--ok); } .v-meter .v-r.no { color: var(--muted); }
.v-meter .v-dist { grid-area: dist; }
.v-meter.subject { grid-template-columns: 22px 1fr; grid-template-areas: none; background: var(--surface-2); margin-bottom: 6px; cursor: default; }
@media (max-width: 900px) { .v-body { grid-template-columns: 1fr; } .v-side { max-height: 320px; } }

/* Map controls, in the Utileyes pattern: buttons top right, one popup at a time,
   legend bottom left, details on the left. */
.m2t-tools button { position: relative; display: flex; align-items: center; justify-content: center; }
.m2t-tools button svg { width: 17px; height: 17px; color: #1f2937; }
.m2t-tools button.on { background-color: #e9ede8 !important; }
.m2t-tools .badge { position: absolute; top: -5px; right: -6px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px;
  background: var(--primary); color: #fff; font-size: 10px; line-height: 16px; font-weight: 600; }
.map-pop { position: absolute; top: 10px; right: 52px; z-index: 4; width: 300px; max-height: calc(100% - 20px); display: flex; flex-direction: column;
  gap: 8px; background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; padding: 12px 14px; box-shadow: 0 10px 30px #0003; font-size: 13px; }
.map-pop.wide { width: 340px; }
.map-pop header { display: flex; justify-content: space-between; align-items: center; }
.map-pop .close { background: none; color: var(--muted); font-size: 20px; padding: 0 4px; }
.map-pop .search-results { position: static; box-shadow: none; max-height: 360px; }
.map-pop .search-results:empty { display: none; }
.f-scroll { overflow-y: auto; display: flex; flex-direction: column; }
.f-sec { border-top: 1px solid var(--rule); }
.f-head { display: flex; justify-content: space-between; align-items: center; width: 100%; background: none; color: var(--ink);
  border-radius: 0; padding: 9px 0; font-weight: 600; font-size: 13px; }
.f-head:hover { background: none; }
.caret::after { content: "\25BE"; color: var(--muted); }
.f-sec.collapsed .caret::after, .legend-head[aria-expanded="false"] .caret::after { content: "\25B8"; }
.f-sec.collapsed .f-body { display: none; }
.f-body { display: flex; flex-direction: column; gap: 8px; padding-bottom: 10px; }
.f-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; margin-top: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--rule);
  border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 500; }
.chip:hover { background: var(--surface-2); color: var(--ink); }
.chip.on { background: var(--brand-soft); color: var(--ink); border-color: var(--brand); }
.map-pop footer { border-top: 1px solid var(--rule); padding-top: 8px; }
.link-btn { background: none; color: var(--link); padding: 2px 4px; font-size: 12px; font-weight: 500; }
.link-btn:hover { background: none; text-decoration: underline; }
.basemaps { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; }
.map-legend { position: absolute; left: 12px; bottom: 28px; z-index: 2; width: 260px; background: color-mix(in srgb, var(--surface) 95%, transparent);
  border: 1px solid var(--rule); border-radius: 12px; padding: 8px 12px; font-size: 12px; box-shadow: var(--shadow); }
.legend-head { display: flex; justify-content: space-between; width: 100%; background: none; color: var(--ink); padding: 2px 0; border-radius: 0; font-weight: 600; font-size: 12px; }
.legend-head:hover { background: none; }
.legend-body { display: flex; flex-direction: column; gap: 3px; margin-top: 6px; }
.legend-body div { display: flex; align-items: center; gap: 7px; }
.map-status { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 2; background: color-mix(in srgb, var(--surface) 94%, transparent);
  border: 1px solid var(--rule); border-radius: 999px; padding: 5px 14px; font-size: 12px; color: var(--muted); box-shadow: var(--shadow); white-space: nowrap; max-width: calc(100% - 140px); overflow: hidden; text-overflow: ellipsis; }
.side-panel.left { left: 12px; right: auto; top: 12px; bottom: auto; max-height: calc(100% - 24px); }
@media (max-width: 900px) {
  .map-pop, .map-pop.wide { left: 12px; right: 52px; width: auto; }
  .side-panel.left { right: 12px; width: auto; top: auto; bottom: 12px; max-height: 55vh; }
  .map-status { top: auto; bottom: 8px; }
  .map-legend { left: 8px; bottom: 34px; width: auto; min-width: 120px; max-width: calc(100% - 70px); }
}
.map-legend .line { width: 18px; height: 3px; display: inline-block; border-radius: 1px; flex: none; }
.map-legend .line.dashed { background: repeating-linear-gradient(90deg, #8a6fb0 0 4px, transparent 4px 7px); height: 2px; }
/* The legend steps aside while a meter or transformer panel is open. */
.side-panel.left:not([hidden]) + .map-legend { display: none; }
.sidebar .brand img.logo-mark { width: 32px; }
html.nav-collapsed #signout { padding: 5px 9px; font-size: 13px; }
.copy-row { display: flex; gap: 6px; margin-top: 6px; }
.copy-row input { flex: 1; min-width: 0; font: 12px ui-monospace, Consolas, monospace; }
.login a.small { align-self: flex-start; }
main#view > .login { max-width: 400px; }

/* Phones. */
@media (max-width: 640px) {
  /* 16px stops iOS from zooming the page when a field gets focus. */
  input, select, textarea { font-size: 16px; }
  h1 { font-size: 20px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .card { padding: 12px; }
  .card .v { font-size: 20px; }
  form.row > label, .row > label { flex: 1 1 140px; }
  form.row select, form.row input { width: 100%; }

  /* Tables as stacked cards: one card per row, column names beside values. */
  .table-wrap { overflow: visible; background: none; border: 0; box-shadow: none; border-radius: 0; }
  .table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; width: 100%; }
  .table-wrap thead, .table-wrap tr.head-row { display: none; }
  .table-wrap tr { background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; box-shadow: var(--shadow);
    padding: 8px 0; margin-bottom: 10px; }
  .table-wrap td { position: relative; border: 0; padding: 5px 14px 5px calc(38% + 10px); min-height: 30px;
    text-align: left !important; overflow-wrap: anywhere; }
  .table-wrap td::before { content: attr(data-label); position: absolute; left: 14px; top: 6px; width: calc(38% - 18px);
    color: var(--muted); font-size: 12px; font-weight: 500; }
  .table-wrap td[data-label=""] { padding-left: 14px; }
  .table-wrap td[data-label=""]::before { display: none; }
  .table-wrap td:empty { display: none; }
  td.actions-cell { white-space: normal; }
  td.actions-cell button, td.actions-cell .btn { margin: 2px 4px 2px 0; padding: 8px 12px; }
  .pager { justify-content: space-between; }

  /* Voltage viewer fills the screen. */
  .overlay { padding: 0; }
  .overlay-card, .overlay-card.wide { max-width: none; min-height: 100dvh; border-radius: 0;
    padding: max(14px, env(safe-area-inset-top, 0px)) 14px calc(20px + env(safe-area-inset-bottom, 0px)); }
  .v-head { flex-wrap: wrap; }
  .v-head > div:first-child { flex: 1 1 200px; min-width: 0; }
  .v-head h3 { flex-wrap: wrap; font-size: 16px; }
  .v-head .row.tight { margin-left: auto; }
  .overlay-card.voltage .close { font-size: 26px; }
  .v-summary { font-size: 13px; padding: 10px 12px; }
  .v-controls { flex-direction: column; align-items: flex-start; }
  #v-chart { min-height: 260px; }
  .v-side { max-height: none; }

  /* Map popups and panels as sheets. */
  .map-pop, .map-pop.wide { left: 8px; right: 52px; top: 8px; max-height: calc(100% - 16px); }
  .map-status { top: 8px; bottom: auto; left: 8px; transform: none; max-width: calc(100% - 64px); }
  .side-panel, .side-panel.left { left: 8px; right: 8px; bottom: 8px; max-height: 60%; border-radius: 14px; }
  .chip { padding: 7px 12px; font-size: 13px; }
  .drawer-body { padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
  .login { margin: 6vh 16px; padding: 24px 20px 20px; }
}
