:root {
  --bg: #f6f7f9;
  --surface: #fff;
  --border: #e2e5ea;
  --text: #1c2330;
  --muted: #5d6675;
  --accent: #1e5fd8;
  --accent-dark: #16489f;
  --ok: #17794a;
  --ok-bg: #e7f5ed;
  --err: #b3261e;
  --err-bg: #fdecea;
  --radius: 10px;
  --shadow: 0 1px 3px rgb(16 24 40 / 8%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --surface: #1c2028;
    --border: #2c323d;
    --text: #e8eaee;
    --muted: #9aa3b2;
    --accent: #74a4ff;
    --accent-dark: #9dbeff;
    --ok: #6ddca5;
    --ok-bg: #16311f;
    --err: #ff9a92;
    --err-bg: #3a1b18;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* Pojistka proti vodorovnému posuvu na mobilu — nic nesmí vytlačit stránku do šířky. */
  overflow-x: hidden;
}

#app { max-width: 880px; margin: 0 auto; padding: 16px 16px 64px; }

/* Na velkém displeji dáme textu víc místa a mírně větší písmo — dlouhé kapitoly
   se v úzkém sloupci čtou špatně. */
@media (min-width: 1000px) {
  body { font-size: 17px; }
  #app { max-width: 1000px; padding-left: 24px; padding-right: 24px; }
}
@media (min-width: 1400px) {
  #app { max-width: 1180px; }
}
#app.loading { color: var(--muted); padding-top: 80px; text-align: center; }

a { color: var(--accent); }

/* --- Záhlaví ------------------------------------------------------------- */
header.bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 22px;
  padding-bottom: 12px; border-bottom: 1px solid var(--border);
}
header.bar .brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
header.bar .logo { height: 26px; width: auto; flex-shrink: 0; }
header.bar .logo-light { display: block; }
header.bar .logo-dark { display: none; }
@media (prefers-color-scheme: dark) {
  header.bar .logo-light { display: none; }
  header.bar .logo-dark { display: block; }
}
header.bar h1 {
  font-size: 17px; margin: 0; font-weight: 600; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
header.bar .nav { display: flex; align-items: center; gap: 8px; }
header.bar .who { color: var(--muted); font-size: 14px; white-space: nowrap; }

/* Přepínač menu — zobrazí se jen na úzkých displejích. */
.nav-toggle { display: none; background: transparent; color: var(--text); border: 1px solid var(--border); padding: 7px 11px; }
.nav-toggle:hover { background: var(--bg); }

@media (max-width: 620px) {
  header.bar { flex-wrap: wrap; }
  header.bar h1 { font-size: 15px; }
  header.bar .logo { height: 22px; }
  .nav-toggle { display: inline-block; }
  header.bar .nav {
    display: none; flex-direction: column; align-items: stretch;
    width: 100%; gap: 6px; padding-top: 10px;
  }
  header.bar .nav.open { display: flex; }
  header.bar .nav .who { padding: 4px 2px; }
  header.bar .nav .btn, header.bar .nav button { width: 100%; text-align: center; }
}

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px; margin-bottom: 14px;
  box-shadow: var(--shadow);
}
@media (min-width: 1000px) {
  .card { padding: 22px 26px; }
}
@media (max-width: 620px) {
  .card { padding: 14px; }
  .course-head { flex-direction: column; gap: 8px; }
  table.evidence { display: block; overflow-x: auto; white-space: nowrap; }
  article.content table { display: block; overflow-x: auto; }
}

.course-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.course-head h2 { margin: 0 0 4px; font-size: 17px; }
.course-head p { margin: 0; color: var(--muted); font-size: 14px; }

.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.todo { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }

.progress { height: 6px; background: var(--border); border-radius: 999px; margin: 14px 0 4px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); transition: width .3s; }
.progress-label { font-size: 13px; color: var(--muted); }

button, .btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border-radius: 8px; border: 1px solid transparent;
  padding: 8px 16px; background: var(--accent); color: #fff;
  text-decoration: none;
  /* Stejná výška jako u polí, ať řádek formuláře nepřečnívá. */
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 38px; line-height: 1.4;
}
button:hover, .btn:hover { background: var(--accent-dark); }
button.secondary, .btn.secondary { background: transparent; color: var(--accent); border-color: var(--border); }
button.secondary:hover { background: var(--bg); }
button:disabled { opacity: .55; cursor: not-allowed; }

.chapter-list { list-style: none; margin: 16px 0 0; padding: 0; }
.chapter-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0; border-top: 1px solid var(--border);
}
.chapter-list li:first-child { border-top: 0; }
.chapter-list a { flex: 1; text-decoration: none; color: var(--text); }
.chapter-list a:hover { color: var(--accent); }
.tick { width: 20px; text-align: center; color: var(--ok); font-weight: 700; }
.tick.off { color: var(--border); }

article.content { line-height: 1.7; }
article.content p, article.content li { max-width: 78ch; }
article.content h3 { margin-top: 30px; font-size: 1.15em; }
article.content h4 { margin-top: 22px; font-size: 1em; }
article.content ul, article.content ol { padding-left: 1.3em; }
article.content li { margin-bottom: 6px; }
article.content table { border-collapse: collapse; width: 100%; margin: 14px 0; font-size: 14px; }
article.content th, article.content td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; }
article.content blockquote {
  margin: 16px 0; padding: 12px 16px; border-left: 3px solid var(--accent);
  background: var(--bg); border-radius: 0 8px 8px 0;
}
article.content code {
  background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: 90%;
  overflow-wrap: anywhere;
}
article.content pre { overflow-x: auto; }

/* Dlouhé odkazy (např. vložené URL) se musí zalomit, ne přetéct z obrazovky. */
article.content a { overflow-wrap: anywhere; text-decoration: underline; }
article.content, .card, .declaration, .feedback, .question { overflow-wrap: break-word; }
table.evidence td, table.evidence th { overflow-wrap: anywhere; }

.question { border-top: 1px solid var(--border); padding: 22px 0; }
.question:first-of-type { border-top: 0; padding-top: 4px; }

/* Zadání: pořadové číslo vedle textu, ne nad ním. Text otázky chodí z obsahu
   jako <p>, takže mu odebíráme krajní odsazení, aby lícoval s číslem. */
.question .qtext { display: flex; gap: 10px; font-weight: 600; margin-bottom: 14px; }
.question .qnum { color: var(--muted); font-variant-numeric: tabular-nums; flex-shrink: 0; }
.question .qbody { min-width: 0; flex: 1; }
.question .qbody > :first-child { margin-top: 0; }
.question .qbody > :last-child { margin-bottom: 0; }
.question .verdict { flex-shrink: 0; font-size: 18px; line-height: 1.4; }
.question .verdict.ok { color: var(--ok); }
.question .verdict.bad { color: var(--err); }

/* Odpověď: přepínač zarovnaný na první řádek textu, ne k hornímu okraji rámečku. */
.question label {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 11px 14px; border: 1px solid var(--border); border-radius: 8px;
  margin-bottom: 8px; cursor: pointer; transition: border-color .15s, background .15s;
}
.question label:hover { border-color: var(--muted); background: var(--bg); }
.question label input,
.question label .mark { margin-top: calc((1.6em - 18px) / 2); }
.question label input { margin-left: 0; margin-right: 0; margin-bottom: 0; flex-shrink: 0; accent-color: var(--accent); width: 18px; height: 18px; }
.question label .mark { flex-shrink: 0; width: 18px; text-align: center; color: var(--muted); }
.question .atext { min-width: 0; flex: 1; }
/* Text odpovědi je také <p> — bez tohoto by se rámeček roztáhl a přepínač zůstal nahoře. */
.question .atext > p { margin: 0; }
.question .atext > :first-child { margin-top: 0; }
.question .atext > :last-child { margin-bottom: 0; }

/* Zvolená odpověď musí být vidět na první pohled. */
.question label:has(input:checked) {
  border-color: var(--accent); background: var(--ok-bg); background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.question label.correct { background: var(--ok-bg); border-color: var(--ok); }
.question label.wrong { background: var(--err-bg); border-color: var(--err); }
.feedback { font-size: 14px; color: var(--muted); margin-top: 6px; padding-left: 4px; }

.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 15px; }
.alert.err { background: var(--err-bg); color: var(--err); }
.alert.ok { background: var(--ok-bg); color: var(--ok); }

.login { max-width: 420px; margin: 60px auto; text-align: center; }
.login h1 { font-size: 22px; }
.login p { color: var(--muted); }
.google-btn {
  display: inline-flex; align-items: center; gap: 10px; margin-top: 18px;
  background: #fff; color: #3c4043; border: 1px solid #dadce0;
  padding: 11px 22px; border-radius: 8px; font-weight: 600; text-decoration: none;
}
.google-btn:hover { background: #f7f8f8; }

table.evidence { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 12px; }
table.evidence th, table.evidence td { border-bottom: 1px solid var(--border); padding: 8px 6px; text-align: left; }
table.evidence th { color: var(--muted); font-weight: 600; }
table.evidence .row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
table.evidence .row-actions button { padding: 5px 10px; min-height: 30px; font-size: 13px; }

.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* --- Formulářové prvky ---------------------------------------------------- */
input[type="text"], input[type="email"], select, textarea {
  font: inherit; padding: 8px 11px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface); color: var(--text);
  line-height: 1.4; min-height: 38px;
}
input[type="text"]:hover, input[type="email"]:hover, select:hover { border-color: var(--muted); }
input[type="text"]:focus-visible, input[type="email"]:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent);
}
input::placeholder { color: var(--muted); }

/* Výchozí vzhled selectu se liší podle prohlížeče a k ostatním polím neseděl —
   kreslíme si vlastní šipku. */
select {
  appearance: none; -webkit-appearance: none;
  padding-right: 32px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' fill='none' stroke='%235d6675' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  background-size: 11px;
}
@media (prefers-color-scheme: dark) {
  select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' fill='none' stroke='%239aa3b2' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  }
  /* Rozbalený seznam kreslí systém — ať v tmavém režimu není bílý. */
  select option { background: var(--surface); color: var(--text); }
}

/* Zaškrtávátka ve formulářích jako přepínače, ať nesplývají s textem. */
.row > label.muted {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); cursor: pointer; min-height: 38px; user-select: none;
}
.row > label.muted:hover { border-color: var(--muted); }
.row > label.muted:has(input:checked) {
  border-color: var(--accent); color: var(--accent); background: var(--bg);
}
.row > label.muted input { margin: 0; accent-color: var(--accent); }

.muted { color: var(--muted); font-size: 14px; }


/* --- Videa --------------------------------------------------------------- */
.video-block { margin: 22px 0; }
.video-block h4 { margin: 0 0 8px; font-size: 15px; }
.video-frame {
  position: relative; width: 100%; aspect-ratio: 16 / 9;
  border-radius: 8px; overflow: hidden; border: 1px solid var(--border); background: #000;
}
.video-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
/* Reels jsou na výšku a vložený rámeček Instagramu má navíc vlastní hlavičku a patičku. */
.video-frame.instagram { aspect-ratio: 400 / 660; max-width: 400px; background: var(--surface); }
.video-block .note { font-size: 14px; color: var(--muted); margin-top: 6px; }

/* --- Historie a potvrzení ------------------------------------------------ */
.history { margin-top: 16px; font-size: 14px; }
.history summary { cursor: pointer; color: var(--muted); font-weight: 600; }
.history table { width: 100%; border-collapse: collapse; margin-top: 10px; }
.history th, .history td { border-bottom: 1px solid var(--border); padding: 6px 6px; text-align: left; }
.history th { color: var(--muted); font-weight: 600; }
.run-label { font-size: 13px; color: var(--muted); }
.declaration {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 14px; margin: 12px 0; font-size: 14px; line-height: 1.6;
}
/* Prohlášení nad odesláním testu — musí být zjevně součástí odesílaného úkonu. */
#quiz-declaration { border-left: 3px solid var(--accent); margin-top: 20px; }

/* --- Rozložení kapitoly se seznamem kapitol ------------------------------- */
.course-layout { margin-top: 14px; }
.chapter-meta { font-size: 13px; color: var(--muted); }

.chapter-nav { margin-bottom: 14px; }
.chapter-nav details {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow);
}
.chapter-nav summary { cursor: pointer; font-weight: 600; font-size: 14px; }
.chapter-nav .chapter-list { margin-top: 8px; }
.chapter-nav .chapter-list li { padding: 6px 0; font-size: 14px; }
.chapter-nav .chapter-list li.active a { color: var(--accent); font-weight: 600; }

@media (min-width: 900px) {
  .course-layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 26px; align-items: start; }
  .chapter-nav { position: sticky; top: 16px; margin-bottom: 0; }
  .chapter-nav details { max-height: calc(100vh - 40px); overflow-y: auto; }
  /* Na širokém displeji je seznam trvale otevřený — skrýt šipku rozbalování. */
  .chapter-nav summary { list-style: none; cursor: default; color: var(--muted); }
  .chapter-nav summary::-webkit-details-marker { display: none; }
}


/* --- Sekce Povolené účty -------------------------------------------------- */
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 4px;
}
.section-head h2 { margin: 0; }

.badge.warn { background: #fdf3d8; color: #7a5a05; }
.badge.group { background: var(--bg); color: var(--muted); border: 1px solid var(--border); font-weight: 500; }
.alert.warn { background: #fdf3d8; color: #7a5a05; }
@media (prefers-color-scheme: dark) {
  .badge.warn, .alert.warn { background: #3a2f12; color: #f0cd6b; }
}

.user-form {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-top: 14px; background: var(--bg);
}
.user-form .form-title { font-weight: 600; margin-bottom: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 620px) { .form-grid { grid-template-columns: 1fr; } }
.form-grid .field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.form-grid .field-wide { grid-column: 1 / -1; }
.form-grid label, .form-grid legend { font-size: 13px; font-weight: 600; color: var(--muted); }
.form-grid fieldset { border: 0; margin: 0; padding: 0; }
.form-grid fieldset legend { padding: 0; margin-bottom: 6px; }
.form-grid .row > label.muted { font-size: 14px; font-weight: 400; color: var(--text); }
.form-grid .hint { color: var(--muted); font-size: 12px; }
.form-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
input[readonly] { background: var(--bg); color: var(--muted); cursor: not-allowed; }

.users-table td { vertical-align: top; }
.users-table td .muted { font-size: 13px; }
.users-table tr.inactive td { opacity: .55; }
