:root {
  --c-bg: #f6f7fb;
  --c-surface: #ffffff;
  --c-surface-2: #f8fafc;
  --c-border: #e2e8f0;
  --c-border-strong: #cbd5e1;
  --c-text: #0f172a;
  --c-text-muted: #475569;
  --c-text-dim: #64748b;
  --c-primary: #4f46e5;
  --c-primary-dark: #4338ca;
  --c-primary-soft: #eef2ff;
  --c-success: #16a34a;
  --c-success-soft: #dcfce7;
  --c-warning: #d97706;
  --c-warning-soft: #fef3c7;
  --c-danger: #dc2626;
  --c-danger-soft: #fee2e2;
  --c-accent: #0ea5e9;

  /* Lane theme colours */
  --rigid-700: #0369a1;     /* deep cyan */
  --rigid-500: #0ea5e9;
  --rigid-50:  #ecfeff;
  --cnc-700: #7c3aed;       /* purple */
  --cnc-500: #a855f7;
  --cnc-50:  #faf5ff;

  --r: 10px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.06);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  /* Responsive breakpoints (consumed by @media queries across every CSS
     file). Keep these in sync if changed; we use only these three. */
  --bp-sm: 600px;     /* phone landscape / small tablet portrait */
  --bp-md: 900px;     /* tablet portrait */
  --bp-lg: 1200px;    /* tablet landscape / small laptop */

  /* Minimum tap target on touch devices. Apple HIG = 44pt; Material = 48dp.
     We pick 44 — slightly tighter to keep small chips usable on a tablet. */
  --touch-min: 44px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  font-size: 14px;
  line-height: 1.5;
}

header.app-header {
  background: linear-gradient(135deg, #1e1b4b 0%, #312e81 60%, #4338ca 100%);
  color: white;
  padding: 0;  /* the three bands handle their own padding */
}
/* Band 1: brand bar — small subtle row with brand on the left, role chip on right */
.app-brand-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 40px;
  background: rgba(0, 0, 0, 0.18);
  font-size: 11px;
}
.app-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: rgba(255, 255, 255, 0.85);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.app-brand a { color: inherit; text-decoration: none; }
.app-brand a:hover { color: white; }

/* Band 2: page title + description */
.app-page-title {
  padding: 18px 40px 14px;
}
header.app-header h1 {
  margin: 0 0 4px; font-size: 22px; font-weight: 700; letter-spacing: -0.01em;
}
header.app-header .app-page-title p {
  margin: 0; color: #c7d2fe; font-size: 13px; max-width: 920px;
}

/* Band 3: nav tab strip — sits flush against the page body */
header.app-header .page-nav {
  padding: 0 40px;
  margin: 0;
  border-bottom: 1px solid rgba(15, 23, 42, 0.12);
}

/* Shared "inventory-table" base — used wherever a module renders a data
   table. Each module's CSS may override specifics but the alignment +
   header treatment lives here so it's consistent across pages. */
.inventory-table {
  width: 100%;
  background: var(--c-surface, #fff);
  border: 1px solid var(--c-border, #e2e8f0);
  border-radius: var(--r, 8px);
  border-collapse: collapse;
  box-shadow: var(--shadow-sm, 0 1px 2px rgba(0,0,0,0.04));
  overflow: hidden;
}
.inventory-table th {
  text-align: left;
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--c-text-dim);
  padding: 10px 14px;
  background: var(--c-surface-2);
  border-bottom: 1px solid var(--c-border);
}
.inventory-table td {
  padding: 10px 14px;
  font-size: 13px;
  border-bottom: 1px solid var(--c-border);
  font-variant-numeric: tabular-nums;
  vertical-align: middle;
}
.inventory-table tbody tr:hover { background: var(--c-surface-2); }
.inventory-table tbody tr:last-child td { border-bottom: none; }

/* Wrap a table in `<div class="table-scroll">` to get horizontal scroll
   on narrow viewports while preserving the column structure. Cards-mode
   would be more "mobile native" but loses the dense scannable layout
   the operator + Lead Engineer rely on. */
.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--r);
}
.table-scroll > .inventory-table { min-width: 600px; }

/* Helper class for non-essential columns we hide on phone-width to keep
   the table readable without horizontal scroll. Apply to <th> and the
   matching <td>s per column. */
@media (max-width: 600px) {
  .col-hide-sm { display: none !important; }
}

/* (Legacy pill-style .page-nav removed — tab-strip styling now lives in
   app-nav.css and is shared across every page that loads that file.) */

main {
  max-width: 1500px;
  margin: 0 auto;
  padding: 20px 32px 64px;
}
@media (max-width: 600px) {
  main { padding: 14px 12px 48px; }
}

/* ---------- Responsive: header + buttons ----------
   Universal rules so every page that uses the shared <header.app-header>
   shrinks gracefully on phone. Floor has its own header pattern; see
   floor.css for that side. */

@media (max-width: 600px) {
  .app-brand-bar {
    padding: 6px 14px;
    font-size: 10px;
  }
  .app-page-title {
    padding: 12px 14px 10px;
  }
  header.app-header h1 { font-size: 18px; }
  header.app-header .app-page-title p {
    font-size: 12px;
    /* Hide the long description on phone — the h1 alone is enough on the
       small screen. Pages that NEED their description should override. */
    display: none;
  }
  header.app-header .page-nav { padding: 0 8px; }
}

/* Touch target floor on every clickable control. Tablets + phones get
   the bumped sizing; mouse-driven layouts keep the tighter desktop look
   (the constraint only kicks in below the tablet breakpoint). */
@media (max-width: 900px) {
  .btn,
  button.tab,
  button.admin-tab,
  button.floor-tab,
  .role-chip {
    min-height: var(--touch-min);
  }
  input[type="text"],
  input[type="number"],
  input[type="email"],
  input[type="password"],
  input[type="date"],
  input[type="search"],
  select,
  textarea {
    min-height: var(--touch-min);
    font-size: 16px;  /* 16px+ prevents iOS Safari from auto-zooming on focus */
  }
}

/* ---------- Lanes layout ---------- */

.lanes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 1180px) {
  .lanes { grid-template-columns: 1fr; }
}

.lane {
  background: var(--c-surface);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--c-border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.lane-head {
  padding: 14px 18px;
  border-bottom: 2px solid;
  display: flex;
  align-items: center;
  gap: 10px;
}

.lane-rigid .lane-head { background: var(--rigid-50); border-bottom-color: var(--rigid-500); }
.lane-cnc   .lane-head { background: var(--cnc-50);   border-bottom-color: var(--cnc-500); }

.lane-id { display: flex; align-items: center; gap: 10px; flex: 1; }
.lane-icon { font-size: 22px; }
.lane-head h2 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.lane-rigid .lane-head h2 { color: var(--rigid-700); }
.lane-cnc   .lane-head h2 { color: var(--cnc-700); }
.lane-tag {
  font-size: 11px;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 999px;
  background: white;
  color: var(--c-text-dim);
  border: 1px solid var(--c-border);
  text-transform: lowercase;
  letter-spacing: 0.02em;
}

.lane-body { padding: 16px 18px 20px; display: flex; flex-direction: column; gap: 18px; }

/* ---------- Collapsible block config ---------- */

.lane-block-config {
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: 8px;
  padding: 10px 14px;
}
.lane-block-config > summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--c-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  list-style: none;
}
.lane-block-config > summary::-webkit-details-marker { display: none; }
.lane-block-config > summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 6px;
  transition: transform 0.15s;
}
.lane-block-config[open] > summary::before { transform: rotate(90deg); }
.lane-block-config > .field-row { margin-top: 12px; }

/* ---------- Inputs ---------- */

.field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
}
.field { display: flex; flex-direction: column; gap: 4px; }
.field label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--c-text-dim);
}
.field input[type="text"],
.field input[type="number"],
.field select {
  padding: 7px 9px;
  border: 1px solid var(--c-border-strong);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  background: white;
  color: var(--c-text);
}
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}
.checkbox-field { flex-direction: row; align-items: center; gap: 8px; }
.checkbox-field label {
  margin: 0; text-transform: none; letter-spacing: 0;
  font-size: 12px; color: var(--c-text-muted); font-weight: 500;
}

/* ---------- Buttons ---------- */

.btn {
  background: var(--c-primary);
  color: white;
  border: none;
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, transform 0.05s;
}
.btn:hover { background: var(--c-primary-dark); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { background: white; color: var(--c-text); border: 1px solid var(--c-border-strong); }
.btn-secondary:hover { background: var(--c-surface-2); }
.btn-ghost { background: transparent; color: var(--c-text-muted); padding: 4px 8px; }
.btn-ghost:hover { background: var(--c-surface-2); color: var(--c-danger); }
.btn-primary-lg { background: var(--c-success); font-size: 14px; font-weight: 600; padding: 10px 22px; }
.btn-primary-lg:hover { background: #15803d; }

/* Lane-themed run button */
.lane-rigid .btn-primary-lg { background: var(--rigid-500); }
.lane-rigid .btn-primary-lg:hover { background: var(--rigid-700); }
.lane-cnc   .btn-primary-lg { background: var(--cnc-500); }
.lane-cnc   .btn-primary-lg:hover { background: var(--cnc-700); }

/* ---------- Orders section ---------- */

.orders-section { display: flex; flex-direction: column; gap: 10px; }
.orders-head { display: flex; align-items: center; justify-content: space-between; }
.orders-head h3 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--c-text-dim);
}
.orders-actions { display: flex; gap: 6px; }
.orders-list { display: flex; flex-direction: column; gap: 10px; }
.orders-list:empty::before {
  content: "No orders queued. Click “+ Add order” to start.";
  display: block;
  padding: 16px;
  text-align: center;
  border: 1px dashed var(--c-border-strong);
  border-radius: 8px;
  color: var(--c-text-dim);
  font-size: 12px;
  font-style: italic;
}

.order-card {
  border: 1px solid var(--c-border);
  border-radius: 8px;
  padding: 12px 14px;
  background: white;
  display: grid;
  grid-template-columns: 78px 1fr auto;
  gap: 14px;
  align-items: start;
}

.order-card .thumb-col { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.order-card .thumb {
  width: 70px; height: 70px;
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.order-card .thumb svg { width: 62px; height: 62px; }
.order-card .thumb-meta { font-size: 9px; color: var(--c-text-dim); text-align: center; font-variant-numeric: tabular-nums; }
.order-card .main-col { min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.order-card .action-col { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }

.dxf-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--c-surface-2);
  border: 1px dashed var(--c-border-strong);
  border-radius: 6px;
  font-size: 12px;
}
.dxf-bar .status-line { flex: 1; color: var(--c-text-dim); min-width: 180px; font-size: 11px; }
.dxf-bar .status-line.ok { color: var(--c-success); font-weight: 500; }
.dxf-bar .status-line.err { color: var(--c-danger); }

/* ---------- Run row ---------- */

.run-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-top: 4px;
}
.run-status { color: var(--c-text-dim); font-size: 12px; }
.run-status.err { color: var(--c-danger); }

/* ---------- Result panel inside each lane ---------- */

.lane-result {
  border-top: 1px dashed var(--c-border);
  padding-top: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.lane-result .solver-badge {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  font-family: var(--mono);
}
.lane-rigid .solver-badge { background: var(--rigid-50); color: var(--rigid-700); }
.lane-cnc   .solver-badge { background: var(--cnc-50); color: var(--cnc-700); }

.kpi-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.kpi {
  background: white;
  border: 1px solid var(--c-border);
  border-radius: 8px;
  padding: 12px 14px;
}
.kpi .kpi-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--c-text-dim);
  margin-bottom: 4px;
  font-weight: 600;
}
.kpi .kpi-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--c-text);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.kpi .kpi-sub { font-size: 10px; color: var(--c-text-dim); margin-top: 4px; }
.kpi.kpi-success .kpi-value { color: var(--c-success); }
.kpi.kpi-warning .kpi-value { color: var(--c-warning); }

@media (max-width: 720px) {
  .kpi-strip { grid-template-columns: 1fr 1fr; }
}

.lane-block-layout {
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: 8px;
  padding: 12px;
}
.lane-block-layout svg { width: 100%; height: auto; max-height: 440px; }

.layout-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 11px;
  margin-top: 8px;
  color: var(--c-text-muted);
}
.layout-legend .lg { display: flex; align-items: center; gap: 5px; }
.layout-legend .sw { width: 12px; height: 12px; border-radius: 3px; border: 1px solid rgba(15,23,42,0.15); }

.orders-results-title {
  margin: 4px 0 6px;
  font-size: 12px;
  color: var(--c-text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

table.orders-results { width: 100%; border-collapse: collapse; font-size: 13px; }
table.orders-results th {
  text-align: left;
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--c-text-dim);
  padding: 8px 10px;
  border-bottom: 1px solid var(--c-border);
}
table.orders-results td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--c-border);
  font-variant-numeric: tabular-nums;
  vertical-align: middle;
}
.fulfilment-bar {
  width: 100px;
  height: 8px;
  background: var(--c-surface-2);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}
.fulfilment-bar .fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: var(--c-primary);
  border-radius: 4px;
}
.fulfilment-bar.over .fill { background: var(--c-accent); }
.fulfilment-bar.partial .fill { background: var(--c-warning); }
.fulfilment-bar.refused .fill { background: var(--c-danger); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.chip.ok      { background: var(--c-success-soft); color: var(--c-success); }
.chip.over    { background: #e0f2fe; color: #075985; }
.chip.partial { background: var(--c-warning-soft); color: #92400e; }
.chip.refused { background: var(--c-danger-soft); color: #991b1b; }

details summary { cursor: pointer; font-size: 11px; color: var(--c-text-dim); }
pre {
  background: #0f172a;
  color: #e2e8f0;
  padding: 12px;
  border-radius: 6px;
  overflow: auto;
  font-size: 11px;
  font-family: var(--mono);
  max-height: 320px;
  margin-top: 10px;
}

.refused-card {
  background: var(--c-danger-soft);
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 14px 18px;
}
.refused-card h3 { margin: 0 0 6px; font-size: 14px; font-weight: 600; color: #991b1b; }
.refused-card p  { margin: 0; font-size: 13px; color: #7f1d1d; }

/* ---------- Responsive: modals + bottom-sheets ----------
   At phone widths, every full-page overlay (admin/inventory/orders
   dialogs, /users add-user, floor confirm-production, floor intake)
   becomes a bottom-anchored sheet — fills the width, rounded top
   corners only. Matches Android's native bottom-sheet pattern and
   keeps the Cancel/Save buttons within thumb reach. */

@media (max-width: 600px) {
  /* Admin + inventory + orders share the .dialog-backdrop + .dialog pair. */
  .dialog-backdrop {
    align-items: flex-end !important;
    padding: 0 !important;
  }
  .dialog {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 92vh !important;
    border-radius: 14px 14px 0 0 !important;
    margin: 0 !important;
    overflow-y: auto;
  }

  /* /users modal */
  .users-modal {
    align-items: flex-end;
    padding: 0;
  }
  .users-modal-card {
    width: 100%;
    max-width: 100%;
    max-height: 92vh;
    border-radius: 14px 14px 0 0;
    overflow-y: auto;
  }

  /* Floor confirm-production + intake sheets */
  .confirm-sheet-backdrop,
  .floor-intake-sheet-backdrop {
    align-items: flex-end;
    padding: 0;
  }
  .confirm-sheet-card,
  .floor-intake-sheet-card {
    width: 100%;
    max-width: 100%;
    max-height: 92vh;
    border-radius: 14px 14px 0 0;
  }
}
