/* ── Google Fonts ── */
@import url('https://fonts.googleapis.com/css2?family=Lora:wght@600;700&family=DM+Sans:wght@400;500;600&display=swap');

/* ── Design tokens (light mode) ── */
:root {
  --color-bg:        #f5f7fa;
  --color-surface:   #ffffff;
  --color-surface2:  #eef1f6;
  --color-border:    #dde1ea;
  --color-text:      #1a1d23;
  --color-text-muted:#6b7280;
  --color-primary:   #2563eb;
  --color-primary-h: #1d4ed8;
  --color-success:   #16a34a;
  --color-hint:      #d97706;
  --color-danger:    #dc2626;
  --color-shadow:    rgba(0,0,0,.08);

  --font-ui:   'DM Sans', system-ui, sans-serif;
  --font-head: 'Lora', Georgia, serif;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;

  --transition: .18s ease;
}

/* ── Dark mode ── */
[data-theme="dark"] {
  --color-bg:        #0f1117;
  --color-surface:   #1a1d27;
  --color-surface2:  #242736;
  --color-border:    #2e3244;
  --color-text:      #e8eaf0;
  --color-text-muted:#8892a4;
  --color-primary:   #3b82f6;
  --color-primary-h: #60a5fa;
  --color-success:   #22c55e;
  --color-hint:      #f59e0b;
  --color-danger:    #f87171;
  --color-shadow:    rgba(0,0,0,.3);
}

/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--font-ui);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100dvh;
  line-height: 1.6;
  transition: background var(--transition), color var(--transition);
}

a { color: var(--color-primary); text-decoration: none; }

/* ── Utility ── */
.hidden { display: none !important; }

/* ── Layout ── */
.app-container {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 1rem;
  width: 100%;
}

/* ── App header ── */
.app-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px var(--color-shadow);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1rem;
  max-width: 860px;
  margin: 0 auto;
}

.app-logo {
  font-family: var(--font-head);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--color-primary);
  letter-spacing: -.01em;
}

.app-logo span { color: var(--color-text); }

.btn-icon {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: .4rem .6rem;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--color-text);
  transition: background var(--transition);
}
.btn-icon:hover { background: var(--color-surface2); }

/* ── Screens ── */
.screen { padding: 2rem 0 4rem; }

/* ── Home screen ── */
.screen-title {
  font-family: var(--font-head);
  font-size: 1.9rem;
  font-weight: 700;
  margin-bottom: .4rem;
  color: var(--color-text);
}

.screen-subtitle {
  color: var(--color-text-muted);
  margin-bottom: 2rem;
  font-size: .95rem;
}

/* ── Topic grid ── */
.temata-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.tema-karta {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}

.tema-karta:hover, .tema-karta:focus-visible {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px var(--color-shadow);
  border-color: var(--color-primary);
  outline: none;
}

.tema-ikona {
  font-size: 2rem;
  margin-bottom: .5rem;
  line-height: 1;
}

.tema-nazev {
  font-family: var(--font-head);
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: .3rem;
}

.tema-popis {
  font-size: .82rem;
  color: var(--color-text-muted);
  margin-bottom: .75rem;
  line-height: 1.4;
}

.tema-meta {
  display: flex;
  justify-content: space-between;
  font-size: .78rem;
  color: var(--color-text-muted);
  margin-bottom: .4rem;
}

.tema-procent { font-weight: 600; color: var(--color-primary); }

/* ── Progress bar ── */
.progress-bar {
  height: 6px;
  background: var(--color-surface2);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: 999px;
  transition: width .4s ease;
}

/* ── Task screen ── */
.uloha-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: 1.25rem;
}

.btn-back {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: .35rem .7rem;
  font-size: .85rem;
  color: var(--color-text-muted);
  cursor: pointer;
  font-family: var(--font-ui);
  transition: background var(--transition), color var(--transition);
}
.btn-back:hover { background: var(--color-surface2); color: var(--color-text); }

.uloha-tema-nazev {
  font-size: .9rem;
  font-weight: 600;
  color: var(--color-text-muted);
}

.uloha-progress-wrap {
  margin-bottom: 1.5rem;
}

.uloha-progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: .78rem;
  color: var(--color-text-muted);
  margin-bottom: .3rem;
}

/* ── Dialog log ── */
.dialog-log {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1rem;
  min-height: 240px;
  max-height: 480px;
  overflow-y: auto;
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: .6rem;
  scroll-behavior: smooth;
}

/* ── Messages ── */
.msg {
  display: flex;
  gap: .6rem;
  align-items: flex-start;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .22s ease, transform .22s ease;
}

.msg.msg-visible {
  opacity: 1;
  transform: none;
}

.msg-ikona {
  font-size: 1.1rem;
  line-height: 1.5;
  flex-shrink: 0;
}

.msg-obsah { flex: 1; min-width: 0; }

.msg-label {
  display: block;
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: .15rem;
  color: var(--color-text-muted);
}

.msg-text {
  font-size: .92rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Message type colours */
.msg-system .msg-text  { color: var(--color-text); font-weight: 500; }
.msg-student           { justify-content: flex-end; }
.msg-student .msg-obsah { background: var(--color-surface2); border-radius: var(--radius-sm); padding: .5rem .75rem; max-width: 80%; }
.msg-student .msg-label { color: var(--color-primary); }
.msg-hint .msg-text    { color: var(--color-hint); }
.msg-hint .msg-label   { color: var(--color-hint); }
.msg-uspech .msg-text  { color: var(--color-success); font-weight: 600; }
.msg-uspech .msg-label { color: var(--color-success); }
.msg-reseni .msg-text  { color: var(--color-danger); }
.msg-reseni .msg-label { color: var(--color-danger); }

/* ── Input area ── */
.vstup-area {
  display: flex;
  gap: .6rem;
  align-items: flex-end;
}

.vstup-pole {
  flex: 1;
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: .65rem .9rem;
  font-family: var(--font-ui);
  font-size: .95rem;
  color: var(--color-text);
  resize: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  min-height: 48px;
}

.vstup-pole:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}

.vstup-pole:disabled {
  opacity: .55;
  cursor: not-allowed;
}

.vstup-pole.shake {
  animation: shake .35s ease;
}

@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%      { transform: translateX(-6px); }
  60%      { transform: translateX(6px); }
}

/* ── Buttons ── */
.btn-primary {
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: .65rem 1.2rem;
  font-family: var(--font-ui);
  font-size: .92rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
  white-space: nowrap;
}
.btn-primary:hover:not(:disabled) { background: var(--color-primary-h); transform: translateY(-1px); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: .6rem 1.1rem;
  font-family: var(--font-ui);
  font-size: .9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition);
}
.btn-secondary:hover { background: var(--color-surface2); }

.btn-dalsi {
  margin-top: .75rem;
  width: 100%;
  padding: .75rem;
  font-size: 1rem;
}

/* ── Results screen ── */
.vysledky-hero {
  text-align: center;
  padding: 2rem 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  margin-bottom: 1.5rem;
}

.vysledky-procent {
  font-family: var(--font-head);
  font-size: 4rem;
  font-weight: 700;
  color: var(--color-primary);
  line-height: 1;
  margin-bottom: .5rem;
}

.vysledky-popis {
  color: var(--color-text-muted);
  font-size: 1rem;
  margin-bottom: 1rem;
}

.vysledky-spravne {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-text);
}

.vysledky-breakdown {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  font-size: .9rem;
  color: var(--color-text-muted);
}

.vysledky-akce {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
}

.vysledky-akce .btn-primary,
.vysledky-akce .btn-secondary {
  flex: 1;
  min-width: 140px;
  text-align: center;
}

/* ── Header akce ── */
.header-akce {
  display: flex;
  gap: .4rem;
  align-items: center;
}

/* ── User dropdown ── */
.user-dropdown-wrap {
  position: relative;
}

.btn-avatar {
  display: flex;
  align-items: center;
  gap: .35rem;
  background: var(--color-surface2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: .3rem .55rem;
  cursor: pointer;
  color: var(--color-text);
  transition: background .15s;
}
.btn-avatar:hover { background: var(--color-border); }

.avatar-inicialy {
  width: 1.55rem;
  height: 1.55rem;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .72rem;
  font-weight: 700;
}

.avatar-chevron {
  font-size: .7rem;
  color: var(--color-text-muted);
}

.user-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + .4rem);
  min-width: 200px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
  z-index: 200;
  padding: .4rem 0;
}

.dropdown-email {
  padding: .45rem 1rem;
  font-size: .82rem;
  color: var(--color-text-muted);
  word-break: break-all;
}

.dropdown-divider {
  height: 1px;
  background: var(--color-border);
  margin: .3rem 0;
}

.dropdown-label {
  padding: .3rem 1rem .1rem;
  font-size: .72rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.dropdown-tridy { padding: .1rem 0; }

.dropdown-trida-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .38rem 1rem;
  font-size: .88rem;
  cursor: pointer;
  color: var(--color-text);
  transition: background .1s;
}
.dropdown-trida-item:hover { background: var(--color-surface2); }
.dropdown-trida-item.aktivni { color: var(--color-primary); font-weight: 600; }

.dropdown-odhlasit {
  width: 100%;
  text-align: left;
  padding: .38rem 1rem;
  font-size: .88rem;
  color: var(--color-danger);
  background: none;
  border: none;
  cursor: pointer;
  transition: background .1s;
}
.dropdown-odhlasit:hover { background: var(--color-surface2); }

/* ── Home header ── */
.home-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.home-header .screen-subtitle { margin-bottom: 0; }

/* ── AI status badge ── */
.ai-stav {
  font-size: .78rem;
  font-weight: 600;
  padding: .35rem .75rem;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
  margin-top: .25rem;
}
.ai-on  { background: #dcfce7; color: #15803d; border: 1px solid #86efac; }
.ai-off { background: var(--color-surface2); color: var(--color-text-muted); border: 1px solid var(--color-border); }
[data-theme="dark"] .ai-on { background: #14532d; color: #4ade80; border-color: #166534; }

/* ── API klíč obrazovka ── */
.apikey-container {
  display: flex;
  justify-content: center;
  padding-top: 3rem;
}

.apikey-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 4px 24px var(--color-shadow);
}

.apikey-ikona {
  font-size: 2.5rem;
  margin-bottom: .75rem;
  line-height: 1;
}

.apikey-card .screen-title   { margin-bottom: .4rem; }
.apikey-card .screen-subtitle { margin-bottom: 1.5rem; font-size: .88rem; }

.apikey-label {
  display: block;
  font-size: .82rem;
  font-weight: 600;
  margin-bottom: .35rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.apikey-input {
  width: 100%;
  background: var(--color-bg);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: .65rem .9rem;
  font-family: var(--font-ui);
  font-size: .95rem;
  color: var(--color-text);
  transition: border-color var(--transition), box-shadow var(--transition);
  margin-bottom: .5rem;
}
.apikey-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}

.apikey-bezpecnost {
  font-size: .78rem;
  color: var(--color-text-muted);
  margin-bottom: .75rem;
  line-height: 1.5;
}

.apikey-chyba {
  font-size: .82rem;
  color: var(--color-danger);
  margin-bottom: .75rem;
}

.apikey-akce {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  margin-bottom: 1rem;
}
.apikey-akce .btn-primary,
.apikey-akce .btn-secondary { width: 100%; text-align: center; }

.apikey-footer { text-align: center; }

.btn-link {
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-size: .8rem;
  cursor: pointer;
  font-family: var(--font-ui);
  text-decoration: underline;
  padding: 0;
}
.btn-link:hover { color: var(--color-danger); }

/* ── Loading indikátor (3 tečky) ── */
.msg-loading .msg-text { display: none; }

.loading-dots {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: .1rem 0;
}
.loading-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-hint);
  animation: blink 1.2s infinite ease-in-out both;
}
.loading-dots span:nth-child(1) { animation-delay: 0s; }
.loading-dots span:nth-child(2) { animation-delay: .2s; }
.loading-dots span:nth-child(3) { animation-delay: .4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: .2; transform: scale(.8); }
  40%           { opacity: 1;  transform: scale(1); }
}

/* ── API error zpráva ── */
.msg-apierror .msg-text  { color: var(--color-danger); font-size: .82rem; }
.msg-apierror .msg-label { color: var(--color-danger); }

/* ── Scrollbar (webkit) ── */
.dialog-log::-webkit-scrollbar { width: 6px; }
.dialog-log::-webkit-scrollbar-track { background: transparent; }
.dialog-log::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 999px; }

/* ══════════════════════════════════════════════════════════════
   NOVÉ KOMPONENTY (produkční rozšíření)
══════════════════════════════════════════════════════════════ */

/* ── Auth tabs (přihlášení / registrace) ── */
.auth-tabs {
  display: flex;
  gap: .5rem;
  margin-bottom: 1.5rem;
}

.auth-tab {
  flex: 1;
  padding: .55rem;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: .85rem;
  font-weight: 500;
  color: var(--color-text-muted);
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.auth-tab.auth-tab-active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

.auth-tab:hover:not(.auth-tab-active) {
  background: var(--color-surface2);
  color: var(--color-text);
}

/* Checkbox "Zůstat přihlášen" */
.auth-zapamatovat {
  display: flex;
  align-items: center;
  gap: .45rem;
  font-size: .88rem;
  color: var(--color-text-muted);
  cursor: pointer;
  margin-bottom: .25rem;
  user-select: none;
}
.auth-zapamatovat input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  cursor: pointer;
  accent-color: var(--color-primary);
}

/* Select ve stylu apikey-input */
select.apikey-input {
  appearance: auto;
  cursor: pointer;
}

/* ── Dvoupanelové rozvržení úlohy ── */
.app-container--wide {
  max-width: 1160px;
  margin: 0 auto;
  padding: 0 1rem;
}

.uloha-dual-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  align-items: start;
}

.uloha-panel { min-width: 0; }

/* Pravý panel — výpočetní kroky */
.uloha-panel--vypocet {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1rem;
  position: sticky;
  top: calc(56px + 1rem); /* výška app-header + mezera */
  max-height: calc(100dvh - 90px);
  overflow-y: auto;
}

.vypocet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .75rem;
  padding-bottom: .5rem;
  border-bottom: 1px solid var(--color-border);
}

.vypocet-nadpis {
  font-size: .82rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.vypocet-log {
  display: flex;
  flex-direction: column;
  gap: .45rem;
}

/* Krok výpočtu */
.vypocet-krok {
  padding: .45rem .7rem;
  border-radius: var(--radius-sm);
  font-size: .88rem;
  border-left: 3px solid var(--color-border);
  background: var(--color-surface2);
  color: var(--color-text-muted);
  word-break: break-word;
  line-height: 1.5;
}

.vypocet-krok--spravne {
  background: #f0fdf4;
  border-left-color: var(--color-success);
  color: #15803d;
}

.vypocet-krok--spatne {
  background: #fef2f2;
  border-left-color: var(--color-danger);
  color: var(--color-danger);
}

.vypocet-krok--napoveda {
  background: #fff7ed;
  border-left-color: #f97316;
  color: #c2410c;
}

.vypocet-krok--vysledek {
  background: #f0fdf4;
  border-left-color: var(--color-success);
  color: #15803d;
  font-weight: 700;
}

[data-theme="dark"] .vypocet-krok--spravne {
  background: rgba(20, 83, 45, .25);
  color: #4ade80;
}

[data-theme="dark"] .vypocet-krok--spatne {
  background: rgba(127, 29, 29, .25);
  color: #f87171;
}

[data-theme="dark"] .vypocet-krok--napoveda {
  background: rgba(124, 45, 18, .25);
  color: #fb923c;
}

[data-theme="dark"] .vypocet-krok--vysledek {
  background: rgba(20, 83, 45, .25);
  color: #4ade80;
  font-weight: 700;
}

/* KaTeX scrollbar ve výpočetním panelu */
.uloha-panel--vypocet::-webkit-scrollbar { width: 5px; }
.uloha-panel--vypocet::-webkit-scrollbar-track { background: transparent; }
.uloha-panel--vypocet::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 999px; }

/* ── Zamčené téma ── */
.tema-karta--zamcena {
  opacity: .5;
  cursor: not-allowed;
  position: relative;
}

.tema-karta--zamcena:hover,
.tema-karta--zamcena:focus-visible {
  transform: none;
  box-shadow: none;
  border-color: var(--color-border);
}

.tema-zamek {
  position: absolute;
  top: .75rem;
  right: .75rem;
  font-size: 1rem;
}

.tema-zamceno-text {
  font-size: .75rem;
  color: var(--color-text-muted);
  margin-top: .4rem;
  font-style: italic;
}

/* ── Denní sada (hero sekce na home screen) ── */
.denni-sada-sekce {
  background: linear-gradient(135deg, var(--color-primary) 0%, #7c3aed 100%);
  border-radius: var(--radius-lg);
  padding: 1.5rem 1.75rem;
  margin-bottom: 1.75rem;
  color: #fff;
}

.denni-sada-sekce .sekce-nadpis {
  font-family: var(--font-head);
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: .3rem;
  color: #fff;
}

.denni-sada-sekce .sekce-popis {
  font-size: .85rem;
  opacity: .85;
  margin-bottom: 1rem;
}

.denni-sada-sekce .btn-primary {
  background: rgba(255, 255, 255, .2);
  border: 1.5px solid rgba(255, 255, 255, .4);
  color: #fff;
  backdrop-filter: blur(4px);
}

.denni-sada-sekce .btn-primary:hover {
  background: rgba(255, 255, 255, .32);
  transform: translateY(-1px);
}

/* ── Responsive — nové komponenty ── */
@media (max-width: 768px) {
  .uloha-dual-panel {
    grid-template-columns: 1fr;
  }

  .uloha-panel--vypocet {
    position: static;
    max-height: 260px;
    order: -1; /* výpočetní panel jde nad dialog na mobilu */
  }

  .app-container--wide { padding: 0 1rem; }
}

@media (max-width: 520px) {
  .screen-title { font-size: 1.5rem; }
  .temata-grid  { grid-template-columns: 1fr; }
  .vstup-area   { flex-direction: column; }
  .vstup-area .btn-primary { width: 100%; }
  .vysledky-procent { font-size: 3rem; }
  .denni-sada-sekce { padding: 1.25rem; }
}
