:root {
  --bg: #f8f9fa;
  --fg: #1a1a1a;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-soft: #eff6ff;
  --border: #e5e5e5;
  --border-strong: #d1d5db;
  --error: #b91c1c;
  --error-soft: #fef2f2;

  /* Highlight palette — softer than Excel's */
  --hl-anchor: #dbeafe;       /* blue */
  --hl-anchor-border: #93c5fd;
  --hl-route-end: #fed7aa;    /* orange */
  --hl-route-start: #bbf7d0;  /* green */
  --hl-dwell: #fef3c7;        /* yellow */
  --hl-banner: #f3f4f6;       /* gray */

  --rail-w: 220px;
  --rail-w-collapsed: 56px;
  --topbar-h: 56px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  margin: 0;
  line-height: 1.5;
  font-size: 14px;
}
button {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 6px;
  padding: 7px 12px;
  background: var(--accent);
  color: white;
}
button:hover { background: #1d4ed8; }
button.secondary {
  background: white;
  color: var(--fg);
  border: 1px solid var(--border-strong);
}
button.secondary:hover { background: #f3f4f6; }
button.ghost {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
}
button.ghost:hover { background: #f3f4f6; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
input, select {
  font: inherit;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: white;
  color: var(--fg);
}
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
/* Placeholder colour — light grey, opacity:1 to neutralize Firefox's default
   placeholder fade. Used by override-with-fallback inputs (Routes name,
   Lanes Google km/hr) where the placeholder IS the fallback value, so the
   curator needs to clearly see "not set" vs. "set with a strange style".
   Picked over var(--muted) (#6b7280) which is dark enough to read as set. */
input::placeholder, textarea::placeholder { color: #b3b8c0; opacity: 1; }
/* Route detail header name input — sits flush with the modal body, full-width,
   same visual weight as the prior static label. */
.name-input {
  width: 100%;
  padding: 6px 8px;
  font-size: 16px;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 4px;
  box-sizing: border-box;
}
code { background: #f3f4f6; padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.hidden { display: none !important; }
.msg { padding: 10px 12px; border-radius: 6px; font-size: 14px; margin-top: 12px; }
.msg.error { background: var(--error-soft); color: var(--error); }
.msg.info { background: var(--accent-soft); color: var(--accent); }
.muted { color: var(--muted); }

/* — Sign-in screen — */
#signin-root {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.signin-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.signin-card h1 { font-size: 20px; font-weight: 600; margin: 0 0 4px; }
.signin-card .sub { color: var(--muted); margin: 0 0 20px; font-size: 14px; }
.signin-card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.signin-card .row { display: flex; gap: 8px; }
.signin-card input[type=email] { flex: 1; }

/* Google sign-in button (DM-4) — single action, white card-on-card, with the
   four-colour Google mark. Replaces the editor's magic-link email two-step. */
.google-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  margin-top: 4px;
  padding: 10px 14px;
  background: white;
  color: #1f2328;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
}
.google-btn:hover { background: #f9fafb; }
.google-btn:disabled { opacity: 0.6; cursor: default; }
.g-logo {
  display: inline-block;
  width: 18px;
  height: 18px;
  border-radius: 2px;
  background: conic-gradient(#ea4335 0 25%, #fbbc05 0 50%, #34a853 0 75%, #4285f4 0 100%);
  -webkit-mask: radial-gradient(circle at center, transparent 5px, #000 5.5px);
          mask: radial-gradient(circle at center, transparent 5px, #000 5.5px);
}
.signin-hint { margin-top: 16px; font-size: 12.5px; color: var(--muted); }

/* — App shell — */
#app-shell {
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
  /* Middle row is `auto` — the deploy/update banner slot; collapses to 0 height
     when empty (DM-22, update-lifecycle.js). */
  grid-template-rows: var(--topbar-h) auto 1fr;
  grid-template-areas:
    "rail topbar"
    "rail banner"
    "rail main";
  min-height: 100vh;
  /* Cap the shell at the viewport so wide content in the 1fr track can't
     push the whole grid (and the body's horizontal scroll) past the right
     edge. Combined with min-width: 0 on main#view-host, this forces the
     main column to stay within (100vw - rail width). */
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
}
#app-shell.rail-collapsed { grid-template-columns: var(--rail-w-collapsed) 1fr; }
.left-rail {
  grid-area: rail;
  background: white;
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
}
.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.brand {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rail-toggle {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
}
.rail-toggle:hover { background: #f3f4f6; color: var(--fg); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-group + .nav-group { margin-top: 6px; }
.nav-group-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 10px 10px 4px;
  user-select: none;
}
.nav-group:first-child .nav-group-label { padding-top: 2px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--fg);
  text-decoration: none;
  border-left: 3px solid transparent;
  margin-left: -3px;
}
.nav-item:hover { background: #f3f4f6; }
.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 500;
}
.nav-item .icon { font-size: 16px; width: 16px; text-align: center; }
/* Collapsed rail — icons only, no group labels, no brand text. The
   toggle stays visible (centered) so the user can expand again. Native
   title-tooltip on each .nav-item provides the label on hover. */
.rail-collapsed .left-rail { padding: 16px 6px; }
.rail-collapsed .brand { display: none; }
.rail-collapsed .brand-row { justify-content: center; padding: 6px 0 12px; }
.rail-collapsed .nav-group-label { display: none; }
.rail-collapsed .nav-item .label { display: none; }
.rail-collapsed .nav-item { justify-content: center; padding: 8px 6px; gap: 0; }

.top-bar {
  grid-area: topbar;
  background: white;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: relative;
}
.view-title { font-weight: 600; font-size: 15px; }
.user-menu { position: relative; }
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-weight: 600;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  cursor: pointer;
  overflow: hidden;
}
.avatar-img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.popover {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: white;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 8px;
  min-width: 220px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  z-index: 100;
}
.popover-row {
  padding: 6px 8px;
  font-size: 13px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}
.popover-btn {
  display: block;
  width: 100%;
  text-align: left;
  background: white;
  color: var(--fg);
  border: 0;
  padding: 6px 8px;
  border-radius: 4px;
  font-size: 14px;
}
.popover-btn:hover { background: #f3f4f6; }

main#view-host {
  grid-area: main;
  padding: 20px 24px;
  overflow: auto;
  /* Grid items default to min-width: auto which lets wide content (long
     table cells) push the whole main track past the viewport. Force the
     track to fit the available space; the overflow: auto above will
     scroll inside the main area if the view's own content needs it. */
  min-width: 0;
}

/* — Deploy / update lifecycle (DM-22) — countdown banner + lockout overlay — */
#update-banner { grid-area: banner; }
.upd-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 20px;
  background: var(--hl-dwell);              /* warn-soft yellow */
  border-bottom: 1px solid #f0c869;
  color: #7c4a00;
  font-size: 13.5px;
}
.upd-banner .spacer { flex: 1; }
.upd-banner button {
  background: #fff;
  color: #92400e;
  border: 1px solid #f0c869;
  padding: 4px 12px;
  font-size: 13px;
}
.upd-banner button:hover { background: #fffaf0; }
.upd-banner button:disabled { opacity: 0.6; cursor: default; }

.upd-lockout {
  position: fixed;
  inset: 0;
  z-index: 2000;                            /* above modals (1000) — the app is unusable mid-update */
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}
.upd-lock-card {
  background: #fff;
  border-radius: 12px;
  padding: 30px 34px;
  max-width: 440px;
  width: 100%;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}
.upd-lock-card h2 { margin: 0 0 8px; font-size: 20px; font-weight: 600; }
.upd-lock-card p { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.upd-lock-card .upd-countdown {
  font-size: 34px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  margin: 12px 0;
}
.upd-lock-card .tiny { font-size: 12px; color: var(--muted); margin-top: 12px; }
.upd-lock-card button { margin-top: 6px; padding: 9px 18px; font-size: 14px; }

/* — Vehicle Legs view — */
.toolbar {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 14px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 16px;
}
.toolbar .field { display: flex; flex-direction: column; gap: 4px; }
.toolbar label { font-size: 12px; color: var(--muted); }
.toolbar input, .toolbar select { min-width: 180px; }
.toolbar .spacer { flex: 1; }
.toolbar .subtitle {
  font-size: 12px;
  color: var(--muted);
  flex-basis: 100%;
  padding-left: 2px;
}

.columns-pop {
  position: absolute;
  background: white;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 10px 12px;
  min-width: 260px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  z-index: 50;
}
.columns-pop h3 { font-size: 12px; font-weight: 600; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.columns-pop label { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 3px 0; cursor: pointer; }
.columns-pop label input { transform: translateY(1px); }

.grid-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  min-width: 0;
  max-width: 100%;
}
.grid-empty {
  padding: 40px 24px;
  text-align: center;
  color: var(--muted);
}
.grid-summary {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.grid-scroll {
  overflow: auto;
  max-height: calc(100vh - 260px);
}
table.legs {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}
table.legs th, table.legs td {
  padding: 6px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  white-space: nowrap;
}
table.legs th {
  font-weight: 600;
  color: var(--muted);
  background: #f9fafb;
  position: sticky;
  top: 0;
  z-index: 2;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
table.legs td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.legs tr.banner td {
  background: var(--hl-banner);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 600;
  font-size: 12px;
  color: #374151;
  padding: 6px 14px;
  position: sticky;
  top: 30px; /* below the header */
  z-index: 1;
}
table.legs tr.banner { cursor: pointer; user-select: none; }
table.legs tr.banner:hover td { filter: brightness(0.97); }
table.legs tr.banner td::before {
  content: "▼";
  display: inline-block;
  width: 12px;
  margin-right: 6px;
  font-size: 9px;
  color: var(--muted);
}
table.legs tbody.route-group.collapsed tr.banner td::before { content: "▶"; }
table.legs tbody.route-group.collapsed tr.leg { display: none; }
table.legs tr.leg td:first-child { padding-left: 24px; }
table.legs tr.leg.hl-anchor td { background: var(--hl-anchor); font-weight: 600; }
table.legs tr.leg.hl-route-end td { background: var(--hl-route-end); }
table.legs tr.leg.hl-route-start td { background: var(--hl-route-start); }
table.legs tr.leg.hl-dwell td { background: var(--hl-dwell); }
table.legs tr.leg:hover td { filter: brightness(0.97); }
table.legs .badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  background: #e5e7eb;
  color: #374151;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
table.legs .badge.anchor { background: #1d4ed8; color: white; }
table.legs .badge.empty { background: transparent; color: var(--muted); }
table.legs .map-pin {
  display: inline-block;
  margin-left: 4px;
  opacity: 0.6;
  text-decoration: none;
}
table.legs .map-pin:hover { opacity: 1; }
table.legs .dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  margin-right: 6px;
  vertical-align: middle;
}

/* — Pricing view — */
.pricing-toolbar {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 14px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 16px;
}
.pricing-toolbar .field { display: flex; flex-direction: column; gap: 4px; }
.pricing-toolbar label { font-size: 12px; color: var(--muted); }
.pricing-toolbar select, .pricing-toolbar input { min-width: 320px; }
.pricing-toolbar input#lanes-filter { min-width: 240px; }
.pricing-toolbar .spacer { flex: 1; }

table.services {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}
table.services th, table.services td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.services th {
  font-weight: 600;
  color: var(--muted);
  background: #f9fafb;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
table.services td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.services tr.svc { cursor: pointer; }
table.services tr.svc:hover td { background: #f3f4f6; }
table.services tr.svc.selected td { background: var(--accent-soft); }
table.services tr.selected td { background: var(--accent-soft); }
table.services th.sortable { cursor: pointer; user-select: none; }
table.services th.sortable:hover { background: #e5e7eb; }
table.services td.actions { text-align: right; white-space: nowrap; }
table.services td.actions button { margin-left: 4px; }
table.services button.tiny { padding: 2px 6px; font-size: 12px; }
table.services td.actions button:disabled { opacity: 0.4; cursor: not-allowed; }
table.services td input[type=number] { width: 80px; text-align: right; padding: 2px 4px; }

/* Lanes grid — fixed layout + long endpoint labels wrap inside their cells
   so the table always fits the container instead of overflowing horizontally.
   Numeric inputs span the full column width — a right-justified narrow input
   inside a wider cell reads as misaligned. */
table.services.lanes-grid { table-layout: fixed; width: 100%; }
/* Top-align cells so a multi-line cell (e.g. priced leg with a product/trucking
   label underneath) doesn't pull short-cell content (e.g. "set price" link) into
   the vertical middle of the row. Without this, neighbouring rows whose cells
   are short get centered against the taller row's height. */
table.services.lanes-grid td { overflow-wrap: anywhere; word-break: break-word; vertical-align: top; }
table.services.lanes-grid td.num input[type=number] { width: 100%; box-sizing: border-box; }

/* Number inputs — hide the browser-default spinner arrows globally.
   Most numeric values in the app (prices, weights, distances, hours) are
   not step-by-1 quantities; the arrows clutter the cell. Opt back in via
   the .with-spinners class on the input when stepping makes sense (e.g.
   quantity ordered, page number). */
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type=number] {
  -moz-appearance: textfield;
}
input[type=number].with-spinners::-webkit-outer-spin-button,
input[type=number].with-spinners::-webkit-inner-spin-button {
  -webkit-appearance: auto;
}
input[type=number].with-spinners {
  -moz-appearance: auto;
}

/* Math-readout block — right-justified ledger of numbers with monospaced
   digits so the decimal points align cleanly. Two columns: num + label.
   Used in the Typical load panel on the service detail view for Price +
   Max/Min/Avg Profit summary. */
.math-equation {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 8px;
  row-gap: 3px;
  font-size: 13px;
  align-items: baseline;
}
.math-equation .num {
  text-align: right;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.math-equation .label { color: var(--muted); }
.math-equation hr {
  grid-column: 1 / -1;
  border: 0;
  border-top: 1px solid var(--border);
  margin: 2px 0;
  height: 0;
}
.math-equation .total { font-weight: 600; }
table.services .pos { color: #047857; }
table.services .neg { color: var(--error); }
table.services .dash { color: var(--muted); }

.customer-badges { display: inline-flex; gap: 4px; align-items: center; }
.customer-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  background: #e5e7eb;
  color: #374151;
  font-size: 11px;
}

.detail-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 20px auto 0;
  overflow: hidden;
  /* Detail cards size to a preset, not to data — keeps navigation between
     records predictable. Standard preset (1280px) is the EnricherEditor
     default; see Applications/EnricherEditor/UXGuide.md for the local
     choice and Software Development/UXGuide.md for the general principle. */
  max-width: 1280px;
}
.detail-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
}
.detail-header .label { font-weight: 600; font-size: 15px; }
.detail-header .rate-line {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}
.detail-section { padding: 14px 18px; border-bottom: 1px solid var(--border); }
.detail-section:last-child { border-bottom: 0; }
.detail-section .section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.detail-section h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.detail-section .empty-note {
  color: var(--muted);
  font-size: 13px;
  padding: 18px 4px;
  text-align: center;
}

table.detail-grid {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}
table.detail-grid th, table.detail-grid td {
  padding: 6px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
table.detail-grid th {
  font-weight: 600;
  color: var(--muted);
  background: #f9fafb;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
table.detail-grid td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* — Modal — */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal {
  background: white;
  border-radius: 10px;
  padding: 22px 24px;
  max-width: 540px;
  width: 90%;
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 10px 30px rgba(0,0,0,0.15);
}
.modal h2 { margin: 0 0 6px; font-size: 17px; font-weight: 600; }
.modal .sub { margin: 0 0 16px; color: var(--muted); font-size: 13px; }
.modal .modal-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.modal .modal-row label { font-size: 12px; color: var(--muted); }
.modal .modal-row input, .modal .modal-row select { width: 100%; }
.modal .modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.modal .shape-pick {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}
.modal .shape-option {
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 10px 12px;
  cursor: pointer;
  background: white;
}
.modal .shape-option:hover { background: #f9fafb; }
.modal .shape-option.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.modal .shape-option strong { display: block; font-size: 13px; }
.modal .shape-option span.desc { font-size: 12px; color: var(--muted); }

/* — Place picker — */
.place-picker { position: relative; }
.place-picker input { width: 100%; }

/* Shared visual styling for both the nested productPicker dropdown
   (.place-picker .results) and the floating placePicker dropdown
   (.place-picker.results — both classes on the same element, portaled
   to document.body so it can escape modal overflow). */
.place-picker .results,
.place-picker.results {
  background: white;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  max-height: 280px;
  overflow: auto;
  z-index: 1100;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
/* Nested case (productPicker) — absolute, anchored to its parent */
.place-picker .results {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
}
/* Floating case (placePicker) — fixed, positioned imperatively in JS so
   the dropdown can extend beyond the modal's overflow:auto boundaries. */
.place-picker.results {
  position: fixed;
  /* top / left / width set by JS via getBoundingClientRect */
}
.place-picker .result {
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.place-picker .result:last-child { border-bottom: 0; }
.place-picker .result:hover { background: #f3f4f6; }
.place-picker .result.highlighted { background: var(--accent-soft); }
.place-picker .result .nl { color: #1d4ed8; font-weight: 600; }
.place-picker .selected-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 6px;
  font-size: 12px;
  margin-top: 6px;
}
.place-picker .selected-chip button {
  background: transparent;
  color: var(--accent);
  padding: 0 4px;
  font-size: 14px;
  line-height: 1;
}

/* — Sub-tabs (first used by Users & Access: Groups | Users) — */
.sub-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.sub-tab {
  padding: 8px 14px;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  background: none;
  border-radius: 0;
  user-select: none;
}
.sub-tab:hover { color: var(--fg); background: none; }
.sub-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

/* — Chips (group / membership tags) — */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 12px;
  padding: 3px 10px;
  font-size: 12px;
  margin: 0 6px 6px 0;
  white-space: nowrap;
}
.chip.muted-chip { background: #f1f2f4; color: var(--muted); }
.chip .x {
  cursor: pointer;
  font-weight: 700;
  color: #9db8e8;
  line-height: 1;
  padding: 0 1px;
}
.chip .x:hover { color: var(--accent); }
.chip.muted-chip .x { color: #b6bcc4; }

/* — Permission matrix (group × view × level) + segmented level control — */
table.perm-matrix { width: 100%; border-collapse: collapse; font-size: 13px; }
table.perm-matrix th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--muted); background: #f9fafb; padding: 8px 12px;
  border-bottom: 1px solid var(--border); font-weight: 600;
}
table.perm-matrix td { padding: 7px 12px; border-bottom: 1px solid #f1f2f4; }
table.perm-matrix tr:last-child td { border-bottom: 0; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 6px; overflow: hidden; }
.seg button {
  background: #fff; color: var(--muted); border: 0; border-right: 1px solid var(--border);
  padding: 4px 12px; font-size: 12px; border-radius: 0; cursor: pointer; line-height: 1.4;
}
.seg button:last-child { border-right: 0; }
.seg button:hover:not(:disabled) { background: #f3f4f6; }
.seg button.on { background: var(--accent); color: #fff; font-weight: 600; }
.seg button.on-read { background: #4b5563; color: #fff; font-weight: 600; }
.seg button.on-none { background: #eef0f3; color: #6b7280; font-weight: 600; }
.seg button:disabled { cursor: not-allowed; opacity: 0.5; }

/* — Level pills (resolved-permission read-out) — */
.lvl-pill {
  display: inline-block;
  font-size: 11px;
  border-radius: 10px;
  padding: 1px 9px;
  font-weight: 600;
}
.lvl-pill.full { background: #e7f3ee; color: #047857; }
.lvl-pill.read { background: #eef0f3; color: #4b5563; }

/* — Costing Models surface — */
.cm-default-chk {
  width: 15px; height: 15px; border: 1px solid var(--border-strong); border-radius: 3px;
  display: inline-block; vertical-align: middle; position: relative; cursor: pointer;
}
.cm-default-chk.on { background: var(--accent); border-color: var(--accent); }
.cm-default-chk.on::after { content: "✓"; color: #fff; font-size: 11px; position: absolute; top: -2px; left: 1.5px; }
.cm-default-chk.locked { cursor: default; opacity: 0.55; }
.cm-rate { font-variant-numeric: tabular-nums; }

.cm-header-rates { font-size: 13px; color: var(--muted); margin-top: 6px; }
.cm-header-rates strong { color: var(--fg); font-variant-numeric: tabular-nums; }

.cm-sections { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; padding: 16px 18px; }
@media (max-width: 1100px) { .cm-sections { grid-template-columns: 1fr; } }
.cm-cp { border: 1px solid var(--border); border-radius: 6px; padding: 12px 14px; min-width: 0; }
.cm-cp h4 { margin: 0 0 4px; font-size: 14px; font-weight: 600; }
.cm-cp .cm-notes { font-size: 12px; color: var(--muted); margin: 0 0 10px; min-height: 1em; }
.cm-cp-foot { margin-top: 8px; font-size: 12px; color: var(--muted); text-align: right; }
.cm-scroll { overflow-x: auto; }

table.cm-pivot { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
table.cm-pivot th, table.cm-pivot td { padding: 5px 8px; border-bottom: 1px solid #f1f2f4; white-space: nowrap; }
table.cm-pivot th.cm-dh { text-align: right; font-size: 12px; color: var(--accent); font-weight: 600; }
table.cm-pivot td.cm-lbl { color: var(--muted); font-size: 12px; }
table.cm-pivot td.cm-val { text-align: right; font-variant-numeric: tabular-nums; }
table.cm-pivot tr.cm-contrib td { color: var(--muted); font-weight: 500; }
table.cm-pivot tr.cm-contrib td.cm-val { color: #047857; font-variant-numeric: tabular-nums; }
table.cm-pivot tr:last-child td { border-bottom: 0; }
.cm-empty-cp { color: var(--muted); font-size: 12px; padding: 8px 0; }

/* editable cost-point cells (write path, S2+) */
.cm-cp .cm-cp-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.cm-cp .cm-status { font-size: 11px; color: var(--muted); font-weight: 400; white-space: nowrap; }
.cm-cp .cm-status.err { color: var(--error); }
table.cm-pivot th.cm-dh a.cm-date { color: var(--accent); text-decoration: none; cursor: pointer; }
table.cm-pivot th.cm-dh a.cm-date:hover { text-decoration: underline; }
table.cm-pivot th.cm-dh .cm-del {
  display: block; margin-top: 2px; font-size: 10.5px; font-weight: 400;
  color: var(--muted); cursor: pointer;
}
table.cm-pivot th.cm-dh .cm-del:hover { color: var(--error); text-decoration: underline; }
/* Editable pivot: the table shrinks to its content and sits left, next to the
   labels (not floating); inputs are a uniform per-section width (set inline), and
   the value column — date header, input, contribution — shares one right edge. */
.cm-pivot.edit { width: auto; }
.cm-pivot.edit th.cm-dh, .cm-pivot.edit td.cm-val { text-align: right; }
.cm-pivot.edit td.cm-lbl { text-align: right; padding-right: 12px; }
.cm-ie { position: relative; display: inline-block; }
.cm-ie input {
  box-sizing: border-box; text-align: right; padding: 3px 6px; border: 1px solid var(--border-strong);
  border-radius: 5px; font: inherit; font-size: 13px; font-variant-numeric: tabular-nums; background: #fff;
}
.cm-ie input::placeholder { color: #b3b8c0; }

/* Column-style adder (trial — Truck Replacement): a column of blank fields to the
   right of the values, set off by a divider, with the + Add button at its foot. */
.cm-pivot.edit td.cm-add, .cm-pivot.edit th.cm-add-h { border-right: 1px dashed var(--border-strong); padding-right: 14px; }
.cm-pivot.edit th.cm-add-h { text-align: right; }
.cm-add-date { box-sizing: border-box; text-align: right; padding: 3px 6px; border: 1px solid var(--border-strong); border-radius: 5px; font: inherit; font-size: 13px; background: #fff; }
.cm-add-lbl { display: block; margin-top: 2px; font-size: 10.5px; color: var(--accent); cursor: pointer; }
.cm-add-lbl:hover { text-decoration: underline; }
/* "Effective date" label over the date columns (left, by the field labels) —
   vertically centered in the header cell (date text down to the row line). */
.cm-pivot.edit th.cm-eff-head {
  text-align: right; vertical-align: middle; padding: 0 12px 0 8px;
  font-size: 11.5px; font-weight: 400; color: var(--muted); white-space: nowrap;
}

/* Effective-date pagination (‹ ›) over a long history. */
.cm-pivot.edit th.cm-arrow, .cm-pivot.edit td.cm-arrow { width: 16px; padding: 0; text-align: center; }
.cm-pg { color: var(--accent); cursor: pointer; font-size: 17px; font-weight: 700; user-select: none; line-height: 1; }
.cm-pg.off { color: var(--border-strong); cursor: default; }
.cm-pg-info { font-size: 11px; color: var(--muted); margin-top: 6px; }
.cm-ie input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px #eff6ff; }
.cm-ie.pfx input { padding-left: 16px; }
.cm-ie.sfx input { padding-right: 28px; }
.cm-ie .pfx-g { position: absolute; left: 6px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 12px; pointer-events: none; }
.cm-ie .sfx-g { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 12px; pointer-events: none; }

/* editable model name + notes (lifecycle, S4) */
.cm-name-input {
  font-size: 17px; font-weight: 600; padding: 4px 8px; border: 1px solid var(--border-strong);
  border-radius: 5px; min-width: 360px; max-width: 560px; background: #fff; font-family: inherit;
}
.cm-name-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px #eff6ff; }
.cm-notes-input {
  display: block; width: 100%; padding: 4px 7px; font-size: 12px; border: 1px solid var(--border-strong);
  border-radius: 5px; color: var(--muted); font-family: inherit; line-height: 1.4;
  resize: vertical; overflow-y: auto; margin: 0 0 10px;
}
.cm-notes-input:focus { outline: none; border-color: var(--accent); color: var(--fg); box-shadow: 0 0 0 2px #eff6ff; }
.cm-model-status { font-size: 11px; color: var(--muted); margin-left: 8px; }
.cm-model-status.err { color: var(--error); }
.cm-danger { padding: 14px 18px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.cm-danger .hint { font-size: 12px; color: var(--muted); }

/* — Detail page (drill-in) — */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
  margin-bottom: 12px;
  cursor: pointer;
}
.back-link:hover { text-decoration: underline; }
.detail-page-header .label { font-weight: 600; font-size: 17px; }
