:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --card: #ffffff;
  --line: #d9e0ea;
  --text: #1f2937;
  --muted: #64748b;
  --accent: #7c3aed;
  --accent-strong: #6d28d9;
  --accent-soft: #ede9fe;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --shadow: 0 18px 35px rgba(15, 23, 42, 0.08);
  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: var(--shadow);
}
.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: 920px;
  line-height: 1.55;
}
.filters {
  padding: 18px;
  margin-bottom: 20px;
}
.filters form {
  display: grid;
  grid-template-columns: 150px 220px 170px 170px auto auto auto;
  gap: 14px;
  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;
  background: #fff;
  color: var(--text);
  font-size: 15px;
}
.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-size: 15px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.btn-primary {
  color: #fff;
  background: var(--accent);
}
.btn-secondary {
  color: var(--text);
  background: transparent;
  border-color: var(--line);
}
.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  padding: 16px;
  margin-bottom: 20px;
}
.stat {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  background: #fff;
}
.stat-label {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
  font-weight: 700;
}
.stat-value {
  font-size: 32px;
  line-height: 1.1;
  font-weight: 800;
}
.stat-sub {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  font-weight: 700;
}
.error {
  display: none;
  margin-bottom: 16px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid rgba(185, 28, 28, 0.18);
  background: var(--bad-soft);
  color: var(--bad);
}
.panel {
  overflow: hidden;
  margin-bottom: 20px;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 {
  margin: 0;
  font-size: 18px;
}
.meta {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}
.table-wrap { overflow: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}
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;
}
td.num, th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
td.amount {
  font-weight: 700;
}
.row-name {
  font-weight: 700;
}
.leader-row { cursor: pointer; }
.leader-row:hover td { background: #f7f8fa; }
.disclosure {
  display: inline-block;
  width: 14px;
  color: var(--muted);
  font-size: 11px;
}
.leader-detail > td {
  padding: 0 15px 12px 29px;
  background: #fbfbfd;
}
.orders-list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
}
.order-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 9px 14px;
  border-bottom: 1px solid #eef2f7;
  font-size: 13px;
}
.order-row:last-child { border-bottom: none; }
.order-row a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.order-row a:hover { text-decoration: underline; }
.order-amount {
  color: var(--text);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.orders-empty {
  padding: 10px 14px;
  color: var(--muted);
  font-size: 13px;
}
.empty-row td,
.loading-row td {
  color: var(--muted);
  padding-top: 20px;
  padding-bottom: 20px;
}
.muted {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}
@media (max-width: 900px) {
  .filters form { grid-template-columns: 1fr 1fr; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .panel-head { flex-direction: column; align-items: flex-start; }
}
@media (max-width: 640px) {
  .page { padding: 18px 12px 28px; }
  .hero, .filters, .stats, .panel { border-radius: 14px; }
  .hero h1 { font-size: 24px; }
  .filters form { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr; }
}

/* блок входа в закрытый отчёт (заглушка «нужно войти») */
.access-actions {
  margin-top: 14px;
}

/* Клик по любому месту поля даты открывает календарь: нативный индикатор растянут
   на всё поле и прозрачен, видимая иконка — фоном (showPicker() в кросс-доменном
   iframe Bitrix заблокирован, а клик по индикатору — нет). */
.field input[type="date"] {
  position: relative;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23697180' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='18' rx='2'/%3E%3Cpath d='M16 2v4M8 2v4M3 10h18'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
  background-size: 15px;
}
.field input[type="date"]::-webkit-calendar-picker-indicator {
  position: absolute;
  inset: 0;
  width: auto;
  height: auto;
  margin: 0;
  padding: 0;
  opacity: 0;
  cursor: pointer;
}

/* ===== переключатель представлений (таблицы / календарь) ===== */
/* слева представление (таблицы/календарь), справа схема расчёта (old/new) */
.view-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.view-switch {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
}
.view-tab {
  min-height: 34px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.view-tab:hover { color: var(--text); background: #f7f8fa; }
.view-tab.is-active {
  background: var(--accent);
  color: #fff;
}

.basis-switch {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
}
.basis-caption {
  padding: 0 8px 0 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.basis-tab {
  min-height: 30px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.basis-tab:hover { color: var(--text); background: #f7f8fa; }
.basis-tab.is-active { background: var(--accent); color: #fff; }
.basis-note {
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

/* ===== календарь выручки =====
   Одна последовательная шкала (фиолетовый, светлый→тёмный): насыщенность = доля
   дня от максимума за период. Уровень 0 — день без продаж, нейтральный серый. */
/* календарь слева, заказы выбранного дня — справа, чтобы drill-down не двигал сетку */
.calendar-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  align-items: start;
}
.calendar-body { padding: 18px 20px 20px; }
.calendar-months {
  display: grid;
  gap: 20px;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
}
.calendar-months.is-single { grid-template-columns: minmax(0, 1fr); }
.calendar-months.is-compact { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.cal-month {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 12px 14px;
  background: #fff;
}
.cal-month-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.cal-month-head h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
}
.cal-month-sum {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.cal-weekdays,
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}
.cal-weekdays {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-align: center;
}
.cal-day {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  gap: 2px;
  min-height: 34px;
  padding: 4px 5px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
}
.calendar-months.is-single .cal-day,
.calendar-months:not(.is-compact) .cal-day { min-height: 58px; }
.cal-day.is-blank {
  border-color: transparent;
  background: transparent;
  cursor: default;
}
.cal-day:disabled { cursor: default; }
.cal-day-num {
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  opacity: 0.75;
}
.cal-day-sum {
  align-self: stretch;
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* шкала насыщенности: 0 — продаж не было, 1..5 — растущая доля от максимума */
.cal-day.lvl-0 { background: #f4f5f7; border-color: #ebedf1; color: var(--muted); }
.cal-day.lvl-1 { background: #ede9fe; border-color: #e2dcfd; }
.cal-day.lvl-2 { background: #ddd6fe; border-color: #d0c6fd; }
.cal-day.lvl-3 { background: #c4b5fd; border-color: #b6a3fc; }
.cal-day.lvl-4 { background: #a78bfa; border-color: #9878f8; }
.cal-day.lvl-5 { background: #7c3aed; border-color: #7c3aed; color: #fff; }
.cal-day.lvl-5 .cal-day-num { opacity: 0.85; }
.cal-day.is-outside { opacity: 0.45; }
.cal-day.is-today { box-shadow: inset 0 0 0 2px var(--text); }
.cal-day.is-open { box-shadow: 0 0 0 2px var(--accent-strong); }
.cal-day:not(:disabled):hover { border-color: var(--accent-strong); }

.calendar-legend {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}
.legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(15, 23, 42, 0.06);
}
.legend-swatch.lvl-1 { background: #ede9fe; }
.legend-swatch.lvl-2 { background: #ddd6fe; }
.legend-swatch.lvl-3 { background: #c4b5fd; }
.legend-swatch.lvl-4 { background: #a78bfa; }
.legend-swatch.lvl-5 { background: #7c3aed; }
.legend-scale { margin-left: 10px; font-variant-numeric: tabular-nums; }
.calendar-empty {
  padding: 24px 4px;
  color: var(--muted);
  font-size: 13px;
}
.calendar-detail {
  align-self: stretch;
  padding: 18px 20px 20px;
  border-left: 1px solid var(--line);
  background: #fbfbfd;
}
.calendar-hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}
.calendar-detail-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.calendar-detail-head h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
}
.calendar-detail-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
@media (max-width: 1100px) {
  .calendar-layout { grid-template-columns: minmax(0, 1fr); }
  .calendar-detail { border-left: none; border-top: 1px solid var(--line); }
}
@media (max-width: 640px) {
  .calendar-body { padding: 14px 12px 16px; }
  .calendar-months { grid-template-columns: minmax(0, 1fr); }
  .calendar-detail { padding: 14px 12px 16px; }
  .calendar-legend { flex-wrap: wrap; }
  .legend-scale { margin-left: 0; width: 100%; }
  .cal-day-sum { font-size: 10px; }
}
