:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --text: #17202a;
  --muted: #5f6f7d;
  --line: #d9e1e8;
  --accent: #1d5f9f;
  --accent-strong: #164a7c;
  --success: #1f7a4d;
  --warning: #a86500;
  --danger: #b42318;
  --shadow: 0 10px 28px rgba(23, 32, 42, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

a {
  color: inherit;
  text-decoration: none;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #18222d;
  color: #f7fafc;
  padding: 22px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.brand-logo {
  display: block;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: #b6c3cf;
  font-size: 12px;
}

.nav-list {
  display: grid;
  gap: 4px;
}

.nav-list a {
  border-radius: var(--radius);
  color: #d8e1e9;
  padding: 11px 12px;
}

.nav-list a:hover,
.nav-list a.active {
  background: #253241;
  color: #ffffff;
}

.sidebar-user {
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  display: grid;
  gap: 5px;
  margin-top: 24px;
  padding-top: 16px;
}

.sidebar-user strong,
.sidebar-user small {
  display: block;
}

.sidebar-user small {
  color: #b6c3cf;
  font-size: 12px;
}

.main {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
  padding: 24px;
}

.app-footer {
  align-items: center;
  border-top: 1px solid var(--line);
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  font-size: 12px;
  font-weight: 700;
  gap: 8px 18px;
  justify-content: space-between;
  margin-top: auto;
  padding-top: 16px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.section-label {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.period-pill {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  margin: 8px 0 0;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 28px;
  line-height: 1.15;
}

h2 {
  margin-bottom: 6px;
  font-size: 18px;
}

h3 {
  margin: 22px 0 10px;
  font-size: 14px;
  text-transform: uppercase;
  color: var(--muted);
}

.topbar-actions,
.detail-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.button {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  gap: 8px;
  min-height: 38px;
  padding: 8px 13px;
  white-space: nowrap;
}

.button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.button.primary:hover {
  background: var(--accent-strong);
}

.button.secondary {
  background: var(--surface);
  color: var(--text);
}

.button.secondary:hover {
  border-color: #9eb3c7;
}

.button.danger {
  background: #fff5f5;
  border-color: #f2b8b5;
  color: var(--danger);
}

.button.danger:hover {
  background: #fdecec;
  border-color: var(--danger);
}

.button.compact {
  font-size: 12px;
  min-height: 30px;
  padding: 5px 9px;
}

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

.metric,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.metric {
  padding: 16px;
}

.metric span,
.metric small {
  color: var(--muted);
  display: block;
}

.metric strong {
  display: block;
  font-size: 28px;
  line-height: 1.1;
  margin: 8px 0 4px;
}

.metric.warning strong {
  color: var(--warning);
}

.content-grid {
  align-items: start;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  margin-bottom: 16px;
}

.split-layout {
  align-items: start;
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}

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

.panel.wide {
  min-width: 0;
}

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

.panel-head p,
.detail-header p {
  color: var(--muted);
  margin-bottom: 0;
}

.period-editor-stack {
  display: grid;
  gap: 16px;
}

.collapsible-panel summary {
  align-items: center;
  cursor: pointer;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  list-style: none;
}

.collapsible-panel summary::-webkit-details-marker {
  display: none;
}

.collapsible-panel summary span {
  font-size: 18px;
  font-weight: 800;
}

.collapsible-panel summary small {
  color: var(--muted);
  font-weight: 700;
}

.collapsible-panel summary::after {
  background: var(--surface-2);
  border-radius: 999px;
  color: var(--accent-strong);
  content: "Отвори";
  font-size: 12px;
  font-weight: 800;
  padding: 5px 8px;
}

.collapsible-panel[open] summary {
  margin-bottom: 14px;
}

.collapsible-panel[open] summary::after {
  content: "Скрий";
}

.table-wrap {
  overflow-x: auto;
}

.table-pagination {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  margin: 10px 0;
}

.table-pagination label {
  align-items: center;
  color: var(--muted);
  display: inline-flex;
  flex-direction: row;
  font-size: 13px;
  font-weight: 700;
  gap: 8px;
}

.table-pagination select {
  min-width: 88px;
}

.table-pagination-info {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  min-width: 96px;
  text-align: right;
}

.batch-toolbar {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
  padding: 10px;
}

.filter-panel {
  margin-bottom: 16px;
}

.filter-bar {
  align-items: end;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.filter-bar label {
  min-width: min(360px, 100%);
}

.accounting-action-row {
  align-items: end;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) minmax(140px, max-content);
  margin-top: 12px;
}

.accounting-action-row .button {
  min-height: 38px;
  width: 100%;
}

.action-control,
.row-action-control {
  align-items: center;
  display: inline-flex;
  gap: 8px;
}

.row-action-control {
  justify-content: flex-end;
}

.action-control select,
.row-action-control select {
  min-height: 30px;
  min-width: 170px;
  padding: 5px 8px;
  width: auto;
}

.table-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

table {
  border-collapse: separate;
  border-spacing: 0;
  min-width: 760px;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 11px 10px;
  text-align: left;
  vertical-align: top;
}

.select-col {
  text-align: center;
  width: 42px;
}

.actions-col {
  background: var(--surface);
  box-shadow: -8px 0 14px rgba(23, 32, 42, 0.04);
  min-width: 250px;
  position: sticky;
  right: 0;
  z-index: 1;
}

th.actions-col {
  background: #f9fbfc;
  z-index: 2;
}

input[type="checkbox"] {
  block-size: 16px;
  inline-size: 16px;
  margin: 0;
  min-height: auto;
  padding: 0;
  width: auto;
}

th {
  background: #f9fbfc;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

tr:hover td {
  background: #fbfdff;
}

tr.selected-row td {
  background: #f4f9ff;
}

tr:hover td.actions-col {
  background: #fbfdff;
}

tr.selected-row td.actions-col {
  background: #f4f9ff;
}

.empty,
.muted {
  color: var(--muted);
}

.notice {
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 700;
  padding: 10px;
}

.notice.warning {
  background: #fff6e5;
  color: var(--warning);
}

.error-text {
  color: var(--danger);
  display: block;
  font-size: 12px;
  font-weight: 700;
  margin-top: 4px;
}

.score,
.status {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  padding: 6px 8px;
}

.score-good {
  background: #e8f6ee;
  color: var(--success);
}

.score-mid {
  background: #fff6e5;
  color: var(--warning);
}

.score-bad {
  background: #fdecec;
  color: var(--danger);
}

.status {
  background: #eef5fc;
  color: var(--accent-strong);
}

.warning-list,
.match-list,
.stop-list {
  display: grid;
  gap: 10px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.warning-list li,
.match-list li,
.stop-list li {
  border-left: 3px solid var(--line);
  padding-left: 10px;
}

.warning-list a,
.table-link {
  color: var(--accent);
  font-weight: 800;
}

.warning-list span,
.match-list span,
.stop-list span {
  color: var(--muted);
  display: block;
}

.form-grid {
  display: grid;
  gap: 11px;
}

label {
  color: var(--muted);
  display: grid;
  font-size: 13px;
  font-weight: 700;
  gap: 5px;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(29, 95, 159, 0.14);
}

textarea {
  min-height: 90px;
  resize: vertical;
}

.form-panel {
  max-width: 720px;
}

.wide-form {
  max-width: 1000px;
}

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

.full-row {
  grid-column: 1 / -1;
}

.form-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
}

.checkbox-row {
  align-items: center;
  display: flex;
  flex-direction: row;
  gap: 10px;
}

.checkbox-row input {
  min-height: auto;
  width: auto;
}

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

.link-button.inverse {
  color: #d8e1e9;
  text-align: left;
}

.login-page {
  background: #edf2f7;
}

.login-shell {
  align-items: center;
  display: grid;
  gap: 16px;
  grid-template-rows: 1fr auto;
  justify-items: center;
  min-height: 100vh;
  padding: 24px;
}

.login-footer {
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  font-size: 12px;
  font-weight: 700;
  gap: 8px 16px;
  justify-content: center;
  text-align: center;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
  max-width: 420px;
  padding: 26px;
  width: 100%;
}

.login-card h1 {
  font-size: 24px;
}

.login-brand {
  color: var(--text);
  margin-bottom: 4px;
}

.login-brand small {
  color: var(--muted);
}

.subject-check-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.check-card {
  align-items: flex-start;
  background: #f9fbfc;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: row;
  gap: 10px;
  padding: 12px;
}

.check-card input {
  margin-top: 3px;
  min-height: auto;
  width: auto;
}

.check-card strong,
.check-card small {
  display: block;
}

.check-card small {
  color: var(--muted);
  font-weight: 600;
}

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

.detail-grid.single {
  grid-template-columns: 1fr;
}

.json-box {
  background: #111827;
  border-radius: var(--radius);
  color: #f9fafb;
  font-size: 12px;
  max-height: 360px;
  overflow: auto;
  padding: 12px;
  white-space: pre-wrap;
}

.detail-grid div {
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 12px;
}

.detail-grid dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.detail-grid dd {
  margin: 5px 0 0;
  font-weight: 700;
}

.big-score {
  border-radius: var(--radius);
  font-size: 28px;
  font-weight: 800;
  margin: 10px 0 18px;
  padding: 14px;
  text-align: center;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

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

  .topbar,
  .panel-head,
  .detail-header {
    align-items: stretch;
    flex-direction: column;
  }

  .kpi-grid,
  .content-grid,
  .split-layout,
  .detail-grid,
  .two-cols {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .main {
    padding: 16px;
  }

  .nav-list {
    grid-template-columns: 1fr 1fr;
  }

  .topbar-actions,
  .detail-actions {
    justify-content: stretch;
  }

  .button {
    justify-content: center;
    width: 100%;
  }
}
