/* STARNET — widgets.css : the WIDGET RAILS (widgets.js).
   Compact pinnable telemetry instruments living in the chrome's dead space — the empty
   middle of #topbar and #bottombar. Built in the topbar.css instrument vocabulary
   (dim label over bright value, hairline separations) at rail scale — but milled like
   real bench instruments: a recessed phosphor-tinted face, a machined top hairline, a
   gold-edged variant for agent-fed readouts, tone tints, sparklines and progress bars.

   Rules of this file (same contract as topbar.css / motion.css):
   - Never a hardcoded colour — only the phosphor / role vars (and neutral black overlays,
     the established chrome idiom), so every theme re-tints.
   - Animate only transform / opacity / colour / border / box-shadow — never layout on a
     hot path; the 60fps canvas runs behind the chrome.
   - Composite vars referencing --ph would live on `body`; this file uses none. */

/* ---- the rails: flex-fill the dead space, scroll (thin) if over-stuffed ---- */
.widget-rail {
  display: flex; align-items: center; gap: 7px;
  flex: 1 1 auto; min-width: 0; align-self: stretch;
  margin: 0 10px; padding: 0 2px;
  overflow-x: auto; overflow-y: hidden;
  scrollbar-width: thin; scrollbar-color: var(--ph-dim) transparent;
  border: 1px dashed transparent; border-radius: 4px;   /* invisible until a drag arms it */
  transition: border-color var(--t-fast, 120ms) var(--ease-soft, ease),
              background-color var(--t-fast, 120ms) var(--ease-soft, ease);
}
.widget-rail::-webkit-scrollbar { height: 5px; }
.widget-rail::-webkit-scrollbar-track { background: transparent; }
.widget-rail::-webkit-scrollbar-thumb { background: var(--ph-faint); border-radius: 3px; }

/* the bottom rail shares its bar with #term-strip: cap it so minimized-window chips keep room */
#wr-bot { max-width: 42vw; }

/* a drag is live: both rails reveal themselves as targets; the hovered one blooms */
.widget-rail.wg-armed { border-color: var(--ph-faint); }
.widget-rail.wg-hot { border-color: var(--ph); background: rgba(0,0,0,0.35);
  box-shadow: 0 0 14px var(--ph-glow2) inset; }

/* ---- one widget: a milled bench instrument ----
   Recessed face (dark-to-darker vertical grade over a faint phosphor wash), a machined
   top hairline catching the light, and an inner shadow seating it INTO the bar. */
.wg {
  display: inline-flex; align-items: center; gap: 8px; flex: 0 0 auto;
  position: relative; padding: 3px 10px; max-height: 34px;
  background:
    linear-gradient(180deg, rgba(var(--ph-rgb, 255,170,51), 0.055) 0%, rgba(0,0,0,0.0) 45%),
    linear-gradient(180deg, rgba(0,0,0,0.30), rgba(0,0,0,0.52));
  border: 1px solid var(--ph-faint); border-radius: 4px;
  box-shadow:
    inset 0 1px 0 rgba(var(--ph-rgb, 255,170,51), 0.10),   /* the machined top hairline */
    inset 0 -4px 10px rgba(0,0,0,0.45),                     /* seated into the bar */
    0 1px 0 rgba(0,0,0,0.6);
  cursor: grab; touch-action: none;
  transition: border-color var(--t-fast, 120ms) var(--ease-soft, ease),
              box-shadow var(--t-fast, 120ms) var(--ease-soft, ease),
              transform var(--t-fast, 120ms) var(--ease-soft, ease);
}
.wg:hover {
  border-color: var(--ph-dim);
  box-shadow:
    inset 0 1px 0 rgba(var(--ph-rgb, 255,170,51), 0.16),
    inset 0 -4px 10px rgba(0,0,0,0.45),
    0 0 12px var(--ph-glow2);
}
.wg:active { cursor: grabbing; }

/* AGENT-FED: a gold-edged instrument — the provenance accent runs the whole left edge,
   echoing the gold provenance dot, so a fed readout reads as a different trust class at a glance */
.wg-fed { border-left: 2px solid rgba(var(--gold-rgb, 255,211,74), 0.55); }
.wg-fed:hover { border-left-color: var(--gold); }

.wg-meta { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-width: 0; }
.wg-lbl { font-size: 10px; letter-spacing: var(--ls-3, 2px); color: var(--ph-dim); line-height: 1; white-space: nowrap; }
.wg-src { display: inline-flex; align-items: center; gap: 3px; font-size: 10.5px; letter-spacing: 1px;
  color: var(--ph-dim); opacity: 0.85; line-height: 1; white-space: nowrap; }
.wg-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--ok);
  box-shadow: 0 0 4px var(--ok); animation: wg-breathe 2.4s ease-in-out infinite; }
/* AGENT-FED provenance: gold dot + "who · when" — the station asserts the reporter, never the figure */
.wg-dot-fed { background: var(--gold); box-shadow: 0 0 4px var(--gold); animation: none; }
.wg-fed .wg-src { color: var(--ph-dim); max-width: 150px; overflow: hidden; text-overflow: ellipsis; }

.wg-val { font-size: 16px; letter-spacing: 1px; color: var(--ph-bright); line-height: 1;
  text-shadow: 0 0 8px var(--ph-glow2), 0 0 2px var(--ph-glow2); white-space: nowrap; font-weight: normal;
  font-variant-numeric: tabular-nums; }
.wg[data-empty="1"] .wg-val { color: var(--ph-dim); text-shadow: none; }   /* honest "—" sits quiet */

/* TONE — an agent-declared semantic tint (whitelisted ok|warn|bad at sanitize). Colours the
   figure and the progress fill only; the instrument body stays in the station grade. */
.wg[data-tone="ok"]   .wg-val { color: var(--ok);   text-shadow: 0 0 8px var(--ok); }
.wg[data-tone="warn"] .wg-val { color: var(--warn); text-shadow: 0 0 8px var(--warn); }
.wg[data-tone="bad"]  .wg-val { color: var(--bad);  text-shadow: 0 0 8px var(--bad); }
.wg[data-tone="ok"]   .wg-sub.wg-ticktext { color: var(--ok); }
.wg[data-tone="warn"] .wg-sub.wg-ticktext { color: var(--warn); }
.wg[data-tone="bad"]  .wg-sub.wg-ticktext { color: var(--bad); }

/* E3: STALE — the source (poll/SSE) went dark, so this last-good figure is no longer live. Dim the
   value and tint the source tag amber (mirrors the canvas linkStaleDim: value present but not fresh).
   The value still shows — it's the last KNOWN truth, honestly flagged as not current. */
.wg[data-stale="1"] .wg-val { opacity: 0.42; text-shadow: none; }
.wg[data-stale="1"] .wg-src { color: var(--warn); opacity: 1; }
.wg[data-stale="1"] .wg-dot { background: var(--warn); box-shadow: 0 0 4px var(--warn); animation: none; }
.wg-sub { font-size: 10px; letter-spacing: 1px; color: var(--ph-dim); white-space: nowrap; }
/* ticker form (agent-fed list): one cycling line at reading size instead of a big figure */
.wg-sub.wg-ticktext { font-size: 12px; letter-spacing: 0.5px; color: var(--text, var(--ph-bright));
  max-width: 300px; overflow: hidden; text-overflow: ellipsis; }

/* ---- spark: line + soft area fill + bright endpoint dot (the "now" reading) ---- */
.wg-spark { width: 46px; height: 16px; flex: 0 0 auto; }
.wg-spark polyline { stroke: var(--ph); stroke-width: 1.2; }
.wg-spark polygon { fill: rgba(var(--ph-rgb, 255,170,51), 0.13); }
.wg-spark circle { fill: var(--ph-bright); }
.wg[data-tone="ok"]   .wg-spark polyline { stroke: var(--ok); }
.wg[data-tone="ok"]   .wg-spark circle   { fill: var(--ok); }
.wg[data-tone="warn"] .wg-spark polyline { stroke: var(--warn); }
.wg[data-tone="warn"] .wg-spark circle   { fill: var(--warn); }
.wg[data-tone="bad"]  .wg-spark polyline { stroke: var(--bad); }
.wg[data-tone="bad"]  .wg-spark circle   { fill: var(--bad); }

/* ---- progress: a recessed channel with a phosphor fill (agent-fed `progress` 0-100) ---- */
.wg-prog { display: inline-block; width: 54px; height: 6px; flex: 0 0 auto;
  background: rgba(0,0,0,0.55); border: 1px solid var(--ph-faint); border-radius: 3px;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.7); overflow: hidden; }
.wg-prog-fill { display: block; height: 100%; border-radius: 2px;
  background: linear-gradient(90deg, var(--ph-dim), var(--ph));
  box-shadow: 0 0 6px var(--ph-glow);
  transition: width var(--t-slow, 400ms) var(--ease-out, ease); }
.wg[data-tone="ok"]   .wg-prog-fill { background: var(--ok);   box-shadow: 0 0 6px var(--ok); }
.wg[data-tone="warn"] .wg-prog-fill { background: var(--warn); box-shadow: 0 0 6px var(--warn); }
.wg[data-tone="bad"]  .wg-prog-fill { background: var(--bad);  box-shadow: 0 0 6px var(--bad); }

/* a live event just folded in — brief phosphor bloom on the value (colour/shadow only) */
.wg.wg-tick .wg-val { animation: wg-tick var(--t-slow, 400ms) var(--ease-out, ease); }
@keyframes wg-tick {
  0%   { color: var(--gold); text-shadow: 0 0 12px var(--gold); }
  100% { color: var(--ph-bright); text-shadow: 0 0 8px var(--ph-glow2); }
}
@keyframes wg-breathe { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

/* hover ✕ — hidden until the instrument is hovered so the chrome stays quiet */
/* .wg-x composes .x-btn (danger hover) — tiny circular, hover-revealed */
.wg-x {
  position: absolute; top: -6px; right: -6px; width: 15px; height: 15px;
  display: none; align-items: center; justify-content: center;
  font-size: 10px; padding: 0; border-radius: 50%;
}
.wg:hover .wg-x { display: inline-flex; }

/* the drag ghost: the same instrument, lifted off the bench */
.wg.wg-drag { position: fixed; z-index: 990; pointer-events: none; opacity: 0.95;
  border-color: var(--ph); box-shadow: 0 0 18px var(--ph-glow2), 0 10px 26px rgba(0,0,0,0.75);
  transform: scale(1.06); background: var(--panel2, rgba(0,0,0,0.9)); }
.wg.wg-drag .wg-x { display: none; }

/* the insert caret: a phosphor sliver marking the drop slot */
.wg-caret { width: 3px; align-self: stretch; margin: 3px 0; flex: 0 0 auto;
  background: var(--ph); box-shadow: 0 0 8px var(--ph-glow); border-radius: 1px; }

/* ---- the ＋ affordance: quiet until hovered; the only rail content when empty ---- */
.wg-add {
  flex: 0 0 auto; width: 20px; height: 20px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-family: inherit; font-size: 13px; line-height: 1;
  color: var(--ph-faint); background: transparent;
  border: 1px solid transparent; border-radius: 4px; cursor: pointer;
  transition: color var(--t-fast, 120ms) var(--ease-soft, ease),
              border-color var(--t-fast, 120ms) var(--ease-soft, ease),
              box-shadow var(--t-fast, 120ms) var(--ease-soft, ease);
}
.widget-rail:hover .wg-add, .wg-add:focus-visible { color: var(--ph-dim); border-color: var(--ph-faint); }
.wg-add:hover { color: var(--ph); border-color: var(--ph-dim); box-shadow: 0 0 8px var(--ph-glow2); }

/* ---- the add-widget popover (fixed; positioned by widgets.js above/below its rail) ---- */
.wg-pop {
  position: fixed; z-index: 995; min-width: 224px; padding: 6px;
  background: var(--panel, rgba(5,3,1,0.95)); border: 1px solid var(--ph-dim); border-radius: 4px;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.9), 0 12px 30px rgba(0,0,0,0.75), 0 0 18px var(--ph-glow2),
    inset 0 1px 0 rgba(var(--ph-rgb, 255,170,51), 0.08);
  animation: wg-pop-in var(--t-fast, 120ms) var(--ease-out, ease);
}
@keyframes wg-pop-in { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
.wg-pop-item {
  display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 12px;
  font-family: inherit; font-size: 13px; letter-spacing: 1px; text-align: left;
  color: var(--text, var(--ph-bright)); background: transparent;
  border: 0; border-left: 2px solid transparent; border-radius: 2px;
  padding: 6px 9px; cursor: pointer;
  transition: background-color var(--t-fast, 120ms) var(--ease-soft, ease),
              border-color var(--t-fast, 120ms) var(--ease-soft, ease);
}
.wg-pop-item:hover { background: rgba(0,0,0,0.4); color: var(--ph-bright); border-left-color: var(--ph); }
.wg-pop-item i { font-style: normal; font-size: 10px; letter-spacing: 1px; color: var(--ph-dim); }
.wg-pop-item.on i { color: var(--ok); }
/* the popover's AGENT-FED section: a milled divider + an honest empty-state hint */
.wg-pop-head { margin: 6px 6px 2px; padding-top: 6px; border-top: 1px solid var(--ph-faint);
  font-size: 10px; letter-spacing: 2px; color: var(--gold); opacity: 0.85; }
.wg-pop-none { padding: 4px 9px 6px; max-width: 230px; }   /* dim grade + size via the grouped empty rule (motion.css) */

/* ---- responsive: the rails are the FIRST thing to shrink; never crowd the real instruments ---- */
@media (max-width: 1280px) { .wg-sub { display: none; } .wg-spark { display: none; } .wg-prog { display: none; } }
@media (max-width: 1000px) { .wg-lbl { letter-spacing: 1px; } .widget-rail { margin: 0 6px; } }

@media (prefers-reduced-motion: reduce) {
  .wg-dot { animation: none; }
  .wg.wg-tick .wg-val { animation-duration: 0.01ms !important; }
  .wg-pop { animation: none; }
  .widget-rail, .wg, .wg-add, .wg-prog-fill { transition-duration: 0.01ms !important; }
}
