/* Tailwind Play CDN supplies the utility layer; this file keeps app-specific components consistent. */

:root {
  color-scheme: light;
  --bg: #f6f9fc;
  --surface: rgba(255, 255, 255, 0.92);
  --surface-muted: #f8fafc;
  --surface-strong: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --slate: #334155;
  --line: rgba(15, 23, 42, 0.1);
  --line-strong: rgba(37, 99, 235, 0.22);
  --brand: #2563eb;
  --brand-strong: #14b8a6;
  --brand-soft: rgba(37, 99, 235, 0.08);
  --green: #16a34a;
  --green-soft: rgba(22, 163, 74, 0.1);
  --amber: #f59e0b;
  --amber-soft: rgba(245, 158, 11, 0.12);
  --rose: #e11d48;
  --rose-soft: rgba(225, 29, 72, 0.09);
  --violet: #7c3aed;
  --violet-soft: rgba(124, 58, 237, 0.09);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-panel: 0 18px 48px rgba(15, 23, 42, 0.08);
  --radius: 8px;
  --font-heading: "Space Grotesk", "Google Sans Flex", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, #ffffff 0%, #f7fbff 44%, #eef4f8 100%),
    repeating-linear-gradient(90deg, rgba(37, 99, 235, 0.04) 0 1px, transparent 1px 86px),
    repeating-linear-gradient(0deg, rgba(20, 184, 166, 0.035) 0 1px, transparent 1px 86px),
    var(--bg);
  color: var(--ink);
  font-family: "Google Sans Flex", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(37, 99, 235, 0.08), transparent 34%, rgba(20, 184, 166, 0.07)),
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), transparent 42%);
  mask-image: linear-gradient(180deg, #000 0, transparent 62%);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
}

button,
select,
summary,
input[type="checkbox"] {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.18);
  outline-offset: 2px;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1420px, 100%);
  margin: 0 auto;
  padding: 24px 16px 52px;
}

@media (min-width: 640px) {
  .app-shell {
    padding-right: 24px;
    padding-left: 24px;
  }
}

@media (min-width: 1024px) {
  .app-shell {
    padding-right: 32px;
    padding-left: 32px;
  }
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 24px;
  margin-bottom: 18px;
  padding: 8px 0 20px;
  border-bottom: 1px solid var(--line);
}

.app-header h1 {
  margin: 4px 0 0;
  color: var(--ink);
  font-family: var(--font-heading);
  font-size: 40px;
  line-height: 1.05;
  font-weight: 700;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  color: var(--brand);
  font-size: 12px;
  font-weight: 780;
  letter-spacing: 0;
  text-transform: uppercase;
}

.header-meta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid rgba(37, 99, 235, 0.16);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--slate);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(12px);
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--green);
  box-shadow: 0 0 0 5px rgba(22, 163, 74, 0.1), 0 0 18px rgba(22, 163, 74, 0.28);
}

.control-band,
.settings-panel,
.dropzone,
.insight-panel,
.data-panel,
.kpi-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-panel);
  backdrop-filter: blur(16px);
}

.control-band::before,
.settings-panel::before,
.insight-panel::before,
.data-panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(37, 99, 235, 0.42), rgba(20, 184, 166, 0.34), transparent);
}

.control-band {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 136px 112px minmax(520px, auto);
  gap: 12px;
  align-items: end;
  padding: 16px;
  margin-bottom: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label {
  color: var(--slate);
  font-size: 12px;
  font-weight: 760;
  letter-spacing: 0;
}

.field input,
.field select,
.filter-bar input:not([type="checkbox"]),
.filter-bar select,
.builder-controls select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 0 11px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--ink);
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
  transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

.field input::placeholder,
.filter-bar input:not([type="checkbox"])::placeholder {
  color: #94a3b8;
}

.field input:focus,
.field select:focus,
.filter-bar input:not([type="checkbox"]):focus,
.filter-bar select:focus,
.builder-controls select:focus {
  border-color: var(--brand);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12), 0 12px 24px rgba(37, 99, 235, 0.08);
}

.file-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.settings-panel {
  margin-bottom: 12px;
  overflow: hidden;
}

.settings-panel summary {
  min-height: 46px;
  padding: 14px 16px;
  color: var(--slate);
  font-family: var(--font-heading);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
  list-style-position: inside;
}

.settings-panel summary:hover {
  background: var(--brand-soft);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(96px, 1fr));
  gap: 12px;
  padding: 0 16px 16px;
}

.wide-field {
  grid-column: span 2;
}

.primary-button,
.ghost-button,
.small-button {
  min-height: 40px;
  border-radius: 7px;
  padding: 0 14px;
  font-weight: 760;
  white-space: nowrap;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease, color 120ms ease, box-shadow 120ms ease;
}

.primary-button:active,
.ghost-button:active,
.small-button:active,
.gram-button:active {
  transform: translateY(1px);
}

.primary-button {
  background: linear-gradient(135deg, var(--brand), var(--brand-strong));
  color: #ffffff;
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.32);
}

.primary-button:hover {
  background: linear-gradient(135deg, #1d4ed8, #0f766e);
}

.ghost-button,
.small-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  color: var(--slate);
}

.ghost-button:hover,
.small-button:hover {
  border-color: rgba(37, 99, 235, 0.36);
  background: var(--brand-soft);
  color: var(--brand);
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.08);
}

.small-button {
  min-height: 34px;
  padding: 0 11px;
  font-size: 12px;
}

.dropzone {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  min-height: 116px;
  padding: 20px;
  margin-bottom: 18px;
  border-style: dashed;
  border-color: rgba(37, 99, 235, 0.28);
  background:
    linear-gradient(135deg, rgba(37, 99, 235, 0.06), rgba(20, 184, 166, 0.06)),
    var(--surface);
}

.dropzone h2 {
  margin: 0 0 7px;
  font-family: var(--font-heading);
  font-size: 20px;
  line-height: 1.25;
  font-weight: 700;
  letter-spacing: 0;
}

.dropzone p {
  margin: 0;
  color: var(--muted);
  font-weight: 650;
}

.secondary-status {
  margin-top: 5px !important;
  font-size: 13px;
}

.dropzone.dragging {
  border-color: var(--brand);
  background: var(--brand-soft);
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.2), 0 20px 34px rgba(37, 99, 235, 0.12);
}

.dropzone-pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid rgba(20, 184, 166, 0.24);
  border-radius: 999px;
  background: rgba(20, 184, 166, 0.1);
  color: #0f766e;
  font-size: 12px;
  font-weight: 780;
  white-space: nowrap;
}

.report {
  display: grid;
  gap: 18px;
}

.is-hidden {
  display: none !important;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
}

.kpi-card {
  position: relative;
  min-height: 104px;
  padding: 16px;
  overflow: hidden;
  display: grid;
  align-content: space-between;
}

.kpi-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: linear-gradient(90deg, var(--brand), var(--green));
}

.kpi-card.alert::before {
  background: var(--rose);
}

.kpi-card.muted::before {
  background: var(--violet);
}

.kpi-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  letter-spacing: 0;
  text-transform: uppercase;
}

.kpi-card strong {
  display: block;
  margin-top: 14px;
  font-size: 29px;
  line-height: 1;
  font-weight: 820;
  letter-spacing: 0;
}

.kpi-card.alert strong {
  color: var(--rose);
}

.kpi-card.muted strong {
  color: var(--violet);
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.feature-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background:
    linear-gradient(180deg, rgba(37, 99, 235, 0.03), rgba(255, 255, 255, 0.88)),
    var(--surface);
  box-shadow: var(--shadow-panel);
}

.feature-card .panel-heading {
  margin-bottom: 0;
  padding-bottom: 10px;
}

.feature-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand);
  font-family: var(--font-heading);
  font-size: 11px;
  font-weight: 700;
}

.feature-lead {
  margin: 0;
  color: var(--slate);
  font-size: 13px;
  line-height: 1.55;
}

.feature-metric {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.feature-metric strong {
  color: var(--ink);
  font-family: var(--font-heading);
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
}

.feature-metric span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

.insight-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
  gap: 14px;
}

.comparison-grid.is-single {
  grid-template-columns: minmax(0, 1fr);
}

.insight-panel,
.data-panel {
  padding: 16px;
  overflow: hidden;
}

.panel-heading,
.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-heading {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.section-heading {
  padding: 2px 0;
}

.panel-heading h2,
.panel-heading h3,
.section-heading h2 {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-heading);
  letter-spacing: 0;
}

.panel-heading h2,
.section-heading h2 {
  font-size: 20px;
  line-height: 1.25;
  font-weight: 700;
}

.panel-heading h3 {
  font-size: 16px;
  line-height: 1.3;
  font-weight: 700;
}

.action-list,
.campaign-list,
.brief-box {
  display: grid;
  gap: 8px;
}

.brief-box {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.action-item,
.campaign-item,
.brief-item {
  display: grid;
  gap: 5px;
  border: 1px solid var(--line);
  border-left: 4px solid rgba(100, 116, 139, 0.34);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.86);
  padding: 10px 12px;
}

.action-item strong,
.campaign-item strong,
.brief-item strong {
  color: var(--ink);
  font-size: 14px;
  font-weight: 740;
  line-height: 1.35;
}

.action-item span,
.campaign-item span,
.brief-item span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.35;
}

.brief-item textarea {
  min-height: 168px;
  width: 100%;
  resize: vertical;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 12px;
  background: var(--surface-muted);
  color: var(--slate);
  font-size: 13px;
  line-height: 1.5;
  outline: none;
}

.brief-summary {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  min-height: 72px;
  border-left: 0;
  background:
    linear-gradient(135deg, rgba(37, 99, 235, 0.04), rgba(20, 184, 166, 0.025)),
    rgba(255, 255, 255, 0.9);
}

.brief-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: rgba(37, 99, 235, 0.09);
  color: var(--brand);
  font-family: var(--font-heading);
  font-size: 11px;
  font-weight: 700;
}

.prompt-card {
  grid-column: 1 / -1;
}

.action-item.opportunity {
  border-left-color: var(--green);
  background: var(--green-soft);
}

.action-item.problem {
  border-left-color: var(--rose);
  background: var(--rose-soft);
}

.action-item.threat {
  border-left-color: var(--violet);
  background: var(--violet-soft);
}

.table-section {
  display: grid;
  gap: 12px;
}

.inspector-section {
  position: relative;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-panel);
  overflow: hidden;
}

.inspector-section::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(37, 99, 235, 0.42), rgba(20, 184, 166, 0.34), transparent);
}

.inspector-section .section-heading {
  margin-bottom: 0;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.bucket-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.segment-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.phrase-panel {
  grid-column: 1 / -1;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
}

.detail-wrap {
  max-height: 620px;
}

table {
  width: 100%;
  min-width: 620px;
  border-collapse: separate;
  border-spacing: 0;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(15, 23, 42, 0.08);
  text-align: left;
  vertical-align: top;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafc;
  color: var(--muted);
  font-size: 11px;
  font-weight: 780;
  letter-spacing: 0;
  text-transform: uppercase;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover {
  background: rgba(37, 99, 235, 0.045);
}

td {
  color: var(--slate);
  font-size: 13px;
  line-height: 1.42;
}

.right {
  text-align: right;
}

.term-cell {
  color: var(--ink);
  font-weight: 760;
}

.muted-cell {
  color: var(--muted);
  font-size: 12px;
}

.label-pill {
  display: inline-flex;
  justify-content: center;
  min-width: 88px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 820;
  line-height: 1.2;
  white-space: nowrap;
}

.label-Opportunity {
  background: var(--green-soft);
  color: #166534;
}

.label-Problem {
  background: var(--rose-soft);
  color: #be123c;
}

.label-Weakness {
  background: var(--amber-soft);
  color: #92400e;
}

.label-Threat {
  background: var(--violet-soft);
  color: #5b21b6;
}

.label-Neutral {
  background: rgba(100, 116, 139, 0.1);
  color: #475569;
}

.segmented-control {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
  box-shadow: var(--shadow-sm);
}

.gram-button {
  width: 34px;
  height: 30px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 780;
}

.gram-button:hover {
  background: var(--brand-soft);
}

.gram-button.active {
  background: linear-gradient(135deg, var(--brand), var(--green));
  color: #ffffff;
}

.filter-bar {
  display: grid;
  grid-template-columns: minmax(160px, 0.8fr) minmax(160px, 0.8fr) max-content minmax(300px, 2fr);
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow-sm);
}

.builder-controls,
.detail-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.builder-controls select {
  min-width: 130px;
  background: #ffffff;
  border-color: var(--line-strong);
  color: var(--ink);
}

.priority-pill {
  display: inline-flex;
  justify-content: center;
  min-width: 42px;
  padding: 4px 7px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--brand), var(--violet));
  color: #ffffff;
  font-size: 11px;
  font-weight: 820;
  line-height: 1.2;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #ffffff;
  padding: 0 12px;
  color: var(--slate);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.toggle-row input {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  margin: 0;
}

.toggle-row input,
.negative-check,
.check-cell input {
  accent-color: var(--brand);
}

.check-cell {
  width: 42px;
  text-align: center;
}

.sort-button {
  padding: 0;
  background: transparent;
  color: inherit;
  font-size: inherit;
  font-weight: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
}

.sort-button:hover {
  color: var(--brand);
}

.empty-row td {
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

input[type="checkbox"] {
  accent-color: var(--brand);
}

@media (max-width: 1240px) {
  .control-band {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .file-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }

  .chart-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 1100px) {
  .control-band,
  .insight-grid,
  .bucket-grid,
  .segment-grid {
    grid-template-columns: 1fr;
  }

  .settings-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .kpi-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .filter-bar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  body {
    font-size: 13px;
  }

  .app-header,
  .dropzone,
  .panel-heading,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .app-header h1 {
    font-size: 30px;
  }

  .header-meta {
    align-self: flex-start;
  }

  .file-actions,
  .detail-actions,
  .builder-controls {
    justify-content: stretch;
  }

  .file-actions button,
  .detail-actions button,
  .builder-controls button,
  .builder-controls select {
    flex: 1 1 130px;
  }

  .kpi-grid,
  .filter-bar,
  .settings-grid,
  .feature-grid,
  .brief-box {
    grid-template-columns: 1fr;
  }

  .wide-field {
    grid-column: span 1;
  }

  .kpi-card {
    min-height: 88px;
  }

  table {
    min-width: 760px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

@media print {
  body {
    background: #ffffff;
  }

  .app-shell {
    width: 100%;
    padding: 0;
  }

  .control-band,
  .settings-panel,
  .dropzone,
  .file-actions,
  .detail-actions,
  .builder-controls,
  .filter-bar,
  .small-button,
  .ghost-button,
  .primary-button,
  .segmented-control,
  .check-cell,
  .detail-wrap {
    display: none !important;
  }

  .report,
  .table-section,
  .insight-grid,
  .bucket-grid,
  .segment-grid,
  .chart-grid,
  .kpi-grid {
    display: block;
  }

  .kpi-card,
  .insight-panel,
  .data-panel {
    box-shadow: none;
    break-inside: avoid;
    margin-bottom: 12px;
  }

  canvas {
    max-height: 180px;
  }

  thead th {
    position: static;
  }
}

/* ── Help Modal ─────────────────────────────────────────────────────────────── */

.help-modal {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.help-modal.is-hidden {
  display: none;
}

.help-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
}

.help-dialog {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: min(860px, 100%);
  max-height: min(88vh, 760px);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-strong);
  box-shadow: 0 32px 80px rgba(15, 23, 42, 0.22);
  overflow: hidden;
}

.help-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px 0;
  flex-shrink: 0;
}

.help-header h2 {
  margin: 0;
  font-family: var(--font-heading);
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
}

.help-close {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 120ms, color 120ms;
}

.help-close:hover {
  background: var(--rose-soft);
  color: var(--rose);
  border-color: var(--rose);
}

.help-tabs {
  display: flex;
  gap: 4px;
  padding: 14px 22px 0;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  overflow-x: auto;
}

.help-tab {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 8px 8px 0 0;
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  margin-bottom: -1px;
  transition: background 120ms, color 120ms;
}

.help-tab:hover {
  background: var(--brand-soft);
  color: var(--brand);
}

.help-tab.active {
  background: var(--surface-strong);
  border-color: var(--line);
  border-bottom-color: var(--surface-strong);
  color: var(--brand);
}

.help-body {
  flex: 1;
  overflow-y: auto;
  padding: 22px;
}

.help-panel {
  display: none;
}

.help-panel.active {
  display: block;
}

.help-intro {
  padding: 14px 16px;
  background: var(--brand-soft);
  border-left: 4px solid var(--brand);
  border-radius: 0 8px 8px 0;
  margin-bottom: 22px;
  font-size: 14px;
  color: var(--slate);
  line-height: 1.55;
}

.help-intro strong {
  color: var(--ink);
}

/* Steps */
.help-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 14px;
}

.help-step {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.step-num {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand), var(--brand-strong));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-heading);
  font-size: 14px;
  font-weight: 700;
  margin-top: 2px;
}

.step-content {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-muted);
}

.step-content strong {
  display: block;
  color: var(--ink);
  font-size: 14px;
  font-weight: 740;
  margin-bottom: 6px;
}

.step-content p {
  margin: 0 0 8px;
  color: var(--slate);
  font-size: 13px;
  line-height: 1.5;
}

.step-content p:last-child {
  margin-bottom: 0;
}

.step-note {
  padding: 8px 10px;
  background: var(--amber-soft);
  border-radius: 6px;
  color: #78350f;
  font-size: 12px;
  font-weight: 650;
  line-height: 1.45;
}

.col-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
}

.col-badge {
  padding: 3px 9px;
  border: 1px solid rgba(37, 99, 235, 0.22);
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.07);
  color: var(--brand);
  font-size: 12px;
  font-weight: 700;
}

.help-tip-box {
  padding: 14px 16px;
  background: var(--green-soft);
  border-left: 4px solid var(--green);
  border-radius: 0 8px 8px 0;
  margin-top: 22px;
  color: var(--slate);
  font-size: 13px;
}

.help-tip-box strong {
  display: block;
  color: var(--ink);
  margin-bottom: 8px;
  font-size: 14px;
}

.help-tip-box ul {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 4px;
}

.help-tip-box li {
  line-height: 1.5;
}

/* Metrics */
.metric-group {
  margin-bottom: 22px;
}

.metric-group-title {
  margin: 0 0 10px;
  font-family: var(--font-heading);
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  padding-bottom: 8px;
  border-bottom: 2px solid var(--brand-soft);
}

.metric-table {
  display: grid;
  gap: 1px;
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow: hidden;
}

.metric-row {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 0;
  background: var(--surface-muted);
}

.metric-row:first-child .metric-name,
.metric-row:first-child .metric-desc {
  padding-top: 12px;
}

.metric-row:last-child .metric-name,
.metric-row:last-child .metric-desc {
  padding-bottom: 12px;
}

.metric-name {
  padding: 8px 14px;
  background: rgba(37, 99, 235, 0.05);
  color: var(--ink);
  font-size: 13px;
  font-weight: 740;
  border-right: 1px solid var(--line);
  line-height: 1.45;
}

.metric-desc {
  padding: 8px 14px;
  background: var(--surface-strong);
  color: var(--slate);
  font-size: 13px;
  line-height: 1.5;
}

.metric-desc code {
  padding: 2px 6px;
  background: var(--brand-soft);
  border-radius: 4px;
  color: var(--brand);
  font-size: 12px;
  font-family: monospace;
}

/* Label cards */
.label-card {
  margin-bottom: 14px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 0 9px 9px 0;
  background: var(--surface-muted);
}

.label-card-Opportunity { border-left-color: var(--green); background: var(--green-soft); }
.label-card-Problem     { border-left-color: var(--rose);  background: var(--rose-soft);  }
.label-card-Weakness    { border-left-color: var(--amber); background: var(--amber-soft); }
.label-card-Threat      { border-left-color: var(--violet);background: var(--violet-soft);}
.label-card-Neutral     { border-left-color: #64748b;      background: rgba(100,116,139,0.08); }

.label-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.label-card-header strong {
  color: var(--ink);
  font-size: 14px;
  font-weight: 740;
}

.label-card > p {
  margin: 0 0 10px;
  color: var(--slate);
  font-size: 13px;
  line-height: 1.5;
}

.label-actions {
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.55);
  border-radius: 7px;
  font-size: 13px;
  color: var(--slate);
}

.label-actions strong {
  display: block;
  color: var(--ink);
  font-weight: 740;
  margin-bottom: 6px;
}

.label-actions ul {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 3px;
}

.label-actions li {
  line-height: 1.45;
}

/* Feature guide */
.feature-guide-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.feature-guide-card {
  display: flex;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-muted);
}

.fg-icon {
  font-size: 22px;
  flex-shrink: 0;
  width: 36px;
  text-align: center;
}

.fg-body strong {
  display: block;
  color: var(--ink);
  font-size: 13px;
  font-weight: 740;
  margin-bottom: 4px;
}

.fg-body p {
  margin: 0;
  color: var(--slate);
  font-size: 12px;
  line-height: 1.5;
}

.fg-body kbd {
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface-strong);
  font-size: 11px;
  font-family: monospace;
  color: var(--ink);
}

/* Dark mode adjustments for modal */
.dark .help-dialog {
  background: #1e293b;
}

.dark .help-tab.active {
  background: #1e293b;
  border-bottom-color: #1e293b;
}

.dark .metric-desc,
.dark .step-content,
.dark .feature-guide-card,
.dark .label-actions {
  background: rgba(255, 255, 255, 0.04);
}

.dark .metric-name {
  background: rgba(37, 99, 235, 0.1);
}

.dark .step-note {
  color: #fbbf24;
}

.dark .label-actions {
  background: rgba(255, 255, 255, 0.06);
}

@media (max-width: 720px) {
  .help-dialog {
    max-height: 95vh;
  }

  .metric-row {
    grid-template-columns: 1fr;
  }

  .metric-name {
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .feature-guide-grid {
    grid-template-columns: 1fr;
  }
}

/* ── Dark mode ─────────────────────────────────────────────────────────────── */

.dark {
  color-scheme: dark;
  --bg: #0b1120;
  --surface: rgba(15, 23, 42, 0.92);
  --surface-muted: #0f172a;
  --surface-strong: #1e293b;
  --ink: #f1f5f9;
  --muted: #94a3b8;
  --slate: #cbd5e1;
  --line: rgba(248, 250, 252, 0.1);
  --line-strong: rgba(37, 99, 235, 0.3);
  --brand-soft: rgba(37, 99, 235, 0.15);
  --green-soft: rgba(22, 163, 74, 0.15);
  --amber-soft: rgba(245, 158, 11, 0.15);
  --rose-soft: rgba(225, 29, 72, 0.13);
  --violet-soft: rgba(124, 58, 237, 0.13);
  --shadow-panel: 0 18px 48px rgba(0, 0, 0, 0.4);
}

.dark body {
  background:
    linear-gradient(180deg, #0d1526 0%, #0b1120 44%, #080f1c 100%),
    repeating-linear-gradient(90deg, rgba(37, 99, 235, 0.06) 0 1px, transparent 1px 86px),
    repeating-linear-gradient(0deg, rgba(20, 184, 166, 0.04) 0 1px, transparent 1px 86px);
}

.dark body::before {
  background:
    linear-gradient(90deg, rgba(37, 99, 235, 0.12), transparent 34%, rgba(20, 184, 166, 0.08)),
    linear-gradient(180deg, rgba(0, 0, 0, 0.3), transparent 42%);
}

.dark .field input,
.dark .field select,
.dark .filter-bar input:not([type="checkbox"]),
.dark .filter-bar select,
.dark .builder-controls select {
  background: rgba(15, 23, 42, 0.96);
  color: var(--ink);
  border-color: var(--line-strong);
}

.dark .field input:focus,
.dark .field select:focus,
.dark .filter-bar input:not([type="checkbox"]):focus,
.dark .filter-bar select:focus,
.dark .builder-controls select:focus {
  background: #1e293b;
}

.dark table tr:hover td {
  background: rgba(37, 99, 235, 0.06);
}

.dark thead th {
  background: rgba(15, 23, 42, 0.98);
}

.dark .header-meta {
  background: rgba(15, 23, 42, 0.86);
  border-color: rgba(37, 99, 235, 0.25);
}

.dark .ghost-button {
  color: var(--slate);
  background: rgba(30, 41, 59, 0.8);
  border-color: rgba(248, 250, 252, 0.12);
}

.dark .ghost-button:hover {
  background: rgba(37, 99, 235, 0.18);
  border-color: rgba(37, 99, 235, 0.4);
}

.dark .kpi-card.alert {
  background: rgba(225, 29, 72, 0.08);
}

.dark .kpi-card.muted {
  background: rgba(124, 58, 237, 0.08);
}

/* ── Loading overlay ────────────────────────────────────────────────────────── */

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(246, 249, 252, 0.88);
  backdrop-filter: blur(6px);
}

.dark .loading-overlay {
  background: rgba(11, 17, 32, 0.88);
}

.loading-overlay.is-hidden {
  display: none;
}

.loading-spinner {
  width: 44px;
  height: 44px;
  border: 3px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-label {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

/* ── Toast notifications ────────────────────────────────────────────────────── */

.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9998;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
  max-width: 360px;
  padding: 12px 16px;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow-panel);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  animation: toast-in 220ms ease, toast-out 280ms ease 2.5s forwards;
}

.dark .toast {
  background: #1e293b;
  border-color: rgba(248, 250, 252, 0.12);
}

.toast-icon {
  font-size: 16px;
  flex-shrink: 0;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes toast-out {
  to { opacity: 0; transform: translateY(8px); }
}

/* ── Row count badge ────────────────────────────────────────────────────────── */

.row-count {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
  padding: 4px 10px;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 999px;
}

/* ── KPI subtitle ───────────────────────────────────────────────────────────── */

.kpi-sub {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}

/* ── Scatter Plot ───────────────────────────────────────────────────────────── */

.scatter-section {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-panel);
  overflow: hidden;
  position: relative;
}

.scatter-section::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(37, 99, 235, 0.42), rgba(20, 184, 166, 0.34), transparent);
}

.scatter-subtitle {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.scatter-wrap {
  position: relative;
  overflow: hidden;
}

.scatter-grid {
  stroke: var(--line);
  stroke-width: 1;
}

.scatter-ref {
  stroke: var(--muted);
  stroke-width: 1.5;
  opacity: 0.6;
}

.scatter-tick {
  fill: var(--muted);
  font-size: 11px;
  font-family: var(--font-heading);
}

.scatter-axis-label {
  fill: var(--slate);
  font-size: 12px;
  font-weight: 700;
  font-family: var(--font-heading);
}

.scatter-qlabel {
  font-size: 11px;
  font-weight: 700;
  font-family: var(--font-heading);
  opacity: 0.65;
}

.scatter-dot {
  cursor: pointer;
  transition: fill-opacity 120ms, r 120ms;
}

.scatter-dot:hover {
  fill-opacity: 1 !important;
  r: 9;
}

.q-shade {
  opacity: 0.045;
}

.q-problem    { fill: var(--rose); }
.q-weakness   { fill: var(--amber); }
.q-gem        { fill: #64748b; }
.q-opportunity { fill: var(--green); }

.scatter-tooltip {
  position: absolute;
  z-index: 100;
  pointer-events: none;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 13px;
  min-width: 164px;
  box-shadow: var(--shadow-panel);
  font-size: 12px;
  color: var(--slate);
  line-height: 1.4;
}

.scatter-tooltip strong {
  display: block;
  color: var(--ink);
  font-size: 13px;
  font-weight: 740;
  margin-bottom: 7px;
}

.stt-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 2px 0;
}

.stt-outlier {
  margin-top: 5px;
  font-size: 11px;
  color: var(--amber);
  font-weight: 700;
}

.dark .scatter-tooltip {
  background: #1e293b;
  border-color: rgba(248, 250, 252, 0.12);
}

/* ── Keyword Gap ────────────────────────────────────────────────────────────── */

.keyword-exact {
  font-family: monospace;
  font-size: 12px;
  padding: 2px 7px;
  background: var(--brand-soft);
  border-radius: 5px;
  color: var(--brand);
  white-space: nowrap;
}
