/* PolyStrata web page - layout on top of tokens.css + components.css (the PolyStrata UI kit). Colours, type, radii and
   shadows come only from the kit's tokens. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body { display: flex; flex-direction: column; overflow: hidden; }
main { flex: 1; min-height: 0; display: flex; }
.view { flex: 1; min-height: 0; min-width: 0; display: flex; flex-direction: column; }
.view[hidden] { display: none; }
.muted { color: var(--st-ink-muted); }
.small { font-size: var(--st-fs-xs); }
.card-title { font-weight: var(--st-fw-bold); font-size: var(--st-fs-base); color: var(--st-ink); }
.st-header { position: relative; z-index: 2; flex: none; }
.st-header .st-tabs { margin-left: var(--st-s-4); }
#unload-btn { flex: none; height: 32px; padding: 0 12px; min-width: 7.75rem; }
.st-header--clip #pill-text { display: none; }

.msg-error { color: var(--st-danger-text); background: var(--st-danger-tint); border-radius: var(--st-r-md); padding: 10px 14px;
             font-size: var(--st-fs-md); }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 6px 0 10px; border-radius: var(--st-r-pill);
        background: var(--st-surface-2); border: 1px solid var(--st-line); font-size: var(--st-fs-xs); color: var(--st-ink-soft); }
.chip .st-btn--icon { width: 22px; height: 22px; border-radius: 50%; }
.chip .st-btn--icon .st-icon { width: 14px; height: 14px; }

/* ---------------------------------------------------------------- monitor */
.view--monitor, .view--about, .view--experts, .view--requests { overflow-y: auto; }
/* #5723: the Experts view, a grid of the learned expert ranks (experts.js) */
.experts { width: 100%; max-width: 1200px; margin: 0 auto; padding: 16px; box-sizing: border-box; }
.experts-card { display: flex; flex-direction: column; gap: 8px; }
.experts-grid-wrap { width: 100%; overflow: hidden; }
#experts-grid { display: block; border-radius: 4px; background: var(--st-surface-2, transparent); }
.experts-tip { min-height: 1.4em; font-variant-numeric: tabular-nums; }
.monitor, .about { max-width: min(100%, 1920px); width: 100%; margin: 0 auto; padding: var(--st-s-6); display: flex; flex-direction: column;
                   gap: var(--st-s-5); }
.state-card { display: flex; flex-direction: column; gap: var(--st-s-3); }
.state-card__head { display: flex; align-items: center; gap: var(--st-s-4); flex-wrap: wrap; }
.state-card, .metric-card, .req-card, .ctx-card, .cc-card, .mcp-card { min-width: 0; }
.badges { display: flex; gap: var(--st-s-2); flex-wrap: wrap; }
.badges .st-badge { opacity: .38; transition: opacity var(--st-dur); }
.badges .st-badge.on { opacity: 1; }
.state-card__row { display: flex; justify-content: space-between; gap: var(--st-s-4); font-size: var(--st-fs-sm);
                   font-weight: var(--st-fw-medium); font-variant-numeric: tabular-nums; }
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: var(--st-s-4); }
.metric-card { padding: var(--st-s-4) var(--st-s-5); }
.model-card__name { font-size: var(--st-fs-md); font-weight: var(--st-fw-bold); line-height: 1.3; overflow-wrap: anywhere; }
.model-card__facts { display: grid; grid-template-columns: auto 1fr; gap: 3px var(--st-s-3); font-size: var(--st-fs-xs);
                     align-items: baseline; margin-top: auto; }
.model-card__facts .mf-k { color: var(--st-ink-muted); }
.model-card__facts .mf-v { text-align: right; font-variant-numeric: tabular-nums; }
.model-card__facts .mf-k--wide { grid-column: 1 / -1; }

.st-metric__value small { font-size: var(--st-fs-md); font-weight: var(--st-fw-medium); color: var(--st-ink-muted); margin-left: 4px; }
.st-metric__sub { font-size: var(--st-fs-xs); color: var(--st-ink-muted); font-variant-numeric: tabular-nums; min-height: 1em; }
.st-metric__spark { display: block; overflow: visible; }
.speed-values { display: flex; justify-content: space-between; gap: var(--st-s-3); }
.speed-values > div { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.speed-values > div:last-child { text-align: right; }
.speed-values .st-metric__value { font-size: clamp(20px, 2.2vw, var(--st-fs-stat)); }
.speed-range { margin-top: -6px; }                      /* the min and max belong under their number, not in a third row of their own */
.st-metric__spark .speed-prefill { color: color-mix(in srgb, var(--st-accent) 65%, black); }
.st-metric__spark[data-tone="warn"] { color: var(--st-warn); }
.st-metric__spark[data-tone="info"] { color: var(--st-info); }
.monitor-row { display: grid; grid-template-columns: minmax(min(260px, 100%), 1fr) minmax(0, 2.4fr); gap: var(--st-s-4); }
.ctx-card { display: flex; flex-direction: column; gap: var(--st-s-2); }
.ctx-gauge { position: relative; width: 150px; max-width: 100%; aspect-ratio: 1; height: auto; margin: var(--st-s-2) auto var(--st-s-3); }
.ctx-gauge .st-gauge { width: 100%; height: 100%; }
.ctx-gauge .st-gauge__fill { transition: stroke-dasharray 400ms var(--st-ease), stroke-dashoffset 400ms var(--st-ease); }
/* #4636: the fill in three parts, in the page's own colours (the prefill tone is the Speed card's) */
.ctx-seg--read, .ctx-key--read { stroke: color-mix(in srgb, var(--st-accent) 65%, black); background: color-mix(in srgb, var(--st-accent) 65%, black); }
.ctx-seg--answer, .ctx-key--answer { stroke: var(--st-info); background: var(--st-info); }
.ctx-key--cached { background: var(--st-accent); }
.ctx-key--free { background: var(--st-surface-2); box-shadow: inset 0 0 0 1px var(--st-line); }
.ctx-legend { list-style: none; margin: 0 0 var(--st-s-2); padding: 0; display: grid; gap: 2px; font-size: var(--st-fs-sm); }
.ctx-legend li { display: grid; grid-template-columns: 10px 1fr auto; align-items: center; gap: var(--st-s-2); font-variant-numeric: tabular-nums; }
.ctx-legend li.is-now { font-weight: var(--st-fw-bold); }
.ctx-key { width: 10px; height: 10px; border-radius: 2px; }
.ctx-gauge__pct[data-tone="warn"] { color: var(--st-warn-text); }
.ctx-gauge__pct[data-tone="danger"] { color: var(--st-danger-text); }
.ctx-note { margin: 0; text-align: center; }
.ctx-gauge__label { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
                    font-size: var(--st-fs-xs); }
.ctx-gauge__pct { font-weight: var(--st-fw-black); font-size: var(--st-fs-xl); line-height: 1.1; font-variant-numeric: tabular-nums; }
.bar-row { display: flex; justify-content: space-between; font-size: var(--st-fs-sm); font-weight: var(--st-fw-medium);
           margin-top: var(--st-s-2); font-variant-numeric: tabular-nums; }
.req-card { display: flex; flex-direction: column; gap: var(--st-s-3); min-width: 0; }
.table-wrap { overflow-x: auto; }
/* Recent requests: keep headings, values and status badges on one line. */
#req-wrap .st-table th,
#req-wrap .st-table td {
  white-space: nowrap;
  padding-inline: 8px;
}
.req-head { display: flex; align-items: center; justify-content: space-between; gap: var(--st-s-2); }
.table-wrap.all { max-height: 420px; overflow-y: auto; }
.req-totals { margin: 0; font-size: var(--st-fs-sm); }
.req-totals:empty { display: none; }
.cc-card { display: flex; flex-direction: column; gap: var(--st-s-3); }
.cc-bars { display: grid; grid-template-columns: 1fr 1fr; gap: var(--st-s-2) var(--st-s-6); }
.cc-bars[hidden] { display: none; }
.cc-note { margin: 0; }
.cc-note:empty { display: none; }
.mcp-card { display: flex; flex-direction: column; gap: var(--st-s-3); }
/* A row is a help line that wraps and a field that keeps its width.  The help is the server's own words and may be
   long, so the label column is the one that gives way: sizing it to max-content once let one long help line squeeze
   every field of the card down to the width of its own spinner arrows. */
.cfg-form { display: grid; grid-template-columns: minmax(min(180px, 100%), 1fr) minmax(11rem, 360px);
            gap: var(--st-s-3) var(--st-s-4); align-items: center; }
.cfg-form label { overflow-wrap: anywhere; font-size: var(--st-fs-sm); font-weight: var(--st-fw-medium); }
.cfg-form label code { font: 400 12px var(--st-font-mono); color: var(--st-ink-muted); display: block; }
.cfg-form .st-input { height: 38px; width: 100%; max-width: 360px; min-width: 0; }
.cfg-actions { display: flex; align-items: center; gap: var(--st-s-3); }
.mcp-server { display: flex; flex-direction: column; gap: var(--st-s-2); padding-top: var(--st-s-3); border-top: 1px solid var(--st-line-soft); }
.mcp-server:first-child { padding-top: 0; border-top: 0; }
.mcp-server__head { display: flex; align-items: center; gap: var(--st-s-2); flex-wrap: wrap; font-size: var(--st-fs-sm); }
.mcp-server__tools { display: flex; flex-wrap: wrap; gap: 6px; }
.mcp-server__tools .chip { height: 26px; padding: 0 10px; font-family: var(--st-font-mono); }
.mcp-note { margin: 0; }

/* ---------------------------------------------------------------- about */
.about { max-width: min(100%, 1100px); }
.about .st-card { display: flex; flex-direction: column; gap: var(--st-s-3); }
.about p { margin: 0; }
.facts { display: grid; grid-template-columns: minmax(140px, max-content) 1fr; gap: 10px var(--st-s-6); margin: 0; font-size: var(--st-fs-md); }
.facts dt { color: var(--st-ink-muted); }
.facts dd { margin: 0; color: var(--st-ink-soft); font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: 6px;
            overflow-wrap: anywhere; }
.facts dd code { font: 400 13px var(--st-font-mono); }
.facts .st-btn--icon { width: 28px; height: 28px; }
.facts .st-btn--icon .st-icon { width: 16px; height: 16px; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: var(--st-s-4); font-size: var(--st-fs-sm);
              font-weight: var(--st-fw-medium); color: var(--st-ink-soft); }
.toggle-row .st-toggle { flex: none; }   /* a long label must not squeeze the switch */

.st-toast { animation: toast-in 180ms var(--st-ease); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

/* ---------------------------------------------------------------- narrow screens */
/* tabs that do not fit the header (a narrow phone, or Images on) scroll instead of widening the page */
.st-header .st-tabs { min-width: 0; overflow-x: auto; scrollbar-width: none; }
@media (max-width: 1000px) {
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cc-bars { grid-template-columns: 1fr; }
  .cfg-form { grid-template-columns: 1fr; gap: 4px; }
  .cfg-form .st-input { margin-bottom: var(--st-s-2); }
}
@media (max-width: 900px) {
  .monitor-row { grid-template-columns: minmax(0, 1fr); }
}
/* The name in the header is a link to the project (#5510); it keeps the look of the name. Focus uses the global ring. */
a.st-header__brand { color: inherit; text-decoration: none; }
a.st-header__brand:hover { color: var(--st-accent-text); text-decoration: none; }
/* The tab strip keeps a width it can scroll. The pill's text hides only when the header row overflows (fitHeader in app.js).
   Load / Unload (PR #3550) sits in the row: 9rem of tabs plus its 7.75rem fit from 458px; below that the tighter floors keep
   it and the theme button in the viewport. */
@media (max-width: 955px) {
  .st-header { padding: 0 var(--st-s-3); gap: var(--st-s-2); }
  .st-header__brand, #theme-btn, #pill, #unload-btn { flex: none; }
  .st-header .st-tabs { margin-left: 0; flex: 1 1 auto; min-width: 9rem; overflow-x: auto; }
  .st-tab { padding: 0 10px; }
  .st-tab .st-icon { display: none; }
}
@media (max-width: 457px) {
  #unload-btn { min-width: 0; padding: 0 8px; }
  .st-header .st-tabs { min-width: 5.5rem; }
}
/* the name plus "Unloading…" still overflows at 374px in Firefox 158 */
@media (max-width: 382px) {
  .st-header__brand { display: none; }
  .st-header .st-tabs { min-width: 4.75rem; }
}
@media (max-width: 640px) {
  .monitor, .about { padding: var(--st-s-4); }
  .facts { grid-template-columns: 1fr; gap: 2px; }
  .facts dd { margin-bottom: var(--st-s-2); }
  .cfg-form .st-input { max-width: none; }
  .st-btn, .st-input, .st-tab { min-height: 40px; }
  .st-btn--icon, .facts .st-btn--icon { width: 40px; height: 40px; }
  .table-wrap { max-width: 100%; }
}
@media (max-width: 560px) {
  .metrics { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 480px) {
  .st-header { padding: 0 var(--st-s-2); gap: 6px; }
  .st-header__brand { font-size: var(--st-fs-md); }
  .st-tabs { gap: 2px; padding: 3px; }
  .st-tab { padding: 0 8px; }
  .composer-hint { display: none; }
  .monitor, .about { padding: var(--st-s-3); }
}

/* the header's model list (more than one model installed). It narrows down to 4rem when the row runs out of room (the open list
   still shows the whole names), and up to 560px it takes the name's place: with the name and the list both in it, the row
   overflows a phone at 383-400px and 458-550px. */
@media (max-width: 560px) { .st-header:has(#model-select:not([hidden])) .st-header__brand { display: none; } }
.model-select{flex:0 1 auto;min-width:4rem;height:30px;max-width:280px;padding:0 var(--st-s-2);border-radius:var(--st-r-md);border:1px solid var(--st-line);background:var(--st-surface-2);color:var(--st-ink);font:inherit;font-size:var(--st-fs-sm)}
.model-select:disabled{opacity:.6}
/* Images tab (POST /v1/images/generations) */
.img-form{display:flex;flex-direction:column;gap:12px}
.img-prompt{height:auto;padding:10px 14px;resize:vertical}
.img-row{display:flex;gap:12px;align-items:flex-end;flex-wrap:wrap}
.img-results{display:flex;flex-direction:column;gap:12px}
.img-results figure{margin:0}
.img-results img{max-width:100%;border-radius:var(--st-r-lg);display:block}
.img-results figcaption{font-size:var(--st-fs-sm, 13px);color:var(--st-ink-2, inherit);margin-top:4px}

#lang { width: 100%; }
.st-toast .st-btn { white-space: nowrap; }
