/* ============================================================
   RUNDECK · shell layouts
   ops workspace · customer portal · driver device frame
   ============================================================ */

/* ================ OPS SHELL (Workspace + Carrier) ============= */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  min-height: 100vh;
  background: var(--bg);
}
.app__side { grid-row: 1 / -1; grid-column: 1; }
.app__top  { grid-row: 1; grid-column: 2; }
.app__main { grid-row: 2; grid-column: 2; overflow-x: hidden; }
.app.is-rail { grid-template-columns: var(--rail-w) 1fr; }

/* placeholder before JS mounts, so no white flash */
.app::before {
  content: ""; grid-row: 1 / -1; grid-column: 1;
  background: var(--n-1000);
}

/* ---- Sidebar ---- */
.side {
  background: var(--n-1000);
  color: var(--n-300);
  display: flex; flex-direction: column;
  min-height: 100vh;
  position: sticky; top: 0; left: 0;
  z-index: var(--z-sticky);
}
.side__brand {
  display: flex; align-items: center; gap: var(--sp-3);
  height: var(--topbar-h);
  padding: 0 var(--sp-5);
  color: var(--n-0);
  border-bottom: 1px solid var(--n-950);
  font-family: var(--font-sans);
  font-weight: var(--fw-700);
  font-size: var(--fs-lg);
  letter-spacing: var(--tr-heading);
  font-variation-settings: "wdth" var(--wd-wide);
}
.side__brand-mark {
  width: 28px; height: 28px;
  flex: 0 0 28px;
}
.side__wordmark { position: relative; }
.side__wordmark::after {
  content: ""; position: absolute; left: 44%; right: 0; bottom: -3px; height: 2px;
  background: var(--v-500);
}

.side__nav { flex: 1; padding: var(--sp-4) 0; overflow-y: auto; }
.side__group { padding: var(--sp-4) 0 var(--sp-2); }
.side__group + .side__group { border-top: 1px solid var(--n-950); }
.side__group-label {
  padding: 0 var(--sp-5) var(--sp-2);
  font-size: var(--fs-3xs);
  color: var(--n-500);
  text-transform: uppercase;
  letter-spacing: var(--tr-micro);
  font-weight: var(--fw-600);
  font-variation-settings: "wdth" var(--wd-condensed);
}
.side__item {
  position: relative;
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 8px var(--sp-5);
  color: var(--n-300);
  font-size: var(--fs-sm);
  font-weight: var(--fw-500);
  cursor: pointer;
  transition: background var(--dur-hover) var(--ease-out),
              color var(--dur-hover) var(--ease-out);
  border-left: 2px solid transparent;
}
.side__item .icon { width: 18px; height: 18px; flex: 0 0 18px; opacity: 0.9; }
.side__item:hover { background: var(--n-950); color: var(--n-0); }
.side__item.is-active {
  background: var(--n-800);
  color: var(--n-0);
  border-left-color: var(--v-500);
}
.side__item.is-active .icon { color: var(--v-500); opacity: 1; }
.side__item-count {
  margin-left: auto;
  background: var(--n-800); color: var(--n-300);
  font-size: 10px; font-weight: var(--fw-600);
  padding: 1px 6px; border-radius: var(--r-full);
  min-width: 18px; text-align: center;
}
.side__item.is-active .side__item-count { background: var(--v-500); color: var(--v-900); }

.side__foot {
  padding: var(--sp-4);
  border-top: 1px solid var(--n-950);
}
.side__user {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3);
  border-radius: var(--r-sm);
  cursor: pointer;
}
.side__user:hover { background: var(--n-950); }
.side__user-avatar {
  width: 30px; height: 30px; border-radius: var(--r-full);
  background: var(--h-500); color: var(--n-0);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: var(--fw-600); font-size: var(--fs-2xs);
  flex: 0 0 30px;
}
.side__user-name { font-size: var(--fs-xs); color: var(--n-0); font-weight: var(--fw-500); }
.side__user-role { font-size: var(--fs-3xs); color: var(--n-400); text-transform: uppercase;
                   letter-spacing: var(--tr-micro); font-weight: var(--fw-600);
                   font-variation-settings: "wdth" var(--wd-condensed); }


/* ---- Topbar ---- */
.top {
  display: flex; align-items: center;
  height: var(--topbar-h);
  padding: 0 var(--sp-6);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  gap: var(--sp-5);
  position: sticky; top: 0; z-index: var(--z-sticky);
  min-width: 0;
}
.top__crumb {
  flex: 0 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.top__crumb .crumb { flex-wrap: nowrap; }
.top__search {
  flex: 1 1 320px;
  min-width: 180px;
  max-width: 420px;
}
.top__search .input-group {
  height: 32px;
  background: var(--n-25);
  padding-left: 10px;
}
.top__search .input-group > .icon { flex: 0 0 14px; color: var(--ink-3); }
.top__search .input { border: 0; background: transparent; padding-left: 8px; }
.top__search .input:focus { outline: 0; }
.top__cluster {
  display: flex; align-items: center; gap: var(--sp-3);
  margin-left: auto;
  flex-shrink: 0;
}
@media (max-width: 1100px) {
  .roleswitch__name, .roleswitch__role { display: none; }
  .roleswitch { padding: 4px; }
}
@media (max-width: 900px) {
  .top__crumb { display: none; }
  .top__search { max-width: none; }
}


/* ---- Role switcher (in topbar) ---- */
.roleswitch {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  padding: 4px 10px 4px 4px;
  background: var(--n-100);
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  font-size: var(--fs-2xs);
  cursor: pointer;
}
.roleswitch:hover { border-color: var(--line-strong); }
.roleswitch__avatar {
  width: 22px; height: 22px; border-radius: var(--r-full);
  background: var(--h-600); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: var(--fw-600); font-size: 10px;
}
.roleswitch__name { color: var(--ink); font-weight: var(--fw-500); }
.roleswitch__role {
  color: var(--ink-3);
  font-variation-settings: "wdth" var(--wd-condensed);
  text-transform: uppercase; letter-spacing: var(--tr-micro);
  font-size: 10px; font-weight: var(--fw-600);
  padding-left: var(--sp-2);
  border-left: 1px solid var(--line);
  margin-left: var(--sp-2);
}
.roleswitch .icon { width: 12px; height: 12px; color: var(--ink-3); }


/* ---- Sub-bar ---- */
.subbar {
  display: flex; align-items: center; gap: var(--sp-4);
  height: var(--subbar-h);
  padding: 0 var(--sp-6);
  background: var(--surface);
  border-bottom: 1px solid var(--line-faint);
  position: sticky; top: var(--topbar-h);
  z-index: calc(var(--z-sticky) - 1);
}


/* ---- Page ---- */
.page {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--sp-6) var(--sp-7) var(--sp-10);
}
.page--full { max-width: none; padding: 0; }
.page--narrow { max-width: 820px; }


/* ---- Demo bar (persistent bottom) ---- */
.demobar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: var(--sp-5);
  z-index: var(--z-sticky);
  background: var(--n-1000); color: var(--n-100);
  border-radius: var(--r-full);
  padding: 6px 6px 6px var(--sp-5);
  display: flex; align-items: center; gap: var(--sp-4);
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-500);
}
.demobar__label {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  color: var(--v-500);
  text-transform: uppercase;
  letter-spacing: var(--tr-micro);
  font-weight: var(--fw-600);
  font-family: var(--font-mono);
  font-size: 10px;
}
.demobar__label::before {
  content: ""; width: 6px; height: 6px; background: var(--v-500);
  border-radius: var(--r-full);
}
.demobar__sep { width: 1px; height: 20px; background: var(--n-800); }
.demobar__btn {
  padding: 6px var(--sp-4);
  background: var(--n-800); color: var(--n-100);
  border-radius: var(--r-full);
  font-size: var(--fs-2xs);
  display: inline-flex; align-items: center; gap: var(--sp-2);
  cursor: pointer;
  transition: background var(--dur-hover) var(--ease-out);
}
.demobar__btn:hover { background: var(--n-700); color: var(--n-0); }
.demobar__btn.is-on { background: var(--v-500); color: var(--v-900); }
.demobar__btn .icon { width: 14px; height: 14px; }
.demobar__btn--role { background: var(--h-700); color: var(--n-0); font-weight: var(--fw-600); }
.demobar__btn--role:hover { background: var(--h-600); }
.demobar__reset {
  padding: 6px 10px;
  background: transparent; color: var(--n-400);
  border-radius: var(--r-full);
  cursor: pointer;
}
.demobar__reset:hover { color: var(--v-500); }


/* ================ CUSTOMER PORTAL SHELL ============= */

.portal { background: var(--n-0); min-height: 100vh; }

.portal-nav {
  height: 64px;
  padding: 0 var(--sp-8);
  background: var(--n-0);
  border-bottom: 1px solid var(--line-faint);
  display: flex; align-items: center; gap: var(--sp-6);
  position: sticky; top: 0; z-index: var(--z-sticky);
}
.portal-nav__brand {
  display: flex; align-items: center; gap: var(--sp-3);
  font-family: var(--font-sans);
  font-weight: var(--fw-700);
  font-size: var(--fs-lg);
  font-variation-settings: "wdth" var(--wd-wide);
  color: var(--n-900);
  letter-spacing: var(--tr-heading);
}
.portal-nav__brand-mark { width: 28px; height: 28px; }
.portal-nav__links {
  display: flex; gap: var(--sp-2);
  margin-left: var(--sp-6);
}
.portal-nav__link {
  padding: var(--sp-3) var(--sp-4);
  color: var(--ink-2);
  font-size: var(--fs-sm);
  font-weight: var(--fw-500);
  border-radius: var(--r-sm);
  cursor: pointer;
}
.portal-nav__link:hover { color: var(--ink); background: var(--n-50); }
.portal-nav__link.is-active { color: var(--h-700); font-weight: var(--fw-600); }
.portal-nav__cluster { margin-left: auto; display: flex; align-items: center; gap: var(--sp-4); }

.portal-page {
  max-width: var(--portal-max);
  margin: 0 auto;
  padding: var(--sp-8) var(--sp-8) var(--sp-14);
}
.portal-hero {
  background: linear-gradient(180deg, var(--h-900) 0%, var(--h-800) 100%);
  color: var(--n-0);
  padding: var(--sp-12) 0 var(--sp-14);
}
.portal-hero__inner {
  max-width: var(--portal-max);
  margin: 0 auto;
  padding: 0 var(--sp-8);
}
.portal-hero__eyebrow {
  color: var(--v-500);
  text-transform: uppercase;
  letter-spacing: var(--tr-micro);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-600);
  font-family: var(--font-mono);
  margin-bottom: var(--sp-4);
}
.portal-hero__title {
  font-size: var(--fs-4xl);
  font-weight: var(--fw-700);
  line-height: var(--lh-tight);
  letter-spacing: var(--tr-display);
  font-variation-settings: "wdth" var(--wd-normal);
  margin-bottom: var(--sp-5);
  color: var(--n-0);
}
.portal-hero__title .accent {
  border-bottom: 3px solid var(--v-500);
  padding-bottom: 2px;
}
.portal-hero__lede {
  font-size: var(--fs-md);
  color: var(--h-100);
  max-width: 55ch;
  line-height: var(--lh-body);
}


/* ================ DRIVER DEVICE FRAME =============== */

.device-stage {
  min-height: 100vh;
  background: linear-gradient(180deg, var(--n-50) 0%, var(--n-100) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-8);
  gap: var(--sp-8);
}
/* Prototype side panels — hidden by default so device stands alone as a real product. */
.device-stage__side { display: none; }

.device {
  width: var(--device-w);
  height: var(--device-h);
  background: var(--n-800);
  border-radius: var(--r-frame);
  padding: 10px;
  box-shadow: 0 10px 40px -8px rgb(5 8 12 / .3),
              inset 0 0 0 2px var(--n-950);
  position: sticky; top: var(--sp-6);
}
.device__screen {
  width: 100%; height: 100%;
  background: var(--surface);
  border-radius: calc(var(--r-frame) - 10px);
  overflow: hidden;
  position: relative;
  display: flex; flex-direction: column;
  color: var(--ink);
}
.device__notch {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
  width: 110px; height: 32px;
  background: var(--n-1000);
  border-radius: var(--r-full);
  z-index: 10;
}
.device__statusbar {
  height: 44px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px var(--sp-6) 0;
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: var(--fw-600);
  color: var(--ink);
}
.device__statusbar-icons { display: flex; align-items: center; gap: 4px; color: var(--ink-2); }
.device__statusbar-icons .icon { width: 14px; height: 14px; }
.device__body {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-5) var(--sp-6) var(--sp-6);
}
.device__cta {
  padding: var(--sp-5) var(--sp-6) calc(var(--sp-6) + 8px);
  background: var(--surface);
  border-top: 1px solid var(--line-faint);
}
.device__home {
  position: absolute; bottom: 6px; left: 50%; transform: translateX(-50%);
  width: 130px; height: 4px;
  background: var(--n-1000); opacity: 0.3;
  border-radius: var(--r-full);
}

/* driver-specific inside device */
.d-topbar {
  display: flex; align-items: center; gap: var(--sp-4);
  padding: var(--sp-3) 0 var(--sp-5);
}
.d-topbar__title { font-size: var(--fs-lg); font-weight: var(--fw-600); }
.d-hero-number {
  font-size: var(--fs-5xl); font-weight: var(--fw-700);
  line-height: 0.95; letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.d-hero-label {
  text-transform: uppercase; letter-spacing: var(--tr-micro);
  font-size: var(--fs-2xs); color: var(--ink-3);
  font-weight: var(--fw-600); font-variation-settings: "wdth" var(--wd-condensed);
  margin-top: var(--sp-2);
}
.d-btn {
  display: flex; align-items: center; justify-content: center;
  gap: var(--sp-3);
  width: 100%; min-height: 56px;
  padding: 0 var(--sp-6);
  font-size: var(--fs-md);
  font-weight: var(--fw-600);
  border-radius: var(--r-md);
  background: var(--v-500); color: var(--v-900);
  cursor: pointer;
  transition: transform var(--dur-press) var(--ease-out);
}
.d-btn:active { transform: scale(0.98); }
.d-btn--secondary { background: var(--n-100); color: var(--ink); }
.d-btn--danger    { background: var(--er); color: #fff; }
.d-btn--primary   { background: var(--h-600); color: #fff; }
.d-btn .icon      { width: 22px; height: 22px; }

.d-card {
  padding: var(--sp-5);
  background: var(--surface);
  border: 1px solid var(--line-faint);
  border-radius: var(--r-md);
  margin-bottom: var(--sp-4);
}
.d-card.is-active {
  border-color: var(--h-600);
  box-shadow: 0 0 0 3px var(--h-100);
}

.d-step {
  display: flex; gap: var(--sp-4); align-items: center;
  padding: var(--sp-4) 0;
  border-bottom: 1px solid var(--line-faint);
}
.d-step:last-child { border-bottom: 0; }
.d-step__num {
  width: 32px; height: 32px; border-radius: var(--r-full);
  background: var(--n-100); color: var(--ink-3);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: var(--fw-600); flex: 0 0 32px;
}
.d-step.is-done .d-step__num { background: var(--ok); color: #fff; }
.d-step.is-active .d-step__num { background: var(--h-600); color: #fff; }


/* ================ MAP PLACEHOLDER ==================== */

.map {
  position: relative;
  background: var(--n-100);
  border: 1px solid var(--line-faint);
  border-radius: var(--r-md);
  overflow: hidden;
  min-height: 320px;
}
.map__svg { width: 100%; height: 100%; display: block; }
.map__chip {
  position: absolute; top: var(--sp-4); left: var(--sp-4);
  padding: var(--sp-2) var(--sp-3);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  font-size: var(--fs-2xs);
  color: var(--ink-2);
  display: inline-flex; align-items: center; gap: var(--sp-2);
  box-shadow: var(--shadow-sm);
}
.map__chip::before {
  content: ""; width: 6px; height: 6px;
  background: var(--v-500);
  border-radius: var(--r-full);
  box-shadow: 0 0 0 3px rgb(214 221 6 / .3);
  animation: pulse-truck 2s var(--ease-out) infinite;
}
.map__legend {
  position: absolute; bottom: var(--sp-4); left: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-sm);
  font-size: var(--fs-2xs);
  display: flex; gap: var(--sp-5);
  box-shadow: var(--shadow-sm);
}
.map__legend-item { display: inline-flex; align-items: center; gap: var(--sp-2); color: var(--ink-2); }
.map__legend-item::before { content: ""; width: 10px; height: 3px; background: currentColor; }
.map__legend-item.is-route::before { background: var(--h-600); }
.map__legend-item.is-driven::before { background: var(--v-500); }
.map__legend-item.is-geo::before { background: var(--wa); }

@keyframes pulse-truck {
  0%   { box-shadow: 0 0 0 3px rgb(214 221 6 / .5); }
  70%  { box-shadow: 0 0 0 12px rgb(214 221 6 / 0); }
  100% { box-shadow: 0 0 0 12px rgb(214 221 6 / 0); }
}


/* ================ WIZARD STEP RAIL =================== */

.wizard {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: var(--sp-8);
}
@media (max-width: 768px) { .wizard { grid-template-columns: 1fr; } }
.wizard__steps { position: sticky; top: calc(var(--topbar-h) + var(--sp-6)); }
.wizard__step {
  display: flex; gap: var(--sp-3); align-items: flex-start;
  padding: var(--sp-3) 0;
  cursor: pointer;
  position: relative;
}
.wizard__step + .wizard__step::before {
  content: ""; position: absolute;
  left: 13px; top: -8px; height: 16px;
  border-left: 2px solid var(--line);
}
.wizard__step-num {
  width: 28px; height: 28px; border-radius: var(--r-full);
  background: var(--n-100); color: var(--ink-3);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: var(--fw-600); font-size: var(--fs-xs);
  flex: 0 0 28px;
  border: 2px solid transparent;
}
.wizard__step.is-done  .wizard__step-num { background: var(--ok); color: #fff; }
.wizard__step.is-active .wizard__step-num { background: var(--surface); color: var(--h-700);
                                            border-color: var(--h-600); }
.wizard__step-body { padding-top: 3px; min-width: 0; }
.wizard__step-title { font-size: var(--fs-sm); font-weight: var(--fw-500); color: var(--ink); }
.wizard__step.is-active .wizard__step-title { color: var(--ink); font-weight: var(--fw-600); }
.wizard__step-sum { font-size: var(--fs-2xs); color: var(--ink-3); margin-top: 2px; }


/* ================ DENSITY MODIFIER (compact board) === */

html[data-density="compact"] .tbl tbody td { padding: 2px var(--sp-3); height: 30px; font-size: var(--fs-2xs); }
html[data-density="compact"] .tbl thead th { padding: 4px var(--sp-3); }
html[data-density="compact"] body { font-variation-settings: "wdth" var(--wd-compact); }
