:root {
  --font-ui: 'Golos Text', system-ui, sans-serif;
  --font-size-base: 14px;
  --ink: #243047;
  --ink-strong: #213655;
  --muted: #8394ac;
  --text-secondary: #526784;
  --primary: #245bea;
  --button-blue: #2d5fe3;
  --hover-tint: #edf3ff;
  --focus-ring: #a8c0ff;
  --page-bg: #f6f8fc;
  --surface: #fff;
  --sidebar-border: #e4eaf3;
  --border-card: #e2e8f2;
  --border-button: #e0e6f0;
  --table-head-bg: #f7f9fd;
  --table-head-text: #91a0b8;
  --accent: #d4f36a;
  --success: #1f8a5b;
  --success-bg: #e9f7ef;
  --warning: #b7791f;
  --warning-bg: #fff6e5;
  --danger: #c2410c;
  --danger-bg: #fdeee8;
  --radius-card: 16px;
  --radius-nav: 12px;
  --radius-button: 8px;
  --radius-chip: 10px;
  --sidebar-width: 264px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  overflow-x: hidden;
  background: var(--page-bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--font-size-base);
  font-weight: 400;
  line-height: 1.5;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover { color: #1b4bc9; }

.shell { min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  width: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  padding: 22px 16px 18px;
  background: var(--surface);
  border-right: 1px solid var(--sidebar-border);
}

.sidebar-top { padding: 0 6px; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink-strong);
}

.brand:hover { color: var(--ink-strong); }

.brand-mark {
  display: block;
  width: auto;
  height: 40px;
  flex: 0 0 auto;
}

.brand-text {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -1.2px;
  line-height: 1;
  white-space: nowrap;
}

.brand-accent { color: var(--primary); }

.brand-tagline {
  margin: 7px 0 0 2px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.35;
}

.menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  min-height: 0;
  padding: 0;
  border: 1px solid var(--border-button);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: none;
}

.sidebar-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  margin-top: 26px;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-label {
  margin: 22px 12px 7px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 1.6px;
  line-height: 1;
  text-transform: uppercase;
}

.nav-label:first-child { margin-top: 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-nav);
  color: var(--text-secondary);
  font-size: 15px;
  font-weight: 550;
  line-height: 1.25;
}

.nav-item svg {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
}

.nav-item:hover {
  background: var(--hover-tint);
  color: var(--ink-strong);
}

.nav-item.is-active,
.nav-item.is-active:hover {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 5px 14px rgba(36, 91, 234, .11);
}

.sidebar-user {
  margin-top: auto;
  padding-top: 18px;
}

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--border-card);
  border-radius: 12px;
  background: #f7f9fd;
}

.avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 50%;
  background: var(--hover-tint);
  color: var(--primary);
  font-size: 14px;
  font-weight: 700;
}

.user-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.user-name {
  overflow: hidden;
  color: var(--ink-strong);
  font-size: 12.5px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-role {
  color: var(--muted);
  font-size: 10.5px;
}

.user-links {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 10px 0;
}

.user-links a {
  color: var(--text-secondary);
  font-size: 11px;
}

.user-links a:hover { color: var(--primary); }

.logout-button {
  min-height: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
  box-shadow: none;
}

.logout-button:hover {
  background: none;
  color: var(--danger);
}

.main-column {
  min-width: 0;
  margin-left: var(--sidebar-width);
}

.page {
  width: 100%;
  max-width: 1280px;
  min-width: 0;
  margin: 0 auto;
  padding: 28px 32px 56px;
}

h1, h2, h3 {
  color: var(--ink-strong);
  font-weight: 600;
}

h1 {
  margin: 0 0 18px;
  font-size: 22px;
  letter-spacing: -.45px;
  line-height: 1.3;
}

h2 {
  margin: 26px 0 12px;
  font-size: 16px;
  letter-spacing: -.2px;
}

h3 {
  margin: 18px 0 8px;
  font-size: 14px;
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  margin: 0 0 20px;
}

.page-head h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -.45px;
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.count-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--hover-tint);
  color: var(--primary);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0;
  vertical-align: middle;
}

.panel,
.card,
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-card);
}

.panel {
  margin-bottom: 18px;
  padding: 18px;
}

.panel.narrow { max-width: 580px; }

.table-wrap {
  max-width: 100%;
  margin-bottom: 18px;
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
}

th,
td {
  padding: 10px 16px;
  border-bottom: 1px solid #eef2f8;
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--table-head-bg);
  color: var(--table-head-text);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .2px;
  text-transform: uppercase;
  white-space: nowrap;
}

td {
  font-size: 13px;
  line-height: 1.45;
}

tbody tr { height: 44px; }
tbody tr:hover { background: #f7f9fd; }
tbody tr:last-child td { border-bottom: 0; }

label {
  display: grid;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 500;
}

input,
select,
textarea,
button {
  font-family: var(--font-ui);
  font-size: var(--font-size-base);
}

input:where(:not([type="checkbox"]):not([type="radio"]):not([type="file"])),
select,
textarea {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border-button);
  border-radius: 10px;
  background: #f7f9fd;
  color: var(--ink);
  font-size: 13px;
}

textarea {
  height: auto;
  min-height: 90px;
  padding: 10px 12px;
}

input::placeholder { color: #aeb9ca; }

input:where(:not([type="checkbox"]):not([type="radio"]):not([type="file"])):focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

input[type="checkbox"],
input[type="radio"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

input[type="file"] {
  width: 100%;
  min-height: 40px;
  font-size: 12.5px;
  color: var(--text-secondary);
}

input[type="file"]::file-selector-button {
  margin-right: 10px;
  padding: 8px 12px;
  border: 1px solid var(--border-button);
  border-radius: var(--radius-button);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 550;
  cursor: pointer;
}

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-button);
  background: var(--button-blue);
  color: #fff;
  font-size: 13px;
  font-weight: 550;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(45, 95, 227, .16);
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}

button:hover,
.button:hover {
  background: #2553cf;
  color: #fff;
}

button.secondary,
.button.secondary {
  border-color: var(--border-button);
  background: var(--surface);
  color: var(--ink);
  box-shadow: none;
}

button.secondary:hover,
.button.secondary:hover {
  background: var(--hover-tint);
  color: var(--ink-strong);
}

button.danger {
  border-color: #f0c9ba;
  background: var(--surface);
  color: var(--danger);
  box-shadow: none;
}

button.danger:hover {
  background: var(--danger-bg);
  color: var(--danger);
}

button:focus-visible,
.button:focus-visible,
a:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.inline-form { display: inline; }

.notice {
  margin: 0 0 16px;
  padding: 12px 14px;
  border: 1px solid var(--border-card);
  border-radius: 12px;
  background: var(--surface);
  font-size: 13px;
}

.notice.error {
  border-color: #f3cdbf;
  background: var(--danger-bg);
  color: var(--danger);
}

.notice.ok {
  border-color: #cbe9d8;
  background: var(--success-bg);
  color: var(--success);
}

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

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
}

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

form.stack {
  display: grid;
  gap: 14px;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
}

.filters label {
  min-width: 190px;
  max-width: 320px;
  flex: 1 1 190px;
}

.filters label.check {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: 40px;
  flex: 0 1 auto;
  font-weight: 400;
}

.filter-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  min-height: 40px;
}

dl.fields {
  display: grid;
  grid-template-columns: minmax(180px, 240px) 1fr;
  gap: 10px 20px;
  margin: 0;
}

dl.fields dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

dl.fields dd {
  margin: 0;
  font-size: 13.5px;
}

ul.details {
  margin: 4px 0 0;
  padding-left: 18px;
}

.details li + li { margin-top: 3px; }

.badge,
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  background: #f2f5fa;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
}

.badge.ok,
.pill-success {
  background: var(--success-bg);
  color: var(--success);
}

.badge.accent,
.pill-accent {
  background: var(--accent);
  color: var(--ink);
}

.badge.warn,
.pill-warning {
  background: var(--warning-bg);
  color: var(--warning);
  text-transform: lowercase;
}

.pill-neutral {
  background: #f2f5fa;
  color: var(--text-secondary);
}

.counts {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}

.count {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 118px;
  padding: 10px 14px;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-chip);
  background: var(--surface);
}

.count-value {
  color: var(--ink-strong);
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -.3px;
  line-height: 1.05;
}

.count-label {
  color: var(--muted);
  font-size: 11px;
}

.count--new {
  border-color: #cdeeda;
  background: var(--success-bg);
}

.count--new .count-value { color: var(--success); }

.count--changed {
  border-color: #dbe6ff;
  background: var(--hover-tint);
}

.count--changed .count-value { color: var(--primary); }

.count--missing {
  border-color: #f6e3bb;
  background: var(--warning-bg);
}

.count--missing .count-value { color: var(--warning); }

.count--errors {
  border-color: #f4d3c6;
  background: var(--danger-bg);
}

.count--errors .count-value { color: var(--danger); }

.count--unchanged,
.count--returned {
  background: #f7f9fd;
}

.kept-details {
  margin: 0 0 18px;
  padding: 14px 16px;
  border: 1px solid var(--border-card);
  border-radius: 12px;
  background: var(--surface);
}

.kept-details summary {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

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

.kept-details summary::before {
  content: "+";
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--hover-tint);
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
}

.kept-details[open] summary::before { content: "−"; }

.kept-list {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.kept-list li {
  padding: 10px 12px;
  border-radius: 10px;
  background: #f7f9fd;
  font-size: 12.5px;
}

.kept-field {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}

.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 18px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12.5px;
}

.pagination a {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border-button);
  border-radius: var(--radius-button);
  background: var(--surface);
  font-weight: 550;
}

.pagination a:hover { background: var(--hover-tint); }

.apply-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
  margin: 18px 0 8px;
}

.grid-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  align-items: end;
}

.grid-form .form-actions { grid-column: 1 / -1; }

.mapping-form {
  display: grid;
  gap: 14px;
  max-width: 620px;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.compact-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 190px;
}

.compact-form select,
.compact-form input {
  width: auto;
  min-width: 130px;
}

.actions {
  display: grid;
  gap: 8px;
}

.counts-cell {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  min-width: 260px;
  color: var(--muted);
  font-size: 12px;
}

.required { color: var(--danger); }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 16px;
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 500;
}

.back-link:hover { color: var(--primary); }

.empty-state {
  padding: 54px 24px;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-card);
  background: var(--surface);
  text-align: center;
}

.empty-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  border-radius: 16px;
  background: var(--hover-tint);
  color: var(--primary);
}

.empty-icon svg {
  width: 26px;
  height: 26px;
}

.empty-state h1 {
  margin: 0 0 8px;
  font-size: 20px;
  letter-spacing: -.3px;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.login-body {
  background-color: var(--page-bg);
  background-image: radial-gradient(#dfe6f2 1px, transparent 1px);
  background-size: 18px 18px;
}

.auth-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  max-width: none;
  padding: 32px 16px;
}

.auth-page > .notice {
  width: 100%;
  max-width: 420px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  padding: 30px 30px 24px;
  border: 1px solid var(--border-card);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: 0 24px 60px rgba(33, 54, 85, .12);
}

.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 24px;
}

.auth-brand .brand-mark { height: 48px; }
.auth-brand .brand-text { font-size: 28px; }

.auth-kicker {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.4px;
  text-transform: uppercase;
}

.auth-kicker::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

.auth-card h1 {
  margin: 0 0 20px;
  font-size: 24px;
  letter-spacing: -.5px;
}

.auth-form {
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 6px;
}

.input-wrap { position: relative; }

.input-icon {
  position: absolute;
  top: 50%;
  left: 12px;
  width: 18px;
  height: 18px;
  color: var(--muted);
  pointer-events: none;
  transform: translateY(-50%);
}

.input-wrap input { padding-left: 38px; }

.auth-submit {
  width: 100%;
  min-height: 42px;
  margin-top: 2px;
}

.auth-footer {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 11.5px;
  text-align: center;
}

@media (max-width: 860px) {
  .sidebar {
    position: sticky;
    inset: 0 0 auto;
    width: 100%;
    padding: 10px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--sidebar-border);
  }

  .sidebar-top {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 0;
  }

  .sidebar-top .brand { flex: 0 1 auto; min-width: 0; }
  .brand-mark { height: 32px; }

  .brand-text {
    font-size: 22px;
    letter-spacing: -1px;
  }

  .brand-tagline { display: none; }

  .menu-toggle {
    display: inline-flex;
    margin-left: auto;
    flex: 0 0 auto;
  }

  .sidebar-panel {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    left: 0;
    max-height: calc(100vh - 62px);
    margin-top: 0;
    padding: 10px 16px 16px;
    overflow-y: auto;
    border-bottom: 1px solid var(--sidebar-border);
    background: var(--surface);
    box-shadow: 0 18px 30px rgba(33, 54, 85, .12);
  }

  .sidebar-panel.is-open { display: flex; }

  .main-column { margin-left: 0; }
  .page { padding: 20px 16px 44px; }

  .page-actions {
    width: 100%;
    margin-left: 0;
  }

  .filters label {
    min-width: 100%;
    max-width: none;
    flex-basis: 100%;
  }

  .filters label.check { min-width: 100%; }
  .filter-actions { width: 100%; }
  dl.fields { grid-template-columns: 1fr; gap: 2px; }
  dl.fields dt { margin-top: 8px; }
  .count { flex: 1 1 42%; }
  .grid-form { grid-template-columns: 1fr; }
  .auth-card { padding: 24px 22px 20px; }
}

@media (max-width: 420px) {
  .page { padding: 18px 14px 40px; }
  .panel { padding: 16px; }
  .page-head h1 { font-size: 20px; }
  .compact-form select,
  .compact-form input { width: 100%; }
}
