/* ============================================================
   Design tokens
   ============================================================ */
:root {
  --color-primary: #1e3a5f;
  --color-primary-hover: #16304f;
  --color-on-primary: #ffffff;
  --color-accent: #2f6fed;
  --color-accent-hover: #2559c4;
  --color-accent-soft: #eaf1ff;
  --color-success: #059669;
  --color-success-soft: #e6f4ea;
  --color-success-text: #1e7b34;
  --color-warning-soft: #fff4e5;
  --color-warning-text: #7a4b00;
  --color-warning-border: #f0c987;
  --color-destructive: #dc2626;
  --color-destructive-soft: #fbe4e2;

  --color-background: #f6f7fb;
  --color-surface: #ffffff;
  --color-surface-muted: #f8fafc;
  --color-foreground: #0f172a;
  --color-muted-foreground: #5b6472;
  --color-subtle-foreground: #8992a0;
  --color-border: #e4e7eb;
  --color-border-strong: #d7dbe0;
  --color-ring: #2f6fed;

  --font-ui: 'Fira Sans', -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --font-mono: 'Fira Code', 'SFMono-Regular', Consolas, monospace;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 10px;
  --radius-full: 999px;

  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 4px 14px rgba(15, 23, 42, 0.10);
  --shadow-lg: 0 8px 30px rgba(15, 23, 42, 0.20);

  --duration-fast: 150ms;
  --duration-base: 220ms;
  --duration-slow: 320ms;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
}

@media (prefers-color-scheme: dark) {
  /* Reserved for future dark mode — app is light-only today, but tokens
     are structured so a dark palette can be swapped in without touching
     component rules. */
}

/* ============================================================
   Reset & base
   ============================================================ */
* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font-ui);
  background: var(--color-background);
  color: var(--color-foreground);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Only the authenticated app pages carry the sidebar (login.html doesn't
   have one, so it doesn't get this class and stays unaffected). */
body.has-sidebar {
  margin-left: 240px;
}

h1, h2, h3 {
  font-family: var(--font-ui);
}

::selection {
  background: var(--color-accent-soft);
  color: var(--color-primary);
}

:focus-visible {
  outline: 2px solid var(--color-ring);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

a { color: var(--color-accent); }

/* ============================================================
   Motion
   ============================================================ */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes overlayIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

@media (prefers-reduced-motion: no-preference) {
  .cs-po-card,
  .model-row,
  .part-row,
  .po-table tbody tr,
  .cs-version-row,
  .cs-extra-row {
    animation: fadeInUp var(--duration-base) var(--ease-out) both;
  }

  .cs-tab-panel {
    animation: fadeIn var(--duration-base) var(--ease-out) both;
  }

  .modal-overlay {
    animation: overlayIn var(--duration-fast) var(--ease-out) both;
  }

  .modal-box {
    animation: modalIn var(--duration-base) var(--ease-out) both;
  }

  /* Light stagger for the first several items in a freshly-rendered list —
     covers the common case without needing per-item JS delays. */
  .cs-po-card:nth-child(1),  .model-row:nth-child(1),  .part-row:nth-child(1),  .po-table tbody tr:nth-child(1),  .cs-version-row:nth-child(1),  .cs-extra-row:nth-child(1)  { animation-delay: 0ms; }
  .cs-po-card:nth-child(2),  .model-row:nth-child(2),  .part-row:nth-child(2),  .po-table tbody tr:nth-child(2),  .cs-version-row:nth-child(2),  .cs-extra-row:nth-child(2)  { animation-delay: 40ms; }
  .cs-po-card:nth-child(3),  .model-row:nth-child(3),  .part-row:nth-child(3),  .po-table tbody tr:nth-child(3),  .cs-version-row:nth-child(3),  .cs-extra-row:nth-child(3)  { animation-delay: 80ms; }
  .cs-po-card:nth-child(4),  .model-row:nth-child(4),  .part-row:nth-child(4),  .po-table tbody tr:nth-child(4),  .cs-version-row:nth-child(4),  .cs-extra-row:nth-child(4)  { animation-delay: 120ms; }
  .cs-po-card:nth-child(5),  .model-row:nth-child(5),  .part-row:nth-child(5),  .po-table tbody tr:nth-child(5),  .cs-version-row:nth-child(5),  .cs-extra-row:nth-child(5)  { animation-delay: 160ms; }
  .cs-po-card:nth-child(6),  .model-row:nth-child(6),  .part-row:nth-child(6),  .po-table tbody tr:nth-child(6),  .cs-version-row:nth-child(6),  .cs-extra-row:nth-child(6)  { animation-delay: 200ms; }
  .cs-po-card:nth-child(n+7), .model-row:nth-child(n+7), .part-row:nth-child(n+7), .po-table tbody tr:nth-child(n+7), .cs-version-row:nth-child(n+7), .cs-extra-row:nth-child(n+7) { animation-delay: 220ms; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
  vertical-align: -3px;
}

.btn-secondary .spinner,
.icon-btn .spinner {
  border-color: rgba(15, 23, 42, 0.15);
  border-top-color: var(--color-muted-foreground);
}

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: 56px 20px;
  color: var(--color-muted-foreground);
  text-align: center;
}

.loading-state p {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-primary);
}

.loading-spinner-lg {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(30, 58, 95, 0.15);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

/* ============================================================
   Sidebar navigation (replaces the old horizontal top bar)
   ============================================================ */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 240px;
  height: 100vh;
  background: var(--color-primary);
  color: #fff;
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
  transition: transform var(--duration-base) ease;
}

.sidebar-brand {
  padding: var(--space-4);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-2);
  flex: 1;
}

.sidebar-nav a {
  color: rgba(255, 255, 255, 0.75);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border-left: 3px solid transparent;
  transition: color var(--duration-fast) ease, background-color var(--duration-fast) ease;
}

.sidebar-nav a:hover,
.sidebar-nav a:focus-visible {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.sidebar-nav a.active {
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
  border-left-color: var(--color-accent);
}

.sidebar-footer {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.85);
}

.sidebar-logout-btn {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--radius-sm);
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background var(--duration-fast) ease;
  white-space: nowrap;
}

.sidebar-logout-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

/* Hidden on desktop - only shown (via the media query below) on narrow
   screens, where the sidebar itself becomes an off-canvas drawer. */
.mobile-topbar {
  display: none;
  background: var(--color-primary);
  color: #fff;
  padding: var(--space-3) var(--space-4);
  align-items: center;
  gap: var(--space-3);
}

.mobile-topbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

.mobile-nav-toggle {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: #fff;
  border-radius: var(--radius-sm);
  width: 36px;
  height: 36px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 99;
}

@media (max-width: 900px) {
  body.has-sidebar { margin-left: 0; }
  .mobile-topbar { display: flex; }
  .sidebar {
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.open { display: block; }
}

/* ============================================================
   Dashboard
   ============================================================ */
.dash-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.dash-tile {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-4);
  text-align: center;
}

.dash-tile-num {
  font-family: var(--font-mono);
  font-size: 32px;
  font-weight: 700;
  color: var(--color-primary);
  font-variant-numeric: tabular-nums;
}

.dash-tile-label {
  font-size: 12px;
  color: var(--color-muted-foreground);
  margin-top: 4px;
}

.dash-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: 10px var(--space-3);
  margin-bottom: var(--space-2);
  font-size: 13px;
  box-shadow: var(--shadow-sm);
}

/* ============================================================
   Status pills
   ============================================================ */
.status-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 700;
  text-transform: capitalize;
  transition: background-color var(--duration-fast) ease;
}

.status-pending { background: var(--color-warning-soft); color: var(--color-warning-text); }
.status-complete { background: var(--color-success-soft); color: var(--color-success-text); }

/* ============================================================
   Layout shells
   ============================================================ */
.cs-dashboard { padding: var(--space-4); max-width: 760px; margin: 0 auto; }
.cs-detail { padding: var(--space-4); max-width: 900px; margin: 0 auto; }

.columns, .po-layout {
  display: flex;
  gap: var(--space-4);
  padding: var(--space-4);
  align-items: flex-start;
  flex-wrap: wrap;
}

.column {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-4);
  flex: 1;
  min-width: 260px;
}

.column h2 {
  margin: 0 0 var(--space-3);
  font-size: 15px;
  font-weight: 600;
  color: var(--color-foreground);
}

.model-col { flex: 0 0 240px; }
.po-form-col { flex: 0 0 380px; }
.po-table-col { flex: 1; min-width: 320px; }

@media (max-width: 900px) {
  .columns, .po-layout {
    flex-direction: column;
  }
  /* !important is deliberate here: several pages set a fixed flex-basis or
     min-width inline on a .column (e.g. sheetStock.html's "flex:0 0 320px",
     users.html's "min-width:420px") for desktop's side-by-side layout.
     Inline styles always beat an external stylesheet rule regardless of
     selector, so without !important these would keep forcing a column
     wider than the screen on a phone even after flex-direction switches to
     column above - the classic cause of a page that scrolls sideways on
     mobile. */
  .model-col, .po-form-col, .po-table-col, .column {
    flex: 1 1 auto !important;
    width: 100% !important;
    min-width: 0 !important;
  }
}

/* ============================================================
   Cards, rows, lists
   ============================================================ */
.cs-po-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-4) var(--space-4);
  margin-bottom: var(--space-3);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  border: 1px solid transparent;
  transition: transform var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) ease;
}

.cs-po-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--color-border);
  transform: translateY(-1px);
}

.cs-po-card:active { transform: translateY(0); }

.cs-po-card-main .cs-po-number { font-weight: 700; font-size: 15px; }
.cs-po-card-main .muted { color: var(--color-muted-foreground); font-size: 13px; margin-top: 2px; }

.cs-po-card-sheets {
  text-align: right;
  font-size: 13px;
  color: var(--color-muted-foreground);
  white-space: nowrap;
}

.cs-po-card-sheets strong {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 19px;
  display: block;
  color: var(--color-accent);
}

.cs-po-summary {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-3);
}

.cs-po-summary .field-block label {
  font-size: 11px;
  color: var(--color-subtle-foreground);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: block;
}

.cs-po-summary .field-block div {
  font-weight: 600;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   Tabs
   ============================================================ */
.cs-tabs {
  display: flex;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
  border-bottom: 1px solid var(--color-border);
  /* 3 tabs' worth of padded text ("Version History") doesn't reliably fit a
     narrow phone screen - scroll the tab strip itself sideways instead of
     letting it force the whole page to scroll horizontally. */
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.cs-tab-btn {
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 14px;
  color: var(--color-muted-foreground);
  border-radius: 0;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: color var(--duration-fast) ease, border-color var(--duration-fast) ease;
}

.cs-tab-btn:hover { color: var(--color-foreground); }

.cs-tab-btn.selected {
  color: var(--color-accent);
  border-bottom-color: var(--color-accent);
}

/* ============================================================
   Sheet cards / output rows (shared by Cutting Config + Cutting Stage)
   ============================================================ */
.cs-sheet-card, .sheet-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  margin-bottom: var(--space-4);
  transition: border-color var(--duration-base) ease, background-color var(--duration-base) ease;
}

.cs-sheet-card.done {
  border-color: var(--color-success);
  background: var(--color-success-soft);
}

.cs-sheet-done-label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
}

.cs-sheet-done-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--color-success);
}

.cs-sheet-total-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  font-size: 12px;
  color: var(--color-muted-foreground);
  margin-bottom: var(--space-2);
  font-variant-numeric: tabular-nums;
}

.cs-actual-cut-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  color: var(--color-primary);
}

.cs-actual-cut-input {
  width: 60px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.cs-actual-cut-locked {
  font-weight: 700;
  color: var(--color-primary);
}

.cs-actual-cut-save-btn {
  padding: 3px 10px;
  font-size: 12px;
}

.cs-actual-cut-save-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.cs-output-row, .output-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
  flex-wrap: wrap;
}

.cs-output-row select, .output-row select { flex: 1; min-width: 120px; }
.cs-output-row input[type="text"] { flex: 1; min-width: 100px; }
.cs-output-row input[type="number"], .output-row input[type="number"] { width: 74px; font-variant-numeric: tabular-nums; }
.cs-output-row input.cs-part-size-input[type="text"] { flex: none; width: 100px; min-width: 0; }

.cs-output-total {
  font-size: 12px;
  color: var(--color-subtle-foreground);
  white-space: nowrap;
  min-width: 70px;
  font-variant-numeric: tabular-nums;
}

/* "What comes out of this sheet" - shown under every Sheets Required line
   on the PO form. */
.sheet-parts-summary {
  font-size: 12px;
  color: var(--color-muted-foreground);
  margin: -4px 0 var(--space-2) 0;
}

/* Informational-only "already in leftover stock" note under an output row -
   never blocks or changes the row above it, so it's deliberately quieter
   than an alert-banner. */
.leftover-note {
  font-size: 12px;
  color: var(--color-muted-foreground);
  margin: -4px 0 var(--space-2) var(--space-2);
  font-style: italic;
}

/* Multi-yield toggle under an output row */
.multi-yield-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin: 0 0 var(--space-3) var(--space-4);
  padding-left: var(--space-2);
  border-left: 2px solid var(--color-border);
}
.multi-yield-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--color-muted-foreground);
  cursor: pointer;
}
.multi-yield-row input[type="number"] { font-variant-numeric: tabular-nums; }

/* Multi-yield guidance / decision block in Cutting Stage + PO form */
.my-guidance {
  font-size: 12.5px;
  background: var(--color-accent-soft);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  margin: var(--space-2) 0;
  color: var(--color-foreground);
}
.my-decision {
  border: 1px solid var(--color-warning-border);
  background: var(--color-warning-soft);
  border-radius: var(--radius-sm);
  padding: 10px;
  margin: var(--space-2) 0;
}
.my-decision p { margin: 0 0 var(--space-2); font-size: 12.5px; color: var(--color-warning-text); }
.my-decision-btns { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.my-decision-btns button { font-size: 12px; padding: 6px 10px; }
.my-pending-chip {
  display: inline-block;
  background: var(--color-warning-soft);
  color: var(--color-warning-text);
  border: 1px solid var(--color-warning-border);
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 9px;
  margin-top: 4px;
}
.stock-warn {
  color: var(--color-destructive);
  font-weight: 600;
}

.sheet-dims { display: flex; gap: var(--space-2); align-items: center; margin-bottom: var(--space-3); flex-wrap: wrap; }
.sheet-dims input { width: 82px; font-variant-numeric: tabular-nums; }
.sheet-dims-label { font-size: 12px; color: var(--color-subtle-foreground); margin-right: 2px; }

.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-2);
}

.sheet-title { font-weight: 700; font-size: 13px; color: var(--color-muted-foreground); }

/* ============================================================
   Version history
   ============================================================ */
.cs-version-row {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-3);
  transition: border-color var(--duration-fast) ease, background-color var(--duration-fast) ease;
}

.cs-version-row.active {
  border-color: var(--color-accent);
  background: var(--color-accent-soft);
}

.cs-version-row-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.cs-version-actions { display: flex; gap: var(--space-2); align-items: center; }

.cs-version-preview {
  margin-top: var(--space-3);
  font-size: 13px;
  background: var(--color-surface-muted);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  animation: fadeIn var(--duration-base) var(--ease-out) both;
}

/* ============================================================
   Extras
   ============================================================ */
.cs-extra-forms {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--space-4);
}

.cs-extra-form-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}

.cs-extra-row {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 10px var(--space-4);
  margin-bottom: var(--space-2);
  font-size: 13px;
}

.cs-extra-row .cs-extra-type {
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--color-accent);
}

.cs-extra-row .cs-extra-time { color: var(--color-subtle-foreground); font-size: 12px; float: right; }

/* ============================================================
   Modal
   ============================================================ */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: var(--space-5);
}

.modal-box {
  background: var(--color-surface);
  border-radius: 12px;
  padding: var(--space-5);
  max-width: 480px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-box h3 { margin: 0 0 6px; font-size: 17px; }

.modal-actions { display: flex; gap: var(--space-3); margin-top: var(--space-4); }
.modal-actions button { flex: 1; }

/* ============================================================
   Order form / tables
   ============================================================ */
.field-row { display: flex; flex-direction: column; gap: var(--space-1); margin-bottom: var(--space-3); }

.field-row label { font-size: 12px; font-weight: 600; color: var(--color-muted-foreground); }

.field-row input:read-only {
  background: var(--color-surface-muted);
  color: var(--color-muted-foreground);
  cursor: default;
}

/* Actionable, not a warning - "here's something helpful to do" rather than
   "something's wrong", so a distinct blue tone from .alert-banner's amber. */
.leftover-action-banner {
  background: var(--color-accent-soft);
  border: 1px solid var(--color-accent);
  color: var(--color-primary);
  padding: 10px var(--space-3);
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: var(--space-3);
}

.alert-banner {
  background: var(--color-warning-soft);
  border: 1px solid var(--color-warning-border);
  color: var(--color-warning-text);
  padding: 10px var(--space-3);
  border-radius: var(--radius-md);
  font-size: 13px;
  margin-bottom: var(--space-3);
  animation: fadeInUp var(--duration-base) var(--ease-out) both;
}

.sheets-required-box {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  margin-bottom: var(--space-3);
  background: var(--color-surface-muted);
  animation: fadeIn var(--duration-base) var(--ease-out) both;
}

.po-sheet-qty-input {
  width: 56px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.sheets-required-table, .po-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.sheets-required-table td, .sheets-required-table th,
.po-table th, .po-table td {
  padding: 8px 6px;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}

.sheets-required-table tr.total-row td {
  font-weight: 700;
  border-top: 2px solid var(--color-border-strong);
  border-bottom: none;
}

.po-table { font-size: 14px; }

.po-table th {
  color: var(--color-muted-foreground);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
}

.po-table tbody tr {
  transition: background-color var(--duration-fast) ease;
}

.po-table tbody tr:hover { background: var(--color-surface-muted); }

/* ============================================================
   Plans bar (Cutting Configuration)
   ============================================================ */
.plans-bar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 10px var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.plans-bar-label { font-size: 13px; font-weight: 600; color: var(--color-muted-foreground); }

.plans-list { display: flex; gap: var(--space-2); flex-wrap: wrap; }

.plan-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 6px 6px 12px;
  border-radius: var(--radius-full);
  background: var(--color-surface-muted);
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: background-color var(--duration-fast) ease, border-color var(--duration-fast) ease, transform var(--duration-fast) ease;
}

.plan-pill:hover { background: #e4e8ee; }
.plan-pill:active { transform: scale(0.97); }

.plan-pill.selected {
  background: var(--color-accent-soft);
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.plan-pill .icon-btn { font-size: 14px; padding: 0 4px; }

/* ============================================================
   Sticky save/action bars
   ============================================================ */
.save-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 10px var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  backdrop-filter: blur(6px);
}

/* ============================================================
   Cutting Configuration columns
   ============================================================ */
.model-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px var(--space-3);
  border-radius: var(--radius-md);
  cursor: pointer;
  margin-bottom: 4px;
  border: 1px solid transparent;
  transition: background-color var(--duration-fast) ease, border-color var(--duration-fast) ease;
}

.model-row:hover { background: var(--color-surface-muted); }

.model-row.selected {
  background: var(--color-accent-soft);
  border-color: var(--color-accent);
}

.model-row-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.part-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--color-border);
}

.part-row-name { flex: 1; font-weight: 600; font-size: 14px; }
.part-row input[type="number"] { width: 74px; font-variant-numeric: tabular-nums; }
.part-row-size { width: 130px; font-size: 13px; color: var(--color-muted-foreground); }

/* ============================================================
   Buttons & inputs
   ============================================================ */
.icon-btn {
  border: none;
  background: transparent;
  color: var(--color-destructive);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  line-height: 1;
  transition: background-color var(--duration-fast) ease, transform var(--duration-fast) ease;
}

.icon-btn:hover { background: var(--color-destructive-soft); }
.icon-btn:active { transform: scale(0.92); }

.add-row { display: flex; gap: var(--space-2); margin-bottom: var(--space-3); }
.add-row input { flex: 1; min-width: 0; }

input, select {
  padding: 9px 11px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  background: var(--color-surface);
  color: var(--color-foreground);
  transition: border-color var(--duration-fast) ease, box-shadow var(--duration-fast) ease;
}

input:hover, select:hover { border-color: #c4cad3; }

input:focus-visible, select:focus-visible {
  border-color: var(--color-ring);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.15);
  outline: none;
}

input::placeholder { color: var(--color-subtle-foreground); }

input:disabled, select:disabled, button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  transition: background-color var(--duration-fast) ease, transform var(--duration-fast) ease,
    box-shadow var(--duration-fast) ease, opacity var(--duration-fast) ease;
}

button:active:not(:disabled) { transform: scale(0.97); }

.btn-primary {
  background: var(--color-accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) { background: var(--color-accent-hover); box-shadow: var(--shadow-sm); }

.btn-secondary {
  background: #e8eaee;
  color: var(--color-foreground);
}

.btn-secondary:hover:not(:disabled) { background: #d9dde3; }

.btn-danger {
  background: var(--color-destructive);
  color: #fff;
}

.btn-danger:hover:not(:disabled) { background: #b91c1c; }

.btn-block { width: 100%; }

/* ============================================================
   Misc utility
   ============================================================ */
.empty-state {
  color: var(--color-subtle-foreground);
  font-size: 14px;
  padding: 28px 0;
  text-align: center;
  animation: fadeIn var(--duration-base) var(--ease-out) both;
}

.save-status {
  font-size: 13px;
  color: var(--color-subtle-foreground);
  margin-left: var(--space-2);
  transition: color var(--duration-fast) ease;
}

.save-status.saving { color: var(--color-warning-text); }
.save-status.error { color: var(--color-destructive); font-weight: 600; }
.save-status.dirty { color: var(--color-warning-text); font-weight: 600; }

.section-hint { font-size: 12px; color: var(--color-subtle-foreground); margin-bottom: var(--space-3); }

.section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--color-muted-foreground);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: var(--space-4) 0 var(--space-2);
}

.muted { color: var(--color-muted-foreground); }

@media (max-width: 640px) {
  .mobile-topbar { padding: var(--space-3); }
  .cs-dashboard, .cs-detail { padding: var(--space-3); }
  .cs-po-card { flex-direction: column; align-items: flex-start; }
  .cs-po-card-sheets { text-align: left; }

  /* iOS Safari auto-zooms the whole page on focusing any input/select
     under 16px - jarring on a form-heavy app like this one where almost
     every screen has several fields. 16px avoids it; the desktop 14px is
     kept as-is since this only matters on a touchscreen. */
  input, select {
    font-size: 16px;
  }
}

@media (max-width: 900px) {
  /* Bigger touch targets for the small "x" remove buttons used throughout
     (remove sheet/output/model/plan/user) - 24x24px is workable with a
     mouse pointer but easy to miss or mis-tap with a finger. */
  .icon-btn {
    padding: 8px 10px;
    font-size: 18px;
  }

  /* Defensive: a couple of flex rows that pair a label/id with a
     right-aligned value (dashboard activity rows, PO card headers) had no
     wrap fallback - harmless on desktop's wide viewport, but a long PO
     number/model name next to a timestamp can run out of room on a phone. */
  .dash-row {
    flex-wrap: wrap;
  }
}
