:root {
  --bg: #0d1014;
  --panel: #151a21;
  --panel-2: #1b222b;
  --line: #262f3a;
  --text: #e7ebf0;
  --muted: #98a3b3;
  --accent: #4d7cfe;
  --accent-soft: rgba(77, 124, 254, 0.14);
  --ok: #3fb950;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

button, .btn {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .45rem .8rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  transition: background .15s ease, border-color .15s ease, transform .1s ease;
}
button:hover, .btn:hover { background: #222b36; border-color: #35414f; }
button:active, .btn:active { transform: translateY(1px); }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover, .btn.primary:hover { background: #3f6ff0; }

input[type=text], input[type=email], input[type=search] {
  font: inherit;
  color: var(--text);
  background: #10151b;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .45rem .7rem;
}
input:focus-visible, button:focus-visible, a:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- pasek gorny ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .7rem 1.2rem;
  background: rgba(21, 26, 33, .86);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { font-weight: 650; letter-spacing: .01em; }
.brand small { color: var(--muted); font-weight: 400; margin-left: .5rem; }
.spacer { margin-left: auto; }

.profile { position: relative; }
.profile > button { background: transparent; border-color: transparent; padding: .3rem .5rem; }
.profile img { width: 28px; height: 28px; border-radius: 50%; background: var(--panel-2); }
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + .5rem);
  min-width: 17rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .9rem;
  display: none;
}
.menu[data-open] { display: block; }
.menu h4 { margin: .2rem 0 .5rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.menu ul { margin: 0 0 .8rem; padding-left: 1.1rem; }
.menu .row { display: flex; gap: .4rem; margin-bottom: .6rem; }
.menu .row input { flex: 1; min-width: 0; }

/* ---------- uklad portalu ---------- */
.layout { display: grid; grid-template-columns: 19rem 1fr; min-height: calc(100vh - 3.4rem); }
.sidebar { border-right: 1px solid var(--line); padding: 1rem; overflow-y: auto; max-height: calc(100vh - 3.4rem); position: sticky; top: 3.4rem; }
.sidebar h3 { font-size: .74rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 1.1rem 0 .4rem; }
.sidebar a { display: block; padding: .35rem .55rem; border-radius: 7px; color: var(--text); text-decoration: none; font-size: .93rem; }
.sidebar a:hover { background: var(--panel-2); }
.sidebar a[aria-current] { background: var(--accent-soft); color: #cdd9ff; }

main { padding: 1.4rem 1.8rem 4rem; min-width: 0; }
.docbar { display: flex; align-items: center; gap: .6rem; margin-bottom: 1rem; flex-wrap: wrap; }
.docbar h1 { font-size: 1.25rem; margin: 0; }
iframe.doc {
  width: 100%;
  min-height: 60vh;
  display: block;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
table.sheet { border-collapse: collapse; width: 100%; font-size: .9rem; }
table.sheet td, table.sheet th { border: 1px solid var(--line); padding: .3rem .5rem; text-align: left; }
table.sheet tr:first-child { background: var(--panel-2); font-weight: 600; }

.note { color: var(--muted); }
.warn { background: #2a1e14; border: 1px solid #5a3d1c; color: #f0d6b0; padding: .7rem .9rem; border-radius: var(--radius); margin-bottom: 1rem; }

/* ---------- strona logowania ---------- */
.hero { min-height: 100vh; display: grid; place-items: center; padding: 2rem; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 2.4rem;
  max-width: 26rem;
  text-align: center;
}
.card h1 { margin: 0 0 .4rem; font-size: 1.5rem; }
.card p { color: var(--muted); margin-top: 0; }

/* ---------- panel uprawnien ---------- */
.perm { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table.perm-table { border-collapse: separate; border-spacing: 0; font-size: .88rem; min-width: 100%; }
table.perm-table th, table.perm-table td { border-bottom: 1px solid var(--line); padding: .4rem .6rem; white-space: nowrap; }
table.perm-table thead th { position: sticky; top: 0; background: var(--panel-2); z-index: 2; text-align: center; }
table.perm-table tbody th { position: sticky; left: 0; background: var(--panel); text-align: left; font-weight: 500; max-width: 26rem; overflow: hidden; text-overflow: ellipsis; }
tr.folder th { background: var(--panel-2) !important; font-weight: 650; }
td.cell { text-align: center; }
td.cell label { display: inline-flex; align-items: center; gap: .15rem; margin: 0 .25rem; color: var(--muted); font-size: .76rem; cursor: pointer; }
input[type=checkbox] { accent-color: var(--accent); width: 15px; height: 15px; }
.savebar { display: flex; align-items: center; gap: .8rem; margin: 1rem 0; }
.saved { color: var(--ok); opacity: 0; transition: opacity .3s ease; }
.saved[data-on] { opacity: 1; }

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; max-height: 40vh; overflow-y: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  main { padding: 1rem 1rem 3rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Ukrywanie elementow atrybutem hidden musi wygrac z display:inline-flex przyciskow. */
[hidden] { display: none !important; }

iframe.doc.pdf { height: 85vh; min-height: 0; }

/* ---------- kartoteka ---------- */
.stats { display: flex; gap: .7rem; flex-wrap: wrap; padding: 1rem 1.4rem .2rem; }
.kafel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .6rem .9rem; min-width: 8.5rem; display: flex; flex-direction: column; gap: .1rem;
}
.kafel span { color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; }
.kafel strong { font-size: 1.35rem; font-weight: 600; }

.layout.kadry { grid-template-columns: 22rem 1fr; }
.layout.kadry .sidebar { padding: 1rem; }
.filtry { display: grid; gap: .5rem; margin-bottom: .9rem; }
.filtry select {
  font: inherit; color: var(--text); background: #10151b;
  border: 1px solid var(--line); border-radius: 8px; padding: .4rem .6rem;
}

.osoba {
  width: 100%; display: flex; align-items: center; gap: .7rem; text-align: left;
  background: transparent; border: 1px solid transparent; border-radius: 9px;
  padding: .5rem .6rem; margin-bottom: .15rem;
}
.osoba:hover { background: var(--panel-2); border-color: var(--line); }
.osoba[aria-current] { background: var(--accent-soft); border-color: #33436b; }
.osoba .kto { display: flex; flex-direction: column; min-width: 0; }
.osoba .kto strong { font-weight: 550; }
.osoba .kto small { color: var(--muted); font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.awatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-size: .8rem; font-weight: 650; letter-spacing: .02em;
  background: linear-gradient(145deg, #2b3a55, #1d2633); color: #cfe0ff; border: 1px solid var(--line);
}
.awatar.duzy { width: 56px; height: 56px; font-size: 1.15rem; }
.kropka { width: 9px; height: 9px; border-radius: 50%; margin-left: auto; flex: none; }
.kropka.ok { background: var(--ok); }
.kropka.zle { background: #f05a5a; }
.kropka.ostrzegawczy { background: #e3a13c; }
.kropka.info { background: #4d9ffe; }
.kropka.szary { background: #5b6675; }

.naglowek { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.2rem; flex-wrap: wrap; }
.naglowek h1 { font-size: 1.4rem; margin: 0 0 .15rem; }
.podtytul { color: var(--muted); margin: 0 0 .4rem; }
.etykieta {
  display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--muted); margin-right: .3rem;
}
.etykieta.ok { color: #9ee6ab; border-color: #27502f; background: #16251a; }
.etykieta.zle { color: #f2a6a6; border-color: #5a2626; background: #261616; }
.etykieta.ostrzegawczy { color: #f0d0a0; border-color: #5a441c; background: #251d12; }
.etykieta.info { color: #b9d4ff; border-color: #26405a; background: #141d28; }

.kolumny { display: grid; grid-template-columns: 1fr 1.25fr; gap: 1rem; align-items: start; }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem;
}
.panel h3 { font-size: .76rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 1.1rem 0 .4rem; }
.panel h3:first-child { margin-top: 0; }
.bilans { display: flex; align-items: baseline; gap: .9rem; font-size: 1.1rem; font-weight: 600; }
.bilans .ok { color: var(--ok); }
.bilans .zle { color: #f05a5a; }
.bilans .note { font-size: .85rem; font-weight: 400; }

.nowy-wpis { display: flex; gap: .4rem; margin-bottom: .9rem; }
.nowy-wpis input { flex: 1; min-width: 0; }
.nowy-wpis select { max-width: 9rem; }

ol.historia { list-style: none; margin: 0; padding: 0; }
ol.historia li {
  display: flex; gap: .6rem; align-items: flex-start;
  border-left: 3px solid var(--line); padding: .45rem .7rem; margin-bottom: .4rem;
  background: #131920; border-radius: 0 8px 8px 0;
}
ol.historia li.ok { border-left-color: var(--ok); }
ol.historia li.zle { border-left-color: #f05a5a; }
ol.historia li.info { border-left-color: #4d9ffe; }
ol.historia li div { display: flex; flex-direction: column; gap: .1rem; min-width: 0; }
ol.historia li strong { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
ol.historia li small { font-size: .76rem; }
.usun-wpis { margin-left: auto; padding: 0 .4rem; background: transparent; border-color: transparent; color: var(--muted); }
.usun-wpis:hover { color: #f2a6a6; }
button.niebezpieczny:hover { border-color: #5a2626; color: #f2a6a6; }

/* ---------- okno edycji ---------- */
dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 14px; padding: 1.4rem; max-width: 40rem; width: calc(100% - 2rem); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(4, 6, 9, .66); }
dialog h2 { margin: 0 0 1rem; font-size: 1.15rem; }
.pola { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.pola label, .szeroko { display: flex; flex-direction: column; gap: .25rem; font-size: .82rem; color: var(--muted); }
.pola input, .pola select, .szeroko textarea {
  font: inherit; color: var(--text); background: #10151b;
  border: 1px solid var(--line); border-radius: 8px; padding: .45rem .7rem;
}
.szeroko { margin-top: .7rem; }
fieldset { border: 1px solid var(--line); border-radius: 10px; margin: .9rem 0 0; padding: .6rem .8rem; }
legend { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; }
.chip { display: inline-flex; align-items: center; gap: .3rem; margin: .2rem .5rem .2rem 0; font-size: .85rem; }
.akcje { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.2rem; }
.blad { color: #f2a6a6; margin: .8rem 0 0; }

@media (max-width: 900px) {
  .layout.kadry { grid-template-columns: 1fr; }
  .kolumny { grid-template-columns: 1fr; }
  .pola { grid-template-columns: 1fr; }
}

/* ---------- przelacznik widoku i wykaz ---------- */
.przelacznik { display: inline-flex; gap: .2rem; margin: .9rem 1.4rem .2rem; padding: .2rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.przelacznik button { background: transparent; border-color: transparent; padding: .35rem 1rem; color: var(--muted); }
.przelacznik button[aria-selected="true"] { background: var(--accent-soft); color: #cdd9ff; border-color: #33436b; }

#wykaz { padding: 1rem 1.4rem 3rem; }
.filtry.poziomo { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-bottom: .9rem; }
.filtry.poziomo input[type=search] { min-width: 18rem; flex: 1 1 18rem; }

table.wykaz-tabela { border-collapse: separate; border-spacing: 0; width: 100%; font-size: .9rem; }
table.wykaz-tabela th, table.wykaz-tabela td { padding: .5rem .8rem; border-bottom: 1px solid var(--line); text-align: left; }
table.wykaz-tabela thead th {
  position: sticky; top: 0; background: var(--panel-2); z-index: 2;
  font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); white-space: nowrap;
}
table.wykaz-tabela thead th[data-sort] { cursor: pointer; user-select: none; }
table.wykaz-tabela thead th[data-sort]:hover { color: var(--text); }
table.wykaz-tabela tbody tr { cursor: pointer; }
table.wykaz-tabela tbody tr:hover { background: var(--panel-2); }
table.wykaz-tabela tbody tr:last-child td { border-bottom: 0; }
.bilans-kom span { margin-right: .4rem; font-weight: 600; }
.bilans-kom .ok { color: var(--ok); }
.bilans-kom .zle { color: #f05a5a; }

/* ---------- liczniki i rejestry na karcie ---------- */
.liczniki { display: flex; gap: .6rem; flex-wrap: wrap; margin-bottom: 1rem; }
.licznik {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: .45rem .8rem; min-width: 6rem; display: flex; flex-direction: column;
}
.licznik span { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.licznik strong { font-size: 1.25rem; font-weight: 650; }
.licznik.dobry strong { color: #6fd18a; }
.licznik.zly strong { color: #f07a7a; }

dl.dane { display: flex; gap: 1.6rem; flex-wrap: wrap; margin: 0 0 .4rem; }
dl.dane dt { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
dl.dane dd { margin: 0; }

.rejestry { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; margin-top: 1rem; align-items: start; }
.rejestry .rejestr-przebieg { grid-column: 1 / -1; }
.rejestr-naglowek { display: flex; align-items: center; gap: .6rem; }
.rejestr-naglowek h3 { margin: 0; }
.licznik-maly {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px;
  padding: 0 .5rem; font-size: .78rem; color: var(--muted);
}
.opis-rejestru { font-size: .8rem; margin: .2rem 0 .7rem; }
.rejestr-kary { border-left: 3px solid #7a3636; }
.rejestr-nagrody { border-left: 3px solid #2f6b3c; }
.rejestr-oceny { border-left: 3px solid #35538c; }
.rejestr-notatki { border-left: 3px solid var(--line); }
ol.historia li.dobry { border-left-color: var(--ok); }
ol.historia li.zly { border-left-color: #f05a5a; }
ol.historia li.zwykly { border-left-color: #4d9ffe; }

/* ---------- wykaz: wieksza czytelnosc ---------- */
table.wykaz-tabela tbody tr:nth-child(even) { background: rgba(255, 255, 255, .022); }
table.wykaz-tabela tbody tr:hover { background: var(--accent-soft); }
table.wykaz-tabela tbody td { border-bottom: 1px solid #1d242e; }
table.wykaz-tabela td.osoba-kom strong { font-weight: 600; color: #f2f5f9; }
table.wykaz-tabela td.osoba-kom small { display: block; color: var(--muted); font-size: .76rem; }
table.wykaz-tabela td.liczba { text-align: right; font-variant-numeric: tabular-nums; }
table.wykaz-tabela thead th.liczba { text-align: right; }
.stopien {
  display: inline-block; padding: .05rem .5rem; border-radius: 6px; font-size: .78rem;
  font-weight: 600; letter-spacing: .01em; border: 1px solid;
}
.stopien.dowodztwo { color: #f0cf8a; border-color: #5c4a20; background: #251f12; }
.stopien.nadzor { color: #b9d4ff; border-color: #26405a; background: #141d28; }
.stopien.oficer { color: #cdd6e2; border-color: #2c3542; background: #181d25; }
.stopien.kadet { color: #9aa5b3; border-color: #262d37; background: #14181e; }
.status-kom { display: inline-flex; align-items: center; gap: .4rem; white-space: nowrap; }
.wiersz-nieaktywny td { opacity: .62; }

@media (max-width: 1100px) { .rejestry { grid-template-columns: 1fr; } }

/* ---------- sygnaly z GSOP ---------- */
ul.sygnaly { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: .4rem; }
ul.sygnaly li {
  background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--line);
  border-radius: 0 8px 8px 0; padding: .5rem .8rem; font-size: .9rem;
}
ul.sygnaly li.zle { border-left-color: #f05a5a; background: #211618; }
ul.sygnaly li.ok { border-left-color: var(--ok); background: #16211a; }
ol.historia li.wygasla { opacity: .55; }
.znaczek {
  display: inline-block; margin-left: .4rem; padding: 0 .35rem; border-radius: 5px;
  font-size: .7rem; font-weight: 700; border: 1px solid;
}
.znaczek.ok { color: #9ee6ab; border-color: #27502f; background: #16251a; }
.znaczek.zle { color: #f2a6a6; border-color: #5a2626; background: #261616; }
.znaczek.info { color: #b9d4ff; border-color: #26405a; background: #141d28; }

/* Przebieg sluzby: notatka do zdarzenia i historia zmian karty */
form.notatka-zdarzenia { display: flex; gap: .5rem; margin-top: .4rem; max-width: 48rem; }
.rejestr-przebieg ol.historia li > div { flex: 1; min-width: 0; }
form.notatka-zdarzenia textarea { flex: 1; min-width: 0; font: inherit; }
p.notatka { margin: .3rem 0 0; padding-left: .6rem; border-left: 2px solid var(--line); }
.historia-zmian summary { cursor: pointer; font-weight: 600; }
.historia-zmian ol { list-style: none; padding: 0; margin: .6rem 0 0; display: grid; gap: .6rem; }
.historia-zmian li { display: grid; gap: .15rem; }

/* Zakladka Szkolenia */
.szkolenia-lista { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 22rem), 1fr)); padding: 0 1rem 1rem; }
.szkolenie h4 { margin: .8rem 0 .2rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.link-osoby { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; cursor: pointer; font: inherit; }

/* Widok dowodztwa: konta i dziennik */
#konta .wstep, .lista-dziennika { padding: 0 1rem; }
.lista-dziennika { max-width: 60rem; }

/* Moja kartoteka: sama wlasna karta, bez listy, statystyk i zakladek */
.tylko-moja #stats, .tylko-moja .przelacznik, .tylko-moja #widokKart > .sidebar { display: none; }
.tylko-moja .layout.kadry { grid-template-columns: 1fr; }

/* Okienko zmian przy wejsciu do portalu */
dialog.okno-zmian { max-width: min(40rem, calc(100vw - 2rem)); }
dialog.okno-zmian .akcje { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1rem; }
