:root {
  --c-bg: #f7f8fa;
  --c-card: #ffffff;
  --c-text: #1a1f2e;
  --c-text-soft: #5b6478;
  --c-border: #e5e8ee;
  --c-accent: #2d5bff;
  --c-good-bg: #d4f4dd;
  --c-good-text: #1a7f37;
  --c-mid-bg:  #fff5cc;
  --c-mid-text:  #946a00;
  --c-bad-bg:  #ffd7d7;
  --c-bad-text:  #b42318;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

main {
  flex: 1 1 auto;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
main:has(#status:not([hidden])),
main:has(#report-mount > *) {
  justify-content: flex-start;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  border: 0; overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* === Search === */
.search { margin-bottom: 16px; }

#search-form {
  display: flex;
  gap: 8px;
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 10px;
  box-shadow: var(--shadow);
}

#search-form input[type="text"] {
  flex: 1 1 auto;
  min-width: 0;
  height: 44px;
  padding: 0 12px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--c-text);
  background: transparent;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  text-transform: uppercase;
  letter-spacing: .02em;
}

#search-form input[type="text"]::placeholder {
  color: var(--c-text-soft);
  text-transform: none;
  letter-spacing: 0;
}

#search-form input[type="text"]:focus,
#search-form input[type="text"]:focus-visible {
  outline: 2px solid var(--c-accent);
  outline-offset: 1px;
  border-color: var(--c-accent);
}

#search-form .year-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}
#search-form .year-group select {
  height: 44px;
  padding: 0 28px 0 10px;
  font-size: 1rem;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  color: var(--c-text);
  background: transparent;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path fill='%235b6478' d='M0 0l5 6 5-6z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
#search-form .year-group select:focus,
#search-form .year-group select:focus-visible {
  outline: 2px solid var(--c-accent);
  outline-offset: 1px;
  border-color: var(--c-accent);
}
#search-form .year-group select option:disabled {
  color: var(--c-text-soft);
}
#search-form .year-group .year-sep {
  color: var(--c-text-soft);
  font-size: .9rem;
}

#search-form button {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 0 18px;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  color: #fff;
  background: var(--c-accent);
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color .12s ease, transform .12s ease;
}
#search-form button:hover { background: #1f47d6; }
#search-form button:active { transform: translateY(1px); }
#search-form button:focus-visible {
  outline: 2px solid var(--c-text);
  outline-offset: 2px;
}

/* === Status / loader / error === */
#status { margin-bottom: 16px; }

.loader {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  color: var(--c-text-soft);
  font-size: .95rem;
}
.loader::before {
  content: "";
  display: inline-block;
  width: 14px; height: 14px;
  margin-right: 10px;
  vertical-align: -2px;
  border: 2px solid var(--c-border);
  border-top-color: var(--c-accent);
  border-radius: 50%;
  animation: loader-spin .9s linear infinite;
}
@keyframes loader-spin { to { transform: rotate(360deg); } }

.error-box {
  margin-top: 8px;
  background: var(--c-bad-bg);
  color: var(--c-bad-text);
  border: 1px solid rgba(180, 35, 24, .25);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: .95rem;
}

/* === Report header === */
.report-header {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.report-header h1 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.25;
  letter-spacing: -0.01em;
}
.report-header .ticker {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 8px;
  font-size: .82rem;
  font-weight: 600;
  color: var(--c-accent);
  background: rgba(45, 91, 255, .08);
  border-radius: 999px;
  vertical-align: middle;
  letter-spacing: .02em;
}
.report-header .years {
  margin: 6px 0 0;
  color: var(--c-text-soft);
  font-size: .9rem;
}
.report-header nav {
  margin-top: 10px;
  font-size: .9rem;
}
.report-header nav a {
  color: var(--c-accent);
  text-decoration: none;
  font-weight: 500;
}
.report-header nav a:hover { text-decoration: underline; }
.report-header nav a:focus-visible {
  outline: 2px solid var(--c-accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* === Report body === */
/* Block layout (not flex) — WeasyPrint's flex+gap+break-inside combination
   overlaps sections on the page when card content is wide (e.g. GAZP with
   trillion-rouble figures). Plain margins are bulletproof in paged media. */
.report-body { display: block; }

.report-section,
.report-verdict { margin-bottom: 16px; }
.report-section:last-child,
.report-verdict:last-child { margin-bottom: 0; }

.report-section {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 14px 14px 6px;
  box-shadow: var(--shadow);
}
.report-section h2 {
  margin: 0 0 10px;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.005em;
}

/* === Metrics table === */
.metrics {
  width: 100%;
  border-collapse: collapse;
  font-size: .92rem;
}
.metrics thead th {
  text-align: left;
  padding: 8px 6px;
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--c-text-soft);
  border-bottom: 1px solid var(--c-border);
}
.metrics tbody th,
.metrics tbody td {
  padding: 10px 6px;
  border-bottom: 1px solid var(--c-border);
  vertical-align: top;
  text-align: left;
}
.metrics tbody tr:last-child th,
.metrics tbody tr:last-child td { border-bottom: 0; }
.metrics .col-label { font-weight: 500; }
.metrics .num {
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}
.metrics .col-ref {
  color: var(--c-text-soft);
  font-size: .86rem;
  line-height: 1.4;
  min-width: 200px;
}

.value-cell { font-weight: 600; }
.value-cell.c-good { color: var(--c-good-text); background: var(--c-good-bg); border-radius: 6px; }
.value-cell.c-mid  { color: var(--c-mid-text);  background: var(--c-mid-bg);  border-radius: 6px; }
.value-cell.c-bad  { color: var(--c-bad-text);  background: var(--c-bad-bg);  border-radius: 6px; }
.value-cell.c-neutral { color: var(--c-text); }

/* === Verdict === */
.report-verdict {
  border-radius: var(--radius);
  padding: 22px 18px;
  text-align: center;
  border: 1px solid var(--c-border);
  background: var(--c-card);
  box-shadow: var(--shadow);
}
.report-verdict h2 {
  margin: 0 0 8px;
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--c-text-soft);
}
.report-verdict .verdict-label {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.01em;
}
.report-verdict .verdict-score {
  margin: 8px 0 0;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  color: var(--c-text-soft);
}
.report-verdict.v-good { background: var(--c-good-bg); border-color: rgba(26, 127, 55, .25); }
.report-verdict.v-good .verdict-label { color: var(--c-good-text); }
.report-verdict.v-good .verdict-score { color: var(--c-good-text); opacity: .85; }
.report-verdict.v-mid  { background: var(--c-mid-bg);  border-color: rgba(148, 106, 0, .25); }
.report-verdict.v-mid  .verdict-label { color: var(--c-mid-text); }
.report-verdict.v-mid  .verdict-score { color: var(--c-mid-text); opacity: .85; }
.report-verdict.v-bad  { background: var(--c-bad-bg);  border-color: rgba(180, 35, 24, .25); }
.report-verdict.v-bad  .verdict-label { color: var(--c-bad-text); }
.report-verdict.v-bad  .verdict-score { color: var(--c-bad-text); opacity: .85; }

/* === Standalone report page layout === */
body.report-page {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
}
body.report-page > main {
  padding: 0;
  max-width: none;
  justify-content: flex-start;
}

/* === Mobile compaction (< 600px) === */
@media screen and (max-width: 599px) {
  main { padding: 12px; }
  body.report-page { padding: 12px; }

  /* Search form: stack input, year selectors and button on small screens */
  #search-form { flex-wrap: wrap; }
  #search-form input[type="text"] { flex-basis: 100%; }
  #search-form .year-group { flex: 1 1 100%; }
  #search-form .year-group select { flex: 1 1 0; min-width: 0; }
  #search-form button { width: 100%; }

  .report-header { padding: 14px; }
  .report-header h1 { font-size: 1.15rem; }

  .report-section { padding: 14px; }
  .report-section h2 { font-size: 1rem; }

  .report-verdict { padding: 18px 14px; }
  .report-verdict .verdict-label { font-size: 1.2rem; line-height: 1.25; }

  /* Metrics: stack each row as a card with labelled values */
  .metrics, .metrics tbody, .metrics tbody tr { display: block; }
  .metrics thead { display: none; }

  .metrics tbody tr {
    padding: 12px 0;
    border-bottom: 1px solid var(--c-border);
  }
  .metrics tbody tr:first-child { padding-top: 4px; }
  .metrics tbody tr:last-child { padding-bottom: 4px; border-bottom: 0; }

  .metrics tbody th,
  .metrics tbody td {
    display: block;
    padding: 0;
    border: 0;
    text-align: left;
    white-space: normal;
  }
  .metrics .num { text-align: left; }
  .metrics .col-label {
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 6px;
  }
  .metrics .col-year,
  .metrics .col-dyn { padding: 3px 0; }
  .metrics .col-year::before,
  .metrics .col-dyn::before {
    content: attr(data-label) ":\00a0";
    color: var(--c-text-soft);
    font-weight: 500;
  }
  .metrics .value-cell {
    display: inline-block;
    padding: 1px 8px;
  }
  .metrics .col-ref {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed var(--c-border);
    color: var(--c-text-soft);
    font-size: .85rem;
    line-height: 1.4;
    min-width: 0;
  }
}

/* === Accessibility: reduced motion === */
@media screen and (prefers-reduced-motion: reduce) {
  .loader::before { animation: none; }
  #search-form button { transition: none; }
}

/* === Print === */
@media print {
  @page { size: A4; margin: 12mm; }
  html, body { background: #fff !important; }
  body { font-size: 9.5pt; }
  .no-print { display: none !important; }
  body, body.report-page { max-width: none; padding: 0; margin: 0; }
  main { max-width: none; padding: 0; margin: 0; }
  .report-header, .report-section, .report-verdict {
    box-shadow: none !important;
    border-color: #ccc !important;
  }
  .report-section, .report-verdict { break-inside: avoid !important; page-break-inside: avoid !important; }
  .metrics th, .metrics td { padding: 4pt 6pt !important; }
  .metrics .col-ref { font-size: 8.5pt; color: #444; }
}
