:root {
  --navy: #1E2A44;
  --navy-2: #2A3858;
  --green: #2F7D6D;
  --green-soft: #E3EFEB;
  --amber: #E0A23B;
  --bg: #F7F5F0;
  --card: #FFFFFF;
  --line: #DCE3DD;
  --text: #1E2A44;
  --muted: #5B6477;
  --danger: #B3412E;
  --surface-2: #FAFAF7;
  --chip: #EEF1F5;
  --line-soft: #EEF1EE;
  --input: #FFFFFF;
  --head-text: #F7F5F0;
  --head-muted: #C9CFD8;
  --accent-text: #FFFFFF;
  --btn: var(--green);
  --btn-hover: #276A5C;
  --active-bg: var(--navy);
  --ok-text: #1F5A4E;
  --err-bg: #FBEAE5;
  --err-text: #8A2E1F;
  --shadow: 0 10px 30px rgba(30, 42, 68, .14);
  --b-pdf: #FBEAE5; --b-pdf-t: #A23A28;
  --b-ppt: #FDF1DC; --b-ppt-t: #9A6412;
  --b-doc: #E4ECFA; --b-doc-t: #2D5BA8;
  --b-xls: #E3F2E8; --b-xls-t: #23744A;
  --b-zip: #ECE7F6; --b-zip-t: #5B3F9A;
  --radius: 14px;
  --serif: 'Domine', Georgia, serif;
  --sans: 'Nunito Sans', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 var(--sans); }
a { color: var(--green); }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }

/* Nagłówek */
.site-header { background: var(--navy); color: var(--head-text); border-left: 10px solid var(--amber); }
.site-header .wrap { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 8px 24px; padding-top: 28px; padding-bottom: 24px; }
.brand { color: inherit; text-decoration: none; display: flex; flex-direction: column; gap: 4px; }
.brand-school { font-size: 13px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--amber); }
.brand-title { font-family: var(--serif); font-size: clamp(24px, 4vw, 36px); line-height: 1.15; font-weight: 700; }
.brand-teacher { margin: 0; color: var(--head-muted); font-weight: 600; }

/* Pasek przedmiotów */
.filter-chips a { flex: none; padding: 7px 14px; border-radius: 999px; text-decoration: none; color: var(--text); font-weight: 600; font-size: 14px; border: 1px solid var(--line); background: var(--card); white-space: nowrap; }
.filter-chips a:hover { border-color: var(--green); }
.filter-chips a.active { background: var(--active-bg); border-color: var(--active-bg); color: #fff; }

main.wrap { padding-top: 24px; padding-bottom: 48px; }
.info { background: var(--green-soft); border-left: 4px solid var(--green); border-radius: 0 var(--radius) var(--radius) 0; padding: 14px 18px; margin-bottom: 20px; font-weight: 600; overflow-wrap: anywhere; }
.search input { width: 100%; font: inherit; padding: 12px 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--input); color: var(--text); }
.search input:focus, .form input:focus, .form select:focus, .form textarea:focus, .auth input:focus { outline: 2px solid var(--green); outline-offset: 1px; border-color: var(--green); }
.page-title { font-family: var(--serif); font-size: clamp(26px, 4vw, 34px); margin: 28px 0 0; line-height: 1.2; }

/* Kafelki przedmiotów */
.subjects-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; margin-top: 20px; }
.subject-tile { display: flex; flex-direction: column; gap: 6px; justify-content: space-between; min-height: 104px; padding: 18px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--text); transition: border-color .15s, transform .15s; }
.subject-tile:hover { border-color: var(--green); transform: translateY(-2px); }
.subject-name { font-family: var(--serif); font-weight: 700; font-size: 18px; line-height: 1.25; }
.subject-count { color: var(--muted); font-size: 14px; }

/* Grupy i karty */
.group { margin-top: 32px; }
.group h2 { font-family: var(--serif); font-size: 22px; margin: 0 0 12px; display: flex; align-items: center; gap: 10px; }
.count { font-family: var(--sans); font-size: 13px; font-weight: 700; color: var(--green); background: var(--green-soft); padding: 2px 9px; border-radius: 999px; }
.cards { display: grid; gap: 10px; }
.card { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.card h3 { margin: 0; font-size: 17px; line-height: 1.3; overflow-wrap: anywhere; }
.card-body { min-width: 0; }
.card-subject { margin: 0 0 2px; font-size: 13px; color: var(--green); font-weight: 700; }
.card-desc { margin: 4px 0 0; color: var(--muted); font-size: 15px; overflow-wrap: anywhere; }
.card-meta { margin: 6px 0 0; display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--muted); }
.due { color: var(--navy); font-weight: 700; }
.due-late { color: var(--danger); }

.badge { width: 52px; height: 52px; border-radius: 12px; display: grid; place-items: center; font-size: 12px; font-weight: 800; letter-spacing: .04em; background: var(--chip); color: var(--navy); }
.badge-pdf { background: var(--b-pdf); color: var(--b-pdf-t); }
.badge-pptx, .badge-ppt, .badge-odp { background: var(--b-ppt); color: var(--b-ppt-t); }
.badge-docx, .badge-doc, .badge-odt { background: var(--b-doc); color: var(--b-doc-t); }
.badge-xlsx, .badge-xls, .badge-ods, .badge-csv { background: var(--b-xls); color: var(--b-xls-t); }
.badge-zip, .badge-7z, .badge-rar { background: var(--b-zip); color: var(--b-zip-t); }
.badge-link { background: var(--green-soft); color: var(--green); }
.badge-sm { width: auto; height: auto; display: inline-block; padding: 2px 6px; border-radius: 6px; font-size: 11px; margin-right: 6px; vertical-align: 1px; }

.btn { display: inline-block; border: 0; cursor: pointer; font: 700 15px var(--sans); text-decoration: none; color: var(--accent-text); background: var(--btn); padding: 10px 18px; border-radius: 10px; white-space: nowrap; }
.btn:hover { background: var(--btn-hover); }
.empty { color: var(--muted); padding: 24px 0; }

.site-footer { border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; padding: 20px 0 32px; }

/* Dodatkowe pliki przy materiale */
.card-extra { margin: 8px 0 0; display: flex; flex-wrap: wrap; gap: 6px; }
.card-extra a { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 700; color: var(--text); text-decoration: none; border: 1px solid var(--line); border-radius: 8px; padding: 4px 9px; background: var(--surface-2); }
.card-extra a:hover { border-color: var(--green); color: var(--green); }
.x-ext { font-size: 10px; letter-spacing: .04em; color: var(--muted); }
.x-size { font-weight: 400; color: var(--muted); }

/* Działy (np. Rok 1, Rok 2) */
details.dzial { margin-top: 10px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
details.dzial > summary { cursor: pointer; list-style: none; padding: 14px 18px; font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 10px; }
details.dzial > summary::-webkit-details-marker { display: none; }
details.dzial > summary::before { content: ''; flex: none; width: 8px; height: 8px; margin: 0 4px 0 2px; border-right: 2.5px solid var(--green); border-top: 2.5px solid var(--green); transform: rotate(45deg); transition: transform .15s; }
details.dzial[open] > summary::before { transform: rotate(135deg); }
details.dzial > .cards { padding: 0 12px 12px; }
details.dzial .card { border-color: var(--line-soft); }
.cards + details.dzial { margin-top: 14px; }

.admin-search { background: var(--input); color: var(--text); width: 100%; max-width: 420px; font: inherit; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 12px; }
fieldset.extras { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin: 0; display: grid; gap: 10px; }
fieldset.extras legend { font-weight: 700; font-size: 14px; padding: 0 4px; }

@media (max-width: 600px) {
  .card { grid-template-columns: auto 1fr; }
  .card .btn { grid-column: 1 / -1; text-align: center; }
  .badge { width: 44px; height: 44px; font-size: 11px; }
}

/* ---------- Panel ---------- */
.admin-bar { background: var(--navy); color: #fff; }
.admin-bar-inner { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; padding-top: 12px; padding-bottom: 12px; }
.admin-bar nav { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; }
.admin-bar nav a { color: var(--head-muted); text-decoration: none; padding: 6px 10px; border-radius: 8px; font-weight: 600; }
.admin-bar nav a.active, .admin-bar nav a:hover { color: #fff; background: var(--navy-2); }
.admin-bar .link-btn { color: var(--head-muted); }
.admin h1 { font-family: var(--serif); font-size: 28px; margin: 8px 0 16px; }
.admin h2 { font-family: var(--serif); font-size: 20px; margin: 8px 0 4px; }
.admin-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; }
.filter-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }

.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-weight: 600; }
.flash-ok { background: var(--green-soft); color: var(--ok-text); }
.flash-err { background: var(--err-bg); color: var(--err-text); }

.form { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; display: grid; gap: 14px; max-width: 760px; margin-bottom: 20px; }
.form label, .auth label { display: grid; gap: 6px; font-weight: 700; font-size: 14px; }
.form input[type=text], .form input[type=url], .form input[type=date], .form input[type=password], .form input[type=file], .form select, .form textarea, .auth input {
  font: 16px var(--sans); padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--input); width: 100%; color: var(--text);
}
.form textarea { resize: vertical; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.opt { font-weight: 400; color: var(--muted); }
.hint { margin: 0; color: var(--muted); font-size: 14px; }
.type-switch { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px 20px; }
.type-switch legend { font-weight: 700; font-size: 14px; margin-bottom: 6px; padding: 0; }
.form label.radio, .form label.check { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.actions { display: flex; align-items: center; gap: 16px; }
.subjects-edit { display: grid; gap: 8px; }
.subject-row { display: grid; grid-template-columns: 2fr 1.2fr 1.2fr auto; gap: 10px; align-items: center; }
.subject-head { font-size: 13px; font-weight: 700; color: var(--muted); }
@media (max-width: 700px) { .subject-row { grid-template-columns: 1fr 1fr; } .subject-head { display: none; } }

.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
table.items { width: 100%; border-collapse: collapse; font-size: 15px; }
.items th { text-align: left; font-size: 13px; color: var(--muted); font-weight: 700; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.items td { padding: 10px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.items tr:last-child td { border-bottom: 0; }
.items td a { font-weight: 700; color: var(--text); }
.hidden-row td { opacity: .6; }
.muted { color: var(--muted); }
.row-actions { white-space: nowrap; display: flex; gap: 12px; align-items: center; }
.inline { display: inline; margin: 0; }
.link-btn { background: none; border: 0; padding: 0; font: 600 15px var(--sans); color: var(--green); cursor: pointer; text-decoration: underline; }
.link-btn.danger { color: var(--danger); }
.pill { border: 0; border-radius: 999px; padding: 4px 10px; font: 700 12px var(--sans); cursor: pointer; }
.pill-on { background: var(--green-soft); color: var(--green); }
.pill-off { background: var(--chip); color: var(--muted); }

.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line); border-top: 6px solid var(--amber); border-radius: var(--radius); padding: 28px; display: grid; gap: 14px; }
.auth-card h1 { font-family: var(--serif); font-size: 24px; margin: 0; }
.auth .btn { width: 100%; padding: 12px; }
.back { font-size: 14px; text-align: center; }

@media (max-width: 600px) {
  .row { grid-template-columns: 1fr; }
  .items thead { display: none; }
  .items tr { display: grid; gap: 4px; padding: 12px 14px; border-bottom: 1px solid var(--line-soft); }
  .items td { padding: 0; border: 0; }
}

/* ---------- Menu główne z listami rozwijanymi ---------- */
.main-nav { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.nav-inner { display: flex; align-items: center; gap: 8px; min-height: 56px; }
.nav-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px; flex: 1; }
.nav-list > li { position: relative; }
.nav-top { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 10px; border: 0; background: none; font: 700 15px var(--sans); color: var(--text); text-decoration: none; cursor: pointer; white-space: nowrap; }
.nav-top:hover, .has-sub:hover > .nav-top, .has-sub.open > .nav-top { background: var(--chip); }
.nav-top.active { color: var(--green); box-shadow: inset 0 -3px 0 var(--green); border-radius: 10px 10px 0 0; }
.caret { font-size: 12px; color: var(--muted); transition: transform .15s; }
.has-sub:hover .caret, .has-sub.open .caret { transform: rotate(180deg); }
.sub { list-style: none; margin: 0; padding: 6px; position: absolute; top: 100%; left: 0; min-width: 260px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); display: none; z-index: 30; }
.has-sub::after { content: ''; position: absolute; left: 0; right: 0; top: 100%; height: 8px; }
.has-sub:hover > .sub, .has-sub.open > .sub, .has-sub:focus-within > .sub { display: block; }
.sub a { display: block; padding: 10px 12px; border-radius: 8px; color: var(--text); text-decoration: none; font-weight: 600; }
.sub a:hover { background: var(--chip); }
.sub a.active { background: var(--green-soft); color: var(--green); }
.nav-burger { display: none; border: 1px solid var(--line); background: var(--card); color: var(--text); font: 700 15px var(--sans); padding: 8px 14px; border-radius: 10px; cursor: pointer; }
.theme-toggle { margin-left: auto; flex: none; width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); font-size: 18px; cursor: pointer; display: grid; place-items: center; }
.theme-toggle:hover { border-color: var(--green); }
.ico-light { display: none; }
.admin-bar .theme-toggle { background: var(--navy-2); border-color: transparent; color: #fff; margin-left: 0; }

.sub-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.sub-tabs a { padding: 8px 16px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--text); text-decoration: none; font-weight: 700; font-size: 14px; }
.sub-tabs a:hover { border-color: var(--green); }
.sub-tabs a.active { background: var(--active-bg); border-color: var(--active-bg); color: #fff; }

@media (max-width: 860px) {
  .nav-inner { flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
  .nav-burger { display: inline-block; }
  .nav-list { display: none; order: 3; flex-basis: 100%; flex-direction: column; gap: 2px; padding-bottom: 8px; }
  .nav-list.show { display: flex; }
  .nav-top { width: 100%; justify-content: space-between; }
  .nav-top.active { box-shadow: inset 3px 0 0 var(--green); border-radius: 0 10px 10px 0; }
  .sub { position: static; display: block; box-shadow: none; border: 0; padding: 0 0 4px 14px; min-width: 0; background: transparent; }
  .has-sub:hover > .nav-top { background: none; }
  .caret { display: none; }
  .has-sub::after { display: none; }
}

/* ---------- Ciemny motyw ---------- */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12161F; --card: #1A202C; --line: #2C3444; --line-soft: #252C3A; --text: #E6E9EF; --muted: #9AA4B5;
  --surface-2: #202737; --chip: #252D3D; --input: #141923; --green: #5CC0A8; --green-soft: #1C3530; --navy: #0E1422; --navy-2: #222B3E;
  --head-muted: #A9B2C2; --btn: #2F7D6D; --btn-hover: #3A9480; --active-bg: #2F7D6D; --ok-text: #A8E2D3; --err-bg: #3A1F1B; --err-text: #F2B8AC;
  --danger: #F08A76; --shadow: 0 12px 32px rgba(0, 0, 0, .5);
  --b-pdf: #3A2220; --b-pdf-t: #F2A594; --b-ppt: #3A2E17; --b-ppt-t: #F0C27A; --b-doc: #1E2B45; --b-doc-t: #93B4F0;
  --b-xls: #1B3326; --b-xls-t: #8FD8AE; --b-zip: #2C2442; --b-zip-t: #C2B0F0;
}
:root[data-theme="dark"] .ico-dark { display: none; }
:root[data-theme="dark"] .ico-light { display: inline; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #12161F; --card: #1A202C; --line: #2C3444; --line-soft: #252C3A; --text: #E6E9EF; --muted: #9AA4B5;
    --surface-2: #202737; --chip: #252D3D; --input: #141923; --green: #5CC0A8; --green-soft: #1C3530; --navy: #0E1422; --navy-2: #222B3E;
    --head-muted: #A9B2C2; --btn: #2F7D6D; --btn-hover: #3A9480; --active-bg: #2F7D6D; --ok-text: #A8E2D3; --err-bg: #3A1F1B; --err-text: #F2B8AC;
    --danger: #F08A76; --shadow: 0 12px 32px rgba(0, 0, 0, .5);
    --b-pdf: #3A2220; --b-pdf-t: #F2A594; --b-ppt: #3A2E17; --b-ppt-t: #F0C27A; --b-doc: #1E2B45; --b-doc-t: #93B4F0;
    --b-xls: #1B3326; --b-xls-t: #8FD8AE; --b-zip: #2C2442; --b-zip-t: #C2B0F0;
  }
  :root:not([data-theme="light"]) .ico-dark { display: none; }
  :root:not([data-theme="light"]) .ico-light { display: inline; }
}

/* Dział nauczyciela w panelu */
.pill-teacher { background: var(--b-ppt); color: var(--b-ppt-t); cursor: default; }
.teacher-note { margin: -4px 0 14px; }
.chip-n { opacity: .7; font-weight: 700; margin-left: 4px; }
.card-actions { display: flex; flex-direction: column; align-items: stretch; gap: 6px; text-align: center; }
.card-edit { font-size: 13px; font-weight: 600; color: var(--muted); }
.teacher-group { margin-top: 8px; }
.import-box { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }

/* ---------- Archiwum ---------- */
.lead { color: var(--muted); max-width: 760px; margin: 8px 0 20px; }
.arch-section { margin-top: 12px; }
.arch-body { padding: 0 14px 14px; display: grid; gap: 14px; }
.arch-folder-name { margin: 6px 0 6px; font-size: 15px; font-weight: 700; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.arch-list { border: 1px solid var(--line-soft); border-radius: 10px; overflow: hidden; }
.arch-row { display: grid; grid-template-columns: 56px 1fr auto auto; gap: 12px; align-items: center; padding: 9px 12px; color: var(--text); text-decoration: none; border-top: 1px solid var(--line-soft); background: var(--card); }
.arch-row:first-child { border-top: 0; }
.arch-row:hover { background: var(--surface-2); }
.arch-row:hover .arch-act { text-decoration: underline; }
.arch-row .badge-sm { margin: 0; text-align: center; }
.arch-title { font-weight: 600; overflow-wrap: anywhere; min-width: 0; }
.arch-desc { display: block; font-weight: 400; font-size: 13px; color: var(--muted); }
.arch-size { font-size: 13px; color: var(--muted); white-space: nowrap; }
.arch-act { font-size: 14px; font-weight: 700; color: var(--green); white-space: nowrap; }
@media (max-width: 600px) {
  .arch-row { grid-template-columns: 48px 1fr auto; }
  .arch-size { display: none; }
}
.tile-archive { border-style: dashed; }
.tile-archive .subject-name::before { content: '🗄 '; }
