/* ═══════════════ tokeny ═══════════════ */

:root {
  color-scheme: light;

  --plane:      #f9f9f7;
  --surface:    #fcfcfb;
  --wash:       #f0efec;
  --ink:        #0b0b0b;
  --ink-2:      #52514e;
  --muted:      #898781;
  --grid:       #e1e0d9;
  --axis:       #c3c2b7;
  --border:     rgba(11, 11, 11, 0.10);

  --series-1:   #2a78d6;
  --series-fill: rgba(42, 120, 214, 0.10);
  --bar:        rgba(42, 120, 214, 0.14);
  --good:       #006300;
  --bad:        #d03b3b;

  --radius:     10px;
  --gap:        16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --plane:    #0d0d0d;
    --surface:  #1a1a19;
    --wash:     #232322;
    --ink:      #ffffff;
    --ink-2:    #c3c2b7;
    --muted:    #898781;
    --grid:     #2c2c2a;
    --axis:     #383835;
    --border:   rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-fill: rgba(57, 135, 229, 0.12);
    --bar:      rgba(57, 135, 229, 0.18);
    --good:     #0ca30c;
    --bad:      #e66767;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:    #0d0d0d;
  --surface:  #1a1a19;
  --wash:     #232322;
  --ink:      #ffffff;
  --ink-2:    #c3c2b7;
  --muted:    #898781;
  --grid:     #2c2c2a;
  --axis:     #383835;
  --border:   rgba(255, 255, 255, 0.10);
  --series-1: #3987e5;
  --series-fill: rgba(57, 135, 229, 0.12);
  --bar:      rgba(57, 135, 229, 0.18);
  --good:     #0ca30c;
  --bad:      #e66767;
}

/* ═══════════════ podstawy ═══════════════ */

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--plane);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 14px; }
h3 { font-size: 13px; letter-spacing: 0.02em; text-transform: uppercase; color: var(--ink-2); }

button, select, input { font: inherit; color: inherit; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

[hidden] { display: none !important; }

/* ═══════════════ logowanie ═══════════════ */

.login {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: var(--plane); padding: 24px; z-index: 50;
}

.login__card {
  width: 100%; max-width: 340px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 28px; display: flex; flex-direction: column; gap: 6px;
}

.login__mark { margin-bottom: 8px; }
.login__card h1 { font-size: 18px; }
.login__sub { margin: 0 0 14px; color: var(--ink-2); font-size: 13px; }
.login__card label { font-size: 12px; color: var(--ink-2); margin-top: 8px; }
.login__error { color: var(--bad); font-size: 13px; margin: 10px 0 0; }

input, select {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; outline: none;
}
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--series-1); outline-offset: 1px;
}
.login__card input { padding: 9px 11px; }

/* ═══════════════ przyciski ═══════════════ */

.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  border-radius: 8px; padding: 8px 14px; cursor: pointer; font-size: 13px;
  transition: background 0.12s ease;
}
.btn:hover { background: var(--wash); }
.btn--primary { background: var(--series-1); border-color: var(--series-1); color: #fff; }
.btn--primary:hover { filter: brightness(1.08); background: var(--series-1); }
.btn--block { width: 100%; margin-top: 16px; padding: 10px; }
.btn--ghost { color: var(--bad); }

/* ═══════════════ górna belka ═══════════════ */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px; background: var(--surface);
  border-bottom: 1px solid var(--border); flex-wrap: wrap;
}

.topbar__brand { display: flex; align-items: center; gap: 9px; font-weight: 600; }
.topbar__controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.control {
  background: var(--surface); border: 1px solid var(--border); color: var(--ink);
  border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 13px;
}
.control:hover { background: var(--wash); }
.control--icon { width: 32px; height: 32px; display: grid; place-items: center; padding: 0; }

.live {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border: 1px solid var(--border); border-radius: 999px;
  font-variant-numeric: tabular-nums; font-size: 13px; color: var(--ink-2);
}
.live__dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--muted);
}
.live.is-live .live__dot { background: var(--good); animation: pulse 2s ease-in-out infinite; }
.live.is-live { color: var(--ink); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .live.is-live .live__dot { animation: none; } }

/* ═══════════════ układ strony ═══════════════ */

.page { max-width: 1240px; margin: 0 auto; padding: 20px; display: grid; gap: var(--gap); }

/* Bez tego szeroka tabela rozpycha ścieżkę gridu i strona przewija się w bok
   (elementy gridu mają domyślnie min-width: auto). */
.page > *, .grid > *, .tiles > * { min-width: 0; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}

.card__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 12px; flex-wrap: wrap;
}
.card__hint { color: var(--muted); font-size: 12px; }
.card__link { color: var(--ink-2); font-size: 12px; text-decoration: none; border-bottom: 1px solid var(--border); }
.card__link:hover { color: var(--ink); }

.grid {
  display: grid; gap: var(--gap);
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
}

/* ═══════════════ kafelki metryk ═══════════════ */

.tiles {
  display: grid; gap: var(--gap);
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.tile {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; cursor: pointer;
  text-align: left; position: relative; transition: border-color 0.12s ease;
}
.tile:hover { border-color: var(--axis); }
.tile.is-active { border-color: var(--series-1); }
.tile.is-active::before {
  content: ""; position: absolute; inset: -1px auto -1px -1px; width: 3px;
  background: var(--series-1); border-radius: var(--radius) 0 0 var(--radius);
}
.tile[data-static="true"] { cursor: default; }
.tile[data-static="true"]:hover { border-color: var(--border); }

.tile__label { color: var(--ink-2); font-size: 12px; display: block; }
.tile__value { font-size: 26px; font-weight: 600; letter-spacing: -0.01em; display: block; margin-top: 2px; }
.tile__delta { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.tile__delta.is-up { color: var(--good); }
.tile__delta.is-down { color: var(--bad); }

/* ═══════════════ wykres ═══════════════ */

.card--chart { padding-bottom: 10px; }
.chart { position: relative; width: 100%; height: 260px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }

.chart__tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; font-size: 12px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.14); white-space: nowrap;
  transform: translate(-50%, -100%);
}
.chart__tooltip b { font-variant-numeric: tabular-nums; }
.chart__tooltip span { color: var(--ink-2); display: block; }

/* ═══════════════ zakładki i wiersze ═══════════════ */

.tabs { display: flex; gap: 2px; flex-wrap: wrap; }
.tab {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 12px; padding: 4px 8px; border-radius: 6px;
}
.tab:hover { background: var(--wash); color: var(--ink-2); }
.tab.is-active { color: var(--ink); background: var(--wash); }

.rows { display: flex; flex-direction: column; gap: 1px; min-height: 40px; }

.row {
  position: relative; display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 6px 8px; border-radius: 6px; cursor: pointer;
  background: none; border: none; text-align: left; width: 100%; color: inherit;
  overflow: hidden;
}
.row__bar {
  position: absolute; inset: 0 auto 0 0; background: var(--bar);
  border-radius: 6px 4px 4px 6px;
}
.row__label {
  position: relative; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; flex: 1; min-width: 0;
}
.row__value {
  position: relative; font-variant-numeric: tabular-nums; color: var(--ink-2);
  display: flex; gap: 10px; align-items: baseline;
}
.row__pct { color: var(--muted); font-size: 12px; min-width: 42px; text-align: right; }
.row:hover .row__label { text-decoration: underline; text-underline-offset: 2px; }
.row[data-filterable="false"] { cursor: default; }
.row[data-filterable="false"]:hover .row__label { text-decoration: none; }

.empty { color: var(--muted); font-size: 13px; padding: 12px 8px; }

/* ═══════════════ filtry ═══════════════ */

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 6px 4px 12px; font-size: 12px;
}
.chip b { font-weight: 600; }
.chip button {
  background: none; border: none; cursor: pointer; color: var(--muted);
  width: 18px; height: 18px; border-radius: 50%; line-height: 1;
}
.chip button:hover { background: var(--wash); color: var(--ink); }

/* ═══════════════ na żywo ═══════════════ */

.sparkline { height: 44px; margin-bottom: 10px; }
.sparkline svg { display: block; width: 100%; height: 100%; }

/* ═══════════════ tabela ═══════════════ */

.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 720px; }
.table th {
  text-align: left; font-weight: 500; color: var(--muted); font-size: 12px;
  padding: 6px 10px; border-bottom: 1px solid var(--grid);
}
.table td { padding: 7px 10px; border-bottom: 1px solid var(--grid); }
.table tr:last-child td { border-bottom: none; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table td.path { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  display: inline-block; padding: 1px 7px; border-radius: 999px;
  background: var(--wash); font-size: 11px; color: var(--ink-2);
}

.footnote { color: var(--muted); font-size: 12px; margin: 4px 0 24px; max-width: 70ch; }

/* ═══════════════ modal ═══════════════ */

.modal {
  border: 1px solid var(--border); border-radius: 12px; padding: 0;
  background: var(--surface); color: var(--ink);
  width: min(640px, calc(100vw - 32px)); max-height: 86vh; overflow: auto;
}
.modal::backdrop { background: rgba(0, 0, 0, 0.45); }
.modal__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface);
}
.modal__head h2 { font-size: 16px; }
.modal__body { padding: 20px; display: grid; gap: 26px; }
.modal__section { display: grid; gap: 10px; }

.hint { color: var(--ink-2); font-size: 13px; margin: 0; }
.hint code { background: var(--wash); padding: 1px 5px; border-radius: 4px; font-family: var(--mono); font-size: 12px; }

.snippet {
  background: var(--wash); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; overflow-x: auto; margin: 0;
  font-family: var(--mono); font-size: 12px; line-height: 1.6;
}
.snippet--sm { font-size: 11.5px; }
.details summary { cursor: pointer; color: var(--ink-2); font-size: 13px; padding: 4px 0; }

.form-row { display: flex; gap: 8px; flex-wrap: wrap; }
.form-row input { flex: 1 1 180px; }
.form-error { color: var(--bad); font-size: 13px; margin: 0; }
.form-error.is-ok { color: var(--good); }

.site-list { display: grid; gap: 6px; }
.site-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px;
}
.site-item__meta { display: grid; min-width: 0; }
.site-item__meta b { font-size: 13px; }
.site-item__meta span {
  color: var(--muted); font-size: 12px; font-family: var(--mono);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.site-item__actions { display: flex; gap: 6px; flex-shrink: 0; }

@media (max-width: 640px) {
  .page { padding: 14px; }
  .topbar { padding: 10px 14px; }
  .tile__value { font-size: 22px; }
  .chart { height: 210px; }
}
