/* =============================================================
   Kita-Konzept Generator – Design basiert auf BE:KI Grade
   Blau: #1e3d73  |  Grün: #3a8c68  |  BG: #f0f4f8
   ============================================================= */

/* ── Variables ─────────────────────────────────────────────────────────── */
:root {
  --primary:        #1e3d73;
  --primary-hover:  #2a4f8f;
  --primary-light:  #3a8c68;
  --accent:         #3a8c68;
  --accent-hover:   #2d7055;
  --bg:             #f0f4f8;
  --surface:        #ffffff;
  --border:         #dde3ec;
  --border-focus:   #3a8c68;
  --text:           #1e293b;
  --text-muted:     #6b7a8d;
  --text-light:     #9ba8bb;
  --success:        #3a8c68;
  --error:          #c0392b;
  --error-bg:       #fef2f2;
  --radius:         12px;
  --radius-sm:      8px;
  --shadow:         0 2px 12px rgba(30,61,115,.08);
  --shadow-lg:      0 8px 32px rgba(30,61,115,.14);
  --transition:     .2s ease;
}

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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: linear-gradient(135deg, #1e3d73 0%, #2a6b52 55%, #3a8c68 100%);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: rgba(255,255,255,.08); }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.3); border-radius: 3px; }

/* Animationen */
@keyframes spin    { to { transform: rotate(360deg); } }
@keyframes fadeIn  { from { opacity:0; transform:translateY(6px); } to { opacity:1; transform:translateY(0); } }

/* ── Layout ────────────────────────────────────────────────────────────── */
.container { max-width: 860px; margin: 0 auto; padding: 0 1.5rem; }
.hidden    { display: none !important; }

/* ── Header ────────────────────────────────────────────────────────────── */
.app-header {
  background: #fff;
  border-bottom: 3px solid var(--primary);
  box-shadow: 0 2px 10px rgba(30,61,115,.12);
  position: sticky;
  top: 0;
  z-index: 200;
}
.header-inner {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1.5rem;
}
.header-text  { display: flex; flex-direction: column; gap: .1rem; }
.app-title    {
  font-family: Georgia, serif;
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: .02em;
  color: var(--primary);
}
.app-subtitle { font-size: .75rem; color: var(--text-muted); }

/* ── Settings panel ────────────────────────────────────────────────────── */
.settings-overlay {
  position: fixed; inset: 0;
  background: rgba(30,61,115,.25);
  z-index: 300;
  cursor: pointer;
}
.settings-panel {
  position: fixed;
  top: 0; right: 0;
  width: 360px; max-width: 100vw;
  height: 100vh;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  z-index: 400;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.4rem;
  border-bottom: 3px solid var(--primary);
  background: var(--primary);
  color: #fff;
}
.settings-header h2 { font-size: 1rem; font-weight: 700; }
.settings-body  { padding: 1.4rem; display: flex; flex-direction: column; gap: 1rem; }
.settings-status {
  padding: .65rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .87rem;
  font-weight: 600;
}
.settings-status.ok  { background: #f0faf5; color: var(--success); border: 1px solid #c8e8d8; }
.settings-status.err { background: var(--error-bg); color: var(--error); border: 1px solid #fca5a5; }

/* ── Form elements ─────────────────────────────────────────────────────── */
.form-label {
  font-size: .83rem;
  font-weight: 700;
  color: var(--text);
  display: block;
  margin-bottom: .35rem;
  letter-spacing: .02em;
}
.form-hint { font-size: .76rem; color: var(--text-muted); margin-top: -.5rem; }
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: .65rem .9rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .92rem;
  font-family: inherit;
  color: var(--text);
  background: #f8fafc;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(58,140,104,.18);
}
.form-textarea { resize: vertical; min-height: 110px; }
.input-row { display: flex; gap: .5rem; align-items: center; }
.input-row .form-input { flex: 1; }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .65rem 1.5rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: .93rem; font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: background var(--transition), transform var(--transition);
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); transform: translateY(-1px); }
.btn-primary:disabled { background: #c8d0dc; cursor: not-allowed; transform: none; }

.btn-secondary {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .65rem 1.4rem;
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary);
  border-radius: var(--radius-sm);
  font-size: .93rem; font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: background var(--transition), color var(--transition);
}
.btn-secondary:hover { background: var(--primary); color: #fff; }

.btn-accent {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .65rem 1.5rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: .93rem; font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 3px 10px rgba(58,140,104,.35);
  transition: background var(--transition), transform var(--transition);
}
.btn-accent:hover:not(:disabled) { background: var(--accent-hover); transform: translateY(-1px); }
.btn-accent:disabled { background: #8fb8a8; cursor: not-allowed; box-shadow: none; transform: none; }

.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--primary);
  padding: .4rem;
  border-radius: 6px;
  transition: background var(--transition);
}
.btn-icon:hover { background: rgba(30,61,115,.08); }
.settings-header .btn-icon { color: #fff; }
.settings-header .btn-icon:hover { background: rgba(255,255,255,.15); }

.btn-full  { width: 100%; }
.btn-ghost {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: .88rem;
  font-family: inherit;
  padding: .45rem .8rem;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
}
.btn-ghost:hover { color: var(--primary); background: #eef2fa; }

/* ── Main area ─────────────────────────────────────────────────────────── */
.app-main { padding: 2rem 1.5rem 5rem; }

/* ── Cards ─────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 4px 24px rgba(0,0,0,.18);
  padding: 2rem;
  border: 1px solid var(--border);
}

/* ── Welcome screen ────────────────────────────────────────────────────── */
.welcome-wrap  { max-width: 640px; margin: 0 auto; }
.welcome-icon  {
  width: 72px; height: 72px;
  background: var(--primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 1.5rem;
  color: #fff;
  box-shadow: 0 4px 14px rgba(30,61,115,.3);
}
.welcome-title { text-align: center; font-size: 1.55rem; font-weight: 800; margin-bottom: .5rem; color: var(--primary); font-family: Georgia, serif; }
.welcome-sub   { text-align: center; color: var(--text-muted); margin-bottom: 2rem; }
.welcome-info  {
  background: #eef2fa;
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 1rem 1.2rem;
  margin-bottom: 2rem;
  font-size: .9rem;
}
.welcome-info h3    { font-size: .93rem; margin-bottom: .4rem; color: var(--primary); font-weight: 700; }
.welcome-steps      { list-style: none; display: flex; flex-direction: column; gap: .5rem; counter-reset: li; }
.welcome-steps li::before {
  content: counter(li) '. ';
  counter-increment: li;
  font-weight: 700;
  color: var(--primary);
}

.api-warning {
  background: #fff7ed;
  border-left: 4px solid #f59e0b;
  border-radius: var(--radius-sm);
  padding: .9rem 1.1rem;
  margin-bottom: 1.5rem;
  font-size: .87rem;
  color: #7c4a0a;
}
.welcome-actions { display: flex; justify-content: center; gap: 1rem; flex-wrap: wrap; }

/* ── Templates ─────────────────────────────────────────────────────────── */
.template-row { display: flex; gap: .6rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.btn-template {
  padding: .45rem .95rem;
  border: 1.5px solid var(--primary);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--primary);
  font-size: .83rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: background var(--transition), color var(--transition);
}
.btn-template:hover { background: var(--primary); color: #fff; }

/* ── Example answer ─────────────────────────────────────────────────────── */
.btn-example {
  font-size: .71rem;
  color: var(--text-light);
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: 4px;
  padding: .13rem .5rem;
  cursor: pointer;
  font-family: inherit;
  transition: color var(--transition), border-color var(--transition);
  margin-bottom: .35rem;
}
.btn-example:hover { color: var(--accent); border-color: var(--accent); }

/* ── Progress bar ──────────────────────────────────────────────────────── */
.progress-wrap { margin-bottom: 1.5rem; }
.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: .81rem;
  color: var(--text-muted);
  margin-bottom: .4rem;
}
.progress-bar  { height: 5px; background: var(--border); border-radius: 99px; overflow: hidden; }
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 99px;
  transition: width .4s ease;
}

/* ── Quiz screen ───────────────────────────────────────────────────────── */
.cat-badge {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  font-size: .72rem; font-weight: 700;
  padding: .22rem .7rem;
  border-radius: 99px;
  margin-bottom: .75rem;
  letter-spacing: .5px;
  text-transform: uppercase;
}
.quiz-title      { font-size: 1.25rem; font-weight: 800; color: var(--primary); margin-bottom: 1.5rem; }
.question-block  { margin-bottom: 1.6rem; }
.question-block:last-child { margin-bottom: 0; }
.question-label  { font-size: .92rem; font-weight: 700; margin-bottom: .4rem; display: flex; align-items: baseline; gap: .5rem; }
.q-num {
  display: inline-block;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: .7rem; font-weight: 800;
  text-align: center;
  line-height: 22px;
  flex-shrink: 0;
}
.question-hint { font-size: .79rem; color: var(--text-muted); margin-bottom: .5rem; font-style: italic; }
.quiz-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 2rem;
  gap: 1rem;
}

/* ── Review screen ─────────────────────────────────────────────────────── */
.review-header { margin-bottom: 1.5rem; }
.review-header h2 { font-size: 1.25rem; font-weight: 800; color: var(--primary); margin-bottom: .3rem; }
.review-section { margin-bottom: 1.5rem; }
.review-section-title {
  font-size: .76rem; font-weight: 800;
  letter-spacing: .8px; text-transform: uppercase;
  color: var(--text-light);
  padding: .5rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: .9rem;
}
.review-item   { margin-bottom: .9rem; }
.review-q      { font-size: .84rem; font-weight: 700; color: var(--text-muted); margin-bottom: .2rem; }
.review-a {
  font-size: .92rem;
  background: #f8fafc;
  border-radius: var(--radius-sm);
  padding: .6rem .8rem;
  border: 1px solid var(--border);
  white-space: pre-wrap;
  color: var(--text);
}
.review-a.empty { color: var(--text-light); font-style: italic; }
.review-actions {
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

/* ── Empty-field warning ────────────────────────────────────────────────── */
.empty-warning {
  background: #fff7ed;
  border: 1.5px solid #f59e0b;
  border-radius: var(--radius-sm);
  padding: 1rem 1.2rem;
  margin-bottom: 1rem;
  font-size: .87rem;
  color: #7c4a0a;
}
.empty-warning ul { padding-left: 1.2rem; margin-top: .4rem; }
.empty-warning li { margin-bottom: .2rem; }

/* ── Result screen ─────────────────────────────────────────────────────── */
.result-header         { margin-bottom: 1.2rem; }
.result-header h2      { font-size: 1.25rem; font-weight: 800; color: var(--primary); margin-bottom: .3rem; }
.result-header p       { color: var(--text-muted); font-size: .9rem; }

.streaming-box {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1.4rem;
  max-height: 60vh;
  overflow-y: auto;
  background: #f8fafc;
  font-size: .91rem;
  line-height: 1.75;
  white-space: pre-wrap;
  color: var(--text);
}
.concept-box {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1.8rem;
  overflow-y: auto;
  background: #f8fafc;
  font-size: .93rem;
  line-height: 1.8;
  color: var(--text);
  margin-top: 1.2rem;
}
.concept-box h1, .concept-box h2, .concept-box h3 { color: var(--primary); margin-top: 1.6rem; margin-bottom: .6rem; }
.concept-box h1 { font-size: 1.35rem; font-family: Georgia, serif; }
.concept-box h2 { font-size: 1.1rem; }
.concept-box h3 { font-size: 1rem; }
.concept-box p  { margin-bottom: .8rem; }
.concept-box ul, .concept-box ol { padding-left: 1.5rem; margin-bottom: .8rem; }
.concept-box li { margin-bottom: .3rem; }
.concept-box strong { color: var(--primary); }
.concept-box hr { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }
.concept-box table { border-collapse: collapse; width: 100%; margin-bottom: 1rem; font-size: .88rem; }
.concept-box th, .concept-box td { border: 1px solid var(--border); padding: .5rem .8rem; }
.concept-box th { background: #eef2fa; color: var(--primary); font-weight: 700; }

.loading-row {
  display: flex; align-items: center; gap: .8rem;
  margin-bottom: 1rem;
  font-size: .9rem; color: var(--text-muted);
}
.spinner {
  width: 22px; height: 22px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  flex-shrink: 0;
}
.result-actions { display: flex; gap: .7rem; margin-top: 1.2rem; flex-wrap: wrap; }
.error-box {
  background: var(--error-bg);
  border: 1.5px solid #fca5a5;
  border-radius: var(--radius-sm);
  padding: 1rem 1.2rem;
  color: var(--error);
  font-size: .9rem;
  margin-top: .5rem;
}

/* ── Edit mode ──────────────────────────────────────────────────────────── */
.concept-editor {
  width: 100%;
  min-height: 500px;
  border: 1.5px solid var(--border-focus);
  border-radius: var(--radius-sm);
  padding: 1.2rem;
  font-family: 'Courier New', monospace;
  font-size: .91rem;
  line-height: 1.8;
  color: var(--text);
  background: #f8fafc;
  resize: vertical;
}
.concept-editor:focus { outline: none; box-shadow: 0 0 0 3px rgba(58,140,104,.18); }

/* ── Quality check ──────────────────────────────────────────────────────── */
.quality-panel { margin-top: 1.5rem; border: 1.5px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.quality-panel-header {
  background: var(--primary);
  color: #fff;
  padding: .7rem 1.2rem;
  font-weight: 700; font-size: .93rem;
  display: flex; align-items: center; justify-content: space-between;
}
.quality-body {
  padding: 1.2rem;
  background: #f8fafc;
  font-size: .9rem;
  line-height: 1.75;
}
.quality-body h1, .quality-body h2, .quality-body h3 { color: var(--primary); margin: 1rem 0 .4rem; }
.quality-body p { margin-bottom: .6rem; }
.quality-body ul, .quality-body ol { padding-left: 1.4rem; margin-bottom: .6rem; }

/* ── Chapter regeneration ───────────────────────────────────────────────── */
.chapter-regen {
  margin-top: 1.2rem;
  padding: .9rem 1.1rem;
  background: #eef2fa;
  border: 1px solid #c8d4ea;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; gap: .8rem; flex-wrap: wrap;
}
.chapter-regen label { font-size: .87rem; font-weight: 700; color: var(--primary); white-space: nowrap; }
.chapter-regen select { flex: 1; min-width: 200px; }

/* ── History screen ─────────────────────────────────────────────────────── */
.history-list { display: flex; flex-direction: column; gap: .8rem; }
.history-item {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .85rem 1rem;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  flex-wrap: wrap;
}
.history-meta  { display: flex; flex-direction: column; gap: .12rem; flex: 1; min-width: 0; }
.history-name  { font-weight: 700; font-size: .93rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-date  { font-size: .76rem; color: var(--text-muted); }
.history-model { font-size: .73rem; color: var(--text-light); }
.history-actions { display: flex; gap: .45rem; flex-wrap: wrap; align-items: center; }

/* ── User management ────────────────────────────────────────────────────── */
.user-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: .5rem .7rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-bottom: .4rem;
  background: #f8fafc;
  font-size: .87rem; gap: .5rem;
}
.role-badge {
  display: inline-block; font-size: .63rem; font-weight: 800;
  padding: .1rem .45rem; border-radius: 99px;
  text-transform: uppercase; letter-spacing: .4px; margin-left: .35rem;
}
.role-badge.admin { background: var(--primary); color: #fff; }
.role-badge.user  { background: var(--border);  color: var(--text-muted); }

/* ── Toggle switch ──────────────────────────────────────────────────────── */
.toggle-switch { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--border); border-radius: 24px;
  transition: .25s;
}
.toggle-slider::before {
  content: ''; position: absolute;
  width: 18px; height: 18px;
  left: 3px; bottom: 3px;
  background: #fff; border-radius: 50%;
  transition: .25s;
}
.toggle-switch input:checked + .toggle-slider { background: var(--accent); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(20px); }

.demo-badge {
  display: inline-block;
  background: #f59e0b;
  color: #fff;
  font-size: .68rem; font-weight: 800;
  padding: .1rem .5rem; border-radius: 99px;
  letter-spacing: .4px; text-transform: uppercase;
  margin-left: .5rem; vertical-align: middle;
}

/* ── Divider ────────────────────────────────────────────────────────────── */
.settings-divider { border: none; border-top: 1px solid var(--border); margin: .25rem 0; }

/* ── Footer ─────────────────────────────────────────────────────────────── */
.app-footer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: #fff;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: .72rem;
  padding: .45rem 1.2rem;
  z-index: 100;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}
.footer-left  { display: flex; align-items: center; justify-content: center; gap: .5rem; flex-wrap: wrap; grid-column: 2; }
.footer-right { display: flex; justify-content: flex-end; grid-column: 3; }
.footer-version { font-size: .68rem; color: var(--text-light); font-family: monospace; }
.app-footer a { color: var(--primary); text-decoration: none; font-weight: 600; }
.app-footer a:hover { text-decoration: underline; }
.footer-sep { opacity: .35; }

/* Prevent content hiding behind footer */
.app-main { padding-bottom: 5rem; }

/* ── Dark mode ──────────────────────────────────────────────────────────── */
body.dark-mode {
  background: linear-gradient(135deg, #0a1628 0%, #0d2820 55%, #0f3020 100%);
  --surface:    #192336;
  --border:     #2a3a52;
  --border-focus:#3a8c68;
  --text:       #dde4f0;
  --text-muted: #8899b0;
  --text-light: #5a6e88;
  --error-bg:   #2d1a1a;
  --shadow:     0 2px 12px rgba(0,0,0,.35);
  --shadow-lg:  0 8px 32px rgba(0,0,0,.5);
}
body.dark-mode .app-header       { background: #192336; }
body.dark-mode .app-footer       { background: #192336; border-color: #2a3a52; }
body.dark-mode .settings-panel   { background: #192336; }
body.dark-mode .settings-body    { background: #192336; }
body.dark-mode .card             { background: #192336; border-color: #2a3a52; }
body.dark-mode .form-input,
body.dark-mode .form-select,
body.dark-mode .form-textarea    { background: #1e2d42; color: var(--text); border-color: var(--border); }
body.dark-mode .history-item     { background: #1e2d42; }
body.dark-mode .quality-body     { background: #1e2d42; }
body.dark-mode .chapter-regen    { background: #1a2d3a; border-color: #2a3a52; }
body.dark-mode .compare-actions  { background: #1e2d42; border-color: #2a3a52; }
body.dark-mode .concept-editor   { background: #1e2d42; color: var(--text); }
body.dark-mode .history-search   { background: #1e2d42; color: var(--text); }
body.dark-mode .hb-section,
body.dark-mode .hb-toc           { background: #192336; border-color: #2a3a52; }
body.dark-mode .review-item      { border-color: #2a3a52; }
body.dark-mode .review-section   { border-color: #2a3a52; }
body.dark-mode .review-section-title { background: #1e2d42; }
body.dark-mode .btn-ghost        { color: var(--text-muted); }
body.dark-mode .btn-ghost:hover  { color: var(--primary); background: rgba(30,61,115,.25); }
body.dark-mode ::-webkit-scrollbar-track { background: rgba(255,255,255,.05); }

/* ── Toast ──────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 4rem; right: 1.5rem;
  z-index: 9999;
  display: flex; flex-direction: column; gap: .5rem;
  pointer-events: none;
  align-items: flex-end;
}
.toast {
  padding: .65rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: .86rem; font-weight: 600;
  box-shadow: 0 4px 16px rgba(0,0,0,.22);
  opacity: 0; transform: translateY(10px);
  transition: opacity .22s ease, transform .22s ease;
  pointer-events: none; white-space: nowrap;
}
.toast.visible { opacity: 1; transform: translateY(0); }
.toast.ok      { background: var(--accent); color: #fff; }
.toast.err     { background: var(--error);  color: #fff; }
.toast.info    { background: var(--primary); color: #fff; }

/* ── Concept stats ──────────────────────────────────────────────────────── */
.concept-stats {
  display: flex; gap: .5rem; align-items: center;
  font-size: .75rem; color: var(--text-muted);
  margin: -.2rem 0 .8rem;
}

/* ── Chapter copy button ────────────────────────────────────────────────── */
.chapter-copy-btn {
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid var(--border);
  border-radius: 5px; padding: .15rem .45rem;
  color: var(--text-muted); cursor: pointer;
  font-size: .7rem; margin-left: .6rem;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  vertical-align: middle;
}
.chapter-copy-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Segmented category progress ────────────────────────────────────────── */
.cat-segments {
  display: flex; gap: 3px; height: 6px; border-radius: 99px; overflow: hidden; margin-top: .3rem;
}
.cat-seg {
  flex: 1; background: rgba(255,255,255,.25); border-radius: 99px;
  transition: background .3s ease;
}
.cat-seg.done   { background: var(--accent); }
.cat-seg.active { background: var(--primary); }

/* ── Comparison panel ───────────────────────────────────────────────────── */
.compare-panel {
  margin-top: 1.2rem;
  border: 1.5px solid var(--accent);
  border-radius: var(--radius-sm);
  overflow: hidden;
  animation: fadeIn .2s ease;
}
.compare-header-bar {
  background: var(--accent); color: #fff;
  padding: .6rem 1rem; font-weight: 700; font-size: .9rem;
}
.compare-cols { display: grid; grid-template-columns: 1fr 1fr; }
.compare-col  { padding: 1rem; font-size: .84rem; line-height: 1.7; }
.compare-col:first-child { border-right: 1.5px solid var(--border); }
.compare-col-title {
  font-weight: 700; font-size: .73rem; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-muted); margin-bottom: .5rem;
}
.compare-col-body { white-space: pre-wrap; color: var(--text); max-height: 300px; overflow-y: auto; }
.compare-actions {
  display: flex; gap: .6rem; padding: .75rem 1rem;
  background: #f8fafc; border-top: 1px solid var(--border);
}

/* ── History search ─────────────────────────────────────────────────────── */
.history-search {
  width: 100%; padding: .6rem .9rem;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-size: .9rem; font-family: inherit; color: var(--text);
  background: #f8fafc; margin-bottom: 1rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.history-search:focus {
  outline: none; border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(58,140,104,.18);
}

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .app-main { padding: 1rem 1rem 5rem; }
  .card     { padding: 1.2rem; }
  .quiz-nav { flex-direction: column; }
  .quiz-nav .btn-secondary,
  .quiz-nav .btn-primary { width: 100%; justify-content: center; }
  .settings-panel { width: 100vw; }
}

/* ── Print ──────────────────────────────────────────────────────────────── */
@media print {
  .app-header, .app-footer,
  .settings-overlay, .settings-panel,
  .result-actions, .loading-row,
  .chapter-regen, .quality-panel,
  .btn-primary, .btn-secondary,
  .btn-accent, .btn-ghost { display: none !important; }

  body  { background: #fff; font-size: 11pt; }
  .card { box-shadow: none; border: none; padding: 0; }
  .concept-box {
    max-height: none; overflow: visible;
    border: none; padding: 0; font-size: 11pt; margin-top: 0;
  }
  .concept-box h1 { font-size: 18pt; page-break-after: avoid; }
  .concept-box h2 { font-size: 14pt; page-break-after: avoid; }
  .concept-box h3 { font-size: 12pt; page-break-after: avoid; }
  .concept-box p, .concept-box li { orphans: 3; widows: 3; }
}
