:root {
  --bg: #f5f6f8; --card: #fff; --text: #1d2330; --muted: #6b7280; --line: #e3e6eb;
  --primary: #2f5bd3; --primary-h: #2449ad; --danger: #c62828;
  --sio: #1b7f5a; --sio-bg: #e5f5ee; --zus: #8a4fbf; --zus-bg: #f2eafa;
  --red: #d32f2f; --red-bg: #ffe5e5;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; }
h1, h2 { margin: 0; }
.muted { color: var(--muted); } .small { font-size: 12px; } .center { text-align: center; }
.error { color: var(--danger); min-height: 1.2em; margin: 8px 0 0; }
.red-text { color: var(--red); }
.spacer { flex: 1; }

.btn { border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 7px 14px;
  border-radius: 6px; cursor: pointer; font: inherit; }
.btn:hover { border-color: #c4c9d2; }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-h); }
.btn.danger { color: var(--danger); border-color: #f0c2c2; }
.btn.ghost { background: transparent; }
.btn.link { border: 0; background: none; color: var(--muted); padding: 6px 0; }

input, select, textarea { font: inherit; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #b8c8f3; border-color: var(--primary); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label.chk { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 14px; }
label.chk input { width: auto; }

/* topbar */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 20px; background: var(--card); border-bottom: 1px solid var(--line); }
.topbar h1 { font-size: 18px; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
main { padding: 16px 20px 40px; }

/* liczniki */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-left: 5px solid var(--muted); border-radius: 8px; padding: 12px 16px; }
.stat h2 { font-size: 15px; margin-bottom: 4px; }
.stat p { margin: 0; }
.stat strong { font-size: 20px; }
.stat.sio { border-left-color: var(--sio); } .stat.sio h2 { color: var(--sio); }
.stat.zus { border-left-color: var(--zus); } .stat.zus h2 { color: var(--zus); }
.stat.other strong { font-size: 15px; }

/* toolbar */
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar input[type=search] { max-width: 320px; }
.toolbar select { width: auto; }

/* tabela */
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: 8px; overflow: auto; max-height: calc(100vh - 290px); }
table { border-collapse: collapse; width: 100%; white-space: nowrap; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; }
th { position: sticky; top: 0; background: #eef0f4; font-size: 12px; text-transform: uppercase; letter-spacing: .02em; z-index: 1; }
#tbl tbody tr { cursor: pointer; }
#tbl tbody tr:hover { background: #f3f6fd; }
#tbl td:first-child, #tbl th:first-child { position: sticky; left: 0; background: inherit; font-weight: 600; }
#tbl th:first-child { z-index: 2; background: #eef0f4; }
#tbl tbody tr td:first-child { background: var(--card); }
#tbl tbody tr:hover td:first-child { background: #f3f6fd; }
tr.inactive td { color: #a0a6b1; text-decoration: line-through; }
td.clip { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }

.tag { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; }
.tag.sio { color: var(--sio); background: var(--sio-bg); }
.tag.zus { color: var(--zus); background: var(--zus-bg); }

/* < 2,5 roku */
.date-young { color: #fff; background: var(--red); padding: 2px 7px; border-radius: 4px; font-weight: 700;
  box-shadow: 0 0 0 2px var(--red-bg), 0 0 8px rgba(211, 47, 47, .55); animation: glow 1.6s ease-in-out infinite alternate; }
@keyframes glow { from { box-shadow: 0 0 0 2px var(--red-bg), 0 0 3px rgba(211,47,47,.35); } to { box-shadow: 0 0 0 2px var(--red-bg), 0 0 10px rgba(211,47,47,.8); } }
@media (prefers-reduced-motion: reduce) { .date-young { animation: none; } }
.legend { margin-top: 8px; }

/* dialogi */
dialog { border: 0; border-radius: 10px; padding: 20px 22px; width: min(860px, 96vw); max-height: 94vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(20, 25, 35, .45); }
dialog h2 { font-size: 18px; margin-bottom: 14px; }
#dlg-pass { width: min(420px, 96vw); } #dlg-pass label { margin-bottom: 10px; }
.wide-dlg { width: min(1100px, 96vw); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px 14px; margin-bottom: 12px; }
.grid .wide { grid-column: span 2; }
@media (max-width: 560px) { .grid .wide { grid-column: auto; } }
form > label.wide { margin-bottom: 10px; }
fieldset.dotacja { border: 1px solid var(--line); border-radius: 8px; display: flex; gap: 18px; padding: 8px 14px 10px; margin: 0 0 12px; }
fieldset.dotacja legend { font-size: 12px; color: var(--muted); padding: 0 4px; }
.zus-box { background: var(--zus-bg); padding: 10px 12px; border-radius: 8px; }
.hint { font-size: 11px; color: var(--sio); min-height: 1em; }
.hint.bad { color: var(--red); font-weight: 600; }
.dlg-actions { display: flex; gap: 8px; align-items: center; margin-top: 14px; }

/* logowanie */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 28px; width: min(400px, 100%); }
.login-card h1 { font-size: 20px; margin-bottom: 18px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
.login-card img { display: block; margin: 6px auto; border: 1px solid var(--line); border-radius: 6px; }
.login-card code { font-size: 13px; word-break: break-all; color: var(--text); }
.login-card p { margin: 0; }
