/* Экраны CRM. Краски только из tokens.css. */

* { box-sizing: border-box; }

html { background: var(--color-bg); }

body {
  margin: 0;
  font-family: var(--font-sans);
  line-height: var(--line-height);
  background: var(--color-bg);
  color: var(--color-text);
  overflow-x: hidden;
}

a { color: var(--color-link); }

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--color-link);
  outline-offset: 2px;
}

.top {
  display: flex;
  gap: var(--space-4);
  align-items: center;
  padding: 12px var(--space-5);
  background: var(--color-header-bg);
  color: var(--color-header-text);
  border-bottom: 1px solid var(--color-header-border);
  box-shadow: var(--shadow-header);
}

.top a,
.top button.linkish {
  color: var(--color-header-text);
  text-decoration: none;
  font-weight: var(--weight-medium);
}

.top nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  min-width: 0;
}

.top nav a[aria-current="page"] {
  color: var(--color-link);
  font-weight: var(--weight-bold);
}

.brand {
  display: inline-flex;
  align-items: center;
  font-weight: var(--weight-bold);
  text-decoration: none;
  min-height: 40px;
  flex: 0 0 auto;
}

.brand-logo,
.brand-mark {
  height: 40px;
  width: auto;
  display: block;
  object-fit: contain;
}

.brand-mark { display: none; }
.brand-logo-dark { display: none; }

html[data-theme="dark"] .brand-logo-light { display: none; }
html[data-theme="dark"] .brand-logo-dark { display: block; }

.userbox {
  margin-left: auto;
  display: flex;
  gap: var(--space-3);
  align-items: center;
}

.userbox span {
  color: var(--color-header-muted);
  font-size: var(--text-sm);
}

.theme-toggle {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--radius-pill);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.theme-toggle svg { width: 20px; height: 20px; display: none; }
html[data-theme-choice="light"] .theme-toggle .icon-sun,
html[data-theme-choice="dark"] .theme-toggle .icon-moon,
html[data-theme-choice="system"] .theme-toggle .icon-auto { display: block; }

button,
.button {
  background: var(--color-accent);
  color: var(--color-accent-contrast);
  border: 0;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  min-height: 40px;
  text-decoration: none;
  cursor: pointer;
  font: inherit;
  font-weight: var(--weight-semibold);
}

button:hover,
.button:hover { background: var(--color-accent-hover); }

.button.secondary,
button.secondary {
  background: var(--color-surface);
  color: var(--color-link);
  border: 1px solid var(--color-link);
}

.button.secondary:hover,
button.secondary:hover {
  background: var(--color-accent-soft);
}

button.linkish {
  background: transparent;
  color: inherit;
  min-height: 0;
  padding: 0;
  font-weight: var(--weight-medium);
  text-decoration: underline;
}

button.linkish:hover { background: transparent; }

main {
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-5) var(--space-6);
}

.page-head,
.actions {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  align-items: center;
  flex-wrap: wrap;
}

h1, h2, h3, .kpi-value { font-family: var(--font-heading); }

h1 {
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  letter-spacing: -0.02em;
  margin: 0 0 var(--space-3);
}

h2 {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  letter-spacing: -0.015em;
  margin: var(--space-2) 0;
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  color: var(--color-text);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}

.narrow { max-width: 420px; margin: 48px auto; }

.banner {
  margin: 0;
  padding: 10px var(--space-5);
  background: var(--color-warn-soft);
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border);
}

.ex-alert {
  background: var(--color-warn-soft);
  border: 2px solid var(--color-warn);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}

.ex-alert h2 {
  margin-top: 0;
}

.errors,
ul.errorlist {
  background: var(--color-bad-soft);
  color: var(--color-bad);
  border: 1px solid var(--color-bad);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  margin: 0 0 var(--space-3);
  list-style: none;
}

.messages {
  list-style: none;
  padding: 8px var(--space-5);
  margin: 0;
  background: var(--color-good-soft);
  color: var(--color-text);
}

.filters,
.grid,
.share-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3) var(--space-4);
  align-items: end;
}

.filters {
  margin-bottom: var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: var(--space-3) var(--space-4);
}

.share-row { grid-template-columns: 1.4fr 1fr 1fr auto; margin-bottom: var(--space-2); }

label {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
}

.wide { grid-column: 1 / -1; }

.input,
select,
textarea,
input[type="month"],
input[type="date"],
input[type="text"],
input[type="url"],
input[type="password"],
input[type="number"],
input[type="email"] {
  width: 100%;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  min-height: 42px;
  font: inherit;
  color: var(--color-text);
  background: var(--color-surface);
}

textarea { min-height: 96px; }

.grid-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
  color: var(--color-text);
}

.table-wrap { max-width: 100%; }

.grid-table th,
.grid-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}

.grid-table th {
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}

.grid-table td[colspan] {
  text-align: center;
  color: var(--color-text-muted);
  padding: var(--space-6) var(--space-4);
}

.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; }
.facts div { display: flex; flex-direction: column; }
.facts dt { color: var(--color-text-muted); font-size: var(--text-sm); }
.facts dd { margin: 0; }

.status {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--color-surface-2);
  color: var(--color-text);
  font-size: var(--text-sm);
}

.status-deposit { background: var(--status-deposit); }
.status-deal { background: var(--status-deal); }
.status-settled { background: var(--status-settled); }
.status-failed { background: var(--status-failed); }
.status-failed_retained { background: var(--status-failed-retained); }

.pager { display: flex; gap: var(--space-3); align-items: center; }

.check { flex-direction: row; align-items: center; gap: var(--space-2); color: var(--color-text); }
.check input { width: auto; min-height: 0; }

.stack h2 { margin-top: 18px; }

.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

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

.muted { font-size: 0.92rem; }

.neg { color: var(--color-bad); }

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

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
  gap: var(--space-3);
}

.account-card { margin-bottom: 0; background: var(--color-surface-2); box-shadow: none; }

.account-card dl {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  margin: 0;
}

.account-card dt { color: var(--color-text-muted); }
.account-card dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.cancelled { color: var(--color-text-muted); text-decoration: line-through; }

.help { margin-top: 0; }

.example {
  background: var(--color-surface-2);
  border-left: 4px solid var(--color-brand);
}

.kpi-grid.kic-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.kic-split {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(260px, 0.9fr);
  gap: var(--space-4);
  align-items: start;
}

.chart-box { height: 320px; }

.status-active,
.status-in_work,
.status-approved,
.status-signed,
.status-paid,
.status-contract { background: var(--color-good-soft); }

.status-lead,
.status-new,
.status-draft { background: var(--color-accent-soft); }

.status-refused { background: var(--color-bad-soft); }

.warn { background: var(--color-warn-soft); color: var(--color-text); }
.bad { background: var(--color-bad-soft); color: var(--color-text); }

.tone-good { box-shadow: inset 3px 0 0 var(--color-good); }
.tone-mid { box-shadow: inset 3px 0 0 var(--color-warn); }
.tone-low { box-shadow: inset 3px 0 0 var(--color-bad); }
.tone-none { box-shadow: inset 3px 0 0 var(--color-border); }
.below-norm { box-shadow: inset 3px 0 0 var(--color-bad); }

.empty { text-align: center; padding: var(--space-6) var(--space-4); }
.empty-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto var(--space-3);
  border-radius: var(--radius-pill);
  background: var(--color-accent-soft);
  color: var(--color-link);
  display: flex;
  align-items: center;
  justify-content: center;
}
.empty-icon svg { width: 24px; height: 24px; }
.empty-title { margin: 0 0 var(--space-1); font-weight: var(--weight-semibold); color: var(--color-text); }
.empty p { margin: 0; }

@media (max-width: 800px) {
  .grid-table {
    display: block;
    overflow-x: auto;
    max-width: 100%;
  }

  .filters,
  .grid,
  .facts,
  .share-row,
  .summary-grid,
  .kic-split,
  .kpi-grid.kic-kpis { grid-template-columns: 1fr; }
  body[data-brand="kic"] .brand-logo { display: none; }
  body[data-brand="kic"] .brand-mark { display: block; }
  .top { flex-wrap: wrap; padding: 12px var(--space-3); }
  .userbox { margin-left: auto; }
  main { padding: var(--space-4) var(--space-3) var(--space-5); }
  h1 { font-size: 1.45rem; }
}

.nav-count {
  display: inline-block;
  min-width: 1.4em;
  margin-left: 0.25em;
  padding: 0 0.4em;
  border-radius: 999px;
  background: var(--color-bad);
  color: #fff;
  font-size: 0.75rem;
  line-height: 1.45;
  text-align: center;
}

.reminder-block + .reminder-block { margin-top: var(--space-4); }

.reminder-row td { vertical-align: top; }

.reminder-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: end;
}

.reminder-actions form { display: flex; gap: var(--space-2); align-items: end; margin: 0; }

.reminder-actions input[type="date"] { min-height: 2.2rem; }
