/* Common shell: brand, sidebar, global header, visited tabs, main scroll area. */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font); font-size: var(--fs-md); line-height: var(--lh);
  color: var(--text); background: var(--canvas);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
h1, h2, h3, p, dl, dd, ul { margin: 0; }
ul { padding: 0; list-style: none; }
.i { width: 1em; height: 1em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.app {
  display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100vh; transition: grid-template-columns var(--motion) ease;
}
.app.is-collapsed { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }

/* ---------- Sidebar ---------- */
.sidebar { display: flex; flex-direction: column; min-height: 0; background: var(--frame); color: var(--frame-text); }
.brand {
  display: flex; align-items: center; gap: 10px; height: var(--header-h); flex: none;
  padding: 0 14px; border-bottom: 1px solid var(--frame-rule); text-decoration: none; background: var(--frame-deep);
}
.brand-logo { width: 30px; height: 30px; border-radius: 6px; background: #fff; display: grid; place-items: center; overflow: hidden; flex: none; }
.brand-logo img { width: 26px; height: 26px; object-fit: contain; }
.brand-logo .brand-fallback { font-weight: 800; font-size: 12px; color: var(--frame); letter-spacing: -.02em; }
/* The Safelink lockup and truck mark share one light plate. */
.brand-plate { display: flex; align-items: center; justify-content: center; min-width: 0; max-width: 100%; height: 36px; padding: 3px 9px; border-radius: 6px; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .25); }
.brand-plate .brand-lockup { display: block; width: 161px; max-width: 100%; height: 30px; object-fit: contain; }
.brand-plate .brand-mark { display: none; }
.brand-plate .brand-fallback { font-weight: 800; font-size: 13px; color: var(--frame); white-space: nowrap; }
.is-collapsed .brand-plate { width: 38px; padding: 4px; }
.is-collapsed .brand-plate .brand-lockup { display: none; }
.is-collapsed .brand-plate .brand-mark { display: block; width: 28px; height: 28px; object-fit: contain; }
.brand-words { display: flex; flex-direction: column; line-height: 1.05; min-width: 0; }
.brand-words strong { font-size: 18px; font-weight: 800; letter-spacing: .01em; }
.brand-words small { font-size: 10.5px; font-weight: 700; letter-spacing: .14em; color: var(--frame-muted); margin-top: 3px; }

.nav { flex: 1; min-height: 0; overflow-y: auto; padding: 6px 8px 16px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.2) transparent; }
.nav-group { margin-top: 14px; }
.nav-group:first-child { margin-top: 8px; }
.group-title {
  display: flex; align-items: center; gap: 8px; height: 22px; margin: 0 6px 4px;
  font-size: 12px; font-weight: 700; letter-spacing: .02em; color: #d5e1eb; white-space: nowrap;
}
.group-title::after { content: ""; flex: 1; height: 1px; background: var(--frame-rule); }
.nav-item {
  position: relative; display: flex; align-items: center; gap: 10px; width: 100%;
  min-height: 36px; padding: 0 10px; border: 0; border-radius: 6px; background: none;
  color: var(--frame-text); font-size: 14px; font-weight: 500; text-decoration: none; text-align: left;
  transition: background var(--motion), color var(--motion);
}
.nav-item .i { font-size: 18px; color: #c8d7e4; }
.nav-item:hover { background: var(--frame-hover); }
.nav-item:hover .i { color: #fff; }
.nav-item:focus-visible { box-shadow: inset 0 0 0 2px var(--frame-text); }
.nav-item[aria-current="page"] {
  background: var(--frame-selected); font-weight: 700; color: #fff;
  box-shadow: inset 3px 0 0 var(--frame-indicator);
}
.nav-item[aria-current="page"] .i { color: #fff; }
.nav-item[aria-current="page"]:focus-visible { box-shadow: inset 3px 0 0 var(--frame-indicator), inset 0 0 0 2px var(--frame-text); }
.nav-label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Reserve bold width so selection never shifts neighbours */
.nav-label::after { content: attr(data-text); display: block; height: 0; overflow: hidden; visibility: hidden; font-weight: 700; }
.nav-item.is-boundary .nav-label { color: #dbe5ee; }
/* DESIGN-20261117 · count of records the signed-in person can act on now in a Maintenance work menu */
.nav-count { flex: none; min-width: 20px; height: 18px; padding: 0 6px; border-radius: 9px; background: rgba(255,255,255,.16); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; font-variant-numeric: tabular-nums; }
.nav-item[aria-current="page"] .nav-count { background: rgba(255,255,255,.28); }
.is-collapsed .nav-count { display: none; }
.open-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--open-dot); box-shadow: 0 0 0 2px var(--open-halo); flex: none; }
.nav-row { display: flex; align-items: center; gap: 2px; }
.nav-row .nav-item { flex: 1; }
.nav-chevron {
  width: 30px; height: 30px; flex: none; display: grid; place-items: center; border: 0; border-radius: 6px;
  background: none; color: #c8d7e4;
}
.nav-chevron:hover { background: var(--frame-hover); color: #fff; }
.nav-chevron .i { font-size: 16px; transition: transform var(--motion); }
.nav-chevron[aria-expanded="true"] .i { transform: rotate(90deg); }
.subnav .nav-item { min-height: 32px; padding-left: 38px; font-size: 13.5px; }
.subnav .nav-item .i { font-size: 16px; }
.sidebar-foot {
  flex: none; display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 10px 16px; border-top: 1px solid var(--frame-rule); font-size: 12px; color: var(--frame-muted);
}

/* Collapsed sidebar */
.is-collapsed .brand { padding: 0; justify-content: center; }
.is-collapsed .brand-words, .is-collapsed .nav-label, .is-collapsed .nav-chevron, .is-collapsed .subnav,
.is-collapsed .sidebar-foot .foot-version { display: none; }
.is-collapsed .group-title { height: 1px; margin: 10px 8px 8px; font-size: 0; }
.is-collapsed .group-title::after { margin: 0; }
.is-collapsed .nav-item { justify-content: center; padding: 0; height: 40px; }
.is-collapsed .open-dot { position: absolute; right: 7px; bottom: 7px; width: 7px; height: 7px; }
.is-collapsed .sidebar-foot { justify-content: center; padding: 10px 0; }

/* ---------- Main column ---------- */
.main-col { display: grid; grid-template-rows: var(--header-h) var(--tabs-h) minmax(0, 1fr); grid-template-columns: minmax(0, 1fr); min-width: 0; min-height: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 0 16px 0 10px;
  background: var(--surface); border-bottom: 1px solid var(--border-strong);
}
.icon-btn {
  width: 34px; height: 34px; display: inline-grid; place-items: center; border: 1px solid transparent;
  border-radius: var(--r-control); background: none; color: var(--text-2);
}
.icon-btn .i { font-size: 18px; }
.icon-btn:hover { background: var(--surface-sunken); border-color: var(--border); color: var(--text); }
.topbar-title { font-size: 14px; font-weight: 600; color: var(--text-2); white-space: nowrap; }
.topbar-title b { color: var(--text); font-weight: 700; }
.topbar-spacer { flex: 1; }
.preview-chip {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px;
  border: 1px solid var(--border); border-radius: var(--r-pill); background: var(--surface-sunken);
  font-size: 12px; color: var(--text-2); white-space: nowrap;
}
.preview-chip .i { font-size: 13px; color: var(--dom-tele); }
.account { position: relative; }
.account-btn {
  display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 8px 0 4px;
  border: 1px solid transparent; border-radius: 8px; background: none; text-align: left;
}
.account-btn:hover, .account-btn[aria-expanded="true"] { background: var(--surface-sunken); border-color: var(--border); }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--dom-fleet-bg); color: var(--frame); }
.avatar .i { font-size: 17px; }
.account-text { display: flex; flex-direction: column; line-height: 1.15; }
.account-text strong { font-size: 13px; font-weight: 600; }
.account-text small { font-size: 12px; color: var(--text-2); }
.account-btn > .i { font-size: 14px; color: var(--text-2); }
.account-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 40; width: 250px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-panel); box-shadow: var(--shadow-pop);
}
.account-menu .menu-meta { padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; font-size: 12px; color: var(--text-2); }
.account-menu .menu-meta strong { display: block; font-size: 13px; color: var(--text); }
.menu-item {
  display: flex; align-items: center; gap: 8px; width: 100%; height: 34px; padding: 0 10px;
  border: 0; border-radius: 6px; background: none; font-size: 13px; text-align: left;
}
.menu-item:hover { background: var(--surface-sunken); }
.menu-item .i { font-size: 16px; color: var(--text-2); }
.demo-tag { display: inline-block; margin-left: 4px; padding: 0 5px; border-radius: 4px; background: #6a43a0; color: #fff; font-size: 10px; font-weight: 800; letter-spacing: .06em; vertical-align: 1px; }

/* Visited tabs */
.tabs {
  display: flex; align-items: flex-end; gap: 2px; padding: 0 12px; min-width: 0; overflow-x: auto;
  background: var(--surface-sunken); border-bottom: 1px solid var(--border-strong); scrollbar-width: none;
}
.tab {
  position: relative; display: flex; align-items: center; height: 30px; flex: none;
  border: 1px solid transparent; border-bottom: 0; border-radius: 6px 6px 0 0; color: var(--text-2);
}
.tab a { display: flex; align-items: center; gap: 7px; height: 100%; padding: 0 12px; font-size: 13px; font-weight: 600; text-decoration: none; }
.tab a .i { font-size: 15px; }
.tab:hover { background: rgba(255,255,255,.7); color: var(--text); }
.tab.is-active { background: var(--surface); border-color: var(--border-strong); color: var(--text); margin-bottom: -1px; height: 31px; }
.tab.is-active::before { content: ""; position: absolute; left: -1px; right: -1px; top: -1px; height: 3px; border-radius: 6px 6px 0 0; background: var(--accent); }
.tab-code { color: var(--key-link); font-weight: 700; }
.tab-close {
  width: 22px; height: 22px; margin-right: 5px; margin-left: -6px; display: grid; place-items: center;
  border: 0; border-radius: 4px; background: none; color: var(--text-3);
}
.tab-close .i { font-size: 13px; }
.tab-close:hover { background: var(--neutral-bg); color: var(--text); }

.main { min-height: 0; overflow: auto; scroll-behavior: auto; }
.page { padding: 16px 16px 32px; max-width: none; }

/* Responsive frame */
@media (max-width: 760px) {
  .app, .app.is-collapsed { grid-template-columns: 0 minmax(0, 1fr); }
  .sidebar { position: fixed; z-index: 60; inset: 0 auto 0 0; width: var(--sidebar-w); transform: translateX(-100%); transition: transform var(--motion); }
  .app.is-mobile-open .sidebar { transform: none; box-shadow: var(--shadow-pop); }
  .preview-chip, .account-text, .topbar-title { display: none; }
}

/* Tablet / phone fit (TERRA-REVIEW 768 px · 390 px):
 * the main column always sits in grid column 2 — when the sidebar becomes position:fixed (≤760 px) it leaves
 * the grid flow, and without this the main column was auto-placed into the 0 px sidebar column. */
.main-col { grid-column: 2; }
.topbar { min-width: 0; }
.topbar > * { min-width: 0; }
@media (max-width: 1100px) {
  .topbar-title, .account-text { display: none; }
  .preview-chip { max-width: 38vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* R4 · Code and Admin: same-level expandable parents in one untitled group (no separate Settings heading). */
.nav-group.no-title .group-rule { height: 1px; margin: 0 8px 8px; background: var(--frame-rule); }
.is-collapsed .nav-group.no-title .group-rule { margin: 10px 8px 8px; }
