:root {
  /* Kolorystyka PZSS — czerwień #C8102E jest tymczasowa (do potwierdzenia z Księgą Znaku). Kolory tylko przez zmienne. */
  --pzss-red: #C8102E;
  --pzss-red-dark: #9E0C24;
  --pzss-red-darker: #7A0A1C;
  --pzss-red-tint: #FBE9EC;
  --pzss-on-red: #FFFFFF;
  --pzss-text: #1A1A1A;
  --pzss-text-muted: #5B626D;
  --pzss-surface: #FFFFFF;
  --pzss-bg: #F4F5F7;
  --pzss-border: #8A919C;
  --pzss-divider: #D5D9DF;
  --pzss-success: #1E7B45;
  --pzss-success-tint: #E6F2EA;
  --pzss-success-hover: #17633A;
  --pzss-success-active: #124F2E;
  --pzss-warning: #9A5B00;
  --pzss-warning-tint: #FDF1DC;
  --pzss-info: #1F5FA8;
  --pzss-info-tint: #E7F0FA;
  --pzss-info-hover: #184C88;
  --pzss-info-active: #123C6C;

  /* nazwy używane w arkuszu */
  --bg: var(--pzss-bg);
  --surface: var(--pzss-surface);
  --ink: var(--pzss-text);
  --muted: var(--pzss-text-muted);
  --line: var(--pzss-divider);
  --line-soft: var(--pzss-bg);
  --brand: var(--pzss-red);
  --brand-dark: var(--pzss-red-dark);
  --brand-darker: var(--pzss-red-darker);
  --link: var(--pzss-info);
  --brand-2: var(--pzss-red);
  --accent: var(--pzss-on-red);
  --ok: var(--pzss-success);
  --ok-bg: var(--pzss-success-tint);
  --warn: var(--pzss-warning);
  --warn-bg: var(--pzss-warning-tint);
  --err: var(--pzss-red-dark);
  --err-bg: var(--pzss-red-tint);
  --info: var(--pzss-info);
  --info-bg: var(--pzss-info-tint);
  --font: Nunito, "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --late: #6b3fa0;
  --late-bg: #f1e9fb;
  --m-bg: var(--pzss-info-tint);
  --m-ink: var(--pzss-info);
  --k-bg: #fdecf3;
  --k-ink: #a02461;
  --dirty: #fff3b0;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(18, 38, 63, .06), 0 1px 3px rgba(18, 38, 63, .08);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
}
a { color: var(--link); }
h1 { font-size: 22px; margin: 0 0 2px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; margin: 0 0 10px; }
p { margin: 6px 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.strong { font-weight: 700; }
[hidden] { display: none !important; }

/* ---------- Pasek górny ---------- */
.topbar {
  display: flex; align-items: center; gap: 20px;
  background: var(--surface); color: var(--ink); border-bottom: 3px solid var(--brand);
  padding: 0 20px; min-height: 58px;
  position: sticky; top: 0; z-index: 20;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo { width: 40px; height: 40px; object-fit: contain; flex: none; }
.brand-name { font-weight: 700; font-size: 16px; color: var(--ink); }
.brand-sub { font-size: 11px; color: var(--muted); }
.mainnav { display: flex; gap: 2px; flex: 1; flex-wrap: wrap; }
.mainnav a {
  color: var(--muted); text-decoration: none; position: relative;
  padding: 18px 11px 16px; font-size: 13.5px;
  border-bottom: 0;
}
.mainnav a:hover { color: var(--ink); }
.mainnav a.active { color: var(--brand-dark); font-weight: 600; }
.mainnav a.active::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: 0; height: 2px; background: var(--brand); border-radius: 2px; }
.whoami { display: flex; align-items: center; gap: 12px; font-size: 12.5px; }
.who-name { font-weight: 600; }
.who-role { color: var(--muted); font-size: 11.5px; }
.whoami .btn.ghost { color: var(--ink); background: transparent; }

.page { padding: 22px 24px 60px; max-width: 1500px; margin: 0 auto; }
.page-head { margin-bottom: 14px; }
.page-head.row { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.head-sel { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- Przyciski i pola ---------- */
.btn {
  font: inherit; font-size: 13px; font-weight: 500;
  padding: 7px 13px; border-radius: 4px;
  border: 1px solid var(--pzss-border); background: var(--surface); color: var(--ink);
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--pzss-text-muted); background: var(--pzss-bg); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; box-shadow: 0 2px 6px rgba(200, 16, 46, .5); }
.btn.primary:hover:not(:disabled) { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn.primary:active:not(:disabled) { background: var(--brand-darker); border-color: var(--brand-darker); }
.btn.accent { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.accent:hover:not(:disabled) { background: var(--pzss-success-hover); border-color: var(--pzss-success-hover); }
.btn.accent:active:not(:disabled) { background: var(--pzss-success-active); border-color: var(--pzss-success-active); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn.danger, .btn.ghost.danger { color: var(--err); }
.btn.danger:not(.ghost) { border-color: var(--pzss-red-dark); }
.btn.danger:hover:not(:disabled) { background: var(--pzss-red-tint); }
.btn.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.icon-btn { border: 0; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); }

select, input, textarea {
  font: inherit; font-size: 13px; color: var(--ink);
  border: 1px solid var(--pzss-border); border-radius: 6px; padding: 6px 8px; background: var(--surface);
}
select:focus, input:focus, textarea:focus { outline: 2px solid var(--pzss-info); outline-offset: -1px; border-color: var(--pzss-info); }
.field { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 500; }
.field textarea, .field input, .field select { width: 100%; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 14px; }
.form-err { color: var(--err); font-size: 12.5px; min-height: 18px; margin-top: 4px; }
.check { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Karty i układ ---------- */
.card {
  background: var(--surface); border: 0; border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.card.attention { border-left: 4px solid var(--warn); }
.card.danger-zone { border-color: var(--pzss-red-dark); }
.grid2 { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.stack > .card:last-child { margin-bottom: 0; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack > .card { margin-bottom: 0; }
.actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
@media (max-width: 980px) { .grid2 { grid-template-columns: 1fr; } }

.round-list, .plain { list-style: none; padding: 0; margin: 0; }
.round-list li { display: grid; grid-template-columns: 80px auto 1fr; gap: 10px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--line-soft); }
.round-list li:last-child { border-bottom: 0; }
.round-list li .small { text-align: right; }
.plain li { padding: 4px 0; }

.big-countdown { display: flex; flex-direction: column; margin: 8px 0 14px; }
.big-countdown strong { font-size: 30px; font-variant-numeric: tabular-nums; color: var(--brand); letter-spacing: .5px; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 10px; }
.kpis div { background: var(--pzss-bg); border-radius: 6px; padding: 8px 10px; display: flex; flex-direction: column; }
.kpis b { font-size: 18px; color: var(--brand); }
.kpis span { font-size: 11.5px; color: var(--muted); }
.progress { height: 6px; background: var(--line-soft); border-radius: 3px; overflow: hidden; min-width: 80px; }
.progress div { height: 100%; background: var(--ok); }

/* ---------- Plakietki ---------- */
.badge {
  display: inline-block; font-size: 11.5px; font-weight: 600;
  padding: 2px 8px; border-radius: 10px; background: var(--line-soft); color: var(--muted);
  white-space: nowrap;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.draft { background: var(--warn-bg); color: var(--warn); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.err { background: var(--err-bg); color: var(--err); }
.badge.late { background: var(--late-bg); color: var(--late); }
.st-planned { background: var(--pzss-bg); color: var(--pzss-text-muted); }
.st-open { background: var(--pzss-success-tint); color: var(--pzss-success); }
.st-closed { background: var(--warn-bg); color: var(--warn); }
.st-accepted { background: var(--pzss-info-tint); color: var(--pzss-info); }
.st-published { background: var(--ok-bg); color: var(--ok); }
.tag {
  display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 4px;
  background: var(--line-soft); color: var(--muted); font-weight: 600; white-space: nowrap;
}
.tag.late { background: var(--late-bg); color: var(--late); }
.tag.corr { background: var(--err-bg); color: var(--err); }
.tag.c-M { background: var(--m-bg); color: var(--m-ink); }
.tag.c-K { background: var(--k-bg); color: var(--k-ink); }

/* ---------- Komunikaty ---------- */
.notice { padding: 9px 12px; border-radius: 6px; margin: 0 0 12px; border: 1px solid; font-size: 13px; }
.notice.info { background: var(--pzss-info-tint); border-color: var(--pzss-info); }
.notice.warn { background: var(--warn-bg); border-color: var(--warn); }
.notice.late { background: var(--late-bg); border-color: #dccbf0; }
.notice.muted-n { background: var(--pzss-bg); border-color: var(--line); color: var(--muted); }
.card .notice { margin-top: 12px; }
.empty { text-align: center; padding: 50px 20px; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); }
.empty-code { font-size: 42px; font-weight: 800; color: #c2c9d4; }
.empty-cell { text-align: center; color: var(--muted); padding: 24px !important; }

/* ---------- Filtry i paski narzędzi ---------- */
.filters {
  display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 9px 12px; margin-bottom: 10px; font-size: 12.5px; color: var(--muted);
}
.filters label, .flabel { display: flex; align-items: center; gap: 6px; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip {
  font: inherit; font-size: 12px; padding: 3px 9px; border-radius: 12px;
  border: 1px solid var(--pzss-border); background: var(--surface); cursor: pointer; color: var(--ink);
}
.chip.on { background: var(--brand-2); color: #fff; border-color: var(--brand-2); }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
.seg-btns { display: flex; gap: 6px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.seg { display: flex; gap: 18px; margin-bottom: 8px; }
.seg label { display: flex; gap: 6px; align-items: center; }

/* ---------- Tabele ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 12px; }
.card .table-wrap { border: 0; margin: 0; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th {
  background: var(--surface); text-align: left; font-size: 11.5px; font-weight: 600; text-transform: uppercase; color: var(--pzss-text-muted);
  padding: 8px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; letter-spacing: .03em;
  position: sticky; top: 0;
}
.tbl td { padding: 7px 8px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl.compact td, .tbl.compact th { padding: 5px 7px; font-size: 12.5px; }
.tbl tr.inactive td { opacity: .55; }
.row-actions { white-space: nowrap; }
.row-actions .btn { margin-right: 3px; }
.code { font-family: Consolas, "Cascadia Mono", monospace; font-size: 12.5px; white-space: nowrap; }

/* Protokół */
.proto td { padding: 4px 6px; }
.proto tr.g-M td { background: var(--m-bg); }
.proto tr.g-K td { background: var(--k-bg); }
.proto tr.g-M .code { color: var(--m-ink); font-weight: 600; }
.proto tr.g-K .code { color: var(--k-ink); font-weight: 600; }
.proto tr td { border-bottom-color: #fff; }
.proto tr.row-dirty td:first-child { box-shadow: inset 4px 0 0 #e0b400; }
.proto .name { font-weight: 600; min-width: 170px; }
.proto input.series {
  width: 46px; text-align: right; padding: 4px 6px; font-variant-numeric: tabular-nums;
  border-color: #c9d1dd;
}
.proto input.remarks { width: 130px; padding: 4px 6px; }
.proto input.dirty { background: var(--dirty); border-color: #e0b400; }
.proto input.warn { background: var(--warn-bg); border-color: #e39b00; }
.proto input.err { background: var(--err-bg); border-color: var(--err); }
.proto input:disabled { background: rgba(255, 255, 255, .5); border-color: transparent; color: var(--ink); }
.proto td.x { text-align: center; color: #9aa3b1; font-weight: 700; }
.proto td.total { font-weight: 700; font-size: 14.5px; min-width: 56px; }
.proto .meta { font-size: 11px; color: var(--muted); min-width: 190px; line-height: 1.35; }
.proto .group-row td { background: #e6eaf0 !important; font-weight: 700; font-size: 12.5px; }
.row-msg { font-weight: 400; font-size: 11.5px; }
.m-err { color: var(--err); }
.m-warn { color: var(--warn); }
.proto-foot {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 10px;
}
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--muted); align-items: center; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; border: 1px solid rgba(0, 0, 0, .1); }
.sw-M { background: var(--m-bg); }
.sw-K { background: var(--k-bg); }
.sw-dirty { background: var(--dirty); }

/* Wyniki i zestawienie */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin: 4px 0 0; border-bottom: 2px solid var(--line); }
.tab {
  font: inherit; font-size: 13px; padding: 7px 12px; border: 1px solid transparent; border-bottom: 0;
  background: transparent; cursor: pointer; border-radius: 6px 6px 0 0; color: var(--muted);
  margin-bottom: -2px;
}
.tab.on { background: transparent; border-color: transparent; border-bottom: 3px solid var(--brand); color: var(--brand); font-weight: 700; }
.tab.t-M.on { border-bottom-color: var(--m-ink); color: var(--m-ink); }
.tab.t-K.on { border-bottom-color: var(--k-ink); color: var(--k-ink); }
.tab .cnt { font-size: 11px; background: var(--line-soft); padding: 0 6px; border-radius: 8px; margin-left: 3px; }
.comp-title { margin: 14px 0 8px; }
.results td { font-size: 13.5px; }
.results tbody tr:nth-child(-n+3) td:first-child { font-weight: 800; color: var(--brand); }
.ranking td.dropped { color: #a3abb8; text-decoration: line-through; background: #f5f6f8; }
.ranking td.dropped .zero { font-size: 11px; }
.ranking td.future { background: #fafbfc; }
.dropped-sw { color: #a3abb8; text-decoration: line-through; background: #f5f6f8; padding: 1px 5px; border-radius: 3px; }
.tyt {
  text-align: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
}
.tyt-1 { font-size: 13px; color: var(--muted); }
.tyt-2 { font-size: 20px; font-weight: 800; color: var(--brand); }
.tyt-3 { font-size: 15px; font-weight: 600; }
.tyt-4 { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* Rundy */
.rounds .round-row td { background: #fbfcfd; border-top: 1px solid var(--line); }
.rounds .sub > td { padding: 0 8px 10px 28px; }
.tbl.inner { background: #fff; border: 1px solid var(--line-soft); border-radius: 6px; }
.tbl.inner th { background: #f8f9fb; position: static; }
.audit .old { color: var(--err); }
.audit .new { color: var(--ok); }

/* Formularz zawodnika */
.comp-set { border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px; margin: 10px 0 0; }
.comp-set legend { font-size: 12px; color: var(--muted); padding: 0 4px; }
.comp-opt { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 13px; }
.comp-opt.na { opacity: .4; }
.err-list { padding-left: 18px; }
.err-list li { margin: 4px 0; }

/* ---------- Logowanie ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--bg); }
.login-box { background: var(--surface); border: 1px solid var(--line); border-top: 4px solid var(--brand); border-radius: 12px; padding: 28px; width: 100%; max-width: 480px; }
.brand.big .logo { width: 52px; height: 52px; }
.brand.big .brand-name { font-size: 20px; }
.brand.big .brand-sub { opacity: 1; color: var(--muted); font-size: 12px; }
.login-box > p { margin: 14px 0; font-size: 13px; }
.login-list { display: flex; flex-direction: column; gap: 8px; }
.login-card {
  font: inherit; text-align: left; display: flex; gap: 12px; align-items: center;
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: #fff; cursor: pointer;
}
.login-card:hover { border-color: var(--brand); background: var(--pzss-red-tint); }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--brand-2); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }

/* ---------- Modal i toasty ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 460px; max-height: 90vh; display: flex; flex-direction: column; border: 1px solid var(--line); }
.modal.wide { max-width: 640px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; }
.modal-body { padding: 12px 18px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--surface); color: var(--ink); border: 1px solid var(--line); padding: 10px 14px; border-radius: 8px; font-size: 13px; box-shadow: var(--shadow); max-width: 380px; transition: opacity .4s, transform .4s; border-left: 4px solid var(--ok); }
.toast.err { border-left-color: var(--pzss-red-dark); }
.toast.info { border-left-color: var(--pzss-info); }
.toast.hide { opacity: 0; transform: translateY(8px); }

@media (max-width: 700px) {
  .page { padding: 14px 12px 40px; }
  .topbar { padding: 8px 12px; gap: 8px; }
  .mainnav a { padding: 8px 8px; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- Wydruk / PDF ---------- */
@media print {
  .topbar, .toolbar, .filters, .head-sel, .seg-btns, .legend, #toasts, .row-actions, [data-act=saveRow] { display: none !important; }
  body { background: #fff; }
  .page { padding: 0; max-width: none; }
  .table-wrap { border: 0; overflow: visible; }
  .tbl th { position: static; }
  .tyt-2 { font-family: Arial, sans-serif; font-size: 16pt; }
  .proto input { border: 0 !important; background: transparent !important; }
}

/* ---------- Dodatki wersji z API ---------- */
.loading { padding: 40px; text-align: center; color: var(--muted); }
.loading::before {
  content: ""; display: inline-block; width: 16px; height: 16px; margin-right: 8px; vertical-align: -3px;
  border: 2px solid var(--line); border-top-color: var(--brand-2); border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.dev-note { font-size: 12px; background: var(--warn-bg); color: var(--warn); border-radius: 6px; padding: 6px 10px; }
.btn.busy { opacity: .6; pointer-events: none; }

/* ---------- Logowanie, rejestracja, tabela klubów ---------- */
.auth-form h2 { font-size: 17px; margin: 18px 0 6px; }
.auth-form .btn.wide { width: 100%; justify-content: center; margin-top: 6px; padding: 9px; }
.auth-switch { text-align: center; font-size: 13px; margin-top: 14px; }
.login-box .notice { margin: 8px 0; }
.clubs .club-name { width: 100%; min-width: 220px; border-color: transparent; background: transparent; }
.clubs .club-name:hover { border-color: var(--line); background: #fff; }
.clubs .club-name:focus { background: #fff; }
.clubs .club-name.dirty { background: var(--dirty); border-color: #e0b400; }
.import-list { max-height: 50vh; overflow-y: auto; }

/* ---------- Protokoły publiczne (bez logowania) ---------- */
.public-link { display: block; text-align: center; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 13px; font-weight: 600; }
.pub-protocol { margin-bottom: 18px; }
.pub-protocol .comp-title { margin: 10px 0 8px; }
@media print { .pub-protocol { break-inside: avoid-page; } }

/* ---------- Reset rundy ---------- */
.reset-list { margin: 8px 0 10px 4px; }
.reset-list li { padding: 2px 0; }
.btn.danger:not(.ghost):not(:disabled) { background: var(--err); border-color: var(--err); color: #fff; }
