/* =========================================================
   Übungsportal – Klausur-Editor (Q-Examiner-Nachbau, ESH)
   ========================================================= */

:root {
  /* ESH (Default) */
  --c-primary: #104CFB;          /* ESH Blau (bestätigt via esh-stbexamensvorbereitung.de) */
  --c-primary-dark: #0A37C0;
  --c-primary-hover: #2C65F6;
  --c-accent: #FF9725;           /* Q-Examiner Akzent (Toolbar/Warnung) */
  --c-bg: #E8E8E8;               /* Content-/Toolbar-Grau (exakt aus Q-Examiner) */
  --c-surface: #ffffff;
  --c-border: #d8dde6;
  --c-text: #222222;             /* Q-Examiner default-font */
  --c-muted: #5b6478;
  --font-scale: 1;
  --zoom: 1;
}

/* Q-Examiner Türkis (exakte Farben aus CSS-Bundle des Demo-Portals) */
html[data-theme="tuerkis"] {
  --c-primary: #017187;          /* --site-header-background */
  --c-primary-dark: #015565;     /* --button-standard-hover-background */
  --c-primary-hover: #35799e;
}

/* Hochkontrast */
html[data-theme="high"] {
  --c-primary: #000000;
  --c-primary-dark: #000000;
  --c-primary-hover: #222222;
  --c-accent: #000000;
  --c-bg: #ffffff;
  --c-surface: #ffffff;
  --c-border: #000000;
  --c-text: #000000;
  --c-muted: #000000;
}
html[data-theme="high"] .header { border-bottom: 3px solid #000; }
html[data-theme="high"] button,
html[data-theme="high"] select,
html[data-theme="high"] input { border: 2px solid #000 !important; }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--c-bg);
  color: var(--c-text);
  font-family: -apple-system, system-ui, "Segoe UI", "Calibri", Roboto, "Helvetica Neue", sans-serif;
  font-size: calc(15px * var(--font-scale));
}

kbd {
  display: inline-block; padding: 1px 6px; border: 1px solid #b9c0cc; border-bottom-width: 2px;
  border-radius: 4px; background: #f6f7f9; font-size: .85em; font-family: inherit; color: #333;
}

/* ===================== BUTTONS ===================== */
.btn {
  font-family: inherit; font-size: 13px; cursor: pointer;
  padding: 8px 16px; border-radius: 6px; border: 1px solid transparent;
  transition: background .15s, border-color .15s;
}
.btn--primary { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }
.btn--primary:hover { background: var(--c-primary-hover); border-color: var(--c-primary-hover); }
.btn--ghost { background: transparent; color: var(--c-primary); border-color: var(--c-primary); }
.btn--ghost:hover { background: rgba(16,76,251,.08); }
.btn--warn { background: var(--c-accent); color: #fff; border-color: var(--c-accent); }
.btn--warn:hover { filter: brightness(.94); }

/* ===================== SETUP ===================== */
.setup {
  position: fixed; inset: 0; z-index: 1000;
  background: linear-gradient(135deg, #0A1A4D, #050D2B);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.setup[hidden] { display: none; }
.setup__card {
  width: 100%; max-width: 520px; background: #fff; border-radius: 12px;
  padding: 28px 30px; box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.setup__brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--c-primary); }
.setup__logo {
  width: 34px; height: 34px; border-radius: 50%; background: var(--c-primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 13px; letter-spacing: .5px;
}
.setup__title { margin: 14px 0 4px; font-size: 22px; }
.setup__intro { margin: 0 0 18px; color: var(--c-muted); font-size: 13px; }
.setup__row { display: flex; gap: 14px; }
.setup__row .setup__field { flex: 1; }
.setup__field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; font-size: 13px; font-weight: 600; }
.setup__field input[type="text"], .setup__field select {
  font: inherit; font-weight: 400; padding: 9px 11px; border: 1px solid #c8ccd4; border-radius: 7px; background: #fff;
}
.setup__field input:focus, .setup__field select:focus { outline: 2px solid var(--c-primary); border-color: var(--c-primary); }
.setup__field--check { justify-content: flex-start; }
.setup__switch { display: flex; align-items: center; gap: 8px; font-weight: 400; font-size: 12px; color: var(--c-muted); margin-top: 2px; }
.setup__switch input { width: 16px; height: 16px; }
.setup__start {
  width: 100%; margin-top: 8px; padding: 12px; font-size: 15px; font-weight: 600;
  background: var(--c-primary); color: #fff; border: none; border-radius: 8px; cursor: pointer;
}
.setup__start:hover { background: var(--c-primary-hover); }

/* ===================== APP ===================== */
.app { display: flex; flex-direction: column; height: 100vh; min-height: 100vh; }
.app[hidden] { display: none; }

/* HEADER */
.header {
  background: var(--c-primary); color: #fff;
  display: flex; align-items: center; gap: 14px;
  padding: 8px 14px; min-height: 56px; box-shadow: 0 1px 3px rgba(0,0,0,.15);
}
.header__brand { display: flex; align-items: center; gap: 10px; min-width: 190px; }
.header__logo {
  width: 38px; height: 38px; border-radius: 50%; background: #fff; color: var(--c-primary);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; letter-spacing: .5px;
}
.header__ident { font-size: 12px; line-height: 1.2; opacity: .92; }
.header__ident-label { display: block; font-size: 11px; opacity: .85; }
.header__ident strong { font-size: 14px; }
.header__title { flex: 1; text-align: center; font-size: 17px; font-weight: 600; }
.header__tools { display: flex; align-items: center; gap: 8px; }

.tool-btn {
  background: transparent; border: 1px solid rgba(255,255,255,.4); color: #fff;
  padding: 6px 11px; border-radius: 6px; font-size: 13px; cursor: pointer; font-family: inherit;
  transition: background .15s;
}
.tool-btn:hover { background: rgba(255,255,255,.15); }
.tool-btn[aria-pressed="true"] { background: #fff; color: var(--c-primary); font-weight: 600; }
.tool-btn--icon { font-size: 15px; line-height: 1; padding: 6px 9px; }
.tool-btn--end {
  background: #fff; color: var(--c-primary); font-weight: 600; border-color: #fff;
}
.tool-btn--end:hover { background: #eef1ff; }

.font-size-group, .zoom-group { display: inline-flex; align-items: center; gap: 2px; }
.font-size-group .tool-btn[data-size="1"] { font-size: 11px; font-weight: 700; padding: 6px 8px; }
.font-size-group .tool-btn[data-size="2"] { font-size: 14px; font-weight: 700; padding: 6px 8px; }
.font-size-group .tool-btn[data-size="3"] { font-size: 17px; font-weight: 700; padding: 6px 8px; }
.zoom-group .zoom-val { font-size: 12px; min-width: 42px; text-align: center; opacity: .95; }
select.tool-btn { padding-right: 26px; }

.countdown {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px;
  padding: 6px 10px; border-radius: 6px; border: 1px solid rgba(255,255,255,.4); white-space: nowrap;
}
.countdown__icon { font-size: 14px; }
.countdown--warn { background: var(--c-accent); border-color: var(--c-accent); color: #fff; font-weight: 600; animation: pulse 1s infinite; }
.countdown--crit { background: #F24F4F; border-color: #F24F4F; color: #fff; font-weight: 700; animation: pulse .7s infinite; }
@keyframes pulse { 50% { opacity: .55; } }

/* MAIN / EDITOR */
.main { flex: 1; overflow: auto; padding: 16px; display: flex; justify-content: center; }
.editor-wrap {
  width: 210mm; max-width: 100%; flex-shrink: 0; background: var(--c-surface);
  border: 1px solid var(--c-border); border-radius: 4px; box-shadow: 0 1px 4px rgba(0,0,0,.06);
  display: flex; flex-direction: column; overflow: hidden;
}
.editor-wrap .tox.tox-tinymce { border: none; border-radius: 0; min-height: 560px; flex: 1; }
.editor-wrap .tox .tox-toolbar, .editor-wrap .tox .tox-toolbar__primary {
  background: var(--c-bg) !important; border-bottom: 2px solid var(--c-accent) !important;
}
.editor-wrap .tox .tox-tbtn--enabled { background: var(--c-primary) !important; }
.editor-wrap .tox .tox-tbtn--enabled svg { fill: #fff !important; }
.editor-wrap .tox .tox-tbtn:hover { background: rgba(16,76,251,.10) !important; }

/* FOOTER */
.footer {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 8px 16px; background: var(--c-surface); border-top: 1px solid var(--c-border);
  font-size: 12px; color: var(--c-muted);
}
.footer__center { text-align: center; }
.footer__actions { display: flex; gap: 8px; justify-content: flex-end; }
.footer__actions .btn { padding: 7px 13px; }
.autosave { font-size: 12px; color: var(--c-muted); }
.autosave--saving { color: var(--c-accent); }
.autosave--saved { color: #1f9d55; }

/* ===================== MODALE ===================== */
.modal {
  position: fixed; inset: 0; z-index: 1100; background: rgba(0,0,0,.55);
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.modal.is-open { display: flex; }
.modal__dialog {
  width: 95%; max-width: 960px; background: #fff; border-radius: 8px; overflow: hidden;
  display: flex; flex-direction: column; box-shadow: 0 10px 40px rgba(0,0,0,.4); max-height: 92vh;
}
.modal__dialog--small { max-width: 460px; }
.modal__header { display: flex; align-items: center; justify-content: space-between; padding: 12px 18px; color: #fff; }
.modal__header--primary { background: var(--c-primary); }
.modal__header--warn { background: var(--c-accent); }
.modal__title { font-size: 15px; font-weight: 600; }
.modal__close { background: transparent; border: 1px solid rgba(255,255,255,.55); color: #fff; padding: 6px 12px; border-radius: 4px; cursor: pointer; font: inherit; font-size: 13px; }
.modal__close:hover { background: rgba(255,255,255,.18); }
.modal__body { padding: 18px; font-size: 14px; line-height: 1.5; overflow: auto; }
.modal__body p { margin: 0 0 .6em; }
.end-warn { color: var(--c-accent); font-size: 15px; }
.modal__footer { display: flex; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--c-border); }
.modal__footer--right { justify-content: flex-end; }

.shortcut-list { width: 100%; border-collapse: collapse; }
.shortcut-list td { padding: 5px 8px; border-bottom: 1px solid #eee; vertical-align: top; }
.shortcut-list td:first-child { white-space: nowrap; }
.shortcut-list .sc-off td:last-child { color: #c0392b; }
.shortcut-section { margin: 14px 0 6px; font-weight: 700; font-size: 13px; }

/* ===================== VORSCHAU ===================== */
.preview__dialog { height: 92vh; background: #d7d7d7; }
.preview__body { flex: 1; overflow: auto; padding: 24px; display: flex; justify-content: center; background: #cfcfcf; }
.preview__footer { display: flex; align-items: center; justify-content: center; gap: 16px; padding: 10px 16px; background: #fafbfc; border-top: 1px solid var(--c-border); }
.preview-counter { font-size: 13px; min-width: 110px; text-align: center; color: var(--c-text); }
.preview-nav:disabled { opacity: .35; cursor: not-allowed; }
.preview-page {
  width: 210mm; min-height: 297mm; background: #fff; box-shadow: 0 2px 12px rgba(0,0,0,.25);
  font-family: "Calibri", "Lucida Sans", "Segoe UI", Arial, sans-serif; font-size: 11pt; line-height: 1.5; color: #222;
  padding: 12mm 15mm; overflow-wrap: break-word; word-break: break-word;
}
.preview-page .qhead {
  display: table; width: 100%; table-layout: fixed; font-weight: 700; font-size: 10pt;
  border-bottom: 2px solid #000; padding-bottom: 5px; margin-bottom: 9mm;
}
.preview-page .qh-l { display: table-cell; width: 30%; vertical-align: bottom; }
.preview-page .qh-c { display: table-cell; text-align: center; vertical-align: bottom; }
.preview-page .qh-r { display: table-cell; width: 30%; text-align: right; vertical-align: bottom; }
.preview-page .qbody { padding-right: 50mm; }   /* Korrekturrand rechts wie im Examen */
.preview-page .cover-meta { margin: 24mm 0 0 8mm; border-collapse: collapse; font-size: 12pt; }
.preview-page .cover-meta td { padding: 4px 0; vertical-align: top; }
.preview-page .cover-meta .cm-l { font-weight: 700; padding-right: 18px; white-space: nowrap; }
.preview-page p { margin: 0 0 1em 0; min-height: 1.4em; }
.preview-page p:empty::before { content: "\00a0"; }
.preview-page h3 { margin: 1em 0 .4em 0; font-size: 13pt; }
.preview-page .qbody table { border-collapse: collapse; }
.preview-page .qbody td, .preview-page .qbody th { border: 1px solid #888; padding: 4px 8px; }

/* ===================== LOCK ===================== */
.lock-overlay {
  position: fixed; inset: 0; z-index: 1200; background: rgba(20,24,33,.96);
  display: none; align-items: center; justify-content: center; color: #fff; text-align: center;
}
.lock-overlay.is-open { display: flex; }
.lock-overlay__box { max-width: 420px; padding: 30px; }
.lock-overlay__icon { font-size: 48px; margin-bottom: 14px; }
.lock-overlay__box h2 { margin: 0 0 8px; }
.lock-overlay__box p { margin: 0 0 22px; opacity: .85; }

/* Mobile */
@media (max-width: 760px) {
  .header { flex-wrap: wrap; }
  .header__title { order: 3; width: 100%; text-align: left; font-size: 14px; }
  .header__tools { flex-wrap: wrap; }
  .setup__row { flex-direction: column; gap: 0; }
}

/* Print (PDF-Export greift auf eigenes Iframe-Dokument zu; hier nur Fallback) */
@media print {
  body { background: #fff !important; }
  .header, .footer, .setup, .modal, .lock-overlay { display: none !important; }
}

/* ===================== EMBEDDED (Lernplattform-iframe) ===================== */
/* Gesetzt von embed.js, wenn das Portal in einem iframe läuft. Füllt das
   iframe voll aus und unterdrückt unnötigen Scroll-Chrome. */
html[data-embedded], html[data-embedded] body { height: 100%; margin: 0; }
html[data-embedded] body { overflow: hidden; }
html[data-embedded] .app { height: 100vh; }

/* Vollbild-Button: aktiver Zustand hervorheben */
#btn-fullscreen.is-on { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }
