/* Base elements and the application shell. */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; overscroll-behavior-y: none; background: var(--bg); }
body {
  margin: 0; min-height: 100dvh; background: var(--bg); color: var(--text);
  font: 400 var(--text-base)/1.5 var(--font); font-feature-settings: 'tnum' 1, 'cv11' 1;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { margin: 0; color: var(--text); line-height: 1.25; letter-spacing: -0.012em; text-wrap: balance; }
h1 { font-size: var(--text-2xl); font-weight: 700; }
h2 { font-size: var(--text-lg); font-weight: 650; }
h3 { font-size: var(--text-md); font-weight: 650; }
p { margin: 0; text-wrap: pretty; }
a { color: var(--link); text-underline-offset: 2px; }
ul, ol { margin: 0; padding: 0; list-style: none; }
img, svg, video { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
h1:focus, [data-focus-target]:focus { outline: none; }
::selection { background: var(--selection); }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.muted { color: var(--text-muted); }
.mono, .job-number { font-family: var(--font-mono); font-size: 0.92em; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------ app shell */
.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 100; padding: 10px 14px; background: var(--surface);
  color: var(--text); border-radius: var(--radius); box-shadow: var(--shadow-2); transition: top var(--dur-fast);
}
.skip-link:focus { top: 12px; }

.shell { display: grid; grid-template-columns: auto minmax(0, 1fr); min-height: 100dvh; }
.shell[data-chrome="none"] { display: block; }

.sidebar {
  position: sticky; top: 0; height: 100dvh; width: 248px; display: flex; flex-direction: column;
  background: var(--brand); color: var(--on-brand); padding: var(--space-4) var(--space-3);
  padding-top: max(var(--space-4), env(safe-area-inset-top)); padding-left: max(var(--space-3), env(safe-area-inset-left));
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; color: inherit; text-decoration: none; }
.brand-mark { width: 32px; height: 32px; flex: none; }
.brand-name { font-weight: 700; font-size: var(--text-lg); letter-spacing: -0.01em; line-height: 1.1; }
.brand-flow { font-weight: 400; color: #8FE0FF; }
.brand-mark { border-radius: 25%; box-shadow: 0 2px 8px rgb(0 0 0 / 0.22); }
.brand-sub { display: block; font-size: var(--text-xs); font-weight: 500; opacity: 0.75; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-link {
  position: relative; display: flex; align-items: center; gap: 12px; min-height: 42px; padding: 0 12px;
  border-radius: var(--radius); color: rgb(255 255 255 / 0.82); text-decoration: none; font-weight: 550;
  transition: background var(--dur-fast), color var(--dur-fast);
}
.nav-link:hover { background: rgb(255 255 255 / 0.08); color: #fff; }
.nav-link[aria-current="page"] { background: rgb(255 255 255 / 0.14); color: #fff; }
.nav-link[aria-current="page"]::before {
  content: ''; position: absolute; left: -12px; top: 9px; bottom: 9px; width: 4px; border-radius: 0 4px 4px 0; background: var(--accent);
}
.nav-link .icon { width: 20px; height: 20px; }
/* Pattern 50: one highlight for the whole rail, clipped to a pill that stretches
   between destinations (ui/motion.js). The links keep the CSS-only highlight above
   until the script takes over, so a script failure still shows the current page. */
.nav { position: relative; }
.nav > .nav-link { z-index: 1; }
.nav-indicator {
  position: absolute; inset: 0; pointer-events: none; opacity: 0;
  background: linear-gradient(to right, var(--accent) 0 4px, rgb(255 255 255 / 0.14) 4px);
}
.nav.has-stretch .nav-link[aria-current="page"] { background: transparent; }
.nav.has-stretch .nav-link[aria-current="page"]::before { display: none; }
.nav-badge { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: #031432; font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.nav-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; padding-top: var(--space-4); border-top: 1px solid rgb(255 255 255 / 0.12); }
.nav-user { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: var(--radius); color: inherit; text-decoration: none; }
.nav-user:hover { background: rgb(255 255 255 / 0.08); }
.avatar {
  width: 32px; height: 32px; flex: none; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700;
  background: var(--accent); color: #031432;
}
.avatar.sm { width: 26px; height: 26px; font-size: 11px; }
.nav-user-name { font-weight: 600; font-size: var(--text-sm); line-height: 1.2; }
.nav-user-role { font-size: var(--text-xs); opacity: 0.75; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: none; align-items: center; gap: 8px; min-height: 56px;
  padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  background: var(--brand); color: var(--on-brand);
}
.topbar .brand { padding: 0; }
.topbar-actions { margin-left: auto; display: flex; gap: 4px; }
.page {
  width: 100%; max-width: 1440px; margin: 0 auto; flex: 1;
  padding: var(--space-6) max(var(--space-6), env(safe-area-inset-right)) var(--space-10) var(--space-6);
}
.page-narrow { max-width: 880px; }
.page-head { display: flex; align-items: flex-end; gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-5); }
.page-head .eyebrow { font-size: var(--text-sm); font-weight: 600; color: var(--text-muted); margin-bottom: 2px; }
.page-head .actions { margin-left: auto; display: flex; gap: var(--space-2); flex-wrap: wrap; }

/* bottom tab bar (phones) */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: none;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 4px max(8px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}
.tabbar-inner { position: relative; display: grid; grid-template-columns: repeat(5, 1fr); }
.tabbar a {
  position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 52px; color: var(--text-muted); text-decoration: none; font-size: 11px; font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}
.tabbar a[aria-current="page"] { color: var(--primary); }
.tabbar .icon { width: 22px; height: 22px; }
.tabbar .tab-dot { position: absolute; top: 6px; left: calc(50% + 8px); min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center; }
/* one pill that stretches between tabs (patterns 11 and 50), clipped by ui/motion.js */
.tab-indicator { position: absolute; inset: 0; pointer-events: none; opacity: 0; background: var(--selection); }

/* banners pinned below the chrome: offline, update available, install */
.banner-stack { position: sticky; top: 0; z-index: 25; display: flex; flex-direction: column; }
.banner {
  display: flex; align-items: center; gap: 12px; padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  font-size: var(--text-sm); font-weight: 550; border-bottom: 1px solid var(--border);
}
.banner .icon { width: 18px; height: 18px; flex: none; }
.banner .btn { margin-left: auto; }
.banner-offline { background: var(--warning-bg); color: var(--warning); border-color: var(--warning-border); }
.banner-update { background: var(--info-bg); color: var(--info); border-color: var(--info-border); }
.banner-install { background: var(--surface); color: var(--text); }

/* ---------------------------------------------------------------- tablet */
@media (max-width: 1100px) {
  .sidebar { width: 76px; padding-inline: 10px; }
  .sidebar .brand-text, .sidebar .nav-label, .sidebar .nav-user-text { display: none; }
  .sidebar .brand { justify-content: center; padding-inline: 0; }
  .nav-link { justify-content: center; padding: 0; min-height: 48px; }
  .nav-link[aria-current="page"]::before { left: -10px; }
  .nav-badge { position: absolute; top: 4px; right: 4px; min-width: 18px; height: 18px; font-size: 10px; }
  .nav-user { justify-content: center; }
  .page { padding: var(--space-5) max(var(--space-5), env(safe-area-inset-right)) var(--space-10) var(--space-5); }
}
@media (pointer: coarse) { :root { --control-h: var(--touch); } }

/* ----------------------------------------------------------------- phone */
@media (max-width: 760px) {
  .shell { display: block; }
  .sidebar { display: none; }
  .topbar { display: flex; }
  .tabbar { display: block; }
  .page { padding: var(--space-4) max(var(--space-4), env(safe-area-inset-right)) calc(96px + env(safe-area-inset-bottom)) max(var(--space-4), env(safe-area-inset-left)); }
  .page-head { margin-bottom: var(--space-4); }
  h1 { font-size: var(--text-xl); }
  :root { --control-h: var(--touch); }
}
/* the on-screen keyboard: keep focused fields clear of the tab bar */
@media (max-width: 760px) { body[data-keyboard="open"] .tabbar { display: none; } }
