/* ─── Design tokens ─────────────────────────────────────────── */
:root {
  color-scheme: light;

  /* Palette */
  --bg:       #f0f2fa;
  --surface:  #ffffff;
  --raised:   #f7f8fd;
  --border:   rgba(0,0,0,.07);
  --border-2: rgba(0,0,0,.13);

  /* Text */
  --ink:      #0c0d1c;
  --ink-2:    #4f5478;
  --ink-3:    #9295b0;

  /* Accent (indigo) */
  --accent:     #5b5bd6;
  --accent-hi:  #4f46e5;
  --accent-2:   #8b5cf6;
  --accent-bg:  rgba(91,91,214,.07);
  --accent-glow:rgba(91,91,214,.20);

  /* Semantic */
  --pos: #16a34a;
  --neg: #dc2626;
  --warn:#b45309;

  /* Elevation */
  --sh-xs: 0 1px 2px rgba(0,0,0,.05);
  --sh-sm: 0 1px 3px rgba(0,0,0,.07), 0 3px 10px rgba(0,0,0,.05);
  --sh:    0 4px 24px rgba(0,0,0,.08), 0 1px 4px rgba(0,0,0,.04);
  --sh-lg: 0 20px 60px rgba(0,0,0,.11), 0 4px 16px rgba(0,0,0,.06);
  --sh-accent: 0 4px 20px rgba(91,91,214,.28);

  /* Shape */
  --r-xs: 6px;
  --r-sm: 8px;
  --r:    12px;
  --r-lg: 16px;
  --r-xl: 22px;

  /* Sidebar */
  --sidebar-w: 230px;

  font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-feature-settings: 'cv01','cv02','cv03','cv04','ss01';
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ─── Reset ─────────────────────────────────────────────────── */
*,::before,::after { box-sizing:border-box; margin:0; padding:0 }

html { height:100% }

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  overflow-x: hidden;
  line-height: 1.5;
}

/* Ambient gradient blobs */
body::before {
  content: '';
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(ellipse 75% 45% at 18% -12%, rgba(91,91,214,.09) 0%, transparent 65%),
    radial-gradient(ellipse 55% 35% at 90% 105%, rgba(139,92,246,.07) 0%, transparent 65%);
}

img, svg { display: block }
button, input, select, textarea { font: inherit; color: inherit }
a { color: var(--accent) }
h1, h2, h3 { line-height: 1.25; font-weight: 700 }
h1 { font-size: 22px; letter-spacing: -.3px }
h2 { font-size: 18px; letter-spacing: -.2px }
h3 { font-size: 14px; letter-spacing: -.1px }

/* ─── Utility ───────────────────────────────────────────────── */
.hidden { display: none !important }

.eyebrow {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--accent);
  line-height: 1;
}

.dim-text { font-size: 13px; color: var(--ink-2) }

.msg {
  font-size: 12.5px;
  color: var(--neg);
  min-height: 16px;
  margin-top: 8px;
}

/* ─── Buttons ───────────────────────────────────────────────── */
button, a.link-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 14px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: background .13s, color .13s, border-color .13s,
              box-shadow .13s, transform .1s, opacity .13s;
  user-select: none;
}

button:disabled, .disabled {
  opacity: .42;
  pointer-events: none;
}

/* Primary — gradient indigo */
.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border-color: transparent;
  box-shadow: var(--sh-accent);
}
.primary:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
  box-shadow: 0 6px 28px var(--accent-glow);
}
.primary:active { transform: translateY(0); filter: brightness(.96) }

/* Outline */
.btn-outline, .secondary {
  background: var(--surface);
  border-color: var(--border-2);
  color: var(--ink-2);
}
.btn-outline:hover, .secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-bg);
}

.small { min-height: 30px; padding: 0 10px; font-size: 12px }

/* Icon button */
.icon-btn {
  width: 34px; height: 34px; min-height: 34px; padding: 0;
  border-radius: var(--r-sm);
  background: transparent;
  border-color: var(--border-2);
  color: var(--ink-3);
}
.icon-btn:hover { background: var(--accent-bg); color: var(--accent); border-color: var(--accent) }

.btn-group, .actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap }

/* ─── Auth screen ────────────────────────────────────────────── */
.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  position: relative;
  z-index: 1;
}

.auth-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--r-xl);
  padding: 32px 30px 28px;
  box-shadow: var(--sh-lg);
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}

.auth-logo h1 { font-size: 20px }

.auth-form { display: grid; gap: 14px }

/* ─── Brand mark ─────────────────────────────────────────────── */
.brand-mark {
  width: 38px; height: 38px;
  flex-shrink: 0;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: -.5px;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 10px var(--accent-glow);
}

/* ─── App shell ──────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0,1fr);
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

/* ─── Sidebar ────────────────────────────────────────────────── */
.sidebar {
  height: 100vh;
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  background: #141d41;
  border-right: 1px solid #c9cdea;
  overflow-y: auto;
}

/* Sidebar uses a dark surface — flip its text/dividers to light */
.sidebar .brand-name { color: #fff }
.sidebar .brand-sub { color: rgba(255,255,255,.55) }
.sidebar-brand { border-bottom-color: rgba(255,255,255,.12) }
.sidebar-footer { border-top-color: rgba(255,255,255,.12) }

.sidebar .tab,
.sidebar .navitem { color: rgba(255,255,255,.72) }
.sidebar .tab:hover,
.sidebar .navitem:hover {
  color: #fff;
  background: rgba(255,255,255,.08);
  border-color: rgba(255,255,255,.12);
}
.sidebar .tab.active,
.sidebar .navitem.active {
  color: #fff;
  background: rgba(255,255,255,.12);
  border-color: rgba(255,255,255,.16);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 6px 4px 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.brand-name {
  display: block;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -.3px;
  color: var(--ink);
  line-height: 1.2;
}

.brand-sub {
  display: block;
  font-size: 10px;
  color: var(--ink-3);
  letter-spacing: .04em;
  margin-top: 1px;
}

/* ─── Sidebar nav ────────────────────────────────────────────── */
.sidenav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.sidebar-section {
  padding: 14px 4px 4px;
  margin-top: 8px;
  border-top: 1px solid rgba(255,255,255,.12);
  display: grid;
  gap: 8px;
}
.sidebar-section .block-label { color: rgba(255,255,255,.6) }
.sidebar-section .field > span { color: rgba(255,255,255,.72) }
.sidebar-note { font-size: 12px; color: rgba(255,255,255,.5); margin: 0 }

/* Alias — JS targets .tab for switchTab */
.tab, .navitem {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-2);
  font-size: 13.5px;
  font-weight: 550;
  cursor: pointer;
  transition: all .14s;
  text-align: left;
  position: relative;
}

.tab svg, .navitem svg {
  width: 16px; height: 16px;
  flex-shrink: 0;
  opacity: .65;
  transition: opacity .14s;
}

.tab:hover, .navitem:hover {
  color: var(--ink);
  background: var(--raised);
  border-color: var(--border);
}

.tab:hover svg, .navitem:hover svg { opacity: 1 }

.tab.active, .navitem.active {
  color: var(--accent);
  background: var(--accent-bg);
  border-color: rgba(91,91,214,.18);
  font-weight: 650;
}

.tab.active svg, .navitem.active svg { opacity: 1 }

.tab.active::before, .navitem.active::before {
  content: '';
  position: absolute;
  left: -1px; top: 50%;
  width: 3px; height: 18px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
  transform: translateY(-50%);
}

.sidebar-footer {
  padding-top: 10px;
  border-top: 1px solid var(--border);
  margin-top: 12px;
}

.logout-nav {
  color: var(--ink-3);
  width: 100%;
}
.logout-nav:hover {
  color: var(--neg);
  background: rgba(220,38,38,.06);
  border-color: rgba(220,38,38,.15);
}

/* ─── Main content area ──────────────────────────────────────── */
.main {
  min-width: 0;
  position: relative;
  padding: 0 28px 48px;
}

.busy-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(6px);
  border-radius: var(--r);
  color: var(--ink);
  font-weight: 600;
  font-size: 14px;
  text-align: center;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
}

.busy-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.busy-spinner {
  width: 22px;
  height: 22px;
  border: 3px solid rgba(15, 143, 131, .25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

/* Per-field label + a small ⓘ with a hover/focus tooltip carrying the help text. */
.key-label { font-weight: 600; display: inline-flex; align-items: center; gap: 6px }
.key-info {
  position: relative;
  font-weight: 400;
  font-size: 12px;
  color: var(--ink-2);
  opacity: .6;
  cursor: help;
}
.key-info:hover, .key-info:focus { opacity: 1; color: var(--accent); outline: none }
/* "Get key ↗" link beside a key label */
.key-link {
  font-weight: 500;
  font-size: 11.5px;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
}
.key-link:hover, .key-link:focus { text-decoration: underline }
/* The tooltip bubble (content comes from data-tip). */
.key-info::after {
  content: attr(data-tip);
  position: absolute;
  left: 0;
  top: calc(100% + 8px);
  z-index: 30;
  width: max-content;
  max-width: 260px;
  white-space: normal;
  font-weight: 400;
  font-size: 12px;
  line-height: 1.45;
  color: #fff;
  background: #1f2533;
  padding: 8px 10px;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,.22);
  opacity: 0;
  visibility: hidden;
  transition: opacity .12s ease;
  pointer-events: none;
}
.key-info:hover::after, .key-info:focus::after { opacity: 1; visibility: visible }

/* Reveal button for password/key fields */
.reveal-wrap{display:flex;align-items:center}
.reveal-wrap input{flex:1}
.reveal-btn{border:0;background:transparent;padding:0 8px;cursor:pointer;font-size:1.05em}
.reveal-btn:focus{outline:2px solid rgba(0,0,0,0.1)}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─── Top bar ────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 0 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 22px;
}

.topbar-left { display: flex; flex-direction: column; gap: 3px }
.topbar-left h2 { margin: 0 }
.topbar-right { display: flex; gap: 8px }

/* ─── Status banner ──────────────────────────────────────────── */
.status {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding: 11px 14px;
  border-radius: var(--r);
  border: 1px solid rgba(91,91,214,.22);
  background: rgba(91,91,214,.06);
  color: var(--accent-hi);
  font-size: 13px;
  font-weight: 500;
}

.status[data-tone="error"] {
  border-color: rgba(220,38,38,.22);
  background: rgba(220,38,38,.06);
  color: var(--neg);
}

/* ─── Panels ─────────────────────────────────────────────────── */
.panel { display: none }
.panel.active { display: block }

.panel-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  min-height: 36px;
}

/* ─── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-sm);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.card-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.card.collapsed .table-scroll {
  display: none;
}

.card.collapsed .card-header {
  padding-bottom: 14px;
}

.card.collapsed .card-title::after {
  content: " (collapsed)";
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--accent-bg);
  color: var(--accent);
  font-size: 11.5px;
  font-weight: 700;
}

/* Alias used in JS-generated HTML */
.table-wrap, .report-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-sm);
  overflow: hidden;
}

.table-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

/* ─── Dashboard iframe ───────────────────────────────────────── */
.iframe-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-sm);
  overflow: hidden;
}

iframe {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
}

#dashboard-frame { min-height: 720px }

/* ─── Table ──────────────────────────────────────────────────── */
.table-scroll { overflow: auto }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

th, td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--ink-3);
  background: var(--raised);
}

tr:last-child td { border-bottom: 0 }
tbody tr:hover td { background: var(--raised) }

td a { color: var(--accent); text-decoration: none }
td a:hover { text-decoration: underline }

/* ─── Run list (History / Reports) ──────────────────────────── */
.run-list, .list { display: grid; gap: 10px }

/* List search + pagination */
.list-search {
  width: 100%;
  margin-bottom: 12px;
  padding: 10px 14px;
  border: 1px solid var(--border-2);
  border-radius: var(--r-sm);
  background: var(--surface);
  font-size: 13.5px;
}
.list-search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg) }
.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 14px;
}
.pager .dim-text { min-width: 110px; text-align: center }

.list-stats {
  margin: -4px 0 12px;
}

.report-item {
  display: grid;
}

.report-item + .report-item {
  margin-top: 2px;
}

/* Targets JS-generated article.list-row */
.run-list .list-row, .list .list-row {
  display: grid;
  grid-template-columns: 175px minmax(0,1fr) 140px auto;
  gap: 14px;
  align-items: center;
  padding: 15px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-xs);
  cursor: pointer;
  transition: border-color .14s, box-shadow .14s, transform .12s;
}

.run-list .list-row:hover, .list .list-row:hover {
  border-color: rgba(91,91,214,.26);
  box-shadow: var(--sh);
  transform: translateY(-1px);
}

.run-list .list-row:focus-visible, .list .list-row:focus-visible {
  border-color: rgba(91,91,214,.55);
  box-shadow: 0 0 0 3px rgba(91,91,214,.14), var(--sh);
  outline: none;
}

/* Checkbox + first cell of a history row */
.row-lead { display: flex; align-items: center; gap: 12px; min-width: 0 }
.run-check { width: 16px; height: 16px; flex: none; cursor: pointer; accent-color: var(--accent) }

/* Destructive button variant (reuses .secondary sizing) */
.secondary.danger { color: var(--neg); border-color: var(--neg) }
.secondary.danger:hover { background: var(--neg); border-color: var(--neg); color: #fff }

.report-row {
  display: grid;
  grid-template-columns: 34px minmax(0,1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--sh-xs);
  cursor: pointer;
  transition: border-color .14s, box-shadow .14s, transform .12s, background .14s;
}

.report-row:hover {
  border-color: rgba(91,91,214,.28);
  box-shadow: var(--sh-sm);
  transform: translateY(-1px);
}

.report-row:focus-visible {
  border-color: rgba(91,91,214,.55);
  box-shadow: 0 0 0 3px rgba(91,91,214,.14), var(--sh-sm);
  outline: none;
}

.report-chevron {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--raised);
  border: 1px solid var(--border);
  color: var(--accent);
  font-weight: 800;
  line-height: 1;
}

.report-file-icon {
  width: 34px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: #f8fafc;
  border: 1px solid rgba(0,0,0,.10);
  color: var(--accent);
  box-shadow: inset 0 -10px 18px rgba(91,91,214,.05);
}

.report-file-icon svg {
  width: 20px;
  height: 20px;
}

.report-row-main {
  min-width: 0;
  display: grid;
  gap: 5px;
}

.report-title-line {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.report-title {
  color: var(--ink);
  font-size: 14px;
  font-weight: 750;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.report-badge {
  flex: 0 0 auto;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--accent-bg);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
}

.report-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  color: var(--ink-2);
  font-size: 12px;
}

.report-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.report-item.open .report-row {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-color: rgba(91,91,214,.22);
  background: linear-gradient(180deg, var(--surface), var(--raised));
}

.row-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-muted {
  font-size: 12px;
  color: var(--ink-2);
  margin-top: 2px;
}

/* ─── Forms / field ──────────────────────────────────────────── */
.field, label {
  display: grid;
  gap: 6px;
}

.field > span, label > span {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
}

input:not([type="range"]):not([type="radio"]):not([type="checkbox"]),
select {
  width: 100%;
  min-height: 38px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--r-sm);
  color: var(--ink);
  outline: none;
  transition: border-color .14s, box-shadow .14s;
  font-size: 13px;
}

input:not([type="range"]):not([type="radio"]):not([type="checkbox"]):focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

output {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
}

/* Checkbox grid */
.check-grid, .checks {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 7px;
}

.check-grid label, .checks label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid var(--border-2);
  border-radius: var(--r-sm);
  background: var(--surface);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-2);
  cursor: pointer;
  transition: all .13s;
  min-height: 34px;
  overflow: hidden;
}

.check-grid label:has(input:checked),
.checks label:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-bg);
  color: var(--ink);
}

.check-grid input[type="checkbox"],
.checks input[type="checkbox"] {
  width: 14px; height: 14px;
  min-height: 14px;
  flex-shrink: 0;
  accent-color: var(--accent);
}

/* Segmented toggle */
.seg, .segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--raised);
  border: 1px solid var(--border-2);
  border-radius: 10px;
  overflow: hidden;
  padding: 3px;
  gap: 3px;
}

.seg label, .segmented label {
  display: grid;
  place-items: center;
  min-height: 34px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  cursor: pointer;
  transition: all .14s;
}

.seg input[type="radio"],
.segmented input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.seg input:checked + span,
.segmented input:checked + span {
  display: block;
  width: 100%; height: 100%;
  line-height: 34px;
  text-align: center;
  border-radius: 8px;
  background: var(--surface);
  color: var(--accent);
  font-weight: 700;
  box-shadow: var(--sh-xs);
}

/* ─── Settings card ──────────────────────────────────────────── */
.settings-card, .settings-form {
  max-width: 560px;
  display: grid;
  gap: 14px;
  padding: 20px;
  margin-top: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-sm);
}

.message {
  font-size: 12.5px;
  color: var(--neg);
  min-height: 16px;
  margin-top: 4px;
}

/* Keys grouped into sections; each section's fields are a 2-column grid. */
#keys-form { max-width: 820px }
.keys-group-title { margin: 8px 0 0 }
.keys-group-title:first-child { margin-top: 0 }
.keys-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 20px;
  align-items: start;
}
.keys-grid > label { min-width: 0 }
@media (max-width: 720px) {
  #keys-form { max-width: 560px }
  .keys-grid { grid-template-columns: 1fr }
}

/* ─── Drawer ─────────────────────────────────────────────────── */
.drawer, .control-card {
  position: fixed;
  top: 14px; right: 14px; bottom: 14px;
  width: min(460px, calc(100vw - 28px));
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--r-xl);
  box-shadow: var(--sh-lg);
  transform: translateX(calc(100% + 20px));
  transition: transform .22s cubic-bezier(.4,0,.2,1);
  overflow: hidden;
}

.drawer.open, .control-card.open {
  transform: translateX(0);
}

.drawer-head, .control-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.drawer-head h2, .control-title h2 { margin: 0; font-size: 16px }

.drawer-form, .control-stack {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow-y: auto;
  padding: 0 20px 20px;
  gap: 0;
}

.form-block, .control-stack section {
  padding-top: 20px;
  display: grid;
  gap: 12px;
  border-top: 1px solid var(--border);
  margin-top: 20px;
}

.form-block:first-child,
.control-stack section:first-child { border-top: 0; margin-top: 0 }

.block-label, .control-stack h2 {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0;
}

.row-gap, .sources-actions { display: flex; gap: 8px }

.run-btn {
  width: 100%;
  min-height: 42px;
  margin-top: 20px;
  font-size: 14px;
  border-radius: var(--r);
}

/* Scrim */
.scrim, .drawer-scrim {
  position: fixed; inset: 0;
  z-index: 40;
  background: rgba(7,8,15,.45);
  backdrop-filter: blur(3px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}

.scrim.open, .drawer-scrim.open {
  opacity: 1;
  pointer-events: auto;
}

/* ─── FAB (mobile controls trigger) ─────────────────────────── */
.fab {
  position: fixed;
  bottom: 20px; right: 20px;
  z-index: 30;
  width: 50px; height: 50px; min-height: 50px; padding: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  color: #fff;
  box-shadow: var(--sh-accent);
  display: none;
}

.fab:hover {
  transform: scale(1.06);
  box-shadow: 0 6px 28px var(--accent-glow);
}

/* ─── Responsive ─────────────────────────────────────────────── */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr }

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 12px 14px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-brand {
    border-bottom: 0; padding-bottom: 0; margin-bottom: 0;
    flex: 0 0 auto;
  }

  .sidenav { flex-direction: row; flex: 1; flex-wrap: wrap }

  .tab, .navitem { width: auto; flex: 0 0 auto }
  .tab.active::before, .navitem.active::before { display: none }

  .sidebar-footer { padding-top: 0; border-top: 0; margin-top: 0 }

  .main { padding: 0 16px 32px }
  .topbar { padding-top: 16px; margin-bottom: 16px }

  .run-list .list-row, .list .list-row { grid-template-columns: 1fr 1fr }
  .report-row { grid-template-columns: 34px minmax(0,1fr) }
  .report-actions { grid-column: 2; justify-content: flex-start }

  .fab { display: grid }
  #open-controls { display: none }
}

@media (max-width: 620px) {
  .check-grid, .checks { grid-template-columns: 1fr }
  .run-list .list-row, .list .list-row { grid-template-columns: 1fr }
  .report-row { grid-template-columns: 1fr; gap: 12px }
  .report-chevron { display: none }
  .report-actions { grid-column: auto }
  .report-title-line { align-items: flex-start; flex-direction: column; gap: 6px }
  .panel-toolbar { flex-wrap: wrap }
}

/* ─── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px }
::-webkit-scrollbar-track { background: transparent }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 999px }
::-webkit-scrollbar-thumb:hover { background: var(--ink-3) }
