:root {
  color-scheme: light;
  --ink: #14201e;
  --muted: #62706d;
  --line: #dbe3e0;
  --paper: #f5f7f5;
  --panel: #ffffff;
  --accent: #0f766e;
  --accent-strong: #0b514c;
  --blue: #2f6f9f;
  --amber: #b86f13;
  --rose: #a23c52;
  --green: #23704b;
  --mint: #cfeee5;
  --sky: #e6f1fb;
  --soft-green: #e8f4ef;
  --soft-amber: #fff3df;
  --soft-rose: #fae8ed;
  --shadow: 0 18px 50px rgba(19, 32, 29, 0.1);
  --shadow-soft: 0 10px 28px rgba(19, 32, 29, 0.07);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.08), transparent 34%),
    linear-gradient(315deg, rgba(184, 111, 19, 0.08), transparent 30%),
    var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px 28px;
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 10px 30px rgba(20, 32, 30, 0.05);
  backdrop-filter: blur(18px);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--blue));
  color: #fff;
  font-size: 15px;
  font-weight: 900;
  box-shadow: 0 12px 26px rgba(15, 118, 110, 0.25);
}

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

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 30px;
  line-height: 1.1;
}

.tagline {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.source-status {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.source-status span {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  box-shadow: var(--shadow-soft);
}

.layout {
  display: grid;
  grid-template-columns: minmax(292px, 356px) minmax(0, 1fr);
  gap: 24px;
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 24px 28px 36px;
}

.filters {
  align-self: start;
  position: sticky;
  top: 96px;
  display: grid;
  gap: 16px;
}

form,
.import-panel,
.summary-band,
.insights-panel,
.result-card,
.table-shell,
.empty-state,
.branch-grid,
.source-list {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

form,
.import-panel {
  padding: 20px;
}

form {
  border-top: 4px solid var(--accent);
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid #d3ddda;
  border-radius: 8px;
  background: #fbfdfc;
  color: var(--ink);
  padding: 10px 12px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

select {
  cursor: pointer;
}

input:focus,
select:focus,
button:focus-visible {
  border-color: rgba(15, 118, 110, 0.65);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.13);
  outline: 0;
}

button:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.22);
  outline-offset: 1px;
}

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

button {
  min-height: 42px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
  padding: 9px 16px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(15, 118, 110, 0.18);
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

button:hover {
  background: var(--accent-strong);
  box-shadow: 0 12px 26px rgba(15, 118, 110, 0.24);
  transform: translateY(-1px);
}

button.secondary,
.tab {
  background: #fff;
  color: var(--accent);
  box-shadow: none;
}

button.secondary:hover,
.tab:hover {
  background: var(--soft-green);
}

.import-panel h2 {
  margin: 0 0 8px;
  font-size: 16px;
}

.import-panel p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.results-area {
  min-width: 0;
}

.summary-band {
  display: grid;
  grid-template-columns: repeat(3, minmax(118px, 160px)) minmax(220px, 1fr);
  gap: 16px;
  align-items: center;
  padding: 20px;
  margin-bottom: 16px;
  border-top: 4px solid var(--blue);
}

.insights-panel {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  padding: 16px;
  margin-bottom: 16px;
}

.insight-item {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 12px;
  border: 1px solid #edf2f0;
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff, #f7fbf9);
}

.insight-item span,
.insight-item small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.insight-item strong {
  overflow-wrap: anywhere;
  font-size: 16px;
  line-height: 1.25;
}

.metric {
  display: block;
  color: var(--accent-strong);
  font-size: 34px;
  font-weight: 850;
  line-height: 1;
}

.metric-label,
.coverage-note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  padding: 6px;
  width: max-content;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.76);
  box-shadow: var(--shadow-soft);
}

.tab {
  min-height: 38px;
  border-color: transparent;
  color: var(--ink);
  padding-inline: 13px;
}

.tab.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

#cardsView {
  display: none;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}

#cardsView.active {
  display: grid;
}

.result-card {
  position: relative;
  overflow: hidden;
  padding: 18px;
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
}

.result-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: linear-gradient(90deg, var(--accent), var(--blue), var(--amber));
}

.result-card:hover {
  border-color: rgba(15, 118, 110, 0.32);
  box-shadow: 0 22px 56px rgba(19, 32, 29, 0.13);
  transform: translateY(-2px);
}

.card-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

.result-card h2 {
  margin: 4px 0 0;
  font-size: 19px;
  line-height: 1.25;
}

.result-meta {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.badge {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 12px;
  font-weight: 850;
  box-shadow: 0 8px 18px rgba(19, 32, 29, 0.08);
}

.badge.safe {
  background: var(--soft-green);
  color: var(--green);
}

.badge.reach {
  background: var(--soft-amber);
  color: var(--amber);
}

.badge.target {
  background: var(--sky);
  color: var(--blue);
}

.badge.unranked {
  background: var(--soft-rose);
  color: var(--rose);
}

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

.facts div {
  min-width: 0;
  padding: 10px;
  border-radius: 8px;
  background: #f7faf9;
  border: 1px solid #edf2f0;
}

.facts dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.facts dd {
  margin: 3px 0 0;
  overflow-wrap: anywhere;
  font-size: 14px;
  font-weight: 700;
}

.card-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.chance-meter {
  display: grid;
  grid-template-columns: auto minmax(92px, 140px);
  gap: 8px;
  align-items: center;
  min-height: 28px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.meter-track {
  width: 100%;
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf2f0;
}

.meter-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #4f9d69);
}

.card-actions a,
.source-list a {
  color: var(--accent);
  font-weight: 800;
  text-decoration: none;
}

.card-actions a:hover,
.source-list a:hover {
  text-decoration: underline;
}

.table-shell {
  overflow: auto;
  border-top: 4px solid var(--accent);
}

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

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

th {
  position: sticky;
  top: 0;
  background: #eef6f3;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.empty-state {
  padding: 28px;
  color: var(--muted);
  line-height: 1.5;
}

.branch-grid,
.source-list {
  display: grid;
  gap: 10px;
  padding: 16px;
  border-top: 4px solid var(--accent);
}

.branch-row,
.source-row {
  display: grid;
  grid-template-columns: 80px minmax(0, 1fr) 180px;
  gap: 12px;
  align-items: start;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}

.source-row {
  grid-template-columns: 180px minmax(0, 1fr);
}

.branch-row:last-child,
.source-row:last-child {
  border-bottom: 0;
}

.code-pill {
  display: inline-flex;
  width: max-content;
  min-width: 42px;
  justify-content: center;
  border-radius: 999px;
  background: var(--mint);
  color: var(--accent-strong);
  padding: 5px 8px;
  font-weight: 850;
}

@media (max-width: 980px) {
  .topbar,
  .layout {
    padding-left: 18px;
    padding-right: 18px;
  }

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

  .source-status {
    justify-content: flex-start;
  }

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

  .filters {
    position: static;
  }

  .summary-band {
    grid-template-columns: repeat(3, 1fr);
  }

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

  .coverage-note {
    grid-column: 1 / -1;
  }
}

@media (max-width: 640px) {
  h1 {
    font-size: 24px;
  }

  .summary-band {
    grid-template-columns: 1fr;
  }

  .insights-panel {
    grid-template-columns: 1fr;
  }

  #cardsView.active {
    grid-template-columns: 1fr;
  }

  .facts,
  .branch-row,
  .source-row {
    grid-template-columns: 1fr;
  }
}
