/* Paddock Group BI — report shell: icon rail, filter pane, visual canvas. */

:root {
  --bg: #f1f3f7;
  --panel: #ffffff;
  --panel-2: #f7f8fb;
  --rail: #1d2433;
  --rail-fg: #9aa6bd;
  --rail-fg-active: #ffffff;
  --fg: #161c28;
  --fg-muted: #5d6880;
  --fg-faint: #8b95aa;
  --line: #dfe3ec;
  --line-soft: #ebeef4;
  --accent: #1f6feb;
  --accent-soft: #e8f0fe;
  --ok: #167d4a;
  --warn: #9a6400;
  --bad: #c22e2e;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
  --radius: 8px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px;
  --rail-w: 72px;
  --filter-w: 300px;
  --font: "Segoe UI", Roboto, "Helvetica Neue", system-ui, -apple-system, sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #11151d;
  --panel: #1a1f29;
  --panel-2: #141922;
  --rail: #0d1117;
  --rail-fg: #8b95aa;
  --fg: #e7ebf3;
  --fg-muted: #9aa6bd;
  --fg-faint: #6e7996;
  --line: #2a3140;
  --line-soft: #222834;
  --accent: #58a6ff;
  --accent-soft: #15283f;
  --ok: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
/* An author `display` beats the UA rule for [hidden], so state it explicitly:
   .login-wrap and .shell are toggled with the hidden attribute. */
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  font-size: 13px;
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- login ---------- */
.login-wrap {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: var(--bg); z-index: 100; padding: var(--s4);
}
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 28px; width: min(360px, 100%); box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 4px; font-size: 20px; font-weight: 600; }
.login-card p { margin: 0 0 20px; color: var(--fg-muted); font-size: 12px; line-height: 1.5; }
.login-card label { display: block; font-size: 11px; color: var(--fg-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .04em; }
.login-card input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 6px; background: var(--panel-2); margin-bottom: 14px;
}
.login-card button {
  width: 100%; padding: 10px; border: 0; border-radius: 6px;
  background: var(--accent); color: #fff; font-weight: 600;
}
.login-err { color: var(--bad); font-size: 12px; margin: 0 0 12px; min-height: 1em; }
.login-langs { display: flex; gap: var(--s2); justify-content: center; margin-top: var(--s4); }
.login-langs button { background: none; border: 1px solid var(--line); color: var(--fg-muted); width: auto; padding: 5px 12px; font-size: 11px; font-weight: 500; }
.login-langs button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }

/* ---------- shell ---------- */
.shell { display: flex; height: 100%; }

.rail {
  width: var(--rail-w); flex: none; background: var(--rail);
  display: flex; flex-direction: column; align-items: stretch; padding: var(--s3) 0;
  overflow-y: auto; scrollbar-width: none;
}
.rail::-webkit-scrollbar { display: none; }
.rail-brand {
  color: #fff; font-weight: 700; font-size: 15px; text-align: center;
  padding: 0 var(--s2) var(--s4); letter-spacing: -.01em; line-height: 1.1;
}
.rail-brand span { display: block; font-size: 9px; font-weight: 400; color: var(--rail-fg); margin-top: 3px; letter-spacing: .02em; }
.rail-btn {
  background: none; border: 0; color: var(--rail-fg); padding: 10px 4px;
  display: grid; gap: 4px; justify-items: center; font-size: 9.5px; line-height: 1.2;
  border-left: 3px solid transparent; text-align: center; width: 100%;
}
.rail-btn svg { width: 19px; height: 19px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.rail-btn:hover { color: #e7ebf3; background: rgba(255, 255, 255, .05); }
.rail-btn[aria-current="page"] { color: var(--rail-fg-active); background: rgba(255, 255, 255, .09); border-left-color: var(--accent); }
.rail-foot { margin-top: auto; display: grid; gap: 2px; padding-top: var(--s3); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  flex: none; background: var(--panel); border-bottom: 1px solid var(--line);
  padding: var(--s3) var(--s4); display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap;
}
.tb-title { flex: 1 1 auto; min-width: 0; }
.tb-actions { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.topbar h1 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: -.01em; }
.topbar .sub { color: var(--fg-muted); font-size: 11.5px; margin: 1px 0 0; }
.spacer { flex: 1; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px;
  border: 1px solid var(--line); border-radius: 100px; font-size: 11px; color: var(--fg-muted);
  background: var(--panel-2); white-space: nowrap;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); flex: none; }
.dot.stale { background: var(--warn); }
.dot.err { background: var(--bad); }
.dot.pulse { animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .dot.pulse { animation: none; } }

.tbtn {
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 11px; font-size: 12px; font-weight: 500; color: var(--fg); white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.tbtn:hover { background: var(--panel-2); border-color: var(--fg-faint); }
.tbtn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.tbtn.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.tbtn svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { background: var(--panel); border: 0; padding: 6px 10px; font-size: 11.5px; font-weight: 500; color: var(--fg-muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }

.body { flex: 1; display: flex; min-height: 0; }

/* ---------- filter pane ---------- */
.filters {
  width: var(--filter-w); flex: none; background: var(--panel);
  border-right: 1px solid var(--line); overflow-y: auto; padding: var(--s4);
}
.filters[hidden] { display: none; }
.filters h2 {
  margin: 0 0 var(--s3); font-size: 11px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--fg-faint); display: flex; align-items: center; gap: var(--s2);
}
.fclose { display: none; padding: 3px 7px; }
.fclose svg { stroke: currentColor; fill: none; stroke-width: 2; }
.fgroup { margin-bottom: var(--s4); padding-bottom: var(--s4); border-bottom: 1px solid var(--line-soft); }
.fgroup:last-child { border-bottom: 0; }
.fgroup > label, .flabel {
  display: block; font-size: 11px; font-weight: 600; color: var(--fg-muted);
  margin-bottom: 6px; letter-spacing: .01em;
}
.presets { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: var(--s2); }
.presets button {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 100px;
  padding: 3px 9px; font-size: 10.5px; color: var(--fg-muted);
}
.presets button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }
.filters input[type="date"], .filters input[type="number"], .filters input[type="text"], .filters select {
  width: 100%; padding: 6px 8px; border: 1px solid var(--line);
  border-radius: 5px; background: var(--panel-2); font-size: 12px; min-width: 0;
}
.timerow { display: grid; grid-template-columns: 1fr auto 1fr; gap: 6px; align-items: center; }
.timerow span { color: var(--fg-faint); font-size: 11px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chips button {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 5px;
  padding: 3px 8px; font-size: 10.5px; color: var(--fg-muted);
}
.chips button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.multi {
  max-height: 168px; overflow-y: auto; border: 1px solid var(--line);
  border-radius: 5px; background: var(--panel-2); padding: 3px;
}
.multi label {
  display: flex; align-items: flex-start; gap: 7px; padding: 4px 6px;
  font-size: 11.5px; border-radius: 4px; cursor: pointer; line-height: 1.35;
}
.multi label:hover { background: var(--line-soft); }
.multi input { margin: 2px 0 0; flex: none; accent-color: var(--accent); }
.multi .mname { min-width: 0; overflow-wrap: anywhere; }
.msum { font-size: 10.5px; color: var(--fg-faint); margin-top: 4px; }
.fsearch { margin-bottom: 5px; }

/* ---------- canvas ---------- */
.canvas { flex: 1; min-width: 0; overflow-y: auto; padding: var(--s4); }
.crossbar {
  display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap;
  margin-bottom: var(--s3); font-size: 11.5px; color: var(--fg-muted);
}
.crossbar[hidden] { display: none; }
.xchip {
  display: inline-flex; align-items: center; gap: 6px; background: var(--accent-soft);
  color: var(--accent); border: 1px solid var(--accent); border-radius: 100px;
  padding: 3px 5px 3px 10px; font-size: 11px; font-weight: 500;
}
.xchip button { background: none; border: 0; color: inherit; font-size: 13px; line-height: 1; padding: 0 3px; }

.kpis {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: var(--s3); margin-bottom: var(--s3);
}
.kpi {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: var(--s3) var(--s4); box-shadow: var(--shadow); min-width: 0;
}
.kpi .k-label { font-size: 10.5px; color: var(--fg-muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 5px; }
.kpi .k-val { font-size: 23px; font-weight: 600; letter-spacing: -.02em; line-height: 1.1; overflow-wrap: anywhere; }
.kpi .k-val small { font-size: 12px; font-weight: 500; color: var(--fg-muted); margin-left: 3px; }
.kpi .k-sub { font-size: 11px; color: var(--fg-muted); margin-top: 5px; display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.delta { font-weight: 600; }
.delta.up { color: var(--ok); }
.delta.down { color: var(--bad); }
.delta.flat { color: var(--fg-faint); }

.grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: var(--s3); align-items: stretch; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: var(--s3) var(--s4) var(--s4); box-shadow: var(--shadow);
  display: flex; flex-direction: column; min-width: 0; grid-column: span 12;
}
.card.c4 { grid-column: span 4; }
.card.c6 { grid-column: span 6; }
.card.c8 { grid-column: span 8; }
.card.c12 { grid-column: span 12; }
@media (max-width: 1180px) { .card.c4, .card.c6, .card.c8 { grid-column: span 12; } }
.card h3 {
  margin: 0 0 2px; font-size: 13px; font-weight: 600; display: flex;
  align-items: center; gap: var(--s2); justify-content: space-between;
}
.card .hint { font-size: 10.5px; color: var(--fg-faint); font-weight: 400; }
.card .note { margin: 0 0 var(--s3); font-size: 11px; color: var(--fg-muted); line-height: 1.45; }
.chart { width: 100%; min-height: 240px; flex: 1; }
.chart.tall { min-height: 320px; }
.chart.short { min-height: 190px; }
.empty { display: grid; place-items: center; min-height: 190px; color: var(--fg-faint); font-size: 12px; }

/* ---------- tables ---------- */
.tbl-wrap { overflow: auto; max-height: 460px; border: 1px solid var(--line-soft); border-radius: 6px; }
table { border-collapse: collapse; width: 100%; font-size: 12px; }
th, td { padding: 7px 10px; text-align: right; white-space: nowrap; }
th:first-child, td:first-child, th.l, td.l { text-align: left; }
thead th {
  position: sticky; top: 0; z-index: 1; background: var(--panel-2);
  color: var(--fg-muted); font-weight: 600; font-size: 11px;
  border-bottom: 1px solid var(--line); user-select: none;
}
thead th.sortable { cursor: pointer; }
thead th.sortable:hover { color: var(--fg); }
thead th .arrow { opacity: .5; font-size: 9px; margin-left: 3px; }
tbody tr { border-bottom: 1px solid var(--line-soft); }
tbody tr:last-child { border-bottom: 0; }
tbody tr:hover { background: var(--panel-2); }
tbody tr.clickable { cursor: pointer; }
td.name { white-space: normal; min-width: 180px; overflow-wrap: anywhere; }
td .ent { color: var(--fg-faint); font-size: 10.5px; }
.bar-cell { position: relative; }
.bar-cell .bg {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  height: 58%; border-radius: 2px; background: var(--accent); opacity: .16;
}
.bar-cell span { position: relative; }
.badge {
  display: inline-block; padding: 1px 7px; border-radius: 100px;
  font-size: 10.5px; font-weight: 500; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--fg-muted);
}
.badge.s-N { border-color: #1f6feb55; color: var(--accent); background: var(--accent-soft); }
.badge.s-C { border-color: #167d4a55; color: var(--ok); background: #167d4a14; }
.badge.s-S { border-color: #9a640055; color: var(--warn); background: #9a640014; }
.badge.s-A { color: var(--fg-faint); }
.flag-warn { color: var(--warn); font-weight: 600; }
.flag-bad { color: var(--bad); font-weight: 600; }
.pager { display: flex; align-items: center; gap: var(--s2); margin-top: var(--s3); font-size: 11.5px; color: var(--fg-muted); flex-wrap: wrap; }

.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--rail); color: #fff; padding: 9px 16px; border-radius: 100px;
  font-size: 12px; box-shadow: var(--shadow); z-index: 90; opacity: 0;
  transition: opacity .25s, transform .25s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

/* ---------- narrow screens ---------- */
@media (max-width: 900px) {
  body { overflow: auto; }
  .shell { flex-direction: column; height: auto; min-height: 100%; }

  /* Nav becomes one horizontal strip. #railPages is a single flex child of
     .rail, so it has to become a row itself or every page button stacks. */
  .rail {
    width: 100%; flex-direction: row; align-items: center;
    padding: var(--s1) var(--s2); gap: var(--s1);
    position: sticky; top: 0; z-index: 30;
    overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch;
  }
  /* Buttons size to their label and never shrink, so Cyrillic labels like
     "Контрагенты" cannot overlap their neighbour; the rail scrolls instead. */
  #railPages { display: flex; gap: var(--s1); flex: 0 0 auto; }
  .rail-brand { display: none; }
  .rail-btn {
    width: auto; flex: 0 0 auto; min-width: 56px; padding: 7px 9px;
    border-left: 0; border-bottom: 3px solid transparent; font-size: 9px;
  }
  .rail-btn span { white-space: nowrap; }
  .rail-btn svg { width: 17px; height: 17px; }
  .rail-btn[aria-current="page"] { border-left-color: transparent; border-bottom-color: var(--accent); }
  .rail-foot { margin-top: 0; margin-left: auto; display: flex; gap: 0; padding-top: 0; flex: 0 0 auto; }

  .body { flex-direction: column; }

  /* Title and freshness share row one; every control sits on row two. */
  .topbar { padding: var(--s2) var(--s3); gap: var(--s2) var(--s2); }
  .topbar h1 { font-size: 15px; }
  .topbar .sub { display: none; }
  .tb-title { flex: 1 1 auto; }
  .tb-actions { flex: 1 0 100%; justify-content: flex-end; gap: var(--s2); }
  .tbtn span { display: none; }           /* icon-only actions, so they fit one row */
  .tbtn { padding: 7px 10px; }
  .pill { font-size: 10.5px; padding: 4px 8px; }

  /* Filters become a drawer over the page instead of a wall above it. */
  .filters {
    position: fixed; inset: 0; z-index: 40;
    width: 100%; max-width: 100%;
    border-right: 0; overflow-y: auto;
    padding: var(--s4) var(--s4) 84px;
    box-shadow: none;
  }
  .filters .fgroup:last-of-type { border-bottom: 0; }
  .filters h2 {
    position: sticky; top: 0; z-index: 1; margin: 0 0 var(--s3);
    background: var(--panel); padding: var(--s2) 0; font-size: 12px;
  }
  .fclose { display: inline-flex; }
  #btnApply {
    position: fixed; left: var(--s4); right: var(--s4);
    bottom: calc(var(--s4) + env(safe-area-inset-bottom, 0px));
    width: auto; z-index: 41; padding: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .22);
  }

  .canvas { overflow: visible; padding: var(--s3); }
  .kpis { grid-template-columns: repeat(auto-fit, minmax(min(100%, 8.5rem), 1fr)); gap: var(--s2); }
  .kpi { padding: var(--s3); }
  .kpi .k-val { font-size: 19px; }
  .kpi .k-label { font-size: 9.5px; }
  .card { padding: var(--s3); }
  .chart { min-height: 210px; }
  .chart.tall { min-height: 250px; }
  .chart.short { min-height: 170px; }
  .tbl-wrap { max-height: 380px; }
  th, td { padding: 6px 8px; }
  td.name { min-width: 150px; }
}

/* Very narrow: let the KPI row breathe as two columns rather than cramming. */
@media (max-width: 420px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi .k-val { font-size: 17px; }
  .rail-btn { min-width: 52px; }
}
