/* Formularze PDF – style aplikacji.
   Kolory z logo (#00A4E1, #848FA8) i gradientu faviconu (#00A3DB → #00488A). Czcionki lokalne (bez Google Fonts – RODO). */
@font-face { font-family: 'Figtree'; font-style: normal; font-weight: 400; font-display: swap; src: url(../fonts/figtree-latin-ext-400-normal.woff2) format('woff2'); unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: 'Figtree'; font-style: normal; font-weight: 400; font-display: swap; src: url(../fonts/figtree-latin-400-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Figtree'; font-style: normal; font-weight: 500; font-display: swap; src: url(../fonts/figtree-latin-ext-500-normal.woff2) format('woff2'); unicode-range: U+0100-02AF, U+1E00-1E9F, U+20A0-20C0, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: 'Figtree'; font-style: normal; font-weight: 500; font-display: swap; src: url(../fonts/figtree-latin-500-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+20AC, U+2122, U+FEFF, U+FFFD; }
@font-face { font-family: 'Figtree'; font-style: normal; font-weight: 600; font-display: swap; src: url(../fonts/figtree-latin-ext-600-normal.woff2) format('woff2'); unicode-range: U+0100-02AF, U+1E00-1E9F, U+20A0-20C0, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: 'Figtree'; font-style: normal; font-weight: 600; font-display: swap; src: url(../fonts/figtree-latin-600-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+20AC, U+2122, U+FEFF, U+FFFD; }
@font-face { font-family: 'Figtree'; font-style: normal; font-weight: 700; font-display: swap; src: url(../fonts/figtree-latin-ext-700-normal.woff2) format('woff2'); unicode-range: U+0100-02AF, U+1E00-1E9F, U+20A0-20C0, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: 'Figtree'; font-style: normal; font-weight: 700; font-display: swap; src: url(../fonts/figtree-latin-700-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+20AC, U+2122, U+FEFF, U+FFFD; }
@font-face { font-family: 'JetBrains Mono'; font-style: normal; font-weight: 400; font-display: swap; src: url(../fonts/jetbrains-mono-latin-ext-400-normal.woff2) format('woff2'); unicode-range: U+0100-02AF, U+1E00-1E9F, U+20A0-20C0, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: 'JetBrains Mono'; font-style: normal; font-weight: 400; font-display: swap; src: url(../fonts/jetbrains-mono-latin-400-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+20AC, U+2122, U+FEFF, U+FFFD; }
@font-face { font-family: 'JetBrains Mono'; font-style: normal; font-weight: 500; font-display: swap; src: url(../fonts/jetbrains-mono-latin-ext-500-normal.woff2) format('woff2'); unicode-range: U+0100-02AF, U+1E00-1E9F, U+20A0-20C0, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: 'JetBrains Mono'; font-style: normal; font-weight: 500; font-display: swap; src: url(../fonts/jetbrains-mono-latin-500-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+20AC, U+2122, U+FEFF, U+FFFD; }
@font-face { font-family: 'DejaVu Sans PL'; src: url(../fonts/DejaVuSans-PL.ttf) format('truetype'); font-display: swap; }

:root {
  --brand: #00A4E1;
  --brand-mid: #005FA1;
  --brand-deep: #00488A;
  --steel: #848FA8;
  --grad: linear-gradient(135deg, #00A3DB, #00488A);
  --bg: #EDF1F6;
  --surface: #FFFFFF;
  --surface-2: #F5F7FA;
  --ink: #12233A;
  --muted: #5C6A80;
  --line: #D6DEE8;
  --fld: rgba(0, 164, 225, .13);
  --fld-line: rgba(0, 140, 200, .85);
  --chk: rgba(132, 143, 168, .22);
  --chk-line: #6C7891;
  --sel: #00488A;
  --pressed: #00488A;
  --danger: #B93A32;
  --danger-bg: #FBEDEC;
  --ok: #1D7F52;
  --ok-bg: #E7F5EE;
  --warn: #9A6400;
  --warn-bg: #FFF4DE;
  --info-bg: #E5F5FC;
  --on-brand: #FFFFFF;
  --shadow: 0 1px 2px rgba(18, 35, 58, .08), 0 8px 28px rgba(18, 35, 58, .09);
  --font-ui: 'Figtree', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, Consolas, monospace;
  color-scheme: light;
}
/* Motyw: data-theme na <html> (Ustawienia → Ogólne). light = zawsze jasny (domyślnie), dark = zawsze ciemny,
   auto = jak w systemie (telefon może przełączać wieczorem). */
:root[data-theme="dark"] {
  --brand: #22B3EC; --brand-mid: #3C9BE0; --brand-deep: #5AAEF0; --steel: #9AA4BA;
  --bg: #0B131D; --surface: #121D2B; --surface-2: #172434; --ink: #E3EBF4; --muted: #93A1B5; --line: #24354A;
  --fld: rgba(34, 179, 236, .16); --fld-line: rgba(34, 179, 236, .9); --chk: rgba(154, 164, 186, .22); --chk-line: #A9B3C8;
  --sel: #5AAEF0; --pressed: #1A6FBF; --danger: #F07A70; --danger-bg: #3A1C1C; --ok: #4CC08A; --ok-bg: #12301F;
  --warn: #F2B84B; --warn-bg: #33270F; --info-bg: #0F2A3A;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 28px rgba(0, 0, 0, .35);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --brand: #22B3EC; --brand-mid: #3C9BE0; --brand-deep: #5AAEF0; --steel: #9AA4BA;
    --bg: #0B131D; --surface: #121D2B; --surface-2: #172434; --ink: #E3EBF4; --muted: #93A1B5; --line: #24354A;
    --fld: rgba(34, 179, 236, .16); --fld-line: rgba(34, 179, 236, .9); --chk: rgba(154, 164, 186, .22); --chk-line: #A9B3C8;
    --sel: #5AAEF0; --pressed: #1A6FBF; --danger: #F07A70; --danger-bg: #3A1C1C; --ok: #4CC08A; --ok-bg: #12301F;
    --warn: #F2B84B; --warn-bg: #33270F; --info-bg: #0F2A3A;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 28px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font-ui); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand-mid); }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
[hidden] { display: none !important; }
.mono { font-family: var(--font-mono); }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- nagłówek ---------- */
.brandbar {
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding: 10px max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px));
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.brandbar .logo { height: 40px; width: auto; display: block; flex: none; }
.app-id { display: flex; flex-direction: column; gap: 1px; padding-left: 16px; border-left: 1px solid var(--line); min-width: 0; text-decoration: none; color: inherit; }
.app-id b { font-size: 16px; font-weight: 700; letter-spacing: .01em; }
.app-id span { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46ch; }
.brandbar .grow { flex: 1 1 auto; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.nav a { text-decoration: none; color: var(--muted); font-weight: 600; padding: 7px 12px; border-radius: 8px; font-size: 13.5px; }
.nav a:hover { color: var(--ink); background: var(--surface-2); }
.nav a.on { color: var(--brand-deep); background: var(--info-bg); }
.who { display: flex; align-items: center; gap: 10px; padding-left: 12px; border-left: 1px solid var(--line); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--grad); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 12px; flex: none; }
.who .nm { font-weight: 600; font-size: 13px; line-height: 1.2; }
.who .nm small { display: block; color: var(--muted); font-weight: 500; font-size: 11.5px; }

/* ---------- przyciski / formularze ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; font-size: 13.5px; white-space: nowrap;
  text-decoration: none; color: var(--ink);
}
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--grad); border-color: transparent; color: var(--on-brand); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--brand-mid); cursor: pointer; font-weight: 600; font-size: 13px; }
.linkbtn.danger { color: var(--danger); }
.inp, select.inp, textarea.inp {
  height: 38px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); padding: 0 11px; width: 100%; min-width: 0;
}
textarea.inp { height: auto; padding: 8px 11px; }
.inp:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 22%, transparent); }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.field small { color: var(--muted); font-size: 12px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }

/* ---------- strona ---------- */
.wrap { max-width: 1180px; margin: 0 auto; padding: 28px max(16px, env(safe-area-inset-right, 0px)) 60px max(16px, env(safe-area-inset-left, 0px)); display: flex; flex-direction: column; gap: 22px; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.head h1 { margin: 0; font-size: 24px; font-weight: 700; text-wrap: balance; }
.head p { margin: 4px 0 0; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.card > .pad { padding: 20px; }
.card h2 { font-size: 15px; margin: 0 0 14px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }

.alert { padding: 11px 14px; border-radius: 9px; font-size: 13.5px; border: 1px solid transparent; }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert.error { background: var(--danger-bg); color: var(--danger); }
.alert.info { background: var(--info-bg); color: var(--ink); border-color: color-mix(in srgb, var(--brand) 35%, transparent); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }

/* wgrywanie */
.drop {
  border: 2px dashed var(--line); border-radius: 12px; padding: 26px 20px; text-align: center; cursor: pointer; transition: border-color .15s, background .15s;
  display: flex; flex-direction: column; align-items: center; gap: 6px; background: var(--surface);
}
.drop:hover, .drop.on { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 6%, var(--surface)); }
.drop svg { width: 34px; height: 34px; color: var(--brand); }
.drop strong { font-size: 15px; }
.drop input { display: none; }

/* tabela */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
.doc-title { font-weight: 600; color: var(--ink); text-decoration: none; display: block; }
a.doc-title:hover { color: var(--brand-mid); }
.doc-sub { color: var(--muted); font-size: 12px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.chip::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip.ready { background: var(--ok-bg); color: var(--ok); }
.chip.queued, .chip.processing { background: var(--info-bg); color: var(--brand-mid); }
.chip.processing::before { animation: pulse 1s infinite alternate; }
.chip.error { background: var(--danger-bg); color: var(--danger); }
.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 5px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); margin-left: 6px; vertical-align: 1px; }
.tag.shared { color: var(--brand-mid); border-color: color-mix(in srgb, var(--brand) 40%, transparent); }
@keyframes pulse { to { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .chip.processing::before { animation: none; } }
.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filters a { text-decoration: none; padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--muted); border: 1px solid var(--line); background: var(--surface); }
.filters a.on { background: var(--pressed); border-color: transparent; color: #fff; }
details.more { position: relative; }
details.more summary { list-style: none; cursor: pointer; }
details.more summary::-webkit-details-marker { display: none; }
details.more .menu { position: fixed; right: auto; top: 0; left: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 6px; min-width: 210px; max-width: calc(100vw - 24px); z-index: 60; display: flex; flex-direction: column; }
details.more .menu form, details.more .menu a { display: block; }
details.more .menu button, details.more .menu a { width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 6px; cursor: pointer; font-size: 13px; color: var(--ink); text-decoration: none; }
details.more .menu button:hover, details.more .menu a:hover { background: var(--surface-2); }
details.more .menu .danger { color: var(--danger); }

/* logowanie */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-right, 0px)) 24px max(16px, env(safe-area-inset-left, 0px)); background: radial-gradient(1200px 500px at 10% -10%, color-mix(in srgb, var(--brand) 18%, transparent), transparent), var(--bg); }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 30px; display: flex; flex-direction: column; gap: 18px; }
.auth-card .logo { height: 64px; width: auto; align-self: center; }
.auth-card h1 { font-size: 20px; margin: 0; text-align: center; }
.auth-card p.lead { margin: -8px 0 0; color: var(--muted); text-align: center; font-size: 13.5px; }
.auth-card .btn { height: 42px; width: 100%; }
.foot { text-align: center; color: var(--muted); font-size: 12px; }

/* instalator */
.req { display: grid; grid-template-columns: 22px 1fr; gap: 6px 10px; font-size: 13.5px; align-items: start; }
.req .ico { font-weight: 700; }
.req .ok { color: var(--ok); } .req .bad { color: var(--danger); } .req .wrn { color: var(--warn); }

@media (max-width: 760px) {
  .who { border-left: 0; padding-left: 0; }
  .app-id span { max-width: 26ch; }
  .hide-sm { display: none; }
  td, th { padding: 9px 10px; }
}

/* postęp analizy w przeglądarce */
.ana { margin-top: 6px; max-width: 260px; }
.bar { height: 5px; border-radius: 3px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--grad); transition: width .3s; }
.ana-stage { margin-top: 3px; }

/* menu „⋯” ustawiane przez ui.js ponad tabelą */
details.more:not([open]) .menu { display: none; }

/* tabele jako karty na wąskich ekranach – bez poziomego przewijania */
@media (max-width: 760px) {
  .table-wrap { overflow: visible; }
  table.cards, table.cards tbody { display: block; }
  table.cards thead { display: none; }
  table.cards tr { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); align-items: center; }
  table.cards tr:last-child { border-bottom: 0; }
  table.cards td { display: block; padding: 0; border: 0; min-width: 0; }
  table.cards td.c-main { grid-column: 1 / -1; }
  table.cards td.c-main .doc-sub { overflow-wrap: anywhere; }
  table.cards td.c-count { text-align: right; color: var(--muted); font-size: 12.5px; }
  table.cards td.c-count::before { content: attr(data-label) ': '; }
  table.cards td.c-actions { grid-column: 1 / -1; }
  table.cards .row-actions { justify-content: flex-start; }
  table.cards td.hide-sm { display: none; }
  .brandbar .nav { order: 3; width: 100%; }
  .who { order: 4; }
}
html, body { overflow-x: hidden; }

/* ustawienia */
.kv { display: grid; grid-template-columns: minmax(140px, 220px) 1fr; gap: 10px 18px; margin: 0; font-size: 13.5px; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.set-form input[type=range] { width: 100%; accent-color: var(--brand-mid); }
.field .check { font-weight: 400; color: var(--ink); font-size: 13.5px; }
@media (max-width: 560px) { .kv { grid-template-columns: 1fr; gap: 2px; } .kv dd { margin-bottom: 10px; } }

/* ---------- kopie zapasowe ---------- */
.bk-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.bk-head h2 { margin: 0; }
.row-actions form { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
.bk-db { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; color: var(--muted); white-space: nowrap; cursor: pointer; }
