/* ============================================================
   Дизайн-система портала «Александрия Петергоф»
   Стиль: Data-Dense Dashboard · светлая тема
   Палитра: navy + blue + green accent (ui-ux-pro-max)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Fira+Sans:wght@300;400;500;600;700&display=swap');

:root {
  /* Цветовые токены */
  --color-primary: #1E3A5F;
  --color-primary-600: #234870;
  --color-on-primary: #FFFFFF;
  --color-secondary: #2563EB;
  --color-accent: #059669;
  --color-accent-soft: #ECFDF5;
  --color-bg: #F8FAFC;
  --color-surface: #FFFFFF;
  --color-fg: #0F172A;
  --color-muted: #F1F5F9;
  --color-text-muted: #64748B;
  --color-border: #E4E7EB;
  --color-danger: #DC2626;
  --color-danger-soft: #FEF2F2;
  --color-warning: #B45309;
  --color-warning-soft: #FFFBEB;
  --color-ring: #2563EB;

  /* Радиусы / тени / отступы (шкала 4/8) */
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.05), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
  --color-input-border: #E2E8F0;
  --color-focus: #3B82F6;
  --sidebar-w: 248px;
}

* { box-sizing: border-box; }

html { font-size: 16px; }

body {
  margin: 0;
  font-family: 'Fira Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--color-fg);
  background: var(--color-bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 1.5rem; font-weight: 600; margin: 0 0 1rem; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; font-weight: 600; margin: 1.25rem 0 0.5rem; }
h3 { font-size: 1rem; font-weight: 600; margin: 1rem 0 0.5rem; color: var(--color-fg); }

a { color: var(--color-secondary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Каркас: сайдбар + контент ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--color-primary);
  color: var(--color-on-primary);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar__brand {
  padding: 1.25rem 1.25rem 1rem;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.01em;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.sidebar__brand small { display: block; font-weight: 400; font-size: 0.72rem; color: rgba(255,255,255,0.6); }
.sidebar__nav { padding: 0.75rem 0.6rem; flex: 1; }
.sidebar__link {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.6rem 0.8rem;
  margin-bottom: 2px;
  border-radius: var(--radius-sm);
  color: rgba(255, 255, 255, 0.82);
  font-size: 0.92rem;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
}
.sidebar__link:hover { background: rgba(255, 255, 255, 0.08); color: #fff; text-decoration: none; }
.sidebar__link.active { background: var(--color-secondary); color: #fff; }
.sidebar__link svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.9; }
.sidebar__foot {
  padding: 0.9rem 1.1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 0.82rem;
}
.sidebar__foot .who { color: rgba(255,255,255,0.95); font-weight: 500; }
.sidebar__foot .role { color: rgba(255,255,255,0.55); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; }

.content { flex: 1; min-width: 0; padding: 1.75rem 2rem; max-width: 1600px; }

/* ---------- Карточки ---------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.25rem;
}

/* ---------- Кнопки ---------- */
button, .btn {
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 500;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-primary);
  background: var(--color-primary);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease, transform 0.1s ease;
  line-height: 1.4;
}
button:hover, .btn:hover { opacity: 0.9; }
button:active, .btn:active { transform: scale(0.96); }
button:focus-visible, .btn:focus-visible,
a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--color-ring);
  outline-offset: 2px;
}
.btn-secondary {
  background: var(--color-surface);
  color: var(--color-primary);
  border-color: var(--color-border);
}
.btn-secondary:hover { background: var(--color-muted); opacity: 1; }
.btn-accent { background: var(--color-accent); border-color: var(--color-accent); }
.btn-danger { background: var(--color-danger); border-color: var(--color-danger); }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.82rem; }
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.1rem; height: 2.1rem; padding: 0; border-radius: var(--radius-sm);
}
.btn-icon svg { width: 16px; height: 16px; }
button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* кнопки-ссылки в тулбарах */
.toolbar { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; margin-bottom: 1rem; }
.toolbar form { display: inline; }

/* ---------- Вкладки-кнопки (навигация между связанными страницами модуля) ---------- */
.tabs { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1.25rem; }
.tabs a {
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: 0.88rem;
  font-weight: 500;
}
.tabs a:hover { background: var(--color-muted); color: var(--color-fg); text-decoration: none; }
.tabs a.active { background: var(--color-secondary); border-color: var(--color-secondary); color: #fff; }

/* ---------- Таблицы ---------- */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
th, td {
  text-align: left;
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}
thead th, table tr:first-child th {
  background: var(--color-muted);
  font-weight: 600;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--color-text-muted);
  white-space: nowrap;
}
tbody tr:hover, table tr:hover { background: #fafcff; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* Один общий скролл страницы, без вложенного скролла таблицы. table-layout:
   fixed + процентные <col> ширины гарантируют, что таблица никогда не
   вылезает за контейнер — горизонтальный скролл не нужен в принципе.
   Шапка "прилипает" к верху окна при обычном скролле страницы. */
.table-scroll { border-radius: var(--radius-sm); }
.table-scroll thead th, .table-scroll table tr:first-child th {
  position: sticky; top: 0; z-index: 1;
}
.table-comfortable { table-layout: fixed; }
.table-comfortable th, .table-comfortable td { padding: 0.45rem 0.6rem; font-size: 0.85rem; }
.table-comfortable tbody tr:hover { background: var(--color-muted); }
.nowrap { white-space: nowrap; }
.col-date { white-space: nowrap; font-variant-numeric: tabular-nums; }
/* Ширину столбца задаёт <col> в colgroup (table-layout:fixed) — здесь только
   обрезаем длинный текст многоточием в её пределах; полный текст по наведению
   (title). */
.col-clip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 0; }

/* ---------- Формы ---------- */
label { font-size: 0.9rem; font-weight: 500; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=tel], input[type=date], input[type=month], select, textarea {
  font-family: inherit;
  font-size: 0.92rem;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--color-input-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-fg);
  max-width: 100%;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--color-focus);
  outline: none;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}
textarea { resize: vertical; }
.field { margin-bottom: 0.9rem; }
.field label { display: block; margin-bottom: 0.35rem; font-weight: 500; color: var(--color-fg); }

/* ---------- Сетка формы (2-3 колонки, лейблы над полями) ---------- */
.form-section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem 1.4rem;
  margin-bottom: 1.1rem;
}
.form-section h3 { margin: 0 0 1rem; font-size: 0.95rem; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.9rem 1.1rem;
  align-items: start;
}
.form-grid .field { margin-bottom: 0; }
.form-grid input, .form-grid select, .form-grid textarea { width: 100%; }
.form-grid .field--wide { grid-column: 1 / -1; }

/* ---------- Панель фильтров над таблицей ---------- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
  background: var(--color-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  margin-bottom: 1.1rem;
}
.filter-bar .field { margin-bottom: 0; }
.filter-bar .field label { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.02em; color: var(--color-text-muted); }
.filter-bar input, .filter-bar select { background: var(--color-surface); }

/* ---------- Поисковая строка (лупа внутри поля) ---------- */
.search-box { position: relative; flex: 1; min-width: 220px; }
.search-box svg {
  position: absolute; left: 0.9rem; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; color: var(--color-text-muted); pointer-events: none;
}
.search-box input { width: 100%; padding-left: 2.6rem; }

/* ---------- Бейджи / статусы ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.6;
}
.badge-ok { background: var(--color-accent-soft); color: var(--color-accent); }
.badge-warn { background: var(--color-warning-soft); color: var(--color-warning); }
.badge-danger { background: var(--color-danger-soft); color: var(--color-danger); }
.badge-muted { background: var(--color-muted); color: var(--color-text-muted); }

.text-muted { color: var(--color-text-muted); }
.text-danger { color: var(--color-danger); }
.text-accent { color: var(--color-accent); }
.hint { font-size: 0.82rem; color: var(--color-text-muted); }

/* алерты */
.alert { padding: 0.7rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; font-size: 0.9rem; }
.alert-danger { background: var(--color-danger-soft); color: var(--color-danger); border: 1px solid #fecaca; }
.alert-warn { background: var(--color-warning-soft); color: var(--color-warning); border: 1px solid #fde68a; }

/* строка-приоритет в таблицах уборки */
tr.prio td { background: var(--color-warning-soft); }

/* пустое состояние */
.empty { color: var(--color-text-muted); font-style: italic; padding: 1rem 0; }

/* ---------- Дашборд ---------- */
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.metric {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius); padding: 1rem 1.2rem; box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 0.15rem;
}
.metric__icon { width: 20px; height: 20px; color: var(--color-secondary); margin-bottom: 0.3rem; }
.metric__value { font-size: 1.7rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.metric__label { font-size: 0.82rem; color: var(--color-text-muted); }
.metric--accent .metric__value { color: var(--color-accent); }
.metric--danger .metric__value { color: var(--color-danger); }

.dash-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1.25rem; align-items: start; }
@media (max-width: 980px) { .dash-grid { grid-template-columns: 1fr; } }

/* bullet-график KPI (производительность vs цель) */
.bullet-row { display: grid; grid-template-columns: 150px 1fr 70px; align-items: center; gap: 0.7rem; margin-bottom: 0.55rem; font-size: 0.88rem; }
.bullet-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bullet {
  position: relative; height: 20px; border-radius: 4px;
  background: linear-gradient(to right, #FFCDD2 0 60%, #FFF9C4 60% 80%, #C8E6C9 80% 100%);
}
.bullet__bar { position: absolute; left: 0; top: 50%; transform: translateY(-50%); height: 9px; background: var(--color-primary); border-radius: 3px; }
.bullet__target { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--color-fg); }
.bullet-val { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.bullet-legend { font-size: 0.78rem; color: var(--color-text-muted); margin-top: 0.6rem; display: flex; gap: 0.9rem; flex-wrap: wrap; }
.bullet-legend span::before { content: ''; display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }
.lg-bad::before { background: #FFCDD2; }
.lg-ok::before { background: #FFF9C4; }
.lg-good::before { background: #C8E6C9; }

/* быстрые команды */
.quick { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 0.7rem; }
.quick a {
  display: flex; align-items: center; gap: 0.6rem; padding: 0.7rem 0.9rem;
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  color: var(--color-fg); font-weight: 500; font-size: 0.9rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}
.quick a:hover { border-color: var(--color-secondary); box-shadow: var(--shadow-sm); transform: translateY(-1px); text-decoration: none; }
.quick svg { width: 18px; height: 18px; color: var(--color-secondary); flex-shrink: 0; }

/* мини-разбивка (уборка по типам) */
.pill-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.pill { background: var(--color-muted); border-radius: var(--radius-sm); padding: 0.4rem 0.7rem; font-size: 0.85rem; }
.pill b { font-variant-numeric: tabular-nums; }

/* ---------- Сетка карточек-категорий (база знаний) ---------- */
.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.85rem;
  list-style: none;
  margin: 0;
  padding: 0;
}
.category-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.9rem 1.1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-fg);
  font-weight: 500;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}
.category-card:hover { border-color: var(--color-secondary); box-shadow: var(--shadow-md); transform: translateY(-1px); text-decoration: none; }
.category-card__icon {
  display: flex; align-items: center; justify-content: center;
  width: 2.2rem; height: 2.2rem; border-radius: var(--radius-sm);
  background: var(--color-muted); color: var(--color-secondary); flex-shrink: 0;
}
.category-card__icon svg { width: 18px; height: 18px; }
.category-card__name { flex: 1; }
.category-card__arrow { color: var(--color-text-muted); }

/* ---------- Карточки задач (дашборд, журнал смены) ---------- */
.task-list { display: flex; flex-direction: column; gap: 0.5rem; }
.task-item {
  display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap;
  padding: 0.6rem 0.85rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}
.task-item--done { opacity: 0.7; }
.task-item--done .task-item__text { text-decoration: line-through; color: var(--color-text-muted); }
.task-item__text { flex: 1; min-width: 160px; }
.task-item__meta { font-size: 0.8rem; color: var(--color-text-muted); white-space: nowrap; }
/* Бейджи+кнопки — отдельная строка под текстом (не сжимают длинный текст
   задачи в узкий столбец рядом с собой). */
.task-item__actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; flex: 1 0 100%; }

/* ---------- Ряд иконок-кнопок (действия в модалках) ---------- */
.icon-actions { display: flex; gap: 0.4rem; align-items: center; margin-left: auto; }

/* ---------- Модальные окна: общий вид ---------- */
dialog {
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 0;
}
dialog::backdrop { background: rgba(15, 23, 42, 0.4); backdrop-filter: blur(4px); }
.dlg-head { padding: 1rem 1.25rem; border-bottom: 1px solid var(--color-border); font-weight: 600; font-size: 1.05rem; }
.dlg-body { padding: 1.25rem; max-height: 70vh; overflow-y: auto; }
.dlg-foot { padding: 0.9rem 1.25rem; border-top: 1px solid var(--color-border); display: flex; gap: 0.6rem; justify-content: flex-end; }
.info-table { width: 100%; border-collapse: collapse; }
.info-table td { padding: 5px 0; border-bottom: 1px solid var(--color-border); vertical-align: top; }
.info-table td:first-child { color: var(--color-text-muted); white-space: nowrap; padding-right: 1rem; width: 40%; }
.info-table tr:last-child td { border-bottom: none; }

/* ---------- Адаптивность ---------- */
@media (max-width: 880px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: static; flex-direction: row;
    overflow-x: auto; align-items: center;
  }
  .sidebar__nav { display: flex; gap: 0.25rem; padding: 0.5rem; }
  .sidebar__link { margin-bottom: 0; white-space: nowrap; padding: 0.5rem 0.7rem; }
  .sidebar__brand, .sidebar__foot, .sidebar__group-label { display: none; }
  .content { padding: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- Хлебные крошки ---------- */
.breadcrumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; font-size: 0.85rem; color: var(--color-text-muted); margin-bottom: 0.9rem; }
.breadcrumbs a { color: var(--color-text-muted); }
.breadcrumbs a:hover { color: var(--color-secondary); }
.breadcrumbs .sep { opacity: 0.6; }
.breadcrumbs .current { color: var(--color-fg); font-weight: 500; }

/* ---------- Группировка ссылок в сайдбаре ---------- */
.sidebar__group-label {
  padding: 0.85rem 1rem 0.3rem;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(255, 255, 255, 0.42);
}
.sidebar__group-label:first-child { padding-top: 0.2rem; }

/* ---------- Спиннер загрузки на кнопках ---------- */
.spinner {
  display: inline-block; width: 13px; height: 13px;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; opacity: 0.85; vertical-align: -2px;
  animation: spin 0.6s linear infinite; margin-right: 0.35rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Диалог подтверждения (замена нативного confirm()) ---------- */
.confirm-dialog { width: min(360px, 90vw); }

/* ---------- Конкуренты и источники: карточки + модалки ---------- */
#competitor-modal, #source-modal { width: min(440px, 92vw); }
.competitor-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.platform-badge {
  display: inline-block;
  background: var(--color-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.15rem 0.5rem;
  font-size: 0.82rem;
}
.url-cell {
  color: var(--color-text-muted);
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
  vertical-align: middle;
}
.btn-link {
  background: transparent;
  border: none;
  color: var(--color-secondary);
  padding: 0.4rem 0;
  text-decoration: underline;
  font-weight: 500;
}
.btn-link:hover { opacity: 1; text-decoration: none; }

/* ---------- Пустые состояния таблиц: центр + иконка ---------- */
td.empty {
  text-align: center;
  font-style: normal;
  padding: 2.5rem 1rem;
}
td.empty::before {
  content: "";
  display: block;
  width: 30px; height: 30px;
  margin: 0 auto 0.55rem;
  opacity: 0.35;
  background-color: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M22 12h-6l-2 3h-4l-2-3H2'/%3E%3Cpath d='M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z'/%3E%3C/svg%3E") center/contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M22 12h-6l-2 3h-4l-2-3H2'/%3E%3Cpath d='M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z'/%3E%3C/svg%3E") center/contain no-repeat;
}

/* ---------- Нативные date-инпуты: иконка календаря под дизайн-систему ---------- */
input[type=date] { color-scheme: light; }
input[type=date]::-webkit-calendar-picker-indicator {
  opacity: 0.55; cursor: pointer; border-radius: 4px; padding: 2px;
}
input[type=date]::-webkit-calendar-picker-indicator:hover { opacity: 1; background: var(--color-muted); }

/* ---------- Тёмная тема ---------- */
:root[data-theme="dark"] {
  color-scheme: dark;
  --color-bg: #0F172A;
  --color-surface: #1E293B;
  --color-fg: #E2E8F0;
  --color-muted: #24324A;
  --color-text-muted: #94A3B8;
  --color-border: #334155;
  --color-input-border: #3B4A61;
  --color-accent-soft: rgba(5, 150, 105, 0.18);
  --color-danger-soft: rgba(220, 38, 38, 0.18);
  --color-warning-soft: rgba(180, 83, 9, 0.22);
}
:root[data-theme="dark"] .card,
:root[data-theme="dark"] .form-section,
:root[data-theme="dark"] .metric,
:root[data-theme="dark"] .category-card,
:root[data-theme="dark"] .task-item { box-shadow: none; }
:root[data-theme="dark"] tbody tr:hover,
:root[data-theme="dark"] table tr:hover,
:root[data-theme="dark"] .table-comfortable tbody tr:hover { background: #24324A; }
:root[data-theme="dark"] thead th,
:root[data-theme="dark"] table tr:first-child th { background: #1B2637; }
:root[data-theme="dark"] .filter-bar,
:root[data-theme="dark"] .pill { background: #1B2637; }
:root[data-theme="dark"] .search-box input,
:root[data-theme="dark"] .filter-bar input,
:root[data-theme="dark"] .filter-bar select { background: var(--color-surface); }
:root[data-theme="dark"] .quick a { color: var(--color-fg); }
:root[data-theme="dark"] tr.prio td { background: rgba(180, 83, 9, 0.16); }
:root[data-theme="dark"] .btn-secondary { color: #E2E8F0; }

/* ---------- Мобильные карточки для плотных таблиц (вместо горизонтального сжатия) ---------- */
@media (max-width: 720px) {
  /* Заголовок в этих таблицах — обычный <tr> без <thead> (после <colgroup> в DOM). */
  .table-cards thead, .table-cards .table-cards__head { display: none; }
  .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
  .table-cards { table-layout: auto; }
  .table-cards tr {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    margin: 0 0.6rem 0.6rem;
    padding: 0.55rem 0.75rem;
    background: var(--color-surface);
    width: auto;
  }
  .table-cards td {
    border-bottom: none;
    padding: 0.3rem 0;
    overflow: visible;
    white-space: normal;
    text-overflow: clip;
    max-width: none;
  }
  .table-cards td.num { text-align: left; }
  .table-cards td:empty,
  .table-cards td.empty-if-blank:empty { display: none; }
  .table-cards td::before {
    content: attr(data-label);
    display: block;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    color: var(--color-text-muted);
    margin-bottom: 0.1rem;
  }
  .table-cards td[data-label=""]::before,
  .table-cards td:not([data-label])::before { content: none; margin: 0; }
  .table-cards td.empty { text-align: center; }
  .table-cards td.empty::before { content: ""; }
}

/* ---------- Печать ---------- */
@media print {
  .sidebar, .toolbar, .no-print { display: none !important; }
  .layout { display: block; }
  .content { max-width: none; padding: 0; }
  .card { box-shadow: none; border: none; padding: 0; }
  body { background: #fff; }
}

/* ---------- Дашборд цен: компактная кнопка-стрелка рекомендации ---------- */
.text-warning { color: var(--color-warning); }
.rec-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: none;
  padding: 0;
  flex-shrink: 0;
  cursor: pointer;
}
.rec-btn svg { width: 13px; height: 13px; }
.rec-btn.up { background: var(--color-accent-soft); color: var(--color-accent); }
.rec-btn.down { background: var(--color-warning-soft); color: var(--color-warning); }
.rec-btn:hover { filter: brightness(0.95); }

.mapping-group-row td {
  padding: 0.55rem 0.6rem;
  font-weight: 600;
  font-size: 0.9rem;
  background: var(--color-muted);
  border-left: 3px solid var(--color-border);
}
.mapping-group-row.own td { border-left-color: var(--color-accent); color: var(--color-accent); }
.mapping-group-row.competitor td { border-left-color: var(--color-secondary); color: var(--color-secondary); }

.scrape-progress {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.scrape-progress__track {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: var(--color-muted);
  overflow: hidden;
}
.scrape-progress__fill {
  height: 100%;
  border-radius: 999px;
  background: var(--color-accent);
  transition: width 0.3s ease;
  width: 0%;
}
.scrape-progress__label {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.scrape-progress__fill.has-errors { background: var(--color-warning); }
