/* ═══════════════════════════════════════════════════════════════
   Pulse · Brand Intelligence — shell stylesheet
   Anatomy: top command bar (no sidebar) + centered content column.
   Theming: [data-theme="dark" | "light"] on <html>; dark is default.
   ═══════════════════════════════════════════════════════════════ */

/* ─── Typeface (self-hosted variable Inter — no CDN, works offline) ── */
@font-face {
  font-family: 'Inter';
  src: url('/fonts/InterVariable.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* ─── Tokens ─────────────────────────────────────────────────── */
:root {
  /* Shape — theme-independent */
  --r-xs: 6px;
  --r-sm: 8px;
  --r:    12px;
  --r-lg: 14px;
  --r-xl: 20px;
  --content-w: 1320px;

  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;
}

/* Dark — the default identity (also applies when no data-theme is set) */
:root, :root[data-theme="dark"] {
  color-scheme: dark;

  --bg:       #0a0c16;
  --surface:  #12152a;
  --raised:   #1a1e38;
  --border:   rgba(255,255,255,.07);
  --border-2: rgba(255,255,255,.13);

  --ink:      #eef0fb;
  --ink-2:    #a6abc8;
  --ink-3:    #6d7294;

  --accent:     #818cf8;
  --accent-hi:  #a5b4fc;
  --accent-2:   #a78bfa;
  --accent-bg:  rgba(129,140,248,.10);
  --accent-glow:rgba(129,140,248,.35);

  --pos: #34d399;
  --neg: #f87171;
  --warn:#fbbf24;

  --appbar-bg: rgba(10,12,22,.72);
  --field-bg: rgba(255,255,255,.045);
  --field-bg-focus: rgba(255,255,255,.06);
  --dot: rgba(255,255,255,.05);
  --glow-1: rgba(99,102,241,.16);
  --glow-2: rgba(167,139,250,.10);
  --glow-3: rgba(79,70,229,.10);
  --headline: linear-gradient(120deg, #ffffff 30%, #b6bcf5 100%);
  --scrim-bg: rgba(4,5,12,.6);
  --auth-bg:
    radial-gradient(ellipse 60% 55% at 78% 12%, rgba(99,102,241,.32) 0%, transparent 60%),
    radial-gradient(ellipse 55% 45% at 12% 88%, rgba(79,70,229,.24) 0%, transparent 62%),
    linear-gradient(180deg, #171a34, #0c0e1e);
  --auth-grid: rgba(255,255,255,.045);
  --pill-bg: linear-gradient(135deg, rgba(99,102,241,.38), rgba(139,92,246,.22));
  --pill-border: rgba(139,140,248,.45);
  --pill-shadow: 0 4px 20px rgba(99,102,241,.28), inset 0 1px 0 rgba(255,255,255,.14);

  --sh-xs: 0 1px 2px rgba(0,0,0,.3);
  --sh-sm: 0 1px 3px rgba(0,0,0,.35), 0 4px 14px rgba(0,0,0,.25);
  --sh:    0 6px 24px rgba(0,0,0,.35), 0 1px 3px rgba(0,0,0,.3);
  --sh-lg: 0 24px 70px rgba(0,0,0,.55), 0 4px 18px rgba(0,0,0,.35);
  --sh-accent: 0 4px 22px rgba(99,102,241,.38);
}

/* Light — clean studio look, same brand accent family */
:root[data-theme="light"] {
  color-scheme: light;

  --bg:       #f5f6f9;
  --surface:  #ffffff;
  --raised:   #f3f4f9;
  --border:   rgba(19,22,45,.08);
  --border-2: rgba(19,22,45,.14);

  --ink:      #14172a;
  --ink-2:    #545a72;
  --ink-3:    #8a8fa6;

  --accent:     #4f46e5;
  --accent-hi:  #4338ca;
  --accent-2:   #7c5cf0;
  --accent-bg:  rgba(79,70,229,.07);
  --accent-glow:rgba(79,70,229,.22);

  --pos: #16a34a;
  --neg: #dc2626;
  --warn:#d97706;

  --appbar-bg: rgba(255,255,255,.78);
  --field-bg: #ffffff;
  --field-bg-focus: #ffffff;
  --dot: rgba(19,22,45,.05);
  --glow-1: rgba(99,102,241,.08);
  --glow-2: rgba(167,139,250,.05);
  --glow-3: rgba(79,70,229,.05);
  --headline: linear-gradient(120deg, #14172a 40%, #4f46e5 110%);
  --scrim-bg: rgba(15,17,32,.4);
  --auth-bg:
    radial-gradient(ellipse 60% 55% at 78% 12%, rgba(99,102,241,.14) 0%, transparent 60%),
    radial-gradient(ellipse 55% 45% at 12% 88%, rgba(79,70,229,.10) 0%, transparent 62%),
    linear-gradient(180deg, #eef0fb, #f7f8fd);
  --auth-grid: rgba(19,22,45,.05);
  --pill-bg: linear-gradient(135deg, rgba(79,70,229,.12), rgba(124,92,240,.08));
  --pill-border: rgba(79,70,229,.30);
  --pill-shadow: 0 2px 10px rgba(79,70,229,.14);

  --sh-xs: 0 1px 2px rgba(19,22,45,.04);
  --sh-sm: 0 1px 2px rgba(19,22,45,.05), 0 2px 8px rgba(19,22,45,.05);
  --sh:    0 4px 16px rgba(19,22,45,.08), 0 1px 3px rgba(19,22,45,.05);
  --sh-lg: 0 20px 60px rgba(19,22,45,.14), 0 4px 14px rgba(19,22,45,.07);
  --sh-accent: 0 3px 14px rgba(79,70,229,.28);
}

/* ─── Reset & base ───────────────────────────────────────────── */
*,::before,::after { box-sizing:border-box; margin:0; padding:0 }

/* Clipped on html too — a stray wide element otherwise widens the layout
   viewport on phones and drags the fixed bars off-screen with it. */
html { height:100%; overflow-x: hidden; overflow-x: clip }

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  overflow-x: hidden;
  overflow-x: clip;
  line-height: 1.5;
  transition: background .25s ease, color .25s ease;
}

/* Aurora canvas — layered glows so the field feels deep, not flat */
body::before {
  content: '';
  position: fixed; inset: -20%; z-index: 0; pointer-events: none;
  background:
    radial-gradient(ellipse 42% 34% at 22% 6%,  var(--glow-1) 0%, transparent 60%),
    radial-gradient(ellipse 38% 30% at 82% 12%, var(--glow-2) 0%, transparent 62%),
    radial-gradient(ellipse 46% 36% at 68% 96%, var(--glow-3) 0%, transparent 62%);
  animation: aurora 26s ease-in-out infinite alternate;
}
@keyframes aurora {
  0%   { transform: translate3d(0,0,0) scale(1) }
  100% { transform: translate3d(2.5%,1.5%,0) scale(1.06) }
}
/* Faint dot-grid texture, fading out toward the bottom */
body::after {
  content: '';
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image: radial-gradient(var(--dot) 1px, transparent 1px);
  background-size: 26px 26px;
  mask-image: linear-gradient(180deg, rgba(0,0,0,.55), transparent 70%);
  -webkit-mask-image: linear-gradient(180deg, rgba(0,0,0,.55), transparent 70%);
}
::selection { background: rgba(129,140,248,.35); color: var(--ink) }

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: 750 }
h1 { font-size: 22px; letter-spacing: -.45px }
h2 { font-size: 18px; letter-spacing: -.35px }
h3 { font-size: 14px; letter-spacing: -.15px }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px }

table, .list-stats, .chip, output { font-variant-numeric: tabular-nums }

/* ─── 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, .message {
  font-size: 12.5px;
  color: var(--neg);
  min-height: 16px;
  margin-top: 8px;
}
.error-msg { color: var(--neg) }

/* ─── 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, filter .13s;
  user-select: none;
}

button:disabled, .disabled {
  opacity: .42;
  pointer-events: none;
}

/* Primary — vivid indigo→violet gradient with an outer glow (both themes) */
.primary {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  border-color: transparent;
  box-shadow: var(--sh-accent), inset 0 1px 0 rgba(255,255,255,.22);
}
.primary:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
  box-shadow: 0 8px 30px rgba(99,102,241,.5), inset 0 1px 0 rgba(255,255,255,.22);
}
.primary:active { transform: translateY(0); filter: brightness(.96) }

/* Outline / secondary */
.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);
}

/* Destructive variant — muted until hovered so lists don't scream red */
.secondary.danger { color: var(--ink-3); border-color: var(--border-2) }
.secondary.danger:hover, .secondary.danger:focus-visible {
  background: var(--neg); border-color: var(--neg); color: #fff;
}

.small { min-height: 30px; padding: 0 10px; font-size: 12px }

.icon-btn {
  width: 36px; height: 36px; min-height: 36px; 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 — hero backdrop, glass card ────────────────── */
.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  position: relative;
  z-index: 1;
  background: var(--auth-bg);
}
.auth::before {
  content: '';
  position: absolute; inset: 0; pointer-events: none;
  background-image:
    linear-gradient(var(--auth-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--auth-grid) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: linear-gradient(180deg, rgba(0,0,0,.8), transparent 75%);
  -webkit-mask-image: linear-gradient(180deg, rgba(0,0,0,.8), transparent 75%);
}
.auth-card {
  width: min(410px, 100%);
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--r-xl);
  padding: 34px 32px 30px;
  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: 36px; height: 36px;
  flex-shrink: 0;
  border-radius: 11px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: -.5px;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 12px var(--accent-glow);
}

/* ─── App shell ──────────────────────────────────────────────── */
.app { position: relative; z-index: 1; min-height: 100vh }

/* ─── Top command bar ────────────────────────────────────────── */
.appbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--appbar-bg);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}
.appbar-inner {
  max-width: var(--content-w);
  margin: 0 auto;
  padding: 0 24px;
  min-height: 62px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
}

.appbar-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}
.brand-text { display: grid; line-height: 1.2 }
.brand-name {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -.3px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-sub {
  font-size: 10px;
  color: var(--ink-3);
  letter-spacing: .05em;
}

/* Center nav — segmented pills */
.appnav {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface) 55%, transparent);
}
.navitem {
  min-height: 34px;
  padding: 0 14px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 600;
  gap: 8px;
}
.navitem svg { width: 15px; height: 15px; opacity: .7 }
.navitem:hover { color: var(--ink); background: var(--accent-bg) }
.navitem:hover svg { opacity: 1 }
.navitem.active {
  color: var(--ink);
  background: var(--pill-bg);
  border-color: var(--pill-border);
  box-shadow: var(--pill-shadow);
}
.navitem.active svg { opacity: 1; color: var(--accent) }

/* Right-side actions */
.appbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}
.model-mini {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 0 4px 0 10px;
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--surface) 55%, transparent);
  color: var(--ink-3);
}
.model-mini svg { width: 14px; height: 14px; color: var(--accent); flex: none }
.model-mini select {
  border: 0;
  background: transparent;
  color: var(--ink-2);
  font-size: 12.5px;
  font-weight: 600;
  max-width: 170px;
  text-overflow: ellipsis;
  padding: 6px 4px;
  cursor: pointer;
  outline: none;
}
.model-mini:hover { border-color: var(--border-2) }
.model-mini select:focus { color: var(--ink) }

/* ─── Main content column ────────────────────────────────────── */
.main {
  position: relative;
  max-width: var(--content-w);
  margin: 0 auto;
  padding: 22px 24px 64px;
  min-width: 0;
}

.page-head { padding: 4px 0 18px }
.page-head h2 {
  font-size: 26px;
  letter-spacing: -.6px;
  background: var(--headline);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}
.page-head .eyebrow { margin-bottom: 5px }

/* ─── Status banner ──────────────────────────────────────────── */
.status {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding: 11px 14px;
  border-radius: var(--r);
  border: 1px solid color-mix(in srgb, var(--accent) 28%, transparent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  color: var(--accent-hi);
  font-size: 13px;
  font-weight: 500;
}
:root[data-theme="light"] .status:not([data-tone="error"]) { color: var(--accent) }
.status[data-tone="error"] {
  border-color: color-mix(in srgb, var(--neg) 30%, transparent);
  background: color-mix(in srgb, var(--neg) 8%, transparent);
  color: var(--neg);
}

/* ─── Busy overlay ───────────────────────────────────────────── */
.busy-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  backdrop-filter: blur(8px);
  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 var(--accent-bg);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg) } }

/* ─── 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;
}
.toolbar-lead {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex-wrap: wrap;
}

/* ─── 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(--ink-3);
  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;
}
.chip.dim { color: var(--ink-3); background: var(--raised) }
.chip.sent-positive { color: var(--pos); background: color-mix(in srgb, var(--pos) 12%, transparent) }
.chip.sent-negative { color: var(--neg); background: color-mix(in srgb, var(--neg) 12%, transparent) }
.chip.sent-neutral  { color: var(--ink-2); background: var(--raised) }

/* Inline link-styled button used in guidance copy ("run your first analysis") */
.meta-cta {
  display: inline;
  min-height: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: inherit;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.meta-cta:hover { color: var(--accent-hi) }

/* Aliases used by JS-generated markup */
.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);
}

/* ─── In-app report viewer ───────────────────────────────────── */
.viewer-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.viewer-title {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#report-frame { min-height: 400px }
@media (max-width: 620px) {
  .viewer-title { order: 3; flex-basis: 100% }
}

/* ─── 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: 200px }

/* ─── Table ──────────────────────────────────────────────────── */
.table-scroll { overflow: auto; overscroll-behavior-x: contain }
#mentions-table td a { overflow-wrap: anywhere }
#mentions-table th, #mentions-table td { min-width: 90px }
#mentions-table td:last-child { white-space: nowrap }
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 }

/* ─── Lists (History / Reports) ──────────────────────────────── */
.run-list, .list { display: grid; gap: 10px }

.list-search {
  width: 100%;
  margin-bottom: 12px;
  padding: 10px 14px;
  border: 1px solid var(--border-2);
  border-radius: var(--r-sm);
  background: var(--field-bg);
  font-size: 13.5px;
  color: var(--ink);
}
.list-search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg) }
.list-search::placeholder { color: var(--ink-3) }

.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 }

.run-list .list-row, .list .list-row {
  display: grid;
  grid-template-columns: minmax(150px,210px) minmax(0,1fr) auto auto;
  gap: 16px;
  align-items: center;
  padding: 13px 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;
}
.run-list .list-row:hover, .list .list-row:hover {
  border-color: var(--border-2);
  box-shadow: var(--sh);
  transform: translateY(-1px);
}
.run-list .list-row:focus-visible, .list .list-row:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg), var(--sh);
  outline: none;
}
/* Bare mention-count cell → tidy right-aligned pill */
.run-list .list-row > .row-muted, .list .list-row > .row-muted {
  justify-self: end;
  padding: 4px 11px;
  border-radius: 999px;
  background: var(--raised);
  border: 1px solid var(--border);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.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) }

.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: var(--border-2);
  box-shadow: var(--sh-sm);
  transform: translateY(-1px);
}
.report-row:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg), 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: var(--raised);
  border: 1px solid var(--border-2);
  color: var(--accent);
  box-shadow: inset 0 -10px 18px var(--accent-bg);
}
.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: var(--pill-border);
  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, 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(--field-bg);
  border: 1px solid var(--border-2);
  border-radius: var(--r-sm);
  color: var(--ink);
  outline: none;
  transition: border-color .14s, box-shadow .14s, background .14s;
  font-size: 13px;
}
input:not([type="range"]):not([type="radio"]):not([type="checkbox"]):focus,
select:focus {
  border-color: var(--accent);
  background: var(--field-bg-focus);
  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) }

.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(--field-bg);
  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);
}

.field-hint {
  display: block;
  margin-top: 5px;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--ink-3);
}

/* ─── Settings ───────────────────────────────────────────────── */
.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);
}

.block-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0;
}

/* Credentials guide */
.cred-guide { gap: 18px }
.cred-group {
  display: grid;
  gap: 6px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.cred-group:first-of-type { padding-top: 0; border-top: 0 }
.cred-title { font-size: 14px; font-weight: 700; color: var(--ink); margin: 0 }
.cred-note { font-size: 12.5px; color: var(--ink-2); margin: 0; line-height: 1.5; overflow-wrap: anywhere }
.cred-list { margin: 4px 0 0; padding-left: 18px; display: grid; gap: 5px }
.cred-list li { font-size: 13px; color: var(--ink); line-height: 1.5; overflow-wrap: anywhere }
.cred-tag {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 999px;
  vertical-align: middle;
  margin-left: 6px;
}
.cred-tag.req { color: var(--accent); background: var(--accent-bg) }
.cred-tag.opt { color: var(--ink-3); background: var(--raised) }
.cred-guide code {
  font-size: 12px;
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--raised);
  color: var(--ink-2);
  word-break: break-all;
}

/* Key fields — grouped 2-column grid */
#keys-form { max-width: 820px; overflow: visible } /* keep key-hint tooltips unclipped */
.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 }
}

/* Per-key label + tooltip + link */
.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 }
.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 }
.key-info::after {
  content: attr(data-tip);
  position: absolute;
  left: 0;
  top: calc(100% + 8px);
  z-index: 30;
  width: max-content;
  /* display:none, not visibility — a hidden tooltip still takes up width. */
  display: none;
  max-width: min(260px, calc(100vw - 40px));
  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);
  pointer-events: none;
}
.key-info:hover::after, .key-info:focus::after { display: block }

/* Reveal button for password/key fields — sits inside the field */
.reveal-wrap{position:relative;display:flex;align-items:center}
.reveal-wrap input{flex:1;padding-right:38px}
.reveal-btn{
  position:absolute;right:3px;top:50%;transform:translateY(-50%);
  min-height:0;border:0;background:transparent;padding:5px 8px;
  cursor:pointer;font-size:1.05em;line-height:1;border-radius:6px;
}
.reveal-btn:focus-visible{outline:2px solid var(--accent);outline-offset:0}

/* ─── 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 }

.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: var(--scrim-bg);
  backdrop-filter: blur(4px);
  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, #6366f1, #8b5cf6);
  border: none;
  color: #fff;
  box-shadow: var(--sh-accent);
  display: none;
}
.fab:hover {
  transform: scale(1.06);
  box-shadow: 0 8px 30px rgba(99,102,241,.5);
}
/* Never show the analysis trigger on the login screen */
#app.hidden ~ .fab { display: none !important }

/* ─── Responsive ─────────────────────────────────────────────── */
@media (max-width: 1020px) {
  .appbar-inner {
    grid-template-columns: auto 1fr;
    grid-template-areas: "brand actions" "nav nav";
    padding: 10px 16px;
    gap: 10px;
  }
  .appbar-brand { grid-area: brand }
  .appbar-actions { grid-area: actions }
  .appnav {
    grid-area: nav;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .appnav::-webkit-scrollbar { display: none }
  .navitem { flex: 1 1 0; justify-content: center }
  .model-mini select { max-width: 110px }
  .main { padding: 18px 16px 48px }
}

/* Phones — single-row app bar, nav becomes a fixed bottom tab bar */
@media (max-width: 620px) {
  .brand-sub { display: none }
  #open-controls { display: none }
  .fab { display: grid; bottom: calc(72px + env(safe-area-inset-bottom, 0px)) }

  /* Blur moves to ::before here: backdrop-filter on .appbar would make it the
     containing block for the fixed nav below and pin it to the bar. */
  .appbar {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    background: transparent;
  }
  .appbar::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: -1;
    background: var(--appbar-bg);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
  }
  .appbar-inner {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas: "brand actions";
    padding: 8px 14px;
    gap: 10px;
    min-height: 0;
  }
  .appbar-actions { gap: 6px }
  .model-mini { flex: 0 1 auto }
  .model-mini select { max-width: 96px }

  /* Nav docks to the bottom of the screen */
  .appnav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 35;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 2px;
    padding: 6px 10px calc(6px + env(safe-area-inset-bottom, 0px));
    border: 0;
    border-top: 1px solid var(--border);
    border-radius: 0;
    background: var(--appbar-bg);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
  }
  .navitem {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    min-height: 48px;
    padding: 4px 2px;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: .01em;
    border-radius: 10px;
  }
  .navitem svg { width: 18px; height: 18px }
  .navitem.active {
    background: var(--accent-bg);
    border-color: transparent;
    box-shadow: none;
    color: var(--accent);
  }

  /* Keep content clear of the bottom bar */
  .main { padding-bottom: calc(92px + env(safe-area-inset-bottom, 0px)) }

  /* Controls become a full-screen sheet */
  .drawer, .control-card {
    top: 0; right: 0; bottom: 0; left: 0;
    width: 100%;
    border: 0;
    border-radius: 0;
  }
  .drawer-form, .control-stack {
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  }

  .check-grid, .checks { grid-template-columns: 1fr }
  .run-list .list-row, .list .list-row { grid-template-columns: 1fr; gap: 8px }
  .run-list .list-row > .row-muted, .list .list-row > .row-muted { justify-self: start }
  .report-row { grid-template-columns: 1fr; gap: 12px }
  .report-chevron, .report-file-icon { display: none }
  .report-title-line { align-items: flex-start; flex-direction: column; gap: 6px }
  .panel-toolbar { flex-wrap: wrap }
  .page-head h2 { font-size: 22px }
  th, td { padding: 8px 10px }
}

/* Drop the install shortcut so logout still fits; it stays in the browser menu. */
@media (max-width: 480px) {
  #install-app { display: none }
}

/* Small phones — tighten the app bar so every control stays on screen */
@media (max-width: 400px) {
  .model-mini svg { display: none }
  .model-mini { padding-left: 8px }
  .model-mini select { max-width: 84px; font-size: 12px }
  .appbar-inner { padding: 8px 10px }
  .main { padding-left: 12px; padding-right: 12px }
  .auth-card { padding: 26px 20px 24px }
  .card-header { padding: 12px 14px }
}

/* ─── 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) }

/* ─── Reduced motion ─────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, ::before, ::after { animation: none !important; transition: none !important }
}
