/* Dispatch Board — ⚙ Settings as a full page (js/settings-page.js): header with Search settings, a menu of groups › categories ›
   sub-settings, and the settings screen on the right. The screens keep their drawer markup (#drawer moves into .sp-main while
   the page is open), so these rules restyle that markup as a page. Loaded after css/polish.css. */

html.sp-on, html.sp-on body { overflow: hidden; }

.sp { position: fixed; inset: 0; z-index: var(--z-page); display: flex; flex-direction: column; background: var(--bg); color: var(--ink); }
.sp:not([hidden]) { animation: spIn .24s var(--ease-out, ease) both; }
@keyframes spIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- header ---------- */
.sp-top { display: flex; align-items: center; gap: 16px; min-height: 62px; padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border); }
.sp-back { display: inline-flex; align-items: center; gap: 6px; flex: none; border: 1px solid var(--border); background: var(--surface-2); color: var(--ink-muted);
  border-radius: 999px; padding: 6px 14px; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background var(--dur-fast, .12s) ease, color var(--dur-fast, .12s) ease; }
.sp-back:hover { background: var(--accent-soft); color: var(--ink); }
.sp-back:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sp-h1 { display: flex; align-items: center; gap: 8px; margin: 0; font-family: var(--font-head); font-size: 20px; font-weight: 650; letter-spacing: -0.01em; text-transform: none; }
.sp-h1 .sp-h1-ico { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); font-size: 16px; }

.sp-search { position: relative; margin-left: auto; width: min(480px, 100%); }
.sp-search .ss-input { height: 40px; }
.sp-results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 5; max-height: min(70vh, 560px); overflow-y: auto; padding: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-pop, var(--shadow)); }
.sp-results:not([hidden]) { animation: dbPopIn .16s var(--ease-out, ease) both; }
.sp-results .ss-chips { padding: 4px 4px 2px; }
.sp-results .ss-empty { padding: 8px 6px; }

/* ---------- body: menu + screen ---------- */
.sp-body { flex: 1; min-height: 0; display: flex; }

.sp-nav { width: 272px; flex: none; overflow-y: auto; padding: 18px 12px 24px; background: var(--surface-2); border-right: 1px solid var(--border); }
.sp-group + .sp-group { margin-top: 16px; }
.sp-group-title { padding: 0 10px 6px; font-size: var(--fs-sm); font-weight: 700; color: var(--ink-faint); text-transform: none; letter-spacing: 0; }
.sp-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 10px; border: 0; border-radius: 8px; background: transparent; color: var(--ink-muted);
  font: inherit; font-size: var(--fs-lg); font-weight: 550; text-align: left; cursor: pointer;
  transition: background var(--dur-fast, .12s) ease, color var(--dur-fast, .12s) ease; }
.sp-item:hover { background: var(--surface-3); color: var(--ink); }
.sp-item:focus-visible, .sp-sub:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.sp-item[aria-current="page"] { background: var(--accent-soft); color: var(--ink); font-weight: 650; box-shadow: inset 3px 0 0 var(--accent); }
.sp-ico { flex: none; display: inline-grid; place-items: center; width: 20px; text-align: center; font-size: 14px; }
.sp-ico svg.ico { width: 18px; height: 18px; }

/* A hue per settings screen, so the menu can be scanned by colour as well as by name. Muted until the row is pointed at or
   is the one open (css/polish.css), which is what makes the current screen easy to find in a menu this long. */
.sp-h1 .sp-h1-ico { --ic: var(--ic-indigo); }
.sp-search .ss-field { --ic: var(--ic-slate); }
.sp-lock { --ic: var(--ic-amber); }
.sp-item[data-sp-cat="account"] { --ic: var(--ic-indigo); }
.sp-item[data-sp-cat="my-theme"] { --ic: var(--ic-violet); }
.sp-item[data-sp-cat="top-bar"] { --ic: var(--ic-blue); }
.sp-item[data-sp-cat="evening-summary"] { --ic: var(--ic-indigo); }
.sp-item[data-sp-cat="branding"] { --ic: var(--ic-pink); }
.sp-item[data-sp-cat="preferences"] { --ic: var(--ic-slate); }
.sp-item[data-sp-cat="locale"] { --ic: var(--ic-teal); }
.sp-item[data-sp-cat="ports"] { --ic: var(--ic-blue); }
.sp-item[data-sp-cat="users"] { --ic: var(--ic-indigo); }
.sp-item[data-sp-cat="driver-app"] { --ic: var(--ic-teal); }
.sp-item[data-sp-cat="archived-drivers"] { --ic: var(--ic-slate); }
.sp-item[data-sp-cat="board"] { --ic: var(--ic-blue); }
.sp-item[data-sp-cat="street-turns"] { --ic: var(--ic-teal); }
.sp-item[data-sp-cat="day-planner"] { --ic: var(--ic-violet); }
.sp-item[data-sp-cat="gps"] { --ic: var(--ic-red); }
.sp-item[data-sp-cat="compliance"] { --ic: var(--ic-green); }
.sp-item[data-sp-cat="brokerage"] { --ic: var(--ic-orange); }
.sp-item[data-sp-cat="scorecards"] { --ic: var(--ic-amber); }
.sp-item[data-sp-cat="rates"] { --ic: var(--ic-green); }
.sp-item[data-sp-cat="pay-rules"] { --ic: var(--ic-green); }
.sp-item[data-sp-cat="accounting"] { --ic: var(--ic-amber); }
.sp-item[data-sp-cat="sales-tax"] { --ic: var(--ic-amber); }
.sp-item[data-sp-cat="portal"] { --ic: var(--ic-blue); }
.sp-item[data-sp-cat="widgets"] { --ic: var(--ic-violet); }
.sp-item[data-sp-cat="integrations"] { --ic: var(--ic-orange); }
.sp-item[data-sp-cat="automation"] { --ic: var(--ic-blue); }
.sp-item[data-sp-cat="activity"] { --ic: var(--ic-slate); }
.sp-item[data-sp-cat="security"] { --ic: var(--ic-green); }
.sp-item[data-sp-cat="import"] { --ic: var(--ic-blue); }
.sp-item[data-sp-cat="maintenance"] { --ic: var(--ic-teal); }
.sp-item[data-sp-cat="plan"] { --ic: var(--ic-amber); }

/* Settings > You > My top bar: each row takes the colour its button has in the bar. */
.switch-row:has([data-topbar="btnGps"]) { --ic: var(--ic-red); }
.switch-row:has([data-topbar="btnLive"]) { --ic: var(--ic-green); }
.switch-row:has([data-topbar="btnPlan"]) { --ic: var(--ic-amber); }
.switch-row:has([data-topbar="btnTheme"]) { --ic: var(--ic-violet); }
.switch-row:has([data-topbar="btnTools"]) { --ic: var(--ic-orange); }
.switch-row:has([data-topbar="btnHelp"]) { --ic: var(--ic-blue); }
.sp-h1 .sp-h1-ico svg.ico { width: 17px; height: 17px; }
.sp-lock { margin-left: auto; display: inline-grid; place-items: center; font-size: 11px; opacity: .8; }
.sp-lock svg.ico { width: 13px; height: 13px; }
.sp-subs { margin: 2px 0 6px 29px; padding-left: 10px; border-left: 1px solid var(--border); }
.sp-sub { display: flex; align-items: center; gap: 6px; width: 100%; padding: 5px 10px; border: 0; border-radius: 6px; background: transparent; color: var(--ink-muted);
  font: inherit; font-size: 13px; text-align: left; cursor: pointer; }
.sp-sub:hover { background: var(--surface-3); color: var(--ink); }
.sp-sub[aria-current="true"] { color: var(--accent); font-weight: 650; }
.sp-sub .sp-out { margin-left: auto; font-size: 11px; color: var(--ink-faint); }
.sp-who { margin: 20px 10px 0; padding-top: 14px; border-top: 1px solid var(--border); font-size: 12px; line-height: 1.5; color: var(--ink-faint); }
.sp-who strong { display: block; color: var(--ink-muted); font-weight: 600; }

.sp-main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--surface); }
.sp-crumb { padding: 16px 44px 0; font-size: var(--fs-sm); color: var(--ink-faint); }
.sp-crumb b { color: var(--ink-muted); font-weight: 600; }
.sp-select { display: none; }

/* ---------- the settings screen (#drawer) inside the page ---------- */
.drawer.sp-hosted { position: static; inset: auto; flex: 1; min-height: 0; width: auto; padding: 6px 44px 0; overflow-y: auto;
  background: transparent; border: 0; box-shadow: none; transform: none; opacity: 1; transition: none; z-index: auto; }
.drawer.sp-hosted::after { content: ""; display: block; height: 48px; }
.drawer.sp-hosted > * { max-width: 880px; }
.drawer.sp-hosted.wide > * { max-width: 1220px; }
.drawer.sp-hosted:not([hidden]) > h2:first-of-type { animation: spFade .2s ease both; }
@keyframes spFade { from { opacity: 0; } to { opacity: 1; } }
.drawer.sp-hosted h2 { margin: 4px 0 6px; font-size: 26px; letter-spacing: -0.015em; }
.drawer.sp-hosted > .sub { max-width: 700px; margin-bottom: 24px; font-size: 14px; line-height: 1.5; }
.drawer.sp-hosted .section-title { margin: 34px 0 12px; padding-top: 24px; font-family: var(--font-head); font-size: var(--fs-xl); font-weight: 650; color: var(--ink); }
.drawer.sp-hosted .section-title:first-of-type { margin-top: 8px; padding-top: 0; }
.drawer.sp-hosted .field { max-width: 640px; }
.drawer.sp-hosted .field-row .field { max-width: none; }
.drawer.sp-hosted .field-row { max-width: 640px; }
.drawer.sp-hosted.wide .field, .drawer.sp-hosted.wide .field-row { max-width: none; }
.drawer.sp-hosted .switch-row { max-width: 640px; }
/* Buttons that fill a narrow panel look stretched on a page: size them to their label. */
.drawer.sp-hosted .field > .btn, .drawer.sp-hosted .field-row > .btn { width: auto; align-self: flex-start; }
.drawer.sp-hosted .field > .btn + .btn { margin-left: 6px; }

/* A page doesn't close: the drawer's × and its Close / Cancel button go. Save buttons sit in a bar that stays in view. */
.drawer.sp-hosted .drawer-close, .drawer.sp-hosted #drawerCancel { display: none !important; }
.drawer.sp-hosted .drawer-actions { position: sticky; bottom: 0; z-index: 2; justify-content: flex-start; margin-top: 28px; padding: 14px 0 16px;
  background: var(--surface); border-top: 1px solid var(--border); }
.drawer.sp-hosted .drawer-actions .btn { flex: 0 0 auto !important; min-width: 128px; }
.drawer.sp-hosted .drawer-actions:not(:has(> :not(#drawerCancel):not([hidden]))) { display: none; }

.sp-loading { padding: 40px 0; }
.sp-failed { max-width: 560px; padding: 28px 0; }
.sp-failed p { color: var(--ink-muted); }

/* Hub pages (Rates & setup, Pay rules): cards that open the Billing or Settlements tab */
.sp-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.sp-card { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 16px 18px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); color: var(--ink); font: inherit; text-align: left; cursor: pointer;
  transition: border-color var(--dur-fast, .12s) ease, box-shadow var(--dur, .2s) ease, transform var(--dur, .2s) var(--ease-out, ease); }
.sp-card:hover { border-color: var(--accent); box-shadow: var(--shadow); transform: translateY(-1px); }
.sp-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sp-card strong { font-size: var(--fs-lg); font-weight: 650; }
.sp-card span { font-size: var(--fs-sm); line-height: 1.4; color: var(--ink-muted); }
.sp-card .sp-go { margin-top: 8px; font-weight: 600; color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  .sp:not([hidden]), .sp-results:not([hidden]), .drawer.sp-hosted:not([hidden]) > h2:first-of-type { animation: none; }
  .sp-card:hover { transform: none; }
}

/* ---------- narrow screens: the menu becomes a picker ---------- */
@media (max-width: 860px) {
  .sp-top { flex-wrap: wrap; gap: 10px; padding: 10px 16px; }
  .sp-search { order: 3; width: 100%; margin-left: 0; }
  .sp-body { flex-direction: column; }
  .sp-nav, .sp-crumb { display: none; }
  .sp-select { display: block; width: calc(100% - 32px); height: 42px; margin: 12px 16px 0; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: 10px;
    background: var(--surface-2); color: var(--ink); font: inherit; font-size: 14px; }
  .drawer.sp-hosted { padding: 4px 16px 0; }
  .drawer.sp-hosted h2 { font-size: 22px; }
}
