:root {
  --accent: #009edb; --accent-d: #0283b6; --accent-l: #e6f6fd;
  --bg: #f4f7fa; --surface: #ffffff; --text: #1e293b; --muted: #64748b; --line: #e2e8f0;
  --ok: #15803d; --ok-bg: #dcfce7; --warn: #b45309; --warn-bg: #fef3c7; --err: #b91c1c; --err-bg: #fee2e2;
  --info: #1d4ed8; --info-bg: #dbeafe; --shadow: 0 1px 2px rgba(15,23,42,.06), 0 4px 16px rgba(15,23,42,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a; --surface: #172033; --text: #e2e8f0; --muted: #94a3b8; --line: #263247; --accent-l: #0b3a52;
    --ok-bg: #12351f; --ok: #6ee7a0; --warn-bg: #3d2c0b; --warn: #fbbf24; --err-bg: #3f1616; --err: #fca5a5;
    --info-bg: #172a52; --info: #93c5fd; --shadow: none; color-scheme: dark;
  }
  .brand img, .login img { filter: brightness(1.15); }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); margin: 0 0 6px; }
.muted { color: var(--muted); } .small { font-size: 12.5px; } .mono { font-family: Consolas, "SFMono-Regular", monospace; font-size: 12.5px; }
.right { text-align: right; } .nowrap { white-space: nowrap; } .break { word-break: break-all; }
.ok-text { color: var(--ok); } .err-text { color: var(--err); }

.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 24px;
  background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 600; font-size: 16px; }
.brand img { height: 26px; }
.top nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.top nav a { padding: 6px 12px; border-radius: 6px; color: var(--muted); font-weight: 500; }
.top nav a.active, .top nav a:hover { background: var(--accent-l); color: var(--accent); text-decoration: none; }
.mode { font-size: 12px; padding: 4px 10px; border-radius: 99px; font-weight: 600; }
.mode-off { background: var(--line); color: var(--muted); } .mode-test, .mode-demo { background: var(--warn-bg); color: var(--warn); }
.mode-prod { background: var(--ok-bg); color: var(--ok); }

.wrap { max-width: 1280px; margin: 0 auto; padding: 22px 24px 40px; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 12px 0 24px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 16px; }
.stat { display: flex; flex-direction: column; gap: 2px; margin: 0; }
.stat span { color: var(--muted); font-size: 12.5px; } .stat b { font-size: 28px; line-height: 1.2; } .stat small { color: var(--muted); }
.stat.warn { border-left: 4px solid var(--warn); } .stat.err { border-left: 4px solid var(--err); }
.stat form { margin-top: 4px; }

.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tbody tr:hover { background: var(--accent-l); }
.tbl.compact td, .tbl.compact th { padding: 6px 8px; }
.tbl tfoot td { font-weight: 600; border-bottom: 0; }
.tbl th.right { text-align: right; }
.scroll { overflow-x: auto; }
.empty { color: var(--muted); padding: 18px 0; text-align: center; }

.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); } .pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.err { background: var(--err-bg); color: var(--err); } .pill.info { background: var(--info-bg); color: var(--info); }
.pill.muted { background: var(--line); color: var(--muted); }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 4px; background: var(--line); color: var(--muted); margin-left: 6px; font-weight: 600; }
.tag.err { background: var(--err-bg); color: var(--err); } .tag.warn { background: var(--warn-bg); color: var(--warn); }
.warn-text { color: var(--warn); }

.btn { display: inline-block; font: inherit; font-weight: 600; font-size: 13px; padding: 7px 14px; border-radius: 7px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; } .btn.primary:hover { background: var(--accent-d); color: #fff; }
.btn.ghost { background: transparent; } .btn.small { padding: 4px 10px; font-size: 12.5px; } .btn.wide { width: 100%; padding: 10px; }
.btn.busy { opacity: .6; cursor: progress; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }
form { margin: 0; }
input[type=search], input[type=email], input[type=password], select {
  font: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); color: var(--text); }
input:focus, select:focus { outline: 2px solid var(--accent-l); border-color: var(--accent); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; } .filters input { min-width: 260px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.inline-form { display: flex; align-items: flex-end; gap: 8px; margin-top: 12px; } .inline-form label { flex: 1; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; border: 1px solid transparent; }
.flash-ok { background: var(--ok-bg); color: var(--ok); } .flash-warn { background: var(--warn-bg); color: var(--warn); }
.flash-err { background: var(--err-bg); color: var(--err); }

.crumbs { margin: 0 0 10px; }
.inv-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; flex-wrap: wrap; margin-bottom: 16px; }
.inv-head .amount { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.inv-head .amount span:first-child { color: var(--muted); font-size: 12.5px; } .inv-head .amount b { font-size: 26px; }
.grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.parties { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 14px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; margin: 0 0 14px; }
.kv dt { color: var(--muted); font-size: 12.5px; } .kv dd { margin: 0; word-break: break-all; }
.list { list-style: none; padding: 0; margin: 12px 0 0; } .list li { padding: 6px 0; border-top: 1px solid var(--line); }
.timeline { list-style: none; padding: 0; margin: 0; max-height: 360px; overflow: auto; }
.timeline li { padding: 6px 0 6px 12px; border-left: 2px solid var(--accent-l); margin-left: 4px; font-size: 13px; }
.pdf-pages { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.pdf-pages a { display: block; width: 100%; max-width: 860px; }
img.pdf-page { display: block; width: 100%; height: auto; background: #fff; border: 1px solid var(--line); border-radius: 6px;
  box-shadow: 0 2px 10px rgba(15,23,42,.08); cursor: zoom-in; }
.center { text-align: center; margin: 0 0 10px; }
pre.log { background: var(--bg); padding: 12px; border-radius: 8px; max-height: 420px; overflow: auto; font-size: 12px; white-space: pre-wrap; }

.login { max-width: 360px; margin: 10vh auto; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 28px; box-shadow: var(--shadow); text-align: center; }
.login img { height: 40px; } .login h1 { margin: 6px 0 18px; font-weight: 500; color: var(--muted); }
.login form { display: flex; flex-direction: column; gap: 14px; text-align: left; }

@media (max-width: 900px) {
  .grid { grid-template-columns: 1fr; } .parties { grid-template-columns: 1fr; }
  .wrap { padding: 14px; } .top { padding: 10px 14px; } .filters input { min-width: 0; width: 100%; }
}
.src { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 0; font-family: Consolas, "SFMono-Regular", "DejaVu Sans Mono", monospace; font-size: 12px; line-height: 1.4; }
.src .l { white-space: pre; padding: 0 12px; min-width: max-content; }
.src .l.add { background: var(--ok-bg); }
.src .l.del { background: var(--err-bg); text-decoration: line-through; opacity: .85; }
.legend { display: inline-block; padding: 1px 8px; border-radius: 4px; margin-left: 6px; }
.legend.add { background: var(--ok-bg); } .legend.del { background: var(--err-bg); text-decoration: line-through; }

/* ---- okno potwierdzenia ---- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: center; justify-content: center;
  z-index: 100; opacity: 0; transition: opacity .15s; padding: 16px; }
.modal-backdrop.open { opacity: 1; }
.modal { background: var(--surface); color: var(--text); border-radius: 12px; padding: 22px 24px 18px; width: min(460px, 100%);
  box-shadow: 0 20px 50px rgba(15, 23, 42, .3); transform: translateY(8px); transition: transform .15s; }
.modal-backdrop.open .modal { transform: none; }
.modal h3 { margin: 0 0 8px; font-size: 17px; text-transform: none; letter-spacing: 0; color: var(--text); }
.modal p { margin: 0 0 18px; color: var(--muted); line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.btn.danger { background: #dc2626; border-color: #dc2626; color: #fff; } .btn.danger:hover { background: #b91c1c; color: #fff; }

/* ---- okienko postępu (u góry strony) ---- */
.progress-panel { position: fixed; top: 64px; left: 50%; transform: translate(-50%, -12px); width: min(560px, calc(100vw - 24px));
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 16px 40px rgba(15, 23, 42, .22);
  z-index: 90; opacity: 0; transition: opacity .2s, transform .2s; }
.progress-panel.open { opacity: 1; transform: translate(-50%, 0); }
.pp-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.pp-title { flex: 1; }
.pp-close { border: 0; background: none; font-size: 20px; line-height: 1; cursor: pointer; color: var(--muted); }
.pp-list { padding: 6px 14px; max-height: 50vh; overflow: auto; }
.pp-row { padding: 8px 0; border-bottom: 1px solid var(--line); } .pp-row:last-child { border-bottom: 0; }
.pp-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; } .pp-line .pill { margin-left: auto; }
.pp-msg { color: var(--muted); margin-top: 2px; word-break: break-word; }
.pp-foot { display: flex; justify-content: flex-end; align-items: center; gap: 8px; padding: 0 14px; flex-wrap: wrap; }
.pp-foot:not(:empty) { padding: 10px 14px 12px; border-top: 1px solid var(--line); } .pp-foot p { margin: 0; flex: 1; }
.spinner { width: 18px; height: 18px; border: 2.5px solid var(--accent-l); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.pp-icon { width: 20px; height: 20px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; color: #fff; }
.pp-icon.ok { background: var(--ok); } .pp-icon.err { background: #dc2626; } .pp-icon.warn { background: #d97706; }
