/* Цвета и шрифты — фирменный стиль PIM (аналитический портал логистической вертикали).
   Раскладка повторяет Looker Studio: шапка, список страниц слева, холст фиксированного размера,
   элементы на координатах LS. Цвета, заданные в самом отчёте LS, переводятся в палитру PIM в app.js (pimColor). */
:root {
  color-scheme: light;
  --pim: #FECC00; --pim-dk: #e0b400; --pim-tint: #fff8e6;
  --ink: #0b0b0b; --ink2: #52514e; --muted: #898781;
  --grid: #e6e5e0; --axis: #c3c2b7; --line: rgba(11, 11, 11, .10);
  --surface: #ffffff; --plane: #f4f4f2; --plane2: #ecebe7;
  --s1: #c98500; --s2: #2a78d6; --s3: #1baf7a; --s4: #4a3aa7; --s5: #e34948; --s6: #008300;
  --good: #0ca30c; --goodink: #006300; --crit: #d03b3b; --negink: #a32020;
  --r: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --shadow: 0 2px 2px 0 rgba(11,11,11,.10), 0 1px 1px 0 rgba(11,11,11,.14), 0 1px 5px 0 rgba(11,11,11,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--plane); color: var(--ink); font: 13px/1.35 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--s2); text-decoration: none; }
button, select, input { font: inherit; color: inherit; }

/* ---------- каркас: шапка + страницы слева + область отчёта ---------- */
.ls { display: flex; flex-direction: column; height: 100vh; }
.ls-top { flex: none; height: 56px; display: flex; align-items: center; gap: 10px; padding: 0 16px; background: var(--ink); color: #fff; border-bottom: 1px solid var(--ink); }
.ls-logo { display: flex; }
.pim-logo { width: 30px; height: 30px; flex: 0 0 30px; background: var(--pim); position: relative; overflow: hidden; border-radius: 3px; }
.pim-logo::before { content: ""; position: absolute; inset: 0; background:
  linear-gradient(148deg, #0b0b0b 0 42%, transparent 42.6%),
  linear-gradient(148deg, transparent 0 46%, #fff 46% 52%, transparent 52.6%); }
.ls-report { font-size: 18px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ls-top-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.ls-fresh { color: #e9e8e2; font-size: 12px; white-space: nowrap; }
.ls-fresh b { color: var(--pim); font-weight: 600; }
.ls-user { color: #e9e8e2; font-size: 12px; white-space: nowrap; }
.ls-user a, .hchip.user a { color: var(--pim); font-weight: 600; }
.ls-reset { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px; border: 1px solid var(--pim-dk); border-radius: 18px; background: var(--pim); color: var(--ink); cursor: pointer; font-weight: 600; }
.ls-reset:hover { background: var(--pim-dk); }
.ls-body { flex: 1; display: flex; min-height: 0; }
.ls-nav { flex: none; width: 224px; overflow: auto; background: var(--surface); border-right: 1px solid var(--line); padding: 8px 12px 8px 0; }
.ls-nav-item { display: block; padding: 11px 12px 11px 20px; border-radius: 0 20px 20px 0; color: var(--ink2); font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ls-nav-item:hover { background: var(--plane2); color: var(--ink); }
.ls-nav-item.active { background: var(--pim); color: var(--ink); }
.ls-nav-item.todo { color: var(--muted); }
.ls-main { flex: 1; overflow: auto; padding: 16px; }

/* ---------- холст страницы ---------- */
.ls-page { position: relative; margin: 0 auto; background: var(--surface); box-shadow: 0 1px 3px rgba(11,11,11,.12); font-family: var(--font); color: var(--ink); }
.ls-el { position: absolute; }
.ls-text { padding: 8px; font-size: 14px; line-height: normal; word-wrap: break-word; }
.ls-text font[size="1"] { font-size: 10px; } .ls-text font[size="2"] { font-size: 13px; } .ls-text font[size="3"] { font-size: 16px; }
.ls-text font[size="4"] { font-size: 18px; } .ls-text font[size="5"] { font-size: 24px; } .ls-text font[size="6"] { font-size: 32px; }
.ls-text a { color: var(--s2); }
.ls-table, .ls-pivot { display: flex; flex-direction: column; }
.ls-combo { background: var(--surface); }
.ls-table.loading::after, .ls-pivot.loading::after, .ls-combo.loading::after { content: ""; position: absolute; inset: 0; background: rgba(255,255,255,.55); }
.ls-flow { max-width: 1760px; margin: 0 auto; background: var(--surface); box-shadow: 0 1px 3px rgba(11,11,11,.12); padding: 14px 20px 24px; }
.ls-flow-heading { margin: 0; font-size: 20px; font-weight: 700; color: var(--ink); }
.note { color: var(--muted); font-size: 12px; }

/* ---------- контролы (выпадающие списки) ---------- */
.ctl { position: relative; width: 100%; height: 100%; }
.ctl-btn { width: 100%; height: 100%; display: flex; align-items: center; gap: 8px; padding: 0 12px 0 20px; background: var(--surface); border: 0; border-radius: 0; box-shadow: var(--shadow); cursor: pointer; text-align: left; font-size: 14px; font-weight: 500; color: var(--ink); }
.ctl-btn:hover { background: var(--plane); }
.ctl-text { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ctl-text .ctl-val { font-size: 12px; font-weight: 600; color: var(--ink); background: var(--pim-tint); padding: 1px 6px; border-radius: 999px; }
.ctl-arrow { flex: none; width: 0; height: 0; border-left: 4px solid transparent; border-right: 4px solid transparent; border-top: 5px solid var(--ink2); }
.ctl-btn.date { font-size: 13px; color: var(--ink2); }

.popup { position: absolute; top: calc(100% + 2px); left: 0; z-index: 50; width: max(100%, 300px); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 24px rgba(11,11,11,.18); padding: 8px 0; }
.popup.right { left: auto; right: 0; }
.popup .search { display: block; width: calc(100% - 24px); margin: 0 12px 6px; padding: 6px 8px; border: 0; border-bottom: 1px solid var(--line); outline: none; }
.popup .search:focus { border-bottom-color: var(--pim-dk); }
.options { max-height: 320px; overflow: auto; }
.option { display: flex; gap: 10px; align-items: center; padding: 6px 16px; cursor: pointer; font-size: 13px; }
.option:hover, .option.current { background: var(--plane2); }
.option input { accent-color: var(--pim-dk); margin: 0; }
.option .opt-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.option .opt-metric { color: var(--muted); font-variant-numeric: tabular-nums; }
.option .only { display: none; border: 0; background: none; color: var(--s2); cursor: pointer; font-size: 12px; padding: 0 4px; }
.option:hover .only { display: inline; }
.popup-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; padding: 8px 12px 0; border-top: 1px solid var(--line); margin-top: 6px; }
.popup-actions .muted { margin-right: auto; }
.popup-actions button, .presets .chip { border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 600; padding: 6px 10px; border-radius: 8px; cursor: pointer; }
.popup-actions button:hover, .presets .chip:hover { background: var(--plane2); }
.popup-actions button.primary { background: var(--pim); border-color: var(--pim-dk); }
.popup-actions button.primary:hover { background: var(--pim-dk); }
.presets { display: flex; flex-wrap: wrap; gap: 4px; padding: 0 8px 8px; }
.range { display: flex; gap: 6px; align-items: center; padding: 0 12px 8px; }
.range input { flex: 1; min-width: 0; padding: 4px 6px; border: 1px solid var(--line); border-radius: 8px; }

/* ---------- инструменты элемента (появляются при наведении) ---------- */
.card-tools { position: absolute; top: -30px; right: 0; display: none; gap: 4px; z-index: 6; }
.ls-el:hover > .card-tools, .card-tools:focus-within { display: flex; }
.ls-table::before, .ls-pivot::before { content: ""; position: absolute; left: 0; right: 0; top: -34px; height: 34px; }
.tool-btn { height: 28px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); cursor: pointer; font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; }
.tool-btn:hover { background: var(--plane2); }
.ctl.tool { width: auto; height: auto; }

/* ---------- таблица ---------- */
.table-wrap { flex: 1; min-height: 0; overflow: auto; }
table.grid { border-collapse: separate; border-spacing: 0; width: 100%; font-variant-numeric: tabular-nums; font-size: 12px; }
.grid th, .grid td { padding: 0 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grid td { height: 31px; border-bottom: 1px solid var(--line); color: var(--ink); }
.grid thead th { position: sticky; top: 0; z-index: 2; height: 42px; background: var(--head); color: var(--ink); font: 700 var(--head-fs, 14px)/1.15 var(--font); text-align: left; vertical-align: middle; }
.grid.wrap thead th { white-space: normal; }
table.grid.fixed { table-layout: fixed; }
.grid td { max-width: 400px; }
.grid th.sortable { cursor: pointer; user-select: none; }
.grid th .sort { font-size: 10px; margin-left: 2px; }
.grid th.num, .grid td.num { text-align: right; }
.grid tbody tr:nth-child(odd) td { background: var(--odd); }
.grid tbody tr:nth-child(even) td { background: var(--even); }
.grid tbody tr:hover td { background: var(--plane2); }
.grid td.neg { color: var(--negink); }
.grid td.null { color: var(--muted); }
.grid .rownum { width: 40px; text-align: left; padding-right: 4px; color: var(--muted); }
.grid tfoot td { position: sticky; bottom: 0; z-index: 1; height: 28px; background: var(--bg, var(--surface)); font-weight: 700; border-bottom: 0; border-top: 1px solid var(--axis); }
.grid tfoot .total-label { text-align: right; }
.table-foot { flex: none; display: flex; justify-content: flex-end; align-items: center; gap: 12px; height: 26px; padding: 0 6px; font-size: 12px; color: var(--ink2); }
.table-foot .timing { margin-right: auto; opacity: 0; color: var(--muted); }
.ls-table:hover .table-foot .timing { opacity: 1; }
.pager { display: inline-flex; gap: 4px; align-items: center; }
.pager button { border: 0; background: none; width: 22px; height: 22px; cursor: pointer; font-size: 15px; color: var(--ink2); border-radius: 50%; }
.pager button:hover:not(:disabled) { background: var(--plane2); }
.pager button:disabled { opacity: .35; cursor: default; }

/* ---------- сводная таблица ---------- */
table.pivot { border-collapse: separate; border-spacing: 0; font-variant-numeric: tabular-nums; font-size: var(--pv-fs, 12px); min-width: 100%; }
.pivot th, .pivot td { height: 29px; padding: 0 16px 0 8px; white-space: nowrap; border-bottom: 1px solid var(--pv-line, var(--grid)); }
.pivot thead th { position: sticky; z-index: 2; background: var(--pv-bg, var(--surface)); color: var(--ink2); font-size: 13px; font-weight: 500; text-align: right; }
.pivot thead tr:nth-child(1) th { top: 0; }
.pivot thead tr:nth-child(2) th { top: 24px; }
.pivot thead tr:nth-child(3) th { top: 54px; }
.pivot .pv-title th { height: 24px; background: var(--pv-head, var(--pim)); color: var(--ink); font-weight: 700; text-align: left; border-bottom: 0; }
.pivot .pv-rowhead { text-align: left; font-size: var(--pv-head-fs, 14px); color: var(--ink2); left: 0; z-index: 3; }
.pivot th.pv-row { position: sticky; left: 0; z-index: 1; background: var(--pv-bg, var(--surface)); text-align: left; font-weight: 400; color: var(--ink2); font-size: 13px; max-width: 320px; overflow: hidden; text-overflow: ellipsis; border-right: 1px solid var(--axis); }
.pivot td { text-align: right; color: var(--ink); position: relative; }
.pivot tbody tr:hover td, .pivot tbody tr:hover th.pv-row { background: var(--plane2); }
.pivot td.neg .v { color: var(--negink); }
.pivot td.total, .pivot th.total { font-weight: 700; color: var(--ink); }
.pivot tfoot th, .pivot tfoot td { position: sticky; bottom: 0; background: var(--pv-bg, var(--surface)); font-weight: 700; border-top: 1px solid var(--axis); }
.pivot tfoot .total-label { text-align: right; color: var(--ink2); font-size: 13px; left: 0; z-index: 2; }
.pivot td .v { position: relative; }
.trunc { font-size: 11px; color: var(--muted); padding: 2px 6px; }

/* ---------- комбинированная диаграмма ---------- */
svg.combo { display: block; font-family: var(--font); }
svg.combo .axis { font-size: 12px; fill: var(--muted); }
svg.combo .legend { font-size: 12px; fill: var(--ink2); }
svg.combo .hit:hover { fill: rgba(11,11,11,.15); }

.muted { color: var(--muted); }
.pad { padding: 8px 16px; }
.error { color: var(--crit); font-size: 12px; }
.empty { padding: 24px; text-align: center; color: var(--muted); }

/* ---------- стартовая страница: выбор отчёта ---------- */
.home { min-height: 100vh; display: flex; flex-direction: column; }
.home-top { background: var(--ink); color: #fff; padding: 14px 24px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.home-top .pim-logo { width: 38px; height: 38px; flex-basis: 38px; }
.brand b { font-size: 16px; letter-spacing: .02em; }
.brand div { font-size: 11.5px; color: #bdbcb6; letter-spacing: .06em; text-transform: uppercase; }
.home-top .spacer { flex: 1; }
.hchip { font-size: 11.5px; color: #e9e8e2; border: 1px solid rgba(255,255,255,.25); border-radius: 999px; padding: 4px 10px; }
.hchip b { color: var(--pim); }
.home-bar { background: var(--surface); border-bottom: 1px solid var(--line); padding: 12px 24px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.home-bar label { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.home-bar input[type=search] { font: 500 13px var(--font); padding: 7px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); width: min(460px, 100%); outline: none; }
.home-bar input[type=search]:focus { border-color: var(--pim-dk); box-shadow: 0 0 0 3px rgba(254,204,0,.25); }
.home-bar .count { margin-left: auto; font-size: 12px; color: var(--ink2); }
.home-main { flex: 1; width: 100%; max-width: 1560px; margin: 0 auto; padding: 20px 24px 60px; }
.grp { font: 700 11px var(--font); letter-spacing: .09em; text-transform: uppercase; color: var(--ink2); margin: 20px 0 10px; display: flex; align-items: center; gap: 10px; }
.grp:first-child { margin-top: 4px; }
.grp::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.reports-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); }
.rcard { background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--pim); border-radius: var(--r); padding: 16px 18px 14px; display: flex; flex-direction: column; gap: 10px; }
.rcard:hover { box-shadow: 0 6px 24px rgba(11,11,11,.08); }
.rcard .hd { display: flex; align-items: flex-start; gap: 10px; }
.rcard h2 { margin: 0; font-size: 17px; letter-spacing: .01em; }
.rcard h2 a { color: var(--ink); }
.rcard h2 a:hover { text-decoration: underline; text-decoration-color: var(--pim); text-decoration-thickness: 2px; }
.rcard .sub { color: var(--ink2); font-size: 12.5px; margin-top: 3px; }
.rcard .sp { flex: 1; }
.badge { font: 600 10px var(--font); letter-spacing: .06em; text-transform: uppercase; padding: 3px 7px; border-radius: 6px; white-space: nowrap; background: var(--plane2); color: var(--ink2); }
.badge.live { background: #e6f5e6; color: var(--goodink); }
.badge.stale { background: #fbe9e9; color: var(--negink); }
.facts { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { display: inline-block; font: 600 11px var(--font); padding: 2px 8px; border-radius: 999px; background: var(--plane2); color: var(--ink2); }
.pill b { color: var(--ink); }
.pages { display: flex; flex-wrap: wrap; gap: 6px; }
.pages a { font: 500 12.5px var(--font); color: var(--ink); background: var(--plane); border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px; }
.pages a:hover { background: var(--pim-tint); border-color: var(--pim-dk); }
.pages a mark { background: var(--pim); color: var(--ink); border-radius: 3px; padding: 0 1px; }
.rcard .ft { display: flex; align-items: center; gap: 10px; margin-top: 2px; }
.rcard .src { font-size: 11px; color: var(--muted); }
.btn { font: 600 12.5px var(--font); padding: 7px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; color: var(--ink); display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { background: var(--plane2); }
.btn.pri { background: var(--pim); border-color: var(--pim-dk); margin-left: auto; }
.btn.pri:hover { background: var(--pim-dk); }
.home-empty { padding: 40px; text-align: center; color: var(--ink2); background: var(--surface); border: 1px dashed var(--axis); border-radius: var(--r); }
.home-foot { padding: 24px; color: var(--muted); font-size: 11.5px; text-align: center; }

/* ---------- вход ---------- */
.login { min-height: 100vh; display: flex; flex-direction: column; }
.login-main { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: min(440px, 100%); background: var(--surface); border: 1px solid var(--line); border-top: 4px solid var(--pim); border-radius: var(--r); padding: 28px 28px 22px; box-shadow: 0 6px 24px rgba(11,11,11,.06); }
.login-card h1 { margin: 0 0 6px; font-size: 20px; }
.login-card p { margin: 0 0 16px; color: var(--ink2); font-size: 13.5px; }
.login-card .domains { display: flex; gap: 6px; flex-wrap: wrap; margin: -6px 0 18px; }
.gbtn { width: 100%; justify-content: center; padding: 11px 14px; font-size: 14px; background: var(--pim); border-color: var(--pim-dk); }
.gbtn:hover { background: var(--pim-dk); }
.gbtn svg { flex: none; }
.login-card .meta { margin: 14px 0 0; font-size: 11.5px; color: var(--muted); text-align: center; }
.flag { font-size: 12.5px; padding: 10px 12px; border-radius: 10px; margin-bottom: 14px; }
.flag.crit { background: #fdecec; border: 1px solid #f0b6b6; color: var(--negink); }
.flag.ok { background: #ecf7ec; border: 1px solid #b6ddb6; color: var(--goodink); }
.flag.warn { background: #fff8e6; border: 1px solid #f2d98a; color: var(--ink2); }

@media (max-width: 800px) {
  .ls-nav { display: none; }
  .ls-main { padding: 8px; }
  .ls-fresh { display: none; }
  .reports-grid { grid-template-columns: 1fr; }
}
