/* Дашборд сделок Битрикс24 — макет. Токены и вёрстка. */

:root {
  color-scheme: light;
  --plane:          #f9f9f7;
  --surface-1:      #fcfcfb;
  --surface-2:      #f2f1ed;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --grid:           #e1e0d9;
  --axis:           #c3c2b7;
  --border:         rgba(11, 11, 11, 0.10);
  --shadow:         0 1px 2px rgba(11, 11, 11, .05), 0 8px 24px rgba(11, 11, 11, .04);

  /* Ordinal-рампа прогресса по воронке (валидирована: light, ordinal, ALL PASS) */
  --stage-1: #86b6ef;
  --stage-2: #3987e5;
  --stage-3: #256abf;
  --stage-4: #0d366b;

  /* Статусы — фиксированные, не темизируются */
  --good:     #0ca30c;
  --critical: #d03b3b;
  --warning:  #fab219;

  --radius:  12px;
  --radius-s: 8px;
  --gap:     16px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --plane:          #0d0d0d;
    --surface-1:      #1a1a19;
    --surface-2:      #232322;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --grid:           #2c2c2a;
    --axis:           #383835;
    --border:         rgba(255, 255, 255, 0.10);
    --shadow:         none;
    --stage-1: #cde2fb;
    --stage-2: #86b6ef;
    --stage-3: #3987e5;
    --stage-4: #184f95;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:          #0d0d0d;
  --surface-1:      #1a1a19;
  --surface-2:      #232322;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --grid:           #2c2c2a;
  --axis:           #383835;
  --border:         rgba(255, 255, 255, 0.10);
  --shadow:         none;
  --stage-1: #cde2fb;
  --stage-2: #86b6ef;
  --stage-3: #3987e5;
  --stage-4: #184f95;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--plane);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.page { max-width: 1200px; margin: 0 auto; padding: 24px 20px 64px; }

/* ---------- Шапка ---------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--gap);
  padding-bottom: 20px;
  border-bottom: 1px solid var(--grid);
  margin-bottom: 24px;
}
.topbar__title { flex: 1 1 260px; }
h1 { font-size: 22px; line-height: 1.2; margin: 0 0 4px; letter-spacing: -.01em; }
.subtitle { color: var(--text-secondary); font-size: 13px; margin: 0; }

.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; min-width: 0; max-width: 100%; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field__label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }

select, .btn {
  font: inherit;
  max-width: 100%;
  min-width: 0;
  color: var(--text-primary);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  padding: 7px 10px;
  cursor: pointer;
}
select:focus-visible, .btn:focus-visible, [tabindex]:focus-visible, a:focus-visible {
  outline: 2px solid var(--stage-3);
  outline-offset: 2px;
}
.btn:hover { background: var(--surface-2); }
.btn--ghost { background: transparent; }

.freshness { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); flex: none; }

/* ---------- Секции ---------- */

.section { margin-bottom: 32px; }
.section__head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; margin-bottom: 12px; flex-wrap: wrap;
}
h2 { font-size: 16px; margin: 0; letter-spacing: -.01em; }
.section__hint { font-size: 12px; color: var(--text-muted); margin: 2px 0 0; }
.section__tools { display: flex; gap: 8px; align-items: center; }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- Итог по открытым (стат-тайлы) ---------- */

.tiles { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: var(--gap); }
.tile { padding: 18px 20px; }
.tile__label { font-size: 12px; color: var(--text-secondary); margin: 0 0 6px; }
.tile__value {
  font-size: 34px; font-weight: 650; letter-spacing: -.02em; line-height: 1.1;
  margin: 0; white-space: nowrap;
}
.tile--hero .tile__value { font-size: 42px; }
.tile__value .unit { font-size: .55em; font-weight: 500; color: var(--text-secondary); margin-left: 4px; }
.tile__meta { font-size: 12px; color: var(--text-muted); margin: 8px 0 0; }
.tile__meta strong { color: var(--text-secondary); font-weight: 600; }

/* ---------- Воронка ---------- */

.funnel { padding: 8px 4px 12px; }
.funnel__row {
  display: grid;
  grid-template-columns: minmax(180px, 260px) 1fr 68px 132px 56px;
  align-items: center;
  gap: 12px;
  padding: 7px 16px;
  border-radius: var(--radius-s);
  position: relative;
}
.funnel__row:hover { background: var(--surface-2); }
.funnel__row--head {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-muted); padding-top: 4px; padding-bottom: 4px;
}
.funnel__row--head:hover { background: transparent; }

.stage-name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.stage-swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.stage-name span {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--text-primary);
}

.bar-track { height: 22px; position: relative; }
.bar {
  height: 22px;
  border-radius: 0 4px 4px 0;
  min-width: 2px;
  transition: width .25s ease;
}
.bar--zero { background: repeating-linear-gradient(45deg, var(--grid) 0 4px, transparent 4px 8px); width: 100% !important; height: 1px; margin-top: 10px; border-radius: 0; }

.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.num--count { color: var(--text-secondary); }
.num--sum { font-weight: 600; }
.num--share { color: var(--text-muted); font-size: 12px; }

.funnel__row--won .num--sum, .chip--won { color: var(--good); }
.funnel__row--lost .num--sum { color: var(--critical); }

.legend {
  display: flex; flex-wrap: wrap; gap: 16px; align-items: center;
  padding: 12px 20px; border-top: 1px solid var(--grid);
  font-size: 12px; color: var(--text-secondary);
}
.legend__item { display: flex; align-items: center; gap: 6px; }
.legend__ramp { display: flex; gap: 2px; }
.legend__ramp i { width: 16px; height: 10px; border-radius: 2px; display: block; }

/* ---------- Таблица сделок ---------- */

table { width: 100%; border-collapse: collapse; }
thead th {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-muted); font-weight: 500; text-align: left;
  padding: 10px 16px; border-bottom: 1px solid var(--grid); white-space: nowrap;
}
tbody td { padding: 11px 16px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
th.right, td.right { text-align: right; }

.deal-title { font-weight: 550; display: block; max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deal-id { font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px 3px 7px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 12px; color: var(--text-primary); white-space: nowrap;
  max-width: 240px;
}
.chip span { overflow: hidden; text-overflow: ellipsis; }
.chip i { width: 8px; height: 8px; border-radius: 50%; flex: none; }

.owner { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.avatar {
  width: 24px; height: 24px; border-radius: 50%; flex: none;
  background: var(--surface-2); border: 1px solid var(--border);
  display: grid; place-items: center; font-size: 10px; font-weight: 600; color: var(--text-secondary);
}
.when { color: var(--text-muted); font-size: 12px; white-space: nowrap; }

/* ---------- Тултип ---------- */

.tooltip {
  position: fixed; z-index: 20; pointer-events: none; opacity: 0;
  transform: translate(-50%, -110%); transition: opacity .12s ease;
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: var(--radius-s);
  box-shadow: 0 6px 24px rgba(11, 11, 11, .18);
  padding: 8px 10px; font-size: 12px; max-width: 260px;
}
.tooltip.is-visible { opacity: 1; }
.tooltip b { display: block; margin-bottom: 4px; }
.tooltip .t-row { display: flex; justify-content: space-between; gap: 16px; color: var(--text-secondary); }
.tooltip .t-row b { display: inline; color: var(--text-primary); font-variant-numeric: tabular-nums; }

/* ---------- Служебное ---------- */

.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); cursor: pointer; }
.note {
  font-size: 12px; color: var(--text-secondary);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-s); padding: 10px 12px; margin-bottom: 20px;
}
.note b { color: var(--text-primary); }
footer { margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--grid); font-size: 12px; color: var(--text-muted); }
footer a { color: var(--text-secondary); }
.hidden { display: none !important; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- Адаптив ---------- */

/* Страховка: широкая таблица скроллится внутри карточки, а не тянет страницу */
.card--scroll { overflow-x: auto; }

/* Средние десктопы: колонки сделок ужимаются, чтобы строка влезала в 1024 */
@media (max-width: 1100px) {
  .deal-title { max-width: 220px; }
  .chip { max-width: 170px; }
}

@media (max-width: 900px) {
  .tiles { grid-template-columns: 1fr 1fr; }
  .tile--hero { grid-column: 1 / -1; }
  .funnel__row { grid-template-columns: minmax(100px, 1fr) 52px 120px; row-gap: 6px; }
  .funnel__row .bar-track { grid-column: 1 / -1; order: 3; }
  .funnel__row--head .bar-track { display: none; }
  .num--share { display: none; }
  /* Таблица сделок → карточки: пять колонок в 768 не помещаются */
  .deals thead { display: none; }
  .deals tbody tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; padding: 12px 14px; border-bottom: 1px solid var(--grid); }
  .deals tbody td { border: 0; padding: 0; min-width: 0; }
  .deals td[data-col="sum"] { text-align: right; font-weight: 600; }
  .deals td[data-col="stage"], .deals td[data-col="owner"] { grid-column: 1 / -1; }
  .deal-title { max-width: none; white-space: normal; }
  .chip { max-width: 100%; }
}

@media (max-width: 640px) {
  .page { padding: 16px 12px 48px; }
  .tiles { grid-template-columns: 1fr; }
  .tile__value, .tile--hero .tile__value { font-size: 30px; }
  /* Мелкие подписи поднимаем до 12px — 11px на телефоне уже нечитаемо */
  .field__label, thead th, .funnel__row--head { font-size: 12px; }
  .controls .field { flex: 1 1 auto; }
  .switch input[type="checkbox"] { width: 18px; height: 18px; }
  .switch { min-height: 32px; }
  .section__tools { flex-wrap: wrap; }
}

/* Самые узкие экраны (320) — воронка в три колонки не влезает по числам */
@media (max-width: 420px) {
  .page { padding: 14px 10px 40px; }
  .funnel { padding: 4px 0 8px; }
  .funnel__row { grid-template-columns: minmax(0, 1fr) 40px 108px; gap: 8px; padding: 7px 10px; }
  .legend { padding: 12px 12px; gap: 10px; }
  .tile { padding: 16px 14px; }
  .tile__value, .tile--hero .tile__value { font-size: 26px; }
  .topbar__title { flex-basis: 100%; }
  .controls { width: 100%; }
  .controls .field:first-child { flex: 1 1 100%; }
  thead th, tbody td { padding-left: 12px; padding-right: 12px; }
}

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

@media print {
  .controls, .section__tools, .btn { display: none; }
  body { background: #fff; }
}
