/* lecture_chooser — styles */

:root {
  --bg: #eef2f7;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #dbe3ec;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --grid-line: #e2e8f0;
  --shadow: 0 1px 3px rgb(15 23 42 / 0.08);
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --card: #121c2e;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --border: #243147;
    --accent: #60a5fa;
    --accent-soft: #1e3a8a55;
    --danger: #f87171;
    --danger-soft: #7f1d1d55;
    --warn: #fbbf24;
    --warn-soft: #78350f55;
    --ok: #4ade80;
    --ok-soft: #14532d55;
    --grid-line: #1e293b;
    --shadow: 0 1px 3px rgb(0 0 0 / 0.4);
  }
}

/* ---------- motywy kolorystyczne ---------- */

/* Wybór zapisany w localStorage, ustawiany jako data-theme na <html>.
   "auto" = brak atrybutu (jasny/ciemny wg preferencji systemu).
   Selektory html[data-theme] wygrywają z :root (też w @media dark),
   więc jawne motywy nadpisują schemat systemowy. */

html[data-theme="light"] {
  --bg: #eef2f7;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #dbe3ec;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --grid-line: #e2e8f0;
  --shadow: 0 1px 3px rgb(15 23 42 / 0.08);
}

html[data-theme="dark"] {
  --bg: #0b1220;
  --card: #121c2e;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: #243147;
  --accent: #60a5fa;
  --accent-soft: #1e3a8a55;
  --grid-line: #1e293b;
  --shadow: 0 1px 3px rgb(0 0 0 / 0.4);
}

html[data-theme="forest"] {
  --bg: #edf5ef;
  --card: #ffffff;
  --text: #0f1c15;
  --muted: #5b7263;
  --border: #d4e3d9;
  --accent: #059669;
  --accent-soft: #d1fae5;
  --grid-line: #e2ece6;
  --shadow: 0 1px 3px rgb(6 78 59 / 0.1);
}

@media (prefers-color-scheme: dark) {
  html[data-theme="forest"] {
    --bg: #0a1510;
    --card: #101f18;
    --text: #dcebe2;
    --muted: #8aa696;
    --border: #20382c;
    --accent: #34d399;
    --accent-soft: #064e3b66;
    --grid-line: #182a20;
    --shadow: 0 1px 3px rgb(0 0 0 / 0.4);
  }
}

html[data-theme="violet"] {
  --bg: #f1eefb;
  --card: #ffffff;
  --text: #191227;
  --muted: #6d6486;
  --border: #e0d9f0;
  --accent: #7c3aed;
  --accent-soft: #ede9fe;
  --grid-line: #e8e3f5;
  --shadow: 0 1px 3px rgb(76 29 149 / 0.1);
}

@media (prefers-color-scheme: dark) {
  html[data-theme="violet"] {
    --bg: #100b1e;
    --card: #191231;
    --text: #e6e1f5;
    --muted: #9a90b8;
    --border: #2c2247;
    --accent: #a78bfa;
    --accent-soft: #4c1d9555;
    --grid-line: #221a3a;
    --shadow: 0 1px 3px rgb(0 0 0 / 0.4);
  }
}

html[data-theme="rose"] {
  --bg: #fbf0f4;
  --card: #ffffff;
  --text: #26101a;
  --muted: #96637a;
  --border: #f2d9e3;
  --accent: #db2777;
  --accent-soft: #fce7f3;
  --grid-line: #f4e2ea;
  --shadow: 0 1px 3px rgb(131 24 67 / 0.1);
}

@media (prefers-color-scheme: dark) {
  html[data-theme="rose"] {
    --bg: #1a0d13;
    --card: #241319;
    --text: #f3e3ea;
    --muted: #b3909f;
    --border: #3d2230;
    --accent: #f472b6;
    --accent-soft: #83184355;
    --grid-line: #2c1a24;
    --shadow: 0 1px 3px rgb(0 0 0 / 0.4);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

/* ---------- pasek górny ---------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  padding: 14px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-title { display: flex; align-items: baseline; gap: 10px; margin-right: auto; }

.topbar h1 { font-size: 1.15rem; margin: 0; }

.subtitle { color: var(--muted); font-size: 0.85rem; }

.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.week-switch { display: flex; flex-wrap: wrap; background: var(--bg); border: 1px solid var(--border); border-radius: 999px; padding: 3px; }

.week-switch button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.85rem;
  white-space: nowrap;
}

.week-switch button small { display: block; font-size: 0.68rem; opacity: 0.8; }

.week-switch button[aria-pressed="true"] { background: var(--accent); color: #fff; }

.btn {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 0.9rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: border-color 0.12s, background-color 0.12s, color 0.12s;
}

/* tło var(--bg) odróżnia przyciski od paska (var(--card)) */
.btn:hover { border-color: var(--accent); background: var(--accent-soft); }

.btn-ghost { background: var(--bg); box-shadow: none; }

.btn-ghost:hover {
  border-color: var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
}

/* wybór motywu kolorystycznego */

.theme-select {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 0.9rem;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.theme-select:hover { border-color: var(--accent); }

.status-chip {
  font-size: 0.85rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  white-space: nowrap;
}

.status-chip.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.status-chip.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.status-chip.err { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

/* ---------- panel statusu ---------- */

.status-panel {
  margin: 12px 20px 0;
  display: grid;
  gap: 6px;
}

.status-line {
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.88rem;
  border: 1px solid transparent;
}

.status-line.error { background: var(--danger-soft); color: var(--danger); }
.status-line.missing { background: var(--warn-soft); color: var(--warn); }
.status-line.warning { background: var(--warn-soft); color: var(--warn); }
.status-line.info { background: var(--accent-soft); color: var(--accent); }

/* ---------- układ główny ---------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  gap: 16px;
  padding: 16px 20px 32px;
  align-items: start;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- kalendarz ---------- */

.cal-scroll { overflow-x: auto; }

.cal-inner { min-width: 860px; }

.cal-head, .cal-body {
  display: grid;
  grid-template-columns: var(--cal-cols);
}

.cal-head {
  position: sticky;
  top: 0;
  z-index: 5;
  border-bottom: 2px solid var(--border);
  background: var(--card);
}

.cal-head .cal-corner { border-right: 1px solid var(--grid-line); }

.cal-head .cal-day-name {
  text-align: center;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 8px 4px;
  border-right: 1px solid var(--grid-line);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.cal-head .cal-day-name:last-child { border-right: 0; }

.cal-body {
  position: relative;
  height: clamp(430px, 68vh, 900px);
  --hours: 12;
}

.cal-hours { position: relative; border-right: 1px solid var(--grid-line); }

.cal-hours span {
  position: absolute;
  left: 0;
  right: 6px;
  transform: translateY(-50%);
  text-align: right;
  font-size: 0.72rem;
  color: var(--muted);
}

.cal-day {
  position: relative;
  border-right: 1px solid var(--grid-line);
  background-image: repeating-linear-gradient(
    to bottom,
    var(--grid-line) 0,
    var(--grid-line) 1px,
    transparent 1px,
    transparent calc(100% / var(--hours))
  );
}

.cal-day:last-child { border-right: 0; }

.cal-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
  padding: 20px;
}

.cal-block {
  position: absolute;
  border-radius: 8px;
  border-left: 4px solid;
  padding: 4px 6px;
  font-size: 0.74rem;
  line-height: 1.3;
  overflow: hidden;
  cursor: pointer;
  transition: filter 0.15s;
}

.cal-block:hover { filter: brightness(1.08); z-index: 3; }

.cal-block b { display: block; font-size: 0.78rem; }

.cal-block .meta { color: var(--muted); }

.cal-block .badge {
  display: inline-block;
  font-size: 0.64rem;
  padding: 0 5px;
  border-radius: 999px;
  border: 1px solid currentColor;
  margin-right: 4px;
}

.badge.hybrid { border-style: dashed; font-style: italic; }

.cal-block.collide { outline: 2px solid var(--danger); outline-offset: -2px; }

/* podgląd offeringu pod kursorem — przygaszona wersja zwykłego kafelka */
.cal-block.preview {
  opacity: 0.55;
  border-style: dashed;
  background: transparent;
  cursor: default;
}

/* offering już wybrany, ale pod kursorem — delikatne podkreślenie */
.cal-block.hover {
  box-shadow: 0 0 0 2px currentColor inset;
}

/* ---------- picker ---------- */

.picker { max-height: calc(100vh - 96px); overflow-y: auto; position: sticky; top: 76px; }

.p-note { font-size: 0.78rem; color: var(--muted); margin: -6px 0 10px; }

.count-chip {
  margin-left: auto;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}

.count-chip.done { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.count-chip.over { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

details.coll-box { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }

details.coll-box + details.coll-box { margin-top: 10px; }

details.coll-box > summary {
  list-style: none;
  cursor: pointer;
  padding: 10px 12px;
  font-weight: 600;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
}

details.coll-box > summary::-webkit-details-marker { display: none; }

details.coll-box > summary::before {
  content: "▸";
  color: var(--muted);
  transition: transform 0.15s;
}

details.coll-box[open] > summary::before { transform: rotate(90deg); }

details.coll-box > summary .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

.coll-body { padding: 10px 12px 12px; display: grid; gap: 10px; }

.cat-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 10px;
}

.cat-card:last-child { margin-bottom: 0; }

.cat-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.cat-head .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

.cat-head h3 { font-size: 0.88rem; margin: 0; }

.cat-head .btn { margin-left: auto; padding: 4px 10px; font-size: 0.78rem; }

.btn-select { border-color: transparent; background: var(--accent); color: #fff; }
.btn-select.selected { background: var(--ok-soft); color: var(--ok); }
/* hover nie może nadpisywać wyglądu przycisków wyboru (patrz .btn:hover) */
.btn-select:hover { background: var(--accent); color: #fff; }
.btn-select.selected:hover { background: var(--ok-soft); color: var(--ok); }

.course { border-bottom: 1px solid var(--grid-line); }
.course:last-child { border-bottom: 0; }

.course-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
}

.course-head .name { font-weight: 600; font-size: 0.86rem; }

.course-head .kinds { color: var(--muted); font-size: 0.72rem; margin-left: auto; text-align: right; }

.course-chip {
  font-size: 0.68rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 1px 7px;
  background: var(--ok-soft);
  color: var(--ok);
  white-space: nowrap;
}

.course-chip.needs { background: var(--warn-soft); color: var(--warn); }

.offering {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 5px 12px 7px 24px;
  font-size: 0.8rem;
}

.offering input[type="radio"], .offering input[type="checkbox"] { margin-top: 3px; accent-color: var(--accent); }

.offering .body { flex: 1; min-width: 0; }

.offering .who { color: var(--text); }

.offering .times { color: var(--muted); font-size: 0.74rem; }

.offering .times .badge {
  display: inline-block;
  font-size: 0.66rem;
  padding: 0 5px;
  border-radius: 999px;
  border: 1px solid var(--border);
  margin-left: 4px;
}

.offering.on .who { font-weight: 600; }

.offering.needs-group { background: var(--warn-soft); border-radius: 6px; }

.no-time { color: var(--warn); font-size: 0.74rem; font-style: italic; }

.course.flash { animation: flash 1.2s; }

@keyframes flash {
  0%, 60% { background: var(--accent-soft); }
  100% { background: transparent; }
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--danger);
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 0.88rem;
  max-width: min(92vw, 560px);
  z-index: 50;
}

/* ---------- responsywność ---------- */

@media (max-width: 1080px) {
  .layout { grid-template-columns: 1fr; }
  .picker { position: static; max-height: none; }
}

@media (max-width: 640px) {
  .topbar { padding: 10px 12px; }
  .topbar-title { width: 100%; }
  .layout { padding: 12px 10px 24px; }
  .cal-inner { min-width: 720px; }
  .cal-block { font-size: 0.68rem; }
  .cal-block b { font-size: 0.72rem; }
  .cal-block .meta .teacher { display: none; }
}

/* ---------- menu „Pobierz” ---------- */

details.dropdown { position: relative; }

details.dropdown > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

details.dropdown > summary::-webkit-details-marker { display: none; }

details.dropdown > summary::after { content: " ▾"; color: var(--muted); }

details.dropdown[open] > summary { border-color: var(--accent); background: var(--accent-soft); }

.dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 30;
  min-width: 230px;
  padding: 6px;
  display: grid;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 28px rgb(15 23 42 / 0.16);
}

.dropdown-menu button {
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 8px 10px;
  border-radius: 7px;
  font-size: 0.88rem;
  cursor: pointer;
  white-space: nowrap;
}

.dropdown-menu button:hover { background: var(--bg); }

.dropdown-sep { height: 1px; background: var(--border); margin: 5px 8px; }

/* podmenu „Google Calendar” — linki „dodaj wydarzenie” dla kolejnych terminów */

.dropdown-sub > .gcal-toggle::after { content: " ▸"; color: var(--muted); }
.dropdown-sub.open > .gcal-toggle::after { content: " ▾"; }

.gcal-list { display: none; margin: 2px 0 4px; padding-left: 8px; border-left: 2px solid var(--border); }
.dropdown-sub.open .gcal-list { display: grid; gap: 1px; max-height: 300px; overflow: auto; }

.gcal-list a {
  display: block;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 0.8rem;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.gcal-list a:hover { background: var(--bg); }

.gcal-note, .gcal-empty { font-size: 0.72rem; color: var(--muted); padding: 2px 8px 6px; }

/* ---------- druk / PDF ---------- */

/* style drukowanego nagłówka — wspólne dla wydruku i eksportu PNG/PDF
   (snapshot DOM); na ekranie #printHead jest niewidoczny, więc niczego nie psują */
#printHead { display: none; }
#printHead .print-title { font-size: 1.1rem; font-weight: 700; }
#printHead .print-date { font-size: 0.78rem; color: var(--muted); }
#printHead .print-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 0.78rem; }
#printHead .print-legend .dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
}

@media print {
  @page { size: A4 landscape; margin: 10mm; }

  /* wymuszamy jasne kolory niezależnie od trybu ciemnego i wybranego motywu */
  :root, html[data-theme] {
    --bg: #ffffff;
    --card: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --border: #dbe3ec;
    --grid-line: #e2e8f0;
  }

  .topbar, #statusPanel, .picker, #toast { display: none !important; }

  .layout { display: block; padding: 0; }

  .card { border: 0; border-radius: 0; box-shadow: none; }

  .cal-scroll { overflow: visible; }
  .cal-inner { min-width: 0; }
  .cal-head { position: static; }

  .cal-day, .cal-block, .cal-block b {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  #printHead { display: grid; gap: 4px; padding: 0 0 8px; }
}
