/* Dispatcher Lab playground. Builds on the site's tokens in /styles.css. */

.nav a[aria-current="page"] { color: var(--text); background: var(--accent-soft); }

.pg { padding-top: 40px; padding-bottom: 48px; }
.pg-intro { max-width: 760px; margin-bottom: 24px; }
.pg-intro h1 { font-size: clamp(2rem, 4.5vw, 2.8rem); letter-spacing: -.03em; margin: 6px 0 12px; }
.pg-intro .lead { color: var(--muted); font-size: 1.05rem; }
.pg-intro code, .hint code { font-family: var(--mono); font-size: .9em; background: var(--accent-soft); padding: 1px 5px; border-radius: 5px; }
.pg-meta { color: var(--muted); font-size: .9rem; margin: 0; }

.api-status { display: inline-flex; align-items: center; gap: 8px; font-size: .82rem; font-weight: 600; padding: 3px 11px; border-radius: 999px; background: var(--accent-soft); color: var(--muted); }
.api-status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.api-status[data-state="waking"]::before { animation: pulse 1s ease-in-out infinite; }
.api-status[data-state="up"] { background: var(--ok-soft); color: var(--ok); }
.api-status[data-state="down"] { background: #fde8e6; color: #b3261e; }
@keyframes pulse { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .api-status[data-state="waking"]::before { animation: none; } }

/* Form */
.pg-form { display: grid; gap: 16px; }
.pg-toolbar { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 12px; }
.pg-select { display: grid; gap: 6px; font-size: .9rem; font-weight: 600; }
.pg-select select { font: inherit; font-weight: 400; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; min-width: 240px; }
.pg-actions { display: flex; gap: 10px; }
.pg-actions .btn { cursor: pointer; font: inherit; font-weight: 600; }
.pg-actions .btn:disabled { opacity: .6; cursor: progress; }

.pg-inputs { display: grid; grid-template-columns: 3fr 2fr; gap: 16px; }
@media (max-width: 820px) { .pg-inputs { grid-template-columns: 1fr; } }
.pg-inputs .field label { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.hint { font-weight: 400; color: var(--muted); font-size: .82rem; }
textarea.code {
  width: 100%; resize: vertical; min-height: 260px;
  font: 13px/1.55 var(--mono); tab-size: 2; white-space: pre; overflow: auto;
  color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px;
}
textarea.code:focus { outline: none; border-color: var(--accent-strong); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.code::selection { background: color-mix(in srgb, var(--accent-strong) 35%, transparent); }

.pg-status { margin: 0; min-height: 1.4em; font-size: .92rem; color: var(--muted); }
.pg-status.is-error { color: #b3261e; font-weight: 600; }
.pg-status.is-ok { color: var(--ok); font-weight: 600; }

/* Results */
.pg-results { display: grid; gap: 16px; margin-top: 24px; scroll-margin-top: 80px; }
.pg-results:empty { display: none; }
/* Grid children default to min-width:auto, which lets the wide trace table stretch them past the
   viewport on phones; let them shrink so the table scrolls inside its own container instead. */
.pg-results > *, .pg-form > *, .pg-inputs > *, .outcome > * { min-width: 0; }
.summary { display: flex; flex-wrap: wrap; gap: 8px 24px; font-size: .95rem; color: var(--muted); }
.summary strong { color: var(--text); font-size: 1.1rem; }
.summary code { font-family: var(--mono); }
.sum-allow strong { color: var(--ok); }
.sum-deny strong { color: #b3261e; }

.diagnostics h2 { font-size: 1rem; margin-bottom: 10px; }
.diagnostics ul { list-style: none; display: grid; gap: 8px; }
.diag { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; font-size: .92rem; }
.sev { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; padding: 2px 7px; border-radius: 6px; }
.diag-error .sev { background: #fde8e6; color: #b3261e; }
.diag-warning .sev { background: #fdf1d8; color: #8a5a00; }
.diag-info .sev { background: var(--accent-soft); color: var(--accent); }

.outcome { padding: 18px 20px; display: grid; gap: 12px; }
.outcome-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; }
.req { font-family: var(--mono); font-size: .95rem; font-weight: 600; word-break: break-all; }
.verdict { font-size: .85rem; font-weight: 700; padding: 4px 12px; border-radius: 999px; white-space: nowrap; }
.verdict.is-allow { background: var(--ok-soft); color: var(--ok); }
.verdict.is-deny { background: #fde8e6; color: #b3261e; }
.verdict.is-invalid { background: #fdf1d8; color: #8a5a00; }
.why { margin: 0; color: var(--muted); }
.why.warn { color: #8a5a00; }

.rule-link { white-space: nowrap; font: 600 .9rem var(--mono); color: var(--accent-strong); background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.rule-link .muted { font-family: var(--font); font-weight: 400; text-decoration: none; }
.muted { color: var(--muted); }

.decomp { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px 16px; margin: 0; padding: 10px 12px; background: var(--bg); border-radius: 10px; }
.decomp > div { min-width: 0; }
.decomp dt { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.decomp dd { margin: 2px 0 6px; word-break: break-all; }
.decomp code { font-family: var(--mono); font-size: .88rem; }

.trace-details summary { cursor: pointer; font-weight: 600; font-size: .92rem; color: var(--accent-strong); }
.trace-wrap { overflow-x: auto; margin-top: 10px; border: 1px solid var(--border); border-radius: 10px; }
.trace { width: 100%; border-collapse: collapse; font-size: .86rem; }
.trace th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); background: var(--bg); padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.trace td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.trace tr:last-child td { border-bottom: 0; }
.trace tr.unmatched { opacity: .55; }
.trace tr.deciding { background: color-mix(in srgb, var(--accent-strong) 10%, transparent); opacity: 1; }
.trace tr.deciding td:first-child { box-shadow: inset 3px 0 0 var(--accent-strong); }
.trace .match { white-space: nowrap; font-weight: 600; }
.type { font: 700 .75rem var(--mono); padding: 2px 7px; border-radius: 6px; }
.type-allow { background: var(--ok-soft); color: var(--ok); }
.type-deny { background: #fde8e6; color: #b3261e; }
.cond { font-family: var(--mono); font-size: .82rem; margin: 2px 0; word-break: break-all; }
.cond code { font-family: inherit; }
.cond .pattern { color: var(--accent-strong); }
.cond.ok .mark { color: var(--ok); font-weight: 700; }
.cond.ko .mark { color: #b3261e; font-weight: 700; }

kbd { font: 600 .78rem var(--mono); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; background: var(--surface); }

/* Dark theme tweaks for the fixed red/amber colours */
:root[data-theme="dark"] .verdict.is-deny, :root[data-theme="dark"] .type-deny, :root[data-theme="dark"] .diag-error .sev, :root[data-theme="dark"] .api-status[data-state="down"] { background: #3b1513; color: #ff8a80; }
:root[data-theme="dark"] .verdict.is-invalid, :root[data-theme="dark"] .diag-warning .sev { background: #3a2c0c; color: #f5c76b; }
:root[data-theme="dark"] .pg-status.is-error, :root[data-theme="dark"] .sum-deny strong { color: #ff8a80; }
:root[data-theme="dark"] .why.warn { color: #f5c76b; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .verdict.is-deny, :root:not([data-theme="light"]) .type-deny, :root:not([data-theme="light"]) .diag-error .sev, :root:not([data-theme="light"]) .api-status[data-state="down"] { background: #3b1513; color: #ff8a80; }
  :root:not([data-theme="light"]) .verdict.is-invalid, :root:not([data-theme="light"]) .diag-warning .sev { background: #3a2c0c; color: #f5c76b; }
  :root:not([data-theme="light"]) .pg-status.is-error, :root:not([data-theme="light"]) .sum-deny strong { color: #ff8a80; }
  :root:not([data-theme="light"]) .why.warn { color: #f5c76b; }
}
