/* Raporty (reports.js): lista po lewej, podgląd z wykresem i tabelą, edytor (kreator / SQL / wykres), harmonogram. */
:root {
  /* Kolory serii wykresu – stała kolejność (sprawdzona paleta, rozróżnialna przy daltonizmie); tekst zawsze w kolorach tekstu */
  --rpt-c1: #2a78d6;
  --rpt-c2: #eb6834;
  --rpt-c3: #1baf7a;
  --rpt-c4: #eda100;
}
@media (prefers-color-scheme: dark) {
  :root { --rpt-c1: #3987e5; --rpt-c2: #d95926; --rpt-c3: #199e70; --rpt-c4: #c98500; }
}

.rpt { display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: 28px; align-items: start; }
.rpt-main { min-width: 0; display: flex; flex-direction: column; gap: 16px; }

/* ---------------------------------------------------------------- lista */
.rpt-side { position: sticky; top: 0; display: flex; flex-direction: column; gap: 12px; max-height: calc(100vh - 140px); }
.rpt-side-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; }
.rpt-side-head h2 { font-size: 26px; }
.rpt-new { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 10px; background: var(--primary-bg); color: var(--primary-text);
  font-weight: 600; font-size: 13px; }
.rpt-new:hover { text-decoration: none; filter: brightness(1.15); }
.rpt-new .ic { margin: 0; }
.rpt-search-wrap { position: relative; }
.rpt-search-wrap .ic { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); margin: 0; pointer-events: none; }
.rpt-search { padding-left: 34px; border-radius: 12px; }
.rpt-list { overflow: auto; display: flex; flex-direction: column; gap: 14px; padding: 2px 4px 12px 0; }
.rpt-group-head { display: flex; align-items: center; gap: 8px; font: 500 10.5px/1.4 var(--font-mono); text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); padding: 0 8px 6px; }
.rpt-group-head .ic { margin: 0; width: 14px; height: 14px; }
.rpt-count { margin-left: auto; font-size: 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 0 7px; }
.rpt-item { position: relative; display: grid; gap: 1px; padding: 9px 30px 9px 12px; border-radius: 12px; color: var(--text); border: 1px solid transparent;
  transition: background .12s, border-color .12s; }
.rpt-item:hover { text-decoration: none; background: var(--surface); border-color: var(--border); }
.rpt-item.active { background: var(--surface); border-color: var(--border-strong); box-shadow: inset 3px 0 0 var(--signal), var(--shadow); }
.rpt-item-name { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rpt-item-sub { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rpt-item-flag { position: absolute; right: 10px; top: 10px; color: var(--muted); }
.rpt-item-flag .ic { margin: 0; width: 14px; height: 14px; }
.rpt-none { padding: 8px; }

/* ---------------------------------------------------------------- strona główna */
.rpt-hero { position: relative; overflow: hidden; display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 18px;
  padding: 30px 32px; border-radius: 22px; background: var(--side-bg); color: var(--side-text); }
.rpt-hero::after { content: ""; position: absolute; right: -80px; top: -120px; width: 320px; height: 320px; border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--signal) 55%, transparent), transparent 70%); opacity: .45; pointer-events: none; }
.rpt-hero h2 { font-size: 40px; color: #fff; }
.rpt-hero p { max-width: 640px; color: var(--side-muted); margin: 10px 0 0; line-height: 1.55; }
.rpt-hero-text, .rpt-hero-actions { position: relative; z-index: 1; }
.rpt-hero-actions { display: flex; gap: 10px; align-items: center; }
.rpt-hero button.primary { background: var(--signal); border-color: var(--signal); color: var(--signal-ink); }
.rpt-eyebrow { font: 500 11px/1.4 var(--font-mono); text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin-bottom: 6px; }
.rpt-hero .rpt-eyebrow { color: var(--signal); }
.rpt-gallery-section h4 { margin-top: 8px; }
.rpt-gallery { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.rpt-tile { display: flex; flex-direction: column; gap: 6px; padding: 18px; border-radius: 18px; background: var(--surface); border: 1px solid var(--border);
  color: var(--text); transition: transform .15s, box-shadow .15s, border-color .15s; }
.rpt-tile:hover { text-decoration: none; transform: translateY(-2px); border-color: var(--border-strong); box-shadow: var(--shadow); }
.rpt-tile:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.rpt-tile strong { font-family: var(--font-display); font-size: 16px; letter-spacing: -.01em; }
.rpt-tile-icon { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--text); margin-bottom: 4px; }
.rpt-tile-icon .ic { margin: 0; width: 19px; height: 19px; }
.rpt-tile-go { margin-top: auto; padding-top: 6px; font-size: 12px; font-weight: 600; }

/* ---------------------------------------------------------------- nagłówek i pasek raportu */
.rpt-back { font-size: 13px; color: var(--muted); align-self: flex-start; }
.rpt-head { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.rpt-head-icon { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; background: var(--side-bg); color: var(--signal); flex: none; }
.rpt-head-icon .ic { margin: 0; width: 24px; height: 24px; }
.rpt-head-text { flex: 1 1 320px; min-width: 0; }
.rpt-head-text p { margin: 8px 0 0; max-width: 760px; line-height: 1.5; }
.rpt-toolbar, .rpt-savebar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; border-radius: 16px; }
.rpt-savebar { position: sticky; bottom: 0; z-index: 3; }
.rpt-toolbar-left, .rpt-toolbar-right { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.rpt-toolbar-left > .ic { color: var(--muted); margin: 0 2px 0 4px; }
.rpt-period { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.rpt-period select { width: auto; min-width: 190px; }
.rpt-range { display: inline-flex; align-items: center; gap: 6px; }
.rpt-range[hidden] { display: none; }
.rpt-range input { width: auto; }
.rpt-strip { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; padding: 10px 14px; border-radius: 12px; font-size: 13px;
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--signal) 45%, var(--border)); }
.rpt-strip .ic { margin: 0; }

/* ---------------------------------------------------------------- wynik */
.rpt-result { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.rpt-result:empty { display: none; }
.rpt-stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.rpt-stat { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; border-radius: 16px; background: var(--surface); border: 1px solid var(--border); }
.rpt-stat-label { font: 500 10.5px/1.4 var(--font-mono); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.rpt-stat strong { font: 650 18px/1.25 var(--font-display); letter-spacing: -.01em; }
.rpt-note { padding: 10px 14px; border-radius: 12px; font-size: 13px; border: 1px solid var(--border); background: var(--surface-2); }
.rpt-note.warn { border-color: color-mix(in srgb, var(--warn) 45%, transparent); background: color-mix(in srgb, var(--warn) 9%, var(--surface)); }
.rpt-skeleton { display: flex; align-items: center; gap: 14px; padding: 28px; border-radius: 18px; border: 1px dashed var(--border-strong); }
.rpt-skeleton .spinner { width: 24px; height: 24px; border-color: var(--border); border-top-color: var(--text); }
.rpt-error { display: flex; gap: 12px; padding: 16px 18px; border-radius: 16px; color: var(--text);
  border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent); background: color-mix(in srgb, var(--danger) 7%, var(--surface)); }
.rpt-error > .ic { color: var(--danger); width: 22px; height: 22px; margin: 0; }
.rpt-error p { margin: 4px 0 0; white-space: pre-wrap; }
.rpt-table { border-radius: 18px; overflow: hidden; box-shadow: none; }
.rpt-table-scroll { overflow: auto; max-height: 70vh; }
.rpt-table table { font-size: 13px; }
.rpt-table th { padding: 0; z-index: 1; border-bottom: 1px solid var(--border-strong); }
.rpt-table td { padding: 9px 12px; }
.rpt-table tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.rpt-table tbody tr:hover td { background: var(--surface-2); }
.rpt-th { width: 100%; justify-content: flex-start; border: none; border-radius: 0; background: none; padding: 10px 12px; font: inherit; color: inherit;
  text-transform: inherit; letter-spacing: inherit; gap: 4px; }
th.num .rpt-th { justify-content: flex-end; }
.rpt-th:hover { background: var(--surface-2); color: var(--text); }
th.sorted { color: var(--text); }
.rpt-arrow { min-width: 8px; }
.rpt-more { display: flex; justify-content: center; }
.rpt-more:not(:empty) { padding: 10px; border-top: 1px solid var(--border); }
.rpt-sql summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.rpt-sql pre, .rpt-sql-out { white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin: 8px 0 0; font-size: 12.5px; }

/* ---------------------------------------------------------------- wykres */
.rpt-chart { position: relative; padding: 18px 20px 12px; border-radius: 18px; box-shadow: none; }
.rpt-chart-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; margin-bottom: 6px; }
.rpt-chart-head strong { font-family: var(--font-display); font-size: 15px; }
.rpt-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 4px 0 8px; font-size: 12.5px; }
.rpt-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.rpt-legend-item i, .rpt-tip i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.rpt-plot { width: 100%; overflow: hidden; }
.rpt-svg { display: block; max-width: 100%; height: auto; font-family: var(--font); }
.rpt-svg .rpt-grid { stroke: var(--border); stroke-width: 1; }
.rpt-svg .rpt-axis { stroke: var(--border-strong); stroke-width: 1; }
.rpt-svg .rpt-tick, .rpt-svg .rpt-label { fill: var(--muted); font-size: 11px; }
.rpt-svg .rpt-mark { transition: opacity .12s; }
.rpt-svg .rpt-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.rpt-svg .rpt-dot { stroke: var(--surface); stroke-width: 2; }
.rpt-svg .rpt-hit { fill: transparent; cursor: crosshair; }
/* Kolory serii jako klasy – CSP panelu (style-src 'self') nie pozwala na atrybut style w SVG */
.rpt-svg .rpt-f1 { fill: var(--rpt-c1); } .rpt-svg .rpt-f2 { fill: var(--rpt-c2); } .rpt-svg .rpt-f3 { fill: var(--rpt-c3); } .rpt-svg .rpt-f4 { fill: var(--rpt-c4); }
.rpt-svg .rpt-s1 { stroke: var(--rpt-c1); } .rpt-svg .rpt-s2 { stroke: var(--rpt-c2); } .rpt-svg .rpt-s3 { stroke: var(--rpt-c3); } .rpt-svg .rpt-s4 { stroke: var(--rpt-c4); }
.rpt-svg .rpt-areafill { opacity: .16; }
.rpt-svg .rpt-cross { stroke: var(--border-strong); stroke-dasharray: 3 3; }
.rpt-tip { position: absolute; z-index: 5; pointer-events: none; min-width: 140px; padding: 9px 12px; border-radius: 10px; font-size: 12.5px;
  background: var(--surface); border: 1px solid var(--border-strong); box-shadow: var(--shadow); color: var(--text); }
.rpt-tip strong { display: block; margin-bottom: 4px; }
.rpt-tip div { display: flex; align-items: center; gap: 6px; }
.rpt-tip b { margin-left: auto; padding-left: 10px; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- edytor */
.rpt-card { padding: 20px 22px; border-radius: 18px; box-shadow: none; }
.rpt-card .subtabs { margin-top: 0; }
.rpt-share { display: flex; flex-direction: column; justify-content: center; gap: 2px; }
.rpt-builder { display: flex; flex-direction: column; gap: 16px; }
.rpt-step { display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 14px; }
.rpt-step-no { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font: 600 13px var(--font-display);
  background: var(--side-bg); color: var(--signal); }
.rpt-step-body { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.rpt-step:last-of-type .rpt-step-body { border-bottom: none; }
.rpt-step-body > label { width: min(520px, 100%); }
.rpt-step-body h3 { margin: 3px 0 0; font-size: 15px; }
.rpt-row { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: flex-end; width: 100%; padding: 10px 12px; border-radius: 12px; background: var(--surface-2);
  border: 1px solid var(--border); }
.rpt-row > label { flex: 1 1 150px; min-width: 0; }
.rpt-row > label.rpt-grow { flex: 2 1 220px; }
.rpt-row > label.check { flex: 0 0 auto; padding-bottom: 8px; }
.rpt-remove { align-self: center; margin-top: 18px; }
.rpt-remove .ic { margin: 0; }
.rpt-sql-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.rpt-editor { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.rpt-code-wrap { display: flex; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--surface); }
.rpt-code-wrap:focus-within { border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 28%, transparent); }
.rpt-gutter { flex: none; min-width: 40px; padding: 12px 8px; text-align: right; white-space: pre; overflow: hidden; user-select: none;
  font: 13px/1.6 var(--font-mono); color: var(--muted); background: var(--surface-2); border-right: 1px solid var(--border); }
.rpt-code { flex: 1; min-height: 320px; border: none; border-radius: 0; padding: 12px 14px; font: 13px/1.6 var(--font-mono); resize: vertical; tab-size: 4;
  white-space: pre; overflow: auto; box-shadow: none !important; }
.rpt-schema-panel { display: flex; flex-direction: column; gap: 8px; max-height: 520px; padding: 12px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--border); }
.rpt-schema-panel h3 { font-size: 14px; margin: 0; }
.rpt-schema-list { overflow: auto; display: flex; flex-direction: column; gap: 4px; }
.rpt-schema summary { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 2px; flex-wrap: wrap; }
.rpt-schema .hint { margin: 2px 0 6px 4px; }
.rpt-schema ul { list-style: none; margin: 0 0 8px; padding: 0 0 0 10px; display: flex; flex-direction: column; gap: 2px; }
.rpt-schema li { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; font-size: 12px; }
.rpt-ins { padding: 1px 6px; border-radius: 6px; font-size: 12px; border: 1px solid transparent; background: none; }
.rpt-ins:hover { border-color: var(--border-strong); background: var(--surface); }
.rpt-schema summary .rpt-ins { font-weight: 600; font-size: 12.5px; }
.rpt-type { font: 500 10px/1.4 var(--font-mono); color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.rpt-chart-form { display: flex; flex-direction: column; gap: 10px; }
.rpt-checks { display: flex; flex-wrap: wrap; gap: 6px 18px; }

/* ---------------------------------------------------------------- telefon */
@media (max-width: 1100px) {
  .rpt-sql-grid { grid-template-columns: 1fr; }
  .rpt-schema-panel { max-height: 360px; }
}
@media (max-width: 860px) {
  .rpt { grid-template-columns: 1fr; gap: 16px; }
  .rpt-side { position: static; max-height: none; }
  .rpt-list { max-height: 50vh; }
  .rpt.rpt-open .rpt-side { display: none; }
  .rpt-hero { padding: 22px 20px; }
  .rpt-hero h2 { font-size: 30px; }
  .rpt-period select { min-width: 0; flex: 1 1 160px; }
  .rpt-toolbar-right, .rpt-toolbar-left { width: 100%; }
  .rpt-toolbar-right button { flex: 1 1 auto; }
  .rpt-step { grid-template-columns: 1fr; }
  .rpt-step-no { display: none; }
  .rpt-card { padding: 16px; }
  .rpt-table-scroll { max-height: none; }
}
@media (min-width: 861px) { .rpt-back[href="#/reports"]:first-child { display: none; } }

/* ---------------------------------------------------------------- edytor SQL: kolorowanie i podpowiedzi */
.rpt-code-layers { position: relative; flex: 1; min-width: 0; display: flex; }
.rpt-code-layers > textarea.rpt-code { position: relative; z-index: 1; background: transparent; color: transparent; caret-color: var(--text); }
.rpt-code-layers > textarea.rpt-code::selection { background: color-mix(in srgb, var(--focus) 30%, transparent); color: transparent; }
.rpt-paint { position: absolute; inset: 0; margin: 0; min-height: 0; overflow: hidden; pointer-events: none; color: var(--text); background: var(--surface); resize: none; }
:root { --hl-k: #1d4ed8; --hl-s: #047857; --hl-n: #b45309; --hl-c: #6b7280; --hl-p: #7c3aed; --hl-t: #0f766e; }
@media (prefers-color-scheme: dark) { :root { --hl-k: #7aa7ff; --hl-s: #5fd3a5; --hl-n: #f0b25a; --hl-c: #8b929b; --hl-p: #c4a5ff; --hl-t: #5ed6c9; } }
.hl-k { color: var(--hl-k); font-weight: 600; }
.hl-s, .hl-i { color: var(--hl-s); }
.hl-n { color: var(--hl-n); }
.hl-c { color: var(--hl-c); font-style: italic; }
.hl-p { color: var(--hl-p); font-weight: 600; }
.hl-t { color: var(--hl-t); font-weight: 600; }
.rpt-suggest { position: absolute; z-index: 5; min-width: 220px; max-width: 360px; max-height: 240px; overflow: auto; margin: 0; padding: 4px; list-style: none;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px; box-shadow: var(--shadow); }
.rpt-suggest[hidden] { display: none; }
.rpt-suggest li { display: flex; justify-content: space-between; gap: 12px; padding: 5px 8px; border-radius: 7px; cursor: pointer; font-size: 13px; }
.rpt-suggest li.active, .rpt-suggest li:hover { background: var(--accent-soft); }
.rpt-suggest-kind { color: var(--muted); font-size: 11px; }

/* ---------------------------------------------------------------- parametry, przegląd uprawnień, rozliczenia, kafelek pulpitu */
.rpt-params { display: inline-flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.rpt-params-slot { display: contents; }
.rpt-param { display: inline-flex; flex-direction: column; gap: 2px; }
.rpt-param select, .rpt-param input { width: auto; min-width: 160px; max-width: 240px; }
.rpt-act-col { width: 1%; text-align: right; }
/* Kolumna działań (np. „Odbierz dostęp”) przyklejona do prawej krawędzi przewijanej tabeli */
td.rpt-act-col, th.rpt-act-col { position: sticky; right: 0; background: var(--card, var(--surface, #fff)); box-shadow: -8px 0 8px -8px rgba(0, 0, 0, .18); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.rpt-billing-link { border: 1px dashed var(--border-strong); }
.rpt-billing-link .ic { width: 14px; height: 14px; margin: 0 2px 0 0; vertical-align: -2px; }
.rpt-strip.warn { background: color-mix(in srgb, var(--warn) 10%, var(--surface)); border-color: color-mix(in srgb, var(--warn) 50%, var(--border)); }
.rpt-strip.ok { background: color-mix(in srgb, var(--ok) 9%, var(--surface)); border-color: color-mix(in srgb, var(--ok) 45%, var(--border)); }
.rpt-changed td { background: color-mix(in srgb, var(--warn) 8%, transparent); }
.rpt-changed .badge { margin-left: 8px; }
.rpt-closure-list { margin: 0; padding-left: 18px; display: grid; gap: 4px; }
.rpt-closures h3 { font-size: 14px; margin: 0 0 8px; }
.rpt-tile-head { display: grid; gap: 1px; color: var(--text); margin-bottom: 6px; }
.rpt-tile-head:hover { text-decoration: none; }
.rpt-mini-chart { padding: 0; border: none; box-shadow: none; background: transparent; }
.rpt-mini-chart .rpt-chart-head { display: none; }
.rpt-mini-chart .rpt-plot { min-height: 150px; }
.rpt-mini-table { width: 100%; font-size: 12.5px; border-collapse: collapse; }
.rpt-mini-table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 11px; padding: 3px 6px; border-bottom: 1px solid var(--border); }
.rpt-mini-table td { padding: 4px 6px; border-bottom: 1px solid var(--border); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }
.rpt-mini-table .num { text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 860px) {
  .rpt-param select, .rpt-param input { min-width: 0; width: 100%; max-width: none; }
  .rpt-params { width: 100%; }
}
