:root {
  --paper: #f4f0e6;
  --ink: #241f1a;
  --muted: #534e46;
  --quiet: #6e675c;
  --line: #ddd4c4;
  --head: #e8e0d2;
  --sat: #e5d9c4;
  --rail: #7d6240;
  --up: #0c6730;
  --up-bg: #e3f3e8;
  --keep: #153e84;
  --keep-bg: #e6eef8;
  --down: #7a4200;
  --down-bg: #f8efd6;
  --stop: #8d2020;
  --stop-bg: #f8e4e4;
  --header-h: 3.4rem;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { scroll-padding-top: var(--header-h); }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: "Segoe UI", "Liberation Sans", "Noto Sans", "DejaVu Sans", system-ui, sans-serif;
  font-size: 0.975rem;
  line-height: 1.4;
}

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

button {
  font: inherit;
  color: inherit;
}

h1, h2, h3, h4, p { overflow-wrap: break-word; }

.vh {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.top {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.top-inner,
.page {
  width: min(1240px, calc(100% - 1.5rem));
  margin-inline: auto;
}

.top-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
  min-height: var(--header-h);
  padding: 0.4rem 0;
}

h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: -0.015em;
  line-height: 1.2;
}

.tabs {
  display: flex;
  gap: 0.3rem;
}

.tabs button {
  border: 1px solid transparent;
  background: transparent;
  padding: 0.42rem 0.95rem;
  font-size: 1.05rem;
  font-weight: 650;
  line-height: 1.2;
  cursor: pointer;
}

.tabs button[aria-selected="true"] {
  background: var(--ink);
  color: var(--paper);
}

.page { padding: 0.35rem 0 2.75rem; }

#spros, #offers { scroll-margin-top: var(--header-h); }

.notice { margin: 0.85rem 0 0; }
.notice p { margin: 0; }
.notice.is-error {
  padding: 0.7rem 0.8rem;
  background: var(--head);
  border: 1px solid var(--line);
}
.notice button {
  margin-top: 0.55rem;
  padding: 0.32rem 0.7rem;
  background: var(--ink);
  color: var(--paper);
  border: 0;
  cursor: pointer;
}

.demand-columns {
  display: block;
  margin-top: 0.85rem;
}

.status {
  display: inline-block;
  padding: 0.02rem 0.32rem;
  border-radius: 2px;
  font-size: 0.84rem;
  font-weight: 700;
  line-height: 1.35;
  white-space: nowrap;
}

.st-up { color: var(--up); background: var(--up-bg); }
.st-keep { color: var(--keep); background: var(--keep-bg); }
.st-down { color: var(--down); background: var(--down-bg); }
.st-stop { color: var(--stop); background: var(--stop-bg); }
.st-unknown { color: var(--ink); background: var(--head); }

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.45rem 1rem;
  margin: 1.25rem 0 0.4rem;
}

.section-head h2,
.block-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.015em;
}

.note {
  margin: 0.12rem 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.map {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.3rem 0.6rem;
}

.map button {
  padding: 0.28rem 0.55rem;
  background: transparent;
  border: 1px solid #c9bfb0;
  border-radius: 2px;
  color: var(--muted);
  font-size: 0.9rem;
}

.map button:disabled { cursor: not-allowed; }

.map p {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.demand {
  width: max-content;
  max-width: 100%;
  border-collapse: collapse;
}

.demand th,
.demand td {
  padding: 0.32rem 0.55rem;
  text-align: left;
  vertical-align: baseline;
  font-weight: 450;
}

.demand thead th {
  padding-bottom: 0.28rem;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 650;
  border-bottom: 1px solid var(--line);
}

.demand tbody tr > * { border-bottom: 1px solid var(--line); }

.demand tr.sat > * { background: var(--sat); }

.demand tr.sat > :first-child { padding-left: 1.2rem; }

.demand .status-cell { width: 1%; white-space: nowrap; }

.name-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.12rem 0.45rem;
}

.name { font-weight: 600; }

.badge {
  color: var(--quiet);
  background: transparent;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.25;
  padding: 0 0.15rem;
  border: 0;
  white-space: nowrap;
}

.lede {
  margin: 0.3rem 0 0.85rem;
  max-width: 42rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.block-title { margin-top: 0.95rem; }

.catalog {
  display: grid;
  grid-template-columns: minmax(15rem, 18.5rem) minmax(0, 1fr);
  gap: 0.5rem 1.5rem;
  align-items: start;
}

.cat-list {
  position: sticky;
  top: calc(var(--header-h) + 0.7rem);
  max-height: calc(100vh - var(--header-h) - 1.4rem);
  overflow: auto;
  padding-bottom: 0.5rem;
}

.glabel {
  margin: 0.85rem 0 0.2rem;
  padding: 0 0.55rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.cat-list .glabel:first-child { margin-top: 0.15rem; }

.cat-list button {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0.34rem 0.55rem;
  text-align: left;
  background: transparent;
  border: 0;
  border-left: 2px solid transparent;
  cursor: pointer;
  line-height: 1.3;
  scroll-margin-top: calc(var(--header-h) + 0.75rem);
}

.cat-list button[aria-current="true"] {
  border-left-color: var(--ink);
  background: var(--head);
}

#cat-title {
  margin: 0.1rem 0 0.75rem;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.015em;
}

.rules {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.1rem 1.75rem;
  align-items: start;
}

.rule-col h4 {
  margin: 0 0 0.4rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.95rem;
  font-weight: 700;
}

.rules ul {
  margin: 0;
  padding-left: 1.15rem;
}

.rules li {
  margin: 0.28rem 0;
  padding-left: 0.1rem;
}

.rules .empty {
  margin: 0;
  color: var(--muted);
}

.matrix-block {
  margin-top: 2.1rem;
  padding-top: 0.3rem;
  border-top: 1px solid var(--line);
}

.offer-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.15rem 0 0.75rem;
}

.offer-filters button {
  padding: 0.32rem 0.62rem;
  background: transparent;
  border: 1px solid #c9bfb0;
  border-radius: 2px;
  color: var(--ink);
  cursor: pointer;
  line-height: 1.25;
}

.offer-filters button[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

.matrix-empty {
  margin: 0 0 0.75rem;
  color: var(--muted);
}

.matrix-scroll {
  overflow: auto;
  max-height: calc(100vh - var(--header-h) - 1rem);
  border: 1px solid var(--line);
  background: var(--paper);
}

.matrix {
  border-collapse: separate;
  border-spacing: 0;
  width: max-content;
  min-width: 100%;
}

.matrix th,
.matrix td {
  padding: 0.3rem 0.45rem;
  font-weight: 450;
  vertical-align: middle;
  background: var(--paper);
}

.matrix thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 0;
  background: var(--head);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  text-align: center;
  vertical-align: bottom;
  min-width: 5.4rem;
  max-width: 7rem;
  border-bottom: 1px solid var(--line);
}

.matrix thead .sort {
  display: inline-flex;
  align-items: flex-end;
  justify-content: center;
  gap: 0.2rem;
  width: 100%;
  min-height: 2.6rem;
  margin: 0;
  padding: 0.35rem 0.4rem;
  background: transparent;
  border: 0;
  color: inherit;
  font: inherit;
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  cursor: pointer;
}

.matrix thead .sticky .sort { justify-content: flex-start; }

.matrix thead th[aria-sort="ascending"],
.matrix thead th[aria-sort="descending"] {
  color: var(--ink);
}

.matrix thead .arrow {
  flex: 0 0 auto;
  font-size: 0.62rem;
  line-height: 1;
}

.matrix .sticky {
  position: sticky;
  left: 0;
  z-index: 1;
  text-align: left;
  min-width: 11.5rem;
  max-width: 16rem;
  border-right: 1px solid var(--line);
  border-left: 3px solid transparent;
  background: var(--paper);
}

.matrix thead .sticky {
  z-index: 3;
  top: 0;
  left: 0;
  background: var(--head);
  min-width: 11.5rem;
  max-width: none;
}

.matrix tbody tr > * { border-bottom: 1px solid var(--line); }

.matrix tr.in-group .sticky { border-left-color: var(--rail); }

.matrix tr.sat td,
.matrix tr.sat .sticky {
  background: var(--sat);
}

.matrix tr.sat .sticky { padding-left: 1.05rem; }

.matrix tr.band .sticky,
.matrix tr.band td {
  background: var(--head);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  border-bottom: 1px solid var(--line);
}

.matrix td.mark { text-align: center; white-space: nowrap; }

.yes,
.no {
  display: inline-block;
  min-width: 2.15rem;
  padding: 0.04rem 0.34rem;
  border-radius: 2px;
  font-size: 0.84rem;
  font-weight: 700;
  line-height: 1.35;
}

.yes { color: var(--up); background: var(--up-bg); }
.no { color: var(--stop); background: var(--stop-bg); }

@media (min-width: 901px) {
  html[data-tab="spros"] .top-inner,
  html[data-tab="spros"] .page {
    width: min(1520px, calc(100% - 1.5rem));
  }

  .demand-columns {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 2rem;
  }

  .demand-columns > .demand-section {
    flex: 0 1 auto;
    width: max-content;
    max-width: calc((100% - 4rem) / 3);
    min-width: 0;
  }
}

@media (max-width: 860px) {
  .catalog { display: block; }

  .cat-list {
    top: var(--header-h);
    z-index: 8;
    display: flex;
    flex-wrap: nowrap;
    gap: 0.15rem;
    max-height: none;
    overflow-x: auto;
    overflow-y: hidden;
    margin: 0 0 0.85rem;
    padding: 0.4rem 0;
    background: var(--paper);
    border-bottom: 1px solid var(--line);
  }

  .glabel {
    flex: 0 0 auto;
    align-self: center;
    margin: 0 0.15rem 0 0.35rem;
    padding: 0;
  }

  .cat-list button {
    flex: 0 0 auto;
    width: auto;
    white-space: nowrap;
    border-left: 0;
    border-bottom: 2px solid transparent;
    padding: 0.4rem 0.55rem;
  }

  .cat-list button[aria-current="true"] {
    background: transparent;
    border-bottom-color: var(--ink);
  }
}

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

  .top-inner { flex-wrap: wrap; padding: 0.45rem 0; }

  .tabs { width: 100%; }

  .tabs button { flex: 1; }

  .page,
  .top-inner { width: min(1240px, calc(100% - 1rem)); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}
