:root {
  --bg: #f4f8ff;
  --panel: #ffffff;
  --ink: #1e293b;
  --muted: #667085;
  --line: #d7e3f5;
  --navy: #0f4c9a;
  --blue: #287ee4;
  --blue-dark: #0f5fb9;
  --accent: #ff7a1a;
  --accent-dark: #e35f00;
  --green: #15803d;
  --green-bg: #dcfce7;
  --yellow: #a16207;
  --yellow-bg: #fef9c3;
  --red: #b91c1c;
  --red-bg: #fee2e2;
  --orange: #c2410c;
  --orange-bg: #ffedd5;
  --gray-bg: #e5e7eb;
  --shadow: 0 18px 45px rgba(40, 126, 228, 0.1);
}

:root[data-theme="dark"] {
  --bg: #0b1220;
  --panel: #111827;
  --ink: #e5eefb;
  --muted: #a8b3c7;
  --line: #26364f;
  --navy: #60a5fa;
  --blue: #60a5fa;
  --blue-dark: #2563eb;
  --accent: #fb923c;
  --accent-dark: #f97316;
  --green: #86efac;
  --green-bg: #123421;
  --yellow: #fde68a;
  --yellow-bg: #3d330b;
  --red: #fca5a5;
  --red-bg: #3d1618;
  --orange: #fdba74;
  --orange-bg: #3f2411;
  --gray-bg: #273142;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Aptos, "Segoe UI", Arial, sans-serif;
}

:root[data-theme="dark"] .sidebar {
  background: linear-gradient(180deg, #123b74 0%, #0b2c59 55%, #081f3d 100%);
}

:root[data-theme="dark"] .brand-mark {
  background: #eaf4ff;
  color: #0f5fb9;
}

:root[data-theme="dark"] .nav-list a {
  background: rgba(255, 255, 255, 0.1);
}

:root[data-theme="dark"] .privacy-banner {
  background: #102647;
  border-color: #1e5da8;
  color: #dbeafe;
}

:root[data-theme="dark"] .privacy-banner strong,
:root[data-theme="dark"] .privacy-banner span {
  color: #e5eefb;
}

:root[data-theme="dark"] textarea,
:root[data-theme="dark"] input,
:root[data-theme="dark"] select,
:root[data-theme="dark"] .btn.secondary {
  background: #0f172a;
  border-color: #2c3f5f;
  color: #e5eefb;
}

:root[data-theme="dark"] th {
  background: #1f2d44;
  color: #e5eefb;
}

:root[data-theme="dark"] .result-table th:nth-child(-n + 3) {
  background: #1d4ed8;
}

:root[data-theme="dark"] tr.status-match td:nth-child(-n + 3) {
  background: #1b5e33;
}

:root[data-theme="dark"] tr.status-added td:nth-child(-n + 3) {
  background: #6d5408;
}

:root[data-theme="dark"] tr.status-removed td:nth-child(-n + 3) {
  background: #6f1d1d;
}

:root[data-theme="dark"] tr.status-edition-changed td:nth-child(-n + 3),
:root[data-theme="dark"] tr.status-revised td:nth-child(-n + 3) {
  background: #7c3d12;
}

:root[data-theme="dark"] tr.status-unknown-format td:nth-child(-n + 3),
:root[data-theme="dark"] tr.status-unknown td:nth-child(-n + 3) {
  background: #334155;
}

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: linear-gradient(180deg, #287ee4 0%, #0f5fb9 54%, #184f8f 100%);
  color: #f8fafc;
  padding: 24px;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: #ffffff;
  color: #287ee4;
  border-radius: 8px;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.brand p,
.side-panel p {
  margin: 4px 0 0;
  color: #cbd5e1;
  font-size: 13px;
}

.nav-list {
  display: grid;
  gap: 8px;
  margin: 28px 0;
}

.nav-list a {
  color: #ffffff;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.14);
}

.side-panel {
  padding-top: 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
}

.side-panel h2 {
  margin: 0 0 10px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.side-panel ol {
  margin: 0;
  padding-left: 18px;
  color: #e2e8f0;
  line-height: 1.6;
  font-size: 13px;
}

.compact {
  margin-top: 22px;
}

.main {
  padding: 24px;
  min-width: 0;
}

.topbar,
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.topbar h2,
.section-head h3 {
  margin: 0;
}

.topbar h2 {
  font-size: 26px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.privacy-banner {
  margin: 18px 0 0;
  padding: 12px 14px;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  background: #eff6ff;
  color: #1e3a8a;
  line-height: 1.45;
}

.privacy-banner strong {
  color: #172033;
}

.privacy-banner span {
  display: inline-block;
  margin-left: 8px;
  color: #475569;
  font-size: 13px;
}

.hidden {
  display: none;
}

.collapsed-doc textarea,
.collapsed-doc .preview-table-wrap {
  display: none;
}

.collapsed-doc {
  box-shadow: none;
}

.section-note {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.btn {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  text-decoration: none;
}

.btn:hover {
  border-color: #93c5fd;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn.primary:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.btn.secondary {
  background: #f8fafc;
}

.topbar {
  border-bottom: 4px solid var(--accent);
  padding-bottom: 18px;
}

.btn.small {
  padding: 7px 10px;
  font-size: 13px;
}

.btn.danger {
  color: var(--red);
  border-color: #fecaca;
  background: #fff7f7;
}

.select-label {
  align-self: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

select {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
  font: inherit;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: 12px;
  margin: 22px 0;
}

.metric,
.chart-panel,
.policy-pane,
.results-section,
.settings-section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  padding: 14px;
}

.metric span {
  display: block;
  min-height: 34px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.metric strong {
  font-size: 26px;
}

.metric.good strong {
  color: var(--green);
}

.metric.added strong {
  color: var(--yellow);
}

.metric.removed strong {
  color: var(--red);
}

.metric.changed strong {
  color: var(--orange);
}

.metric.unknown strong {
  color: #475569;
}

.dashboard-grid,
.workspace {
  display: grid;
  grid-template-columns: 0.8fr 1.2fr;
  gap: 16px;
  margin-bottom: 16px;
}

.chart-panel,
.policy-pane,
.results-section,
.settings-section {
  padding: 16px;
  min-width: 0;
}

.section-head span {
  color: var(--muted);
  font-size: 13px;
}

canvas {
  display: block;
  width: 100%;
  max-height: 240px;
  margin-top: 12px;
}

textarea {
  width: 100%;
  height: 210px;
  margin: 12px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  resize: vertical;
  color: var(--ink);
  background: #fbfdff;
  line-height: 1.4;
}

.preview-table-wrap,
.results-table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  background: #f1f5f9;
  color: #334155;
  font-weight: 800;
}

.result-table th:nth-child(-n + 3) {
  background: var(--blue-dark);
  color: #f8fafc;
}

.result-group-row td {
  background: linear-gradient(90deg, var(--blue-dark), var(--blue)) !important;
  color: #f8fafc;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.result-group-button {
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  padding: 0;
}

.result-group-meta {
  color: #eaf4ff;
  font-weight: 600;
  margin-left: 10px;
}

tr.status-match td {
  background: var(--green-bg);
}

tr.status-match td:nth-child(-n + 3) {
  background: #bbf7d0;
}

tr.status-added td {
  background: var(--yellow-bg);
}

tr.status-added td:nth-child(-n + 3) {
  background: #fde68a;
}

tr.status-removed td {
  background: var(--red-bg);
}

tr.status-removed td:nth-child(-n + 3) {
  background: #fecaca;
}

tr.status-edition-changed td {
  background: var(--orange-bg);
}

tr.status-edition-changed td:nth-child(-n + 3),
tr.status-revised td:nth-child(-n + 3) {
  background: #fed7aa;
}

tr.status-revised td {
  background: var(--orange-bg);
}

tr.status-unknown-format td,
tr.status-unknown td {
  background: var(--gray-bg);
}

tr.status-unknown-format td:nth-child(-n + 3),
tr.status-unknown td:nth-child(-n + 3) {
  background: #cbd5e1;
}

.results-section {
  margin-bottom: 16px;
}

.settings-section label {
  display: block;
  margin: 12px 0 6px;
  color: var(--muted);
  font-weight: 700;
}

.settings-section input {
  width: 100%;
  max-width: 620px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

@media (max-width: 1500px) {
  .workspace {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .main,
  .sidebar {
    padding: 16px;
  }

  .topbar,
  .section-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }
}
