/* Общие стили обеих страниц сайта */
  /* Тёмная тема в мягких сине-серых тонах (не чёрная) */
  :root {
    --bg: #262d3a; --card: #2f3747; --card-2: #374053; --head: #343d4f;
    --text: #eef2f8; --muted: #a9b3c4; --line: #434d61;
    --accent: #7eb0ff; --accent-bg: #3a4d6e; --accent-text: #0f1a2c;
    --total: #ffd36e; --total-bg: #4a4330; --month: #363a37; --month-text: #e3dcc4;
    --filled: #35486a; --filled-text: #ffffff; --empty: #2b3241; --hover: #3c4862;
    --warn-bg: #4c4228; --warn: #ffd98a; --err-bg: #55303a; --err: #ffb4bd;
    --ok: #7fdcb0; --stale: #ffcf70; --old: #ff9a9a;
    color-scheme: dark;
  }
  * { box-sizing: border-box; }
  /* место под полосу прокрутки всегда занято — короткие страницы не сдвигаются вбок */
  html { scrollbar-gutter: stable; }
  body { margin: 0; background: var(--bg); color: var(--text);
         background-image: radial-gradient(1200px 500px at 15% -10%, #33405a 0%, transparent 60%);
         background-attachment: fixed;
         font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
  .wrap { max-width: 1600px; margin: 0 auto; padding: 24px 16px 48px; }
  header { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: end; justify-content: space-between; }
  /* меню всегда прижато к верху, даже если кнопки справа переносятся на две строки */
  header > div:first-child { align-self: flex-start; }
  h1 { margin: 0; font-size: 24px; }
  .sub { color: var(--muted); margin-top: 4px; }
  .controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
  input, button { font: inherit; color: inherit; background: var(--card);
                  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }
  input[type=search] { width: 260px; max-width: 100%; }
  button { cursor: pointer; }
  button:hover { border-color: var(--accent); }
  .banner { margin-top: 16px; padding: 10px 14px; border-radius: 8px; }
  .banner.warn { background: var(--warn-bg); color: var(--warn); }
  .banner.err { background: var(--err-bg); color: var(--err); }
  .banner summary { cursor: pointer; }
  .banner ul { margin: 6px 0 0; padding-left: 20px; }
  .kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin: 20px 0; }
  .kpi { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
  .kpi .label { color: var(--muted); font-size: 13px; }
  .kpi .value { font-size: 26px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
  .kpi.main { background: linear-gradient(135deg, var(--total-bg), var(--card)); border-color: #6b5d36; }
  .kpi.main .value { color: var(--total); }
  .tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--line); }
  .tab { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none;
         padding: 10px 14px; color: var(--muted); }
  .tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
  .panel { background: var(--card); border: 1px solid var(--line); border-top: none;
           border-radius: 0 0 12px 12px; overflow: auto; max-height: calc(100vh - 120px); }
  table { width: 100%; border-collapse: collapse; }
  th, td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
  td.wrap-cell { white-space: normal; min-width: 200px; }
  th { position: sticky; top: 0; z-index: 2; background: var(--head); font-weight: 600; color: var(--muted);
       font-size: 12px; cursor: pointer; user-select: none; vertical-align: bottom; }
  th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
  th .arrow { color: var(--accent); }
  tr.total td { font-weight: 700; border-top: 2px solid var(--accent); background: var(--head); }
  .muted { color: var(--muted); }
  .members { color: var(--muted); font-weight: 400; font-size: 12px; white-space: normal; }
  .empty { padding: 40px; text-align: center; color: var(--muted); }
  footer { margin-top: 16px; color: var(--muted); font-size: 13px; }

  /* сводная таблица */
  .pivot th { white-space: normal; min-width: 72px; border-left: 1px solid var(--line); }
  .pivot td { border-left: 1px solid var(--line); }
  .pivot th:first-child, .pivot td:first-child { position: sticky; left: 0; z-index: 1; background: var(--card);
       min-width: 260px; max-width: 340px; white-space: normal; border-left: none; }
  .pivot th:first-child { z-index: 3; background: var(--head); }
  .pivot .m { background: var(--month); color: var(--month-text); }
  .pivot th.m { color: #cfc6a6; }
  .pivot .cur { background: var(--total-bg); color: var(--total); font-weight: 700; font-size: 15px; }
  .pivot th.cur { color: var(--total); font-size: 12px; box-shadow: inset 0 -3px 0 var(--total); }
  .pivot td.filled { background: var(--filled); color: var(--filled-text); font-weight: 600; }
  .pivot td.nil { background: var(--empty); }
  .pivot tr.agent { cursor: pointer; }
  .pivot tr.agent:hover td { background-image: linear-gradient(var(--hover), var(--hover)); }
  .pivot tr.agent td:first-child { font-weight: 600; color: #ffffff; }
  .pivot tr.agent td:first-child::before { content: "▸ "; color: var(--accent); }
  .pivot tr.agent.open td { border-bottom-color: transparent; }
  .pivot tr.agent.open td:first-child { box-shadow: inset 4px 0 0 var(--accent); }
  .pivot tr.agent.open td:first-child::before { content: "▾ "; }
  .pivot tr.detail > td { padding: 0; background: var(--card-2); box-shadow: inset 4px 0 0 var(--accent); }
  .pivot tr.total td:first-child { background: var(--head); }
  .pivot .last.ok { color: var(--ok); }
  .pivot .last.stale { color: var(--stale); }
  .pivot .last.old { color: var(--old); font-weight: 600; }
  .detail-box { position: sticky; left: 0; width: min(900px, calc(100vw - 64px)); padding: 12px 16px 16px; }
  .detail-box table { background: var(--card); border: 1px solid var(--line); border-radius: 8px; margin-top: 8px; }
  .detail-box td, .detail-box th { position: static; border-left: none; }
  .detail-box tr.cat td { background: var(--accent-bg); color: #ffffff; font-weight: 700; }
  .detail-box .sum-line { margin-top: 8px; font-weight: 600; font-size: 15px; display: flex; flex-wrap: wrap; gap: 8px 24px; align-items: center; }
  .pivot .last { white-space: nowrap; text-align: center; font-variant-numeric: tabular-nums; }
  .order-dates { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
  .order-dates .chip { background: var(--card); border: 1px solid var(--line); border-radius: 999px;
                       padding: 2px 10px; font-size: 13px; white-space: nowrap; cursor: pointer; }
  .order-dates .chip:hover { border-color: var(--accent); }
  .order-dates .chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
  .detail-box select { font: inherit; color: inherit; background: var(--card); border: 1px solid var(--line);
                       border-radius: 6px; padding: 3px 6px; font-weight: 400; }

  /* переключатель сегментов */
  .segs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; }
  .seg { padding: 8px 18px; border-radius: 999px; font-weight: 600; }
  .seg .n { color: var(--muted); font-weight: 400; margin-left: 4px; }
  .seg.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
  .seg.active .n { color: rgba(15,26,44,.7); }
  .seg-toggle { margin-left: auto; border-radius: 999px; padding: 8px 16px; border-style: dashed; color: var(--accent); }
  .seg-toggle.on { border-style: solid; border-color: var(--accent); background: var(--accent-bg); color: #fff; }
  .pivot tr.agent.noorders td:first-child { color: var(--muted); font-weight: 500; }

  /* редактор столбцов */
  .cols-btn { margin-left: auto; align-self: center; border-radius: 999px; padding: 6px 14px; color: var(--accent); }
  /* фильтр «Группы товаров» */
  .cat-filter { margin-left: auto; align-self: center; position: relative; }
  .cat-filter + .cols-btn { margin-left: 8px; }
  .cat-btn { border-radius: 999px; padding: 6px 14px; color: var(--accent); max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .cat-btn.on { background: var(--accent-bg); border-color: var(--accent); color: #fff; font-weight: 700; }
  .cat-pop { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; width: 340px; max-height: 65vh; overflow: auto;
             background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; box-shadow: 0 12px 30px rgba(0,0,0,.45); }
  .cat-pop[hidden] { display: none; }
  .cat-pop .pop-help { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
  .cat-pop .pop-tools { display: flex; gap: 6px; margin-bottom: 8px; }
  .cat-pop label { display: flex; align-items: center; gap: 8px; padding: 4px 2px; cursor: pointer; }
  .cat-pop label:hover { color: var(--accent); }
  .cat-pop .unit { color: var(--muted); font-size: 12px; margin-left: auto; }
  .detail-box .rename { border-radius: 999px; padding: 4px 12px; color: var(--accent); font-weight: 600; }
  .banner.filter {background: var(--accent-bg); color: #fff; border: 1px solid var(--accent); }
  .banner.filter button { margin-left: 8px; }
  .pivot th.cat-head { cursor: grab; }
  .pivot th.drop-target { box-shadow: inset 3px 0 0 var(--total); }
  .modal[hidden] { display: none; }
  .modal { position: fixed; inset: 0; z-index: 50; background: rgba(15, 20, 30, .6);
           display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow: auto; }
  .modal-box { background: var(--card); border: 1px solid var(--line); border-radius: 14px; width: min(860px, 100%);
               padding: 18px 20px; box-shadow: 0 20px 60px rgba(0,0,0,.4); }
  .modal-head { display: flex; justify-content: space-between; align-items: center; }
  .modal-head h2 { margin: 0; font-size: 20px; }
  .modal-head h2 span { color: var(--accent); }
  .help { color: var(--muted); font-size: 13px; line-height: 1.55; }
  .help code { background: var(--card-2); padding: 1px 6px; border-radius: 4px; color: var(--text); }
  .gcard { background: var(--card-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 8px 0; }
  .gcard.dragging { opacity: .4; }
  .gcard.drop-target { border-color: var(--total); box-shadow: 0 -3px 0 var(--total); }
  .gcard .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
  .gcard .handle { cursor: grab; color: var(--muted); font-size: 18px; padding: 0 4px; user-select: none; }
  .gcard input.name { font-weight: 700; flex: 1 1 220px; }
  .gcard textarea { width: 100%; font: inherit; color: inherit; background: var(--card); border: 1px solid var(--line);
                    border-radius: 8px; padding: 6px 10px; resize: vertical; }
  .gcard .field { margin-top: 8px; font-size: 12px; color: var(--muted); }
  .gcard .field input { width: 100%; }
  .gcard .prod { display: inline-block; background: var(--card); border: 1px solid var(--line); border-radius: 999px;
                 padding: 1px 4px 1px 10px; margin: 3px 4px 0 0; font-size: 12px; color: var(--text); }
  .gcard .prod button { border: none; background: none; padding: 0 6px; color: var(--old); }
  .gcard .del { color: var(--old); }
  .modal-foot { display: flex; gap: 12px; align-items: center; margin-top: 12px; }
  .modal-foot #colsMsg { flex: 1; }
  button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 700; }
  .prod-tools { padding: 10px 12px; display: flex; gap: 16px; align-items: center; flex-wrap: wrap; color: var(--muted); }
  .prod-tools label { color: var(--text); cursor: pointer; }
  select.assign { font: inherit; color: inherit; background: var(--card); border: 1px solid var(--line);
                  border-radius: 6px; padding: 2px 6px; max-width: 260px; }
  select.assign.other { border-color: var(--stale); color: var(--stale); }

/* навигация между страницами */
.pages { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
/* лого слева от названий страниц — размером со строку меню */
.pages a.logo { display: flex; padding: 0 6px 0 0; color: var(--text); background: none; box-shadow: none; }
.pages a.logo svg { width: 30px; height: 30px; }
.pages a.logo:hover { color: var(--accent); background: none; }
.pages a { font-size: 22px; font-weight: 700; color: var(--muted); text-decoration: none; padding: 2px 12px 4px;
           border-radius: 10px; }
.pages a:hover { color: var(--text); background: var(--card); }
/* вкладки внутри раздела «Анализ» */
.subtabs { display: flex; gap: 4px; margin-top: 16px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.subtabs a { white-space: nowrap; }
.subtabs a { padding: 8px 16px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; font-weight: 600; }
.subtabs a:hover { color: var(--text); }
.subtabs a.active { color: var(--accent); border-bottom-color: var(--accent); }
/* кто вошёл на сайт */
.pages .user-chip { margin-left: 10px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.pages .user-chip a { font-size: 13px; font-weight: 400; padding: 2px 8px; margin-left: 4px; color: var(--accent); border: 1px solid var(--line); border-radius: 999px; }
.pages .user-chip a:hover { border-color: var(--accent); background: none; }
.pages a.active { color: var(--text); background: var(--card); box-shadow: inset 0 -3px 0 var(--accent); }

/* ===== телефон (экран до 700 px): компактнее, ничего не вылезает за край ===== */
@media (max-width: 700px) {
  html { scrollbar-gutter: auto; }
  body { background-attachment: scroll; background-repeat: no-repeat; min-height: 100vh; }
  .wrap { padding: 10px 10px 32px; }
  header { gap: 8px; }
  header > div:first-child { width: 100%; }
  /* меню — разделы в одну строку, «Выйти» — справа или строкой ниже */
  .pages { gap: 0; row-gap: 4px; }
  .pages a { font-size: 14px; padding: 4px 5px 6px; white-space: nowrap; flex: none; border-radius: 8px; }
  .pages a.logo { padding-right: 2px; }
  .pages a.logo svg { width: 22px; height: 22px; }
  .pages .user-chip { margin-left: auto; flex: none; font-size: 12px; }
  .sub { font-size: 13px; }
  .subtabs { margin: 12px -10px 0; padding: 0 10px; scrollbar-width: none; }
  .subtabs::-webkit-scrollbar { display: none; }
  .subtabs a { padding: 8px 10px; font-size: 14px; }
  .controls { width: 100%; gap: 6px; }
  /* шрифт полей 16 px — иначе iPhone увеличивает страницу при вводе */
  input, select, textarea { font-size: 16px; }
  input[type=search] { width: 100%; flex: 1 1 100%; }
  input[type=month], input[type=date] { min-width: 0; }
  .banner { margin-top: 10px; padding: 8px 10px; font-size: 13px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 12px 0; }
  .kpi { padding: 10px 12px; min-width: 0; }
  .kpi .label { font-size: 12px; }
  .kpi .value { font-size: 20px; overflow-wrap: anywhere; }
  .tab { padding: 8px 10px; font-size: 14px; }
  .panel { max-height: 72vh; }
  th, td { padding: 6px 7px; }
  th { font-size: 11px; }
  td { font-size: 13px; }
  td.wrap-cell { min-width: 150px; }
  footer { font-size: 12px; }
  /* сводная: столбец контрагентов уже, список «в МойСклад» — не больше двух строк */
  .pivot th:first-child, .pivot td:first-child { min-width: 140px; max-width: 160px; }
  .pivot th { min-width: 58px; }
  .pivot .cur { font-size: 14px; }
  .pivot .members { font-size: 11px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .detail-box { width: calc(100vw - 24px); padding: 10px 8px 12px; }
  .detail-box td.wrap-cell { min-width: 0; }
  .segs { margin-top: 12px; gap: 6px; }
  .seg { padding: 6px 12px; }
  .seg-toggle { margin-left: 0; padding: 6px 12px; font-size: 13px; }
  .cols-btn, .cat-btn { padding: 5px 10px; font-size: 14px; }
  .cat-btn { max-width: 60vw; }
  /* выпадающие окна и окна-редакторы — во всю ширину экрана */
  .cat-pop { position: fixed; left: 8px; right: 8px; top: 64px; width: auto; max-height: 75vh; }
  .modal { padding: 8px; }
  .modal-box { padding: 14px 12px; border-radius: 12px; }
  .modal-head { gap: 8px; }
  .modal-head h2 { font-size: 18px; }
  .modal-foot { flex-wrap: wrap; }
  .gcard .row { gap: 6px; }
  .gcard input.name { flex-basis: 100%; }
  select.assign { max-width: 46vw; }
}
