/* --- 1. Переменные и Глобальные стили --- */
:root {
  /* Палитра светлой темы */
  --bg: hsl(220, 16%, 96%);
  --card-bg: hsl(0, 0%, 100%);
  --border: hsl(210, 14%, 89%);
  --accent: hsl(224, 83%, 53%);
  --bg: hsl(220, 16%, 96%);
  /* Modern design tokens (2025) */
  --surface: hsl(0 0% 100% / 0.9);
  --glass: rgba(255, 255, 255, 0.6);
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 6px;
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --container-max: 1400px;
  --accent-text: hsl(0, 0%, 100%);
  --text-main: hsl(222, 47%, 11%);
  --text-muted: hsl(215, 9%, 47%);
  --danger: hsl(0, 72%, 51%);
  --danger-text: hsl(0, 0%, 100%);
  --header-bg: hsl(222, 47%, 11%);
  --header-text: hsl(210, 40%, 98%);
  --table-header-bg: hsl(220, 16%, 98%);
  --skeleton-from: hsl(210, 15%, 80%);
  --skeleton-to: hsl(210, 15%, 95%);
  --delta-pos: #16a34a;

  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  
  /* ============================================================================
     NEW PORTAL DESIGN TOKENS (from portal-styles.css)
     ============================================================================ */
  /* Dark Mode Only - Surface Colors */
  --bg-surface-dark: #18232e;
  --bg-card-dark: #101922;

  /* Primary Brand Color */
  --primary: #2b8cee;
  --primary-light: rgba(43, 140, 238, 0.1);
  --primary-muted: rgba(43, 140, 238, 0.3);

  /* Text Colors (Dark Mode) */
  --text-primary: #f9fafb;
  --text-secondary: #e5e7eb;
  --text-tertiary: #9ca3af;

  /* Spacing Scale */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-12: 3rem;

  /* Rating Table Design Tokens (from динамика_рентабельности_по_кустам_html_график.html) */
  --bg-body-rating: radial-gradient(circle at 0 0, #101729 0, #050816 40%, #050816 100%);
  --card-bg-rating: rgba(12, 17, 35, 0.86);
  --card-border-rating: rgba(255, 255, 255, 0.06);
  --accent-rating: #4f8bff;
  --accent-soft-rating: rgba(79, 139, 255, 0.18);
  --accent-strong-rating: #7c5cff;
  --text-main-rating: #f7f9ff;
  --text-muted-rating: #99a1c4;
  --text-soft-rating: #626a8c;
  --danger-rating: #ff6b81;
  --success-rating: #23d997;
  --warning-rating: #f9b24e;
  --radius-card-rating: 24px;
  --radius-pill-rating: 999px;
  --shadow-soft-rating: 0 18px 60px rgba(0, 0, 0, 0.55);
  --blur-glass-rating: 22px;
  --transition-fast-rating: 160ms ease-out;

  /* Border Radius */
  --radius-xl: 1rem;
  --radius-2xl: 1.25rem;

  /* Typography */
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.25rem;
  --font-size-2xl: 1.5rem;

  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;

  /* Line Heights */
  --line-height-tight: 1.25;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.75;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Применяем слой для принудительной тёмной темы */
html.theme-dark {
  /* Dark-mode tokens — keep these as variables so the rest of the stylesheet can remain unchanged */
  --bg: hsl(222, 20%, 13%);
  --card-bg: hsl(220, 20%, 18%);
  --border: hsl(215, 14%, 34%);
  --accent: hsl(224, 83%, 65%);
  --accent-soft: hsl(224, 83%, 20%);
  --text-main: hsl(210, 40%, 96%);
  --text-muted: hsl(215, 12%, 63%);
  --danger: hsl(0, 82%, 61%);
  --table-header-bg: hsl(222, 20%, 22%);
  --skeleton-from: hsl(215, 14%, 34%);
  --skeleton-to: hsl(220, 13%, 40%);
  --delta-pos: #4ade80;
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--card-bg) 95%, #000 5%),
    var(--card-bg)
  );
}

/* Применяем системную тёмную тему, если устройство предпочитает dark-mode */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: hsl(222, 20%, 13%);
    --card-bg: hsl(220, 20%, 18%);
    --border: hsl(215, 14%, 34%);
    --accent: hsl(224, 83%, 65%);
    --accent-soft: hsl(224, 83%, 20%);
    --text-main: hsl(210, 40%, 96%);
    --text-muted: hsl(215, 12%, 63%);
    --header-bg: hsl(220, 20%, 18%);
    --header-text: hsl(210, 40%, 98%);
    --table-header-bg: hsl(222, 20%, 22%);
    --skeleton-from: hsl(215, 14%, 34%);
    --skeleton-to: hsl(220, 13%, 40%);
    --delta-pos: #4ade80;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

/* --- 2. Основная структура (Shell) --- */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  padding: calc(var(--space-md) / 2) var(--space-lg);
  background: var(--header-bg);
  color: var(--header-text);
  box-shadow: var(--shadow-md);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  flex-wrap: wrap;
}

.header-left {
  flex-shrink: 0;
}

header .title {
  font-size: clamp(1.125rem, 3vw, 1.5rem);
  font-weight: 700;
}

header .subtitle {
  font-size: 0.75rem;
  color: #9ca3af;
}

header .header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto; /* Прижимаем всю правую часть вправо */
}

.theme-switcher {
  display: flex;
  align-items: center;
  background-color: var(--header-bg);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 2px;
}

.theme-switcher input[type="radio"] {
  display: none;
}

.theme-switcher label {
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 99px;
  color: var(--text-muted);
  transition:
    color 0.2s,
    background-color 0.2s;
  font-size: 12px;
  line-height: 1;
}

.theme-switcher label:hover {
  color: var(--header-text);
}

.theme-switcher input[type="radio"]:checked + label {
  background-color: var(--accent);
  color: var(--accent-text);
  box-shadow: var(--shadow);
}

html.theme-dark .theme-switcher {
  border-color: hsl(215, 14%, 44%);
}

html.theme-dark .theme-switcher input[type="radio"]:checked + label {
  background-color: var(--accent);
  color: var(--header-bg);
}

.nav {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-left: 1.5rem;
}
.source-controls-left {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  width: 48px; /* Фиксированная ширина для выравнивания */
}
.source-status {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.6875rem; /* 11px */
  margin-top: 0.25rem;
  color: var(--text-muted);
  flex-direction: column;
}

.source-status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--text-muted); /* По умолчанию серый (не проверено) */
  flex-shrink: 0;
}

.source-status-indicator.loading {
  background-color: var(--accent);
  animation: pulse 1.5s infinite;
}

.source-status-indicator.success {
  background-color: var(--delta-pos);
}

.source-status-indicator.error {
  background-color: var(--danger);
}

@keyframes pulse {
  0% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
  100% {
    opacity: 1;
  }
}

/* Стили для таблицы с примерами данных в настройках */
.sample-data-table {
  width: 100%;
  margin-top: 0.75rem;
  border: 1px solid var(--border);
  font-size: 11px;
  border-collapse: collapse;
}
.sample-data-table th,
.sample-data-table td {
  padding: 4px 6px;
  border: 1px solid var(--border);
  text-align: left;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sample-data-table th {
  background-color: var(--table-header-bg);
}
.nav-btn {
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 6px 12px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: #e5e7eb;
  transition: all 150ms ease-in-out;
}

.nav-btn.active {
  background: linear-gradient(
    90deg,
    color-mix(in srgb, var(--accent) 70%, rgba(255, 255, 255, 0%)),
    var(--accent)
  );
  border-color: var(--accent);
  color: #f9fafb;
}

.nav-btn:not(.active):hover {
  background: hsl(220, 20%, 25%);
}

.nav-dropdown {
  position: relative;
  display: inline-block;
}

.nav-dropdown-content {
  display: none;
  position: absolute;
  background-color: var(--header-bg);
  min-width: 160px;
  box-shadow: var(--shadow-md);
  z-index: 1;
  border-radius: 0.5rem;
  overflow: hidden;
}

.nav-dropdown-content a {
  color: var(--header-text);
  padding: 12px 16px;
  text-decoration: none;
  display: block;
  font-size: 0.875rem;
}
.nav-dropdown-content a:hover {
  background-color: hsl(220, 20%, 25%);
}
.nav-dropdown:hover .nav-dropdown-content {
  display: block;
}

main {
  padding: 1rem 1.5rem 1.5rem;
  flex: 1;
}
.source-icon[title="Тип: gsheet"] {
  color: #0f9d58; /* Зеленый цвет Google Sheets */
}
.page {
  display: none;
}

.page.active {
  display: block;
}

/* --- 3. Компоненты --- */

/* Card */
.card {
  background: var(--card-bg);
  border-radius: 0.75rem;
  padding: 1rem 1rem 0.75rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  border: 1px solid var(--border);
  transition: box-shadow 150ms ease-in-out;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.card-title {
  font-size: 0.875rem;
  font-weight: 600;
}

.card-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.card-header-top {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

/* Button */
.btn {
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 6px 12px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  background: var(--bg);
  transition: all 150ms ease-in-out;
  color: var(--text-main);
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.btn-primary:hover:not(:disabled) {
  background: hsl(224, 83%, 48%);
  box-shadow: var(--shadow-md);
}
html.theme-dark .btn-primary:hover:not(:disabled) {
  background: hsl(224, 83%, 70%);
}

.btn-outline {
  background: transparent;
  border-color: var(--border);
  color: var(--text-main);
}
.btn-outline:hover:not(:disabled) {
  background: var(--accent-soft);
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--danger-text);
}

.btn-danger:hover:not(:disabled) {
  background: hsl(0, 72%, 41%);
}
html.theme-dark .btn-danger:hover:not(:disabled) {
  background: hsl(0, 82%, 66%);
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
  box-shadow: none;
}

.btn-icon {
  padding: 6px;
  width: 28px;
  height: 28px;
  justify-content: center;
}

/* Sources UI additions */
.source-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.source-left {
  display: flex;
  gap: 12px;
  align-items: center;
}
.source-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}
.sync-source-btn {
  background: var(--accent-soft);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 6px 10px;
  border-radius: 6px;
}
.sync-source-btn:hover {
  background: var(--accent);
  color: var(--accent-text);
}

/* Visual polish for source cards */
.source-card {
  padding: 14px 16px;
  border-radius: 12px;
  background: linear-gradient(
    180deg,
    var(--card-bg),
    color-mix(in srgb, var(--card-bg) 90%, #000 10%)
  );
  border: 1px solid var(--border);
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    border-color 160ms ease;
}
.source-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 10px 30px rgba(2, 6, 23, 0.12);
  border-color: color-mix(in srgb, var(--accent) 18%, var(--border));
}
/* Inline sync error UI */
.source-sync-error {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--danger) 6%, var(--card-bg) 94%),
    color-mix(in srgb, var(--card-bg) 96%, #000 4%)
  );
  border: 1px solid color-mix(in srgb, var(--danger) 70%, var(--border) 30%);
  color: var(--danger-text);
  display: block;
}
.source-sync-error .error-summary {
  font-weight: 700;
  margin-bottom: 8px;
}
.source-sync-error .error-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.source-sync-error .error-details {
  width: 100%;
  max-height: 160px;
  overflow: auto;
  background: rgba(0, 0, 0, 0.04);
  padding: 8px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--text-main);
  white-space: pre-wrap;
}
.source-name {
  font-weight: 700;
  font-size: 0.95rem;
}
.source-details code {
  background: transparent;
  padding: 2px 6px;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, "Roboto Mono", "Courier New", monospace;
  font-size: 0.82rem;
  color: var(--text-muted);
}
.source-icon {
  font-size: 22px;
  color: var(--accent);
}

/* Dark theme tweaks for cards */
html.theme-dark .source-card {
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--card-bg) 95%, #000 5%),
    var(--card-bg)
  );
}

/* Form & Input */
form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.75rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

label span {
  color: var(--text-muted);
}

input,
select {
  padding: 0.375rem 0.5rem;
  font-size: 0.75rem;
  border-radius: 0.375rem;
  border: 1px solid var(--border);
  outline: none;
  background-color: var(--card-bg);
  color: var(--text-main);
}

input:focus-visible,
select:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 0.125rem var(--accent-soft);
  outline: 2px solid transparent;
}

.input-hint {
  font-size: 0.6875rem; /* 11px */
  color: var(--text-muted);
  margin-top: 0.25rem;
  line-height: 1.4;
}

.form-buttons {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

/* Table */
table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.75rem;
}

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 0.375rem 0.5rem;
  text-align: left;
  white-space: nowrap;
}

th {
  background: var(--table-header-bg);
  font-weight: 500;
  color: var(--text-muted);
  user-select: none;
}

th.sortable {
  cursor: pointer;
}

th.sortable:hover {
  background: var(--accent-soft);
  transition: background-color 150ms ease-in-out;
  color: var(--accent);
}

th .sort-indicator {
  font-size: 0.625rem;
  margin-left: 0.125rem;
  opacity: 0.7;
}

th.draggable {
  cursor: move;
}

tbody tr:hover {
  background: var(--accent-soft);
  transition: background-color 150ms ease-in-out;
  cursor: pointer;
}

.row-selected {
  background: var(--accent-soft) !important;
}

.logo-cell img {
  max-height: 1.5rem;
  max-width: 3.75rem;
  object-fit: contain;
  display: block;
}

/* Other Components */
.toolbar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.status {
  font-size: 0.6875rem;
  margin-top: 0.25rem;
  min-height: 0.875rem;
  color: var(--accent);
}

.status.success {
  color: var(--delta-pos);
}

.status.error {
  color: var(--danger);
}

code {
  font-family:
    ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New",
    monospace;
  font-size: 0.75rem;
  background: var(--header-bg);
  color: #e5e7eb;
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
}

/* --- 4. Стили страниц --- */

/* Общая разметка для страниц с колонками */
.layout {
  display: flex;
  width: 100%;
  gap: 1.5rem;
  /* Keep entire layout within viewport height for single-screen UX (accounts for header + wizard) */
  height: calc(100vh - 260px);
  overflow: hidden; /* children scroll internally */
}

/* make card children fill available height inside bm-layout so inner wrappers can scroll */
.bm-layout > .card {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.bm-layout > .card > .bm-grid-wrapper {
  flex: 1 1 auto;
  min-height: 0; /* allow the wrapper to shrink and overflow properly */
}

.layout-left {
  flex: 2;
  min-width: 0;
}

.layout-right {
  flex: 1.2;
  min-width: 17.5rem;
}

/* Страница "Обложка" */
.overview-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  gap: 1rem;
}

.overview-section-title {
  font-size: 0.8125rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.overview-list {
  font-size: 0.75rem;
  color: var(--text-muted);
  padding-left: 1rem;
}

.overview-list li {
  margin-bottom: 4px;
}

.overview-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  background: var(--header-bg);
  color: #e5e7eb;
  font-size: 0.6875rem;
  margin-right: 0.25rem;
}

.hashtag {
  display: inline-flex;
  align-items: center;
  padding: 5px 12px;
  border-radius: 16px;
  background-color: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
  margin: 0 4px;
  border: 1px solid transparent;
  transition: all 0.2s ease-in-out;
}
.hashtag:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
}
.hashtag i {
  margin-right: 8px;
}

/* Страница "Справочник" */
.columns-config {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.6875rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.columns-config label {
  flex-direction: row;
  align-items: center;
  gap: 0.25rem;
  cursor: pointer;
}

.table-wrapper {
  overflow: auto;
  max-height: 70vh; /* Высота подбирается по месту */
  margin-top: 8px;
}

.table-wrapper th {
  position: sticky;
  top: 0;
}

.columns-config input[type="checkbox"] {
  margin: 0;
  accent-color: var(--accent);
}

.embed-placeholder {
  padding: 1rem;
  font-size: 0.75rem;
  color: #9ca3af;
}

header .header-summary {
  display: flex;
  gap: 0.25rem 0.75rem; /* row-gap, column-gap */
  flex-wrap: wrap;
  justify-content: flex-end; /* Выравниваем элементы по правому краю */
  font-size: 0.6875rem; /* 11px */
  color: #9ca3af;
}

/* --- Модальное окно --- */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-content {
  background: var(--card-bg);
  border-radius: 0.75rem;
  padding: 1rem;
  box-shadow: var(--shadow-md);
  max-width: 90%;
  max-height: 90%;
  overflow-y: auto;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.modal-content .card-header {
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.5rem;
}

.modal-content .card-title {
  font-size: 1rem;
}

.modal-content .modal-body {
  flex-grow: 1;
  overflow-y: auto;
  padding-right: 0.5rem; /* Для скроллбара */
}

.modal-tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border);
  flex-grow: 1;
}

.modal-tab-btn {
  padding: 0.5rem 1rem;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px; /* Чтобы нижняя граница перекрывала общую */
}

.modal-tab-btn.active {
  color: var(--text-main);
  font-weight: 600;
  border-bottom-color: var(--accent);
}

.modal-tab-panel:not(.active) {
  display: none;
}

/* Панель настроек (всплывающая) */
.bm-settings-panel {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
}
.bm-settings-panel.visible {
  display: none !important;
}

/* Страница "Настройки" (общие стили) */
.settings-group {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}
.settings-radio {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}
.settings-radio input[type="radio"] {
  accent-color: var(--accent);
}
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem;
}
.settings-grid.settings-grid-metrics {
  grid-template-columns: 1fr auto;
}
.settings-grid .has-fallback {
  color: var(--text-muted);
}

.settings-footer {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* --- 5. Утилиты и Анимации --- */

/* Skeleton Loader */
.skeleton {
  opacity: 0.7;
  animation: skeleton-loading 1s linear infinite alternate;
}

.skeleton-text {
  width: 100%;
  height: 0.75rem;
  margin-bottom: 0.5rem;
  border-radius: 0.25rem;
}

.skeleton-text:last-child {
  margin-bottom: 0;
  width: 80%;
}

@keyframes skeleton-loading {
  from {
    background-color: var(--skeleton-from);
  }
  to {
    background-color: var(--skeleton-to);
  }
}

/* --- 6. Адаптивность (Media Queries) --- */

@media (max-width: 960px) {
  main {
    padding: 12px 12px 16px;
  }

  .layout {
    flex-direction: column;
  }

  .layout-right {
    order: -1;
  }

  .overview-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Toast notifications */
.toast-container {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 1200;
  max-width: calc(100% - 2rem);
}
.toast {
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 10px 14px;
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: 220px;
  max-width: 420px;
}
.toast.info {
  border-left: 4px solid var(--accent);
}
.toast.success {
  border-left: 4px solid var(--delta-pos);
}
.toast.error {
  border-left: 4px solid var(--danger);
}
.toast .toast-msg {
  flex: 1;
  font-size: 0.875rem;
}
.toast .toast-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
}

@media (max-width: 640px) {
  header {
    padding: 1rem 1rem 0.5rem;
  }
  main {
    padding: 0.75rem;
  }
  .header-top {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* --- 7. Стили для страницы "Бизнес-модель" --- */

.bm-controls-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
  padding: 0.75rem 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.bm-control-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
}

.bm-control-group-right {
  margin-left: auto;
}

.bm-controls-panel .inline-label {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.bm-sources-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem 1rem 1rem;
  background: var(--card-bg);
  box-shadow: var(--shadow-sm);
  margin: 0 1rem 1rem;
}

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

.bm-sources-summary {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.bm-source-group-title {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.bm-source-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.bm-source-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
  background: var(--bg-muted);
  border: 1px dashed var(--border);
  color: var(--text-main);
  font-size: 0.85rem;
}

.bm-source-badge i {
  color: var(--accent);
}

.bm-layout {
  display: grid;
  /* Для ноутбуков: фиксированный двухколоночный макет ~60/40; правый столбец имеет разумные пределы */
  grid-template-columns: 60% minmax(300px, 40%);
  gap: 1.5rem;
  align-items: flex-start;
}

.bm-panel-right {
  /* Теперь это card, основные стили в style.css */
  position: sticky;
  top: 1rem;
  max-height: 100%;
  overflow: auto;
}

.bm-panel-right-inner {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.bm-grid-wrapper {
  overflow: auto;
  /* Left panel should scroll internally so the overall page stays single-screen. */
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* Ensure table stretches inside the scrollable wrapper */
.bm-grid-wrapper table {
  width: 100%;
}

#bm-grid {
  font-size: 13px;
}

#bm-grid th,
#bm-grid td {
  padding: 8px 10px;
}
#bm-grid th {
  position: sticky;
  top: 0;
  background-color: var(--table-header-bg); /* Убедимся, что фон есть */
}

#bm-grid .col-frozen {
  position: sticky;
  left: 0;
  background: var(--card-bg);
  z-index: 1;
}

#bm-grid th.col-frozen {
  z-index: 2;
}

#bm-grid tr.group-header {
  background-color: var(--table-header-bg);
  font-weight: 600;
  cursor: pointer;
  position: sticky;
  top: 35px; /* Высота основного заголовка */
  z-index: 1;
}
#bm-grid tr.group-header:hover {
  background-color: var(--accent-soft);
}
#bm-grid tr.group-header i {
  margin-right: 8px;
  width: 12px;
}

#bm-chart-container {
  position: relative;
  min-height: 250px;
  max-height: 400px;
  height: 30vh;
}

#bm-grid .editable {
  background-color: var(--accent-soft);
  cursor: cell;
  outline: none;
  border: 1px solid transparent;
}

#bm-grid .editable:focus {
  background-color: var(--card-bg);
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

#bm-grid .delta-pos {
  color: var(--delta-pos);
}
#bm-grid .delta-neg {
  color: var(--danger);
}

.bm-summary,
.bm-alerts {
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.bm-summary-item {
  display: flex;
  justify-content: space-between;
}
.bm-summary-label {
  color: var(--text-muted);
}
.bm-summary-value {
  font-weight: 600;
}

@media (max-width: 1200px) {
  .bm-layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .bm-panel-right {
    position: static;
  }
}

/* --- Страница INFO: Документация --- */
.doc-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  transition: all 0.2s ease;
}

.doc-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.doc-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.doc-header i {
  font-size: 1.5rem;
  color: var(--accent);
}

.doc-header h3 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--text-main);
}

.doc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.doc-list li {
  margin: 0;
}

.doc-list a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  transition: all 0.2s ease;
}

.doc-list a:hover {
  color: var(--accent);
  text-decoration: underline;
  transform: translateX(4px);
}

.page-content {
  max-width: 1400px;
  margin: 0 auto;
}

/* === Wizard & Calendar UI Polish === */
.bm-wizard-steps .wizard-step-btn {
  background: transparent;
  border: 1px solid transparent;
  padding: 8px 12px;
  border-radius: 999px;
  font-weight: 600;
  color: var(--text-muted);
}

/* Step containers: keep within viewport and scroll content internally */
#bm-wizard-step-1, #bm-wizard-step-2 {
  max-height: calc(100vh - 300px);
  overflow: auto;
}

#bm-wizard-step-2 .card {
  display: flex;
  flex-direction: column;
}

#bm-wizard-step-2 .bm-grid-wrapper,
#bm-wizard-step-2 .card .bm-grid-wrapper {
  max-height: 320px;
  overflow: auto;
}
.bm-wizard-steps .wizard-step-btn.active {
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 80%, rgba(255,255,255,0%)), var(--accent));
  color: var(--accent-text);
  box-shadow: 0 6px 18px rgba(2,6,23,0.12);
}
.bm-wizard-steps .wizard-step-btn:hover { transform: translateY(-2px); }

.bm-wizard-nav {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
}
.bm-wizard-nav .btn {
  padding: 8px 14px;
}

#bm-calendar-config { background: var(--card-bg); padding: 12px; border-radius: 10px; border: 1px solid var(--border); }
#bm-calendar-config textarea { border: 1px dashed var(--border); padding: 8px; border-radius: 6px; resize: vertical; }
#bm-calendar-config .bm-weekend-checkbox { width: 16px; height: 16px; accent-color: var(--accent); }

#bm-status-bar { padding: 10px 12px; background: linear-gradient(180deg, color-mix(in srgb, var(--card-bg) 96%, var(--accent) 4%), var(--card-bg)); border-radius: 10px; border: 1px solid var(--border); }
#bm-status-message { font-size: 0.9rem; color: var(--text-muted); }

#bm-download-ready.btn-ready { border-color: var(--accent); color: var(--accent); background: transparent; }

/* === Wizard v1.8 Styles === */

/* Wizard card and header */
.wizard-card {
  padding: 1.5rem;
  margin-top: 1rem;
}

.wizard-header {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.wizard-intro {
  text-align: center;
}

.wizard-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 0.5rem 0;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

.wizard-title i {
  color: var(--accent);
}

.wizard-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 0;
}

/* Wizard steps with step numbers and labels */
.bm-wizard-steps {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  flex-wrap: wrap;
}

.wizard-step-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 1.5rem;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  border-radius: 12px;
  min-width: 140px;
}

.wizard-step-btn .step-number {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--table-header-bg);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
  transition: all 0.2s ease;
  border: 2px solid var(--border);
}

.wizard-step-btn .step-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
  transition: color 0.2s ease;
  text-align: center;
}

.wizard-step-btn:hover {
  background: var(--accent-soft);
}

.wizard-step-btn:hover .step-number {
  border-color: var(--accent);
  color: var(--accent);
}

.wizard-step-btn.active .step-number {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
  box-shadow: 0 4px 12px hsla(224, 83%, 53%, 0.3);
}

.wizard-step-btn.active .step-label {
  color: var(--text-main);
  font-weight: 600;
}

.wizard-step-btn.completed .step-number {
  background: var(--delta-pos);
  color: white;
  border-color: var(--delta-pos);
}

.wizard-step-btn.completed .step-number::after {
  content: '✓';
  position: absolute;
  font-size: 1.2rem;
}

.wizard-step-connector {
  width: 60px;
  height: 2px;
  background: var(--border);
  flex-shrink: 0;
}

/* Wizard progress bar */
#bm-wizard-progress {
  margin-top: 1rem;
  height: 6px;
  background: var(--table-header-bg);
  border-radius: 6px;
  overflow: hidden;
}

#bm-wizard-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), hsl(224, 83%, 65%));
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 6px;
}

/* Wizard navigation */
.bm-wizard-nav {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
}

/* Wizard step content */
.wizard-step-content {
  margin-top: 1.5rem;
  animation: wizardFadeIn 0.3s ease;
}

@keyframes wizardFadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.wizard-step-layout {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 1.5rem;
  align-items: start;
}

.wizard-step-card {
  padding: 1.5rem;
}

.wizard-step-summary {
  position: sticky;
  top: 1rem;
}

/* Wizard forms */
.wizard-form {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.form-section {
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.form-section:last-of-type {
  border-bottom: none;
  padding-bottom: 0;
}

.section-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-main);
  margin: 0 0 1rem 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.section-title i {
  color: var(--accent);
  font-size: 0.9rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

.form-grid-2 {
  grid-template-columns: 1fr 1fr;
}

.form-grid-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.field-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-main);
}

.field-input {
  padding: 0.625rem 0.875rem;
  font-size: 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text-main);
  transition: all 0.2s ease;
}

.field-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  outline: none;
}

.field-hint {
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Sources panel */
.sources-panel, .sources-summary {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.source-slot {
  padding: 0.75rem;
  background: var(--table-header-bg);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.source-slot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.source-slot-label {
  font-weight: 600;
  font-size: 0.85rem;
}

.source-select {
  width: 100%;
  padding: 0.5rem;
  font-size: 0.8rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text-main);
  margin-top: 0.5rem;
}

.source-info {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.source-info.muted {
  font-style: italic;
}

/* Model level display */
.model-level-display {
  padding: 1rem;
}

.model-level-badge {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem;
  background: var(--accent-soft);
  border: 2px solid var(--accent);
  border-radius: 12px;
  width: 100%;
  text-align: center;
}

.level-number {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
}

.level-label {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-main);
}

.level-desc {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
}

/* Coverage stats */
.coverage-stat {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.coverage-stat:last-child {
  border-bottom: none;
}

.coverage-label {
  color: var(--text-muted);
}

.coverage-value {
  font-weight: 600;
  color: var(--text-main);
}

/* Preview sections */
.preview-section {
  margin-bottom: 1rem;
}

.preview-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: var(--table-header-bg);
  border-radius: 8px;
  margin-bottom: 0.5rem;
}

.preview-item.highlight {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
}

.preview-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.preview-value {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
}

.preview-item.highlight .preview-value {
  color: var(--accent);
}

/* Project bars table */
.project-bars-container {
  overflow-x: auto;
  max-height: 400px;
  overflow-y: auto;
}

.project-bars-table {
  width: 100%;
  font-size: 0.75rem;
  border-collapse: collapse;
}

.project-bars-table th,
.project-bars-table td {
  padding: 0.5rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.project-bars-table th {
  background: var(--table-header-bg);
  position: sticky;
  top: 0;
  z-index: 1;
}

/* Loading states */
.summary-loading {
  padding: 2rem;
  text-align: center;
  color: var(--text-muted);
}

.summary-loading i {
  margin-right: 0.5rem;
}

/* Responsive */
@media (max-width: 1024px) {
  .wizard-step-layout {
    grid-template-columns: 1fr;
  }
  
  .wizard-step-summary {
    position: static;
  }
  
  .wizard-step-connector {
    display: none;
  }
  
  .bm-wizard-steps {
    gap: 0.5rem;
  }
  
  .wizard-step-btn {
    padding: 0.75rem 1rem;
    min-width: auto;
  }
  
  .form-grid-2, .form-grid-3 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .wizard-step-btn .step-label {
    font-size: 0.7rem;
  }
  
  .wizard-step-btn .step-number {
    width: 32px;
    height: 32px;
    font-size: 0.9rem;
  }
  
  .bm-wizard-nav {
    flex-direction: column;
    align-items: stretch;
  }
  
  .bm-wizard-nav .btn {
    width: 100%;
  }
}

/* ============================================================================
   NEW PORTAL DESIGN STYLES (from portal-styles.css)
   ============================================================================ */

/* Material Symbols Icon Font Settings */
.material-symbols-outlined {
  font-family: 'Material Symbols Outlined';
  font-weight: normal;
  font-style: normal;
  font-size: 24px;
  display: inline-block;
  line-height: 1;
  text-transform: none;
  letter-spacing: normal;
  word-wrap: normal;
  white-space: nowrap;
  direction: ltr;
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
  -webkit-font-smoothing: antialiased;
}

/* Surface & Card Colors (Dark Mode) */
.bg-surface {
  background-color: var(--bg-surface-dark);
}

.bg-card {
  background-color: var(--bg-card-dark);
}

/* Sidebar Styles */
#sidebar {
  transition: all var(--transition-base);
}

#sidebar-toggle {
  transition: all var(--transition-fast);
}

#sidebar-toggle:hover {
  transform: scale(1.05);
}

#sidebar-toggle:active {
  transform: scale(0.95);
}

/* Navigation Link Active State */
.nav-link-active,
.nav-btn.active {
  background-color: rgba(55, 65, 81, 0.9);
  color: #f9fafb;
}

.directory-tab-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  color: inherit;
}

.directory-tab-btn.active {
  color: #f9fafb;
  border-color: var(--primary);
}

/* Layout Utilities */
.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Typography Utilities */
.text-display {
  font-family: 'Inter', 'Helvetica Neue', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.label-sm {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideInDown {
  from {
    transform: translateY(-10px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.animate-fade-in {
  animation: fadeIn 300ms ease-in-out;
}

.animate-slide-in-down {
  animation: slideInDown 300ms ease-in-out;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background-color: var(--bg-surface-dark);
}

::-webkit-scrollbar-thumb {
  background-color: #475569;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background-color: #64748b;
}

/* Utility Classes */
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.backdrop-blur {
  backdrop-filter: blur(10px);
}

/* Responsive Helpers */
@media (max-width: 768px) {
  .hide-mobile {
    display: none;
  }
}

@media (min-width: 769px) {
  .hide-desktop {
    display: none;
  }
}

/* --- Источники: единый композер и маппинг --- */
.source-composer {
  border: 1px solid #273141;
  border-radius: 12px;
  padding: 16px;
  background: #111826;
  margin-bottom: 16px;
}

.composer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px 16px;
}

.composer-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
}

.composer-field input,
.composer-field select {
  background: #0c1422;
  border: 1px solid #2d3a4f;
  border-radius: 8px;
  padding: 10px 12px;
  color: #e5e7eb;
}

.composer-field small.input-hint {
  color: #9ca3af;
}

.composer-field-full {
  grid-column: 1 / -1;
}

.composer-inline {
  display: flex;
  gap: 8px;
}

.composer-inline input {
  flex: 1;
}

.composer-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.composer-actions-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.mapping-summary {
  color: #9ca3af;
  font-size: 12px;
}

.mapping-modal {
  max-width: 960px;
  width: 92%;
  background: #0c1422;
  border-radius: 12px;
  border: 1px solid #273141;
}

.mapping-body {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 16px;
  padding: 12px 16px 0 16px;
}

.mapping-block-title {
  font-size: 12px;
  color: #9ca3af;
  margin-bottom: 6px;
}

.columns-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  background: #0f1a2a;
  padding: 12px;
  border-radius: 10px;
  min-height: 64px;
  border: 1px solid #1f2a3c;
}

.column-chip {
  background: #1b2535;
  border: 1px solid #2d3a4f;
  border-radius: 999px;
  padding: 6px 12px;
  color: #e5e7eb;
  font-size: 12px;
  cursor: grab;
  user-select: none;
}

.column-chip.selected,
.column-token.selected {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
  background: rgba(59, 130, 246, 0.15);
}

.target-drop:focus,
.target-drop:hover {
  border-color: #3b82f6;
  outline: none;
}

.target-drop.ready-to-drop {
  border-color: #10b981;
  background: rgba(16, 185, 129, 0.1);
}

.mapping-targets {
  background: #0f1a2a;
  border: 1px solid #1f2a3c;
  border-radius: 10px;
  padding: 12px;
}

.mapping-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid #1f2a3c;
}

.mapping-row:last-child {
  border-bottom: none;
}

.field-label {
  color: #e5e7eb;
  font-size: 13px;
  flex: 1;
}

.field-dropzone {
  min-width: 140px;
  min-height: 36px;
  padding: 8px 10px;
  background: #111b2b;
  border: 1px dashed #2d3a4f;
  border-radius: 8px;
  color: #cbd5e1;
  font-size: 12px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.field-dropzone:hover {
  border-color: #3b82f6;
  background: rgba(59, 130, 246, 0.1);
}

/* ============================================================================
   RATING TABLE STYLES (Dashboard Page)
   Адаптированы из динамика_рентабельности_по_кустам_html_график.html
   ============================================================================ */

.rating-shell-wrapper {
  width: 100%;
}

.rating-shell {
  width: 100%;
  margin: 0 auto;
  background: radial-gradient(circle at 0 0, rgba(79, 139, 255, 0.24), transparent 55%),
    radial-gradient(circle at 100% 100%, rgba(124, 92, 255, 0.18), transparent 55%);
  border-radius: 32px;
  padding: 1.5px;
  box-shadow: var(--shadow-soft-rating);
  position: relative;
  overflow: hidden;
}

.rating-shell::before {
  content: "";
  position: absolute;
  inset: -40%;
  background: conic-gradient(
    from 140deg,
    rgba(79, 139, 255, 0.15),
    rgba(124, 92, 255, 0.22),
    rgba(35, 217, 151, 0.2),
    rgba(79, 139, 255, 0.15)
  );
  opacity: 0.4;
  filter: blur(40px);
  z-index: -1;
}

.rating-panel {
  background: linear-gradient(145deg, rgba(9, 12, 28, 0.98), rgba(4, 6, 18, 0.98));
  border-radius: 30px;
  padding: 24px 22px 18px;
  border: 1px solid rgba(255, 255, 255, 0.03);
  backdrop-filter: blur(var(--blur-glass-rating));
}

/* HEADER */

.rating-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.rating-header .header-left h1 {
  font-size: 1.4rem;
  letter-spacing: 0.02em;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.rating-header .header-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted-rating);
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.rating-header .header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* TAGS / META */

.tag-period {
  padding: 4px 9px;
  border-radius: var(--radius-pill-rating);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.04);
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-muted-rating);
}

.trend-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: var(--radius-pill-rating);
  background: rgba(35, 217, 151, 0.08);
  color: var(--success-rating);
  font-size: 0.74rem;
}

.trend-pill .icon {
  font-size: 0.9rem;
}

.divider-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  border-radius: 16px;
  padding: 10px 12px;
  background: radial-gradient(circle at 0 0, rgba(79, 139, 255, 0.16), transparent 60%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.02), rgba(9, 14, 40, 0.9));
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.divider-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.divider-meta span {
  font-size: 0.76rem;
  color: var(--text-muted-rating);
}

.divider-meta span b {
  color: var(--text-main-rating);
  font-weight: 500;
}

.divider-meta .divider-dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  margin-inline: 8px;
}

.divider-meta .right-meta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* CHIPS / TOOLBAR */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: var(--radius-pill-rating);
  border: 1px solid rgba(255, 255, 255, 0.04);
  background: rgba(255, 255, 255, 0.02);
  color: var(--text-muted-rating);
  font-size: 0.78rem;
  cursor: default;
  white-space: nowrap;
}

.chip strong {
  color: var(--text-main-rating);
  font-weight: 500;
}

.chip-select {
  cursor: pointer;
}

.chip-select::after {
  content: "▾";
  font-size: 0.7rem;
  color: var(--text-soft-rating);
  margin-left: 4px;
  display: inline-block;
}

.chip-primary {
  border-color: rgba(79, 139, 255, 0.7);
  background: radial-gradient(circle at 0 0, rgba(79, 139, 255, 0.2), rgba(124, 92, 255, 0.05));
  color: #dbe4ff;
}

.chip-primary strong {
  color: #ffffff;
}

.chip-ghost {
  border-style: dashed;
  opacity: 0.9;
  cursor: pointer;
}

.chip-toggle {
  cursor: pointer;
  transition: all var(--transition-fast-rating);
}

.chip-toggle.is-active {
  border-color: rgba(79, 139, 255, 0.7);
  background: radial-gradient(circle at 0 0, rgba(79, 139, 255, 0.2), rgba(124, 92, 255, 0.05));
  color: #dbe4ff;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  flex-wrap: wrap;
  width: 100%;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex: 1 0 auto;
}

.toolbar-delta {
  display: inline-flex;
  gap: 4px;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.dash-tabs {
  display: inline-flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.dash-tab {
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.02);
  color: var(--text-muted-rating);
  font-weight: 600;
  transition: all var(--transition-fast-rating);
}

.dash-tab:hover {
  border-color: rgba(79, 139, 255, 0.5);
  color: #dbe4ff;
}

.dash-tab.is-active {
  background: linear-gradient(120deg, rgba(79, 139, 255, 0.18), rgba(124, 92, 255, 0.16));
  border-color: rgba(79, 139, 255, 0.6);
  color: #fff;
  box-shadow: 0 8px 28px rgba(79, 139, 255, 0.15);
}

.dash-tab-panel {
  display: none;
  width: 100%;
}

.dash-tab-panel.is-active {
  display: block;
}

.placeholder-card {
  border: 1px dashed rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.02);
}

.search-shell {
  margin-left: auto;
  flex: 1 0 200px;
  max-width: 260px;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  padding: 0 12px;
  transition: border-color 0.2s, background 0.2s;
}

.search-box:focus-within {
  border-color: rgba(79, 139, 255, 0.4);
  background: rgba(79, 139, 255, 0.05);
}

.search-box .icon {
  font-size: 0.9rem;
  color: var(--text-soft-rating);
  margin-right: 6px;
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 7px 0;
  border: none;
  background: transparent;
  color: var(--text-main-rating);
  font-size: 0.78rem;
  outline: none;
}

.search-input:focus {
  color: var(--text-main-rating);
}

.search-input::placeholder {
  color: var(--text-soft-rating);
}

.scope-wrapper {
  position: relative;
  display: inline-block;
}

.scope-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 180px;
  padding: 6px;
  border-radius: 14px;
  background: radial-gradient(circle at 0 0, rgba(79, 139, 255, 0.22), transparent 60%),
    rgba(6, 8, 22, 0.98);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.7);
  z-index: 20;
}

.scope-menu.concept-menu {
  min-width: 160px;
}

.scope-option {
  width: 100%;
  text-align: left;
  padding: 6px 8px;
  border-radius: 10px;
  background: transparent;
  border: none;
  color: var(--text-muted-rating);
  font-size: 0.76rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.scope-option:hover {
  background: rgba(79, 139, 255, 0.12);
  color: var(--text-main-rating);
}

.scope-option.is-active {
  background: rgba(79, 139, 255, 0.22);
  color: var(--text-main-rating);
}

.scope-option .scope-badge {
  font-size: 0.64rem;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-soft-rating);
}

.inline-dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: inline-block;
}

/* METRIC TOGGLE */

.metric-toggle {
  display: inline-flex;
  padding: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  gap: 4px;
}

.metric-tab {
  border: none;
  background: transparent;
  color: var(--text-muted-rating);
  font-size: 0.78rem;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: background var(--transition-fast-rating), color var(--transition-fast-rating);
}

.metric-tab.is-active {
  background: radial-gradient(circle at 0 0, rgba(79, 139, 255, 0.4), rgba(124, 92, 255, 0.2));
  color: var(--text-main-rating);
}

/* LIST HEADER */

.list-head {
  margin-top: 2px;
  padding: 4px 12px 2px;
  display: grid;
  grid-template-columns: auto minmax(0, 1.7fr) minmax(0, 1.0fr) auto 80px;
  gap: 8px;
  font-size: 0.7rem;
  color: var(--text-soft-rating);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.list-head span:nth-child(3),
.list-head span:nth-child(4),
.list-head span:nth-child(5) {
  text-align: right;
}

/* ROWS */

.leaderboard {
  margin-top: 6px;
  display: grid;
  gap: 8px;
  list-style: none;
}

.bar-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1.7fr) minmax(0, 0.9fr) minmax(0, 0.9fr) 104px;
  align-items: center;
  gap: 10px;
  padding: 5px 12px;
  border-radius: 18px;
  background: rgba(10, 13, 30, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.04);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(14px);
  transition: transform var(--transition-fast-rating), box-shadow var(--transition-fast-rating),
    border-color var(--transition-fast-rating), background var(--transition-fast-rating);
  position: relative;
  overflow: hidden;
}

.bar-row::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, rgba(79, 139, 255, 0.16), transparent 40%);
  opacity: 0;
  transition: opacity var(--transition-fast-rating);
  pointer-events: none;
}

.bar-row:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.88);
  border-color: rgba(79, 139, 255, 0.7);
}

.bar-row:hover::before {
  opacity: 1;
}

.rank-badge {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-pill-rating);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.86rem;
  font-weight: 600;
  background: radial-gradient(circle at 30% 0, #ffffff, #f2c76e);
  color: #111218;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.18), 0 6px 18px rgba(0, 0, 0, 0.6);
}

.rank-badge.top-2 {
  background: radial-gradient(circle at 30% 0, #ffffff, #c3d2ff);
}

.rank-badge.top-3 {
  background: radial-gradient(circle at 30% 0, #ffffff, #ffd2c0);
}

.rank-badge.default {
  background: radial-gradient(circle at 30% 0, #f4f5fb, #cacfe6);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.45);
}

.bar-info {
  min-width: 0;
}

.bar-name {
  font-size: 0.9rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 1px;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.bar-logo-wrapper {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.03);
}

.bar-logo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.bar-logo-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted-rating);
  text-transform: uppercase;
}

.city-pill {
  font-size: 0.7rem;
  color: #c0c7f5;
  background: rgba(116, 130, 255, 0.18);
  border-radius: var(--radius-pill-rating);
  padding: 2px 8px;
}

.concept-pill {
  font-size: 0.7rem;
  color: #ffe9b8;
  background: rgba(249, 178, 78, 0.16);
  border-radius: var(--radius-pill-rating);
  padding: 2px 8px;
  white-space: nowrap;
}

.bar-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  font-size: 0.72rem;
  color: var(--text-soft-rating);
}

.bar-meta .meta-line-primary {
  color: var(--text-soft-rating);
}

.bar-meta .meta-line-secondary {
  color: var(--text-muted-rating);
}

/* METRIC BLOCKS */

.metric-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.metric-value {
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.value-label {
  margin-left: 4px;
  font-size: 0.7rem;
  color: var(--text-muted-rating);
}

.metric-baseline {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--text-soft-rating);
  flex-wrap: wrap;
}

.metric-baseline .prev-value {
  color: var(--text-soft-rating);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.metric-baseline .prev-label {
  color: var(--text-muted-rating);
}

.metric-baseline .delta-pill {
  flex-basis: 100%;
  margin-top: 2px;
}

.delta-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 500;
}

.delta-pill.up {
  background: rgba(35, 217, 151, 0.14);
  color: var(--success-rating);
}

.delta-pill.down {
  background: rgba(255, 107, 129, 0.14);
  color: var(--danger-rating);
}

.delta-pill.flat {
  background: rgba(153, 161, 196, 0.22);
  color: var(--text-soft-rating);
}

.metric-block.ytd-col {
  align-items: flex-start;
  gap: 4px;
}

.metric-block.ytd-col .metric-value .unit {
  color: var(--text-soft-rating);
  font-size: 0.7rem;
}

/* SPARKLINE */

.sparkline {
  width: 100%;
  height: 52px;
  padding: 4px 6px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: radial-gradient(circle at 0 0, rgba(79, 139, 255, 0.10), transparent 55%);
}

.sparkline svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* RESPONSIVE */

@media (max-width: 1024px) {
  .bar-row {
    grid-template-columns: auto minmax(0, 1.8fr) minmax(0, 1.1fr) 80px;
  }
  .sparkline {
    height: 40px;
  }
}

@media (max-width: 768px) {
  .rating-panel {
    padding-inline: 16px;
  }
  .bar-row {
    grid-template-columns: auto minmax(0, 2.1fr) minmax(0, 1.4fr);
  }
  .sparkline {
    display: none;
  }
  .list-head span:last-child {
    display: none;
  }
  .concept-pill {
    display: none;
  }
}

.mapping-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px 16px 16px;
}

.mapping-actions {
  display: flex;
  gap: 8px;
}

.required {
  color: #f97316;
  font-size: 12px;
}

/* ============================================================================
   PROFITABILITY BY CLUSTER WIDGET STYLES
   ============================================================================ */

.profitability-card {
  --accent-bg: rgba(147, 51, 234, 0.95);
  --accent-border: rgba(192, 132, 252, 0.9);
  --accent-text: #f5f3ff;
  --accent-glow: rgba(147, 51, 234, 0.32);

  width: 100%;
  background:
    radial-gradient(circle at top right, rgba(15, 23, 42, 0.4), transparent 55%),
    radial-gradient(circle at bottom left, var(--accent-glow), transparent 65%),
    linear-gradient(140deg, #020617, #020617);
  border-radius: 24px;
  border: 1px solid rgba(148, 163, 184, 0.45);
  transition: background 0.25s ease-out, border-color 0.25s ease-out;
}

.profitability-card .card-header,
.profitability-card .chart-wrapper,
.profitability-card .kpi-caption,
.profitability-card .kpi-carousel {
  padding-left: 1rem;
  padding-right: 1rem;
}

.profitability-card .card-header {
  padding-bottom: 8px;
  margin-bottom: 8px;
}

.profitability-card .card-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}

.profitability-card h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
  font-weight: 650;
  letter-spacing: 0.02em;
  color: #e5e7eb;
}

.metric-switch,
.view-switch,
.period-switch {
  display: inline-flex;
  align-items: center;
  background: rgba(15, 23, 42, 0.9);
  border-radius: 999px;
  padding: 2px;
  border: 1px solid rgba(55, 65, 81, 0.9);
}

.metric-btn,
.view-btn,
.period-btn {
  border: none;
  background: transparent;
  color: #9ca3af;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s ease-out, color 0.12s ease-out, transform 0.12s ease-out;
}

.metric-btn--active,
.view-btn--active,
.period-btn--active {
  background: linear-gradient(135deg, var(--accent-bg), rgba(255, 255, 255, 0.18));
  color: var(--accent-text);
  box-shadow: 0 0 0 1px var(--accent-border), 0 0 18px var(--accent-glow);
  transform: translateY(-0.5px);
}

.metric-btn:not(.metric-btn--active):hover,
.view-btn:not(.view-btn--active):hover,
.period-btn:not(.period-btn--active):hover {
  background: rgba(31, 41, 55, 0.9);
  color: #e5e7eb;
}

.header-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.profitability-body {
  padding-top: 10px;
  border-top: 1px solid rgba(31, 41, 55, 0.95);
}

.legend-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 8px;
}

.custom-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  max-width: 900px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: #e5e7eb;
  cursor: pointer;
  opacity: 0.9;
  padding: 4px 10px 4px 6px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(55, 65, 81, 0.9);
  transition: background 0.12s ease-out, opacity 0.12s ease-out, box-shadow 0.12s ease-out;
}

.legend-item:hover {
  background: rgba(31, 41, 55, 0.9);
  box-shadow: 0 0 8px rgba(55, 65, 81, 0.5);
}

.legend-item--muted {
  opacity: 0.35;
  background: rgba(15, 23, 42, 0.6);
  border-color: rgba(55, 65, 81, 0.6);
}

.legend-item--hover {
  background: rgba(31, 41, 55, 0.95);
  box-shadow: 0 0 12px rgba(55, 65, 81, 0.6);
}

.legend-dot {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  flex-shrink: 0;
  background: #020617;
  border: 2px solid rgba(148, 163, 184, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.legend-dot img {
  width: 100%;
  height: 100%;
  border-radius: 999px;
  display: block;
  object-fit: cover;
}

.legend-label {
  white-space: nowrap;
}

.chart-wrapper {
  position: relative;
  width: 100%;
  height: 322px;
  margin-top: 12px;
  max-width: 100%;
}

.chart-wrapper canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.kpi-caption {
  margin-top: 10px;
  margin-bottom: 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #9ca3af;
  opacity: 0.9;
}

.kpi-carousel {
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin-top: 4px;
}

.kpi-viewport {
  position: relative;
  flex: 1;
  overflow-x: hidden;
  overflow-y: hidden;
  scroll-behavior: smooth;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.kpi-viewport::-webkit-scrollbar {
  display: none;
}

.kpi-viewport::before,
.kpi-viewport::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 8px;
  pointer-events: none;
  z-index: 2;
}

.kpi-viewport::before {
  left: 0;
  background: linear-gradient(to right, rgba(2, 6, 23, 0.85), rgba(2, 6, 23, 0.4), transparent);
}

.kpi-viewport::after {
  right: 0;
  background: linear-gradient(to left, rgba(2, 6, 23, 0.85), rgba(2, 6, 23, 0.4), transparent);
}

.kpi-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
  flex-wrap: nowrap;
  justify-content: flex-start;
  padding: 0;
  transition: transform 260ms ease-out;
  will-change: transform;
}

.kpi-nav {
  width: 28px;
  height: auto;
  align-self: stretch;
  border-radius: 16px;
  border: 1px solid rgba(55, 65, 81, 0.9);
  background: rgba(15, 23, 42, 0.9);
  color: #9ca3af;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 14px;
  padding: 0;
  flex-shrink: 0;
  transition: background 0.12s ease-out, color 0.12s ease-out;
}

.kpi-nav:hover {
  background: rgba(31, 41, 55, 0.9);
  color: #e5e7eb;
}

.kpi-card {
  flex: 0 0 240px;
  border-radius: 16px;
  border: 1px solid rgba(55, 65, 81, 0.9);
  background: rgba(15, 23, 42, 0.6);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  transition: background 0.12s ease-out, box-shadow 0.12s ease-out, transform 0.12s ease-out;
}

.kpi-card:hover {
  background: rgba(15, 23, 42, 0.9);
  box-shadow: 0 0 0 1px var(--accent-border), 0 0 12px var(--accent-glow);
  transform: translateY(-1px);
}

.kpi-card--dimmed {
  opacity: 0.30;
  filter: grayscale(0.4) brightness(0.8);
  pointer-events: none;
}

.kpi-card--focused {
  box-shadow: 0 0 0 2px var(--accent-border), 0 0 24px var(--accent-glow);
  transform: scale(1.02);
  z-index: 10;
}

.kpi-card--hover {
  box-shadow: 0 0 0 1px var(--accent-border), 0 0 24px var(--accent-glow);
  transform: translateY(-2px);
}

.kpi-top {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  margin-bottom: 4px;
}

.kpi-dot {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  flex-shrink: 0;
  background: radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.35), transparent 55%), #020617;
  border: 2px solid rgba(148, 163, 184, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.kpi-dot img {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  display: block;
}

.kpi-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #9ca3af;
  opacity: 0.9;
}

.kpi-rank-badge {
  font-size: 9px;
  font-weight: 600;
  color: #9ca3af;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid rgba(75, 85, 99, 0.9);
  background: rgba(15, 23, 42, 0.9);
  margin-left: auto;
}

.kpi-main-row {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 10px;
  margin-top: 4px;
}

.kpi-main-left {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  flex: 0 0 auto;
}

.kpi-main-right {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  padding-left: 4px;
}

.kpi-value {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.2;
  color: #e5e7eb;
}

.kpi-delta-pill {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(148, 163, 184, 0.4);
  color: #e5e7eb;
  white-space: nowrap;
}

.kpi-delta-pill-positive {
  color: #4ade80;
  border-color: rgba(74, 222, 128, 0.5);
  background: rgba(22, 163, 74, 0.16);
}

.kpi-delta-pill-negative {
  color: #f97373;
  border-color: rgba(248, 113, 113, 0.6);
  background: rgba(127, 29, 29, 0.16);
}

.kpi-delta-pill-neutral {
  color: #9ca3af;
  border-color: rgba(148, 163, 184, 0.4);
  background: rgba(15, 23, 42, 0.4);
}

.kpi-sparkline {
  width: 100%;
  height: 38px;
  display: block;
}

@media (max-width: 900px) {
  .profitability-card {
    padding: 16px;
  }

  .chart-wrapper {
    height: 253px;
  }

  .header-controls {
    flex-direction: column;
    width: 100%;
  }
}
