/* Apex IPM — mirrors ui/theme.py dark/light industrial look */
:root, html[data-theme="dark"] {
  --win: #23272a;
  --base: #2d3237;
  --alt: #373c44;
  --text: #e6e6e6;
  --muted: #8c8c8c;
  --border: #4a4e53;
  --highlight: #0078b4;
  /* Readable links on dark backgrounds (avoid default blue / purple) */
  --link: #7ec8ff;
  --link-visited: #d4b8ff;
  --link-hover: #b3e0ff;
  --btn-hover: #4a4e53;
  --btn-press: #2d3237;
  --good: #27ae60;
  --bad: #c0392b;
  --warn: #ff6600;
}
html[data-theme="light"] {
  --win: #fafafa;
  --base: #ffffff;
  --alt: #f0f0f0;
  --text: #282828;
  --muted: #666;
  --border: #ccc;
  --highlight: #0078b4;
  --link: #0a6fa3;
  --link-visited: #5a3080;
  --link-hover: #078fcb;
  --btn-hover: #e0e0e0;
  --btn-press: #d0d0d0;
  --good: #1e8449;
  --bad: #a93226;
  --warn: #d35400;
}

* { box-sizing: border-box; }
html {
  height: 100%;
}
html, body {
  margin: 0;
  min-height: 100%;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--win);
  color: var(--text);
  font-size: 14px;
}
/* Full chrome (layout_app): lock document scroll — only .content-area scrolls */
body:has(.app-shell) {
  height: 100%;
  overflow: hidden;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100dvh;
  min-height: 0;
  overflow: hidden;
}
.app-header {
  flex-shrink: 0;
  background: var(--base);
  border-bottom: 1px solid var(--border);
  padding: 4px 6px 2px;
}
.app-header-row1 {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 2px;
  min-height: 36px;
}
.app-logo { height: 32px; max-width: 180px; object-fit: contain; }
.app-logo-text { font-weight: bold; font-size: 14px; color: var(--text); }
.app-header-row1 .spacer { flex: 1; }
.btn-shop {
  background: var(--alt);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}
.btn-shop:hover { background: var(--btn-hover); }

.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 4px;
  background: var(--base);
  padding: 2px 4px;
  min-height: 38px;
  overflow-x: auto;
  border-top: 1px solid var(--border);
}
/* Primary actions scroll on the left; theme / admin / help / logout stay pinned to the right */
.toolbar-leading {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 4px;
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden; /* let search flex fill; use .toolbar horizontal scroll if needed */
}
.toolbar-leading-actions {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 4px;
  flex-shrink: 0;
}
.toolbar-leading-actions > a,
.toolbar-leading-actions > .sep {
  flex-shrink: 0;
}
.toolbar-trailing {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 4px;
  flex: 0 0 auto;
  margin-left: auto;
  flex-shrink: 0;
}
.toolbar-trailing .toolbar-theme-form {
  display: inline-flex;
  margin: 0;
}
/* Grows/shrinks with viewport so space between left actions and right cluster is filled */
.toolbar-search-form {
  flex: 1 1 0;
  min-width: 100px;
  max-width: none;
  display: flex;
  align-items: center;
  margin: 0;
}
.toolbar-search-form input[type="search"] {
  width: 100%;
  min-width: 0;
  max-width: none;
}
.toolbar a, .toolbar button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--alt);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 10px;
  border-radius: 4px;
  text-decoration: none;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
  font-family: inherit;
}
.toolbar a:hover, .toolbar button:hover { background: var(--btn-hover); }
.toolbar .sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; flex-shrink: 0; }
.toolbar input[type="search"], .toolbar select {
  background: var(--win);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 8px;
  border-radius: 3px;
  min-height: 28px;
  font-size: 13px;
}
.toolbar form { display: inline-flex; align-items: center; margin: 0; }

/* Quote list: per-row actions use the same chip look as the main nav toolbar */
.quote-row-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  max-width: 880px;
}
.quote-row-toolbar form,
.quote-row-toolbar .quote-toolbar-form {
  display: inline-flex;
  align-items: center;
  margin: 0;
}
.quote-row-toolbar a.quote-toolbar-chip,
.quote-row-toolbar button.quote-toolbar-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--alt);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 10px;
  border-radius: 4px;
  text-decoration: none;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
  font-family: inherit;
  box-sizing: border-box;
  margin: 0;
}
.quote-row-toolbar a.quote-toolbar-chip:hover,
.quote-row-toolbar button.quote-toolbar-chip:hover {
  background: var(--btn-hover);
}
.quote-row-toolbar button.quote-toolbar-chip--danger {
  border-color: color-mix(in srgb, var(--bad) 45%, var(--border));
  color: var(--bad);
}
.quote-row-toolbar button.quote-toolbar-chip--danger:hover {
  background: color-mix(in srgb, var(--bad) 12%, var(--alt));
}
.quote-row-toolbar .quote-toolbar-hint {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border: 1px dashed var(--border);
  border-radius: 4px;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}
.quote-row-toolbar .quote-toolbar-chip--disabled,
.quote-row-toolbar button.quote-toolbar-chip:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: auto;
  color: var(--muted);
  background: var(--bg);
  border-style: dashed;
}
.quote-row-toolbar button.quote-toolbar-chip:disabled:hover,
.quote-row-toolbar .quote-toolbar-chip--disabled:hover {
  background: var(--bg);
}
.quote-row-toolbar .quote-toolbar-chip--disabled.quote-toolbar-chip--danger {
  color: color-mix(in srgb, var(--bad) 55%, var(--muted));
  border-color: color-mix(in srgb, var(--bad) 25%, var(--border));
}
.plate-actions-item--disabled {
  opacity: 0.55;
  cursor: not-allowed;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: 4px;
  box-sizing: border-box;
}
.plate-actions-item--disabled.plate-actions-item--danger {
  color: color-mix(in srgb, var(--bad) 55%, var(--muted));
}
.btn-shop--disabled,
.btn-shop:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: auto;
}
.btn-shop--disabled:hover,
.btn-shop:disabled:hover {
  background: var(--btn);
}

/* ☰ / ⚙ menus: hidden on desktop; shown in portrait via (max-width:1200px) and (orientation:portrait) */
.toolbar-phone-nav,
.toolbar-phone-actions {
  display: none;
}
.toolbar-phone-nav summary,
.toolbar-phone-actions summary {
  list-style: none;
}
.toolbar-phone-nav summary::-webkit-details-marker,
.toolbar-phone-actions summary::-webkit-details-marker {
  display: none;
}
.toolbar-dd-summary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 8px 12px;
  background: var(--alt);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  font-size: 1.15rem;
  line-height: 1;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.toolbar-dd-summary:active {
  background: var(--btn-press);
}
.toolbar-dd-panel {
  position: absolute;
  top: calc(100% + 6px);
  min-width: min(280px, calc(100vw - 24px));
  max-height: min(70vh, 420px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--base);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  padding: 6px;
  z-index: 400;
}
.toolbar-phone-nav {
  position: relative;
}
.toolbar-phone-nav .toolbar-dd-panel {
  left: 0;
  right: auto;
}
.toolbar-phone-actions {
  position: relative;
}
.toolbar-phone-actions .toolbar-dd-panel {
  left: auto;
  right: 0;
}
.toolbar-dd-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  margin: 2px 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  box-sizing: border-box;
}
.toolbar-dd-item:hover,
.toolbar-dd-item:focus {
  background: var(--alt);
  outline: none;
}
.toolbar-dd-item.is-active {
  background: var(--win);
  box-shadow: inset 0 0 0 2px var(--highlight);
  font-weight: 600;
}
.toolbar-dd-ico {
  flex-shrink: 0;
  width: 1.5rem;
  text-align: center;
}
.toolbar-dd-theme-form {
  margin: 4px 0 0;
  padding: 0;
}
.toolbar-dd-theme-btn {
  background: var(--alt) !important;
  border: 1px solid var(--border) !important;
}
.toolbar-dd-danger {
  color: var(--bad);
  font-weight: 600;
}
/* Menu rows live inside .toolbar — override chip styles from `.toolbar a, .toolbar button` */
.toolbar .toolbar-dd-panel > a.toolbar-dd-item,
.toolbar .toolbar-dd-panel > button.toolbar-dd-item {
  background: transparent;
  border: none;
  box-shadow: none;
  white-space: normal;
}
.toolbar .toolbar-dd-panel > a.toolbar-dd-item:hover,
.toolbar .toolbar-dd-panel > button.toolbar-dd-item:hover {
  background: var(--alt);
}
.toolbar .toolbar-dd-panel > a.toolbar-dd-item.is-active {
  background: var(--win);
  box-shadow: inset 0 0 0 2px var(--highlight);
}
.toolbar .toolbar-dd-panel .toolbar-dd-theme-form {
  display: block;
  width: 100%;
}

.main-split {
  display: flex;
  flex: 1 1 0;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}
/* Left nav: icon-only rail; expands on hover or keyboard focus.
   Clamp min/max width so flex (min-width:auto) doesn’t grow the rail from link text. */
.nav-side {
  --nav-rail-width: 52px;
  --nav-expanded-width: 220px;
  box-sizing: border-box;
  flex-shrink: 0;
  align-self: stretch;
  width: var(--nav-rail-width);
  min-width: var(--nav-rail-width);
  max-width: var(--nav-rail-width);
  background: var(--base);
  border-right: 1px solid var(--border);
  padding: 8px 0;
  overflow-x: hidden;
  overflow-y: auto;
  min-height: 0;
  transition: width 0.22s ease, min-width 0.22s ease, max-width 0.22s ease;
}
.nav-side:hover,
.nav-side:focus-within {
  width: var(--nav-expanded-width);
  min-width: var(--nav-expanded-width);
  max-width: var(--nav-expanded-width);
}
.nav-side a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  color: var(--text);
  text-decoration: none;
  border-left: 3px solid transparent;
  font-size: 13px;
  white-space: nowrap;
  justify-content: flex-start;
  position: relative;
  transition: padding 0.18s ease, justify-content 0.18s ease, gap 0.18s ease;
}
/* Icon-only rail: no gap, center icon, label takes no space */
.nav-side:not(:hover):not(:focus-within) a {
  justify-content: center;
  gap: 0;
  padding-left: 8px;
  padding-right: 8px;
}
.nav-side:hover a,
.nav-side:focus-within a {
  padding: 8px 14px;
  justify-content: flex-start;
  gap: 8px;
}
.nav-side a:hover { background: var(--alt); }
.nav-side a.active {
  background: var(--win);
  border-left-color: var(--highlight);
  font-weight: 600;
}
.nav-ico {
  flex-shrink: 0;
  width: 22px;
  text-align: center;
  opacity: 0.9;
}
.nav-label {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  opacity: 0;
  max-width: 0;
  transition: opacity 0.15s ease, max-width 0.22s ease;
}
.nav-side:hover .nav-label,
.nav-side:focus-within .nav-label {
  opacity: 1;
  max-width: 200px;
}
@media (prefers-reduced-motion: reduce) {
  .nav-side,
  .nav-side a,
  .nav-label {
    transition: none;
  }
}

.content-area {
  flex: 1 1 0;
  min-width: 0; /* allow flex child to shrink so nested tables can scroll horizontally */
  min-height: 0;
  overflow: auto;
  overflow-x: auto;
  overflow-y: auto;
  padding: 12px 16px;
  background: var(--win);
  -webkit-overflow-scrolling: touch;
}

.group-box {
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-top: 12px;
  margin-bottom: 12px;
  padding: 10px 12px;
  background: var(--base);
}
.group-box > .gb-title {
  font-weight: bold;
  margin: -10px -12px 10px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--alt);
  border-radius: 4px 4px 0 0;
}

/* Settings / Admin / Inventory Orders — collapsible subsections fill content area */
.settings-shell {
  width: 100%;
  max-width: none;
  box-sizing: border-box;
}
.settings-lead {
  color: var(--muted);
  margin: 0 0 12px;
  line-height: 1.45;
}
details.settings-accordion {
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-top: 10px;
  margin-bottom: 10px;
  background: var(--base);
  overflow: hidden;
}
details.settings-accordion > summary {
  list-style: none;
  list-style-type: none;
  cursor: pointer;
  padding: 10px 36px 10px 12px;
  background: var(--alt);
  border-bottom: 1px solid transparent;
  position: relative;
  user-select: none;
}
details.settings-accordion > summary::-webkit-details-marker {
  display: none;
}
details.settings-accordion > summary::after {
  content: "▸";
  position: absolute;
  right: 14px;
  top: 50%;
  margin-top: -0.5em;
  line-height: 1;
  color: var(--muted);
  font-size: 12px;
  transition: transform 0.15s ease;
}
details.settings-accordion[open] > summary {
  border-bottom-color: var(--border);
}
details.settings-accordion[open] > summary::after {
  transform: rotate(90deg);
}
details.settings-accordion > summary:hover {
  background: var(--btn-hover);
}
.settings-accordion-title {
  display: block;
  font-weight: bold;
  font-size: 14px;
  color: var(--text);
}

/* Fabrication projects: color status section headings + KPI (Not Started) */
:root {
  --fab-purple: #b58cff; /* light purple for Not Started */
}
details.settings-accordion.fab-status--in-process .settings-accordion-title {
  color: var(--warn);
}
details.settings-accordion.fab-status--not-started .settings-accordion-title {
  color: var(--fab-purple);
}
details.settings-accordion.fab-status--delivered .settings-accordion-title {
  color: var(--good);
}
details.settings-accordion.fab-status--canceled .settings-accordion-title {
  color: var(--bad);
}
.fab-kpi-not-started-value {
  color: var(--fab-purple);
}
.settings-accordion-sub {
  display: block;
  font-weight: normal;
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.35;
}
.settings-accordion-panel {
  padding: 12px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  font-size: 13px;
}
.kpi-grid span { color: var(--muted); display: block; font-size: 12px; }
.kpi-grid strong { font-size: 14px; }

/* Dashboard KPIs */
.kpi-dashboard-row {
  display: flex;
  align-items: flex-end;
  gap: 16px 28px;
  flex-wrap: wrap;
}
.kpi-dashboard-row .kpi-grid--main {
  flex: 1 1 0;
  min-width: min(100%, 280px);
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}
.kpi-section-title {
  grid-column: 1 / -1;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 14px 0 6px 0;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.kpi-grid .kpi-section-title:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}
/* Metrics page — range chips, bars, forecast cards */
.metrics-range-nav { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.metrics-range-link { display: inline-block; margin-right: 6px; margin-bottom: 6px; padding: 4px 10px; text-decoration: none; }
.metrics-range-link.is-active { outline: 2px solid var(--highlight); outline-offset: 2px; border-radius: 4px; }
.metrics-lead { color: var(--muted); font-size: 13px; margin: 0 0 8px; max-width: 52rem; }
.metrics-kpi-sub { font-size: 11px; font-weight: normal; color: var(--muted); }
.metrics-disclaimer {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 12px;
  padding: 8px 10px;
  background: var(--alt);
  border: 1px solid var(--border);
  border-radius: 4px;
  max-width: 52rem;
}
.metrics-forecast-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}
.metrics-forecast-card {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 12px;
  background: var(--base);
  font-size: 13px;
}
.metrics-forecast-label { font-weight: 600; margin-bottom: 8px; }
.metrics-forecast-values { display: flex; flex-direction: column; gap: 6px; color: var(--muted); }
.metrics-forecast-values strong { color: var(--text); }
.metrics-forecast-meta { font-size: 11px; color: var(--muted); margin-top: 8px; }
.metrics-muted { font-size: 12px; color: var(--muted); margin: 0 0 8px; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin-top: 8px; }
.metrics-bar-block { margin-top: 12px; max-width: 640px; }
.metrics-bar-block--compact { max-width: 480px; }
.metrics-bar-title { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 8px; }
.metric-bar-row {
  display: grid;
  grid-template-columns: 88px 1fr 56px;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
  font-size: 12px;
}
.metric-bar-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.metric-bar-track {
  height: 10px;
  background: var(--alt);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.metric-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--highlight);
  min-width: 0;
  transition: width 0.2s ease;
}
.metric-bar-fill--weight { background: #3cb371; }
.metric-bar-fill--mix { background: #4682b4; }
.metric-bar-val { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: var(--base);
}
table.data th, table.data td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  text-align: left;
}
table.data th { background: var(--alt); color: var(--text); }
table.data tr:nth-child(even) td { background: rgba(0,0,0,0.08); }
/* Production: selected task row (single-row status buttons) */
table.data tr.is-selected td {
  box-shadow: inset 0 0 0 2px var(--highlight);
  background: rgba(0, 120, 180, 0.12) !important;
}
html[data-theme="light"] table.data tr.is-selected td {
  background: rgba(0, 120, 180, 0.08) !important;
}

/* Scheduling — Gantt (parity with ui/scheduling_page.py STATUS_COLORS) */
.scheduling-intro { color: var(--muted); font-size: 13px; margin-bottom: 12px; }
.sched-legend { display: flex; flex-wrap: wrap; gap: 12px 20px; margin-bottom: 12px; font-size: 12px; align-items: center; }
.sched-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.sched-swatch { width: 14px; height: 14px; border-radius: 3px; border: 1px solid var(--border); flex-shrink: 0; }
.sched-swatch--not-started { background: #f1c40f; }
.sched-swatch--in-progress-fill { background: var(--highlight); }
.sched-swatch--complete { background: var(--good); }
.sched-legend--progress { font-size: 12px; }
.sched-range-form { margin-bottom: 6px; }
.sched-range-select { font-size: 13px; padding: 4px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--win); color: var(--text); }
.sched-day-axis-row { display: flex; align-items: stretch; min-height: 28px; margin-bottom: 4px; min-width: 480px; }
.sched-day-axis-spacer { flex: 0 0 200px; max-width: 200px; min-width: 200px; }
.fab-sched-day-axis .sched-day-axis-spacer { flex: 0 0 298px; max-width: 298px; min-width: 298px; }
.sched-day-axis-track { flex: 1; position: relative; min-height: 28px; border-bottom: 1px solid var(--border); min-width: 200px; }
.sched-day-tick { position: absolute; bottom: 0; transform: translateX(-50%); font-size: 10px; color: var(--muted); text-align: center; line-height: 1.1; pointer-events: none; white-space: nowrap; }
.sched-day-tick__day { display: block; font-weight: 700; color: var(--text); }
.sched-day-tick__mon { display: block; font-size: 9px; }
.sched-gantt-today { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--bad); z-index: 2; pointer-events: none; opacity: 0.85; }
.sched-gantt-panel { overflow-x: auto; margin-bottom: 16px; -webkit-overflow-scrolling: touch; }
.sched-gantt-axis { font-size: 12px; color: var(--muted); margin: 0 0 8px 168px; min-width: 220px; }
.sched-gantt-row { display: flex; align-items: stretch; min-height: 32px; margin-bottom: 2px; min-width: 480px; }
.sched-gantt-label { flex: 0 0 200px; max-width: 200px; min-width: 200px; padding: 6px 8px 6px 0; font-size: 12px; overflow: hidden; }
.sched-gantt-sublabel { font-size: 11px; color: var(--muted); line-height: 1.3; margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word; }
.sched-gantt-label > a { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sched-gantt-track { flex: 1; position: relative; min-height: 28px; background: var(--alt); border: 1px solid var(--border); border-radius: 4px; min-width: 200px; }
.sched-bar { position: absolute; top: 3px; bottom: 3px; min-width: 2px; border-radius: 3px; border: 1px solid rgba(0,0,0,0.28); font-size: 11px; font-weight: 600; display: flex; align-items: center; justify-content: center; text-decoration: none; box-sizing: border-box; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.45); overflow: hidden; padding: 0 4px; }
html[data-theme="light"] .sched-bar { color: #1a1a1a; text-shadow: none; border-color: rgba(0,0,0,0.15); }
.sched-bar:hover { filter: brightness(1.08); }
.sched-bar-none { position: absolute; left: 8px; top: 50%; transform: translateY(-50%); font-size: 12px; color: var(--muted); }
.sched-bar--open { background: #4682b4; }
.sched-bar--in-progress { background: rgba(218, 165, 32, 0.42); }
.sched-bar--qa-pending { background: #ff8c00; }
.sched-bar--ready-to-ship { background: #3cb371; }
.sched-bar--delivered { background: #6495ed; }
.sched-bar--closed { background: #808080; }
.sched-bar--unknown { background: #6c757d; }
/* Time elapsed within scheduled span (primary progress-over-time indicator) */
.sched-bar__time {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  max-width: 100%;
  border-radius: 2px 0 0 2px;
  pointer-events: none;
  z-index: 0;
  box-sizing: border-box;
  opacity: 0.92;
}
.sched-fill--not-started .sched-bar__time { background: #f1c40f; }
.sched-fill--in-progress .sched-bar__time { background: var(--highlight); }
.sched-fill--complete .sched-bar__time { background: var(--good); }
.sched-bar__label {
  position: relative;
  z-index: 1;
  pointer-events: none;
}
/* Fabrication schedule: project ID | description | Gantt track */
.fab-sched-gantt-row {
  display: flex;
  align-items: stretch;
  min-height: 32px;
  margin-bottom: 2px;
  min-width: 560px;
}
.fab-sched-gantt-id {
  flex: 0 0 108px;
  max-width: 108px;
}
.fab-sched-gantt-desc {
  flex: 0 0 188px;
  max-width: 228px;
  padding: 6px 10px 6px 0;
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.25;
  align-self: center;
}
.fab-sched-gantt-row .sched-gantt-track {
  flex: 1;
  min-width: 200px;
}
.fab-sched-gantt-axis {
  margin-left: 298px;
  min-width: 220px;
}

/* Inline text links in tables (e.g. Inventory → Actions) */
table.data td a {
  color: var(--link);
  text-decoration: underline;
}
table.data td a:visited {
  color: var(--link-visited);
}
table.data td a:hover {
  color: var(--link-hover);
}

/* Main content links: readable in dark mode; exclude button-styled anchors */
.content-area a:not(.btn-shop) {
  color: var(--link);
}
.content-area a:not(.btn-shop):visited {
  color: var(--link-visited);
}
.content-area a:not(.btn-shop):hover {
  color: var(--link-hover);
}

/* Text-style action buttons (matches link treatment; use modifiers for semantic colors) */
.link-btn {
  background: none;
  border: none;
  color: var(--link);
  cursor: pointer;
  padding: 0;
  font: inherit;
  text-decoration: underline;
}
.link-btn:hover {
  color: var(--link-hover);
}
.link-btn--danger {
  color: var(--bad);
}
.link-btn--danger:hover {
  color: var(--bad);
  filter: brightness(1.15);
}

.quick-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.quick-filters a {
  padding: 4px 12px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--alt);
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
}
.quick-filters a:hover { filter: brightness(1.08); }
.quick-filters a.on { border-bottom: 2px solid var(--highlight); background: var(--win); }

.pie-row { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 8px; }
.pie-card {
  flex: 1;
  min-width: 220px;
  text-align: center;
}
.pie-ring {
  width: 180px;
  height: 180px;
  border-radius: 50%;
  margin: 8px auto;
  position: relative;
}
.pie-legend { font-size: 12px; color: var(--muted); text-align: left; max-width: 200px; margin: 0 auto; }

.alert-box { color: var(--warn); font-weight: bold; white-space: pre-wrap; }
.smart-red { color: var(--bad); }
/* Consumables catalog: minimum 0 = reference-only row (no low-stock tracking) */
.consumables-row--reference td {
  color: var(--highlight);
}
.consumables-row--reference a,
.consumables-row--reference .btn-shop {
  color: var(--link);
}

@media (max-width: 720px) {
  .consumables-filter-bar {
    grid-template-columns: 1fr;
  }
}
.dashboard-smart-alerts.smart-red a {
  color: inherit;
  text-decoration: underline;
}
.dashboard-inventory-alerts,
.dashboard-inventory-alerts .data th,
.dashboard-inventory-alerts .data td {
  color: var(--warn);
}

.dashboard-job-progress-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 7rem;
}
.dashboard-job-progress {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  min-width: 56px;
  max-width: 140px;
}
.dashboard-job-progress__bar {
  height: 100%;
  background: var(--highlight);
  border-radius: 4px;
  min-width: 0;
}
.dashboard-job-progress__label {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  flex: 0 0 auto;
}

.dashboard-days-remaining {
  color: var(--good);
  font-weight: 600;
}
.dashboard-days-overdue {
  color: var(--bad);
  font-weight: 600;
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(120px, auto) 1fr;
  gap: 8px 14px;
  align-items: center;
}
.form-grid label { display: block; color: var(--muted); font-size: 12px; margin-top: 0; }
.form-grid input, .form-grid select, .form-grid textarea {
  width: 100%; max-width: 400px;
  padding: 6px 8px;
  border-radius: 3px;
  border: 1px solid var(--border);
  background: var(--win);
  color: var(--text);
}

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: var(--base);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  max-width: 320px;
  width: 90%;
}

/* Login center */
.login-wrap { max-width: 400px; margin: 4rem auto; padding: 20px; }
.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  margin-bottom: 14px;
}
.login-logo {
  max-width: 270px;
  width: 100%;
  height: auto;
  object-fit: contain;
}
.login-subtitle {
  color: #0b7a7a;
  font-weight: 700;
  font-size: 12px;
  line-height: 1.35;
}
.pw-wrap {
  position: relative;
  width: 100%;
  max-width: 400px; /* match .form-grid input max-width */
}
.pw-wrap input {
  max-width: none; /* container controls width */
  padding-right: 52px; /* room for smaller button */
}
.pw-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--alt);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 2px 6px;
  cursor: pointer;
  font-size: 12px;
  min-height: 17px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.pw-toggle:hover { background: var(--btn-hover); }
.pw-toggle svg {
  width: 11px;
  height: 11px;
}

/* -------------------------------------------------------------------------- */
/* Responsive: phones, tablets, small laptops (≤992px)                        */
/* - Portrait: same chrome as phone (☰ / search / ⚙); sidebar hidden           */
/* - Landscape: same layout as desktop (vertical nav rail + full toolbar)     */
/* -------------------------------------------------------------------------- */

@media (max-width: 992px) {
  html { font-size: 15px; }
  .app-shell {
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
  }
  .app-header { padding: 6px 8px 4px; }
  .app-header-row1 {
    flex-wrap: wrap;
    gap: 10px;
    row-gap: 8px;
  }
  .app-header-row1 .spacer {
    flex: 1 1 120px;
    min-width: 0;
  }
  .app-header-row1 .btn-shop {
    flex: 1 1 auto;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 14px;
  }
  .app-logo { height: 28px; }

  /* Toolbar: touch targets only — layout stays desktop in landscape; portrait uses (max-width:1200px)+portrait block below */
  .toolbar a,
  .toolbar button {
    min-height: 44px;
    padding: 8px 12px;
    font-size: 14px;
  }
  .toolbar-trailing .toolbar-theme-form {
    flex: 0 0 auto;
  }
  .toolbar input[type="search"] {
    width: 100%;
    max-width: none;
    min-height: 44px;
    font-size: 16px; /* avoids iOS zoom on focus */
  }
  .toolbar select {
    min-height: 44px;
    font-size: 16px;
    max-width: 100%;
  }

  .content-area {
    padding: 12px 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .group-box {
    padding: 12px 12px;
    margin-left: 0;
    margin-right: 0;
  }
  .group-box > .gb-title {
    margin: -12px -12px 10px;
    padding: 8px 12px;
  }

  h1 { font-size: 1.45rem; margin-top: 0.25rem; }

  .form-grid {
    grid-template-columns: 1fr;
    gap: 6px 0;
    align-items: stretch;
  }
  .form-grid > label { margin-top: 10px; }
  .form-grid > label:first-of-type { margin-top: 0; }
  .form-grid input,
  .form-grid select,
  .form-grid textarea {
    max-width: none;
    width: 100%;
    min-height: 44px;
    font-size: 16px;
  }
  .form-grid textarea {
    min-height: 88px;
  }

  table.data {
    font-size: 12px;
  }
  table.data th,
  table.data td {
    padding: 10px 8px;
  }

  .kpi-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }
  .kpi-dashboard-row .kpi-grid--main {
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    min-width: 0;
  }
  .pie-card { min-width: 0; }
  .pie-ring {
    width: min(180px, 70vw);
    height: min(180px, 70vw);
  }
  .pie-row { flex-direction: column; align-items: center; }

  .modal-box {
    max-width: calc(100vw - 24px);
    margin: 12px;
    padding: 14px;
  }

  .quick-filters {
    gap: 8px;
  }
  .quick-filters a {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    padding: 8px 14px;
  }
}

/*
 * Portrait ≤1200px (phone + tablet): same “cellphone” chrome — ☰ | search | ⚙; sidebar hidden.
 * Leading + trailing toolbar strips hidden; all actions live in ⚙ (and pages in ☰).
 * Landscape uses desktop nav + toolbar (see base + max-width:992px block).
 */
@media (max-width: 1200px) and (orientation: portrait) {
  .app-header {
    overflow: visible;
  }
  .toolbar {
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 6px;
    padding: 6px 8px;
    overflow: visible;
  }
  .toolbar-phone-nav,
  .toolbar-phone-actions {
    display: block;
    align-self: center;
  }
  .toolbar-leading-actions {
    display: none !important;
  }
  .toolbar-trailing {
    display: none !important;
  }
  .toolbar-leading {
    flex: 1 1 0 !important;
    min-width: 0 !important;
    overflow: visible;
  }
  .toolbar-search-form {
    flex: 1 1 0 !important;
    min-width: 0 !important;
  }
  .toolbar-search-form input[type="search"] {
    min-height: 44px;
    font-size: 16px;
  }

  .main-split .nav-side {
    display: none !important;
  }
}

/* Narrow phones: slightly smaller type + login full-bleed */
@media (max-width: 576px) {
  html { font-size: 14px; }
  .login-wrap {
    margin: 1.5rem 12px;
    padding: 16px;
    max-width: none;
  }

  /* Dashboard: Fabrication KPI strip — prevent value clipping on phone portrait */
  .fab-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }
  .fab-kpi-grid .kpi-value {
    font-size: clamp(14px, 4.8vw, 18px);
    line-height: 1.15;
    overflow-wrap: anywhere;
    word-break: break-word;
  }
}

/* Optional: very small height — reduce login margin */
@media (max-width: 576px) and (max-height: 520px) {
  .login-wrap { margin-top: 1rem; }
}

/* Ultra-narrow phones: stack KPI cards */
@media (max-width: 360px) {
  .fab-kpi-grid {
    grid-template-columns: 1fr !important;
  }
}

@media print {
  body:has(.app-shell) {
    height: auto;
    overflow: visible;
  }
  .app-shell {
    height: auto;
    max-height: none;
    overflow: visible;
  }
  .main-split {
    overflow: visible;
  }
  .content-area {
    overflow: visible;
  }
}

/* -------------------------------------------------------------------------- */
/* Web shop floor (kiosk-style; layout_shop_floor.html)                        */
/* -------------------------------------------------------------------------- */

.shop-floor-body {
  margin: 0;
  min-height: 100vh;
  background: var(--base);
  color: var(--text);
}

.shop-floor-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--win);
}

.shop-floor-header-left {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 14px;
}

.shop-floor-brand {
  font-weight: 700;
  font-size: 15px;
  color: var(--muted);
}

.shop-floor-title {
  font-size: 20px;
  font-weight: 700;
}

.shop-floor-header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.shop-floor-theme-form {
  margin: 0;
  display: inline;
}

.shop-floor-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 16px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--alt);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  box-sizing: border-box;
}

.shop-floor-btn:hover {
  background: var(--btn-hover);
}

.shop-floor-btn--ghost {
  background: transparent;
}

.shop-floor-btn--primary {
  background: var(--alt);
}

.shop-floor-btn--danger {
  background: #5c2222;
  border-color: #7a3333;
  color: #fff;
}

.shop-floor-btn--done {
  min-height: 44px;
  padding: 8px 14px;
  background: #1e4d2e;
  border-color: #2a6b3f;
  color: #fff;
  font-weight: 700;
}

.shop-floor-main {
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  max-width: 100%;
}

.shop-floor-shell {
  display: grid;
  grid-template-columns: minmax(200px, 270px) minmax(0, 1fr) minmax(200px, 300px);
  gap: 14px;
  align-items: start;
  width: 100%;
}

.shop-floor-side {
  background: var(--win);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 10px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  position: sticky;
  top: 8px;
}

.shop-floor-side-title {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
}

.shop-floor-side-hint {
  display: block;
  font-weight: 500;
  font-size: 12px;
  color: var(--muted);
}

.shop-floor-side-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.shop-floor-side-list li {
  margin-bottom: 6px;
}

.shop-floor-side-empty {
  font-size: 13px;
  color: var(--muted);
  padding: 8px 4px;
}

.shop-floor-pill {
  width: 100%;
  margin: 0;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--alt);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  text-align: left;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
  font-family: inherit;
}

.shop-floor-pill:hover {
  background: var(--btn-hover);
}

.shop-floor-pill.is-active {
  border-color: #3498db;
  box-shadow: 0 0 0 1px color-mix(in srgb, #3498db 45%, transparent);
  background: color-mix(in srgb, #3498db 14%, var(--alt));
}

.shop-floor-pill-line1 {
  font-weight: 700;
}

.shop-floor-pill-meta {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  line-height: 1.35;
}

.shop-floor-center {
  min-width: 0;
}

@media (max-width: 1100px) {
  .shop-floor-shell {
    grid-template-columns: 1fr;
  }

  .shop-floor-side {
    position: static;
    max-height: none;
  }

  .shop-floor-side--jobs {
    order: 1;
  }

  .shop-floor-center {
    order: 3;
  }

  .shop-floor-side--materials {
    order: 2;
  }
}

.shop-floor-lead {
  margin: 0 0 14px;
  font-size: 15px;
  color: var(--muted);
  max-width: 56rem;
}

.shop-floor-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 14px 20px;
  margin-bottom: 14px;
}

.shop-floor-filter-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  flex: 1 1 240px;
  min-width: min(100%, 280px);
}

.shop-floor-filter-input {
  font-size: 18px;
  padding: 12px 14px;
  min-height: 48px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--win);
  color: var(--text);
  width: 100%;
  box-sizing: border-box;
}

.shop-floor-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  cursor: pointer;
  user-select: none;
}

.shop-floor-check input {
  width: 18px;
  height: 18px;
}

.shop-floor-table {
  font-size: 14px;
}

.shop-floor-table th,
.shop-floor-table td {
  vertical-align: middle;
}

.shop-floor-job-link {
  color: var(--link);
  font-weight: 600;
}

.shop-floor-status-cell {
  min-width: 220px;
}

.shop-floor-status-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.shop-floor-status-form,
.shop-floor-done-form {
  margin: 0;
}

.shop-floor-status-select {
  font-size: 16px;
  padding: 10px 12px;
  min-height: 44px;
  min-width: 140px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--win);
  color: var(--text);
}

.shop-floor-flash-err {
  background: color-mix(in srgb, var(--bad) 18%, transparent);
  border: 1px solid var(--bad);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 12px;
}

.sf-scan-btn {
  font-size: 14px;
  padding: 8px 12px;
  min-height: 40px;
}

.sf-plate-ok {
  color: var(--good);
  font-weight: bold;
  margin-left: 6px;
}

.sf-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 9998;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}

.sf-modal-backdrop[hidden] {
  display: none !important;
}

.sf-modal {
  background: var(--win);
  color: var(--text);
  border-radius: 10px;
  border: 1px solid var(--border);
  max-width: 420px;
  width: 100%;
  padding: 16px;
  margin-top: 24px;
  z-index: 9999;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

.sf-modal h2 {
  margin: 0 0 8px 0;
  font-size: 1.15rem;
}

#sf-qr-reader {
  width: 100%;
  min-height: 240px;
  background: #111;
  border-radius: 8px;
  overflow: hidden;
}

.sf-modal-msg {
  font-size: 14px;
  margin: 8px 0;
  min-height: 1.25em;
}

.sf-modal-msg--err {
  color: var(--bad);
}

.sf-modal-msg--ok {
  color: var(--good);
}

.sf-manual-grid {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.sf-manual-grid label {
  font-size: 13px;
  color: var(--muted);
}

.sf-manual-grid input[type="text"],
.sf-manual-grid input[type="file"] {
  width: 100%;
  font-size: 16px;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--win);
  color: var(--text);
}

