/* ==========================================================================
   App shell — sidebar, topbar, page frame, command palette, kiosk surface
   ========================================================================== */

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

/* ==========================================================================
   Sidebar
   ========================================================================== */

/* The sidebar is furniture, not a list on a page. It reads as a recessed
   panel: a gradient away from the light, a firm edge, and a hairline of
   daylight on the inside of that edge. */
.app-sidebar {
  grid-row: 1 / -1;
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(
      to bottom,
      color-mix(in oklch, var(--shell) 82%, var(--raised)) 0,
      var(--shell) 220px
    );
  border-right: 1px solid var(--line-strong);
  box-shadow: inset -1px 0 0 color-mix(in oklch, var(--raised) 55%, transparent);
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: var(--z-sticky);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  height: var(--topbar-h);
  padding: 0 var(--s-4);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  color: var(--ink);
  text-decoration: none;
  transition: background-color var(--dur-hover) ease;
}
@media (hover: hover) and (pointer: fine) {
  .brand:hover { background: color-mix(in oklch, var(--primary-soft) 60%, transparent); }
}

/* The mark is a stack of slats seen edge-on — the product itself, at 1:1
   with the ruler motif's tick rhythm. */
.brand-mark {
  width: 24px; height: 24px;
  flex-shrink: 0;
  color: var(--primary);
}

.brand-text { display: flex; flex-direction: column; min-width: 0; }

.brand-name {
  font-size: var(--fs-sm);
  font-weight: 600;
  letter-spacing: -0.012em;
  line-height: 1.2;
}
.brand-sub {
  font-size: var(--fs-3xs);
  color: var(--ink-muted);
  letter-spacing: var(--tracking-label);
  line-height: 1.2;
  white-space: nowrap;
}

.nav {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--s-4) var(--s-3) var(--s-6);
}

/* Groups are separated by a real rule, so the nav scans as five short lists
   rather than one long undifferentiated one. */
.nav-group + .nav-group {
  margin-top: var(--s-4);
  padding-top: var(--s-4);
  border-top: 1px solid color-mix(in oklch, var(--line) 62%, transparent);
}

.nav-group-t {
  padding: 0 var(--s-3) var(--s-2);
  font-size: var(--fs-3xs);
  font-weight: 600;
  color: var(--ink-faint);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  font-size: var(--fs-xs);
  font-weight: 450;
  color: var(--ink-2);
  text-decoration: none;
  /* No transition on colour here: nav is clicked a hundred times a day and
     a fade makes the app feel slower than it is. Hover only. */
  transition: background-color var(--dur-hover) ease;
  position: relative;
  border: 1px solid transparent;
}
.nav-item svg { width: 15px; height: 15px; color: var(--ink-muted); flex-shrink: 0; }

@media (hover: hover) and (pointer: fine) {
  .nav-item:hover { background: color-mix(in oklch, var(--raised) 70%, transparent); color: var(--ink); }
  .nav-item:hover svg { color: var(--ink-2); }
}

/* The current page is stated four ways at once — fill, full border, weight and
   a saturated icon — rather than by a wash of tint alone. A full border, never
   a side stripe. */
.nav-item[aria-current='page'] {
  background: var(--primary-soft);
  border-color: var(--primary-line);
  color: var(--primary-ink);
  font-weight: 600;
  box-shadow: var(--shadow-xs);
}
.nav-item[aria-current='page'] svg { color: var(--primary); }

.nav-count {
  margin-left: auto;
  font-family: var(--font-data);
  font-size: var(--fs-3xs);
  font-weight: 500;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}
/* A count that means "act on this" gets counted, not just coloured. */
.nav-count.is-critical {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 19px;
  height: 17px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--critical);
  color: oklch(1 0 0);
  font-weight: 600;
}

.nav-ft {
  padding: var(--s-3);
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}

/* ---- Icon rail (< 1100px) ---- */

@media (max-width: 1100px) {
  .app { grid-template-columns: var(--sidebar-rail-w) minmax(0, 1fr); }
  .brand { justify-content: center; padding: 0; }
  .brand-text, .nav-group-t, .nav-item span, .nav-count, .nav-ft .btn span { display: none; }
  .nav { padding: var(--s-3) var(--s-2); }
  .nav-item { justify-content: center; padding: var(--s-3) 0; }
  .nav-group + .nav-group { margin-top: var(--s-3); padding-top: var(--s-3); border-top: 1px solid var(--line); }
  .nav-ft .btn { width: 100%; padding: 0; }
}

/* ---- Off-canvas (< 768px) ---- */

@media (max-width: 768px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .app-sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    z-index: var(--z-drawer);
    transform: translateX(-100%);
    transition: transform var(--dur-drawer) var(--ease-drawer);
    box-shadow: var(--shadow-lg);
  }
  .app[data-nav='open'] .app-sidebar { transform: translateX(0); }
  .brand { justify-content: flex-start; padding: 0 var(--s-4); }
  .brand-text, .nav-group-t, .nav-item span, .nav-count { display: revert; }
  .nav-item { justify-content: flex-start; padding: var(--s-3); }
  .nav-group + .nav-group { border-top: none; margin-top: var(--s-5); padding-top: 0; }
  .nav-scrim {
    position: fixed; inset: 0;
    z-index: var(--z-drawer-backdrop);
    background: var(--overlay);
  }
}

.nav-toggle { display: none; }
@media (max-width: 768px) { .nav-toggle { display: inline-flex; } }

/* ==========================================================================
   Topbar
   ========================================================================== */

.app-topbar {
  position: sticky;
  top: 0;
  z-index: calc(var(--z-sticky) + 10);
  display: flex;
  align-items: center;
  gap: var(--s-4);
  height: var(--topbar-h);
  padding: 0 var(--s-6);
  background: color-mix(in oklch, var(--raised) 88%, transparent);
  backdrop-filter: blur(10px) saturate(1.4);
  border-bottom: 1px solid var(--line);
  transition: box-shadow 180ms ease, border-color 180ms ease;
}
/* Earns its elevation only once content is actually running under it. */
.app-topbar[data-scrolled='true'] {
  border-bottom-color: var(--line-strong);
  box-shadow: 0 1px 0 color-mix(in oklch, var(--line) 55%, transparent),
              0 6px 16px -10px oklch(0.22 0.012 143 / 0.35);
}

@media (max-width: 768px) { .app-topbar { padding: 0 var(--s-4); } }

.crumbs {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  font-size: var(--fs-xs);
  color: var(--ink-muted);
  min-width: 0;
}
.crumbs strong { color: var(--ink); font-weight: 600; }
.crumbs .sep { color: var(--line-strong); }

/* Search opens the command palette — one input, one keyboard shortcut */
.topsearch {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  height: 30px;
  min-width: 200px;
  max-width: 300px;
  padding: 0 var(--s-2) 0 var(--s-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--canvas);
  color: var(--ink-muted);
  font-size: var(--fs-2xs);
  cursor: pointer;
  transition: border-color var(--dur-hover) ease, background-color var(--dur-hover) ease;
}
@media (hover: hover) and (pointer: fine) {
  .topsearch:hover { border-color: var(--ink-muted); background: var(--shell); }
}
.topsearch svg { width: 14px; height: 14px; }
.topsearch .kbd { margin-left: auto; }

@media (max-width: 900px) { .topsearch span, .topsearch .kbd { display: none; } .topsearch { min-width: 0; width: 30px; padding: 0; justify-content: center; } }

/* Planning date — MRP is always "as of" a date, so the date is chrome,
   not a buried setting. */
.plan-date {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: 0 var(--s-3);
  height: 30px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--shell);
  font-size: var(--fs-2xs);
  color: var(--ink-2);
  white-space: nowrap;
}
.plan-date .d { font-family: var(--font-data); font-weight: 500; color: var(--ink); }
@media (max-width: 1240px) { .plan-date .lbl { display: none; } }
@media (max-width: 620px) { .plan-date { display: none; } }

.env-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  height: 20px;
  padding: 0 var(--s-2);
  border: 1px dashed var(--accent-line);
  border-radius: var(--r-xs);
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: var(--fs-3xs);
  font-weight: 600;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
@media (max-width: 1000px) { .env-badge .full { display: none; } }

/* ==========================================================================
   Page frame
   ========================================================================== */

.app-main { min-width: 0; display: flex; flex-direction: column; }

.page {
  flex: 1;
  padding: var(--s-6);
  max-width: var(--content-max);
  width: 100%;
}
@media (max-width: 768px) { .page { padding: var(--s-5) var(--s-4); } }

/* The page header closes with the measuring rule — the app's signature mark,
   used where it means something rather than as ornament: it sets the datum the
   screen below is measured from. */
.page-hd {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--s-5);
  flex-wrap: wrap;
  padding-bottom: var(--s-5);
  margin-bottom: var(--s-6);
  border-bottom: 1px solid var(--line);
  position: relative;
}
.page-hd::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 7px;
  background-image:
    repeating-linear-gradient(to right, var(--line-strong) 0 1px, transparent 1px 48px),
    repeating-linear-gradient(to right, var(--line) 0 1px, transparent 1px 8px);
  background-size: 100% 7px, 100% 3px;
  background-repeat: repeat-x;
  pointer-events: none;
}

.page-hd h1 { font-size: var(--fs-2xl); }
.page-hd .sub {
  font-size: var(--fs-sm);
  line-height: 1.55;
  color: var(--ink-muted);
  margin-top: var(--s-3);
  max-width: 74ch;
}

.page-actions { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; }

.section { margin-top: var(--s-7); }
.section-hd {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--s-3) var(--s-4);
  margin-bottom: var(--s-4);
}
/* Children must be allowed to shrink, or a long segmented control pushes
   the whole page sideways instead of scrolling inside itself. */
.section-hd > * { min-width: 0; }
.section-hd h2 { font-size: var(--fs-md); }

/* ==========================================================================
   Command palette
   ========================================================================== */

.cmdk-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal-backdrop);
  background: var(--overlay);
  display: flex;
  justify-content: center;
  padding: 12vh var(--s-5) var(--s-5);
  transition: opacity var(--dur-pop) var(--ease-out);
}
.cmdk-backdrop[hidden] { display: none; }
@starting-style { .cmdk-backdrop { opacity: 0; } }
.cmdk-backdrop.closing { opacity: 0; }

.cmdk {
  width: min(600px, 100%);
  align-self: flex-start;
  background: var(--raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 66vh;
  transition: opacity var(--dur-pop) var(--ease-out), transform var(--dur-pop) var(--ease-out);
}
@starting-style { .cmdk { opacity: 0; transform: scale(0.98) translateY(-6px); } }
.cmdk-backdrop.closing .cmdk { opacity: 0; transform: scale(0.98) translateY(-6px); }

.cmdk-input {
  width: 100%;
  height: 48px;
  padding: 0 var(--s-5);
  border: none;
  border-bottom: 1px solid var(--line);
  background: transparent;
  font-size: var(--fs-md);
  color: var(--ink);
}
.cmdk-input:focus-visible { outline: none; }
.cmdk-input::placeholder { color: var(--ink-muted); }

.cmdk-list { overflow-y: auto; padding: var(--s-2); overscroll-behavior: contain; }

.cmdk-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  width: 100%;
  padding: var(--s-3);
  border-radius: var(--r-sm);
  font-size: var(--fs-xs);
  color: var(--ink-2);
  cursor: pointer;
  text-align: left;
  text-decoration: none;
}
.cmdk-item svg { width: 15px; height: 15px; color: var(--ink-muted); flex-shrink: 0; }
.cmdk-item[data-active='true'] { background: var(--primary-soft); color: var(--primary-ink); }
.cmdk-item[data-active='true'] svg { color: var(--primary); }
.cmdk-item .meta { margin-left: auto; font-size: var(--fs-3xs); color: var(--ink-muted); font-family: var(--font-data); }
.cmdk-item .hint { color: var(--ink-muted); font-weight: 400; }

.cmdk-ft {
  display: flex;
  align-items: center;
  gap: var(--s-4);
  padding: var(--s-3) var(--s-5);
  border-top: 1px solid var(--line);
  background: var(--shell);
  font-size: var(--fs-3xs);
  color: var(--ink-muted);
}
.cmdk-ft .k { display: inline-flex; align-items: center; gap: var(--s-2); }

/* ==========================================================================
   Shop-floor kiosk — a genuinely different surface.
   Wall-mounted tablet under glare, operated with gloves.
   ========================================================================== */

.kiosk {
  min-height: 100vh;
  background: var(--canvas);
  color: var(--ink);
  display: flex;
  flex-direction: column;
}

.kiosk-bar {
  display: flex;
  align-items: center;
  gap: var(--s-5);
  padding: var(--s-4) var(--s-6);
  background: var(--shell);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.kiosk-station {
  font-size: var(--fs-lg);
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* align-content:start so rows size to their content — otherwise the scan
   panel stretches to fill the whole terminal. */
.kiosk-body { flex: 1; padding: var(--s-6); display: grid; gap: var(--s-5); align-content: start; }

/* Gloves. 56px, not 44. */
.kiosk-btn {
  min-height: 56px;
  padding: 0 var(--s-6);
  border-radius: var(--r-md);
  border: 1px solid var(--line-strong);
  background: var(--shell-2);
  color: var(--ink);
  font-size: var(--fs-md);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-3);
  cursor: pointer;
  transition: background-color var(--dur-hover) ease, transform var(--dur-press) var(--ease-out);
}
.kiosk-btn:active { transform: scale(0.98); }
.kiosk-btn-primary { background: var(--primary); border-color: var(--primary); color: var(--ink-inverse); }
.kiosk-btn-danger  { background: var(--critical-soft); border-color: var(--critical-line); color: var(--critical); }
.kiosk-btn svg { width: 20px; height: 20px; }

.kiosk-scan {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--s-4);
  padding: var(--s-5);
  border: 2px dashed var(--line-strong);
  border-radius: var(--r-lg);
  background: var(--shell);
}
.kiosk-scan input {
  flex: 1 1 200px;
  min-width: 0;
  height: 56px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--canvas);
  color: var(--ink);
  padding: 0 var(--s-5);
  font-family: var(--font-data);
  font-size: var(--fs-lg);
  letter-spacing: 0.06em;
}
.kiosk-scan input:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

/* Big glanceable job card */
.job-card {
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--shell);
  padding: var(--s-5);
  display: grid;
  gap: var(--s-4);
}
.job-card .jc-id {
  font-family: var(--font-data);
  font-size: var(--fs-2xl);
  font-weight: 600;
  letter-spacing: -0.01em;
}
.job-card .jc-dim {
  font-family: var(--font-data);
  font-size: var(--fs-3xl);
  font-weight: 500;
  color: var(--primary);
  letter-spacing: -0.02em;
}

/* ==========================================================================
   Charts — inline SVG, no library
   ========================================================================== */

.chart { width: 100%; display: block; overflow: visible; }
.chart .grid-line { stroke: var(--line-faint); stroke-width: 1; }
.chart .axis-line { stroke: var(--line-strong); stroke-width: 1; }
.chart .axis-t {
  font-family: var(--font-data);
  font-size: 9.5px;
  fill: var(--ink-muted);
}
.chart .bar { transition: opacity var(--dur-hover) ease; }
@media (hover: hover) and (pointer: fine) {
  .chart .bar:hover { opacity: 0.78; }
}
.chart .series-line { fill: none; stroke-width: 1.75; stroke-linejoin: round; stroke-linecap: round; }
.chart .zero-line { stroke: var(--ink-2); stroke-width: 1; }
.chart .today-line { stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 3 3; }

/* ==========================================================================
   Page-local helpers
   ========================================================================== */

/* Stat strip across the top of a page. Not gradient tiles — a row of
   numbers separated by hairlines, which is what a planner actually scans. */
.stat-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--raised);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}
.stat-strip > * {
  padding: var(--s-5);
  border-right: 1px solid var(--line);
}
.stat-strip > *:last-child { border-right: none; }
@media (max-width: 900px) {
  .stat-strip > * { border-right: none; border-bottom: 1px solid var(--line); }
  .stat-strip > *:last-child { border-bottom: none; }
}

/* A key/value spec row used in drawers */
.spec-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-5);
  padding: var(--s-3) 0;
  border-bottom: 1px solid var(--line-faint);
  font-size: var(--fs-xs);
}
.spec-row:last-child { border-bottom: none; }
.spec-row dt { color: var(--ink-muted); }
.spec-row dd { margin: 0; text-align: right; }

/* Formula display for the rules engine */
.formula {
  font-family: var(--font-data);
  font-size: var(--fs-2xs);
  line-height: 1.7;
  padding: var(--s-3) var(--s-4);
  background: var(--shell);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--ink-2);
  overflow-x: auto;
  white-space: pre;
}
.formula .tok-var { color: var(--primary-ink); font-weight: 500; }
.formula .tok-num { color: var(--accent-ink); }
.formula .tok-fn  { color: var(--info); }
.formula .tok-cmt { color: var(--ink-muted); font-style: italic; }
