/* Телефон: раздел «Отчёт».
   Только правила внутри @media (max-width: 640px): компьютерный вид не меняется. */
@media (max-width: 640px) {
  /* Шапка и выбор периода */
  #report-root > .panelhead h2 { line-height: 1.3; }
  #report-root > .panelhead .unit-fresh { display: block; margin: 4px 0 0; font-size: 13px; }
  #report-root .unit-filters { position: relative; gap: 10px; }
  #report-root .unit-filters .seg button { min-height: 40px; }
  #report-root .report-step { flex-wrap: nowrap; min-width: 0; }
  #report-root .report-step .navbtn { flex: none; width: 42px; height: 44px; font-size: 18px; }
  /* Календарь — на ширину строки фильтров, касания от 40 px. */
  #report-root .datepick { position: static; flex: 1 1 0; min-width: 0; }
  #report-date .datebtn { width: 100%; height: 44px; justify-content: center; font-size: 15px; }
  #report-date .datemenu { top: auto; left: 0; right: auto; margin-top: 6px; width: min(340px, 100%); box-sizing: border-box; }
  #report-date .calday { height: 40px; font-size: 14px; }
  #report-date .calstep { width: 40px; height: 40px; }
  #report-date .callink { min-height: 40px; padding: 4px 12px; }
  #report-reconcile, #report-ozon-check { flex: 1 1 100%; min-height: 44px; }
  #report-root .ghost, .report-modal .ghost { min-height: 40px; }
  #report-root .report-blockhead .primary { min-height: 40px; }

  /* Плитки: полоса 2+2, «Реклама без заказов» — на всю ширину; цифра целиком в одну
     строку, шрифт подстраивается под ширину плитки. */
  .kpigrid.report-kpis { gap: 0; }
  .report-kpis .kpi, .report-kpis .kpi:nth-child(n+4) { grid-column: auto; container-type: inline-size; min-width: 0;
    padding: 14px 0 14px 14px; border-top: 0; border-left: 1px solid var(--line); border-bottom: 1px solid var(--line); }
  .report-kpis .kpi:nth-child(odd) { padding-left: 0; padding-right: 12px; border-left: 0; }
  .report-kpis .kpi:last-child { grid-column: 1 / -1; border-bottom: 0; }
  .kpigrid.report-kpis .kpi .v { font-size: min(20px, 15.5cqi); white-space: nowrap; overflow-wrap: normal; }

  /* Таблицы отчёта — карточка на строку: подпись колонки над цифрой. */
  .report-table { display: block; margin: 4px 0; }
  .report-table thead { display: none; }
  .report-table tbody { display: block; }
  .report-table tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 12px; align-items: end;
    padding: 12px 2px; border-bottom: 1px solid var(--line); }
  .report-table td, .report-table td.num { display: block; min-width: 0; padding: 0; border: 0; text-align: left; white-space: normal; }
  .report-table td.report-art, .report-table td.report-why { min-width: 0; }
  .report-table .report-wide, .report-table .report-narrow-hide { display: block; }
  .report-table td:empty { display: none; }
  .report-table td:first-child, .report-table td.report-why { grid-column: 1 / -1; }
  .report-table td[data-label]:not(:first-child)::before { content: attr(data-label); display: block; margin-bottom: 2px;
    font-size: 11px; font-weight: 500; color: var(--muted-2); line-height: 1.3; }
  .report-table td.report-why[data-label]::before { margin-bottom: 4px; }
  .report-table tr.total { margin-top: 6px; padding: 12px; border: 0; border-radius: var(--r-row); background: var(--card-active); }
  .report-table tr.total td { background: none; border: 0; }
  .report-art .nm { font-size: 14px; }

  /* Сводка по магазинам и по дням: название и маржа сверху, под ними выручка, ЧП и ДРР. */
  .report-table.report-summary tr, .report-table.report-series tr { grid-template-columns: repeat(6, minmax(0, 1fr)); align-items: baseline; }
  .report-table.report-summary td, .report-table.report-series td { grid-column: span 2; }
  .report-table.report-summary td:first-child, .report-table.report-series td:first-child { grid-column: span 3; order: -2; font-size: 15px; }
  .report-table.report-summary td:nth-child(2), .report-table.report-series td:nth-child(4) { grid-column: span 3; order: -1; justify-self: end; text-align: right;
    font-size: 16px; font-weight: 700; }
  .report-table.report-summary td:nth-child(2)[data-label]::before, .report-table.report-series td:nth-child(4)[data-label]::before { display: none; }
  .report-table.report-summary td.report-narrow-hide, .report-table.report-summary td.report-wide { display: none; }
  /* По дням: маржа каждого магазина — плашками по три в ряд под цифрами портфеля. */
  .report-table.report-series td.report-wide { grid-column: span 2; padding: 4px 8px; border-radius: var(--r-row);
    font-size: 13px; font-weight: 600; text-align: left; justify-self: stretch; min-width: 0; }
  .report-table.report-series td.report-wide[data-label]::before { color: inherit; opacity: .75; overflow: hidden;
    text-overflow: ellipsis; white-space: nowrap; }
  /* Магазины: четыре числа (выручка, ЧП, ДРР, реклама) — в один ряд. */
  .report-table.report-summary tr { grid-template-columns: repeat(12, minmax(0, 1fr)); }
  .report-table.report-summary td { grid-column: span 3; }
  .report-table.report-summary td:first-child, .report-table.report-summary td:nth-child(2) { grid-column: span 6; }
  .report-table.report-summary .report-margin { display: inline; }
  .report-table.report-summary .report-margin .report-dpp { display: inline; }
  /* Без отрицательных полей: строка шире таблицы давала боковую прокрутку. */
  .report-table tbody tr[data-shop] { padding-left: 8px; padding-right: 8px; border-radius: var(--r-row); }
  .report-table tbody tr[data-shop]:active { background: var(--card-hover); }
  .report-table tbody tr[data-shop]:hover td { background: none; }
  .report-table.report-series td.report-heat { padding: 2px 10px; border-radius: var(--r-pill); }
  .report-table.report-series td:first-child a { display: inline-block; padding: 6px 0; }

  /* Товары: сначала маржа, ДРР и ЧП, потом остальное. */
  .report-table.report-problems td:nth-child(n+5):nth-child(-n+7), .report-table.report-all td:nth-child(n+6) { order: 1; }
  .report-table.report-problems td.report-why { order: 2; }
  .report-table.report-problems td:nth-child(n+2):nth-child(-n+4), .report-table.report-problems td:nth-child(n+9),
  .report-table.report-all td:nth-child(n+2):nth-child(-n+5) { order: 3; }

  /* Один товар в разных магазинах: название и разброс, под ними магазины. */
  .report-table.report-cross td:first-child { grid-column: span 2; }
  .report-table.report-cross td:nth-child(3) { order: -1; grid-column: 3; text-align: right; }
  .report-table.report-cross td:first-child { order: -2; }
  .report-table.report-cross .report-chip { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; margin: 0 0 6px; padding: 8px 12px; }
  .report-table.report-cross .report-chip .report-link { white-space: nowrap; }
  .report-table.report-cross .report-chip small { flex: 1 1 100%; }

  /* Окна отчёта: почти на весь экран; шапку с крестиком рисует stockModal. */
  .stock-modal:has(> .report-modal) { padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom)); }
  .modal-card.stock-wide.report-modal { width: 100%; max-height: 100%; padding: 0 14px 14px; }
  .report-modal > .modal-title { position: sticky; top: 0; z-index: 2; margin: 0; padding: 16px 0 10px;
    background: var(--surface); font-size: 18px; line-height: 1.3; }
  .report-modal .modal-actions { flex-wrap: nowrap; }
  .stock-modal .report-modal .modal-actions > * { flex: 1 1 0; min-width: 0; min-height: 44px; padding-left: 10px; padding-right: 10px; }
  .report-modal .stock-explain { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .report-modal .stock-explain .kpi { container-type: inline-size; min-width: 0; }
  .report-modal .stock-explain .kpi .v { font-size: min(20px, 15.5cqi); white-space: nowrap; }
  .report-modal .stock-explain .kpi .report-dpp { white-space: normal; }
  .report-modal-head .ghost { margin-left: 0; flex: 1 1 auto; }
  .report-modal .report-why .badge { white-space: normal; }
  /* Реклама без заказов: шапка карточки в столбик, список магазинов на ширину строки. */
  #report-root .report-card { padding: 16px 14px 12px; }
  #report-root .report-card-head { flex-direction: column; gap: 10px; }
  #report-root .report-card-total { align-items: flex-start; }
  #report-root .report-pick { flex: 1 1 100%; }
  #report-root .report-pick-btn { width: 100%; min-height: 44px; justify-content: space-between; }
  #report-root .report-pick-menu { width: 100%; box-sizing: border-box; }
  #report-root .report-pick-menu button { min-height: 44px; }
  /* Один товар в разных магазинах: столбцы плашек — на всю ширину. */
  .report-table.report-cmp-table td:nth-child(2), .report-table.report-cmp-table td:nth-child(3) { grid-column: 1 / -1; }
  .report-cmp { white-space: normal; flex-wrap: wrap; }
  /* Новинки: лента заказов по дням — на всю ширину карточки, а не в узкой ячейке. */
  .report-table.report-novelty td:last-child { grid-column: 1 / -1; }
}
