/* Notruf von Station Kepler — Design-Tokens & Layout
   Optik gespiegelt vom SQL-Trainer, um ein einheitliches Erscheinungsbild zu wahren. */
:root {
  --bg: #f4f6fb;
  --bg-elev: #ffffff;
  --bg-sunken: #eef1f7;
  --surface-2: #f8fafc;
  --border: #dde3ee;
  --border-strong: #c6cfe0;
  --text: #1b2333;
  --text-muted: #5a6377;
  --text-faint: #8a93a6;
  --brand: #2f5fe0;
  --brand-strong: #234bc4;
  --brand-soft: #e7eefc;
  --accent: #0e8a6a;
  --ok-bg: #e5f6ee;
  --ok-fg: #0b7a54;
  --ok-border: #a7e0c6;
  --err-bg: #fdeaea;
  --err-fg: #b42323;
  --err-border: #f2b8b8;
  --warn-bg: #fdf4e3;
  --warn-fg: #98670c;
  --code-bg: #f6f8fc;
  --shadow: 0 1px 2px rgba(20,30,60,.06), 0 6px 20px rgba(20,30,60,.06);
  --shadow-sm: 0 1px 2px rgba(20,30,60,.08);
  --radius: 14px;
  --radius-sm: 9px;
  --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --focus: 0 0 0 3px rgba(47,95,224,.35);
  --dur: 160ms;
}
:root[data-theme="dark"], html.dark {
  --bg: #0e1320;
  --bg-elev: #161d2e;
  --bg-sunken: #101524;
  --surface-2: #1b2436;
  --border: #263248;
  --border-strong: #35435f;
  --text: #e8ecf5;
  --text-muted: #a3adc2;
  --text-faint: #7c869c;
  --brand: #6f9bff;
  --brand-strong: #8bafff;
  --brand-soft: #1c2a49;
  --accent: #37c79b;
  --ok-bg: #12312a;
  --ok-fg: #4ad9a8;
  --ok-border: #1f5647;
  --err-bg: #351a1e;
  --err-fg: #ff9a9a;
  --err-border: #5c2a2f;
  --warn-bg: #33280f;
  --warn-fg: #e6bd6a;
  --code-bg: #10182a;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 26px rgba(0,0,0,.35);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.35);
  --focus: 0 0 0 3px rgba(111,155,255,.4);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1320; --bg-elev: #161d2e; --bg-sunken: #101524; --surface-2: #1b2436;
    --border: #263248; --border-strong: #35435f; --text: #e8ecf5; --text-muted: #a3adc2;
    --text-faint: #7c869c; --brand: #6f9bff; --brand-strong: #8bafff; --brand-soft: #1c2a49;
    --accent: #37c79b; --ok-bg: #12312a; --ok-fg: #4ad9a8; --ok-border: #1f5647;
    --err-bg: #351a1e; --err-fg: #ff9a9a; --err-border: #5c2a2f; --warn-bg: #33280f;
    --warn-fg: #e6bd6a; --code-bg: #10182a;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 26px rgba(0,0,0,.35);
    --shadow-sm: 0 1px 2px rgba(0,0,0,.35); --focus: 0 0 0 3px rgba(111,155,255,.4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
button { font-family: inherit; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 8px; }

.wrap { max-width: 1280px; margin: 0 auto; padding: 22px clamp(14px, 3vw, 32px) 64px; }

/* Header */
header.app {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding-bottom: 18px; margin-bottom: 22px; border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 40px; height: 40px; border-radius: 11px; flex: none;
  background: linear-gradient(135deg, var(--brand), #6b3fe0);
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 15px;
  box-shadow: var(--shadow-sm); letter-spacing: .02em;
}
.brand h1 { font-size: 18px; }
.brand .sub { color: var(--text-muted); font-size: 12.5px; margin-top: 1px; }
.spacer { flex: 1 1 auto; }

.dbchip {
  display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-muted);
  background: var(--bg-elev); border: 1px solid var(--border); padding: 6px 11px; border-radius: 999px;
}
.dbchip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); }
.dbchip.ready .dot { background: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }

/* Buttons */
.btn {
  appearance: none; border: 1px solid var(--border-strong); background: var(--bg-elev); color: var(--text);
  padding: 9px 15px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 550; cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px; transition: background var(--dur), border-color var(--dur), transform var(--dur);
}
.btn:hover { background: var(--surface-2); border-color: var(--text-faint); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-muted); padding: 7px 10px; }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { padding: 6px 11px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.kbd { font-family: var(--mono); font-size: 11px; background: color-mix(in srgb, currentColor 12%, transparent); padding: 1px 5px; border-radius: 5px; }

/* Segmented control */
.seg { display: inline-flex; background: var(--bg-sunken); border: 1px solid var(--border); border-radius: 999px; padding: 3px; }
.seg button {
  border: none; background: transparent; color: var(--text-muted); font-size: 13.5px; font-weight: 550;
  padding: 7px 15px; border-radius: 999px; cursor: pointer; transition: background var(--dur), color var(--dur);
}
.seg button[aria-pressed="true"] { background: var(--bg-elev); color: var(--text); box-shadow: var(--shadow-sm); }

/* Layout grid */
.grid { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 22px; align-items: start; }
@media (max-width: 940px) { .grid { grid-template-columns: 1fr; } }

.card {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.card > .card-head {
  display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.card > .card-head h2 { font-size: 14.5px; }
.card > .card-head .hint { color: var(--text-faint); font-size: 12px; margin-left: auto; }
.card-body { padding: 16px; }
.side-note { margin: 0; color: var(--text-muted); font-size: 12.5px; }

/* Seitenleiste sticky */
aside.side { position: sticky; top: 16px; }
@media (max-width: 940px) { aside.side { position: static; } }

/* Missionslog */
#missionList { display: grid; gap: 6px; }
.mrow {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; cursor: pointer;
  background: transparent; border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 8px 10px; color: var(--text); transition: background var(--dur), border-color var(--dur);
}
.mrow:hover:not(:disabled) { background: var(--surface-2); }
.mrow.active { background: var(--brand-soft); border-color: color-mix(in srgb, var(--brand) 30%, transparent); }
.mrow.locked { color: var(--text-faint); cursor: not-allowed; }
.mrow .mmark {
  width: 24px; height: 24px; border-radius: 7px; flex: none; display: grid; place-items: center;
  font-size: 12px; font-weight: 700; background: var(--bg-sunken); color: var(--text-muted);
}
.mrow.done .mmark { background: var(--ok-fg); color: #fff; }
.mrow.active .mmark { background: var(--brand); color: #fff; }
.mrow .mtxt { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.mrow .mt-t { font-size: 13px; font-weight: 600; }
.mrow .mt-s { font-size: 11px; color: var(--text-faint); }

/* Schema browser */
.schema-body, #schemaList { max-height: 40vh; overflow: auto; }
details.tbl { border-radius: var(--radius-sm); }
details.tbl > summary {
  list-style: none; cursor: pointer; padding: 8px 10px; border-radius: var(--radius-sm);
  display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13.5px;
  transition: background var(--dur);
}
details.tbl > summary::-webkit-details-marker { display: none; }
details.tbl > summary:hover { background: var(--surface-2); }
details.tbl > summary .chev { color: var(--text-faint); transition: transform var(--dur); font-size: 11px; }
details.tbl[open] > summary .chev { transform: rotate(90deg); }
details.tbl > summary .cnt { margin-left: auto; color: var(--text-faint); font-size: 11.5px; font-weight: 500; }
.cols { padding: 2px 6px 10px 26px; }
.col-row { display: flex; align-items: baseline; gap: 8px; padding: 3px 6px; font-size: 12.5px; border-radius: 6px; }
.col-row:hover { background: var(--surface-2); }
.col-name { font-family: var(--mono); color: var(--text); }
.col-name .pk { color: var(--brand); font-weight: 700; }
.col-type { color: var(--text-faint); font-size: 11px; text-transform: lowercase; margin-left: auto; }

/* Story-Karte */
.story-card .card-head { align-items: flex-start; }
.story-card .num {
  width: 30px; height: 30px; border-radius: 9px; background: var(--brand-soft); color: var(--brand);
  font-weight: 800; font-size: 15px; display: grid; place-items: center; flex: none;
}
.story-card .thead-text { flex: 1; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.story-card .thead-text h2 { font-size: 16px; }
.pill { font-size: 11px; font-weight: 650; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.pill.topic { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }

.narrative {
  font-size: 14.5px; line-height: 1.6; color: var(--text); background: var(--surface-2);
  border-left: 3px solid var(--brand); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 13px 15px;
}
.mission-box {
  margin-top: 14px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; background: var(--bg-elev);
}
.mission-label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--brand); font-weight: 700; margin-bottom: 5px; }
.mission-box #aufgabe { font-size: 14px; color: var(--text); }

/* Editor */
.editor-shell { border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; background: var(--code-bg); }
textarea.sql {
  width: 100%; border: none; background: transparent; color: var(--text); resize: vertical;
  font-family: var(--mono); font-size: 13.5px; line-height: 1.55; padding: 13px 14px; min-height: 100px; display: block; tab-size: 2;
}
textarea.sql:focus { outline: none; }
.editor-shell:focus-within { box-shadow: var(--focus); }
.editor-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
select.examples {
  appearance: none; background: var(--bg-elev); border: 1px solid var(--border-strong); color: var(--text);
  padding: 9px 30px 9px 12px; border-radius: var(--radius-sm); font-size: 13.5px; cursor: pointer; max-width: 300px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238a93a6' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
}

/* Result table */
.result-meta { font-size: 12.5px; color: var(--text-muted); margin: 12px 2px 8px; display: flex; align-items: center; gap: 10px; }
.table-scroll { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); max-height: 420px; }
table.data { border-collapse: collapse; width: 100%; font-size: 13px; }
table.data th, table.data td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data thead th {
  position: sticky; top: 0; background: var(--surface-2); color: var(--text-muted);
  font-weight: 650; font-size: 12px; z-index: 1; border-bottom: 1px solid var(--border-strong);
}
table.data td { font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 12.5px; }
table.data tbody tr:nth-child(even) { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
table.data tbody tr:hover { background: var(--brand-soft); }
td.nullv { color: var(--text-faint); font-style: italic; }

.msg { padding: 11px 14px; border-radius: var(--radius-sm); font-size: 13.5px; border: 1px solid transparent; }
.msg.err { background: var(--err-bg); color: var(--err-fg); border-color: var(--err-border); }
.msg.ok { background: var(--ok-bg); color: var(--ok-fg); border-color: var(--ok-border); }
.msg.info { background: var(--surface-2); color: var(--text-muted); }
.status-line { margin-top: 12px; }
.status-line:empty { margin-top: 0; }

.solution { margin-top: 12px; border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); background: var(--code-bg); padding: 12px 14px; }
.solution h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); margin-bottom: 6px; font-weight: 650; }
.solution pre { margin: 0; font-family: var(--mono); font-size: 12.5px; color: var(--text); white-space: pre-wrap; }
.solution .explain { margin-top: 9px; font-family: var(--sans); font-size: 13px; color: var(--text-muted); }

/* Weiter-Leiste */
.next-bar {
  display: flex; align-items: center; gap: 12px; margin-top: 14px; padding: 12px 16px;
  background: var(--brand-soft); border: 1px solid color-mix(in srgb, var(--brand) 30%, transparent); border-radius: var(--radius);
}
.next-bar .next-label { font-size: 13.5px; font-weight: 600; color: var(--text); }

.hidden { display: none !important; }

/* Sieg-Bildschirm */
.win-overlay {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 24px;
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(4px);
}
.win-panel {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); max-width: 480px; padding: 28px 26px; text-align: center;
}
.win-badge {
  width: 56px; height: 56px; border-radius: 16px; margin: 0 auto 14px; display: grid; place-items: center;
  font-size: 26px; color: #fff; background: linear-gradient(135deg, var(--brand), #6b3fe0); box-shadow: var(--shadow-sm);
}
.win-panel h2 { font-size: 20px; margin-bottom: 8px; }
.win-panel p { color: var(--text-muted); font-size: 14px; line-height: 1.6; }
.win-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 20px; }

/* Loading overlay */
.overlay {
  position: fixed; inset: 0; background: var(--bg); display: grid; place-items: center; z-index: 50;
  transition: opacity 300ms; text-align: center; padding: 20px;
}
.overlay.gone { opacity: 0; pointer-events: none; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--border-strong); border-top-color: var(--brand); margin: 0 auto 16px; animation: spin .8s linear infinite; }
.overlay p { color: var(--text-muted); font-size: 14px; }
.overlay .big { color: var(--text); font-size: 16px; font-weight: 600; margin-bottom: 4px; }
@keyframes spin { to { transform: rotate(360deg); } }

footer.foot { margin-top: 40px; padding-top: 18px; border-top: 1px solid var(--border); color: var(--text-faint); font-size: 12px; text-align: center; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  .spinner { animation: spin 1.2s steps(12) infinite; }
}

/* iframe-Einbettung: Kopf/Fuss ausblenden */
body.embed header.app { display: none; }
body.embed .foot { display: none; }
body.embed .wrap { padding-top: 14px; }
