:root {
  /* Base colours */
  --bg-body: #f5f5f7;
  --bg-surface: #ffffff;
  --bg-surface-soft: #f9fafb;
  --bg-accent-soft: #ecfeff;

  --border-subtle: #e5e7eb;
  --border-strong: #cbd5e1;

  --text-main: #111827;
  --text-ink: #0f172a;
  --text-muted: #6b7280;
  --text-soft: #9ca3af;

  --accent: #0f766e;
  --accent-strong: #064e3b;
  --accent-alt: #0891b2;

  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --success: #16a34a;
  --warning: #b45309;

  /* Tints for richer UI */
  --tint-green-soft: #ecfdf5;
  --tint-blue-soft: #eff6ff;
  --tint-yellow-soft: #fefce8;
  --tint-red-soft: #fef2f2;
  --tint-slate-soft: #f1f5f9;

  --tint-green-border: #bbf7d0;
  --tint-blue-border: #bfdbfe;
  --tint-yellow-border: #fef08a;
  --tint-red-border: #fecaca;

  /* Radii */
  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --radius-pill: 999px;

  /* Shadows */
  --shadow-soft: 0 12px 32px rgba(15, 23, 42, 0.12);
  --shadow-subtle: 0 8px 20px rgba(15, 23, 42, 0.08);
  --shadow-strong: 0 22px 60px rgba(15, 23, 42, 0.18);
}

/* Base */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-main);
  background: radial-gradient(circle at top, #e0f2fe 0, #f5f5f7 44%, #f9fafb 100%);
}

a {
  color: inherit;
  text-decoration: none;
}

h1, h2, h3, h4 {
  margin: 0;
  font-weight: 600;
  color: var(--text-ink);
}

p {
  margin: 0;
}

/* Layout containers */

.shell {
  max-width: 1120px;
  margin: 0 auto;
  padding: 20px 18px 56px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 26px 18px 48px;
}

@media (max-width: 640px) {
  .shell,
  main {
    padding: 20px 16px 40px;
  }
}

/* Header / nav */

header {
  background: #ffffffee;
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(209, 213, 219, 0.9);
  position: sticky;
  top: 0;
  z-index: 20;
}

.app-header--landing {
  position: static;
  border-bottom: none;
  background: transparent;
  backdrop-filter: none;
}

.header-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.logo-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-mark {
  width: 26px;
  height: 26px;
  border-radius: 11px;
  background: conic-gradient(from 180deg, #0f766e, #14b8a6, #0ea5e9, #0f766e);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 18px rgba(15, 118, 110, 0.45);
}

.logo-mark span {
  font-size: 13px;
  font-weight: 700;
  color: #f9fafb;
}

.logo-text {
  display: flex;
  flex-direction: column;
}

.logo-main {
  font-weight: 700;
  font-size: 19px;
  letter-spacing: 0.04em;
}

.logo-sub {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-soft);
  letter-spacing: 0.12em;
}

.app-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}

.app-nav a {
  padding: 6px 11px;
  border-radius: var(--radius-pill);
  color: var(--text-muted);
  transition: background 0.15s ease, color 0.15s ease;
}

.app-nav a:hover {
  background: rgba(15, 23, 42, 0.04);
  color: var(--text-ink);
}

.app-nav a.active {
  background: rgba(15, 118, 110, 0.08);
  color: var(--accent-strong);
  font-weight: 500;
}

@media (max-width: 640px) {
  .header-inner {
    flex-direction: column;
    align-items: flex-start;
  }
  .app-nav {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 4px;
  }
}

/* Page headers */

.page-header {
  margin-bottom: 18px;
}

.page-kicker {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--text-soft);
  margin-bottom: 4px;
}

.page-header h1 {
  font-size: clamp(24px, 3vw, 30px);
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}

.page-header .muted {
  max-width: 640px;
}

/* Hero (landing) */

.hero {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(255, 255, 255, 0.92));
  border-radius: 24px;
  box-shadow: var(--shadow-soft);
  border: 1px solid rgba(209, 213, 219, 0.95);
  padding: 30px 24px 24px;
  margin-top: 18px;
}

.hero-inner {
  max-width: 720px;
}

.hero-tag {
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-soft);
  margin-bottom: 8px;
}

.hero h1 {
  font-size: clamp(30px, 4vw, 36px);
  margin-bottom: 10px;
  letter-spacing: -0.03em;
}

.lead {
  font-size: 15px;
  color: var(--text-muted);
  max-width: 540px;
  margin-bottom: 20px;
}

/* Grid sections */

.sections,
.history-shell,
.layout {
  margin-top: 18px;
}

.sections {
  display: grid;
  gap: 18px;
}

.sections-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

@media (min-width: 768px) {
  .sections-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 767px) {
  .sections-3 {
    grid-template-columns: minmax(0, 1fr);
  }
}

.layout {
  display: grid;
  gap: 18px;
  align-items: flex-start;
}

.layout--2-1 {
  grid-template-columns: 1fr;
}

@media (min-width: 880px) {
  .layout--2-1 {
    grid-template-columns: 2.1fr 1.6fr;
  }
}

/* Cards */

.card,
.top-shell,
.history-shell {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-soft);
  padding: 20px 18px 18px;
}

.card--tight {
  padding: 16px 16px 14px;
}

.top-shell {
  padding: 18px 18px 16px;
  box-shadow: var(--shadow-strong);
  background: linear-gradient(135deg, #ecfdf5, #eff6ff);
  border: 1px solid #dbeafe;
}

.card-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
}

.card-eyebrow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-soft);
  margin-bottom: 4px;
}

.card-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 16px;
  border-radius: var(--radius-pill);
  font-size: 14px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 500;
  text-decoration: none;
  background: #e5e7eb;
  color: var(--text-main);
  transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-subtle);
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-alt));
  color: #f9fafb;
  border-color: rgba(15, 118, 110, 0.85);
}

.btn.secondary {
  background: #ffffff;
  border-color: var(--border-subtle);
  color: var(--text-main);
}

.btn.ghost {
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
}

.btn[disabled] {
  opacity: 0.7;
  cursor: default;
  box-shadow: none;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 4px;
}

.btn-link {
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
}

.btn-link:hover {
  text-decoration: underline;
}

/* Pills / tags */

.pill,
.tag-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 11px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  border: 1px solid #dbeafe;
  background: var(--tint-blue-soft);
  color: #1e3a8a;
}

.pill.source {
  border-color: var(--tint-green-border);
  background: var(--tint-green-soft);
  color: #047857;
}

.tag-pill {
  background: var(--bg-surface-soft);
  border-color: var(--border-subtle);
  color: var(--text-muted);
}

/* Text helpers */

.muted {
  color: var(--text-muted);
  font-size: 14px;
}

.small-note {
  margin-top: 22px;
  font-size: 12px;
  color: var(--text-muted);
  max-width: 560px;
}

/* Status */

.status {
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-muted);
  min-height: 18px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: transparent;
}

.status.loading::before {
  background: #2563eb;
}

.status.error {
  color: var(--danger);
}

.status.error::before {
  background: var(--danger);
}

.status.ok {
  color: var(--success);
}

.status.ok::before {
  background: var(--success);
}

/* Forms */

.field-group {
  margin-top: 16px;
}

label {
  font-size: 13px;
  font-weight: 600;
  display: block;
  color: var(--text-main);
}

input,
select,
textarea {
  width: 100%;
  padding: 9px 11px;
  border-radius: 10px;
  border: 1px solid #cbd5e1;
  margin-top: 6px;
  font-size: 14px;
  background: #f9fafb;
  transition: border-color 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(34, 197, 165, 0.25);
  background: #ffffff;
}

input[type="file"] {
  padding: 7px 10px;
  background: #f9fafb;
}

.helper {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.helper strong {
  font-weight: 600;
  color: var(--text-main);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

/* Tables */

.table-wrap,
.history-table-wrap,
.dept-table-wrap {
  margin-top: 6px;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  padding: 8px 10px;
  border-bottom: 1px solid #e2e8f0;
  text-align: left;
  white-space: nowrap;
}

th {
  font-weight: 600;
  font-size: 13px;
  color: var(--text-ink);
  background: #f9fafb;
}

td:nth-child(2) {
  white-space: normal;
}

/* Report-specific components */

.top-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.top-subline {
  font-size: 14px;
  color: var(--text-muted);
}

.grid {
  display: grid;
  gap: 18px;
  margin-top: 22px;
}

.grid--4 {
  grid-template-columns: 1fr;
}

.grid--2 {
  grid-template-columns: 1fr;
}

@media (min-width: 900px) {
  .grid--4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .grid--2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Charts */

.chart-wrap {
  position: relative;
  width: 100%;
  height: 260px;
}

@media (max-width: 640px) {
  .chart-wrap {
    height: 220px;
  }
}

.chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}

/* KPI */

.kpi-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #6b7280;
  margin-bottom: 4px;
}

.kpi-value {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 2px;
}

.kpi-note {
  font-size: 13px;
  color: var(--text-muted);
}

/* KPI in tight cards */

.card.card--tight .kpi-label {
  font-size: 13px;
  color: #6b7280;
}

.card.card--tight .kpi-value {
  margin-top: 2px;
  font-size: 22px;
  font-weight: 600;
}

.card.card--tight .kpi-note {
  margin-top: 4px;
  font-size: 12px;
  color: #9ca3af;
}

/* Lens tabs */

.lens-tabs {
  display: flex;
  gap: 10px;
  border-bottom: none;
  padding-bottom: 0;
  background: var(--tint-slate-soft);
  border-radius: 14px;
  padding: 8px 10px;
  border: 1px solid #e2e8f0;
}

.lens-tab-btn {
  border: none;
  background: transparent;
  padding: 6px 14px;
  border-radius: 9999px;
  font-size: 13px;
  color: #475569;
  cursor: pointer;
  border: 1px solid transparent;
}

.lens-tab-btn:hover {
  background: #eef2ff;
  color: #312e81;
}

.lens-tab-btn.active {
  background: #312e81;
  color: #f9fafb;
  border-color: #312e81;
}

/* Insight lists */

.insight-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.insight-pill {
  border-radius: 8px;
  padding: 8px 10px;
  border: 1px solid #e5e7eb;
  background: #f9fafb;
}

.insight-pill-main {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.insight-pill-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}

.insight-pill-body {
  font-size: 13px;
  color: #374151;
}

.lens-tag {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 9999px;
  background: #e0f2fe;
  border: 1px solid #bae6fd;
  color: #075985;
  font-size: 11px;
}

.insight-dept {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 9999px;
  background: #fef9c3;
  border: 1px solid #fde047;
  color: #854d0e;
  font-size: 11px;
}

.insight-severity-label {
  text-transform: capitalize;
}

/* Severity colours */

.severity-critical {
  border-color: var(--tint-red-border);
  background: var(--tint-red-soft);
}

.severity-major {
  border-color: #fed7aa;
  background: #fffbeb;
}

.severity-minor,
.severity-info {
  border-color: #e2e8f0;
  background: #f8fafc;
}

/* Confidence block */

#insights-confidence {
  margin-top: 4px;
}

#insights-confidence .insight-pill {
  background: #ffffff;
}

#insights-confidence .insight-pill span {
  font-size: 13px;
}

/* Q&A styling */

.qa-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.qa-item {
  font-size: 13px;
}

.qa-label {
  font-size: 11px;
  color: #6b7280;
  margin-bottom: 2px;
}

.qa-text {
  padding: 6px 10px;
  border-radius: 12px;
  max-width: 100%;
}

.qa-item-question {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.qa-item-question .qa-text {
  background: #111827;
  color: #f9fafb;
}

.qa-item-answer {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.qa-item-answer .qa-text {
  background: #f1f5f9;
  color: #111827;
}

.qa-item-thinking .qa-text {
  background: #e5e7eb;
  color: #4b5563;
  font-style: italic;
}

.qa-item-meta {
  font-size: 12px;
  color: #4b5563;
}

.qa-cited-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  margin-top: 2px;
}

.qa-cited-label {
  font-weight: 500;
  margin-right: 4px;
}

.qa-chip {
  border: 1px solid #e5e7eb;
  border-radius: 9999px;
  padding: 2px 8px;
  background: #ffffff;
  font-size: 11px;
  cursor: pointer;
}

.qa-chip:hover {
  background: #f3f4f6;
}

.qa-status-pill {
  margin-left: 6px;
  padding: 2px 6px;
  font-size: 10px;
  border-radius: 999px;
  background: #e2e8f0;
  color: #475569;
}

.qa-status-ready {
  background: #dcfce7;
  color: #166534;
}

.qa-status-clarification_needed {
  background: #fef9c3;
  color: #92400e;
}

.qa-status-unsupported,
.qa-status-error {
  background: #fee2e2;
  color: #b91c1c;
}

/* Highlight pulse */

.highlight-pulse {
  animation: highlightPulse 1.5s ease-out;
}

@keyframes highlightPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.6);
  }
  100% {
    box-shadow: 0 0 0 10px rgba(37, 99, 235, 0);
  }
}

/* Department section */

.dept-table-wrap {
  margin-top: 6px;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  background: #f9fafb;
  padding: 6px;
}

.dept-cards {
  display: none;
  margin-top: 10px;
  gap: 10px;
}

.dept-card {
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  padding: 10px 12px 9px;
  background: #f9fafb;
}

.dept-card-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}

.dept-card-name {
  font-weight: 600;
  font-size: 14px;
}

.dept-chip {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--bg-accent-soft);
  color: #0369a1;
  border: 1px solid #bae6fd;
  white-space: nowrap;
}

.dept-card-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px 8px;
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

.dept-metric-label {
  color: #6b7280;
}

.dept-metric-value {
  font-weight: 500;
  color: var(--text-main);
}

@media (max-width: 768px) {
  .dept-cards {
    display: grid;
  }
  .dept-table-wrap {
    display: none;
  }
}

/* Slightly smaller text in raw views */

.dept-card-metrics .dept-metric-value,
.dept-card-metrics .dept-metric-label,
.dept-table-wrap table td,
.dept-table-wrap table th {
  font-size: 12px;
}

/* History */

.history-shell {
  padding: 16px 16px 14px;
}

.history-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.history-title {
  font-size: 15px;
  font-weight: 600;
}

.history-sub {
  font-size: 13px;
  color: var(--text-muted);
}

.empty {
  margin-top: 6px;
  font-size: 14px;
  color: #9ca3af;
}

.hint-row {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-muted);
}

.history-table-wrap table tr:hover {
  background: #f1f5f9;
}

/* Mapping */

.field-note {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.field-note strong {
  font-weight: 600;
  color: var(--text-main);
}

.checkbox-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.checkbox-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid #cbd5e1;
  background: var(--bg-surface-soft);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.checkbox-pill input {
  margin: 0;
}

.actions-row {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.error {
  color: #b91c1c;
  font-size: 12px;
  margin-top: 4px;
  display: none;
}

/* Footer */

footer {
  border-top: 1px solid var(--border-subtle);
  margin-top: 36px;
  padding-top: 14px;
  font-size: 13px;
  color: #6b7280;
  text-align: center;
}

/* Search field in history */

#history-search {
  border-radius: 999px;
  border: 1px solid #d1d5db;
  background: #ffffff;
}

#history-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(34, 197, 165, 0.25);
}

@media (max-width: 480px) {
  .card,
  .top-shell,
  .history-shell {
    padding: 14px 12px 12px;
  }
}
