/* Podstawy (wcześniej dodawane przy publikacji) */
:root { padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
body { margin: 0; }
img { max-width: 100%; }
[hidden] { display: none !important; }

/* Układ: pasek wyników całych studiów → zakładki semestrów → karta przedmiotów (lewa) + symulator celu (prawa); na telefonie jedna kolumna. */
:root {
  --paper: #EDF0F6;
  --sheet: #FFFFFF;
  --ink: #16213A;
  --muted: #5B6680;
  --line: #D6DCE7;
  --accent: #2346B8;
  --accent-ink: #FFFFFF;
  --accent-soft: #E2E8FA;
  --ok: #1D7A4E;
  --warn: #9A5B00;
  --bad: #B3232C;
  --bad-soft: #FBE7E8;
  --font-display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", sans-serif;
  --font-body: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --r: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0E1320; --sheet: #161D2D; --ink: #E5E9F3; --muted: #95A1BB; --line: #2A3349;
    --accent: #93A9FF; --accent-ink: #0E1320; --accent-soft: #1F2947;
    --ok: #5DCB94; --warn: #E8B14E; --bad: #FF7C82; --bad-soft: #3A1B20;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0E1320; --sheet: #161D2D; --ink: #E5E9F3; --muted: #95A1BB; --line: #2A3349;
  --accent: #93A9FF; --accent-ink: #0E1320; --accent-soft: #1F2947;
  --ok: #5DCB94; --warn: #E8B14E; --bad: #FF7C82; --bad-soft: #3A1B20;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body { background: var(--paper); color: var(--ink); font: 15px/1.5 var(--font-body); }
.wrap { max-width: 1120px; margin: 0 auto; padding-inline: 16px; padding-block: 24px 64px; display: grid; gap: 20px; }
h1, h2, h3 { font-family: var(--font-display); margin: 0; text-wrap: balance; letter-spacing: -0.01em; }
h1 { font-size: 1.9rem; font-weight: 700; }
h2 { font-size: 1.25rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 700; }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.label { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.muted { color: var(--muted); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Header */
.top { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 12px 24px; }
.top p { margin: 4px 0 0; color: var(--muted); max-width: 60ch; }
.sync { font-size: .82rem; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.sync::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.sync[data-s="cloud"]::before { background: var(--ok); }
.sync[data-s="error"]::before { background: var(--warn); }

/* Stats strip */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r); }
.stat { padding: 14px 18px; display: grid; gap: 2px; min-width: 0; }
.stat + .stat { border-left: 1px solid var(--line); }
.stat .big { font-family: var(--font-mono); font-size: 1.7rem; font-weight: 600; line-height: 1.2; }
.stat .sub { font-size: .82rem; color: var(--muted); }
@media (max-width: 720px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat:nth-child(3) { border-left: 0; }
  .stat:nth-child(n+3) { border-top: 1px solid var(--line); }
}

.banner { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; padding: 10px 14px; border: 1px dashed var(--accent); border-radius: var(--r); background: var(--accent-soft); font-size: .92rem; }
.banner p { margin: 0; flex: 1 1 280px; }

/* Tabs */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tab { border: 1px solid var(--line); background: var(--sheet); padding: 6px 12px; border-radius: 999px; cursor: pointer; display: inline-flex; gap: 8px; align-items: baseline; }
.tab .num { font-size: .8rem; color: var(--muted); }
.tab[aria-selected="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.tab[aria-selected="true"] .num { color: inherit; opacity: .75; }

.grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
@media (max-width: 900px) { .grid { grid-template-columns: minmax(0, 1fr); } }

.card { background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; display: grid; gap: 14px; min-width: 0; }
.card-head { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; justify-content: space-between; }
.sem-name { font-family: var(--font-display); font-weight: 700; font-size: 1.25rem; border: 1px solid transparent; background: transparent; padding: 2px 6px; margin-left: -6px; border-radius: 6px; min-width: 0; width: 100%; max-width: 22ch; }
.sem-name:hover, .sem-name:focus { border-color: var(--line); }

/* Subject table */
.table-scroll { overflow-x: auto; margin-inline: -4px; }
table { width: 100%; border-collapse: collapse; min-width: 460px; }
th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; padding: 6px 4px; border-bottom: 1px solid var(--line); }
td { padding: 5px 4px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
th.c-ects, td.c-ects { width: 78px; }
th.c-grade, td.c-grade { width: 128px; }
th.c-x, td.c-x { width: 36px; }
td input, td select { width: 100%; border: 1px solid transparent; background: transparent; padding: 6px 8px; border-radius: 6px; }
td input:hover, td select:hover, td input:focus, td select:focus { border-color: var(--line); background: var(--paper); }
td.c-ects input { font-family: var(--font-mono); text-align: right; }
select.grade { font-family: var(--font-mono); font-weight: 600; cursor: pointer; }
select.grade[data-g="none"] { color: var(--muted); font-weight: 400; }
select.grade[data-g="2"] { color: var(--bad); background: var(--bad-soft); }
select.grade[data-g="hi"] { color: var(--ok); }
.icon-btn { border: 0; background: transparent; width: 30px; height: 30px; border-radius: 6px; cursor: pointer; color: var(--muted); font-size: 1.1rem; line-height: 1; }
.icon-btn:hover { background: var(--bad-soft); color: var(--bad); }

.btn { border: 1px solid var(--line); background: var(--sheet); padding: 7px 14px; border-radius: 8px; cursor: pointer; font-weight: 700; font-size: .9rem; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); color: var(--accent-ink); }
.btn.danger:hover { border-color: var(--bad); color: var(--bad); }
.btn.small { padding: 4px 10px; font-size: .82rem; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* Semester summary */
.sum { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.sum > div { display: grid; gap: 2px; min-width: 0; }
.sum .v { font-family: var(--font-mono); font-size: 1.15rem; font-weight: 600; }
@media (max-width: 560px) { .sum { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; display: flex; }
.bar i { display: block; height: 100%; }
.bar .earned { background: var(--ok); }
.bar .pending { background: var(--accent); opacity: .35; }
.bar .lost { background: var(--bad); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .8rem; color: var(--muted); }
.legend span::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; vertical-align: 0; }
.legend .l-e::before { background: var(--ok); }
.legend .l-p::before { background: var(--accent); opacity: .35; }
.legend .l-l::before { background: var(--bad); }

.alert { padding: 10px 12px; border-radius: 8px; background: var(--bad-soft); color: var(--bad); font-size: .9rem; }

/* Simulator */
.sim .target { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.sim input[type="number"] { width: 90px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); font-family: var(--font-mono); font-size: 1.1rem; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 2px 10px; font-family: var(--font-mono); font-size: .82rem; cursor: pointer; }
.chip:hover, .chip[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.verdict { padding: 12px 14px; border-radius: 8px; border-left: 4px solid var(--muted); background: var(--paper); display: grid; gap: 4px; }
.verdict[data-s="ok"] { border-left-color: var(--ok); }
.verdict[data-s="warn"] { border-left-color: var(--warn); }
.verdict[data-s="bad"] { border-left-color: var(--bad); }
.verdict strong { font-family: var(--font-display); font-size: 1.05rem; }
.verdict p { margin: 0; font-size: .92rem; }
.plan { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.plan li { display: flex; justify-content: space-between; gap: 12px; font-size: .92rem; padding: 4px 0; border-bottom: 1px dotted var(--line); }
.plan li span:first-child { min-width: 0; overflow-wrap: anywhere; }
.plan .num { font-weight: 600; white-space: nowrap; }

/* Settings & backup */
details.card { gap: 0; }
details.card[open] { gap: 14px; }
summary { cursor: pointer; font-family: var(--font-display); font-weight: 700; }
.settings { display: grid; gap: 14px; }
.settings label { display: flex; gap: 10px; align-items: center; }
textarea { width: 100%; min-height: 110px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); padding: 8px 10px; font-family: var(--font-mono); font-size: .8rem; }
.inline-confirm { display: inline-flex; gap: 6px; align-items: center; font-size: .88rem; flex-wrap: wrap; }

.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 10px 14px; border-radius: 10px; display: flex; gap: 14px; align-items: center; font-size: .9rem; max-width: calc(100% - 32px); box-shadow: 0 6px 24px rgba(0,0,0,.2); }
.toast button { background: transparent; border: 0; color: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; }
footer { font-size: .82rem; color: var(--muted); }
footer p { margin: 0 0 4px; max-width: 75ch; }
@media (prefers-reduced-motion: no-preference) { .bar i { transition: width .25s ease; } }

/* Konto i logowanie */
.account { display: grid; gap: 6px; justify-items: end; }
.account-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-end; }
.who { font-weight: 700; font-size: .9rem; overflow-wrap: anywhere; }
.sync[data-s="busy"]::before { background: var(--accent); }
@media (max-width: 560px) { .account { justify-items: start; } .account-row { justify-content: flex-start; } }

.login { max-width: 420px; width: 100%; justify-self: end; }
@media (max-width: 560px) { .login { justify-self: stretch; max-width: none; } }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--paper); border-radius: 8px; }
.seg button { border: 0; background: transparent; padding: 6px 10px; border-radius: 6px; cursor: pointer; font-weight: 700; color: var(--muted); }
.seg button[aria-selected="true"] { background: var(--sheet); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
#login-form { display: grid; gap: 6px; }
#login-form label { font-size: .85rem; font-weight: 700; }
#login-form input { border: 1px solid var(--line); background: var(--paper); border-radius: 8px; padding: 8px 10px; width: 100%; }
#login-form input:focus { border-color: var(--accent); }
#login-form .row { margin-top: 6px; }
.btn:disabled { opacity: .6; cursor: wait; }
.hint { margin: 4px 0 0; font-size: .84rem; color: var(--muted); }
.hint.warn { color: var(--warn); }
.form-error { margin: 4px 0 0; padding: 8px 10px; border-radius: 8px; background: var(--bad-soft); color: var(--bad); font-size: .88rem; }

/* Sposób liczenia średniej, ikony, forma zaliczenia */
.method-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.method-row .hint { margin: 0; }
.seg-inline { display: inline-grid; grid-template-columns: auto auto; }
.seg button[aria-checked="true"] { background: var(--sheet); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.ico { display: inline-grid; place-items: center; width: 1.15em; height: 1.15em; margin-right: 6px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; line-height: 1; font-size: 1em; }
.tab-add { color: var(--accent); border-style: dashed; }
.tab .num { font-size: .78rem; }
th.c-kind, td.c-kind { width: 112px; }
select.kind { color: var(--muted); }
.sum .v.alt { color: var(--muted); font-weight: 400; }
.sem-name { border-bottom: 1px dashed var(--line); border-radius: 6px 6px 0 0; }
.sem-foot { display: flex; justify-content: flex-end; padding-top: 10px; border-top: 1px solid var(--line); }
.link-danger { border: 0; background: transparent; color: var(--muted); font-size: .84rem; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; padding: 4px 0; text-align: right; }
.link-danger:hover { color: var(--bad); }
table { min-width: 560px; }
.seg-inline { background: var(--sheet); border: 1px solid var(--line); }
.seg-inline button[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); box-shadow: none; }

/* Odzyskiwanie hasła i konto */
.link-btn { border: 0; background: transparent; color: var(--accent); font-size: .88rem; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; padding: 4px 2px; }
.field { display: grid; gap: 6px; }
.code-input { font-family: var(--font-mono); letter-spacing: .06em; text-transform: uppercase; }
.codebox { max-width: 520px; width: 100%; justify-self: end; border-color: var(--accent); }
@media (max-width: 560px) { .codebox { justify-self: stretch; max-width: none; } }
.code-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.code { font-family: var(--font-mono); font-size: 1.35rem; font-weight: 600; letter-spacing: .08em; padding: 8px 12px; background: var(--accent-soft); border-radius: 8px; user-select: all; overflow-wrap: anywhere; }
.check { display: flex; gap: 8px; align-items: center; font-size: .92rem; }
.mini-form { display: grid; gap: 6px; padding-top: 12px; border-top: 1px solid var(--line); }
.mini-form label { font-size: .85rem; font-weight: 700; }
.mini-form input { border: 1px solid var(--line); background: var(--paper); border-radius: 8px; padding: 8px 10px; width: 100%; }
.mini-form input:focus { border-color: var(--accent); }

/* Okienko dla niezalogowanych */
dialog.intro { border: 1px solid var(--line); border-radius: 14px; background: var(--sheet); color: var(--ink); padding: 24px; width: min(480px, calc(100% - 32px)); box-shadow: 0 20px 60px rgba(10, 20, 50, .25); }
dialog.intro::backdrop { background: rgba(14, 19, 32, .55); }
dialog.intro h2 { font-size: 1.35rem; margin-bottom: 10px; }
dialog.intro p { margin: 0 0 10px; line-height: 1.55; }
dialog.intro .row { margin-top: 16px; }
@media (max-width: 480px) { dialog.intro .row { flex-direction: column; align-items: stretch; } dialog.intro .row .btn { width: 100%; } }

/* Usuwanie konta, limit semestrów */
.danger-zone h3 { color: var(--bad); }
.btn.danger-btn { border-color: var(--bad); color: var(--bad); }
.btn.danger-btn:hover { background: var(--bad); color: var(--sheet); border-color: var(--bad); }
.tab:disabled { opacity: .5; cursor: not-allowed; }

/* Linki wyglądające jak przyciski */
a.btn { display: inline-block; text-decoration: none; color: inherit; }

/* Pasek uprawnień (moderator, admin) i tryb podglądu konta */
.staff-banner { border: 2px solid var(--accent); background: var(--accent-soft); }
.preview-banner { border: 2px solid var(--warn); background: color-mix(in srgb, var(--warn) 12%, var(--sheet)); position: sticky; top: 8px; z-index: 5; }

/* Drobne odstępy (dawniej atrybuty style w index.html) */
.flush { margin: 0; }
.light { font-weight: 400; }
th.c-ects { text-align: right; }
.sim-lead { margin: 4px 0 0; font-size: .92rem; }
.plan-title { margin-bottom: 6px; }
#plan-note { font-size: .82rem; margin: 8px 0 0; }
.import-label { display: block; margin-bottom: 6px; }
#import-msg { font-size: .88rem; }
.import-row { margin-top: 8px; }

/* Zdjęcie profilowe (albo kółko z inicjałami) */
.avatar { display: inline-grid; place-items: center; flex: none; border-radius: 50%; object-fit: cover; color: #fff; font-weight: 700; background: var(--muted); user-select: none; }
.avatar.small { width: 24px; height: 24px; font-size: .64rem; }
.avatar.big { width: 72px; height: 72px; font-size: 1.4rem; }
.who { display: inline-flex; align-items: center; gap: 8px; }
.avatar-row { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; }
label.btn { display: inline-block; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.avatar-row .row:has(#av-file:focus-visible) #av-pick { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Wymuszona zmiana hasła (okno bez zamykania) */
#force-pw .mini-form { border-top: 0; padding-top: 0; }
#force-pw .alert { margin: 0 0 10px; }

/* Komunikat od administracji i licznik nieprzeczytanych wiadomości */
.count-badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 999px; background: var(--bad); color: #fff; font-size: .72rem; line-height: 18px; text-align: center; }
dialog.notice { border: 2px solid var(--accent); }
dialog.notice .label { margin: 0 0 4px; }
.notice-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 1rem; }

/* Wylogowanie przez administratora */
.kicked-reason { padding: 8px 12px; border-left: 3px solid var(--warn); background: var(--paper); border-radius: 0 8px 8px 0; }

/* Eksport do PDF */
.pdf-btn { margin-left: auto; }
@media (max-width: 560px) { .pdf-btn { margin-left: 0; } }

/* Dymek „Skopiowano!” nad przyciskiem */
#copy-json, #copy-xml, #copy-summary { position: relative; }
.bubble { position: absolute; left: 50%; bottom: calc(100% + 8px); transform: translateX(-50%); background: var(--ink); color: var(--paper); font-size: .8rem; font-weight: 700; padding: 4px 10px; border-radius: 6px; white-space: nowrap; pointer-events: none; box-shadow: 0 4px 14px rgba(0,0,0,.18); transition: opacity .35s; }
.bubble::after { content: ""; position: absolute; top: 100%; left: 50%; margin-left: -5px; border: 5px solid transparent; border-top-color: var(--ink); }
.bubble.out { opacity: 0; }
@media (prefers-reduced-motion: no-preference) { .bubble { animation: bubble-in .18s ease-out; } }
@keyframes bubble-in { from { opacity: 0; transform: translate(-50%, 4px); } }

/* Ostrzeżenie przed automatycznym wylogowaniem */
.warn-dialog { border-color: var(--warn) !important; }
.warn-count { font-family: var(--font-mono); font-size: 1.6rem; font-weight: 600; color: var(--warn); margin: 4px 0 8px; }
