:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #17212b;
  --muted: #5f6b7a;
  --line: #cfd6df;
  --primary: #1f5f99;
  --primary-dark: #174973;
  --warn: #9a6700;
  --warn-bg: #fff4d6;
  --success: #14532d;
  --success-bg: #eaf6ee;
  --active: #7a3f00;
  --active-bg: #fff2e5;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.42;
}

a {
  color: var(--primary);
  text-decoration: none;
}

.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  color: var(--text);
  font-weight: 700;
  font-size: 18px;
}

nav {
  display: flex;
  gap: 16px;
  align-items: center;
}

.nav-form {
  margin: 0;
}

.nav-form button {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  padding: 0;
}

.page {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px;
}

section {
  margin-bottom: 24px;
}

.band {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 20px;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

h1, h2, h3, p {
  margin: 0;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 18px;
  margin-bottom: 12px;
}

h3 {
  font-size: 16px;
  margin: 16px 0 8px;
}

p, .muted, .sub {
  color: var(--muted);
}

.metrics,
.facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.metric,
.facts div {
  border: 1px solid var(--line);
  background: #fbfcfe;
  padding: 12px;
}

.metric span,
.facts span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.metric strong,
.facts strong {
  font-size: 18px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.sync-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.source-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.source-panel {
  border: 1px solid var(--line);
  background: #fbfcfe;
  padding: 12px;
}

.source-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.source-title span,
.source-foot {
  color: var(--muted);
  font-size: 12px;
}

.source-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(90px, 1fr));
  gap: 8px;
}

.source-metrics div {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.source-metrics span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 3px;
}

.source-metrics strong {
  font-size: 17px;
}

.source-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.law-blocks {
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  gap: 12px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  gap: 12px;
}

.dashboard-card {
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 16px;
}

.dashboard-card-wide {
  grid-column: span 2;
}

.dashboard-card h2 {
  margin-bottom: 4px;
}

.card-title-row,
.compact-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.card-title-row h2,
.compact-card-head h2 {
  margin-bottom: 0;
}

.count-badge {
  border: 1px solid var(--line);
  background: #eef4ff;
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  padding: 3px 7px;
  white-space: nowrap;
}

.mini-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.mini-metrics span,
.action-list em {
  border: 1px solid var(--line);
  background: #fbfcfe;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 600;
  padding: 2px 6px;
}

.action-list strong {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.dashboard-compact-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(260px, 1fr));
  gap: 12px;
}

.compact-card {
  min-width: 0;
}

.compact-card-head {
  margin-bottom: 10px;
}

.compact-card-head a {
  font-size: 12px;
}

.action-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.action-list a {
  display: grid;
  gap: 3px;
  color: var(--text);
  border: 1px solid var(--line);
  background: #fbfcfe;
  padding: 10px;
}

.action-list span {
  color: var(--muted);
  font-size: 12px;
}

.enrich-form {
  grid-template-columns: minmax(180px, 1fr) auto;
  margin-top: 12px;
}

.law-block {
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 14px;
}

.law-block-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.law-block h2 {
  margin-bottom: 4px;
}

.law-groups {
  display: grid;
  gap: 8px;
}

.law-group {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.law-group span,
.law-group small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.law-group-count {
  min-width: 92px;
  text-align: right;
}

.law-group-count strong {
  font-size: 22px;
}

.panel-form,
.request-form,
.filters {
  display: grid;
  gap: 12px;
  align-items: end;
}

.request-form,
.filters {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.wide {
  grid-column: span 2;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 8px 10px;
  font: inherit;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid #c7dcf2;
  outline-offset: 1px;
  border-color: var(--primary);
}

textarea {
  min-height: 90px;
  resize: vertical;
}

.button {
  min-height: 36px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 8px 12px;
  font: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.button.primary:hover {
  background: var(--primary-dark);
}

.button:disabled {
  cursor: default;
  opacity: 0.65;
}

.button.small {
  min-height: 30px;
  padding: 5px 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  background: #edf1f5;
}

tbody tr:hover {
  background: #f8fafc;
}

.badge {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  border: 1px solid var(--line);
  padding: 2px 8px;
  background: #fff;
}

.badge.compact {
  min-height: 20px;
  padding: 1px 6px;
  font-size: 12px;
}

.badge.warn {
  color: var(--warn);
  border-color: #f3ce73;
  background: var(--warn-bg);
  margin-left: 6px;
}

.status-badge {
  font-weight: 700;
}

.status-ec {
  color: var(--success);
  border-color: #9bc9aa;
  background: var(--success-bg);
}

.status-e {
  color: var(--active);
  border-color: #efbf86;
  background: var(--active-bg);
}

.badge.state-enabled {
  color: #125c2f;
  border-color: #a8d5b8;
  background: #edf8f1;
}

.badge.state-disabled {
  color: #5c6670;
  background: #f4f6f8;
}

.badge.state-out_of_scope {
  color: #5c6670;
  background: #f8f9fb;
}

.badge.state-unconfigured {
  color: var(--warn);
  border-color: #f3ce73;
  background: var(--warn-bg);
}

.note {
  border: 1px solid var(--line);
  background: #fbfcfe;
  padding: 12px;
  line-height: 1.5;
}

.help-note {
  border-left: 3px solid var(--primary);
  background: #fbfcfe;
  color: var(--muted);
  padding: 9px 10px;
  margin: 8px 0 12px;
  line-height: 1.45;
}

.guide {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.compact-guide {
  margin-top: 0;
}

.guide-card {
  border: 1px solid var(--line);
  background: #fbfcfe;
  padding: 10px;
  min-width: 0;
}

.guide-card strong,
.guide-card span {
  display: block;
}

.guide-card span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  margin-top: 4px;
}

.status-flow {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  margin: 12px 0;
}

.status-flow div {
  border: 1px solid var(--line);
  background: #fbfcfe;
  padding: 9px;
}

.status-flow div.active {
  border-color: var(--primary);
  background: #eef4ff;
}

.status-flow strong,
.status-flow span {
  display: block;
}

.status-flow span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  margin-top: 3px;
}

.request-stage {
  margin-top: 12px;
}

.guide-details {
  border: 1px solid var(--line);
  background: var(--surface);
  margin-bottom: 24px;
}

.guide-details > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: #eef1f5;
  color: var(--text);
  list-style: none;
}

.guide-details > summary::-webkit-details-marker {
  display: none;
}

.guide-details > summary::after {
  content: "+";
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-weight: 700;
  flex: 0 0 auto;
}

.guide-details[open] > summary::after {
  content: "-";
}

.guide-details small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.details-body {
  padding: 0 14px 14px;
}

.inner-panel {
  margin: 14px 0 0;
}

code {
  display: block;
  margin-top: 8px;
  white-space: pre-wrap;
  color: var(--text);
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 18px;
}

.clip {
  max-width: 440px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compact-table {
  table-layout: fixed;
  font-size: 12px;
}

.compact-table th,
.compact-table td {
  padding: 7px;
}

.compact-table td {
  overflow: hidden;
  text-overflow: ellipsis;
}

.diagnostic-badge {
  cursor: help;
  max-width: 100%;
}

.copy-button {
  min-height: 22px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font: inherit;
  font-size: 11px;
  padding: 1px 5px;
  cursor: pointer;
  margin-left: 4px;
}

.copy-button:hover {
  color: var(--primary);
  border-color: var(--primary);
}

.clip-text {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-height: 1.35;
}

.good {
  background: var(--surface);
  border-top: 3px solid #344054;
  padding: 18px;
}

.statline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.statline span {
  border: 1px solid var(--line);
  padding: 6px 8px;
  background: #fbfcfe;
}

.warning {
  color: var(--warn);
  background: var(--warn-bg);
  border: 1px solid #f3ce73;
  padding: 10px;
  margin-bottom: 12px;
}

.panel {
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 14px;
  min-width: 0;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tab {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 7px 10px;
}

.tab.active {
  border-color: var(--primary);
  color: var(--primary);
  background: #eef4ff;
}

.strong-link {
  font-weight: 700;
}

.request-journal td:first-child {
  min-width: 150px;
}

.request-create-grid,
.request-workspace {
  display: grid;
  grid-template-columns: minmax(340px, 0.9fr) minmax(520px, 1.4fr);
  gap: 16px;
  align-items: start;
}

.lookup-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: 8px;
  align-items: end;
}

.compact-head {
  margin-bottom: 10px;
}

.compact-fields,
.compact-filters {
  gap: 8px;
}

.catalog-results {
  margin-top: 12px;
}

.catalog-list,
.good-list,
.selected-list {
  display: grid;
  gap: 8px;
}

.catalog-item,
.good-card,
.selected-card {
  border: 1px solid var(--line);
  background: #fbfcfe;
  padding: 10px;
  min-width: 0;
}

.catalog-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.good-card {
  color: var(--text);
  display: grid;
  gap: 4px;
}

.good-card span {
  color: var(--muted);
  font-size: 12px;
}

.good-card.active {
  border-color: var(--primary);
  background: #eef4ff;
}

.manual-good {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 120px 100px 110px auto;
  gap: 8px;
  align-items: end;
  margin-bottom: 12px;
}

.cart-table input[name="quantity"] {
  min-width: 96px;
}

.request-left,
.request-right {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.request-right {
  position: sticky;
  top: 76px;
}

.request-extra {
  margin-top: 12px;
}

.compact-statline {
  justify-content: flex-start;
  margin-bottom: 10px;
}

.selected-top {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}

.exclusion-form {
  margin-top: 8px;
}

.nested-filters {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  margin-top: 8px;
}

.advanced-panel {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.compact-form {
  grid-template-columns: repeat(3, minmax(160px, 240px));
  margin-bottom: 12px;
}

.okpd2-catalog {
  display: grid;
  gap: 8px;
  font-size: 13px;
}

.okpd2-section {
  margin: 0;
  border: 1px solid var(--line);
  background: var(--surface);
}

.okpd2-section summary {
  display: flex;
  gap: 8px;
  align-items: center;
  min-height: 38px;
  padding: 8px 12px;
  color: var(--text);
  background: #eef1f5;
  list-style: none;
}

.okpd2-section summary::-webkit-details-marker {
  display: none;
}

.okpd2-section summary::before {
  content: "+";
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-weight: 700;
}

.okpd2-section[open] summary::before {
  content: "-";
}

.okpd2-section.food-section summary {
  background: #eaf5ee;
}

.section-code {
  display: inline-flex;
  min-width: 28px;
  font-weight: 700;
}

.okpd2-classes {
  display: grid;
}

.okpd2-class {
  display: grid;
  grid-template-columns: minmax(220px, 0.75fr) minmax(560px, 2fr);
  gap: 10px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
}

.okpd2-class.food-row {
  background: #fbfefc;
}

.okpd2-class-head {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 8px;
  line-height: 1.3;
}

.okpd2-class-head strong {
  white-space: nowrap;
}

.okpd2-sources {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 8px;
}

.okpd2-source {
  border: 1px solid var(--line);
  background: #fbfcfe;
  padding: 8px;
  min-width: 0;
}

.okpd2-source-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.okpd2-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.okpd2-actions form {
  margin: 0;
}

.search-results {
  margin-top: 12px;
}

.results-table td {
  max-width: 360px;
}

.contract-summary {
  display: grid;
  gap: 5px;
  min-width: 210px;
}

.contract-summary-main,
.contract-summary-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.contract-summary-main a:first-child {
  font-weight: 700;
}

.contract-eis-link {
  color: var(--primary);
  font-size: 12px;
  text-decoration: underline;
  width: fit-content;
}

.contract-summary .badge {
  white-space: nowrap;
}

th.col-customer_name,
td.col-customer_name {
  min-width: 360px;
}

th.col-delivery_address,
td.col-delivery_address {
  min-width: 420px;
}

th.col-contract_amount,
td.col-contract_amount {
  white-space: nowrap;
}

.result-main {
  min-width: 320px;
}

.source-provenance {
  display: grid;
  gap: 2px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.weak-evidence {
  color: var(--warn);
  font-weight: 700;
}

details {
  margin-top: 8px;
}

summary {
  color: var(--primary);
  cursor: pointer;
}

.details-grid {
  display: grid;
  gap: 10px;
  margin-top: 8px;
  padding: 10px;
  background: #fbfcfe;
  border: 1px solid var(--line);
}

.details-grid .muted {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
}

.column-picker {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  background: #fbfcfe;
}

.suggestions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 10px;
}

.suggestion {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 10px;
  color: var(--text);
}

.suggestion small {
  color: var(--muted);
}

.sub {
  display: block;
  margin-top: 4px;
  font-size: 12px;
}

.muted-row {
  opacity: 0.55;
}

.inline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.inline input[name="expert_comment"] {
  min-width: 220px;
  flex: 1;
}

.check {
  display: inline-flex;
  grid-auto-flow: column;
  gap: 6px;
  align-items: center;
  color: var(--text);
}

.check input {
  width: 16px;
  min-height: 16px;
}

.check-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  min-height: 36px;
}

.check-group > span {
  color: var(--muted);
  font-size: 12px;
  margin-right: 2px;
}

.links {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.workflow,
.pager {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  align-items: center;
}

.workflow form,
.pager form {
  margin: 0;
}

.login-panel {
  max-width: 420px;
  margin: 40px auto;
}

@media (max-width: 860px) {
  .page {
    padding: 12px;
  }

  .topbar {
    height: auto;
    display: grid;
    gap: 8px;
    padding: 10px 12px;
  }

  nav {
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .grid-2,
  .dashboard-grid,
  .dashboard-compact-grid,
  .request-create-grid,
  .request-workspace,
  .manual-good,
  .law-blocks,
  .okpd2-class,
  .okpd2-sources,
  .compact-form,
  .request-form,
  .filters {
    grid-template-columns: 1fr;
  }

  .dashboard-card-wide,
  .wide {
    grid-column: auto;
  }

  .section-head {
    display: grid;
  }

  .request-right {
    position: static;
  }

  table {
    display: block;
    overflow-x: auto;
  }
}
