/* The LLM usage tab of the operator's area (js/admin-llm.js,
   js/admin-llm-chart.js, js/admin-llm-budget.js). Loaded by index.html
   after admin-ops.css. Only what the tab needs beyond app.css's shared
   parts: the stat cards, the chart, the model table's --cols and its fold
   into cards, and the budget's bars. Colours, spaces and type sizes are
   tokens from app.css or from the block below.

   The stat cards, wide (three a row; on a phone two):
     [ Calls        ][ Tokens in   ][ Tokens out ]
     [ Estimated ...][ p95 response][ Failure rate]

   The chart, in a grid of two columns and two rows (the words are HTML so
   they keep their size; the bars are an SVG stretched over its cell):
     [ y words ][ bars ................................ ]
     [         ][ day words ........................... ]

   A model row, wide:
     [ model .............. ][ calls ][ tokens in ][ tokens out ][ cost ]
   and folded into a card, when the table gets less than about 840px
   (the same limit as the other admin tables, and for the same reason):
     [ model                                                          ]
     [ Calls 12   Tokens in 1,000   Tokens out 500   Cost €0.05       ]

   A budget row: the name and its lamp, a bar with a notch at 80%, and
   the sentence "500,000 of 2,000,000 used today (25%)". */

:root {
  --llm-stat-min: 150px;           /* two cards a row on a phone */
  --llm-axis-width: 48px;          /* "20K" and "1.2M" */
  --llm-plot-height: 200px;
  --llm-column-count: 88px;
  --llm-column-tokens: 120px;      /* "1,134,567" */
  --llm-column-cost: 120px;        /* "€1,234.57" */
  --llm-notch-width: 2px;
  --llm-hidden-size: 1px;
}
@media (min-width: 821px) {
  :root { --llm-stat-min: 260px; } /* three a row in the main column */
}

[data-part="llm"] > .panel-head { margin-bottom: var(--space-1); }
.llm-sub { margin: 0 0 var(--space-4); }
.llm-panel { margin-bottom: var(--space-5); }
.llm-panel > .panel-head { margin-bottom: var(--space-3); }
.llm-panel .callout { margin-bottom: var(--space-4); }

/* --- the stat cards ----------------------------------------------- */

.llm-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, var(--llm-stat-min)), 1fr));
  gap: var(--space-3);
  margin: 0 0 var(--space-4);
}
.llm-stat { padding: var(--space-4); }
.llm-stat dt { font: 500 var(--text-m)/18px var(--font-sans); color: var(--ink2); }
.llm-stat dd { margin: 0; }
.llm-stat-value {
  margin-top: var(--space-1);
  font: 500 var(--text-2xl)/28px var(--font-sans);
  letter-spacing: -.01em;
  color: var(--ink);
}
.llm-stat-note { margin-top: var(--space-1); overflow-wrap: anywhere; }

.llm-unmetered { margin: 0 0 var(--space-5); color: var(--ink2); }
.llm-unmetered b { color: var(--ink); }

/* --- the chart ---------------------------------------------------- */

.llm-chart {
  display: grid;
  grid-template-columns: var(--llm-axis-width) minmax(0, 1fr);
  grid-template-rows: var(--llm-plot-height) auto;
}
.llm-yaxis,
.llm-plot,
.llm-xaxis { position: relative; }

.llm-yaxis span,
.llm-xaxis span {
  position: absolute;
  font: 400 var(--text-xs)/16px var(--font-sans);
  font-variant-numeric: tabular-nums;
  color: var(--mute);
  white-space: nowrap;
}
.llm-yaxis span { right: var(--space-2); transform: translateY(50%); }
.llm-xaxis { grid-column: 2; height: 20px; margin-top: var(--space-1); }
.llm-xaxis span { top: 0; transform: translateX(-50%); }

/* app.css gives every svg a 1.8 stroke in the ink colour (the icons). In a
   box stretched to the chart that stroke would be 1.8 days wide, so the
   bars and columns have none and the lines say 1px however it is
   stretched. */
.llm-plot svg { display: block; width: 100%; height: 100%; stroke: none; }
.llm-grid { stroke: var(--line2); stroke-width: 1; }
.llm-grid:first-of-type { stroke: var(--line); }   /* the zero line */
.llm-column { fill: transparent; }
.llm-column:hover { fill: var(--hover); }
.llm-bar { fill: var(--progress); pointer-events: none; }

.llm-summary { margin: var(--space-3) 0 0; }

/* Read by a screen reader, not seen: the chart's values as a table. */
.llm-vh {
  position: absolute;
  width: var(--llm-hidden-size);
  height: var(--llm-hidden-size);
  margin: calc(-1 * var(--llm-hidden-size));
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* --- the model table ---------------------------------------------- */

.llm-model-body { container: llm / inline-size; }

.list.llm-model-list .list-head,
.list.llm-model-list .list-row {
  --cols:
    minmax(0, 1fr)
    var(--llm-column-count) var(--llm-column-tokens) var(--llm-column-tokens) var(--llm-column-cost);
}
.llm-model-list .card-only { display: none; }
/* A model's name is whatever the agent reported: long ones wrap. */
.llm-model-row .who .t { white-space: normal; overflow-wrap: anywhere; }

@container llm (max-width: 840px) {
  .llm-model-list .list-head { display: none; }
  .llm-model-list .list-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-4);
  }
  .llm-model-row .who { flex: 1 0 100%; }
  .llm-model-list .cell-num { text-align: left; }
  .llm-model-list .card-only { display: inline; color: var(--mute); }
}

/* --- the budget --------------------------------------------------- */

.llm-limits {
  display: grid;
  gap: var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
}
.llm-limit-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}
.llm-limit-name { font-weight: 500; }
.llm-limit .s { margin-top: var(--space-1); }

/* The notch at 80%, where the warning starts: a gap in the bar. */
.llm-meter { position: relative; }
.llm-meter::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 80%;
  width: var(--llm-notch-width);
  background: var(--surface);
}
.llm-meter[data-level="warning"] i { background: var(--solid-warning); }
.llm-meter[data-level="exhausted"] i { background: var(--red); }

/* The editor sheet: the defaults button sits at the left, the rest at the
   right. On a phone the sheet's footer wraps (components.css), and sharing
   a row with Cancel and Save cuts this label to "Use configure", so it
   takes a row of its own. */
.llm-defaults { flex: 1; min-width: 0; }
.llm-defaults:empty { display: none; }
@media (max-width: 820px) {
  .llm-defaults { flex: 1 0 100%; }
}
