/* Design tokens (from React app) */
:root {
  --background: 220 25% 97%;
  --foreground: 222 35% 12%;
  --card: 0 0% 100%;
  --card-foreground: 222 35% 12%;
  --primary: 234 89% 58%;
  --primary-foreground: 0 0% 100%;
  --primary-glow: 252 89% 68%;
  --secondary: 220 20% 94%;
  --secondary-foreground: 222 35% 12%;
  --muted: 220 20% 94%;
  --muted-foreground: 222 15% 45%;
  --accent: 188 86% 53%;
  --success: 152 70% 42%;
  --warning: 38 95% 55%;
  --danger: 0 78% 60%;
  --info: 210 90% 56%;
  --border: 220 18% 88%;
  --radius: 0.75rem;
  --gradient-primary: linear-gradient(135deg, hsl(234 89% 58%), hsl(252 89% 68%));
  --shadow-card: 0 1px 3px hsl(222 35% 12% / 0.04), 0 8px 24px -8px hsl(222 35% 12% / 0.08);
  --container-max: 1400px;
  --container-pad: 2rem;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font-feature-settings: "cv11", "ss01";
  line-height: 1.5;
}

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

.container {
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
  padding-left: var(--container-pad);
  padding-right: var(--container-pad);
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid hsl(var(--border) / 0.6);
  background: hsl(var(--card) / 0.6);
  backdrop-filter: blur(12px);
}

.site-header__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 0;
}

.site-header__brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-icon {
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.75rem;
  background: var(--gradient-primary);
  color: hsl(var(--primary-foreground));
  flex-shrink: 0;
}

.logo-icon svg { width: 1.25rem; height: 1.25rem; }

.site-header h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.site-header .subtitle {
  margin: 0;
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
}

.breadcrumb a { transition: color 0.15s; }
.breadcrumb a:hover { color: hsl(var(--foreground)); }
.breadcrumb .sep { margin: 0 0.375rem; opacity: 0.5; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.375rem 0.875rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: calc(var(--radius) - 2px);
  border: 1px solid transparent;
  cursor: pointer;
  background: transparent;
  color: inherit;
  transition: background 0.15s, border-color 0.15s;
  font-family: inherit;
}

.btn svg { width: 1rem; height: 1rem; }

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.btn--ghost {
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
}

.btn--ghost:hover { background: hsl(var(--secondary)); }

.btn--outline {
  border-color: hsl(var(--border));
  background: hsl(var(--card));
}

.btn--outline:hover { background: hsl(var(--secondary)); }

.btn--icon {
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
}

.btn--primary {
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  border-color: hsl(var(--primary));
}

.btn--primary:hover {
  filter: brightness(1.05);
}

.header-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

/* Badge */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 9999px;
  border: 1px solid hsl(var(--border));
  background: hsl(var(--card));
}

.badge svg { width: 0.875rem; height: 0.875rem; }

.badge--success { background: hsl(var(--success) / 0.15); color: hsl(var(--success)); border-color: hsl(var(--success) / 0.3); }
.badge--warning { background: hsl(var(--warning) / 0.15); color: hsl(var(--warning)); border-color: hsl(var(--warning) / 0.3); }
.badge--muted { background: hsl(var(--muted)); color: hsl(var(--muted-foreground)); }

/* Hero */
.hero {
  position: relative;
  overflow: hidden;
  border-radius: 1.5rem;
  border: 1px solid hsl(var(--border) / 0.6);
  padding: 2rem 3rem;
  box-shadow: var(--shadow-card);
  background: var(--gradient-primary);
}

.hero::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.2;
  background-image:
    radial-gradient(circle at 20% 30%, white, transparent 40%),
    radial-gradient(circle at 80% 70%, white, transparent 40%);
  pointer-events: none;
}

.hero__content {
  position: relative;
  max-width: 42rem;
  color: hsl(var(--primary-foreground));
}

.hero__badge {
  display: inline-block;
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 9999px;
  background: rgba(255, 255, 255, 0.15);
}

.hero h2 {
  margin: 1rem 0 0;
  font-size: clamp(1.75rem, 4vw, 2.25rem);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.hero p {
  margin: 0.75rem 0 0;
  font-size: clamp(1rem, 2vw, 1.125rem);
  opacity: 0.85;
}

/* Main layout */
main { padding: 2.5rem 0; }
main.space-y > * + * { margin-top: 2.5rem; }
main.space-y-sm > * + * { margin-top: 1.5rem; }

/* Страница отчёта: шапка + фильтры закреплены, скролл только контента */
.report-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.report-page .site-header {
  position: relative;
  top: auto;
  flex-shrink: 0;
}

.report-page .report-layout {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0 var(--container-pad) 0;
  margin: 0 auto;
  width: 100%;
  max-width: var(--container-max);
  overflow: hidden;
}

.report-page .report-filters-bar {
  flex-shrink: 0;
  padding-top: 1rem;
  padding-bottom: 0.75rem;
  background: hsl(var(--background));
  border-bottom: 1px solid hsl(var(--border) / 0.55);
  box-shadow: 0 4px 12px -4px hsl(222 35% 12% / 0.06);
}

.report-page .report-filters-bar .filters {
  margin: 0;
}

.report-page .report-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-top: 1.25rem;
  padding-bottom: 2rem;
  -webkit-overflow-scrolling: touch;
}

.report-page .report-scroll > * + * {
  margin-top: 1.5rem;
}

.section-title h3 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.section-title p {
  margin: 0.25rem 0 0;
  font-size: 0.875rem;
  color: hsl(var(--muted-foreground));
}

/* Cards */
.card {
  border: 1px solid hsl(var(--border) / 0.6);
  border-radius: var(--radius);
  background: hsl(var(--card));
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.card--hover {
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
  height: 100%;
  display: block;
}

.card--hover:hover {
  transform: translateY(-4px);
  box-shadow: 0 10px 30px -8px hsl(222 35% 12% / 0.12);
}

.card--dim { opacity: 0.8; }

.card__header { padding: 1.25rem 1.25rem 0; }

.card__header--toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem 1.25rem;
}

.card__header--toolbar > div:first-child {
  flex: 1 1 12rem;
  min-width: 0;
}

.card__header--toolbar .card__title { margin: 0; }

.lead-link {
  color: hsl(var(--primary));
  font-weight: 500;
  text-decoration: none;
}

.lead-link:hover {
  text-decoration: underline;
}

.input-text--search {
  width: min(100%, 11.5rem);
  min-width: 8.5rem;
  padding: 0.4rem 0.65rem;
  font-size: 0.8125rem;
}

#leads-phone-search {
  width: 9.75rem;
  max-width: 9.75rem;
  min-width: 9.75rem;
}

.card__toolbar-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  flex: 1 1 auto;
  justify-content: flex-end;
  min-width: 0;
}

.card__toolbar-icon-group {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  padding-left: 0.625rem;
  margin-left: 0.125rem;
  border-left: 1px solid hsl(var(--border) / 0.65);
}

.card__toolbar-icon-group .btn--icon {
  width: 2.5rem;
  height: 2.5rem;
  min-width: 2.5rem;
  min-height: 2.5rem;
  padding: 0;
  flex-shrink: 0;
}

.card__toolbar-icon-group .btn svg {
  width: 1.125rem;
  height: 1.125rem;
}

.card__toolbar-actions .table-paging-toolbar {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: hsl(var(--muted-foreground));
  white-space: nowrap;
  flex-shrink: 0;
}

.card__toolbar-actions .table-paging-toolbar .select {
  min-width: 4.25rem;
}

.card__toolbar-actions .select--compact,
.card__toolbar-actions .input-text--search {
  flex-shrink: 0;
}

@media (max-width: 767px) {
  .card__toolbar-actions {
    flex-basis: 100%;
    justify-content: flex-start;
  }

  .card__toolbar-icon-group {
    margin-left: auto;
    padding-left: 0.625rem;
  }
}

.select--compact {
  min-width: 9.5rem;
  padding: 0.375rem 1.75rem 0.375rem 0.625rem;
  font-size: 0.8125rem;
}

.btn--sm {
  padding: 0.25rem 0.625rem;
  font-size: 0.8125rem;
}
.card__body { padding: 1.25rem; }
.card__body--chart { height: 280px; position: relative; }
.card__body--chart-md { height: 300px; position: relative; }

.card__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.card__desc {
  margin: 0.25rem 0 0;
  font-size: 0.875rem;
  color: hsl(var(--muted-foreground));
}

/* Reports grid */
.reports-grid {
  display: grid;
  gap: 1.25rem;
  grid-template-columns: 1fr;
}

@media (min-width: 640px) {
  .reports-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 1024px) {
  .reports-grid { grid-template-columns: repeat(3, 1fr); }
}

.report-card__icon {
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  border-radius: 0.75rem;
}

.report-card__icon svg { width: 1.5rem; height: 1.5rem; }

.report-card__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}

.tags { display: flex; flex-wrap: wrap; gap: 0.375rem; }

.tag {
  padding: 0.125rem 0.5rem;
  font-size: 0.75rem;
  border-radius: 0.375rem;
  background: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
}

.report-card__link {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: hsl(var(--primary));
}

.report-card__link--muted { color: hsl(var(--muted-foreground)); }

.report-card__link svg {
  width: 1rem;
  height: 1rem;
  transition: transform 0.2s;
}

.card--hover:hover .report-card__link svg { transform: translateX(4px); }

/* KPI */
.kpi-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}

@media (min-width: 640px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { .kpi-grid { grid-template-columns: repeat(4, 1fr); } }

.kpi-grid--deals {
  grid-template-columns: repeat(auto-fit, minmax(11.25rem, 1fr));
}

@media (min-width: 1024px) {
  .kpi-grid--deals { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 1280px) {
  .kpi-grid--deals { grid-template-columns: repeat(5, 1fr); }
}

.kpi {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 1.25rem;
}

.kpi__label {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: hsl(var(--muted-foreground));
}

.kpi__value {
  margin: 0.5rem 0 0;
  font-size: 1.875rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.kpi__hint {
  margin: 0.25rem 0 0;
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
}

.kpi__icon {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 0.75rem;
  flex-shrink: 0;
}

.kpi__icon svg { width: 1.25rem; height: 1.25rem; }

/* Filters */
.filters {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.65rem;
  padding: 1rem;
}

.filters__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  min-width: 0;
}

.filters__row--main {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.filters__row--dates {
  padding-top: 0.65rem;
  border-top: 1px solid hsl(var(--border) / 0.55);
}

.filters__label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: hsl(var(--muted-foreground));
}

.filters__label svg { width: 1rem; height: 1rem; }

.filters__source-badge {
  padding: 0.2rem 0.55rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 999px;
  background: hsl(var(--muted) / 0.35);
  color: hsl(var(--muted-foreground));
  white-space: nowrap;
}

.filters__source-badge--error {
  background: hsl(0 78% 60% / 0.12);
  color: hsl(0 65% 45%);
}

.filters__count {
  margin-left: 0;
  font-size: 0.875rem;
  color: hsl(var(--muted-foreground));
  white-space: nowrap;
}

.filters__count strong { color: hsl(var(--foreground)); }

.filters__date-range {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem 0.5rem;
  flex: 1 1 auto;
  min-width: 0;
}

.filters__date-range .input-date {
  min-width: 8.75rem;
}

.filters__date-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: hsl(var(--muted-foreground));
  white-space: nowrap;
}

.filters__date-sep {
  color: hsl(var(--muted-foreground));
  font-size: 0.875rem;
  user-select: none;
}

.filters__date-presets {
  display: inline-flex;
  flex-shrink: 0;
  align-items: stretch;
  margin-left: 0.25rem;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--card));
  overflow: hidden;
  box-shadow: 0 1px 2px hsl(222 35% 12% / 0.04);
}

.filters__preset-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0.85rem;
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  border: none;
  border-right: 1px solid hsl(var(--border));
  border-radius: 0;
  background: transparent;
  color: hsl(var(--foreground));
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
}

.filters__preset-btn:last-child {
  border-right: none;
}

.filters__preset-btn:hover {
  background: hsl(var(--secondary));
}

.filters__preset-btn:active {
  background: hsl(var(--secondary) / 0.85);
}

.filters__preset-btn:focus-visible {
  outline: 2px solid hsl(var(--primary) / 0.45);
  outline-offset: -2px;
  z-index: 1;
}

.btn--xs {
  padding: 0.2rem 0.45rem;
  font-size: 0.75rem;
  line-height: 1.2;
}

.input-date {
  min-width: 9.5rem;
  padding: 0.5rem 0.65rem;
  font-size: 0.875rem;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--card));
  color: inherit;
  font-family: inherit;
  cursor: pointer;
}

.input-date:focus {
  outline: 2px solid hsl(var(--primary) / 0.35);
  outline-offset: 1px;
}

.select {
  min-width: 180px;
  padding: 0.5rem 2rem 0.5rem 0.75rem;
  font-size: 0.875rem;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--card)) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 0.75rem center;
  appearance: none;
  color: inherit;
  font-family: inherit;
  cursor: pointer;
}

.select--wide { min-width: 200px; }

/* Charts grid */
.charts-row {
  display: grid;
  gap: 1.5rem;
}

@media (min-width: 1024px) {
  .charts-row--3 { grid-template-columns: 2fr 1fr; }
  .charts-row--2 { grid-template-columns: repeat(2, 1fr); }
}

/* Funnel (SVG, косые грани как Recharts) */
.funnel {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  height: 100%;
  min-height: 260px;
  padding: 0 0.5rem 0.75rem;
}

.funnel-tooltip {
  position: absolute;
  z-index: 10;
  pointer-events: none;
  padding: 0.35rem 0.65rem;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.3;
  color: hsl(var(--foreground));
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
  box-shadow: 0 4px 14px hsl(222 35% 12% / 0.14);
  white-space: nowrap;
  transform: translate(-50%, calc(-100% - 8px));
}

.funnel-seg {
  cursor: default;
}

.manager-leads-btn {
  padding: 0;
  border: none;
  background: none;
  font: inherit;
  font-variant-numeric: tabular-nums;
  font-weight: inherit;
  color: inherit;
  cursor: pointer;
  text-decoration: none;
}

.manager-leads-btn:hover {
  opacity: 0.72;
}

.manager-leads-btn:focus-visible {
  outline: 2px solid hsl(var(--primary) / 0.45);
  outline-offset: 2px;
  border-radius: 2px;
}

#manager-leads-table,
#manager-deals-table {
  width: 100%;
}

.funnel-svg {
  width: 100%;
  height: 100%;
  max-height: 300px;
  display: block;
}

/* Tables */
.table-wrap { overflow-x: auto; }

.table-paging-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0 1.25rem 0.75rem;
}

.table-paging-bar__label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: hsl(var(--muted-foreground));
}

.table-paging-bar__label .select {
  min-width: 4.5rem;
}

.table-load-more {
  display: flex;
  justify-content: center;
  padding: 0 1.25rem 1.25rem;
}

.table-load-more[hidden] {
  display: none;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

th, td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid hsl(var(--border) / 0.6);
}

th {
  font-weight: 500;
  color: hsl(var(--muted-foreground));
  font-size: 0.8125rem;
}

td.text-right, th.text-right { text-align: right; }

.tabular-nums { font-variant-numeric: tabular-nums; }

#table-leads th.col-time-duration,
#table-leads td.col-time-duration {
  min-width: 6.75rem;
  white-space: nowrap;
}

.text-muted { color: hsl(var(--muted-foreground)); }

.font-medium { font-weight: 500; }

.table-note {
  margin: 0.75rem 0 0;
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
}

.deal-health {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.625rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.deal-health--ok {
  background: #dcfce7;
  color: #166534;
}

.deal-health--warning {
  background: #fef3c7;
  color: #92400e;
}

.deal-health--critical {
  background: #fee2e2;
  color: #991b1b;
}

.deal-row--warning td {
  background: #fffbeb;
}

.deal-row--critical td {
  background: #fff1f2;
}

.deals-stage-table {
  min-width: 1400px;
}

.deals-stage-table .deals-stage-th {
  vertical-align: bottom;
  line-height: 1.35;
  min-width: 7.5rem;
  max-width: 11rem;
  white-space: normal;
}

/* Stage badge */
.stage-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 9999px;
}

.stage-badge__dot {
  width: 0.375rem;
  height: 0.375rem;
  border-radius: 50%;
  margin-right: 0.375rem;
}

/* Progress bar */
.progress {
  height: 0.5rem;
  width: 100%;
  overflow: hidden;
  border-radius: 9999px;
  background: hsl(var(--secondary));
}

.progress__fill {
  height: 100%;
  border-radius: 9999px;
  background: var(--gradient-primary);
  transition: width 0.3s;
}

/* Loading */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  color: hsl(var(--muted-foreground));
  font-size: 0.875rem;
}

.loading--error { color: hsl(0 78% 50%); }

.report-layout { position: relative; }
.report-layout--busy { pointer-events: none; }

.report-preloader {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: min(70vh, 520px);
  padding: 2rem 1rem;
  animation: preloader-in 0.35s ease;
}

.report-preloader--overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  min-height: 100%;
  background: hsl(var(--background) / 0.88);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.report-preloader__card {
  width: min(100%, 22rem);
  padding: 1.75rem 1.5rem 1.5rem;
  text-align: center;
  border-radius: var(--radius);
  border: 1px solid hsl(var(--border));
  background: hsl(var(--card));
  box-shadow: 0 12px 40px hsl(220 25% 20% / 0.08);
}

.report-preloader__spinner {
  width: 3rem;
  height: 3rem;
  margin: 0 auto 1.25rem;
  border-radius: 50%;
  border: 3px solid hsl(var(--border));
  border-top-color: hsl(var(--primary));
  animation: preloader-spin 0.85s linear infinite;
}

.report-preloader__title {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
  font-weight: 600;
  color: hsl(var(--foreground));
}

.report-preloader__status {
  margin: 0 0 1.1rem;
  font-size: 0.8125rem;
  color: hsl(var(--muted-foreground));
  min-height: 1.25em;
}

.report-preloader__track {
  height: 0.5rem;
  border-radius: 9999px;
  background: hsl(var(--secondary));
  overflow: hidden;
}

.report-preloader__bar {
  height: 100%;
  width: 0%;
  border-radius: 9999px;
  background: var(--gradient-primary);
  transition: width 0.35s ease;
}

.report-preloader--done .report-preloader__bar {
  transition: width 0.25s ease;
}

.report-preloader__percent {
  margin: 0.65rem 0 0;
  font-size: 0.8125rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: hsl(var(--primary));
}

.report-preloader__cancel {
  min-width: 7.5rem;
  margin: 1rem auto 0;
}

.report-preloader--error .report-preloader__percent { display: none; }
.report-preloader--error .report-preloader__cancel { display: none; }
.report-preloader--error .report-preloader__spinner {
  border-top-color: hsl(0 78% 55%);
  animation: none;
  opacity: 0.5;
}
.report-preloader--error .report-preloader__status {
  color: hsl(0 78% 45%);
}

@keyframes preloader-spin {
  to { transform: rotate(360deg); }
}

@keyframes preloader-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Modal / Settings */
body.modal-open { overflow: hidden; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal[aria-hidden="true"] {
  display: none;
}

.modal__overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
}

.modal__dialog {
  position: relative;
  width: 100%;
  max-width: 32rem;
  max-height: min(90vh, 720px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: hsl(var(--card));
  border-radius: var(--radius);
  border: 1px solid hsl(var(--border) / 0.6);
  box-shadow: 0 24px 48px -12px hsl(222 35% 12% / 0.2);
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 1.25rem 0;
}

.modal__title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
}

.modal__close svg {
  width: 1.25rem;
  height: 1.25rem;
}

.modal__body {
  padding: 1rem 1.25rem 1.25rem;
  overflow-y: auto;
}

.modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding-top: 1rem;
  margin-top: 0.5rem;
  border-top: 1px solid hsl(var(--border) / 0.6);
}

.modal__status {
  margin: 0.75rem 0 0;
  font-size: 0.8125rem;
  min-height: 1.25rem;
}

.modal__status--ok { color: hsl(var(--success)); }
.modal__status--error { color: hsl(var(--danger)); }

.modal__dialog--settings {
  max-width: 52rem;
}

.stage-mapping-wrap {
  overflow-x: auto;
}

.stage-mapping-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.stage-mapping-table th,
.stage-mapping-table td {
  padding: 0.5rem 0.65rem;
  border-bottom: 1px solid hsl(var(--border) / 0.6);
  vertical-align: top;
}

.stage-mapping-table th {
  text-align: left;
  font-weight: 600;
  color: hsl(var(--muted-foreground));
  background: hsl(var(--secondary) / 0.35);
}

.stage-mapping-table__label {
  width: 38%;
  font-weight: 500;
  white-space: nowrap;
}

.stage-mapping-select {
  width: 100%;
  min-width: 14rem;
  max-width: 100%;
  font-size: 0.8125rem;
}

.stage-mapping-loading {
  margin: 0.5rem 0;
  font-size: 0.8125rem;
  color: hsl(var(--muted-foreground));
}

.stage-mapping-extra-ids {
  margin: 0.35rem 0 0;
  font-size: 0.75rem;
}

.stage-mapping-fallback {
  width: 100%;
  font-size: 0.8125rem;
}

.stage-mapping-hint--error {
  color: hsl(var(--danger));
}

.modal__tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0 1.25rem;
  border-bottom: 1px solid hsl(var(--border) / 0.6);
}

.modal__tab {
  margin: 0;
  padding: 0.65rem 1rem;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: hsl(var(--muted-foreground));
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.modal__tab:hover {
  color: hsl(var(--foreground));
}

.modal__tab--active {
  color: hsl(var(--primary));
  border-bottom-color: hsl(var(--primary));
}

.settings-panel[hidden] {
  display: none !important;
}

.settings-panel--active {
  display: block;
}

.bitrix24-status {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  margin: 0.75rem 0;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius);
  background: hsl(var(--muted) / 0.35);
  font-size: 0.8125rem;
}

.bitrix24-status--configured {
  background: hsl(152 70% 42% / 0.1);
}

.bitrix24-status__badge {
  font-weight: 600;
  color: hsl(var(--muted-foreground));
}

.bitrix24-status__badge--ok {
  color: hsl(152 55% 32%);
}

.bitrix24-status__preview {
  font-family: ui-monospace, monospace;
  letter-spacing: 0.04em;
  color: hsl(var(--foreground));
}

.bitrix24-actions {
  margin-top: 0.75rem;
}

.bitrix24-test-status {
  margin: 0.65rem 0 0;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: hsl(var(--muted-foreground));
}

.bitrix24-test-status--ok {
  color: hsl(152 55% 32%);
}

.bitrix24-test-status--error {
  color: hsl(var(--destructive));
}

.field-label {
  display: block;
  margin: 0 0 0.35rem;
  font-size: 0.8125rem;
  font-weight: 500;
}

.settings-section + .settings-section {
  margin-top: 1.5rem;
}

.settings-section__title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
}

.settings-section__hint {
  margin: 0.35rem 0 0.75rem;
  font-size: 0.8125rem;
  color: hsl(var(--muted-foreground));
}

.schedule-grid {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.schedule-grid__head,
.schedule-row {
  display: grid;
  grid-template-columns: 2.5rem 1fr 1fr;
  gap: 0.5rem;
  align-items: center;
}

.schedule-grid__head {
  font-size: 0.75rem;
  font-weight: 500;
  color: hsl(var(--muted-foreground));
  padding-bottom: 0.25rem;
}

.schedule-row__day {
  font-size: 0.875rem;
  font-weight: 500;
}

.input-time,
.textarea {
  width: 100%;
  padding: 0.5rem 0.625rem;
  font-size: 0.875rem;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--card));
  color: inherit;
  font-family: inherit;
}

.textarea {
  resize: vertical;
  min-height: 6rem;
}

.radio {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
  font-size: 0.875rem;
  cursor: pointer;
}

.radio input {
  accent-color: hsl(var(--primary));
}

/* Columns settings */
.columns-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  max-height: min(50vh, 420px);
  overflow-y: auto;
}

.column-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0.625rem;
  border: 1px solid hsl(var(--border) / 0.6);
  border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--secondary) / 0.35);
}

.column-item__check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  cursor: pointer;
  flex: 1;
  min-width: 0;
}

.column-item__check input {
  accent-color: hsl(var(--primary));
  flex-shrink: 0;
}

.column-item__actions {
  display: flex;
  gap: 0.125rem;
  flex-shrink: 0;
}

.column-item__move:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* Highlight rules */
.modal--wide .modal__dialog {
  max-width: 52rem;
}

.modal__subtitle {
  margin: 0.25rem 0 0;
  font-size: 0.8125rem;
  color: hsl(var(--muted-foreground));
  font-weight: 400;
}

.modal__header {
  flex-wrap: wrap;
}

.modal__body--split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  align-items: start;
}

.modal__body--split .modal__status,
.modal__body--split .modal__footer {
  grid-column: 1 / -1;
}

@media (max-width: 768px) {
  .modal__body--split { grid-template-columns: 1fr; }
}

.rules-panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.rules-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 280px;
  overflow-y: auto;
}

.rules-empty {
  font-size: 0.875rem;
  color: hsl(var(--muted-foreground));
  padding: 0.5rem 0;
}

.rule-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.625rem;
  border: 1px solid hsl(var(--border) / 0.6);
  border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--card));
}

.rule-item--off { opacity: 0.55; }

.rule-item__body {
  display: flex;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
}

.rule-item__severity {
  width: 0.5rem;
  border-radius: 2px;
  flex-shrink: 0;
  align-self: stretch;
}

.rule-item__severity--critical { background: #dc2626; }
.rule-item__severity--danger { background: #f87171; }
.rule-item__severity--warning { background: #f59e0b; }
.rule-item__severity--success { background: #22c55e; }
.rule-item__severity--info { background: #3b82f6; }
.rule-item__severity--neutral { background: #9ca3af; }

/* Подсветка сделок — лёгкий tint + акцентная граница */
#deals-table tbody tr.hl-deal-row--info > td {
  background: hsl(210 100% 97%);
  border-top-color: hsl(210 40% 92%);
  border-bottom-color: hsl(210 40% 92%);
}
#deals-table tbody tr.hl-deal-row--info > td:first-child {
  border-left: 3px solid hsl(210 70% 65%);
}

#deals-table tbody tr.hl-deal-row--warning > td {
  background: hsl(45 100% 96%);
  border-top-color: hsl(45 40% 90%);
  border-bottom-color: hsl(45 40% 90%);
}
#deals-table tbody tr.hl-deal-row--warning > td:first-child {
  border-left: 3px solid hsl(38 92% 50%);
}

#deals-table tbody tr.hl-deal-row--danger > td {
  background: hsl(0 86% 97%);
  border-top-color: hsl(0 30% 92%);
  border-bottom-color: hsl(0 30% 92%);
}
#deals-table tbody tr.hl-deal-row--danger > td:first-child {
  border-left: 3px solid hsl(0 72% 51%);
}

#deals-table tbody tr.hl-deal-row--critical > td {
  background: hsl(0 93% 94%);
  border-top-color: hsl(0 35% 88%);
  border-bottom-color: hsl(0 35% 88%);
}
#deals-table tbody tr.hl-deal-row--critical > td:first-child {
  border-left: 3px solid hsl(0 65% 42%);
}

#deals-table tbody td.hl-deal-cell--info {
  background: hsl(210 100% 94%) !important;
}
#deals-table tbody td.hl-deal-cell--warning {
  background: hsl(45 100% 90%) !important;
  font-weight: 500;
}
#deals-table tbody td.hl-deal-cell--danger {
  background: hsl(0 93% 92%) !important;
  font-weight: 500;
}
#deals-table tbody td.hl-deal-cell--critical {
  background: hsl(0 96% 88%) !important;
  font-weight: 600;
}
#deals-table tbody td.hl-deal-cell--emph {
  box-shadow: inset 0 0 0 1px hsl(0 0% 0% / 0.04);
}

.filters__issues-only {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8125rem;
  color: hsl(var(--muted-foreground));
  white-space: nowrap;
  cursor: pointer;
}
.filters__issues-only input {
  margin: 0;
}

.rule-item__meta {
  margin: 0.125rem 0 0;
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
}

.rule-item__actions {
  display: flex;
  gap: 0.125rem;
  flex-shrink: 0;
}

.rules-presets { margin-top: 1rem; }

.rules-presets__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin-top: 0.375rem;
}

.rules-editor {
  border: 1px solid hsl(var(--border) / 0.6);
  border-radius: calc(var(--radius) - 2px);
  padding: 1rem;
  background: hsl(var(--secondary) / 0.25);
}

.rules-editor[hidden] { display: none; }

.rule-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.rule-form__row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.rule-form__checks {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.rule-form__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8125rem;
}

.field--grow { flex: 1; min-width: 8rem; }

.field-hint {
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
}

.input-text {
  padding: 0.5rem 0.625rem;
  font-size: 0.875rem;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--card));
  color: inherit;
  font-family: inherit;
  width: 100%;
}

/* 404 */
.not-found {
  text-align: center;
  padding: 4rem 1rem;
}

.not-found h1 { font-size: 4rem; margin: 0; opacity: 0.3; }
.not-found p { color: hsl(var(--muted-foreground)); }
