/* ============================================================================
   PCR Load-test — control-room instrument panel
   Signature: railway signal aspects (green clear / amber caution / red danger)
   encode agent state & call health. Cyan "phosphor" is the data/interactive ink.
   ========================================================================== */

:root {
    /* control-room slate — not pure black */
    --bg:        #0B1017;
    --bg-2:      #121A24;
    --bg-3:      #18222E;
    --line:      #223041;
    --line-soft: #1A2531;

    /* ink */
    --ink:       #DCE6F0;
    --ink-dim:   #7E93A8;
    --ink-faint: #4A5C70;

    /* phosphor — data & interactive accent */
    --phos:      #45C8E0;
    --phos-dim:  #2A7C8C;

    /* rail signal aspects — status only */
    --sig-green: #3FCF6A;
    --sig-amber: #F2B33D;
    --sig-red:   #F0524B;

    --font-display: "Chakra Petch", "Segoe UI Variable", "Segoe UI", system-ui, sans-serif;
    --font-mono:    "JetBrains Mono", "Cascadia Code", "SF Mono", Consolas, ui-monospace, monospace;
    --font-body:    "Segoe UI Variable", "Segoe UI", system-ui, sans-serif;

    --r: 4px;              /* control panels are square-ish, minimal radius */
    --pad: clamp(16px, 3vw, 32px);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background-color: var(--bg);
    /* faint instrument grid — reads as a screen, stays quiet */
    background-image:
        linear-gradient(var(--line-soft) 1px, transparent 1px),
        linear-gradient(90deg, var(--line-soft) 1px, transparent 1px);
    background-size: 44px 44px;
    background-position: -1px -1px;
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.5;
    letter-spacing: 0.01em;
    min-height: 100vh;
}

a { color: var(--phos); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

:focus-visible {
    outline: 2px solid var(--phos);
    outline-offset: 2px;
    border-radius: 2px;
}

/* ---- scrollbar (tema control-room) -------------------------------------- */
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--line);
    border-radius: 8px;
    border: 2px solid transparent;
    background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--phos-dim);
    border-width: 1px;
}
::-webkit-scrollbar-corner { background: transparent; }

/* ---- shell -------------------------------------------------------------- */
.shell {
    max-width: 1180px;
    margin: 0 auto;
    padding: var(--pad);
    display: flex;
    flex-direction: column;
    gap: 22px;
}

/* ---- eyebrow / labels --------------------------------------------------- */
.eyebrow {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.28em;
    text-transform: uppercase;
    color: var(--ink-faint);
}

/* ---- masthead ----------------------------------------------------------- */
.mast {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--line);
}
.mast__title {
    margin: 4px 0 0;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(26px, 4vw, 40px);
    letter-spacing: 0.04em;
    line-height: 1;
    text-transform: uppercase;
    color: var(--ink);
}
.mast__title b { color: var(--phos); font-weight: 700; }
.mast__online {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--ink-dim);
    white-space: nowrap;
}
.mast__online .n { color: var(--ink); font-weight: 700; }

/* ---- signal aspect lamp (the signature) --------------------------------- */
.lamp {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--ink-faint);
    box-shadow: 0 0 0 1px rgba(0,0,0,.4) inset;
    flex: none;
}
.lamp--green  { background: var(--sig-green); box-shadow: 0 0 10px 1px rgba(63,207,106,.7); }
.lamp--amber  { background: var(--sig-amber); box-shadow: 0 0 10px 1px rgba(242,179,61,.6); }
.lamp--red    { background: var(--sig-red);   box-shadow: 0 0 10px 1px rgba(240,82,75,.6); }
.lamp--idle   { background: var(--ink-faint); box-shadow: none; }
.lamp--green.lamp--live { animation: pulse 1.6s ease-in-out infinite; }

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 10px 1px rgba(63,207,106,.7); }
    50%      { box-shadow: 0 0 16px 3px rgba(63,207,106,.95); }
}

/* ---- transport controls ------------------------------------------------- */
.transport {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.transport__spacer { flex: 1 1 auto; }

.btn {
    appearance: none;
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--ink);
    background: var(--bg-3);
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 5px 8px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: border-color .12s ease, background .12s ease, color .12s ease;
}
.btn:hover { border-color: var(--phos-dim); }
.btn__glyph { font-size: 11px; line-height: 1; }

/* aspect-tinted actions: start=green, pause=amber, stop=red */
.btn--go     { color: var(--sig-green); border-color: rgba(63,207,106,.35); }
.btn--go:hover     { background: rgba(63,207,106,.12); border-color: var(--sig-green); }
.btn--hold   { color: var(--sig-amber); border-color: rgba(242,179,61,.35); }
.btn--hold:hover   { background: rgba(242,179,61,.12); border-color: var(--sig-amber); }
.btn--halt   { color: var(--sig-red); border-color: rgba(240,82,75,.35); }
.btn--halt:hover   { background: rgba(240,82,75,.12); border-color: var(--sig-red); }

.btn--link,
.btn--edit {
    color: var(--phos);
    border-color: rgba(69,200,224,.35);
    text-decoration: none;
}
.btn--link:hover,
.btn--edit:hover { background: rgba(69,200,224,.12); border-color: var(--phos); text-decoration: none; }

/* compact per-row controls */
.btn--mini {
    padding: 3px 5px;
    font-size: 10px;
    letter-spacing: 0.06em;
    background: transparent;
}

/* ---- platform host bar -------------------------------------------------- */
.host-bar { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; }
.host-bar__field { flex: 1 1 320px; }
.host-bar__apply { flex: 0 0 auto; }
.host-bar__msg {
    font-family: var(--font-mono);
    font-size: 12px;
    align-self: center;
}
.host-bar__msg--ok  { color: var(--sig-green); }
.host-bar__msg--bad { color: var(--sig-red); }

/* ---- home: header band compatto ---------------------------------------- */
.page-wide.shell--home { gap: 16px; }

.hbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px 20px;
    flex-wrap: wrap;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--line);
}
.hbar__brand { display: flex; align-items: center; gap: 12px; }
.hbar__title {
    margin: 0;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(20px, 3vw, 28px);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    line-height: 1;
}
.hbar__title b { color: var(--phos); }
.hbar__count { font-family: var(--font-mono); font-size: 13px; color: var(--ink-dim); }
.hbar__count .n { color: var(--ink); font-weight: 700; }
.hbar__actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.hbar__sep { width: 1px; align-self: stretch; min-height: 20px; background: var(--line); margin: 0 4px; }

/* ---- home: striscia metriche compatta ----------------------------------- */
.statbar {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    border: 1px solid var(--line);
    border-radius: var(--r);
    background: var(--bg-2);
    overflow: hidden;
}
.stat {
    display: flex;
    align-items: baseline;
    gap: 9px;
    padding: 11px 20px;
    border-left: 1px solid var(--line-soft);
}
.stat:first-child { border-left: 0; }
.stat__k {
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--ink-faint);
}
.stat__v {
    font-family: var(--font-mono);
    font-size: 20px;
    font-weight: 700;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}
.stat__v small { font-size: 11px; color: var(--ink-dim); font-weight: 400; margin-left: 3px; }
.stat__v--bad  { color: var(--sig-red); }
.stat__v--ok   { color: var(--sig-green); }
.stat__v--tail { color: var(--phos); }

/* ---- home: config host inline (secondaria) ------------------------------ */
.host-inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; align-self: center; }
.host-inline__k {
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--ink-faint);
}
.host-inline .input { width: 260px; max-width: 46vw; padding: 6px 9px; font-size: 12px; }
.host-inline__msg { font-family: var(--font-mono); font-weight: 700; }
.host-inline__msg--ok  { color: var(--sig-green); }
.host-inline__msg--bad { color: var(--sig-red); }

/* ---- azioni compatte a icona ------------------------------------------- */
.btn--icon {
    padding: 3px 0;
    min-width: 30px;
    justify-content: center;
    font-size: 12px;
    letter-spacing: 0;
}
.row-actions__sep { width: 1px; align-self: stretch; min-height: 16px; background: var(--line); margin: 0 4px; }

/* ---- flotta agenti: card ------------------------------------------------ */
.fleet {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 14px;
}
.agent-card {
    border: 1px solid var(--line);
    border-radius: var(--r);
    background: var(--bg-2);
    box-shadow: inset 3px 0 0 var(--ink-faint);   /* barra di stato a sinistra */
    padding: 14px 16px 14px 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    cursor: pointer;
    transition: border-color .12s ease, transform .12s ease;
}
.agent-card:hover { border-color: var(--phos-dim); transform: translateY(-1px); }
.agent-card--running { background-color: rgba(63,207,106,.07); box-shadow: inset 3px 0 0 var(--sig-green); }
.agent-card--paused  { background-color: rgba(242,179,61,.06); box-shadow: inset 3px 0 0 var(--sig-amber); }
.agent-card--stopped { background-color: rgba(240,82,75,.06);  box-shadow: inset 3px 0 0 var(--sig-red); }
.agent-card--init    { box-shadow: inset 3px 0 0 var(--ink-faint); }

.agent-card__top { display: flex; align-items: center; gap: 10px; }
.agent-card__id { font-family: var(--font-mono); font-size: 16px; font-weight: 700; color: var(--ink); }
.agent-card__locale { font-family: var(--font-mono); font-size: 12px; color: var(--ink-dim); }
.agent-card__state {
    margin-left: auto;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.agent-card__actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.agent-card__groups { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---- group tags & filter chips ------------------------------------------ */
.tag {
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.06em;
    color: var(--phos);
    background: rgba(69,200,224,.10);
    border: 1px solid rgba(69,200,224,.30);
    border-radius: 999px;
    padding: 2px 8px;
    white-space: nowrap;
}

.group-filter {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 4px 0 14px;
}
.chip {
    appearance: none;
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.06em;
    color: var(--ink-dim);
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 4px 12px;
    transition: border-color .12s ease, color .12s ease, background .12s ease;
}
.chip:hover { border-color: var(--phos-dim); color: var(--ink); }
.chip.is-active {
    color: var(--phos);
    border-color: var(--phos);
    background: rgba(69,200,224,.12);
}

/* ---- instrument cluster (hero) ------------------------------------------ */
.cluster {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1px;
    background: var(--line);
    border: 1px solid var(--line);
    border-radius: var(--r);
    overflow: hidden;
}
.gauge {
    background: var(--bg-2);
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 108px;
}
.gauge__label {
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--ink-faint);
}
.gauge__value {
    font-family: var(--font-mono);
    font-size: clamp(26px, 3.4vw, 36px);
    font-weight: 700;
    line-height: 1;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
}
.gauge__value--ok  { color: var(--sig-green); }
.gauge__value--bad { color: var(--sig-red); }
.gauge__unit { font-size: 13px; color: var(--ink-dim); font-weight: 400; margin-left: 4px; }
.gauge__note {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--ink-dim);
    margin-top: auto;
}

/* the latency panel spans wider and shows p50/p90/p99 side by side */
.gauge--latency { grid-column: 1 / -1; }
@media (min-width: 720px) {
    .gauge--latency { grid-column: span 2; }
}
.lat {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}
.lat__col { display: flex; flex-direction: column; gap: 8px; }
.lat__pct {
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.12em;
    color: var(--ink-faint);
    text-transform: uppercase;
}
.lat__ms {
    font-family: var(--font-mono);
    font-size: clamp(20px, 2.6vw, 28px);
    font-weight: 700;
    line-height: 1;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}
.lat__col--tail .lat__ms { color: var(--phos); }   /* p99 is the number that matters */
.lat__bar {
    height: 4px;
    border-radius: 2px;
    background: var(--line);
    overflow: hidden;
}
.lat__bar > i {
    display: block;
    height: 100%;
    background: var(--phos-dim);
}
.lat__col--tail .lat__bar > i { background: var(--phos); }

/* ---- section header ----------------------------------------------------- */
.section-head {
    display: flex;
    align-items: baseline;
    gap: 14px;
}
.section-head h2 {
    margin: 0;
    font-family: var(--font-display);
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--ink);
}
.section-head .rule {
    flex: 1;
    height: 1px;
    background: var(--line);
    align-self: center;
}

/* ---- fleet table -------------------------------------------------------- */
.panel {
    border: 1px solid var(--line);
    border-radius: var(--r);
    background: var(--bg-2);
    overflow: hidden;
}
.grid { width: 100%; border-collapse: collapse; }
.grid thead th {
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--ink-faint);
    text-align: left;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--bg-3);
}
.grid tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--line-soft);
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--ink-dim);
    vertical-align: middle;
    font-variant-numeric: tabular-nums;
}
.grid tbody tr:last-child td { border-bottom: none; }
.grid tbody tr:hover td { background: rgba(69,200,224,.04); }
.grid td.num { text-align: right; }

.cell-root { display: inline-flex; align-items: center; gap: 10px; }
.cell-root a, .cell-root__id { color: var(--ink); font-weight: 700; }
.cell-root a:hover, .row-click:hover .cell-root__id { color: var(--phos); }

/* state pill */
.state {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.state--running { color: var(--sig-green); }
.state--paused  { color: var(--sig-amber); }
.state--stopped { color: var(--sig-red); }
.state--init    { color: var(--ink-faint); }

.row-actions { display: inline-flex; gap: 6px; justify-content: flex-end; }

/* countdown */
.countdown { color: var(--ink); }
.countdown--idle { color: var(--ink-faint); }

/* ---- agent detail ------------------------------------------------------- */
.back-link {
    font-family: var(--font-mono);
    font-size: 12px;
    letter-spacing: 0.08em;
    color: var(--ink-dim);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.back-link:hover { color: var(--phos); text-decoration: none; }

.detail-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 22px;
}
@media (min-width: 820px) {
    .detail-grid { grid-template-columns: 260px 1fr; align-items: start; }
}

/* the full signal head — big version of the signature */
.signal {
    border: 1px solid var(--line);
    border-radius: var(--r);
    background: var(--bg-2);
    padding: 22px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
    text-align: center;
}
.signal__head {
    background: #05080C;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.signal__lamp {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #0E141B;
    box-shadow: inset 0 0 0 2px rgba(0,0,0,.5);
}
.signal__lamp--red-on   { background: var(--sig-red);   box-shadow: 0 0 18px 3px rgba(240,82,75,.8), inset 0 0 6px rgba(255,255,255,.35); }
.signal__lamp--amber-on { background: var(--sig-amber); box-shadow: 0 0 18px 3px rgba(242,179,61,.8), inset 0 0 6px rgba(255,255,255,.35); }
.signal__lamp--green-on { background: var(--sig-green); box-shadow: 0 0 18px 3px rgba(63,207,106,.8), inset 0 0 6px rgba(255,255,255,.35); }

.signal__state {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}
.signal__next {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--ink-dim);
}
.signal__next b { color: var(--ink); }
.signal__actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

.detail-title h1 {
    margin: 8px 0 2px;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(24px, 3.4vw, 34px);
    letter-spacing: 0.03em;
    text-transform: uppercase;
}
.detail-title .locale-tag {
    font-family: var(--font-mono);
    color: var(--phos);
}

/* program listing — the agent's instruction tape */
.program {
    list-style: none;
    counter-reset: step;
    margin: 0;
    padding: 6px 0;
}
.program li {
    counter-increment: step;
    display: grid;
    grid-template-columns: 34px 1fr;
    gap: 12px;
    align-items: baseline;
    padding: 7px 16px;
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--ink-dim);
    border-left: 2px solid transparent;
}
.program li::before {
    content: counter(step, decimal-leading-zero);
    color: var(--ink-faint);
    font-size: 11px;
}
.program li.is-current {
    color: var(--ink);
    background: rgba(69,200,224,.07);
    border-left-color: var(--phos);
}
.program li.is-current::before { color: var(--phos); }
.program li.is-current::after {
    content: "◂ PC";
    margin-left: 8px;
    color: var(--phos);
    font-size: 10px;
    letter-spacing: 0.1em;
}

/* result badges in recent-calls table */
.result { font-weight: 700; }
.result--ok { color: var(--sig-green); }
.result--ko { color: var(--sig-red); }

.empty {
    padding: 40px;
    text-align: center;
    color: var(--ink-faint);
    font-family: var(--font-mono);
    font-size: 13px;
}

/* ---- editor form -------------------------------------------------------- */
.editor { display: flex; flex-direction: column; gap: 22px; }
.form-pad { padding: 18px 20px; }

.banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--r);
    font-family: var(--font-mono);
    font-size: 13px;
    border: 1px solid;
}
.banner--error {
    color: var(--sig-red);
    border-color: rgba(240,82,75,.4);
    background: rgba(240,82,75,.08);
}
.banner__glyph { font-weight: 700; }

.field-row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}
.field { display: flex; flex-direction: column; gap: 7px; flex: 1 1 160px; }
.field__label {
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--ink-faint);
}

.input {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--ink);
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 9px 11px;
    width: 100%;
}
.input:focus-visible { border-color: var(--phos); outline: none; }
.input option { background: var(--bg-3); color: var(--ink); }
.textarea { resize: vertical; line-height: 1.45; }
.code { white-space: pre; overflow-wrap: normal; overflow-x: auto; tab-size: 2; }

.hint {
    margin: 0;
    color: var(--ink-faint);
    font-family: var(--font-mono);
    font-size: 12px;
}

/* payload rows */
.payload-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 0;
    border-bottom: 1px solid var(--line-soft);
}
.payload-row:last-child { border-bottom: none; }
.payload-row__head { display: flex; gap: 10px; align-items: center; }
.input--key { max-width: 220px; }

/* program instruction rows */
.instr-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid var(--line-soft);
    flex-wrap: wrap;
}
.instr-row:last-child { border-bottom: none; }
.instr-row__n {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--ink-faint);
    width: 24px;
    flex: none;
}
.input--op     { width: 88px; flex: none; }
.input--method { width: 92px; flex: none; }
.input--path   { flex: 2 1 200px; width: auto; }
.input--grow   { flex: 1 1 160px; width: auto; }
.instr-row .input { width: auto; flex: 1 1 120px; }
.instr-row__ctl { display: inline-flex; gap: 5px; margin-left: auto; }
.instr-row__ctl .btn--mini { padding: 5px 8px; }
.btn:disabled { opacity: .35; cursor: not-allowed; }

.editor__actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding-top: 4px;
}

/* ---- full-width editor page -------------------------------------------- */
.page-wide {
    max-width: none;
    margin: 0;
    padding: var(--pad);
    display: flex;
    flex-direction: column;
    gap: 22px;
}

.editor-2col {
    display: grid;
    grid-template-columns: 1fr;
    gap: 22px;
    align-items: stretch; /* colonne di pari altezza */
}
@media (min-width: 1000px) {
    .editor-2col { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}
.editor-col { display: flex; flex-direction: column; gap: 22px; min-width: 0; }

/* sezione che si allunga per riempire la colonna (payload) */
.editor-fill { flex: 1 1 auto; display: flex; flex-direction: column; gap: 14px; }
.panel--fill { flex: 1 1 auto; display: flex; flex-direction: column; }
.panel--fill .pane { flex: 1 1 auto; }
.panel--fill .pane .textarea { flex: 1 1 auto; min-height: 180px; }

/* ---- payload tabs ------------------------------------------------------- */
.tabs {
    display: flex;
    gap: 2px;
    padding: 0 8px;
    background: var(--bg-3);
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
}
.tab {
    appearance: none;
    background: transparent;
    border: 0;
    border-bottom: 2px solid transparent;
    color: var(--ink-dim);
    font-family: var(--font-mono);
    font-size: 12px;
    letter-spacing: 0.04em;
    padding: 11px 14px;
    cursor: pointer;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin-bottom: -1px;
}
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--phos); border-bottom-color: var(--phos); }
.tab__warn { color: var(--sig-red); font-size: 9px; }
.tab--add { color: var(--ink-faint); font-size: 15px; font-weight: 700; padding-inline: 14px; }
.tab--add:hover { color: var(--phos); }

.pane { padding: 16px 20px; display: flex; flex-direction: column; gap: 12px; }
.pane__head { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; }
.field--inline { flex: 0 1 240px; }

.json-badge {
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    padding: 4px 9px;
    border-radius: 999px;
    border: 1px solid;
    align-self: center;
}
.json-badge--ok  { color: var(--sig-green); border-color: rgba(63,207,106,.4); }
.json-badge--bad { color: var(--sig-red);   border-color: rgba(240,82,75,.4); }

/* ---- code editor (programma) ------------------------------------------- */
.prog-lang {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.14em;
    color: var(--ink-faint);
}
.code-editor {
    display: flex;
    border: 1px solid var(--line);
    border-radius: var(--r);
    background: var(--bg-2);
    overflow: hidden;
    flex: 1 1 auto;
    min-height: 55vh;
}
/* metriche condivise: il layer evidenziato DEVE combaciare con la textarea */
.code-editor__hl,
.code-editor__input,
.code-editor__ln {
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 20px;
    letter-spacing: 0;
}
.code-editor__gutter {
    flex: none;
    padding: 14px 0;
    background: var(--bg-3);
    border-right: 1px solid var(--line);
    overflow: hidden;
    user-select: none;
    text-align: right;
}
.code-editor__ln { padding: 0 12px; color: var(--ink-faint); }
.code-editor__ln.has-err { color: var(--sig-red); font-weight: 700; }

.code-editor__area { position: relative; flex: 1 1 auto; min-width: 0; }
.code-editor__hl,
.code-editor__input {
    position: absolute;
    inset: 0;
    margin: 0;
    border: 0;
    padding: 14px 16px;
    white-space: pre;
    tab-size: 2;
    overflow: auto;
}
.code-editor__hl {
    z-index: 1;
    pointer-events: none;
    color: var(--ink);
    overflow: hidden;
}
.code-editor__hl code { font: inherit; }
.code-editor__input {
    z-index: 2;
    background: transparent;
    color: transparent;
    caret-color: var(--phos);
    resize: none;
    outline: none;
}
.code-editor__input::selection { background: rgba(69,200,224,.28); }
.code-editor__input::placeholder { color: var(--ink-faint); }

/* token del mini-linguaggio */
.tok-kw      { color: var(--phos); font-weight: 700; }
.tok-method  { color: var(--sig-amber); }
.tok-path    { color: var(--sig-green); }
.tok-ident   { color: #B79CEB; }
.tok-num     { color: #E8896B; }
.tok-secret  { color: var(--ink-dim); font-style: italic; }
.tok-var     { color: #E4C46A; font-weight: 700; }
.tok-op      { color: var(--ink-dim); }
.tok-comment { color: var(--ink-faint); font-style: italic; }
.tok-err     { color: var(--sig-red); text-decoration: underline wavy var(--sig-red); }

/* layout pagina agente: due colonne (sx = semaforo+programma+call, dx = dettaglio) */
/* header: indietro + titolo + semaforo (luci + stato) su una riga */
.agent-head {
    display: flex;
    align-items: center;
    gap: 14px 20px;
    flex-wrap: wrap;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--line);
}
.agent-head .back-link { flex: none; }
.agent-head__title {
    margin: 0;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(20px, 3vw, 30px);
    letter-spacing: 0.03em;
    text-transform: uppercase;
    line-height: 1;
}
.sig-mini { display: inline-flex; align-items: center; gap: 9px; margin-left: auto; }
.sig-mini__lamp {
    width: 14px; height: 14px; border-radius: 50%;
    background: #0E141B; box-shadow: inset 0 0 0 1px rgba(0,0,0,.5); flex: none;
}
.sig-mini__lamp--red   { background: var(--sig-red);   box-shadow: 0 0 10px 1px rgba(240,82,75,.7); }
.sig-mini__lamp--amber { background: var(--sig-amber); box-shadow: 0 0 10px 1px rgba(242,179,61,.6); }
.sig-mini__lamp--green { background: var(--sig-green); box-shadow: 0 0 10px 1px rgba(63,207,106,.7); }
.sig-mini__state {
    font-family: var(--font-display);
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    font-size: 14px;
    margin-left: 4px;
}

.agent-2col {
    display: grid;
    grid-template-columns: 1fr;
    gap: 22px;
    align-items: start;
}
@media (min-width: 1000px) {
    .agent-2col { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
    .agent-col--calls { position: sticky; top: 16px; }
}
.agent-col { display: flex; flex-direction: column; gap: 22px; min-width: 0; }

/* Ultime call: scroll interno del contenuto (non della pagina), intestazione fissa */
.calls-scroll { max-height: calc(100vh - 130px); overflow: auto; }
.calls-scroll thead th { position: sticky; top: 0; z-index: 1; }

/* Pagina agente a tutta altezza: la pagina NON scorre, scorrono i pannelli interni */
@media (min-width: 1000px) {
    .agent-page { height: 100vh; height: 100dvh; overflow: hidden; }
    .agent-page .agent-2col {
        flex: 1 1 auto;
        min-height: 0;
        align-items: stretch;              /* le colonne riempiono l'altezza, non il contenuto */
        grid-template-rows: minmax(0, 1fr); /* riga vincolata all'altezza della griglia */
    }
    .agent-page .agent-col { min-height: 0; }
    .agent-page .agent-col:not(.agent-col--calls) { overflow-y: auto; }   /* colonna sx (programma + dettaglio) */
    .agent-page .agent-col--calls { overflow: hidden; position: static; }  /* colonna dx: header fisso, tabella riempie */
    .agent-page .agent-col--calls .calls-scroll { flex: 1 1 auto; min-height: 0; max-height: none; }
}

/* programma con marker '>' sull'istruzione in esecuzione */
.prog-listing { padding: 10px 0; }
.prog-line {
    display: grid;
    grid-template-columns: 22px 1fr;
    align-items: baseline;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 20px;
    padding: 1px 14px;
}
.prog-line__mark { color: var(--phos); font-weight: 700; text-align: center; }
.prog-line__text { white-space: pre; color: var(--ink-dim); }
.prog-line.is-current { background: rgba(69,200,224,.08); }
.prog-line.is-current .prog-line__text { color: var(--ink); }

/* tabella che manda a capo: scrolla la pagina, non la tabella */
.grid--wrap td { overflow-wrap: anywhere; }

/* righe cliccabili + dettaglio call (pagina agente) */
.row-click { cursor: pointer; }
.row-click:hover td { background: rgba(69,200,224,.06); }
.grid tbody tr.is-selected td { background: rgba(69,200,224,.12); }

.call-detail { display: flex; flex-direction: column; gap: 16px; }
.call-detail__meta { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.call-detail__meta .kv {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--ink-dim);
}
.call-detail__cols {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); /* 2 col dove c'è spazio, sx=richiesta dx=risposta */
    gap: 20px;
    align-items: start;
}
.detail-h {
    margin: 0 0 10px;
    font-family: var(--font-display);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--phos);
}
.detail-sub {
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--ink-faint);
    margin: 12px 0 5px;
}
.detail-pre {
    margin: 0;
    padding: 12px 14px;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--r);
    color: var(--ink);
    font-size: 12px;
    line-height: 1.5;
    max-height: 320px;
    overflow: auto;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* programma in sola lettura (pagina agente) */
.program-src {
    margin: 0;
    padding: 16px 18px;
    color: var(--ink);
    font-size: 13px;
    line-height: 20px;
    overflow-x: auto;
}

.prog-errors {
    border: 1px solid rgba(240,82,75,.35);
    border-radius: var(--r);
    background: rgba(240,82,75,.06);
    padding: 10px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.prog-errors__item {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--ink);
}
.prog-errors__ln {
    color: var(--sig-red);
    font-weight: 700;
    margin-right: 8px;
}
.prog-ok {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--sig-green);
    padding: 4px 2px;
}

/* horizontal scroll guard for tables on narrow screens */
.scroll-x { overflow-x: auto; }

@media (prefers-reduced-motion: reduce) {
    .lamp--green.lamp--live { animation: none; }
    * { scroll-behavior: auto; }
}

/* ---- endpoint dashboard ------------------------------------------------- */
.statbar--link { cursor: pointer; text-decoration: none; transition: border-color .12s ease; }
.statbar--link:hover { border-color: var(--phos-dim); text-decoration: none; }

.note {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--ink-dim);
    margin: 10px 0 0;
}

/* inline p50/p90/p99 mini-bars inside a table cell */
.epbar { display: flex; align-items: center; gap: 3px; min-width: 96px; }
.epbar > i {
    display: block;
    height: 6px;
    border-radius: 2px;
    background: var(--phos-dim);
}
.epbar > i:last-child { background: var(--phos); }

/* detail panel */
.ep-detail {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1px;
    background: var(--line);
    border: 1px solid var(--line);
    border-radius: var(--r);
    overflow: hidden;
}
@media (min-width: 860px) {
    .ep-detail { grid-template-columns: repeat(2, 1fr); }
    .ep-detail__wide { grid-column: 1 / -1; }
}
.ep-cell {
    background: var(--bg-2);
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.ep-cell__label {
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--ink-faint);
}

/* status distribution segmented bar */
.dist { display: flex; height: 14px; border-radius: 3px; overflow: hidden; background: var(--line); }
.dist > i { display: block; height: 100%; }
.dist__2xx { background: var(--sig-green); }
.dist__3xx { background: var(--phos-dim); }
.dist__4xx { background: var(--sig-amber); }
.dist__5xx { background: var(--sig-red); }
.dist__err { background: var(--ink-faint); }
.dist-legend { display: flex; flex-wrap: wrap; gap: 12px; }
.dist-legend span {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--ink-dim);
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.dist-legend b { color: var(--ink); font-weight: 700; }
.swatch { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }

/* timeline svg */
.spark { width: 100%; height: 120px; display: block; }
.spark__line { fill: none; stroke: var(--phos); stroke-width: 1.5; }
.spark__area { fill: var(--phos-dim); opacity: .18; }

/* ---- agent detail: programma | variabili split ------------------------- */
.prog-vars { display: grid; grid-template-columns: 1fr; gap: 18px; }
@media (min-width: 720px) {
    .prog-vars { grid-template-columns: 3fr 2fr; align-items: start; }
}
.prog-vars > section { min-width: 0; }   /* i figli della griglia possono restringersi: abilita l'ellipsis */
.vars-panel { min-height: 60px; padding: 12px 16px; }
.vars-list { display: flex; flex-direction: column; gap: 8px; }
.vars-row { display: flex; gap: 12px; align-items: baseline; min-width: 0; }
.vars-row__k {
    flex: 0 0 auto;
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 700;
    color: var(--phos);
    white-space: nowrap;
}
.vars-row__v {
    flex: 1 1 auto;
    min-width: 0;            /* chiave dell'ellipsis in flex: consente di scendere sotto la larghezza del contenuto */
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--ink);
    white-space: nowrap;     /* una sola riga */
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---- autocomplete (intellisense) del programma ---- */
.ac-pop {
    position: absolute;
    z-index: 5;
    min-width: 160px;
    max-height: 220px;
    overflow-y: auto;
    background: var(--bg-3);
    border: 1px solid var(--line);
    border-radius: var(--r);
    box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 20px;
    padding: 4px 0;
}
.ac-item {
    padding: 2px 12px;
    color: var(--ink-dim);
    cursor: pointer;
    white-space: pre;
}
.ac-item.is-sel {
    background: rgba(69, 200, 224, .18);
    color: var(--ink);
}
.ac-item:hover { color: var(--ink); }
