/*
 * design_system.css — Stage 12.0.116
 *
 * Universal styles for reusable components introduced in 12.0.116:
 *   delta_indicator, progress_bar, tab_toggle, share_link_button,
 *   period_compare_toggle, filter_chips (universal), drill_down_table.
 *
 * Все стили используют CSS variables из tokens.css (12.0.83). Этот файл
 * НЕ переопределяет токены — он только добавляет компонентные классы
 * под префиксом `ds-` («design-system»), чтобы исключить collision
 * с существующими (.kpi-card, .pnl-table, .planfact-*, .rnp-*).
 *
 * Подключается в base.html ПОСЛЕ components.css.
 */

/* ──────────────────────────────────────────────────────────────────
 * Delta indicator
 * ────────────────────────────────────────────────────────────────── */
.ds-delta {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
.ds-delta--sm { font-size: 11px; }
.ds-delta--md { font-size: 12px; }
.ds-delta--good { color: var(--color-success); }
.ds-delta--bad  { color: var(--color-danger); }
.ds-delta--flat { color: var(--color-text-muted); }
.ds-delta__arrow { font-weight: 700; }
.ds-delta__pct { opacity: 0.85; font-weight: 500; }

/* ──────────────────────────────────────────────────────────────────
 * Progress bar
 * ────────────────────────────────────────────────────────────────── */
.ds-progress {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ds-progress__label {
  font-size: 12px;
  color: var(--color-text-secondary);
  font-weight: 500;
}
.ds-progress__row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.ds-progress__bar {
  flex: 1;
  height: 14px;
  background: var(--color-surface-soft);
  border-radius: 7px;
  overflow: hidden;
  position: relative;
  min-width: 80px;
}
.ds-progress__fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  border-radius: 7px;
  transition: width 0.3s ease;
}
.ds-progress__fill--good { background: var(--color-success); }
.ds-progress__fill--mid  { background: var(--color-warning); }
.ds-progress__fill--bad  { background: var(--color-danger); }
.ds-progress__pct {
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--color-text-primary);
  min-width: 42px;
  text-align: right;
}
.ds-progress__detail {
  font-size: 11px;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

/* ──────────────────────────────────────────────────────────────────
 * Tab toggle (segmented control)
 * ────────────────────────────────────────────────────────────────── */
.ds-tabs {
  display: inline-flex;
  background: var(--color-surface-soft);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 2px;
}
.ds-tabs--sm { padding: 2px; }
.ds-tabs__tab {
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s;
}
.ds-tabs__tab:hover { color: var(--color-text-primary); }
.ds-tabs__tab--active {
  background: var(--color-surface);
  color: var(--color-text-primary);
  box-shadow: var(--shadow-sm);
}
.ds-tabs--sm .ds-tabs__tab { padding: 4px 10px; font-size: 11px; }

/* ──────────────────────────────────────────────────────────────────
 * Period compare toggle
 * ────────────────────────────────────────────────────────────────── */
.ds-compare-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  font-size: 12px;
  color: var(--color-text-secondary);
  user-select: none;
}
.ds-compare-toggle input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.ds-compare-toggle__slider {
  width: 32px;
  height: 18px;
  background: var(--color-surface-soft);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  position: relative;
  transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.ds-compare-toggle__slider::after {
  content: '';
  position: absolute;
  left: 2px;
  top: 1px;
  width: 12px;
  height: 12px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
  transition: left 0.15s, background 0.15s;
}
.ds-compare-toggle input:checked + .ds-compare-toggle__slider {
  background: var(--color-primary);
  border-color: var(--color-primary);
}
.ds-compare-toggle input:checked + .ds-compare-toggle__slider::after {
  left: 17px;
}
.ds-compare-toggle__label {
  font-weight: 500;
}

/* ──────────────────────────────────────────────────────────────────
 * Universal filter chips bar (12.0.116)
 *
 * Note: existing `.filter-chips` / `.filter-chip` (12.0.115) кейс —
 * inline pills only (no dropdown). Universal версия использует префикс
 * `ds-filter-*` чтобы две системы могли сосуществовать.
 * ────────────────────────────────────────────────────────────────── */
.ds-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: var(--space-3);
}

.ds-filter-chip {
  position: relative;
  display: inline-block;
}
.ds-filter-chip__summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  font-size: 12px;
  color: var(--color-text-secondary);
  font-weight: 500;
  transition: background 0.1s, border-color 0.1s;
  white-space: nowrap;
}
.ds-filter-chip__summary::-webkit-details-marker { display: none; }
.ds-filter-chip__summary:hover {
  background: var(--color-surface-soft);
  border-color: var(--color-border-strong);
}
.ds-filter-chip--active .ds-filter-chip__summary {
  background: var(--color-primary-soft);
  border-color: var(--color-primary);
  color: var(--color-primary-strong);
  font-weight: 600;
}
.ds-filter-chip__caret { font-size: 9px; opacity: 0.6; }

.ds-filter-chip__menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 10;
  min-width: 180px;
  max-height: 280px;
  overflow-y: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.ds-filter-chip__menu--date {
  flex-direction: column;
  gap: 8px;
  padding: 12px;
}

.ds-filter-chip__option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 6px 10px;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 12px;
  text-align: left;
  cursor: pointer;
  color: var(--color-text-primary);
}
.ds-filter-chip__option:hover { background: var(--color-surface-soft); }
.ds-filter-chip__option--active {
  background: var(--color-primary-soft);
  color: var(--color-primary-strong);
  font-weight: 600;
}
.ds-filter-chip__count {
  font-size: 10px;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}
.ds-filter-chip__date-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--color-text-muted);
}
.ds-filter-chip__date-label input {
  font-family: inherit;
  font-size: 12px;
  padding: 4px 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
}

/* ──────────────────────────────────────────────────────────────────
 * Drill-down table
 * ────────────────────────────────────────────────────────────────── */
.ds-drill-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.ds-drill-table th,
.ds-drill-table td {
  padding: 8px 10px;
  text-align: right;
  border-bottom: 1px solid var(--color-border);
}
.ds-drill-table th:first-child,
.ds-drill-table td:first-child {
  text-align: left;
  font-weight: 500;
}
.ds-drill-table thead th {
  background: var(--color-surface-soft);
  font-size: 11px;
  text-transform: uppercase;
  color: var(--color-text-muted);
  font-weight: 600;
  letter-spacing: 0.04em;
}
.ds-drill-row--parent td {
  font-weight: 700;
  background: var(--color-surface-soft);
}
.ds-drill-row--total td {
  font-weight: 700;
  border-top: 2px solid var(--color-border-strong);
}
.ds-drill-row--child td:first-child {
  padding-left: 28px;
  color: var(--color-text-secondary);
  font-weight: 400;
}
.ds-drill-row--collapsed { display: none; }

.ds-drill-cell--neg { color: var(--color-danger); }
.ds-drill-cell--pos { color: var(--color-success); }
.ds-drill-pct {
  display: block;
  font-size: 10px;
  color: var(--color-text-muted);
  font-weight: 400;
}

.ds-drill-toggle {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  text-align: left;
}
.ds-drill-toggle::before {
  content: '▸';
  display: inline-block;
  margin-right: 6px;
  font-size: 10px;
  color: var(--color-text-muted);
  transition: transform 0.15s;
}
.ds-drill-toggle.is-open::before { transform: rotate(90deg); }

/* ──────────────────────────────────────────────────────────────────
 * Share-link feedback
 * ────────────────────────────────────────────────────────────────── */
[data-ds-share-link][data-ds-share-state="copied"] {
  background: var(--color-success);
  border-color: var(--color-success);
  color: #fff;
}

/* ──────────────────────────────────────────────────────────────────
 * Mobile responsive adjustments
 * ────────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .ds-filter-bar { gap: 4px; }
  .ds-filter-chip__summary { font-size: 11px; padding: 4px 8px; }
  .ds-filter-chip__menu { min-width: 160px; max-height: 240px; }
  .ds-tabs__tab { padding: 5px 10px; font-size: 11px; }
  .ds-progress__row { gap: var(--space-1); }
  .ds-progress__bar { height: 12px; }
  .ds-progress__pct { min-width: 36px; font-size: 11px; }
  .ds-drill-table { font-size: 12px; }
  .ds-drill-table th, .ds-drill-table td { padding: 6px 8px; }
}
