/* Kabinet: velké písmo, velká tlačítka, jasný kontrast */
:root {
  --bg: #f4f2ec;
  --surface: #ffffff;
  --surface-2: #efece4;
  --border: #d9d3c6;
  --text: #1d211b;
  --muted: #5a5f56;
  --primary: #2f5d50;
  --primary-ink: #ffffff;
  --primary-soft: #e2eee8;
  --lesson-border: #c9d6cf;
  --personal: #f6e5c2;
  --personal-ink: #5c3f0c;
  --today: #fbf5e4;
  --danger: #a33a2c;
  --focus: #1f6fd1;
  --shadow: 0 1px 2px rgba(30, 30, 20, .06), 0 4px 14px rgba(30, 30, 20, .06);
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151917;
    --surface: #1f2421;
    --surface-2: #2a302c;
    --border: #3a423d;
    --text: #eef1ec;
    --muted: #b0b8b0;
    --primary: #79bfa9;
    --primary-ink: #0f1a16;
    --primary-soft: #243832;
    --lesson-border: #3c4b44;
    --personal: #45381f;
    --personal-ink: #f5dca8;
    --today: #1b211e;
    --danger: #f08a78;
    --focus: #7fb4ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .5; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.3rem; }

p { margin: 0; }
.muted { color: var(--muted); }
.big { font-size: 1.15rem; }
small { font-weight: 400; color: var(--muted); }

/* ---------- Rozložení ---------- */

.app {
  display: grid;
  grid-template-columns: 230px 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 24px 16px;
  border-right: 1px solid var(--border);
  background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 1.3rem; padding: 0 8px; }
.nav { display: flex; flex-direction: column; gap: 6px; }
.nav-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  border: 0;
  background: none;
  padding: 12px 14px;
  border-radius: 10px;
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 500;
}
.nav-btn svg {
  width: 24px;
  height: 24px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.nav-btn:hover { background: var(--surface-2); }
.nav-btn.is-active { background: var(--primary); color: var(--primary-ink); font-weight: 600; }
.sidebar-note { margin-top: auto; font-size: .85rem; color: var(--muted); padding: 0 8px; }

.main { padding: 28px 32px 56px; min-width: 0; max-width: 1100px; outline: none; }

.view-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.eyebrow { font-size: .95rem; font-weight: 600; color: var(--primary); margin-bottom: 2px; }
.lead { margin-top: 6px; color: var(--muted); max-width: 60ch; }
.hint { color: var(--muted); margin: 0 0 14px; }
.pager { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Tlačítka ---------- */

.btn {
  min-height: 44px;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 9px 16px;
  border-radius: 10px;
  font-weight: 500;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: var(--primary); filter: brightness(1.1); }
.btn-danger { color: var(--danger); border-color: currentColor; background: transparent; }
.btn-big { font-size: 1.1rem; padding: 12px 22px; min-height: 52px; }
.btn-small { min-height: 36px; padding: 5px 12px; font-size: .95rem; }

/* ---------- Karty ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }

.welcome .steps { margin: 14px 0 20px; padding-left: 1.4em; display: grid; gap: 8px; }

/* Osobní události na obrazovce Dnes */
.personal-card { border-left: 6px solid var(--personal-ink); }
.event-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.event-list li {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--personal);
  color: var(--personal-ink);
}
.ev-time { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 6.5em; }
.ev-title { flex: 1; font-weight: 500; }

/* Karta hodiny */
.lesson-card { border-left: 6px solid var(--primary); scroll-margin-top: 16px; }
.lesson-card.is-now { box-shadow: 0 0 0 3px var(--primary), var(--shadow); }
.lesson-head { display: flex; align-items: center; gap: 20px; margin-bottom: 14px; flex-wrap: wrap; }
.lesson-when {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 86px;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--surface-2);
}
.lesson-when .num { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.lesson-when .time { font-size: .9rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.lesson-what { flex: 1; min-width: 0; }
.lesson-what h2 { font-size: 1.4rem; }
.lesson-what p { color: var(--muted); }
.lesson-what p b { color: var(--text); }
.badge {
  background: var(--primary);
  color: var(--primary-ink);
  font-weight: 600;
  font-size: .9rem;
  padding: 4px 12px;
  border-radius: 999px;
}

.last-time {
  background: var(--primary-soft);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 16px;
  white-space: pre-wrap;
}
.last-time.is-empty { background: var(--surface-2); color: var(--muted); }

.lesson-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.lesson-fields .field:last-child { grid-column: 1 / -1; }
.save-state { min-height: 1.4em; font-size: .9rem; color: var(--primary); font-weight: 600; }

/* ---------- Formulářová pole ---------- */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-weight: 600; }
.field input, .field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  padding: 10px 12px;
  font-size: 1rem;
}
.field input { min-height: 46px; }
.field textarea { resize: vertical; min-height: 48px; }
.field input:focus, .field textarea:focus { border-color: var(--primary); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ---------- Týden a rozvrh (mřížka) ---------- */

.week-wrap { overflow-x: auto; padding-bottom: 6px; }
.week {
  display: grid;
  grid-template-columns: 74px repeat(5, minmax(120px, 1fr));
  gap: 8px;
  min-width: 700px;
}

.day-col-head {
  border: 0;
  background: var(--surface-2);
  padding: 10px;
  border-radius: 10px;
  font-size: 1rem;
  text-align: center;
  color: var(--text);
}
.day-col-head b { margin-left: 4px; }
button.day-col-head:hover { filter: brightness(.96); }
.day-col-head.is-today { background: var(--primary); color: var(--primary-ink); }

.row-label {
  display: flex;
  flex-direction: column;
  justify-content: center;
  color: var(--muted);
}
.row-label b { color: var(--text); font-size: 1.05rem; }
.row-label .times {
  display: flex;
  flex-direction: column;
  font-size: .82rem;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
}
.row-label .times span:last-child { opacity: .75; }

.personal-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 44px;
  padding: 5px;
  border-radius: 10px;
  border: 1px dashed var(--border);
  background: transparent;
  text-align: left;
}
.personal-cell:hover { border-color: var(--personal-ink); }
.personal-cell.is-today { background: var(--today); }
.event {
  border-radius: 6px;
  padding: 3px 8px;
  background: var(--personal);
  color: var(--personal-ink);
  font-size: .85rem;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell { min-height: 72px; border-radius: 10px; }
.cell.free.is-today { background: var(--today); }
.lesson {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 2px;
  text-align: left;
  padding: 8px 12px;
  border: 1px solid var(--lesson-border);
  border-left: 5px solid var(--primary);
  background: var(--surface);
  min-width: 0;
}
.lesson:hover { box-shadow: var(--shadow); border-color: var(--primary); }
.lesson.is-today { background: var(--today); }
.lesson .subj { font-weight: 600; }
.lesson .meta { color: var(--muted); font-size: .92rem; }
.lesson .subj .meta { font-weight: 400; margin-left: 4px; }
.lesson .note-text {
  font-size: .85rem;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.lesson .note-ended { color: var(--primary); }
.lesson .note-prep { color: var(--personal-ink); }

.back-btn { margin-bottom: 14px; }

/* Odpadlé hodiny a suplování */
.lesson-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.lesson-card.is-cancelled { border-left-color: var(--border); background: var(--surface-2); box-shadow: none; }
.lesson-card.is-cancelled h2 { text-decoration: line-through; color: var(--muted); }
.lesson-card.is-cancelled .lesson-head { margin-bottom: 8px; }
.lesson-card.is-extra { border-left-color: var(--personal-ink); }
.badge-muted { background: var(--border); color: var(--text); }
.badge-extra { background: var(--personal); color: var(--personal-ink); }
.tag {
  display: inline-block;
  font-size: .75rem;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--personal);
  color: var(--personal-ink);
}
.lesson.is-cancelled { background: var(--surface-2); border-left-color: var(--border); }
.lesson.is-cancelled .subj { text-decoration: line-through; color: var(--muted); }
.lesson.is-extra { border-left-color: var(--personal-ink); }
.day-actions { margin-top: 4px; }

/* Příští vyučování (víkend, volný den) */
.next-day h2 { margin: 14px 0 10px; }
.next-list { list-style: none; margin: 0 0 18px; padding: 0; display: grid; gap: 8px; }
.next-list li { display: flex; gap: 14px; padding: 8px 12px; border-radius: 10px; background: var(--surface-2); }
.nl-time { min-width: 5.5em; font-variant-numeric: tabular-nums; color: var(--muted); }
.nl-what { display: flex; flex-direction: column; }
.nl-prep { font-size: .9rem; color: var(--personal-ink); }

/* Skenování rozvrhu */
.dialog-wide { width: min(720px, calc(100vw - 32px)); }
.dialog p + p { margin-top: 8px; }
.btn-file { display: inline-flex; align-items: center; cursor: pointer; }
.scan-grid {
  display: grid;
  grid-template-columns: 36px repeat(5, 1fr);
  gap: 4px;
  margin: 16px 0;
  font-size: .85rem;
  max-height: 50vh;
  overflow: auto;
}
.sg-head { font-weight: 600; text-align: center; color: var(--muted); align-self: center; }
.sg-cell { background: var(--surface-2); border-radius: 6px; padding: 4px 6px; display: flex; flex-direction: column; min-height: 40px; }
.sg-cell.empty { background: transparent; border: 1px dashed var(--border); }
.warn { color: var(--danger); font-weight: 600; }
.spinner {
  width: 36px;
  height: 36px;
  margin: 18px auto 4px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
.field select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  padding: 8px 12px;
  font-size: 1rem;
}

.tt-cell {
  min-height: 72px;
  border-radius: 10px;
  border: 2px dashed var(--border);
  background: transparent;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  color: var(--muted);
  text-align: left;
}
.tt-cell:hover { border-color: var(--primary); color: var(--primary); }
.tt-cell.filled {
  border: 1px solid var(--lesson-border);
  border-left: 5px solid var(--primary);
  background: var(--surface);
  color: var(--text);
}
.tt-cell .subj { font-weight: 600; }
.tt-cell .meta { color: var(--muted); font-size: .92rem; }
.day-col-head.static { cursor: default; }

/* ---------- Dialogy ---------- */

.dialog {
  border: 0;
  border-radius: 16px;
  padding: 26px;
  width: min(480px, calc(100vw - 32px));
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 10px 40px rgba(0, 0, 0, .3);
}
.dialog::backdrop { background: rgba(20, 24, 22, .5); }
.dialog h2 { margin-bottom: 18px; }
.dialog-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.spacer { flex: 1; }

/* ---------- Nastavení ---------- */

.settings { display: grid; gap: 4px; max-width: 720px; }
.settings .card p { margin-top: 6px; }
.bells {
  display: grid;
  grid-template-columns: auto 1fr 1fr;
  gap: 8px 14px;
  align-items: center;
  margin: 16px 0;
  max-width: 420px;
}
.bells input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  min-height: 44px;
  background: var(--surface);
  font-variant-numeric: tabular-nums;
}
.bell-num { font-weight: 600; }
.row-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }

/* ---------- Oznámení ---------- */

.banner {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  background: var(--danger);
  color: #fff;
  padding: 12px 18px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  max-width: calc(100vw - 32px);
}
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 12px 20px;
  border-radius: 12px;
  font-weight: 500;
  box-shadow: var(--shadow);
  z-index: 10;
}

/* ---------- Menší obrazovky ---------- */

@media (max-width: 900px) {
  .lesson-fields { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: auto 0 0 0;
    height: auto;
    flex-direction: row;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    border-right: 0;
    border-top: 1px solid var(--border);
    z-index: 4;
  }
  .brand, .sidebar-note { display: none; }
  .nav { flex-direction: row; flex: 1; justify-content: space-around; gap: 2px; }
  .nav-btn { flex-direction: column; gap: 2px; padding: 6px 8px; font-size: .8rem; flex: 1; text-align: center; }
  .main { padding: 18px 16px 100px; }
  h1 { font-size: 1.45rem; }
  .pager .btn { flex: 1; }
  .card { padding: 16px; }
  .toast { bottom: 96px; }
}
