/* ==========================================================================
   Organizer Kasi — segregator z kolorowymi przekładkami i markerem.
   Projektowane pod iPada 11" (834×1194 pionowo, 1194×834 poziomo),
   działa też na komputerze i telefonie. Jasny motyw domyślny.

   Zasady ruchu (w duchu Emila Kowalskiego):
   - animujemy tylko transform i opacity, krótko (150–300 ms),
   - wejścia z ease-out, wyjścia szybsze od wejść,
   - nic nie rośnie od zera (scale startuje od .96, nie od 0),
   - efekty hover tylko dla myszki; na dotyku liczy się reakcja na wciśnięcie,
   - prefers-reduced-motion wyłącza ruch, zostawia przenikanie.
   ========================================================================== */

:root {
  --bg: #f3f4f7;
  --surface: #ffffff;
  --surface-2: #eceef3;
  --ink: #16181d;
  --muted: #626977;
  --line: rgba(22, 24, 29, .09);
  --line-strong: rgba(22, 24, 29, .16);
  --accent: #2a44c9;
  --accent-ink: #ffffff;
  --accent-soft: #e8ecfc;
  --marker: #fbd65a;
  --danger: #c4372c;
  --danger-soft: #fdecea;

  --shadow-sm: 0 0 0 1px rgba(22, 24, 29, .05), 0 1px 2px rgba(22, 24, 29, .05);
  --shadow-md: 0 0 0 1px rgba(22, 24, 29, .05), 0 2px 4px rgba(22, 24, 29, .04), 0 8px 20px -6px rgba(22, 24, 29, .10);
  --shadow-lg: 0 0 0 1px rgba(22, 24, 29, .06), 0 24px 60px -12px rgba(22, 24, 29, .30);

  --c-blue: #2a44c9;   --c-green: #1f8558; --c-red: #c4372c;  --c-orange: #cc6d14;
  --c-violet: #6a43c8; --c-teal: #13839a;  --c-pink: #c2337f; --c-gray: #5b6373;

  --font-body: "Atkinson Hyperlegible", system-ui, -apple-system, sans-serif;
  --font-head: "Bricolage Grotesque", "Atkinson Hyperlegible", system-ui, sans-serif;

  --r-xs: 8px;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;

  --ease-out: cubic-bezier(.23, 1, .32, 1);
  --ease-in: cubic-bezier(.55, 0, 1, .45);
  --ease-drawer: cubic-bezier(.32, .72, 0, 1);

  --tap: 44px;              /* minimalny cel dotyku wg Apple */
  --sidebar-w: 260px;
  --col-w: 312px;
  --topbar-h: 0px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --vh: 100vh;
  color-scheme: light;
}
@supports (height: 100dvh) { :root { --vh: 100dvh; } }

:root[data-theme="dark"] {
  --bg: #111318;
  --surface: #1a1d24;
  --surface-2: #23272f;
  --ink: #eceef3;
  --muted: #9ca3b0;
  --line: rgba(255, 255, 255, .08);
  --line-strong: rgba(255, 255, 255, .16);
  --accent: #91a3ff;
  --accent-ink: #0f1430;
  --accent-soft: #252c4a;
  --marker: rgba(251, 214, 90, .32);
  --danger: #ff8f84;
  --danger-soft: #3b2020;
  --shadow-sm: 0 0 0 1px rgba(255, 255, 255, .06);
  --shadow-md: 0 0 0 1px rgba(255, 255, 255, .07), 0 8px 24px -8px rgba(0, 0, 0, .6);
  --shadow-lg: 0 0 0 1px rgba(255, 255, 255, .08), 0 30px 70px -10px rgba(0, 0, 0, .75);
  --c-blue: #91a3ff;   --c-green: #5fd19e; --c-red: #ff8f84;  --c-orange: #f3a85c;
  --c-violet: #b99dff; --c-teal: #5ecbe0;  --c-pink: #f590c6; --c-gray: #a5adbb;
  color-scheme: dark;
}

.c-blue { --c: var(--c-blue); }     .c-green { --c: var(--c-green); }
.c-red { --c: var(--c-red); }       .c-orange { --c: var(--c-orange); }
.c-violet { --c: var(--c-violet); } .c-teal { --c: var(--c-teal); }
.c-pink { --c: var(--c-pink); }     .c-gray { --c: var(--c-gray); }

/* ---------- Podstawy ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 1rem/1.55 var(--font-body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { font-family: var(--font-head); font-weight: 700; line-height: 1.12; margin: 0; letter-spacing: -.015em; }
h1 { font-size: clamp(1.75rem, 1.3rem + 1.3vw, 2.4rem); }
h2 { font-size: 1.32rem; }
h3 { font-size: 1.06rem; }
p { margin: 0; }
a { color: var(--accent); text-underline-offset: 3px; }
a, button, label, summary, input[type=file] { touch-action: manipulation; }
svg { width: 1.15em; height: 1.15em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus { outline: none; }
:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
::selection { background: var(--marker); color: inherit; }

/* ---------- Przyciski: reakcja na wciśnięcie zamiast hovera ---------- */
.btn, .icon-btn, .theme-toggle, .arrange-btn, .add-topic, .link-btn, .switch a, .seg a {
  transition: transform 160ms var(--ease-out), background-color 160ms, color 160ms, border-color 160ms, box-shadow 160ms;
  -webkit-user-select: none; user-select: none;
}
.btn:active, .icon-btn:active, .theme-toggle:active, .arrange-btn:active { transform: scale(.96); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  min-height: var(--tap); padding: 0 1.05em; border-radius: var(--r-sm);
  border: 0; background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm);
  font: 700 .95rem/1 var(--font-body); text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 1px 2px rgba(42, 68, 201, .3), inset 0 1px 0 rgba(255, 255, 255, .15); }
.btn-ghost { background: transparent; box-shadow: inset 0 0 0 1.5px var(--line-strong); color: var(--muted); }
.btn-small { min-height: 38px; padding: 0 .85em; font-size: .88rem; }
.btn-block { width: 100%; min-height: 50px; }
.link-btn { background: none; border: 0; padding: .4rem 0; color: var(--muted); font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line-strong); }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px;
  border: 0; border-radius: var(--r-sm); background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn.tiny { width: 36px; height: 36px; }
.icon-btn.danger { color: var(--muted); }
.icon-btn:active { background: var(--surface-2); }

@media (hover: hover) and (pointer: fine) {
  .btn:hover { box-shadow: var(--shadow-md); }
  .btn-primary:hover { filter: brightness(1.07); }
  .btn-ghost:hover { color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--muted); }
  .icon-btn:hover { background: var(--surface-2); color: var(--ink); }
  .icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
  .link-btn:hover { color: var(--ink); }
}

/* ---------- Pola formularzy (16px+ żeby iPad nie powiększał strony) ---------- */
label { display: grid; gap: .4rem; font-weight: 700; font-size: .92rem; }
input:not([type=radio]):not([type=file]), textarea, select {
  width: 100%; min-height: var(--tap); padding: .6em .85em; border-radius: var(--r-sm);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font: 400 1rem/1.4 var(--font-body);
  transition: border-color 160ms, box-shadow 160ms;
  -webkit-appearance: none; appearance: none;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23626977' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .7em center; background-size: 18px; padding-right: 2.4em;
}
textarea { resize: vertical; min-height: 5em; line-height: 1.5; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

.theme-toggle {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%;
  border: 0; background: var(--surface-2); color: var(--ink); cursor: pointer;
}
.theme-toggle .i-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .i-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .i-moon { display: none; }

/* ---------- Logowanie / konto ---------- */
.auth-wrap { min-height: var(--vh); display: grid; place-content: center; gap: 1.25rem; padding: calc(1.5rem + var(--safe-top)) 1rem calc(3rem + var(--safe-bottom)); }
.auth-top { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.auth-top:has(> :only-child) { justify-content: flex-end; }
.auth-card {
  width: min(420px, calc(100vw - 2rem)); display: grid; gap: 1.1rem;
  background: var(--surface); border-radius: var(--r-lg); padding: 2rem; box-shadow: var(--shadow-md);
  animation: rise 420ms var(--ease-out) both;
}
.auth-card + .auth-card { animation-delay: 60ms; }
.auth-brand { display: flex; align-items: center; gap: .8rem; }
.form-error { background: var(--danger-soft); color: var(--danger); padding: .7rem .9rem; border-radius: var(--r-sm); font-weight: 700; font-size: .92rem; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

/* Znak: segregator z dwiema przekładkami */
.brand-mark { position: relative; width: 22px; height: 28px; border-radius: 5px; background: var(--accent); flex: none; }
.brand-mark::before, .brand-mark::after { content: ""; position: absolute; right: -6px; width: 7px; height: 7px; border-radius: 0 2px 2px 0; }
.brand-mark::before { top: 5px; background: var(--marker); }
.brand-mark::after { top: 15px; background: var(--c-green); }
:root[data-theme="dark"] .brand-mark::before { background: #fbd65a; }

/* ==========================================================================
   Układ: [panel klas] [działy/tematy] [treść]
   ========================================================================== */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: var(--vh); }
.view-grade .shell, .view-topic .shell, .view-students .shell, .view-student .shell {
  grid-template-columns: var(--sidebar-w) var(--col-w) minmax(0, 1fr);
}
.topbar, .scrim { display: none; }

/* ---------- Panel boczny ---------- */
.sidebar {
  position: sticky; top: 0; height: var(--vh); display: flex; flex-direction: column; gap: 1rem;
  padding: calc(1.1rem + var(--safe-top)) 0 calc(1rem + var(--safe-bottom)) 1rem;
  background: var(--surface); z-index: 3;
  view-transition-name: sidebar;
}
.sidebar::after { content: ""; position: absolute; top: 0; bottom: 0; right: 0; width: 1px; background: var(--line); }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding-right: 1rem; }
.brand { display: flex; align-items: center; gap: .7rem; color: var(--ink); text-decoration: none; font: 700 1.12rem/1 var(--font-head); letter-spacing: -.01em; }

.switch { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; padding: 3px; margin-right: 1rem; background: var(--surface-2); border-radius: var(--r-sm); }
.switch a {
  display: flex; align-items: center; justify-content: center; gap: .4rem; min-height: 40px; padding: 0 .4rem;
  border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 700; font-size: .92rem;
}
.switch a.is-on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm), 0 2px 6px -2px rgba(22, 24, 29, .12); }
.switch-count { font-weight: 400; font-size: .78rem; color: var(--muted); }

.search { position: relative; margin-right: 1rem; }
.search svg { position: absolute; left: .8rem; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.sidebar .search input { padding-left: 2.4rem; background: var(--surface-2); border-color: transparent; }
.sidebar .search input:focus { background: var(--surface); border-color: var(--accent); }

.tabs-label { font-size: .8rem; color: var(--muted); font-weight: 700; margin: .25rem 0 -.6rem; }

/* Przekładki klas — wystają z prawej krawędzi panelu */
.tabs { display: grid; align-content: start; gap: 2px; overflow-y: auto; overflow-x: hidden; padding: .25rem 0; flex: 1 1 auto; min-height: 0; overscroll-behavior: contain; }
.tabs-empty { color: var(--muted); font-size: .92rem; padding-right: 1rem; }
.tab {
  position: relative; display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  min-height: var(--tap); padding: .55rem .9rem .55rem 1.05rem; color: var(--ink); text-decoration: none;
  border-radius: var(--r-sm) 0 0 var(--r-sm); font-weight: 700;
  transition: background-color 160ms;
}
.tab::before {
  content: ""; position: absolute; left: 0; top: 11px; bottom: 11px; width: 4px; border-radius: 0 4px 4px 0; background: var(--c);
  transition: top 240ms var(--ease-out), bottom 240ms var(--ease-out), width 240ms var(--ease-out);
}
.tab:active { background: var(--surface-2); }
.tab-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab-count { font-size: .8rem; color: var(--muted); font-weight: 400; min-width: 1.6em; text-align: right; font-variant-numeric: tabular-nums; }
.tab.is-active { background: var(--bg); box-shadow: inset 0 1px 0 var(--line), inset 0 -1px 0 var(--line); z-index: 1; }
.tab.is-active::before { top: 0; bottom: 0; width: 6px; border-radius: var(--r-sm) 0 0 var(--r-sm); }
@media (hover: hover) and (pointer: fine) { .tab:not(.is-active):hover { background: var(--surface-2); } }
.btn-add-tab { margin-right: 1rem; }

.sidebar-foot { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .75rem 1rem 0 0; border-top: 1px solid var(--line); }
.who { display: flex; align-items: center; gap: .6rem; min-height: var(--tap); color: var(--ink); text-decoration: none; font-weight: 700; min-width: 0; }
.avatar { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: .85rem; flex: none; }

/* ---------- Kolumna środkowa (działy i tematy / lista uczniów) ---------- */
.col {
  position: sticky; top: var(--topbar-h); height: calc(var(--vh) - var(--topbar-h)); overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 1rem;
  padding: calc(1.4rem + var(--safe-top)) 1rem calc(1.25rem + var(--safe-bottom)) 1.15rem;
  background: var(--bg); box-shadow: inset 0 4px 0 var(--c), inset -1px 0 0 var(--line);
  view-transition-name: column;
}
.col-head { display: grid; gap: .35rem; }
.col-title { display: flex; align-items: flex-start; justify-content: space-between; gap: .5rem; }
.col-title h2 { padding-top: .35rem; overflow-wrap: break-word; hyphens: auto; -webkit-hyphens: auto; }
.row-actions { display: flex; align-items: center; gap: .1rem; flex: none; }
.row-actions form { margin: 0; }

.arrange-btn {
  min-height: 34px; padding: 0 .8rem; margin-right: .2rem; border-radius: 99px; border: 0; cursor: pointer;
  background: var(--surface-2); color: var(--ink); font: 700 .82rem/1 var(--font-body);
}
.arrange-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

.sec { display: grid; gap: .15rem; padding-top: .8rem; border-top: 1px solid var(--line); }
.sec:first-of-type { border-top: 0; padding-top: 0; }
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: .4rem; min-height: 36px; }
.sec-head h3 { font-size: .98rem; color: var(--c); overflow-wrap: break-word; hyphens: auto; -webkit-hyphens: auto; padding-left: .75rem; }
.sec-tools { display: none; align-items: center; flex: none; }
.sec-tools form { margin: 0; }

.topic-list, .student-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.topic-item { display: flex; align-items: center; gap: .2rem; border-radius: var(--r-sm); }
.topic-item > a, .student-item {
  flex: 1; min-width: 0; display: grid; gap: .1rem; min-height: 52px; align-content: center;
  padding: .55rem .75rem; border-radius: var(--r-sm); color: var(--ink); text-decoration: none;
  transition: background-color 160ms, box-shadow 200ms;
}
.topic-item > a:active, .student-item:active { background: var(--surface-2); }
.topic-name, .student-name { font-weight: 700; overflow-wrap: break-word; hyphens: auto; -webkit-hyphens: auto; }
.topic-meta { font-size: .82rem; color: var(--muted); }
.topic-item.is-active > a, .student-item.is-active { background: var(--surface); box-shadow: var(--shadow-md); }
@media (hover: hover) and (pointer: fine) {
  .topic-item > a:hover, .student-item:hover { background: var(--surface); }
}

/* Marker: aktywny temat/uczeń zostaje „zakreślony” — rysuje się od lewej raz po wejściu */
.topic-item.is-active .topic-name, .student-item.is-active .student-name {
  background-image: linear-gradient(var(--marker), var(--marker));
  background-repeat: no-repeat; background-position: 0 88%; background-size: 100% 42%;
  box-decoration-break: clone; -webkit-box-decoration-break: clone;
  animation: marker 520ms var(--ease-out) 120ms both;
  border-radius: 2px;
}
@keyframes marker { from { background-size: 0% 42%; } }

.move { display: none; flex-direction: column; }
.move form { margin: 0; }
.move-gap { height: 36px; width: 36px; }

/* Tryb „Układaj”: pokazuje strzałki i narzędzia działów */
.col.is-arranging .move { display: flex; }
.col.is-arranging .sec-tools { display: flex; }
.col.is-arranging .topic-item > a { pointer-events: none; opacity: .75; }
.col.is-arranging .move, .col.is-arranging .sec-tools { animation: fade-in 200ms var(--ease-out); }
@keyframes fade-in { from { opacity: 0; } }
/* Na komputerze narzędzia działu są dostępne od razu po najechaniu */
@media (hover: hover) and (pointer: fine) {
  .sec:hover .sec-tools, .sec-tools:focus-within { display: flex; }
  .topic-item:hover .move, .topic-item:focus-within .move { display: flex; }
}

.add-topic {
  display: inline-flex; align-items: center; gap: .45rem; width: fit-content; min-height: 40px;
  margin: 0 0 .3rem .45rem; padding: 0 .35rem; border-radius: var(--r-xs);
  border: 0; background: none; color: var(--muted); font: 400 .9rem/1.3 var(--font-body); cursor: pointer; text-align: left;
}
.add-topic:active { color: var(--accent); background: var(--accent-soft); }
.add-topic svg { width: 1em; height: 1em; }
@media (hover: hover) and (pointer: fine) { .add-topic:hover { color: var(--accent); } }
.btn-add-section { width: 100%; }
.grade-move { margin-top: auto; display: flex; gap: 1.25rem; padding-top: 1rem; flex-wrap: wrap; }
.grade-move form { margin: 0; }

.seg { display: inline-flex; gap: 3px; padding: 3px; margin-top: .45rem; background: var(--surface-2); border-radius: var(--r-sm); width: fit-content; }
.seg a { display: inline-flex; align-items: center; gap: .35rem; min-height: 36px; padding: 0 .85rem; border-radius: 8px; color: var(--muted); text-decoration: none; font-size: .9rem; font-weight: 700; }
.seg a span { font-weight: 400; }
.seg a.is-on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm), 0 2px 6px -2px rgba(22, 24, 29, .12); }

.student-item { display: flex; align-items: center; gap: .75rem; }
.initials {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; flex: none;
  background: var(--surface); color: var(--c); font-weight: 700; font-size: .82rem; box-shadow: inset 0 0 0 2px var(--c);
}
.student-text { display: grid; min-width: 0; }

/* ---------- Treść główna ---------- */
.main {
  min-width: 0; padding: calc(2rem + var(--safe-top)) clamp(1.25rem, 3.2vw, 3rem) calc(4rem + var(--safe-bottom));
  max-width: 1000px; container-type: inline-size; view-transition-name: main;
}
.page-head { display: grid; gap: .65rem; margin-bottom: 1.6rem; }
.page-title { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.page-title h1 { overflow-wrap: break-word; hyphens: auto; -webkit-hyphens: auto; text-wrap: balance; }
.back-link {
  display: inline-flex; align-items: center; gap: .4rem; width: fit-content; min-height: 32px;
  color: var(--muted); text-decoration: none; font-weight: 700; font-size: .9rem;
}
.back-link::before { content: ""; width: 7px; height: 7px; border-left: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); margin-left: 2px; }
.page-head .back-link { color: var(--c); }
.lede { color: var(--muted); font-size: 1.08rem; max-width: 62ch; }
.lede a { color: inherit; text-decoration-color: var(--line-strong); }

.dropzone {
  position: relative; border-radius: var(--r-lg); background: var(--surface);
  box-shadow: inset 0 0 0 2px var(--line-strong);
  transition: box-shadow 200ms var(--ease-out), background-color 200ms, transform 200ms var(--ease-out);
}
.dropzone:active { transform: scale(.99); }
.dropzone.is-over { box-shadow: inset 0 0 0 2px var(--accent); background: var(--accent-soft); transform: scale(1.01); }
.dropzone.is-busy { pointer-events: none; }
.dropzone.is-busy .drop-label { opacity: .4; }
.drop-label { display: grid; justify-items: center; gap: .3rem; padding: 1.6rem 1rem; text-align: center; font-weight: 400; cursor: pointer; transition: opacity 200ms; }
.drop-label svg { width: 30px; height: 30px; color: var(--accent); margin-bottom: .25rem; }
.drop-status:empty { display: none; }
.drop-status { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 700; }
.dropzone:focus-within { box-shadow: inset 0 0 0 2px var(--accent); }
.dropzone.is-busy::after {
  content: ""; position: absolute; left: 1.25rem; right: 1.25rem; bottom: 1rem; height: 4px; border-radius: 4px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent) 0 0 / 40% 100% no-repeat, var(--accent-soft);
  animation: busy 1.1s var(--ease-out) infinite;
}
@keyframes busy { from { background-position: -40% 0, 0 0; } to { background-position: 140% 0, 0 0; } }

.add-row { display: flex; gap: .6rem; margin: .9rem 0 2rem; flex-wrap: wrap; }

.materials { list-style: none; margin: 0; padding: 0; display: grid; gap: .75rem; }
.material {
  display: grid; grid-template-columns: auto 1fr auto; gap: 1rem; align-items: start;
  padding: 1rem 1rem 1rem 1.1rem; background: var(--surface); border-radius: var(--r-md); box-shadow: var(--shadow-sm);
}
.material-body { min-width: 0; display: grid; gap: .25rem; }
.material-body h3 { overflow-wrap: break-word; hyphens: auto; -webkit-hyphens: auto; }
.material-body h3 a { color: var(--ink); text-decoration-color: var(--line-strong); }
.material-body .muted { overflow-wrap: break-word; hyphens: auto; -webkit-hyphens: auto; }
.material-text { margin-top: .3rem; }
.material-actions { display: flex; align-items: center; gap: .3rem; flex-wrap: wrap; justify-content: flex-end; }
.material-actions form { margin: 0; }
.material audio { margin-top: .5rem; width: 100%; max-width: 420px; }

.file-badge {
  display: grid; place-items: center; width: 50px; height: 58px; border-radius: 7px 15px 7px 7px;
  font: 700 .7rem/1 var(--font-body); letter-spacing: .02em; color: #fff; background: var(--c-gray);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .12);
}
.file-badge svg { width: 22px; height: 22px; }
.k-pdf { background: #c4372c; } .k-doc { background: #2b5fc9; } .k-sheet { background: #1f8558; }
.k-slides { background: #cc6d14; } .k-audio, .k-video { background: #6a43c8; }
.k-link { background: var(--accent-soft); color: var(--accent); box-shadow: none; }
.k-note { background: #fbd65a; color: #3b3000; box-shadow: none; }
.thumb { display: block; width: 76px; height: 76px; border-radius: var(--r-sm); overflow: hidden; background: var(--surface-2); box-shadow: var(--shadow-sm); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 300ms var(--ease-out); }
.thumb:active img { transform: scale(1.04); }

.note-text { margin-top: .45rem; padding: .85rem 1rem; background: var(--bg); border-radius: var(--r-sm); max-width: 75ch; overflow-wrap: break-word; hyphens: auto; -webkit-hyphens: auto; line-height: 1.6; }
.note-text.is-collapsed { max-height: 200px; overflow: hidden; -webkit-mask-image: linear-gradient(#000 65%, transparent); mask-image: linear-gradient(#000 65%, transparent); }

.empty-note { color: var(--muted); padding: .75rem 0; max-width: 52ch; }
.placeholder { min-height: 60vh; display: grid; place-items: center; color: var(--muted); text-align: center; }

.welcome { display: grid; gap: 1rem; max-width: 760px; padding-top: 2rem; }
.welcome-actions { display: flex; gap: .7rem; flex-wrap: wrap; }
.welcome-actions form { margin: 0; }
.welcome-grid { list-style: none; margin: 1rem 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .75rem; }
.welcome-grid a, .results a {
  position: relative; display: flex; align-items: center; gap: .75rem; min-height: 64px; padding: .9rem 1rem .9rem 1.25rem;
  background: var(--surface); border-radius: var(--r-md); box-shadow: var(--shadow-sm); overflow: hidden;
  color: var(--ink); text-decoration: none; font-weight: 700;
  transition: transform 160ms var(--ease-out), box-shadow 200ms;
}
.welcome-grid a::before, .results a::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--c); }
.welcome-grid a { display: grid; gap: .2rem; }
.welcome-grid a:active, .results a:active { transform: scale(.98); }
@media (hover: hover) and (pointer: fine) { .welcome-grid a:hover, .results a:hover { box-shadow: var(--shadow-md); } }
.results { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.results a > span:last-child { display: grid; }
.results .dot { display: none; }

/* Karta ucznia */
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .75rem; margin: 0 0 2rem; }
.facts > div { padding: .95rem 1.05rem; background: var(--surface); border-radius: var(--r-md); box-shadow: var(--shadow-sm); }
.facts dt { font-size: .82rem; color: var(--muted); font-weight: 700; margin-bottom: .25rem; }
.facts dd { margin: 0; font-size: 1.06rem; overflow-wrap: break-word; hyphens: auto; -webkit-hyphens: auto; }
.facts a { color: var(--ink); text-decoration-color: var(--line-strong); }
.student-notes { display: grid; gap: .6rem; }
.student-notes h2 { font-size: 1.12rem; }
.student-notes .note-text { background: var(--surface); box-shadow: var(--shadow-sm); }
.student-foot { margin-top: 2rem; padding-top: 1.25rem; border-top: 1px solid var(--line); }
.student-foot form { margin: 0; }
.badge-archived { width: fit-content; padding: .25rem .7rem; border-radius: 99px; background: var(--surface-2); color: var(--muted); font-size: .85rem; font-weight: 700; }

/* ---------- Okna dialogowe ---------- */
.dlg {
  width: min(480px, calc(100vw - 2rem)); max-height: calc(var(--vh) - 2rem); padding: 0; border: 0; border-radius: var(--r-lg);
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg); overflow: hidden;
}
.dlg-wide { width: min(700px, calc(100vw - 2rem)); }
.dlg form { display: grid; gap: 1.05rem; padding: 1.6rem; max-height: calc(var(--vh) - 2rem); overflow-y: auto; overscroll-behavior: contain; }
.dlg h2 { font-size: 1.35rem; }
.dlg-actions { position: sticky; bottom: -1.6rem; display: flex; justify-content: flex-end; gap: .6rem; margin: .25rem -1.6rem -1.6rem; padding: 1rem 1.6rem 1.6rem; background: linear-gradient(transparent, var(--surface) 30%); }
.dlg::backdrop { background: rgba(15, 18, 25, .38); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.dlg[open] { animation: dlg-in 260ms var(--ease-out); }
.dlg[open]::backdrop { animation: fade-in 260ms var(--ease-out); }
.dlg.is-closing { animation: dlg-out 150ms var(--ease-in) forwards; }
.dlg.is-closing::backdrop { animation: fade-out 150ms var(--ease-in) forwards; }
@keyframes dlg-in { from { opacity: 0; transform: translateY(8px) scale(.96); } }
@keyframes dlg-out { to { opacity: 0; transform: scale(.97); } }
@keyframes fade-out { to { opacity: 0; } }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .95rem 1rem; }
.form-grid .span-2 { grid-column: 1 / -1; }

.colors { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: .6rem; }
.colors legend { font-weight: 700; font-size: .92rem; margin-bottom: .5rem; padding: 0; }
.swatch { position: relative; width: 40px; height: 40px; border-radius: 50%; background: var(--c); cursor: pointer; display: block; transition: transform 160ms var(--ease-out), box-shadow 200ms var(--ease-out); }
.swatch:active { transform: scale(.9); }
.swatch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.swatch:has(input:checked) { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--c); }
.swatch:has(input:focus-visible) { outline: 2.5px solid var(--accent); outline-offset: 6px; }

/* ---------- Komunikaty ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(1.25rem + var(--safe-bottom)); z-index: 60;
  max-width: min(560px, calc(100vw - 2rem)); padding: .85rem 1.15rem; border-radius: var(--r-md);
  background: var(--ink); color: var(--bg); font-weight: 700; box-shadow: var(--shadow-lg); cursor: pointer;
  transform: translateX(-50%); animation: toast-in 380ms var(--ease-out);
  transition: opacity 180ms var(--ease-in), transform 180ms var(--ease-in);
}
.toast-error { background: var(--danger); color: #fff; }
:root[data-theme="dark"] .toast-error { color: #2a0d0b; }
.toast.is-gone { opacity: 0; transform: translate(-50%, 12px) scale(.98); pointer-events: none; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 18px) scale(.96); } }

/* ---------- Przejścia między stronami (Safari 18.2+, Chrome 126+) ---------- */
@view-transition { navigation: auto; }
::view-transition-old(main) { animation: 120ms var(--ease-in) both vt-out; }
::view-transition-new(main) { animation: 220ms var(--ease-out) both vt-in; }
::view-transition-old(root), ::view-transition-new(root),
::view-transition-old(sidebar), ::view-transition-new(sidebar),
::view-transition-old(column), ::view-transition-new(column) { animation: none; }
@keyframes vt-out { to { opacity: 0; } }
@keyframes vt-in { from { opacity: 0; transform: translateY(6px); } }

/* ==========================================================================
   iPad: pionowo (i mniejsze laptopy) — panel klas chowa się do szuflady
   ========================================================================== */
@media (max-width: 1099px) {
  :root { --topbar-h: calc(56px + var(--safe-top)); --col-w: 300px; }
  .shell, .view-grade .shell, .view-topic .shell, .view-students .shell, .view-student .shell {
    grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr;
  }
  .view-grade .shell, .view-topic .shell, .view-students .shell, .view-student .shell { grid-template-columns: var(--col-w) minmax(0, 1fr); }

  .topbar {
    position: sticky; top: 0; z-index: 20; grid-column: 1 / -1;
    display: flex; align-items: center; gap: .5rem; height: var(--topbar-h);
    padding: var(--safe-top) .75rem 0 .5rem;
    background: color-mix(in srgb, var(--surface) 86%, transparent);
    -webkit-backdrop-filter: saturate(1.6) blur(14px); backdrop-filter: saturate(1.6) blur(14px);
    box-shadow: inset 0 -1px 0 var(--line);
    view-transition-name: topbar;
  }
  ::view-transition-old(topbar), ::view-transition-new(topbar) { animation: none; }
  .topbar-title { flex: 1; min-width: 0; font: 700 1.06rem/1 var(--font-head); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .menu-btn { color: var(--ink); width: var(--tap); height: var(--tap); }

  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; height: auto; width: min(320px, 86vw); z-index: 40;
    padding-left: 1rem; transform: translateX(-102%); visibility: hidden;
    transition: transform 420ms var(--ease-drawer), visibility 0s linear 420ms;
    box-shadow: var(--shadow-lg); border-radius: 0 var(--r-lg) var(--r-lg) 0;
    view-transition-name: none;
  }
  .sidebar::after { display: none; }
  .sidebar .theme-toggle { display: none; }
  .drawer-open .sidebar { transform: translateX(0); visibility: visible; transition: transform 420ms var(--ease-drawer), visibility 0s; }
  .sidebar.is-dragging { transition: none; }
  .tab { border-radius: var(--r-sm); margin-right: 1rem; }
  .tab.is-active { box-shadow: var(--shadow-sm); background: var(--bg); }

  .scrim {
    display: block; position: fixed; inset: 0; z-index: 30; background: rgba(15, 18, 25, .32);
    opacity: 0; pointer-events: none; transition: opacity 300ms var(--ease-out);
  }
  .scrim[hidden] { display: block; }
  .drawer-open .scrim { opacity: 1; pointer-events: auto; }

  .col { padding-top: 1.25rem; }
  .main { padding-top: 1.75rem; }
}

/* ==========================================================================
   Telefon: tylko jeden poziom naraz
   ========================================================================== */
.only-mobile { display: none; }
@media (max-width: 699px) {
  .view-grade .shell, .view-topic .shell, .view-students .shell, .view-student .shell { grid-template-columns: minmax(0, 1fr); }
  .col { position: static; height: auto; min-height: calc(var(--vh) - var(--topbar-h)); box-shadow: inset 0 4px 0 var(--c); }
  .view-topic .col, .view-student .col { display: none; }
  .view-grade .main, .view-students .main { display: none; }
  .only-mobile { display: inline-flex; }
  .main { padding: 1.25rem 1rem calc(3rem + var(--safe-bottom)); }
  .material { grid-template-columns: auto 1fr; }
  .material-actions { grid-column: 1 / -1; justify-content: flex-start; }
  .form-grid { grid-template-columns: 1fr; }
  /* Okna jako arkusz od dołu */
  .dlg, .dlg-wide { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: var(--r-lg) var(--r-lg) 0 0; }
  .dlg form { padding-bottom: calc(1.6rem + var(--safe-bottom)); }
  .dlg[open] { animation: sheet-in 420ms var(--ease-drawer); }
  .dlg.is-closing { animation: sheet-out 200ms var(--ease-in) forwards; }
  @keyframes sheet-in { from { transform: translateY(100%); } }
  @keyframes sheet-out { to { transform: translateY(100%); } }
}

/* Wąska kolumna treści: przyciski materiału pod opisem */
@container (max-width: 600px) {
  .material { grid-template-columns: auto 1fr; }
  .material-actions { grid-column: 2; justify-content: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-delay: 0s !important; transition-duration: 1ms !important; }
  .dlg[open], .toast { animation: fade-in 150ms linear !important; }
  @view-transition { navigation: none; }
}
