/* === СкандиЭкоДом — брендбук === */

:root {
  /* Cream surfaces */
  --cream:      #F5F1EB;
  --cream-2:    #EFE8DB;
  --card-a:     #FFFCF5;
  --card-b:     #F5EBD7;

  /* Ink */
  --ink-strong: #1F1A14;
  --ink:        #3C2F23;
  --ink-mute:   #7A6A56;

  /* Dark surfaces */
  --dark-a:     #14100D;
  --dark-b:     #281C14;
  --on-dark:    #F3ECDC;
  --on-dark-mute: rgba(243, 236, 220, 0.62);

  /* Gold */
  --gold-1:     #C19A5B;
  --gold-2:     #E6C285;
  --gold-3:     #B8893E;
  --gold-line:  rgba(193, 154, 91, 0.30);
  --gold-line-strong: rgba(193, 154, 91, 0.55);
  --gold-glow:  rgba(193, 154, 91, 0.10);

  /* Status (приглушённые, не неон) */
  --status-good: #6B7F4D;
  --status-warn: #B07A1A;
  --status-bad:  #8E3E3E;

  /* Radii */
  --r-sm: 10px;
  --r-md: 12px;
  --r-lg: 14px;
  --r-xl: 18px;

  /* Shadows — тёплые */
  --shadow-sm: 0 4px 16px rgba(60, 40, 20, 0.06);
  --shadow-md: 0 12px 32px rgba(60, 40, 20, 0.08);
  --shadow-lg: 0 24px 60px rgba(60, 40, 20, 0.10);
  --shadow-dark: 0 24px 60px rgba(0, 0, 0, 0.35);

  /* Fonts */
  --font-sans: 'Manrope', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  background: var(--cream);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv11', 'ss01';
}

a { color: inherit; text-decoration: none; }

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 28px;
}

/* === Типографика === */
.h-eyebrow {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold-3);
  font-family: var(--font-sans);
}
.h-section {
  font-family: var(--font-sans);
  font-weight: 600;
  letter-spacing: -0.025em;
  color: var(--ink-strong);
  font-size: 30px;
  margin: 0 0 4px;
  line-height: 1.15;
}
.h-section-sub {
  color: var(--ink-mute);
  font-size: 14px;
  margin: 0;
  line-height: 1.5;
}
.t-mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.t-mute { color: var(--ink-mute); }
.t-gold {
  background: linear-gradient(135deg, var(--gold-1) 0%, var(--gold-2) 50%, var(--gold-3) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* === Layout === */
section.section { padding: 56px 0; position: relative; }
section.section-tight { padding: 36px 0; }
section.on-dark {
  background: linear-gradient(135deg, var(--dark-a), var(--dark-b));
  color: var(--on-dark);
}
section.on-dark .h-section { color: var(--on-dark); }
section.on-dark .h-section-sub { color: var(--on-dark-mute); }
section.on-dark .h-eyebrow { color: var(--gold-2); }

/* Seam divider — золотая линия с ромбом */
.seam {
  display: flex; align-items: center; justify-content: center;
  padding: 10px 0;
}
.seam::before, .seam::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-line) 50%, transparent);
}
.seam-diamond {
  width: 8px; height: 8px;
  background: linear-gradient(135deg, var(--gold-1), var(--gold-2));
  transform: rotate(45deg);
  margin: 0 14px;
}

/* === Header === */
.appbar {
  background: linear-gradient(180deg, rgba(245,241,235,0.96), rgba(245,241,235,0.88));
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 30;
  border-bottom: 1px solid var(--gold-line);
}
.appbar-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 0;
  gap: 24px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 38px; height: 38px;
  border-radius: var(--r-sm);
  background: linear-gradient(135deg, var(--gold-1) 0%, var(--gold-2) 100%);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(193, 154, 91, 0.30);
}
.brand-mark svg { width: 22px; height: 22px; color: var(--dark-a); stroke-width: 2.4; }
.brand-name {
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.015em;
  color: var(--ink-strong);
}
.brand-tag { display: block; color: var(--ink-mute); font-size: 11px; letter-spacing: 0.06em; }

/* === Header controls cluster === */
.header-controls {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}

/* === Source tabs (под шапкой) === */
.source-tabs {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 28px 16px;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}
.source-tabs::-webkit-scrollbar { display: none; }
.tab-btn {
  appearance: none;
  border: 1px solid var(--gold-line);
  background: var(--card-a);
  color: var(--ink-mute);
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 13px;
  letter-spacing: 0.01em;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px;
  white-space: nowrap;
  transition: background .15s ease, color .15s ease, border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.tab-btn .tab-ico {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px;
}
.tab-btn .tab-ico svg { width: 14px; height: 14px; }
.tab-btn:hover:not(.is-active) {
  color: var(--ink-strong);
  background: rgba(193, 154, 91, 0.08);
  border-color: var(--gold-line-strong);
}
.tab-btn.is-active {
  background: linear-gradient(135deg, var(--gold-1) 0%, var(--gold-2) 50%, var(--gold-3) 100%);
  color: var(--dark-a);
  font-weight: 600;
  border-color: var(--gold-3);
  box-shadow: 0 4px 12px rgba(193, 154, 91, 0.30);
}
.tab-btn.is-active .tab-ico { color: var(--dark-a); }
@media (max-width: 720px) {
  .source-tabs {
    justify-content: flex-start;
    padding: 10px 16px 14px;
  }
}

/* === Tab content visibility === */
.tab-content[hidden] { display: none !important; }

/* === No-data placeholder (для Авито/ВК до подключения API) === */
.no-data-placeholder {
  display: flex; flex-direction: column; gap: 8px; align-items: flex-start;
  padding: 18px;
  background: var(--cream);
  border: 1px dashed var(--gold-line-strong);
  border-radius: var(--r-md);
  color: var(--ink-mute);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
}
.no-data-placeholder .np-head {
  display: flex; align-items: center; gap: 8px;
  color: var(--status-warn);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.no-data-placeholder .np-head svg { width: 14px; height: 14px; }
.no-data-placeholder .np-body { color: var(--ink-mute); }
.metric.metric-empty .value {
  background: none;
  -webkit-text-fill-color: var(--ink-mute);
  color: var(--ink-mute);
  font-size: 18px;
  font-weight: 500;
}

/* === Window toggle (7d / 30d) === */
.window-toggle {
  display: inline-flex;
  background: var(--card-a);
  border: 1px solid var(--gold-line);
  border-radius: var(--r-md);
  padding: 4px;
  box-shadow: var(--shadow-sm);
  gap: 2px;
}
.window-btn {
  appearance: none;
  border: 0;
  background: transparent;
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 13px;
  color: var(--ink-mute);
  padding: 7px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s ease, color .15s ease, box-shadow .15s ease;
  letter-spacing: 0.01em;
}
.window-btn:hover:not(.is-active) {
  color: var(--ink-strong);
  background: rgba(193, 154, 91, 0.08);
}
.window-btn.is-active {
  background: linear-gradient(135deg, var(--gold-1) 0%, var(--gold-2) 50%, var(--gold-3) 100%);
  color: var(--dark-a);
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(193, 154, 91, 0.30);
}

/* === Period selector === */
.period-pick {
  display: flex; align-items: center; gap: 12px;
  background: var(--card-a);
  border: 1px solid var(--gold-line);
  border-radius: var(--r-md);
  padding: 6px 14px;
  box-shadow: var(--shadow-sm);
  min-width: 280px;
}
.period-pick svg { width: 16px; height: 16px; color: var(--gold-3); }
.period-pick select {
  appearance: none;
  border: 0;
  background: transparent;
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 14px;
  color: var(--ink-strong);
  padding: 8px 4px;
  flex: 1;
  cursor: pointer;
  outline: none;
}
.period-pick .chev { color: var(--ink-mute); }

/* === Game-style Loader === */
.app-loader {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(28, 32, 35, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 5000;
  animation: app-loader-fade-in 0.25s ease-out;
}
.app-loader.is-open { display: flex; }

@keyframes app-loader-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.app-loader__card {
  background: linear-gradient(135deg, #1c2023 0%, #2a2e32 100%);
  border: 1px solid var(--gold-3);
  border-radius: var(--r-lg);
  padding: 32px 36px;
  min-width: 360px;
  max-width: 480px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5), 0 0 60px rgba(218, 165, 32, 0.15);
  text-align: center;
  position: relative;
  overflow: hidden;
}
/* золотая обводка-блик сверху */
.app-loader__card::before {
  content: '';
  position: absolute;
  top: 0; left: -50%;
  width: 200%;
  height: 2px;
  background: linear-gradient(90deg,
    transparent 0%,
    var(--gold-1) 25%,
    var(--gold-3) 50%,
    var(--gold-1) 75%,
    transparent 100%);
  animation: app-loader-shimmer 2s ease-in-out infinite;
}
@keyframes app-loader-shimmer {
  0%   { transform: translateX(-50%); }
  100% { transform: translateX(50%); }
}

.app-loader__title {
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gold-3);
  margin-bottom: 6px;
}
.app-loader__subtitle {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 20px;
  letter-spacing: -0.01em;
  color: #fff;
  margin-bottom: 22px;
  text-shadow: 0 0 24px rgba(218, 165, 32, 0.4);
}

.app-loader__bar {
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 14px;
  position: relative;
}
.app-loader__bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg,
    var(--gold-1) 0%,
    var(--gold-2) 50%,
    var(--gold-3) 100%);
  border-radius: 999px;
  box-shadow: 0 0 16px rgba(218, 165, 32, 0.6);
  position: relative;
}
/* бегущий блик по полосе */
.app-loader__bar-fill::after {
  content: '';
  position: absolute;
  top: 0; left: 0;
  height: 100%;
  width: 60px;
  background: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.5) 50%, transparent 100%);
  animation: app-loader-bar-shine 1.6s linear infinite;
}
@keyframes app-loader-bar-shine {
  0%   { transform: translateX(-60px); }
  100% { transform: translateX(420px); }
}

.app-loader__stage {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: rgba(255, 255, 255, 0.65);
  letter-spacing: 0.02em;
  min-height: 18px;
  transition: opacity 0.2s ease;
}

/* === Custom Period Dropdown — открывается строго вниз === */
.period-dropdown-wrap {
  position: relative;
  min-width: 240px;
  padding: 0;
}
.period-dd-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 8px 14px;
  background: transparent;
  border: 0;
  cursor: pointer;
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 14px;
  color: var(--ink-strong);
  outline: none;
  border-radius: var(--r-md);
  text-align: left;
}
.period-dd-btn:hover { background: var(--gold-glow); }
.period-dd-btn:focus-visible {
  outline: 2px solid var(--gold-3);
  outline-offset: 2px;
}
.period-dd-btn .period-dd-current {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.period-dd-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: #fff;
  border: 1px solid var(--gold-line);
  border-radius: var(--r-md);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.18);
  z-index: 1000;
  max-height: 70vh;
  overflow-y: auto;
}
.period-dd-menu[hidden] { display: none; }

/* Свой период — календарь от/до в дропдауне. */
.period-dd-custom {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px 4px;
  flex-wrap: wrap;
}
.period-dd-custom .period-dd-date {
  flex: 1 1 0;
  min-width: 0;
  font-size: 13px;
  font-family: inherit;
  padding: 6px 8px;
  border: 1px solid var(--gold-line, rgba(184,137,58,0.30));
  border-radius: var(--r-sm, 8px);
  background: #fff;
  color: var(--ink-strong, #2a2a2a);
}
.period-dd-custom .period-dd-dash { color: var(--ink-mute, #8a8278); }
.period-dd-custom .period-dd-apply {
  flex: 0 0 auto;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  border: none;
  border-radius: var(--r-sm, 8px);
  background: var(--gold-3, #b8893a);
  color: #fff;
  cursor: pointer;
  transition: opacity .15s ease;
}
.period-dd-custom .period-dd-apply:hover { opacity: 0.88; }

.period-dd-group {
  padding: 6px 10px 4px;
  font-family: var(--font-sans);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold-3);
}
.period-dd-divider {
  height: 1px;
  background: var(--gold-line);
  margin: 4px 8px;
}
.period-dd-item {
  padding: 8px 12px;
  cursor: pointer;
  border-radius: var(--r-sm);
  font-family: var(--font-sans);
  font-size: 13.5px;
  color: var(--ink);
  user-select: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
.period-dd-item:hover { background: var(--gold-glow); }
.period-dd-item.is-active {
  background: linear-gradient(135deg, var(--gold-2) 0%, var(--gold-1) 100%);
  color: var(--dark-a);
  font-weight: 600;
}
.period-dd-item.is-active::before { content: '✓'; }
.period-dd-item:not(.is-active)::before { content: ''; width: 14px; display: inline-block; }

/* === Freshness === */
.fresh {
  display: flex; align-items: center; gap: 10px;
  font-size: 12px;
  color: var(--ink-mute);
  font-family: var(--font-mono);
}
.fresh .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--status-good);
  box-shadow: 0 0 0 4px rgba(107, 127, 77, 0.18);
}
.fresh.warn .dot { background: var(--status-warn); box-shadow: 0 0 0 4px rgba(176, 122, 26, 0.18); }
.fresh.bad  .dot { background: var(--status-bad); box-shadow: 0 0 0 4px rgba(142, 62, 62, 0.18); }

/* === Settings link (header) === */
.settings-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--r-sm);
  color: var(--ink-mute);
  background: transparent;
  border: 1px solid transparent;
  transition: color .15s ease, background .15s ease, border-color .15s ease;
  margin-left: 8px;
}
.settings-link:hover {
  color: var(--gold-3);
  background: var(--gold-glow);
  border-color: var(--gold-line);
}

/* === Единое меню «Настройки» (admin) === */
.settings-menu { position: relative; margin-left: 8px; }
.settings-btn {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 36px;
  padding: 0 8px;
  border-radius: var(--r-sm);
  color: var(--ink-mute);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: color .15s ease, background .15s ease, border-color .15s ease;
}
.settings-btn:hover, .settings-menu.is-open .settings-btn {
  color: var(--gold-3);
  background: var(--gold-glow);
  border-color: var(--gold-line);
}
.settings-btn .chev { transition: transform .15s ease; }
.settings-menu.is-open .settings-btn .chev { transform: rotate(180deg); }

.settings-dd-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 280px;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--surface, #fff);
  border: 1px solid var(--gold-line, rgba(184,137,58,0.25));
  border-radius: var(--r-md, 12px);
  box-shadow: 0 12px 32px rgba(60,45,20,0.16);
  z-index: 50;
}
.settings-dd-menu[hidden] { display: none; }
.settings-dd-menu a {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--r-sm, 8px);
  color: var(--ink-strong, #2a2a2a);
  text-decoration: none;
  transition: background .12s ease;
}
.settings-dd-menu a:hover { background: var(--gold-glow, rgba(184,137,58,0.10)); }
.settings-dd-menu a svg { flex: 0 0 auto; margin-top: 2px; color: var(--gold-3, #b8893a); }
.settings-dd-menu a span { display: flex; flex-direction: column; gap: 2px; }
.settings-dd-menu a strong { font-size: 14px; font-weight: 600; }
.settings-dd-menu a em { font-size: 12px; font-style: normal; color: var(--ink-mute, #8a8278); }

/* === User badge (header) === */
.user-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: 10px;
  padding: 6px 10px 6px 12px;
  background: var(--cream);
  border: 1px solid var(--gold-line);
  border-radius: 999px;
}
.user-badge-name {
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-strong);
  letter-spacing: -0.005em;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-badge-logout {
  background: transparent;
  border: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-mute);
  cursor: pointer;
  padding: 0;
  transition: color .15s ease, background .15s ease;
}
.user-badge-logout:hover {
  color: var(--status-bad);
  background: rgba(142, 62, 62, 0.08);
}

/* === Cost source badge (на карточке расхода) === */
.cost-source-note {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  background: var(--gold-glow);
  color: var(--gold-3);
  border: 1px solid var(--gold-line);
}
.cost-source-note.is-partial {
  background: rgba(176, 122, 26, 0.08);
  border-color: rgba(176, 122, 26, 0.30);
  color: var(--status-warn);
}

/* === Карточки === */
.card {
  background: linear-gradient(135deg, var(--card-a) 0%, var(--card-b) 100%);
  border: 1px solid var(--gold-line);
  border-radius: var(--r-lg);
  padding: 26px;
  position: relative;
  transition: transform .25s ease, box-shadow .25s ease, border-color .25s ease;
  box-shadow: var(--shadow-sm);
}
.card.hoverable:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--gold-line-strong);
}
.card-dark {
  background: linear-gradient(135deg, var(--dark-a) 0%, var(--dark-b) 100%);
  color: var(--on-dark);
  border: 1px solid rgba(193, 154, 91, 0.32);
  border-radius: var(--r-lg);
  padding: 26px;
  box-shadow: var(--shadow-dark);
}

/* === Metric Hero === */
.metric-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(4, 1fr);
}
@media (max-width: 980px) { .metric-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .metric-grid { grid-template-columns: 1fr; } }

.metric {
  display: flex; flex-direction: column; gap: 6px;
}
.metric .label {
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-mute);
  display: flex; align-items: center; gap: 8px;
}
.metric .label svg { width: 14px; height: 14px; color: var(--gold-3); }
.metric .value {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 38px;
  line-height: 1.0;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--gold-1) 0%, var(--gold-2) 50%, var(--gold-3) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-top: 6px;
}
.metric .value.empty {
  background: none;
  -webkit-text-fill-color: var(--ink-mute);
  color: var(--ink-mute);
  font-size: 28px;
}
.metric .sub {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-mute);
  margin-top: 4px;
  display: flex; align-items: center; gap: 8px;
}
.delta { display: inline-flex; align-items: center; gap: 4px; font-weight: 500; }
.delta.up   { color: var(--status-bad); }   /* увеличение бюджета/CPA = плохо */
.delta.down { color: var(--status-good); }  /* уменьшение CPA/расхода = хорошо */
.delta.up.good   { color: var(--status-good); }
.delta.down.bad  { color: var(--status-bad); }
.delta svg { width: 12px; height: 12px; }

/* === Двухколоночные графики === */
.col-2 {
  display: grid;
  gap: 22px;
  grid-template-columns: 1fr 1fr;
}
@media (max-width: 980px) { .col-2 { grid-template-columns: 1fr; } }

.chart-card { padding: 22px 24px; }
.chart-card .title-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.chart-card .title {
  font-weight: 600; font-size: 16px; color: var(--ink-strong); letter-spacing: -0.015em;
}
.chart-wrap { position: relative; height: 280px; }

/* === Источники === */
.sources-grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 28px;
  align-items: start;
}
@media (max-width: 880px) { .sources-grid { grid-template-columns: 1fr; } }
.sources-list { display: flex; flex-direction: column; gap: 1px; }
.source-row {
  display: grid;
  grid-template-columns: 28px 1fr auto auto;
  gap: 14px;
  align-items: center;
  padding: 14px 16px;
  border-radius: var(--r-md);
  background: var(--cream);
  border: 1px solid transparent;
  transition: background .15s ease, border-color .15s ease;
  cursor: pointer;
}
.source-row:hover { background: var(--card-a); border-color: var(--gold-line); }
.source-row .icon-wrap {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(193,154,91,0.15), rgba(230,194,133,0.15));
  color: var(--gold-3);
}
.source-row .icon-wrap svg { width: 14px; height: 14px; }
.source-row .name {
  font-size: 14px;
  color: var(--ink-strong);
  font-weight: 500;
}
.source-row .name .meta {
  display: block; font-size: 11px; color: var(--ink-mute); font-family: var(--font-mono);
  margin-top: 2px; letter-spacing: 0.02em;
}
.source-row .count {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 16px;
  color: var(--ink-strong);
}
.source-row .pct {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--gold-3);
  padding: 2px 8px;
  background: rgba(193,154,91,0.12);
  border-radius: 999px;
  letter-spacing: 0.02em;
}

/* === Воронка === */
.funnel-bars { display: flex; flex-direction: column; gap: 10px; }
.funnel-bar {
  display: grid;
  grid-template-columns: 1fr 60px 64px auto;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  border-radius: var(--r-md);
  background: var(--cream);
  border: 1px solid var(--gold-line);
  position: relative;
  overflow: hidden;
}
.funnel-ai-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  font-family: var(--font-sans);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: linear-gradient(135deg, var(--gold-2) 0%, var(--gold-1) 100%);
  border: 1px solid var(--gold-3);
  border-radius: var(--r-sm);
  color: var(--dark-a);
  cursor: pointer;
  transition: filter .15s ease, transform .1s ease;
}
.funnel-ai-btn:hover { filter: brightness(1.08); }
.funnel-ai-btn:active { transform: translateY(1px); }
.funnel-ai-btn svg { width: 11px; height: 11px; }
.funnel-bar .fill {
  position: absolute; inset: 0;
  background: linear-gradient(90deg, rgba(193,154,91,0.18) 0%, rgba(193,154,91,0.04) 100%);
  z-index: 0;
}
.funnel-bar.qualified .fill { background: linear-gradient(90deg, rgba(107,127,77,0.22) 0%, rgba(107,127,77,0.04) 100%); }
.funnel-bar.in_work   .fill { background: linear-gradient(90deg, rgba(193,154,91,0.22) 0%, rgba(193,154,91,0.04) 100%); }
.funnel-bar.rejected  .fill { background: linear-gradient(90deg, rgba(176,122,26,0.22) 0%, rgba(176,122,26,0.04) 100%); }
.funnel-bar.junk      .fill { background: linear-gradient(90deg, rgba(142,62,62,0.22) 0%, rgba(142,62,62,0.04) 100%); }
.funnel-bar > * { position: relative; z-index: 1; }
.funnel-bar .label {
  font-size: 14px;
  color: var(--ink-strong);
  font-weight: 500;
  display: flex; align-items: center; gap: 10px;
}
.funnel-bar .label svg { width: 14px; height: 14px; color: var(--gold-3); }
.funnel-bar .count { font-family: var(--font-mono); font-weight: 700; color: var(--ink-strong); }
.funnel-bar .share { font-family: var(--font-mono); font-size: 11px; color: var(--ink-mute); }
.direct-breakdown {
  display: flex; gap: 24px; justify-content: center;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink-mute);
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--gold-line);
}
.direct-breakdown .item { display: flex; align-items: center; gap: 8px; }
.direct-breakdown .item svg { width: 14px; height: 14px; color: var(--gold-3); }
.direct-breakdown .num { color: var(--ink-strong); font-weight: 700; }

/* === Master vs EPK === */
.dual-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
}
@media (max-width: 880px) { .dual-grid { grid-template-columns: 1fr; } }
.kind-card { padding: 30px; }
.kind-card .title {
  font-size: 22px;
  font-weight: 600;
  color: var(--ink-strong);
  letter-spacing: -0.02em;
  margin: 0;
}
.kind-card .ad-count {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-mute);
  margin-top: 4px;
  letter-spacing: 0.04em;
}
.kind-window {
  display: flex; flex-direction: column; gap: 4px;
  padding: 18px 0;
  border-top: 1px solid var(--gold-line);
}
.kind-window:first-of-type { border-top: 1px solid var(--gold-line); margin-top: 18px; }
.kind-window .window-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.20em;
  text-transform: uppercase;
  color: var(--gold-3);
}
.kind-window .stats-line {
  display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap;
  margin-top: 6px;
}
.kind-window .big {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 24px;
  color: var(--ink-strong);
  letter-spacing: -0.02em;
}
.kind-window .pair {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink-mute);
}
.kind-card .archived-note {
  margin-top: 16px;
  padding: 12px 14px;
  background: rgba(176, 122, 26, 0.08);
  border: 1px solid rgba(176, 122, 26, 0.20);
  border-radius: var(--r-sm);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--status-warn);
  display: flex; align-items: center; gap: 8px;
}
.kind-card .archived-note svg { width: 14px; height: 14px; }

/* === Таблица групп === */
.table-toolbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 16px;
  background: var(--card-a);
  border: 1px solid var(--gold-line);
  border-radius: var(--r-md);
  margin-bottom: 14px;
}
.toolbar-input {
  flex: 1;
  min-width: 200px;
  border: 1px solid var(--gold-line);
  background: var(--cream);
  color: var(--ink-strong);
  padding: 8px 12px;
  border-radius: var(--r-sm);
  font-family: var(--font-sans);
  font-size: 13px;
  outline: none;
}
.toolbar-input:focus { border-color: var(--gold-3); }
.toolbar-cb {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
}
.toolbar-cb input { accent-color: var(--gold-3); }

.table-wrap {
  background: linear-gradient(135deg, var(--card-a) 0%, var(--card-b) 100%);
  border: 1px solid var(--gold-line);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.groups-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.groups-table th {
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-mute);
  text-align: left;
  padding: 14px 12px;
  border-bottom: 1px solid var(--gold-line);
  background: rgba(245, 235, 215, 0.4);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.groups-table th:hover { color: var(--gold-3); }
.groups-table th.sorted { color: var(--gold-3); }
.groups-table th.num { text-align: right; }
.groups-table td {
  padding: 14px 12px;
  border-bottom: 1px solid rgba(193, 154, 91, 0.14);
  vertical-align: middle;
  font-family: var(--font-mono);
  color: var(--ink-strong);
}
.groups-table td.num { text-align: right; }
.groups-table tr:last-child td { border-bottom: 0; }
.groups-table tr:hover td { background: rgba(255, 252, 245, 0.55); }
.groups-table .group-cell {
  font-family: var(--font-sans);
  white-space: normal;
  max-width: 360px;
}
.groups-table .group-cell .top { font-weight: 500; color: var(--ink-strong); }
.groups-table .group-cell .bot { display: block; font-size: 11px; color: var(--ink-mute); font-family: var(--font-mono); margin-top: 3px; letter-spacing: 0.02em; }
.row-marker { display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-right: 8px; vertical-align: middle; }
tr.cat-top .row-marker { background: var(--status-good); box-shadow: 0 0 0 3px rgba(107,127,77,0.18); }
tr.cat-mid .row-marker { background: var(--status-warn); box-shadow: 0 0 0 3px rgba(176,122,26,0.18); }
tr.cat-bottom .row-marker { background: var(--status-bad); box-shadow: 0 0 0 3px rgba(142,62,62,0.18); }
tr.cat-silent .row-marker { background: var(--ink-mute); box-shadow: 0 0 0 3px rgba(122,106,86,0.12); }

/* === Drill-down tables (Avito items / VK campaigns) === */
.drill-table { font-size: 13px; }
.drill-table td { white-space: nowrap; }
.drill-table .item-cell {
  font-family: var(--font-sans);
  white-space: normal;
  max-width: 360px;
}
.drill-table .item-cell .top {
  display: flex; align-items: center; gap: 8px;
  font-weight: 500;
  color: var(--ink-strong);
  line-height: 1.3;
}
.drill-table .item-cell .bot {
  display: block;
  font-size: 11px;
  color: var(--ink-mute);
  font-family: var(--font-mono);
  margin-top: 3px;
  letter-spacing: 0.02em;
}
.drill-table .row-marker { display: inline-block; width: 6px; height: 6px; border-radius: 50%; vertical-align: middle; flex: 0 0 6px; }
.drill-table tr.cat-top .row-marker { background: var(--status-good); box-shadow: 0 0 0 3px rgba(107,127,77,0.18); }
.drill-table tr.cat-mid .row-marker { background: var(--status-warn); box-shadow: 0 0 0 3px rgba(176,122,26,0.18); }
.drill-table tr.cat-bottom .row-marker { background: var(--status-bad); box-shadow: 0 0 0 3px rgba(142,62,62,0.18); }
.drill-table tr.cat-silent .row-marker { background: var(--ink-mute); box-shadow: 0 0 0 3px rgba(122,106,86,0.12); }

.drill-table tr.row-status-blocked,
.drill-table tr.row-status-stopped {
  opacity: 0.55;
  filter: saturate(0.5);
}

.cell-positive { color: var(--gold-3); font-weight: 700; }
.cell-zero { color: var(--ink-mute); }

.status-pill {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(193, 154, 91, 0.12);
  color: var(--gold-3);
  border: 1px solid var(--gold-line);
  white-space: nowrap;
}
.status-pill.status-active   { color: var(--status-good); background: rgba(107,127,77,0.10); border-color: rgba(107,127,77,0.32); }
.status-pill.status-paused   { color: var(--status-warn); background: rgba(176,122,26,0.10); border-color: rgba(176,122,26,0.32); }
.status-pill.status-stopped,
.status-pill.status-blocked  { color: var(--ink-mute); background: rgba(122,106,86,0.10); border-color: rgba(122,106,86,0.28); }

/* === Buttons === */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 13px;
  padding: 8px 16px;
  border-radius: var(--r-sm);
  border: 0;
  cursor: pointer;
  transition: all .2s ease;
  text-decoration: none;
  user-select: none;
}
.btn svg { width: 14px; height: 14px; }
.btn-gold {
  background: linear-gradient(135deg, var(--gold-1) 0%, var(--gold-2) 50%, var(--gold-3) 100%);
  color: var(--dark-a);
  box-shadow: 0 4px 12px rgba(193, 154, 91, 0.30);
}
.btn-gold:hover { transform: translateY(-1px); box-shadow: 0 8px 18px rgba(193, 154, 91, 0.40); }
.btn-outline-gold {
  background: transparent;
  color: var(--gold-3);
  border: 1px solid var(--gold-line-strong);
}
.btn-outline-gold:hover { background: rgba(193, 154, 91, 0.10); }
.btn-link {
  background: transparent;
  color: var(--gold-3);
  padding: 4px 0;
  font-weight: 500;
}
.btn-link:hover { color: var(--gold-1); }

/* === Архивные === */
.archive-section { padding: 28px 0; }
details.collapse { padding: 0; }
details.collapse summary {
  list-style: none;
  cursor: pointer;
  display: flex; align-items: center; gap: 14px;
  padding: 18px 22px;
  background: rgba(245, 235, 215, 0.35);
  border: 1px solid var(--gold-line);
  border-radius: var(--r-md);
  font-weight: 500;
  color: var(--ink-strong);
  transition: background .2s ease;
}
details.collapse summary:hover { background: rgba(245, 235, 215, 0.55); }
details.collapse summary::-webkit-details-marker { display: none; }
details.collapse summary .arrow { transition: transform .2s ease; margin-left: auto; color: var(--gold-3); }
details.collapse[open] summary .arrow { transform: rotate(180deg); }
.archive-list { padding: 14px 0; display: flex; flex-direction: column; gap: 8px; }
.archive-item {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 16px;
  align-items: center;
  padding: 14px 20px;
  background: var(--cream);
  border: 1px solid var(--gold-line);
  border-radius: var(--r-sm);
}
.archive-item .ad-id { font-family: var(--font-mono); font-weight: 700; color: var(--ink-strong); }
.archive-item .leads-count { font-family: var(--font-mono); color: var(--gold-3); }
.archive-item .dates { font-family: var(--font-mono); font-size: 12px; color: var(--ink-mute); }

/* === Footer === */
.appfoot {
  padding: 36px 0 48px;
  margin-top: 32px;
  border-top: 1px solid var(--gold-line);
  font-size: 12px;
  color: var(--ink-mute);
  display: flex; align-items: center; justify-content: space-between; gap: 18px; flex-wrap: wrap;
  font-family: var(--font-mono);
}

/* === Toast / Banner === */
.banner {
  padding: 12px 20px;
  background: rgba(176, 122, 26, 0.10);
  border: 1px solid rgba(176, 122, 26, 0.25);
  color: var(--status-warn);
  font-size: 13px;
  text-align: center;
}
.banner-onboarding {
  margin: 60px auto;
  max-width: 720px;
  padding: 40px;
  background: linear-gradient(135deg, var(--card-a) 0%, var(--card-b) 100%);
  border: 1px solid var(--gold-line);
  border-radius: var(--r-xl);
  text-align: center;
  box-shadow: var(--shadow-md);
}
.banner-onboarding h2 { color: var(--ink-strong); font-weight: 600; letter-spacing: -0.02em; margin: 0 0 12px; }
.banner-onboarding p { color: var(--ink-mute); margin: 0 0 18px; line-height: 1.55; }

/* === Loader === */
.loader {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--gold-line);
  border-top-color: var(--gold-3);
  border-radius: 50%;
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Доступность === */
:focus-visible { outline: 2px solid var(--gold-3); outline-offset: 2px; }

/* === Блок «Эффективность» — мини-строка под hero ===
   Не дублирует hero-карточки визуально: компактная table-row 4×1 с
   ровными колонками, золотыми числами на кремовом фоне, без больших
   градиентов. */
.efficiency-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-top: 16px;
  padding: 14px 18px;
  background: var(--cream);
  border: 1px solid var(--gold-line);
  border-radius: var(--r-md);
  align-items: center;
}
@media (max-width: 980px) { .efficiency-row { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .efficiency-row { grid-template-columns: 1fr; } }

.efficiency-cell {
  display: flex; flex-direction: column; gap: 4px;
  padding: 6px 8px;
  border-right: 1px solid var(--gold-line);
}
.efficiency-cell:last-child { border-right: 0; }
@media (max-width: 980px) {
  .efficiency-cell:nth-child(2) { border-right: 0; }
  .efficiency-cell:nth-child(3) { border-right: 1px solid var(--gold-line); }
}
@media (max-width: 520px) {
  .efficiency-cell { border-right: 0; border-bottom: 1px solid var(--gold-line); padding-bottom: 10px; }
  .efficiency-cell:last-child { border-bottom: 0; }
}

.efficiency-cell .ef-label {
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-mute);
  display: flex; align-items: center; gap: 6px;
}
.efficiency-cell .ef-label svg { width: 12px; height: 12px; color: var(--gold-3); }
.efficiency-cell .ef-value {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 18px;
  color: var(--ink-strong);
  letter-spacing: -0.01em;
}
.efficiency-cell .ef-value.t-gold {
  background: linear-gradient(135deg, var(--gold-1) 0%, var(--gold-2) 50%, var(--gold-3) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* === Маркетинговый бюджет: вторая строка под efficiency-row ===
   Три ячейки (Реклама / Прочие / Всего) + кнопка-шестерёнка. */
.budget-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1.15fr auto;
  gap: 14px;
  margin-top: 12px;
  padding: 14px 18px;
  background: var(--cream);
  border: 1px solid var(--gold-line);
  border-radius: var(--r-md);
  align-items: center;
}
@media (max-width: 980px) {
  .budget-row { grid-template-columns: 1fr 1fr; }
  .budget-row .budget-cell--total { grid-column: 1 / -1; border-top: 1px solid var(--gold-line); padding-top: 12px; }
  .budget-row .budget-settings { grid-column: 1 / -1; justify-self: end; }
}
@media (max-width: 520px) {
  .budget-row { grid-template-columns: 1fr; }
  .budget-row .budget-cell--total { grid-column: 1; }
}

.budget-cell {
  display: flex; flex-direction: column; gap: 4px;
  padding: 6px 8px;
  border-right: 1px solid var(--gold-line);
}
.budget-row > .budget-cell:nth-last-child(2) { border-right: 0; }
.budget-cell--total {
  background: rgba(218, 165, 32, 0.04);
  border-radius: var(--r-sm);
  padding-left: 12px; padding-right: 12px;
}

.budget-cell .ef-label {
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-mute);
  display: flex; align-items: center; gap: 6px;
}
.budget-cell .ef-label svg { width: 12px; height: 12px; color: var(--gold-3); }
.budget-cell .ef-value {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 18px;
  color: var(--ink-strong);
  letter-spacing: -0.01em;
}
.budget-cell .ef-value.t-gold {
  background: linear-gradient(135deg, var(--gold-1) 0%, var(--gold-2) 50%, var(--gold-3) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.budget-cell .budget-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-mute);
  min-height: 14px;
}

.budget-settings {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 12px;
  border: 1px solid var(--gold-line);
  border-radius: var(--r-sm);
  background: #fff;
  color: var(--ink-strong);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}
.budget-settings:hover { background: var(--cream-deep); border-color: var(--gold-3); }
.budget-settings svg { width: 14px; height: 14px; color: var(--gold-3); }

/* === AI-карточка (саммари/анализ) === */
.ai-card {
  margin-top: 16px;
  background: linear-gradient(135deg, #fff 0%, var(--cream) 100%);
  border: 1px solid var(--gold-line);
  border-radius: var(--r-md);
  overflow: hidden;
  position: relative;
}
.ai-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 4px; height: 100%;
  background: linear-gradient(180deg, var(--gold-1) 0%, var(--gold-3) 100%);
}
.ai-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 14px 22px;
  border-bottom: 1px solid var(--gold-line);
  gap: 12px;
  flex-wrap: wrap;
}
.ai-card-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-strong);
}
.ai-card-title svg { width: 14px; height: 14px; color: var(--gold-3); }
.ai-card-actions { display: inline-flex; gap: 8px; align-items: center; }

.ai-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--dark-a);
  background: linear-gradient(135deg, var(--gold-2) 0%, var(--gold-1) 100%);
  border: 1px solid var(--gold-3);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: filter .15s ease, transform .1s ease;
}
.ai-btn:hover { filter: brightness(1.05); }
.ai-btn:active { transform: translateY(1px); }
.ai-btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.ai-btn-ghost {
  background: transparent;
  color: var(--ink-mute);
  border-color: var(--gold-line);
  padding: 6px 10px;
}
.ai-btn-ghost:hover { background: var(--cream-deep); border-color: var(--gold-3); color: var(--ink-strong); }

.ai-card-body {
  padding: 16px 22px;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
}
.ai-card-body h3, .ai-card-body h4 {
  margin: 14px 0 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-strong);
  letter-spacing: -0.005em;
}
.ai-card-body h3:first-child, .ai-card-body h4:first-child { margin-top: 0; }
.ai-card-body ul { margin: 4px 0 8px 0; padding-left: 22px; }
.ai-card-body li { margin: 3px 0; }
.ai-card-body p { margin: 6px 0; }
.ai-card-body strong { color: var(--ink-strong); }
.ai-card-body code {
  font-family: var(--font-mono);
  font-size: 12.5px;
  background: var(--cream-deep);
  padding: 1px 5px;
  border-radius: 3px;
}

.ai-empty {
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink-mute);
  text-align: center;
  padding: 18px 12px;
}

.ai-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--gold-line);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-mute);
}
.ai-meta-item { display: inline-flex; align-items: center; gap: 4px; }
.ai-meta-cached { color: var(--status-good); }

/* AI-thinking — мини-progress внутри карточки (для AI-кнопок) */
.ai-thinking {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 8px 0;
}
.ai-thinking > span {
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--ink-strong);
  font-weight: 600;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
}
/* Без эмодзи (брендбук). Пульсирующая золотая точка вместо мозга. */
.ai-thinking > span::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gold-3, #b8923a);
  animation: ai-pulse 1.5s ease-in-out infinite;
}
@keyframes ai-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(1.15); opacity: 0.7; }
}
.ai-thinking::after {
  content: '';
  display: block;
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg,
    var(--gold-line) 0%,
    var(--gold-2) 25%,
    var(--gold-3) 50%,
    var(--gold-2) 75%,
    var(--gold-line) 100%);
  background-size: 200% 100%;
  animation: ai-progress-flow 1.6s linear infinite;
}
@keyframes ai-progress-flow {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.ai-error {
  padding: 12px 14px;
  background: rgba(142, 62, 62, 0.05);
  border: 1px solid rgba(142, 62, 62, 0.20);
  border-radius: var(--r-sm);
  color: var(--status-bad);
  font-size: 13px;
}

/* === AI-модалка (универсальная для S2/S3/S4/S5) === */
.ai-modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(28, 32, 35, 0.55);
  display: flex; align-items: flex-start; justify-content: center;
  z-index: 200; padding: 40px 16px;
  overflow-y: auto;
}
.ai-modal-backdrop[hidden] { display: none; }
.ai-modal {
  background: #fff;
  border-radius: var(--r-lg);
  max-width: 720px; width: 100%;
  box-shadow: 0 24px 64px rgba(0,0,0,0.25);
  border: 1px solid var(--gold-line);
  overflow: hidden;
  position: relative;
}
.ai-modal::before {
  content: '';
  position: absolute; top: 0; left: 0;
  width: 4px; height: 100%;
  background: linear-gradient(180deg, var(--gold-1) 0%, var(--gold-3) 100%);
}
.ai-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px 16px 26px;
  border-bottom: 1px solid var(--gold-line);
  gap: 14px;
}
.ai-modal-title {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 auto;
  min-width: 0;
}
.ai-modal-title svg {
  width: 18px; height: 18px;
  color: var(--gold-3);
  flex-shrink: 0;
}
.ai-modal-title h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink-strong);
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ai-modal-title .sub {
  font-size: 12px;
  color: var(--ink-mute);
  font-family: var(--font-mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ai-modal-actions { display: inline-flex; gap: 6px; flex-shrink: 0; }

.ai-modal-context {
  padding: 12px 22px 12px 26px;
  background: var(--cream);
  border-bottom: 1px solid var(--gold-line);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-mute);
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
}
.ai-modal-context .ai-ctx-item { display: inline-flex; align-items: center; gap: 4px; }
.ai-modal-context .ai-ctx-item strong { color: var(--ink); font-weight: 600; }

.ai-modal-body {
  padding: 22px 26px;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink);
  max-height: 65vh;
  overflow-y: auto;
}
.ai-modal-body h3, .ai-modal-body h4 {
  margin: 14px 0 6px;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ink-strong);
}
.ai-modal-body h3:first-child, .ai-modal-body h4:first-child { margin-top: 0; }
.ai-modal-body ul, .ai-modal-body ol { margin: 4px 0 8px 0; padding-left: 22px; }
.ai-modal-body li { margin: 3px 0; }
.ai-modal-body p { margin: 6px 0; }
.ai-modal-body code {
  font-family: var(--font-mono);
  font-size: 12.5px;
  background: var(--cream-deep);
  padding: 1px 5px;
  border-radius: 3px;
}

/* Блок «Исходные данные что AI увидел» — для верификации цифр */
.ai-source {
  margin-top: 16px;
  padding: 10px 14px;
  background: var(--cream);
  border: 1px solid var(--gold-line);
  border-radius: var(--r-sm);
}
.ai-source > summary {
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-mute);
  user-select: none;
  padding: 2px 0;
}
.ai-source > summary::marker { color: var(--gold-3); }
.ai-source > summary:hover { color: var(--ink-strong); }
.ai-source[open] > summary { color: var(--ink-strong); margin-bottom: 8px; border-bottom: 1px dashed var(--gold-line); padding-bottom: 8px; }
.ai-source-data {
  margin: 0;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--gold-line);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 320px;
  overflow-y: auto;
}

/* Маленькая AI-кнопка для строк таблиц */
.ai-row-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  font-family: var(--font-sans);
  font-size: 11.5px;
  font-weight: 600;
  background: transparent;
  border: 1px solid var(--gold-line);
  border-radius: var(--r-sm);
  color: var(--ink-mute);
  cursor: pointer;
  transition: all .15s ease;
}
.ai-row-btn:hover {
  background: var(--gold-glow);
  border-color: var(--gold-3);
  color: var(--ink-strong);
}
.ai-row-btn svg { width: 11px; height: 11px; }

/* Бейдж «с НДС» рядом с лейблами расхода — скромный, золотой, в стиле брендбука.
   Чтобы было однозначно понятно что все суммы расхода включают НДС. */
/* Разбивка расхода «реклама + специалист» — две выровненные строки под суммой. */
.cost-split {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 220px;
}
.cost-split .cs-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  font-size: 12px;
  line-height: 1.5;
}
.cost-split .cs-lbl { color: var(--ink-mute, #8a8278); }
.cost-split .cs-val {
  color: var(--ink-strong, #2a2a2a);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

/* Разбивка лидов: качественные (золото) · спам (приглушённый). */
.lead-split { font-size: 12px; color: var(--ink-mute, #8a8278); }
.lead-split .ls-good { color: var(--gold-3, #b8893a); font-weight: 600; }
.lead-split .ls-junk { color: var(--ink-mute, #8a8278); font-weight: 600; }

/* Договора в таблице кампаний — золотое выделение (это деньги). */
.deal-num { color: var(--gold-3, #b8893a); font-weight: 700; }

/* Вкладка, где пользователю нельзя видеть суммы (класс no-money на .tab-content):
   прячем денежные блоки целиком (графики расхода/CPA, маркетинговый бюджет).
   Точечные рубли при этом отдаются как «—» (money() в formatters.js). */
.no-money .is-money { display: none !important; }

.vat-badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--gold-3, #b8893a);
  background: var(--gold-glow, rgba(184,137,58,0.10));
  border: 1px solid var(--gold-2, rgba(184,137,58,0.30));
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: 5px;
  vertical-align: middle;
  white-space: nowrap;
}

/* Сегментированный переключатель метрики (диаграмма тренда Я.Директа). */
.metric-seg {
  display: inline-flex;
  gap: 3px;
  margin-bottom: 16px;
  padding: 3px;
  background: var(--cream-2);
  border: 1px solid var(--gold-line);
  border-radius: var(--r-sm);
}
.metric-seg button {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.01em;
  padding: 6px 14px;
  border: none;
  background: transparent;
  color: var(--ink-mute);
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}
.metric-seg button:hover:not(.is-active) { color: var(--ink); background: var(--gold-glow); }
.metric-seg button.is-active {
  background: var(--gold-1);
  color: var(--dark-a);
  font-weight: 600;
}
@media (max-width: 560px) {
  .metric-seg { display: flex; width: 100%; }
  .metric-seg button { flex: 1; padding: 6px 6px; font-size: 11px; }
}
