:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --card: #ffffff;
  --line: #d9e0ea;
  --text: #1f2937;
  --muted: #64748b;
  --accent: #7c3aed;
  --accent-soft: #ede9fe;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}
.page {
  max-width: 1600px;
  margin: 0 auto;
  padding: 28px 20px 40px;
}
.hero,
.filters,
.stats,
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 18px 35px rgba(15, 23, 42, 0.08);
}
.hero {
  padding: 24px 28px;
  margin-bottom: 20px;
}
.hero h1 {
  margin: 0 0 8px;
  font-size: 30px;
  line-height: 1.1;
}
.hero p {
  margin: 0;
  color: var(--muted);
  max-width: 980px;
  line-height: 1.55;
}
.filters {
  padding: 18px;
  margin-bottom: 20px;
}
.filters form {
  display: grid;
  grid-template-columns: 320px 280px minmax(0, 1fr);
  gap: 16px;
  align-items: end;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.field input,
.field select {
  width: 100%;
  min-height: 46px;
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 0 13px;
  font-size: 15px;
  color: var(--text);
  background: #fff;
}
.actions {
  display: flex;
  gap: 12px;
  align-items: center;
  grid-column: 1 / -1;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid transparent;
  text-decoration: none;
  font-weight: 700;
  cursor: pointer;
  font-size: 15px;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: transparent; border-color: var(--line); color: var(--text); }
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  padding: 16px;
  margin-bottom: 20px;
}
/* Плитки сводки — кнопки-фильтры: клик выставляет соответствующий срез таблицы. */
.stat {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  background: #fff;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.stat:hover { border-color: var(--accent); background: #fbfaff; }
.stat:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.stat.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.stat-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 8px;
}
.stat-value {
  font-size: 30px;
  font-weight: 800;
  line-height: 1.1;
}
.stat-sub {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}
.stat.is-bad .stat-value { color: var(--bad); }
.stat.is-warn .stat-value { color: var(--warn); }
.stat.is-ok .stat-value { color: var(--ok); }
.panel {
  padding: 0;
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 {
  margin: 0;
  font-size: 18px;
}
.meta {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}
.error {
  display: none;
  margin-bottom: 16px;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--bad-soft);
  color: var(--bad);
  border: 1px solid rgba(185, 28, 28, 0.18);
}
.table-wrap { overflow: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1180px;
}
th,
td {
  padding: 13px 15px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
th {
  background: #f8fafc;
  color: #57708f;
  font-size: 12px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
th.sortable { padding: 0; }
th.sortable.is-sorted { color: var(--text); }
.sort-trigger {
  width: 100%;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 13px 15px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  text-align: left;
  cursor: pointer;
}
.sort-trigger:hover,
.sort-trigger:focus-visible { color: var(--text); }
.sort-indicator {
  font-size: 11px;
  opacity: 0.9;
}
.gap-days { font-weight: 700; }
.gap-days.is-negative { color: var(--warn); }
td a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 700;
}
td a:hover { text-decoration: underline; }
.deal-id {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}
.nowrap { white-space: nowrap; }
.muted {
  color: var(--muted);
  font-size: 12px;
}
/* Стадия: цвета приходят с сервера (палитра по порядку стадий в воронке),
   здесь только форма бейджа и нейтральный дефолт, если цвет не пришёл. */
.stage-badge {
  display: inline-block;
  max-width: 260px;
  padding: 5px 10px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #f1f5f9;
  color: #475569;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
}
.facades-badge {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  text-decoration: none;
}
td a.facades-badge { font-weight: 800; }
.facades-ordered { background: var(--ok-soft); border-color: #bbf7d0; color: var(--ok); }
.facades-pending { background: var(--warn-soft); border-color: #fde68a; color: var(--warn); }
.facades-none { background: #f1f5f9; border-color: #e2e8f0; color: #64748b; }
.facades-risk-warn { background: var(--warn-soft); border-color: #fde68a; color: var(--warn); }
.facades-risk-critical { background: var(--bad-soft); border-color: #fecaca; color: var(--bad); }
.deal-id.is-risk-warn { color: var(--warn); font-weight: 700; }
.deal-id.is-risk-critical { color: var(--bad); font-weight: 700; }
td a.facades-ordered:hover,
td a.facades-pending:hover { text-decoration: underline; }
.badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-critical { background: #ffe4e6; color: #be123c; }
.badge-overdue { background: var(--bad-soft); color: var(--bad); }
.badge-none { background: #f1f5f9; color: #475569; }
tr.is-overdue td { background: rgba(185, 28, 28, 0.045); }
.empty-row td,
.loading-row td {
  color: var(--muted);
  padding-top: 20px;
  padding-bottom: 20px;
}
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters form { grid-template-columns: minmax(0, 1fr); }
}
