:root {
  color-scheme: light;
  --bg: #f5f7f9;
  --surface: #ffffff;
  --ink: #151a20;
  --muted: #667085;
  --line: #d7dee6;
  --accent: #1769aa;
  --accent-soft: #e8f2fb;
  --good: #0f7b55;
  --warn: #9a6700;
}

* {
  box-sizing: border-box;
}

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

.page-shell {
  width: min(1280px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-end;
  margin-bottom: 20px;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 32px;
}

h2 {
  font-size: 18px;
}

.metadata {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px 14px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

a {
  color: var(--accent);
}

.link-button {
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  padding: 0;
  text-decoration: underline;
}

.secondary-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  padding: 7px 10px;
}

.secondary-button[aria-expanded="true"] {
  border-color: var(--accent);
  color: var(--accent);
}

.is-hidden {
  display: none;
}

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

.summary-card {
  min-height: 88px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 15px;
}

.summary-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.summary-card strong {
  display: block;
  font-size: 25px;
  line-height: 1.1;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 2fr) repeat(5, minmax(130px, 1fr));
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
  margin-bottom: 16px;
}

label {
  display: grid;
  gap: 6px;
}

label span {
  color: var(--muted);
  font-size: 12px;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--ink);
  font: inherit;
  padding: 8px 10px;
}

select[multiple] {
  min-height: 74px;
}

.content-grid {
  display: grid;
  grid-template-columns: 1.35fr 0.85fr;
  gap: 16px;
}

.panel {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  min-width: 0;
}

.panel.wide {
  grid-column: 1 / -1;
}

.panel-header {
  padding: 16px 18px 0;
}

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

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

#result-count {
  color: var(--muted);
  font-size: 13px;
}

#subthemes-context {
  color: var(--muted);
  font-size: 13px;
}

#clusters-context {
  color: var(--muted);
  font-size: 13px;
}

#cluster-years-context {
  color: var(--muted);
  font-size: 13px;
}

#tuning-context {
  color: var(--muted);
  font-size: 13px;
}

.chart-shell {
  min-height: 340px;
  padding: 16px;
}

.line-chart {
  min-height: 300px;
}

.line-chart svg {
  display: block;
  width: 100%;
  height: 300px;
}

.line-chart text {
  fill: var(--muted);
  font-size: 11px;
}

.line-chart .grid-line {
  stroke: #edf1f5;
  stroke-width: 1;
}

.line-chart .series-line {
  fill: none;
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.line-chart .series-point {
  fill: var(--surface);
  stroke: var(--accent);
  stroke-width: 2;
}

.rank-list {
  display: grid;
  gap: 10px;
  padding: 16px 18px 18px;
}

.rank-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

button.rank-item {
  width: 100%;
  border-right: 0;
  border-left: 0;
  border-top: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  text-align: left;
}

button.rank-item:hover .rank-name {
  color: var(--accent);
}

.rank-item:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

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

.rank-count {
  color: var(--muted);
  font-size: 13px;
}

.bar {
  grid-column: 1 / -1;
  height: 7px;
  border-radius: 999px;
  background: #edf1f5;
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  background: var(--accent);
}

.proposition-list {
  display: grid;
  padding: 10px 18px 18px;
}

.proposition-card {
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding: 16px 0;
}

.proposition-card:first-child {
  border-top: 0;
}

.proposition-title {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: baseline;
}

.badge {
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  padding: 4px 7px;
}

.ementa {
  color: #2f3a45;
  line-height: 1.45;
}

.meta-row,
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  background: #fbfcfd;
}

.subtheme-chart {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(58px, 1fr));
  align-items: end;
  gap: 12px;
  min-height: 300px;
  padding: 16px 18px 18px;
}

.subtheme-bar {
  display: grid;
  align-items: end;
  gap: 7px;
  min-width: 0;
  height: 270px;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  padding: 0;
  text-align: center;
}

.subtheme-bar span {
  display: block;
  min-height: 4px;
  border-radius: 5px 5px 0 0;
  background: var(--accent);
}

.subtheme-bar strong {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.subtheme-bar em {
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
  line-height: 1.2;
  min-height: 38px;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.subtheme-bar:hover span {
  background: var(--good);
}

.subtheme-bar:hover em {
  color: var(--ink);
}

.empty {
  padding: 22px 0;
  color: var(--muted);
}

.cluster-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  padding: 16px 18px 18px;
}

.tab-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 18px 0;
}

.tab-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  padding: 8px 10px;
}

.tab-button.is-active {
  border-color: var(--accent);
  color: var(--accent);
}

.cluster-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 14px;
}

.cluster-card h3 {
  margin: 0 0 8px;
  font-size: 16px;
  text-transform: capitalize;
}

.cluster-card p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  margin: 8px 0 0;
}

.cluster-meta {
  color: var(--muted);
  font-size: 12px;
}

.table-shell {
  overflow-x: auto;
  padding: 16px 18px 18px;
}

.year-table-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  padding-top: 8px;
}

.year-table-grid h3 {
  margin: 0;
  padding: 0 18px;
  font-size: 15px;
}

.metric-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-size: 13px;
}

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

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

.metric-table th {
  color: var(--muted);
  font-weight: 600;
}

.metric-table td strong,
.metric-table td span {
  display: block;
}

.metric-table td span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.metric-table tr.is-best {
  background: var(--accent-soft);
}

.pdf-report {
  display: none;
}

.report-page {
  color: #111827;
  font-family: Arial, Helvetica, sans-serif;
}

.report-page h1 {
  font-size: 26px;
  margin-bottom: 4px;
}

.report-page h2 {
  border-bottom: 1px solid #d7dee6;
  font-size: 17px;
  margin: 22px 0 10px;
  padding-bottom: 6px;
}

.report-meta {
  color: #4b5563;
  font-size: 12px;
  margin-bottom: 16px;
}

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

.report-card {
  border: 1px solid #d7dee6;
  padding: 10px;
}

.report-card span {
  color: #4b5563;
  display: block;
  font-size: 11px;
  margin-bottom: 5px;
}

.report-card strong {
  font-size: 18px;
}

.report-table {
  border-collapse: collapse;
  font-size: 11px;
  margin-bottom: 14px;
  width: 100%;
}

.report-table th,
.report-table td {
  border-bottom: 1px solid #d7dee6;
  padding: 6px;
  text-align: right;
  vertical-align: top;
}

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

@media (max-width: 960px) {
  .page-header,
  .content-grid {
    display: grid;
  }

  .metadata {
    justify-content: flex-start;
  }

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

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

}

@media (max-width: 620px) {
  .summary-grid,
  .toolbar {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 26px;
  }

  .chart-shell {
    height: 300px;
  }
}

@media print {
  @page {
    margin: 14mm;
    size: A4;
  }

  body {
    background: #ffffff;
  }

  .page-shell {
    display: none;
  }

  .pdf-report {
    display: block;
  }

  .report-section {
    break-inside: avoid;
  }
}
