:root {
  --accent-primary: #2563eb;
  --accent-soft: #e0f2fe;
  --accent-secondary: #0f766e;
  --accent-cool: #dbeafe;
  --surface-bg: #f8fafc;
  --surface-tint: #eef2ff;
  --accent-warm: #f59e0b;
  --ink: #1f2937;
  --panel: rgba(255, 255, 255, 0.94);
  --white: #ffffff;
  --line: rgba(31, 41, 55, 0.14);
  --muted: rgba(31, 41, 55, 0.64);
  --shadow: 0 18px 50px rgba(31, 41, 55, 0.08);
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 92% 12%, rgba(37, 99, 235, 0.15), transparent 22rem),
    radial-gradient(circle at 8% 24%, rgba(15, 118, 110, 0.12), transparent 20rem),
    linear-gradient(135deg, var(--surface-bg) 0%, var(--surface-tint) 100%);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1600px, calc(100% - 48px));
  margin: 0 auto;
  padding: 28px 0 38px;
}

.topbar {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 300px);
  gap: 18px;
  align-items: end;
  margin-bottom: 16px;
}

.topbar::after {
  display: none;
}

.title-head,
.source-block,
.filter-band,
.period-band,
.quick-band,
.kpi-card,
.insight-card,
.panel {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.title-head {
  min-height: 138px;
  border-radius: 8px;
  padding: 18px 20px;
  display: grid;
  align-content: center;
}

.eyebrow,
.period,
.panel-header p,
.source-block span,
.field span,
.kpi-card span,
.kpi-card small,
.panel-stat,
.rank-meta,
.watch-meta,
.subtext {
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-secondary);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-family: "Adelle", Georgia, serif;
  font-size: 2.45rem;
  line-height: 1.02;
  font-weight: 750;
}

.period {
  margin-top: 8px;
  font-size: 0.96rem;
}

.source-block {
  min-height: 138px;
  min-width: 0;
  border-radius: 8px;
  padding: 14px;
  display: grid;
  align-content: center;
  gap: 5px;
}

.source-block span {
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.source-block strong {
  overflow: hidden;
  color: var(--ink);
  font-size: 0.94rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filter-band {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(200px, 1.2fr) repeat(6, minmax(120px, 1fr)) minmax(380px, auto) 42px;
  gap: 10px;
  align-items: end;
  border-radius: 8px;
  padding: 12px;
  backdrop-filter: blur(12px);
}

.period-band {
  display: grid;
  grid-template-columns: repeat(6, minmax(130px, 1fr));
  gap: 10px;
  align-items: end;
  border-radius: 8px;
  margin-top: 10px;
  padding: 12px;
}

.quick-band {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  border-radius: 8px;
  margin-top: 10px;
  padding: 10px 12px;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field span {
  font-size: 0.76rem;
  font-weight: 800;
}

.field input,
.field select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-bg);
  color: var(--ink);
  padding: 0 10px;
  outline: none;
}

.field select:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.field input:focus,
.field select:focus,
.metric-button:focus,
.reset-button:focus {
  border-color: var(--accent-secondary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.18);
}

.metric-control {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
  height: 40px;
  border: 1px solid var(--line);
  background: rgba(37, 99, 235, 0.08);
  border-radius: 8px;
  padding: 3px;
}

.metric-button,
.quick-button,
.reset-button {
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  min-width: 0;
}

.metric-button {
  padding: 0 10px;
  font-size: 0.84rem;
  font-weight: 800;
  white-space: nowrap;
  overflow: visible;
  text-overflow: clip;
}

.quick-button {
  min-height: 34px;
  border-color: var(--line);
  background: var(--surface-bg);
  padding: 0 12px;
  font-size: 0.84rem;
  font-weight: 800;
}

.quick-button:hover {
  border-color: var(--accent-secondary);
  color: var(--accent-secondary);
}

.metric-button.active {
  background: var(--accent-secondary);
  color: var(--white);
}

.reset-button {
  width: 42px;
  height: 40px;
  border-color: var(--line);
  background: var(--surface-bg);
  color: var(--accent-primary);
  font-size: 1.22rem;
  line-height: 1;
}

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

.insight-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 0 0 14px;
}

.year-panel {
  margin-bottom: 14px;
}

.kpi-card,
.insight-card,
.panel {
  border-radius: 8px;
}

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

.kpi-card::after {
  content: "";
  position: absolute;
  right: -18px;
  bottom: -18px;
  width: 92px;
  height: 42px;
  background: var(--accent-cool);
  border-radius: 50% 50% 0 0;
  opacity: 0.78;
}

.insight-card {
  min-height: 92px;
  padding: 14px 16px;
  display: grid;
  gap: 7px;
  align-content: center;
}

.insight-card span,
.insight-card small {
  color: var(--muted);
}

.insight-card span {
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.insight-card strong {
  font-family: "Adelle", Georgia, serif;
  font-size: 1.38rem;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.kpi-card:nth-child(1)::after {
  background: var(--accent-primary);
}

.kpi-card:nth-child(2)::after {
  background: var(--accent-secondary);
}

.kpi-card:nth-child(3)::after {
  background: var(--accent-warm);
}

.kpi-card:nth-child(4)::after {
  background: var(--accent-soft);
}

.kpi-card span {
  font-size: 0.82rem;
  font-weight: 800;
}

.kpi-card strong {
  position: relative;
  z-index: 1;
  display: block;
  min-width: 0;
  font-family: "Adelle", Georgia, serif;
  font-size: 1.72rem;
  line-height: 1.12;
  font-weight: 760;
  overflow-wrap: anywhere;
}

.kpi-card small {
  position: relative;
  z-index: 1;
  font-size: 0.86rem;
}

.content-grid,
.table-grid {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.content-grid {
  grid-template-columns: minmax(0, 1.35fr) minmax(360px, 0.65fr);
}

.wide-left {
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.42fr);
}

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

.panel {
  min-width: 0;
  padding: 16px;
}

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

.panel-header h2 {
  font-family: "Adelle", Georgia, serif;
  font-size: 1.16rem;
  line-height: 1.22;
}

.panel-header p,
.panel-stat {
  margin-top: 4px;
  font-size: 0.86rem;
}

.panel-stat {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  background: var(--surface-bg);
  font-weight: 800;
}

.daily-chart {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(18px, 1fr));
  gap: 4px;
  align-items: end;
  height: 270px;
  border-bottom: 1px solid var(--line);
  padding-top: 18px;
}

.day-column {
  min-width: 0;
  height: 100%;
  display: grid;
  align-items: end;
  gap: 6px;
}

.day-bar {
  position: relative;
  min-height: 3px;
  border-radius: 6px 6px 0 0;
  background: linear-gradient(180deg, var(--accent-primary), #60a5fa);
}

.day-bar::after {
  content: attr(data-db);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 5px);
  transform: translateX(-50%);
  color: var(--muted);
  font-size: 0.66rem;
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}

.day-column:hover .day-bar::after {
  opacity: 1;
}

.day-label {
  min-height: 14px;
  text-align: center;
  color: var(--muted);
  font-size: 0.62rem;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}

.rank-list,
.watch-list,
.year-compare-list {
  display: grid;
  gap: 10px;
}

.rank-row,
.watch-row,
.year-compare-row {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.rank-top,
.watch-top,
.year-compare-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: baseline;
}

.rank-name,
.watch-name,
.year-compare-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.rank-value,
.watch-value,
.year-compare-value {
  font-weight: 800;
}

.rank-track,
.year-compare-track {
  height: 9px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(67, 60, 66, 0.1);
}

.rank-fill,
.year-compare-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--accent-primary);
}

.rank-meta,
.watch-meta,
.year-compare-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.78rem;
}

.year-compare-fill {
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
}

.year-compare-row.is-best .year-compare-name {
  color: var(--accent-secondary);
}

.matrix-wrap,
.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.matrix-table,
.data-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.matrix-table th,
.matrix-table td,
.data-table th,
.data-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: right;
  vertical-align: middle;
}

.matrix-table th:first-child,
.matrix-table td:first-child,
.data-table th:first-child,
.data-table td:first-child {
  text-align: left;
}

.matrix-table th,
.data-table th {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.matrix-table td {
  min-width: 116px;
  border-left: 1px solid var(--line);
  font-weight: 800;
}

.matrix-table td:first-child {
  min-width: 140px;
  border-left: 0;
  color: var(--ink);
}

.heat-cell {
  color: var(--ink);
}

.data-table th,
.data-table td {
  font-size: 0.88rem;
}

.data-table td:first-child {
  width: 42%;
}

.entity-name {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.entity-name strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.subtext {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.76rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 92px;
  min-height: 26px;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 0.76rem;
  font-weight: 800;
  white-space: nowrap;
}

.status-strong {
  background: var(--accent-cool);
  color: #1d4ed8;
}

.status-normal {
  background: rgba(67, 60, 66, 0.08);
  color: var(--ink);
}

.status-watch {
  background: var(--accent-warm);
  color: var(--white);
}

.status-risk {
  background: var(--accent-primary);
  color: var(--white);
}

.empty-state {
  min-height: 150px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  padding: 20px;
}

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

  .title-head {
    grid-column: span 2;
    grid-row: 1;
  }

  .topbar::after {
    display: none;
  }

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

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

  .search-field,
  .metric-control {
    grid-column: span 2;
  }

  .reset-button {
    width: 100%;
  }

  .content-grid,
  .wide-left,
  .table-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 20px, 1500px);
    padding-top: 18px;
  }

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

  .title-head {
    grid-column: auto;
    grid-row: auto;
  }

  h1 {
    font-size: 1.78rem;
  }

  .source-block,
  .title-head {
    min-height: 0;
    width: 100%;
  }

  .filter-band {
    position: static;
    grid-template-columns: 1fr;
  }

  .search-field,
  .metric-control {
    grid-column: auto;
  }

  .metric-control {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    height: auto;
  }

  .metric-button {
    min-height: 36px;
  }

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

  .period-band,
  .quick-band,
  .insight-grid {
    grid-template-columns: 1fr;
  }

  .quick-band {
    display: grid;
  }

  .kpi-card strong {
    font-size: 1.32rem;
  }

  .daily-chart {
    gap: 3px;
    height: 220px;
  }

  .day-label {
    font-size: 0.58rem;
  }
}

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

  .panel {
    padding: 12px;
  }

  .panel-header {
    display: grid;
  }

  .panel-stat {
    width: max-content;
  }
}
