:root {
  --bg: #f1f1f1;
  --panel: rgba(255, 255, 255, 0.96);
  --panel-strong: #ffffff;
  --ink: #333333;
  --muted: #61707c;
  --line: rgba(51, 51, 51, 0.12);
  --accent: #3c9794;
  --accent2: #2890a4;
  --accent-soft: #8fccca;
  --accent-deep: #1b5f5e;
  --green: #84bf84;
  --olive: #70a134;
  --danger: #da4531;
  --warning: #fe8b5f;
  --shadow: 0 18px 48px rgba(27, 95, 94, 0.08);
  --radius: 20px;
  --title-font: "HK Grotesk SemiBold", "HK Grotesk", "Segoe UI", sans-serif;
  --body-font: "HK Grotesk", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body-font);
}

body {
  min-height: 100vh;
}

.shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 24px;
  padding: 24px;
}

.sidebar,
.panel,
.hero {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.sidebar {
  position: sticky;
  top: 24px;
  align-self: start;
  border-radius: 28px;
  padding: 24px;
}

.brand-block h1,
.hero h2,
.panel h3 {
  margin: 0;
  font-family: var(--title-font);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-block h1 {
  font-size: 2rem;
  line-height: 1;
  margin-bottom: 12px;
}

.sidebar-snapshot {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
}

.sidebar-brand-logo {
  display: block;
  width: 78px;
  height: 78px;
  object-fit: contain;
  margin: 4px 0 14px;
  border-radius: 20px;
}

.lede,
.entity-meta,
.legend-block li,
label,
input,
select,
button,
table {
  font-size: 0.94rem;
}

.eyebrow {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.74rem;
  color: var(--accent-deep);
  font-weight: 700;
}

.control-group {
  display: grid;
  gap: 8px;
  margin-top: 18px;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mode-switch-3 {
  grid-template-columns: 1fr 1fr;
}

.mode-button-span2 {
  grid-column: 1 / -1;
}

/* ── trend chart inline metric selector ─────────────────────────────────── */
.trend-metric-select {
  display: block;
  margin-top: 6px;
  width: 100%;
  max-width: 360px;
  padding: 5px 10px;
  font-size: 12px;
  font-family: inherit;
  color: var(--text-secondary, #4a5e5b);
  background: var(--bg-card, #fff);
  border: 1px solid var(--border, #d1dbd9);
  border-radius: 6px;
  cursor: pointer;
}
.trend-metric-select:focus {
  outline: none;
  border-color: var(--accent, #1b5a5a);
}

/* ── peer-self row highlight ─────────────────────────────────────────────── */
tr.peer-self td {
  background: var(--accent-soft, #eaf3f2);
  font-weight: 600;
  color: var(--accent-deep, #14403f);
}

.mode-button {
  background: #ffffff;
  color: var(--accent-deep);
  font-weight: 700;
}

.mode-button.is-active {
  background: var(--accent-deep);
  color: #ffffff;
  border-color: var(--accent-deep);
}

label {
  font-weight: 600;
}

input,
select,
button {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  color: var(--ink);
  width: 100%;
}

input,
select {
  background: #ffffff;
  appearance: none;
}

button {
  background: transparent;
  cursor: pointer;
  transition: transform 160ms ease, background-color 160ms ease, color 160ms ease;
}

button:hover {
  transform: translateY(-1px);
}

.legend-block {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.legend-block ul {
  margin: 12px 0 0;
  padding-left: 18px;
  color: var(--muted);
  display: grid;
  gap: 10px;
}

.content {
  display: grid;
  gap: 20px;
}

.hero {
  border-radius: var(--radius);
  padding: 24px 26px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 18px;
  align-items: end;
}

.hero h2 {
  font-size: clamp(2rem, 3vw, 3.2rem);
  line-height: 0.95;
}

.entity-meta {
  margin: 10px 0 0;
  color: var(--muted);
  max-width: 60ch;
}

.hero-note {
  align-self: stretch;
  border-radius: 22px;
  background: linear-gradient(155deg, rgba(143, 204, 202, 0.25), rgba(60, 151, 148, 0.09));
  padding: 18px;
  display: grid;
  align-content: center;
}

.hero-logo {
  width: 72px;
  height: 72px;
  object-fit: contain;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.7);
  padding: 8px;
  margin: 0 0 10px;
}

.hero-note-label {
  margin: 0 0 8px;
  font-weight: 700;
}

.hero-note-topics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 10px;
}

.hero-topic-button {
  width: auto;
  min-width: 0;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--accent-deep);
  font-size: 0.82rem;
  font-weight: 700;
}

.hero-topic-button.is-active {
  background: var(--accent-deep);
  color: #ffffff;
  border-color: var(--accent-deep);
}

.hero-note p:last-child {
  margin: 0;
}

.compare-toggle.is-active {
  background: var(--accent-deep);
  color: white;
  border-color: var(--accent-deep);
}

.tab-panel {
  display: grid;
  gap: 20px;
}

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

.panel-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

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

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

.metric-card {
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 18px;
  display: grid;
  gap: 10px;
}

.tone-teal {
  background: linear-gradient(180deg, rgba(143, 204, 202, 0.22), rgba(255, 255, 255, 0.98));
}

.tone-amber {
  background: linear-gradient(180deg, rgba(254, 139, 95, 0.16), rgba(255, 255, 255, 0.98));
}

.tone-ink {
  background: linear-gradient(180deg, rgba(27, 95, 94, 0.12), rgba(255, 255, 255, 0.98));
}

.tone-rose {
  background: linear-gradient(180deg, rgba(218, 69, 49, 0.12), rgba(255, 255, 255, 0.98));
}

.metric-topline {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: start;
}

.metric-label {
  font-size: 0.9rem;
  color: var(--muted);
}

.metric-value {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -0.04em;
}

.metric-delta {
  display: grid;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

.delta-positive {
  color: var(--accent-deep);
}

.delta-negative {
  color: var(--danger);
}

.panel {
  border-radius: var(--radius);
  padding: 22px 24px;
}

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

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

.toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.compare-toggle {
  width: auto;
}

.export-button {
  width: auto;
  min-width: 0;
  padding: 9px 12px;
  border-radius: 999px;
  background: #ffffff;
  color: var(--accent-deep);
  border-color: rgba(27, 95, 94, 0.2);
  font-size: 0.84rem;
  font-weight: 700;
}

.export-button:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.chart-wrap {
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(143, 204, 202, 0.16), rgba(255, 255, 255, 0.9));
  padding: 14px;
}

#trend-chart {
  width: 100%;
  height: 340px;
  display: block;
}

#system-balance-chart,
#entity-balance-chart {
  width: 100%;
  height: 300px;
  display: block;
}

.beta-badge {
  display: inline-block;
  background: rgba(13, 107, 92, 0.12);
  color: #0d6b5c;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 20px;
  margin-top: 6px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.table-wrap {
  overflow: auto;
}

.compact-top {
  margin-top: 14px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

tbody tr:hover {
  background: rgba(143, 204, 202, 0.12);
}

.empty-state {
  color: var(--muted);
}

.report-section {
  padding-top: 14px;
  border-top: 2px solid var(--warning);
  display: grid;
  gap: 16px;
}

.report-section:first-child {
  padding-top: 0;
  border-top: 0;
}

.report-section-title {
  margin: 0;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.report-summary-grid {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 18px;
  align-items: center;
}

.report-columns-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.donut-card,
.bars-card,
.ranking-card {
  background: rgba(255, 255, 255, 0.64);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 16px;
}

.donut-wrap {
  display: grid;
  place-items: center;
  gap: 10px;
}

.donut-svg {
  width: 180px;
  height: 180px;
}

.donut-legend {
  display: grid;
  gap: 8px;
  width: 100%;
}

.legend-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  font-size: 0.88rem;
}

.legend-name {
  display: flex;
  align-items: center;
  gap: 8px;
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
}

.bars-list,
.ranking-list {
  display: grid;
  gap: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr) 130px;
  gap: 10px;
  align-items: start;
  font-size: 0.86rem;
}

.bar-track {
  position: relative;
  height: 18px;
  border-radius: 999px;
  background: rgba(27, 42, 47, 0.08);
  overflow: hidden;
}

.bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 999px;
}

.bar-fill.private {
  background: var(--accent2, #2890a4);
}

.bar-fill.public {
  background: #c9d5ea;
}

.bar-value {
  text-align: right;
  color: var(--ink);
}

.ranking-header {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.85rem;
  flex-wrap: wrap;
}

.ranking-header-spacer {
  flex: 1;
}

.ranking-header-unit {
  min-width: 110px;
  text-align: right;
  font-size: 0.78rem;
  font-weight: 700;
}

.ranking-line {
  display: grid;
  grid-template-columns: minmax(170px, 1.6fr) 90px 120px;
  gap: 10px;
  align-items: start;
  padding: 5px 0;
  border-bottom: 1px solid rgba(27, 42, 47, 0.07);
  font-size: 0.85rem;
}

.ranking-line:last-child {
  border-bottom: 0;
}

.ranking-name {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.ranking-share {
  text-align: right;
}

.group-private {
  color: #2890a4;
}

.group-public {
  color: #8fa0ba;
}

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

  .sidebar {
    position: static;
  }

  .hero,
  .dual-panels {
    grid-template-columns: 1fr;
  }

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

  .report-summary-grid,
  .report-columns-3 {
    grid-template-columns: 1fr;
  }

  .panel-header {
    align-items: flex-start;
  }
}

@media (max-width: 720px) {
  .shell {
    padding: 14px;
    gap: 14px;
  }

  .sidebar,
  .hero,
  .panel {
    padding: 18px;
    border-radius: 22px;
  }

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

  .mode-button,
  .compare-toggle,
  .export-button,
  .hero-topic-button {
    width: 100%;
    min-width: 0;
  }

  .bar-row,
  .ranking-line {
    grid-template-columns: 1fr;
  }
}
