/* Executive dashboard — 6 row-blocks of cards */
@layer screens {
  .dash { display: flex; flex-direction: column; gap: 14px; }
  .dash-row { display: flex; gap: 14px; flex-wrap: wrap; align-items: stretch; }
  .dash-card { border-radius: 13px; padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
  .card-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
  .card-head .odetail-label { margin-bottom: 0; }
  .view-all { margin-left: auto; color: var(--primary); font-size: 12px; font-weight: 600; }
  .danger-text { color: var(--danger-fg); }
  .ok-text { color: var(--ok-fg); }

  /* Row 1 — KPI tiles */
  .dash-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
  .kpi-tile {
    background: var(--surface); border: 1px solid var(--line); border-radius: 13px;
    padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; text-decoration: none; color: var(--text);
  }
  .kpi-tile.click:hover { box-shadow: 0 2px 12px rgba(20, 35, 60, 0.09); text-decoration: none; }
  .kpi-label { font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
  .kpi-num { font-size: 24px; font-weight: 700; }
  .kpi-unit { font-size: 14px; font-weight: 600; color: var(--muted); }
  .kpi-sub { font-size: 12px; color: var(--muted); }

  /* Row 2a — calendar */
  .cal-card { flex: 1.1 1 430px; }
  .cal-dows { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
  .cal-dows span { font-size: 10.5px; font-weight: 700; color: var(--muted); text-align: center; }
  .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
  .cal-cell {
    min-height: 76px; border: 1.5px solid var(--line); border-radius: 9px; padding: 6px 8px;
    display: flex; flex-direction: column; gap: 2px; text-decoration: none; color: var(--text);
    background: var(--surface);
  }
  .cal-cell.active { background: var(--primary-soft); border-color: var(--primary-border); }
  .cal-cell.today { border-color: var(--primary); }
  .cal-cell:hover { text-decoration: none; border-color: var(--primary); }
  .cal-day { font-size: 11px; font-weight: 700; }
  .cal-trucks { font-size: 10.5px; font-weight: 700; color: var(--rail); }
  .cal-stops { font-size: 10.5px; color: var(--text-2); }
  .cal-value { font-size: 10px; font-weight: 700; color: var(--primary); }

  /* Row 2b — live map */
  .live-card { flex: 2 1 460px; }
  .live-date { font-size: 11px; font-weight: 700; color: var(--primary); }
  .live-legend { display: flex; flex-wrap: wrap; gap: 6px; }
  .legend-chip { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 2px 9px; font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--text-2); }
  .legend-dot { width: 8px; height: 8px; border-radius: 50%; }
  .live-map { flex: 1; min-height: 250px; border-radius: 11px; }
  .empty-map { display: grid; place-items: center; text-align: center; color: var(--muted); font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--line); padding: 20px; }

  /* Row 2b — today's dispatch orders + delivery status (replaces live map) */
  .dispatch-sub { font-size: 11.5px; color: var(--muted); margin: 2px 0 6px; }
  .dispatch-unmatched { color: var(--urgent, #c0392b); font-weight: 700; text-decoration: none; }
  .dispatch-list { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; max-height: 270px; }
  .dispatch-row { display: grid; grid-template-columns: 1fr auto auto 20px; align-items: center; gap: 8px; padding: 6px 9px; border-radius: 8px; text-decoration: none; color: var(--text); font-size: 12.5px; border: 1px solid transparent; }
  .dispatch-row:hover { background: var(--surface-2); border-color: var(--line); }
  .dispatch-row.done { color: var(--text-2); }
  .dispatch-cust { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .dispatch-qty { font-size: 11.5px; color: var(--text-2); }
  .dispatch-status { font-size: 11.5px; font-weight: 600; white-space: nowrap; }
  .dispatch-row.done .dispatch-status { color: var(--ok, #2e9e5b); }
  .dispatch-proof { text-align: center; }

  /* Row 2c — metrics */
  .metrics-card { flex: 1 1 280px; }
  .metric-bar { height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
  /* the fill % is the only dynamic bit — passed in via the --w custom property */
  .metric-fill { height: 100%; width: var(--w, 0); background: var(--ok); }
  .metric-fill.blue { background: #4a92cc; }
  .metric-rows { display: flex; flex-direction: column; }
  .metric-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 6px 2px; border-bottom: 1px solid var(--line); font-size: 13px; color: var(--text-2); }
  .metric-row span.mono { font-size: 14px; font-weight: 700; color: var(--text); }

  /* Row 3a — demand forecast (7 days actual + 7 days forecast) */
  .demand-card { flex: 2 1 460px; }
  .demand-chart { display: flex; align-items: flex-end; gap: 3px; padding: 14px 2px 0; min-height: 116px; }
  .demand-col { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 3px; padding: 2px 1px; border-radius: 7px; }
  .demand-col.is-today { background: var(--primary-soft); }
  .demand-val { font-size: 9.5px; font-weight: 700; color: var(--muted); height: 12px; line-height: 12px; }
  /* the bar height is the only dynamic bit — passed in via the --h custom property */
  .demand-bar { width: 78%; max-width: 20px; min-height: 2px; height: var(--h, 2px); border-radius: 4px 4px 0 0; }
  .demand-bar.actual { background: var(--primary); }
  .demand-bar.forecast {
    background: repeating-linear-gradient(45deg, color-mix(in oklch, var(--primary) 45%, transparent) 0 4px, transparent 4px 7px);
    border: 1.5px dashed color-mix(in oklch, var(--primary) 60%, transparent);
  }
  .demand-x { font-size: 9.5px; color: var(--muted); white-space: nowrap; }
  .demand-col.is-today .demand-x { font-weight: 800; color: var(--primary); }
  .demand-legend { display: flex; align-items: center; gap: 14px; margin-top: 8px; font-size: 11px; color: var(--muted); }
  .demand-legend .spacer { flex: 1; }
  .dl-key { display: inline-flex; align-items: center; gap: 5px; }
  .dl-key::before { content: ""; width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
  .dl-key.actual::before { background: var(--primary); }
  .dl-key.forecast::before { background: repeating-linear-gradient(45deg, color-mix(in oklch, var(--primary) 45%, transparent) 0 3px, transparent 3px 5px); border: 1px dashed color-mix(in oklch, var(--primary) 60%, transparent); }

  /* Row 3b — pipeline */
  .pipe-card { flex: 1 1 280px; }
  .pipe-row { display: flex; align-items: center; gap: 10px; padding: 9px 11px; border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px; text-decoration: none; color: var(--text); }
  .pipe-row:hover { border-color: var(--primary-border); text-decoration: none; }
  .pipe-dot { width: 9px; height: 9px; border-radius: 50%; }
  .pipe-dot.pill-new { background: var(--st-new-fg); }
  .pipe-dot.pill-verified { background: var(--st-verified-fg); }
  .pipe-dot.pill-planned { background: var(--st-planned-fg); }
  .pipe-dot.pill-delivered { background: var(--st-delivered-fg); }
  .pipe-name { font-size: 13.5px; font-weight: 600; }
  .pipe-count { margin-left: auto; font-size: 15px; font-weight: 700; }

  /* Row 4 — factory floor */
  .factory-card { flex: 1 1 100%; gap: 12px; }
  .factory-sub-label { font-size: 13px; font-weight: 600; color: var(--text-2); }
  .machine-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); gap: 10px; }
  .machine-tile { border: 1.5px solid var(--line); border-radius: 11px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
  .machine-tile.state-running { border-color: var(--ok); background: var(--ok-bg); }
  .machine-tile.state-setup { border-color: var(--warn); background: var(--warn-bg); }
  .machine-tile.state-idle { opacity: 0.7; }
  .machine-top { display: flex; align-items: center; gap: 7px; }
  .machine-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); }
  .machine-no { font-size: 12.5px; font-weight: 600; }
  .machine-st { margin-left: auto; font-size: 11px; font-weight: 700; color: var(--text-2); }
  .machine-bottle { font-size: 13.5px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .machine-qty { font-size: 14px; }
  .stage-divider { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; }
  .stage-arrow { font-size: 15px; font-weight: 700; color: var(--muted); }
  .stage-label { font-size: 12px; font-weight: 700; color: var(--text-2); }
  .room-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 10px; }
  .room-tile { border: 1.5px solid var(--line); border-radius: 11px; padding: 11px 13px; display: flex; flex-direction: column; gap: 6px; }
  .room-tile.closed { opacity: 0.7; }
  .room-tile.open { border-color: var(--primary-border); }
  .room-total { font-size: 16px; }
  .room-run { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--text-2); }

  /* Row 4b/5 — list rows */
  .list-row { display: flex; align-items: baseline; gap: 8px; padding: 7px 2px; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--text); }
  .list-row:hover { text-decoration: none; }
  .list-name { font-size: 13px; font-weight: 600; }
  .list-meta { font-size: 12px; color: var(--muted); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .top-cust { display: flex; flex-direction: column; gap: 4px; padding: 4px 0; text-decoration: none; color: var(--text); }
  .top-cust-head { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
  .alert-row { display: flex; align-items: center; gap: 10px; padding: 9px 11px; border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px; }
  .alert-label { font-size: 13px; color: var(--text-2); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* Production staff chip cards */
@layer screens {
  .staff-cards { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
  .staff-card { flex: 1 1 280px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
  .staff-chips { display: flex; flex-wrap: wrap; gap: 6px; }
  .staff-chip { display: inline-flex; align-items: center; gap: 5px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-pill); padding: 4px 11px; font-size: 12.5px; font-weight: 600; }
  .staff-chip::before { content: "👤"; font-size: 11px; }
  .staff-shifts { display: flex; flex-wrap: wrap; gap: 6px; }
}
