/* kpi.css — Fleet Ops operations dashboard (components/tabs/fleet.mjs) + its print/PDF report.
   Builds on app.css tokens (--surface*, --border, --text*, --accent, --radius*) and its .ss-card /
   .kpi-tiles / .kpi-tile / .fleet-winbar / .fleet-win classes. Kept in its own file so the shared
   app.css stays conflict-free. */

.ops-wrap { max-width: 1400px; min-width: 0; }
.ops-wrap > * { min-width: 0; }
.ops-wrap .ss-card { margin-bottom: 0; min-width: 0; }
.ops-body { display: flex; flex-direction: column; gap: 12px; transition: opacity .2s; }
.ops-body.stale { opacity: .55; }
/* placeholders render() swaps content into: no box of their own (no extra flex gap when empty) */
.ops-slot { display: contents; }
.rk-body { transition: opacity .2s; }
.rk-body.stale { opacity: .55; }

/* header */
.ops-head { align-items: flex-end; }
.ops-title { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; min-width: 0; }
.ops-title h3 { margin: 0; font-size: 1.15rem; }
.ops-sub { font-size: .78rem; color: var(--text-muted); }
.ops-export { display: flex; gap: 6px; flex-wrap: wrap; }
.ops-exp-btn { min-height: var(--ctl-h); padding: 6px 14px; font-size: var(--ctl-font); }

/* filter bar */
.ops-filters { display: flex; flex-direction: column; gap: 10px; }
.ops-filter-row { display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; min-width: 0; }
.ops-flabel { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); width: 64px; flex: 0 0 auto; }
.ops-seg { flex-wrap: wrap; }
.ops-seg .fleet-win { min-height: 30px; }
.ops-dates { display: flex; gap: 8px; flex-wrap: wrap; }
.ops-range-err { flex: 1 0 100%; margin: 0; font-size: .78rem; }
.ops-field input[aria-invalid="true"] { border-color: var(--danger, #e5484d); }
.ops-body.stale { transition: opacity .15s; }
.ops-field { display: inline-flex; align-items: center; gap: 6px; font-size: .78rem; color: var(--text-muted); }
/* the date / company fields are exactly as tall as the period buttons (30 px; 44 on touch), so picking
   Custom does not make the row grow */
#tab-root .ops-field input, #tab-root .ops-field select, #tab-root .ops-robot-find { font: inherit; font-size: .85rem; box-sizing: border-box; height: 30px; min-height: 30px;
  padding: 0 8px; line-height: normal; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; color-scheme: dark; max-width: 100%; }
.ops-chips { display: flex; gap: 6px; flex-wrap: wrap; min-width: 0; }
/* robots: search (many robots) + chips; with a big fleet the chips scroll inside ~3 rows instead of
   pushing the charts down */
.ops-robots { display: flex; flex-direction: column; gap: 8px; flex: 1 1 0; min-width: 0; }
.ops-robots .ops-chips { max-height: 112px; overflow-y: auto; overscroll-behavior: contain; padding: 1px; }
.ops-robot-find { font: inherit; font-size: .85rem; box-sizing: border-box; height: 30px; padding: 0 10px; width: min(260px, 100%);
  color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; }
.ops-robot-find[hidden] { display: none; }
.ops-company-row[hidden] { display: none; }
.ops-robots-row { align-items: flex-start; }
.ops-robots-row > .ops-flabel { line-height: 30px; }
.ops-company-row select { min-width: 180px; }
.ops-chip { font: inherit; font-size: 12px; display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 4px 11px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-muted); cursor: pointer; }
.ops-chip.on { border-color: var(--accent); color: var(--text); background: color-mix(in srgb, var(--accent) 16%, var(--surface-2)); }
.ops-chip:focus-visible, .fleet-win:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.ops-swatch { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; display: inline-block; }

/* tiles */
.ops-tiles { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); }
@media (min-width: 900px) { .ops-tiles { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.ops-tile { display: flex; flex-direction: column; justify-content: center; min-width: 0; }
.ops-tile .kpi-value { font-size: 1.3rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ops-tile .kpi-note { display: block; font-size: .68rem; color: var(--text-muted); margin-top: 2px; }

/* chart */
.ops-chart .fleet-head { margin-bottom: 6px; }
.ops-chart-box { width: 100%; }
.ops-chart-svg { width: 100%; height: auto; display: block; max-height: 300px; }
.ops-chart-svg .ops-hit { cursor: pointer; }
.ops-chart-svg .ops-bar:hover rect:not(.ops-hit), .ops-chart-svg .ops-bar.sel rect:not(.ops-hit) { filter: brightness(1.15); }
.ops-chart-svg .ops-bar.sel .ops-hit { fill: color-mix(in srgb, var(--text) 7%, transparent); }
.ops-chart-foot { display: flex; justify-content: space-between; align-items: center; gap: 6px 14px; flex-wrap: wrap; margin-top: 6px; }
.ops-legend { display: flex; gap: 4px 12px; flex-wrap: wrap; font-size: .75rem; }
.ops-key { display: inline-flex; align-items: center; gap: 5px; }
.ops-readout { font-size: .75rem; color: var(--text-muted); font-variant-numeric: tabular-nums; min-width: 0; }
.ops-note { font-size: .75rem; color: var(--text-muted); margin: 8px 0 0; }

/* tables */
.ops-table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.ops-table { width: 100%; border-collapse: collapse; font-size: .82rem; font-variant-numeric: tabular-nums; }
.ops-table th, .ops-table td { padding: 7px 8px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
.ops-table thead th { font-size: .66rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); font-weight: 600; }
.ops-table th:first-child { text-align: left; }
.ops-table tbody th { font-weight: 600; display: table-cell; }
.ops-table tbody th .ops-swatch { margin-right: 6px; vertical-align: -1px; }
.ops-table tfoot th, .ops-table tfoot td { font-weight: 700; border-bottom: 0; background: var(--surface-2); }
.ops-table tfoot th { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.ops-table tfoot td:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.ops-table tr.approx td { color: var(--text-muted); }
.ops-est { font-size: .65rem; font-weight: 500; color: var(--warn); margin-left: 6px; }

/* pending (not measured) */
.ops-pending { opacity: .85; }
.ops-pending-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.ops-pill { font-size: .72rem; padding: 3px 9px; border-radius: 999px; border: 1px dashed var(--border); color: var(--text-muted); }

@media (max-width: 1100px) {
  .ops-table th, .ops-table td { padding: 6px 4px; }
  .ops-table thead th { font-size: .6rem; letter-spacing: .02em; }
}
/* narrow screens: tables become a list of cards (no sideways scrolling) */
@media (max-width: 760px) {
  .ops-table thead { display: none; }
  .ops-table, .ops-table tbody, .ops-table tfoot, .ops-table tr { display: block; width: 100%; }
  .ops-table tr { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 2px 10px; padding: 10px 4px;
    border-bottom: 1px solid var(--border); }
  .ops-table th, .ops-table td { border: 0; padding: 2px 0; text-align: left; white-space: normal; }
  .ops-table tbody th, .ops-table tfoot th { grid-column: 1 / -1; font-size: .9rem; padding-bottom: 4px; }
  .ops-table td { display: flex; flex-direction: column; }
  .ops-table td::before { content: attr(data-label); font-size: .64rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
  .ops-table tfoot tr { border-radius: var(--radius-sm); background: var(--surface-2); padding: 10px; margin-top: 6px; }
  .ops-table tfoot th, .ops-table tfoot td { background: none; }
  .ops-table-wrap { overflow-x: visible; }
}
@media (max-width: 520px) {
  .ops-flabel { width: 100%; }
  .ops-head { align-items: flex-start; flex-direction: column; }
  .ops-export { width: 100%; }
  .ops-exp-btn { flex: 1 1 0; min-height: var(--tap); }
  .ops-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .ops-tile { padding: 10px 8px; }
  .ops-tile .kpi-value { font-size: 1.15rem; }
  .ops-seg .fleet-win, .ops-chip { min-height: 36px; }
  .ops-chart .fleet-head { flex-direction: column; align-items: flex-start; }
  .ops-table tr { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 2px 8px; }
  .ops-table td { font-size: .8rem; }
  .ops-table td::before { font-size: .58rem; }
  /* phones: the charging / recording columns live in the export and the Recording KPIs card */
  .ops-breakdown .ops-table [data-k="charging_h"], .ops-breakdown .ops-table [data-k="recording_sessions"],
  .ops-breakdown .ops-table [data-k="recording_h"] { display: none; }
  .ops-dates { width: 100%; }
  .ops-dates .ops-field { flex: 1 1 140px; }
  .ops-dates input { flex: 1 1 auto; min-width: 0; }
  .ops-company-row .ops-field, .ops-company-row select { flex: 1 1 auto; width: 100%; min-width: 0; }
  .ops-robot-find { width: 100%; }
}
/* touch screens (iPad, phones): 44 px targets */
@media (pointer: coarse) {
  .ops-seg .fleet-win, .rk-card .fleet-win, .ops-chip, .ops-exp-btn, .ops-field input, .ops-field select { min-height: 44px; }
  #tab-root .ops-field input, #tab-root .ops-field select, #tab-root .ops-robot-find { height: 44px; min-height: 44px; font-size: 16px; }
  .ops-robots .ops-chips { max-height: 150px; }
}
@media (max-width: 359px) {
  .ops-tiles { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .ops-tile .kpi-value { font-size: 1.05rem; }
  .ops-table tr { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ops-seg .fleet-win { padding: 5px 8px; }
}

/* ===================== print / PDF report (#ops-print, built by fleet.mjs printReport) ========== */
#ops-print { display: none; }
@media print {
  html.ops-printing, html.ops-printing body { background: #fff !important; color: #1b2430 !important; color-scheme: light;
    min-height: 0 !important; height: auto !important; overflow: visible !important; padding: 0 !important; margin: 0 !important; }
  html.ops-printing body > *:not(#ops-print) { display: none !important; }
  html.ops-printing #ops-print { display: block; }
  @page { size: A4; margin: 14mm 12mm; }
}
#ops-print { font: 10.5pt/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: #1b2430; background: #fff;
  -webkit-print-color-adjust: exact; print-color-adjust: exact; }
#ops-print h1 { font-size: 18pt; margin: 2px 0 0; font-weight: 700; }
#ops-print h2 { font-size: 11.5pt; margin: 0 0 6px; font-weight: 700; }
.opr-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; border-bottom: 2px solid #1b2430;
  padding-bottom: 8px; margin-bottom: 12px; }
.opr-brand { font-weight: 800; letter-spacing: .28em; font-size: 9pt; color: #2a78d6; }
.opr-meta { text-align: right; font-size: 8.5pt; color: #4a5565; }
.opr-tiles { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-bottom: 12px; }
.opr-tile { border: 1px solid #d9dee5; border-radius: 6px; padding: 6px 8px; break-inside: avoid; }
.opr-tile b { display: block; font-size: 13pt; font-variant-numeric: tabular-nums; }
.opr-tile span { display: block; font-size: 7.5pt; color: #4a5565; text-transform: uppercase; letter-spacing: .04em; }
.opr-tile i { display: block; font-size: 7.5pt; color: #4a5565; font-style: normal; }
.opr-sec { margin-bottom: 12px; break-inside: avoid; }
.opr-sec.opr-break { break-inside: auto; }
.opr-chart svg { width: 100%; height: auto; display: block; }
.opr-legend { display: flex; gap: 12px; font-size: 8pt; margin-top: 4px; }
.opr-sw { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.opr-table { width: 100%; border-collapse: collapse; font-size: 8pt; font-variant-numeric: tabular-nums; }
.opr-table th, .opr-table td { padding: 3px 5px; border-bottom: 1px solid #e3e7ec; text-align: right; white-space: nowrap; }
.opr-table th:first-child { text-align: left; }
.opr-table thead th { font-size: 7pt; text-transform: uppercase; letter-spacing: .04em; color: #4a5565; border-bottom: 1.5px solid #9aa8b8; }
/* the total is printed once, after the last row (a table-footer-group repeats on every page, which read as a page subtotal) */
.opr-table tfoot { display: table-row-group; }
.opr-table tfoot th, .opr-table tfoot td { font-weight: 700; border-top: 1.5px solid #9aa8b8; border-bottom: 0; }
.opr-table tr { break-inside: avoid; }
.opr-foot { margin-top: 10px; font-size: 7.5pt; color: #4a5565; border-top: 1px solid #d9dee5; padding-top: 6px; }
.opr-foot p { margin: 0 0 3px; }
