/* Link Builder — light theme.  Chart colour slots come from the validated default palette. */
:root {
  --page: #f6f7f9; --surface: #ffffff; --surface-2: #f9fafb; --line: #e6e8ec; --line-strong: #d5d8de;
  --text: #111827; --text-2: #4b5563; --muted: #6b7280;
  --primary: #4f46e5; --primary-600: #4338ca; --primary-50: #eef2ff;
  --ok: #047857; --warn: #b45309; --bad: #b91c1c;
  /* chart: outcome series (fixed order) + chrome */
  --series-1: #2a78d6; --series-2: #1baf7a; --series-3: #eb6834;
  --grid: #eef0f3; --axis: #c3c2b7; --tick: #898781;
  /* status (reserved, always with icon + label) */
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --radius: 12px; --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --sidebar: 236px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--page); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; line-height: 1.25; margin: 0; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 4px; font-weight: 650; }
h3 { margin: 8px 0 2px; font-size: 15px; }
p { margin: 4px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.block { display: block; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------------- shell ---------------- */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 8px;
           padding: 18px 14px; background: #0f172a; color: #cbd5e1; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 15px; padding: 4px 8px 14px; }
.brand:hover { text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
              background: linear-gradient(135deg, #6366f1, #22d3ee); color: #fff; font-size: 12px; font-weight: 800; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: #cbd5e1; font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav a.active { background: rgba(99,102,241,.22); color: #fff; }
.nav-ico { width: 18px; text-align: center; opacity: .8; }
.nav-section { margin: 14px 10px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #64748b; }
.sidebar-user { border-top: 1px solid rgba(255,255,255,.08); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.user-chip { display: flex; align-items: center; gap: 10px; color: #e2e8f0; padding: 6px 8px; border-radius: 8px; }
.user-chip:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.avatar { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: #334155; color: #fff; font-weight: 700; }
.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.user-meta small { color: #94a3b8; }
.main { padding: 28px 32px 120px; max-width: 1360px; width: 100%; }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-user { border: 0; padding: 0; flex-direction: row; }
  .main { padding: 18px; }
}

/* ---------------- layout pieces ---------------- */
.page-head, .card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.page-head { margin-bottom: 20px; }
.page-head p { margin: 4px 0 0; }
.card-head { margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
        padding: 18px 20px; margin-bottom: 18px; }
.card.narrow, .form.narrow { max-width: 520px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-bottom: 18px; }
.grid-2 > .card { margin-bottom: 0; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.cols.three { grid-template-columns: 1fr 1fr 1fr; }
.cols.wide-left { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 18px; align-items: start; }
.cols.wide-right { grid-template-columns: minmax(0, 4fr) minmax(0, 8fr); gap: 18px; align-items: start; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
@media (max-width: 1000px) { .grid-2, .cols, .cols.three, .cols.wide-left, .cols.wide-right { grid-template-columns: 1fr; } }
.table-wrap { overflow-x: auto; }

/* ---------------- forms & buttons ---------------- */
.form label { display: block; font-weight: 600; margin-bottom: 12px; font-size: 13px; }
.form label small, .form small { font-weight: 400; color: var(--muted); }
input, select, textarea { width: 100%; font: inherit; padding: 9px 11px; border: 1px solid var(--line-strong);
                          border-radius: 8px; background: #fff; margin-top: 5px; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid #c7d2fe; border-color: var(--primary); }
textarea { resize: vertical; }
input[type=checkbox] { width: auto; margin: 0 8px 0 0; accent-color: var(--primary); }
input[type=file] { padding: 6px; background: var(--surface-2); }
.row input, .row select, .filter-row select { width: auto; margin: 0; }
label.check { display: flex; align-items: center; font-weight: 500; margin-bottom: 8px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 0 0 12px; }
.title-input { font-weight: 650; font-size: 15px; max-width: 360px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
       border: 1px solid var(--line-strong); background: #fff; color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
       white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-600); }
.btn.danger { color: var(--bad); border-color: #fecaca; }
.btn.ghost { background: transparent; border-color: rgba(255,255,255,.14); color: #cbd5e1; }
.btn.ghost:hover { background: rgba(255,255,255,.06); color: #fff; }
.btn.block { width: 100%; padding: 10px; }
.small-btn { padding: 6px 10px; font-size: 12px; width: 100%; }
button.link { background: none; border: 0; padding: 0; color: var(--primary); cursor: pointer; font: inherit; }
button.link.danger, .link.danger { color: var(--bad); }
.actions form, .actions details { display: inline-block; margin-right: 10px; }
.inline-details[open] { display: block; margin-top: 6px; }

/* ---------------- tables, badges, chips ---------------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
tr.removed { opacity: .5; }
details summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.pre { white-space: pre-wrap; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.chip { display: inline-block; padding: 2px 9px; border-radius: 99px; background: var(--primary-50); color: #3730a3; font-size: 12px; margin: 0 4px 4px 0; }
.chip.ok { background: #ecfdf5; color: var(--ok); }
.chip.warn { background: #fffbeb; color: var(--warn); }
.count { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 99px; background: #e0e7ff; color: #3730a3; font-size: 11px; text-align: center; }
.badge { display: inline-block; padding: 1px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: #f3f4f6; color: #374151; white-space: nowrap; }
.s-success, .c-alive { background: #d1fae5; color: #065f46; }
.s-pending_approval, .s-pending_verification, .c-pending { background: #e0f2fe; color: #075985; }
.s-needs_human, .s-skipped, .c-missing, .c-blocked { background: #fef3c7; color: #92400e; }
.s-failed, .c-dead { background: #fee2e2; color: #991b1b; }
.s-running, .s-queued { background: #e0e7ff; color: #3730a3; }
.s-removed { background: #e5e7eb; color: #6b7280; }

/* ---------------- notices ---------------- */
.notice { background: var(--primary-50); border: 1px solid #c7d2fe; border-radius: 10px; padding: 11px 14px; margin-bottom: 16px; }
.notice.warn { background: #fffbeb; border-color: #fde68a; }
.notice.ok { background: #ecfdf5; border-color: #a7f3d0; }
.empty { text-align: center; padding: 36px; }
.steps { text-align: left; max-width: 560px; margin: 12px auto 20px; padding-left: 20px; }
.steps li { margin-bottom: 8px; }
.refresh-banner { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
                  gap: 12px; padding: 8px 16px; background: var(--primary-50); border-bottom: 1px solid #c7d2fe; font-weight: 600; }

/* ---------------- clients ---------------- */
.client-card { color: var(--text); transition: box-shadow .15s, border-color .15s; }
.client-card:hover { text-decoration: none; border-color: #c7d2fe; box-shadow: 0 4px 16px rgba(79,70,229,.10); }
.client-logo { width: 100%; height: 76px; display: flex; align-items: center; justify-content: center;
               background: var(--surface-2); border-radius: 10px; overflow: hidden; }
.client-logo img { max-width: 90%; max-height: 66px; object-fit: contain; }
.client-logo span { font-size: 26px; font-weight: 750; color: var(--primary); }
.client-logo.lg { width: 76px; height: 76px; flex: none; border: 1px solid var(--line); background: #fff; }
.client-logo.sm { width: 40px; height: 40px; flex: none; border: 1px solid var(--line); background: #fff; }
.client-logo.sm span { font-size: 16px; }
.client-logo.sm img { max-height: 34px; }
.client-head { display: flex; align-items: center; gap: 18px; margin-bottom: 20px; }
.crumbs { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.meta-row { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 6px; color: var(--text-2); font-size: 13px; }
.client-list { display: flex; flex-direction: column; }
.client-row { display: flex; align-items: center; gap: 12px; padding: 8px 4px; border-bottom: 1px solid var(--line); color: var(--text); }
.client-row:last-child { border-bottom: 0; }
.client-row:hover { background: var(--surface-2); text-decoration: none; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; overflow-x: auto; }
.tabs a { padding: 10px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--primary); border-color: var(--primary); }
.tabs a:hover { text-decoration: none; color: var(--text); }
.assets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.asset-img { height: 90px; background: var(--surface-2); border: 1px dashed var(--line-strong); border-radius: 8px;
             display: flex; align-items: center; justify-content: center; margin-bottom: 6px; overflow: hidden; }
.asset-img img { max-width: 100%; max-height: 88px; object-fit: contain; }
.asset label { font-size: 12px; }

/* ---------------- statistics ---------------- */
.report.loading [data-tiles], .report.loading [data-frequency], .report.loading .grid-2 { opacity: .55; transition: opacity .15s; }
.filter-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.filter-note { margin-left: auto; }
.segmented { display: inline-flex; background: #fff; border: 1px solid var(--line-strong); border-radius: 9px; padding: 3px; }
.segmented button { border: 0; background: transparent; padding: 6px 14px; border-radius: 6px; font: inherit; font-weight: 600; color: var(--text-2); cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--primary-50); color: var(--primary-600); }
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
@media (max-width: 1100px) { .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat-tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.stat-label { font-size: 12px; color: var(--text-2); font-weight: 600; }
.stat-value { font-size: 26px; font-weight: 650; line-height: 1.2; margin: 4px 0 2px; color: var(--text); }
.stat-note { font-size: 12px; color: var(--muted); }
.viz-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 4px 0 10px; font-size: 12px; color: var(--text-2); }
.viz-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.viz-legend-total { color: var(--text); font-weight: 650; }
.viz-swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.viz-plot { width: 100%; }
.viz-plot svg { display: block; overflow: visible; }
.viz-grid { stroke: var(--grid); stroke-width: 1; }
.viz-axis { stroke: var(--axis); stroke-width: 1; }
.viz-tick { fill: var(--tick); font-size: 11px; font-variant-numeric: tabular-nums; }
.viz-col { cursor: default; outline: none; transition: opacity .12s; }
.viz-col.dim { opacity: .35; }
.viz-col:focus-visible rect[fill="transparent"] { stroke: var(--primary); stroke-width: 1; }
.viz-empty { padding: 36px 0; text-align: center; color: var(--muted); }
.viz-table { margin-top: 10px; }
.viz-table table { margin-top: 8px; font-size: 13px; }
.viz-tooltip { position: fixed; z-index: 50; pointer-events: none; background: #fff; border: 1px solid var(--line);
               border-radius: 10px; box-shadow: 0 8px 24px rgba(15,23,42,.14); padding: 8px 12px; min-width: 150px; font-size: 12px; }
.viz-tooltip-title { color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.viz-tooltip-row { display: flex; align-items: center; gap: 8px; padding: 1px 0; color: var(--text-2); }
.viz-tooltip-row strong { color: var(--text); min-width: 28px; font-variant-numeric: tabular-nums; }
.viz-key-line { width: 12px; height: 2px; border-radius: 2px; display: inline-block; }
.hbars { display: flex; flex-direction: column; gap: 9px; }
.hbar-row { display: grid; grid-template-columns: minmax(90px, 34%) 1fr; align-items: center; gap: 12px; outline: none; }
.hbar-row:hover .hbar-label, .hbar-row:focus-visible .hbar-label { color: var(--text); }
.hbar-label { font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-track { display: flex; align-items: center; min-height: 16px; }
.hbar-seg { height: 14px; }
.hbar-seg.end { border-radius: 0 4px 4px 0; }
.hbar-value { margin-left: 8px; font-size: 12px; font-weight: 650; color: var(--text); font-variant-numeric: tabular-nums; }
.health-row { display: grid; grid-template-columns: 24px 1fr auto 44px; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.health-row:last-child { border-bottom: 0; }
.health-icon { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; font-size: 12px; font-weight: 700; color: #fff; }
.tone-good { background: var(--good); } .tone-warning { background: var(--warning); color: #3b2a00; }
.tone-serious { background: var(--serious); } .tone-critical { background: var(--critical); }
.tone-info { background: var(--series-1); } .tone-muted { background: #9ca3af; }
.health-label { color: var(--text-2); }
.health-pct { color: var(--muted); font-size: 12px; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------------- login ---------------- */
.auth-page { min-height: 100vh; display: grid; place-items: center;
             background: radial-gradient(1200px 600px at 10% -10%, #e0e7ff 0, transparent 60%),
                         radial-gradient(900px 500px at 110% 110%, #cffafe 0, transparent 55%), var(--page); }
.auth-wrap { width: 100%; max-width: 400px; padding: 24px; }
.auth-brand { display: flex; align-items: center; justify-content: center; gap: 10px; font-weight: 700; font-size: 17px; margin-bottom: 18px; }
.auth-card { padding: 28px; }
.auth-card h1 { margin-bottom: 2px; }
.auth-foot { text-align: center; margin-top: 14px; }

/* ---------------- live panel ---------------- */
.live { position: fixed; right: 20px; bottom: 20px; width: 420px; max-height: 70vh; display: flex; flex-direction: column;
        background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 16px 40px rgba(15,23,42,.18); z-index: 30; }
.live-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.live-head strong { flex: 1; font-size: 13px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--good); animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.live-question { padding: 12px 14px; background: #fffbeb; border-bottom: 1px solid #fde68a; }
.live-question.attention { animation: flash 1s 3; }
@keyframes flash { 50% { background: #fde68a; } }
.q-label { font-weight: 700; color: #92400e; }
.live-question p { margin: 6px 0 10px; }
.live-question input { margin-bottom: 8px; }
.live-api { padding: 12px 14px; background: #fef2f2; border-bottom: 1px solid #fecaca; }
.live-api .q-label { color: #991b1b; }
.live-api p { margin: 6px 0; }
.live-events { list-style: none; margin: 0; padding: 8px 14px; overflow-y: auto; font-size: 12px; flex: 1; }
.live-events li { padding: 3px 0; border-bottom: 1px dashed #f1f5f9; }
.live-events .t { color: var(--muted); margin-right: 6px; }
.live-events .k-text { color: var(--text); }
.live-events .k-tool { color: var(--muted); }
.live-events .k-result { font-weight: 700; color: var(--ok); }
.live-events .k-error { font-weight: 700; color: var(--bad); }
.live-events .k-question, .live-events .k-answer { color: #92400e; }
.live.collapsed .live-events { display: none; }
.live-api details { margin: 6px 0 10px; }
.live-api pre { max-height: 160px; overflow: auto; white-space: pre-wrap; word-break: break-word; font-size: 11px;
                background: #fff; border: 1px solid #fecaca; border-radius: 6px; padding: 6px 8px; margin: 6px 0 0; }

/* Live view of the browser on the server (screen.js); sits left of the live panel so its buttons stay usable. */
.screen { position: fixed; top: 20px; left: 20px; right: 460px; bottom: 20px; display: flex; flex-direction: column;
          background: #0f172a; border-radius: 14px; box-shadow: 0 16px 40px rgba(15,23,42,.35); z-index: 31; overflow: hidden; }
.screen-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; color: #e2e8f0; }
.screen-head strong { font-size: 13px; }
.screen-head .muted { flex: 1; color: #94a3b8; }
.screen-view { flex: 1; min-height: 0; background: #020617; position: relative; }
.screen.idle .screen-view::after { content: "No job is running right now. The agent's browser appears here while a job runs.";
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 20px; text-align: center;
  color: #94a3b8; font-size: 14px; pointer-events: none; }
@media (max-width: 1000px) {
  .screen { right: 20px; bottom: auto; height: 50vh; }
}
