/* ============================================================
 * Operations Insights — backlog, ageing, throughput, filing deadlines.
 *
 * Two colour jobs, kept apart on purpose:
 *
 *   Ageing     ordered magnitude, so one hue stepped light to dark. The order
 *              is carried by lightness, which survives any colour vision and
 *              prints legibly. Verified monotonic in OKLab L.
 *   Filing     state, so the reserved status steps — and never colour alone:
 *              every band is a tinted pill with its name in it, so the hue
 *              reinforces a label rather than replacing one. Text takes an ink
 *              token, which is why the tint can be light without hurting
 *              contrast.
 *
 * Counts are numbers, not charts: a backlog of 40 reads faster as "40" than
 * as a bar somebody has to measure against an axis.
 *
 * Markup: frontend/templates/index.html (#view-operations-insights)
 * Behaviour: frontend/static/js/operations-insights.js
 * ============================================================ */

:root {
  /* Sequential — ageing. Light to dark, monotonic in lightness. */
  --oi-age-1: #dce9e6;
  --oi-age-2: #aecdc8;
  --oi-age-3: #7cb0a9;
  --oi-age-4: #43908a;
  --oi-age-5: #1a5c3a;
  --oi-age-ink: #25231b;

  /* Status — filing urgency. Fixed steps, used as tints behind ink text. */
  --oi-lost:     #d03b3b;
  --oi-critical: #ec835a;
  --oi-urgent:   #fab219;
  --oi-watch:    #6b6961;
  --oi-ok:       #0ca30c;
  --oi-lost-bg:     #f7e0e0;
  --oi-critical-bg: #fbe6dc;
  --oi-urgent-bg:   #fdf0d2;
  --oi-watch-bg:    #eceae4;
  --oi-ok-bg:       #d9eed9;
}

[data-theme="dark"] {
  --oi-age-1: #20423f;
  --oi-age-2: #2c5a57;
  --oi-age-3: #3a7a76;
  --oi-age-4: #4f98a3;
  --oi-age-5: #7fc0c8;
  --oi-age-ink: #e0dfdc;

  --oi-lost-bg:     #3d1f1f;
  --oi-critical-bg: #3a261d;
  --oi-urgent-bg:   #3a2f16;
  --oi-watch-bg:    #26251f;
  --oi-ok-bg:       #1b3320;
}

/* ---- scope bar -------------------------------------------------------- */

.oi-scope {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
  padding: 15px 17px;
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}
.oi-field { display: block; min-width: 0; }
.oi-field > span {
  display: block;
  font-size: calc(10px * var(--ui-font-scale, 1)); text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-muted); font-weight: 600; margin-bottom: 4px;
}
.oi-wide { grid-column: 1 / -1; }
.oi-input {
  width: 100%; padding: 7px 9px;
  font-family: inherit; font-size: calc(12px * var(--ui-font-scale, 1));
  color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.oi-input:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

/* ---- headline figures ------------------------------------------------- */

.oi-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 11px;
  margin-bottom: 16px;
}
.oi-tile {
  padding: 13px 15px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}
.oi-tile-label {
  display: block;
  font-size: calc(10px * var(--ui-font-scale, 1)); text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-muted); font-weight: 600;
}
.oi-tile-value {
  display: block; margin-top: 4px;
  font-size: calc(25px * var(--ui-font-scale, 1)); font-weight: 600; line-height: 1.1;
  font-variant-numeric: tabular-nums; color: var(--text);
}
.oi-tile-note {
  display: block; margin-top: 2px;
  font-size: calc(10.5px * var(--ui-font-scale, 1)); color: var(--text-faint);
}
/* The one tile that is an alarm rather than a number gets the status step. */
.oi-tile.is-alarm { border-left: 3px solid var(--oi-lost); }
.oi-tile.is-alarm .oi-tile-value { color: var(--oi-lost); }

/* ---- cards ------------------------------------------------------------ */

.oi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 15px 17px;
  margin-bottom: 16px;
}
.oi-card-head {
  display: flex; flex-wrap: wrap; align-items: center; gap: 9px;
  margin-bottom: 13px;
}
.oi-card-head h3 {
  margin: 0; font-size: calc(13px * var(--ui-font-scale, 1)); font-weight: 600; color: var(--text);
}
.oi-spacer { flex: 1 1 auto; }
.oi-hint { font-size: calc(11px * var(--ui-font-scale, 1)); color: var(--text-muted); }
.oi-empty {
  margin: 0; padding: 16px 0; text-align: center;
  font-size: calc(12px * var(--ui-font-scale, 1)); color: var(--text-muted);
}

/* ---- filing bands ----------------------------------------------------- */

.oi-bands { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }

.oi-band {
  display: inline-flex; align-items: baseline; gap: 7px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
}
.oi-band b {
  font-size: calc(15px * var(--ui-font-scale, 1)); font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.oi-band span { font-size: calc(11px * var(--ui-font-scale, 1)); font-weight: 600; letter-spacing: .02em; }
/* The tint carries the state; the text stays ink, so contrast is the text
   token's and the hue never has to carry meaning on its own. */
.oi-band-lost     { background: var(--oi-lost-bg);     color: var(--text); border-color: var(--oi-lost); }
.oi-band-critical { background: var(--oi-critical-bg); color: var(--text); }
.oi-band-urgent   { background: var(--oi-urgent-bg);   color: var(--text); }
.oi-band-watch    { background: var(--oi-watch-bg);    color: var(--text); }
.oi-band-ok       { background: var(--oi-ok-bg);       color: var(--text); }
.oi-band-unknown  { background: var(--surface-2); color: var(--text-muted);
                    border-color: var(--divider); }

.oi-dot {
  width: 8px; height: 8px; border-radius: 999px; flex: 0 0 auto;
  display: inline-block;
}
.oi-dot-lost { background: var(--oi-lost); }
.oi-dot-critical { background: var(--oi-critical); }
.oi-dot-urgent { background: var(--oi-urgent); }
.oi-dot-watch { background: var(--oi-watch); }
.oi-dot-ok { background: var(--oi-ok); }
.oi-dot-unknown { background: var(--text-faint); }

/* ---- ageing bars ------------------------------------------------------ */

.oi-stage { margin-bottom: 14px; }
.oi-stage:last-child { margin-bottom: 0; }
.oi-stage-head {
  display: flex; align-items: baseline; gap: 9px; margin-bottom: 5px;
}
.oi-stage-name {
  font-size: calc(12px * var(--ui-font-scale, 1)); font-weight: 600; text-transform: capitalize;
}
.oi-stage-meta {
  font-size: calc(10.5px * var(--ui-font-scale, 1)); color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.oi-bar {
  display: flex;
  height: 22px;
  border-radius: 3px;
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--divider);
}
/* A 2px surface gap between segments, so adjacent steps of one hue stay
   countable rather than reading as one long block. */
.oi-seg + .oi-seg { margin-left: 2px; }
.oi-seg {
  display: grid; place-items: center;
  font-size: calc(10px * var(--ui-font-scale, 1)); font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--oi-age-ink);
  min-width: 0; overflow: hidden;
  cursor: default;
}
.oi-seg-1 { background: var(--oi-age-1); }
.oi-seg-2 { background: var(--oi-age-2); }
.oi-seg-3 { background: var(--oi-age-3); }
.oi-seg-4 { background: var(--oi-age-4); color: #fff; }
.oi-seg-5 { background: var(--oi-age-5); color: #fff; }
[data-theme="dark"] .oi-seg-4,
[data-theme="dark"] .oi-seg-5 { color: #10201f; }

.oi-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.oi-legend-item {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: calc(10px * var(--ui-font-scale, 1)); color: var(--text-muted);
}
.oi-swatch {
  width: 11px; height: 11px; border-radius: 2px;
  border: 1px solid rgba(0,0,0,.08);
}

/* ---- tables ----------------------------------------------------------- */

.oi-table-wrap { overflow-x: auto; }
.oi-table { width: 100%; border-collapse: collapse; font-size: calc(12px * var(--ui-font-scale, 1)); }
.oi-table th {
  padding: 7px 10px 7px 0; text-align: left; white-space: nowrap;
  font-size: calc(10px * var(--ui-font-scale, 1)); text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-muted); font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.oi-table td {
  padding: 8px 10px 8px 0; color: var(--text);
  border-bottom: 1px solid var(--divider); vertical-align: middle;
}
.oi-table tr:last-child td { border-bottom: none; }
.oi-num { text-align: right; padding-right: 0; font-variant-numeric: tabular-nums; }
.oi-faint { color: var(--text-faint); }
.oi-mono {
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: calc(11px * var(--ui-font-scale, 1));
}

.oi-days { font-weight: 700; font-variant-numeric: tabular-nums; }
.oi-days.is-lost { color: var(--oi-lost); }

.oi-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 999px;
  font-size: calc(10px * var(--ui-font-scale, 1)); font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--divider);
  color: var(--text);
}

.oi-limit-input {
  width: 72px; padding: 4px 7px;
  font-family: inherit; font-size: calc(11.5px * var(--ui-font-scale, 1));
  text-align: right; font-variant-numeric: tabular-nums;
  color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}

@media (max-width: 700px) {
  .oi-scope { grid-template-columns: 1fr; }
  .oi-tiles { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
}
