/* SQL-Labor – Gestaltung */
:root {
  --bg: #f4f6fb;
  --bg-2: #eaeef7;
  --panel: #ffffff;
  --panel-2: #f7f9fd;
  --line: #dde3ef;
  --text: #172033;
  --muted: #5b6680;
  --accent: #0891b2;
  --accent-2: #7c3aed;
  --accent-soft: #e0f7fb;
  --ok: #15803d;
  --ok-soft: #e7f7ec;
  --err: #c0262d;
  --err-soft: #fdecec;
  --warn: #a16207;
  --warn-soft: #fff6dc;
  --code-bg: #0f172a;
  --code-text: #e2e8f0;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  --radius: 12px;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0a0f1c;
  --bg-2: #0f1626;
  --panel: #121a2c;
  --panel-2: #0f1727;
  --line: #22304a;
  --text: #e5ecf7;
  --muted: #93a1bb;
  --accent: #22d3ee;
  --accent-2: #a78bfa;
  --accent-soft: #0e2f3a;
  --ok: #4ade80;
  --ok-soft: #0f2a1c;
  --err: #f87171;
  --err-soft: #34161a;
  --warn: #fbbf24;
  --warn-soft: #33270b;
  --code-bg: #0b1222;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0f1c; --bg-2: #0f1626; --panel: #121a2c; --panel-2: #0f1727; --line: #22304a;
    --text: #e5ecf7; --muted: #93a1bb; --accent: #22d3ee; --accent-2: #a78bfa; --accent-soft: #0e2f3a;
    --ok: #4ade80; --ok-soft: #0f2a1c; --err: #f87171; --err-soft: #34161a; --warn: #fbbf24; --warn-soft: #33270b;
    --code-bg: #0b1222; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.55 var(--sans); }
a { color: var(--accent); }
code, pre, kbd { font-family: var(--mono); }
kbd { font-size: 12px; padding: 1px 6px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; background: var(--panel-2); }
h1, h2, h3 { line-height: 1.25; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- Kopfzeile ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 18px;
  padding: 0 18px; height: 58px; background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .2px; color: var(--text); text-decoration: none; white-space: nowrap; }
.brand .logo { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); font-family: var(--mono); font-size: 13px; }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: 11.5px; letter-spacing: 0; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav a { padding: 8px 12px; border-radius: 9px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: 14px; white-space: nowrap; }
.nav a:hover { background: var(--bg-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.userbox { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px;
  background: var(--bg-2); color: var(--accent); border: 1px solid var(--line); }

/* ---------- Bedienelemente ---------- */
.btn { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); background: var(--panel); color: var(--text);
  padding: 8px 13px; border-radius: 9px; font: 600 14px var(--sans); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .55; cursor: wait; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
:root[data-theme="dark"] .btn.primary { color: #04202a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary { color: #04202a; } }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--err); }
.btn.danger:hover { border-color: var(--err); background: var(--err-soft); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--bg-2); border-color: transparent; }
.btn.small { padding: 5px 9px; font-size: 13px; }
.btn.icon { padding: 7px 9px; }
input[type=text], input[type=password], input[type=search], select, textarea {
  font: 14px var(--sans); color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 8px 11px; width: 100%;
}
textarea { font-family: var(--mono); font-size: 13.5px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); border-color: var(--accent); }
label { display: block; font-weight: 600; font-size: 13.5px; margin: 12px 0 5px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--bg-2); color: var(--muted); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.err { background: var(--err-soft); color: var(--err); }
.badge.acc { background: var(--accent-soft); color: var(--accent); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 18px 20px; }
.page { max-width: 1200px; margin: 0 auto; padding: 24px 18px 60px; }
.page h1 { margin: 6px 0 4px; font-size: 26px; }
.toast-wrap { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--accent); box-shadow: var(--shadow); padding: 10px 14px; border-radius: 10px; max-width: 380px; }
.toast.err { border-left-color: var(--err); }
.toast.ok { border-left-color: var(--ok); }

/* ---------- Modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(5, 10, 20, .55); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { width: min(560px, 100%); max-height: 90vh; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 22px; }
.modal h2 { margin: 0 0 8px; font-size: 20px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.tpl { display: block; width: 100%; text-align: left; padding: 12px 14px; margin: 8px 0; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); cursor: pointer; color: var(--text); font: inherit; }
.tpl:hover { border-color: var(--accent); }
.tpl b { display: block; }
.tpl span { color: var(--muted); font-size: 13.5px; }
.secret { font-family: var(--mono); font-size: 18px; padding: 10px 14px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: inline-block; letter-spacing: .5px; }

/* ---------- Arbeitsplatz ---------- */
.workspace { display: grid; grid-template-columns: 290px 1fr; height: calc(100vh - 58px); }
.side { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.side-head { padding: 14px; border-bottom: 1px solid var(--line); }
.side-head .row { margin-top: 8px; gap: 6px; }
.side-body { flex: 1; overflow: auto; padding: 8px 8px 14px; }
.side-foot { padding: 12px 14px; border-top: 1px solid var(--line); display: flex; gap: 8px; flex-wrap: wrap; }
.tree-table { margin: 2px 0; }
.tree-table > button { all: unset; display: flex; align-items: center; gap: 8px; width: 100%; box-sizing: border-box; padding: 6px 8px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 14px; }
.tree-table > button:hover { background: var(--bg-2); }
.tree-table > button .cnt { margin-left: auto; color: var(--muted); font-weight: 500; font-size: 12px; }
.tree-table ul { list-style: none; margin: 0 0 6px; padding: 0 0 0 28px; font-size: 13px; }
.tree-table li { display: flex; gap: 6px; align-items: baseline; padding: 2px 0; }
.tree-table li .t { color: var(--muted); font-family: var(--mono); font-size: 11.5px; margin-left: auto; text-align: right; }
.key { font-size: 10px; font-weight: 800; padding: 0 4px; border-radius: 4px; }
.key.pk { background: #fde68a; color: #713f12; }
.key.fk { background: #ddd6fe; color: #4c1d95; }
.tico { color: var(--accent); font-family: var(--mono); font-size: 12px; }
.empty { color: var(--muted); padding: 18px 10px; text-align: center; font-size: 14px; }

.main { display: grid; grid-template-rows: auto minmax(160px, 42%) 1fr; min-height: 0; min-width: 0; }
.toolbar { display: flex; gap: 8px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.toolbar .dbname { font-family: var(--mono); font-size: 13px; color: var(--muted); }
.editor-wrap { min-height: 0; border-bottom: 1px solid var(--line); position: relative; }
.editor-wrap .CodeMirror { height: 100%; font-family: var(--mono); font-size: 14.5px; background: var(--panel); color: var(--text); }
.CodeMirror-gutters { background: var(--panel-2) !important; border-right: 1px solid var(--line) !important; }
.CodeMirror-linenumber { color: var(--muted) !important; }
.CodeMirror-cursor { border-left: 2px solid var(--accent) !important; }
.CodeMirror-selected, .CodeMirror-focused .CodeMirror-selected { background: color-mix(in srgb, var(--accent) 22%, transparent) !important; }
.cm-s-default .cm-keyword { color: var(--accent-2); font-weight: 700; }
.cm-s-default .cm-string { color: #16a34a; }
.cm-s-default .cm-number { color: #ea580c; }
.cm-s-default .cm-comment { color: var(--muted); font-style: italic; }
.cm-s-default .cm-builtin, .cm-s-default .cm-type { color: var(--accent); }
.cm-s-default .cm-variable-2 { color: #0ea5e9; }
.CodeMirror-hints { font-family: var(--mono); font-size: 13px; border-radius: 8px; z-index: 60; }
.results { overflow: auto; min-height: 0; padding: 14px; background: var(--bg); }
.tabs { display: flex; gap: 4px; margin-bottom: 10px; }
.tabs button { all: unset; cursor: pointer; padding: 6px 12px; border-radius: 8px; font-weight: 600; font-size: 13.5px; color: var(--muted); }
.tabs button.active { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.res { margin-bottom: 14px; overflow: hidden; }
.res-head { display: flex; gap: 10px; align-items: center; padding: 9px 14px; border-bottom: 1px solid var(--line); font-size: 13px; flex-wrap: wrap; }
.res-head code { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60ch; display: inline-block; vertical-align: bottom; }
.res-body { padding: 10px 14px; }
.res.err { border-color: color-mix(in srgb, var(--err) 50%, var(--line)); }
.res.err .res-head { background: var(--err-soft); color: var(--err); }
.res .hint { margin-top: 8px; padding: 9px 12px; border-radius: 9px; background: var(--warn-soft); color: var(--text); font-size: 14px; }
.res .hint::before { content: "💡 "; }
.tbl-wrap { overflow: auto; max-height: 420px; }
table.data { border-collapse: separate; border-spacing: 0; font-size: 13.5px; width: max-content; }
table.data th, table.data td { padding: 6px 12px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; max-width: 420px; overflow: hidden; text-overflow: ellipsis; }
table.data th { position: sticky; top: 0; background: var(--panel-2); font-weight: 700; z-index: 1; }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 12.5px; }
table.data td.null { color: var(--muted); font-style: italic; }
table.data tr:hover td { background: var(--bg-2); }
table.data td.rn, table.data th.rn { color: var(--muted); font-size: 11.5px; text-align: right; }
.welcome { padding: 8px 6px; color: var(--muted); }
.welcome h3 { color: var(--text); margin: 4px 0 6px; }
.hist-item { padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.hist-item:hover { background: var(--panel-2); }
.hist-item pre { margin: 6px 0 0; white-space: pre-wrap; word-break: break-word; font-size: 12.5px; max-height: 7.5em; overflow: hidden; }
.hist-item .meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- Lernen ---------- */
.learn { display: grid; grid-template-columns: 280px 1fr; max-width: 1240px; margin: 0 auto; gap: 26px; padding: 22px 18px 60px; }
.learn-nav { position: sticky; top: 76px; align-self: start; max-height: calc(100vh - 96px); overflow: auto; }
.learn-nav h4 { margin: 16px 8px 4px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); }
.learn-nav a { display: block; padding: 6px 10px; border-radius: 8px; text-decoration: none; color: var(--text); font-size: 14px; }
.learn-nav a:hover { background: var(--bg-2); }
.learn-nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.article { padding: 30px 38px; min-width: 0; }
.article h1 { font-size: 30px; margin: 0 0 6px; }
.article h2 { margin-top: 32px; padding-top: 6px; font-size: 21px; }
.article h3 { margin-top: 22px; font-size: 17px; }
.article p, .article li { max-width: 78ch; }
.article code { background: var(--bg-2); padding: 1px 6px; border-radius: 6px; font-size: .92em; }
.article pre { background: var(--code-bg); color: var(--code-text); padding: 14px 16px; border-radius: 12px; overflow: auto; font-size: 13.5px; position: relative; }
.article pre code { background: none; padding: 0; color: inherit; }
.article pre .open-sql { position: absolute; top: 8px; right: 8px; font-size: 12px; padding: 4px 9px; border-radius: 7px; border: 1px solid #334155; background: #1e293b; color: #e2e8f0; cursor: pointer; font-family: var(--sans); font-weight: 600; }
.article pre .open-sql:hover { background: var(--accent); color: #04202a; }
.article table { border-collapse: collapse; margin: 14px 0; font-size: 14px; }
.article th, .article td { border: 1px solid var(--line); padding: 6px 12px; text-align: left; }
.article th { background: var(--panel-2); }
.article blockquote { margin: 16px 0; padding: 10px 16px; border-left: 4px solid var(--accent); background: var(--accent-soft); border-radius: 0 10px 10px 0; }
.article blockquote p { margin: 6px 0; }
.article details { margin: 12px 0; border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; background: var(--panel-2); }
.article details summary { cursor: pointer; font-weight: 700; color: var(--accent); }
.article .pager { display: flex; justify-content: space-between; gap: 10px; margin-top: 40px; padding-top: 18px; border-top: 1px solid var(--line); }
.article img, .article svg { max-width: 100%; }
.lead { font-size: 17px; color: var(--muted); }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; margin: 18px 0; }
.grid-cards a { text-decoration: none; color: var(--text); padding: 16px; }
.grid-cards a:hover { border-color: var(--accent); }
.grid-cards small { color: var(--muted); display: block; margin-top: 4px; }

/* ---------- Admin ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin: 18px 0; }
.stat { padding: 14px 16px; }
.stat b { display: block; font-size: 26px; }
.stat span { color: var(--muted); font-size: 13px; }
table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list th, table.list td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.list th { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: var(--panel-2); }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.dbcard { margin-bottom: 14px; }
.dbcard h3 { margin: 0; font-size: 16px; font-family: var(--mono); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.chip { all: unset; cursor: pointer; padding: 5px 10px; border-radius: 8px; border: 1px solid var(--line); font-size: 13px; background: var(--panel-2); }
.chip:hover, .chip.active { border-color: var(--accent); color: var(--accent); }
.log { font-size: 13px; }
.log .item { padding: 10px 0; border-bottom: 1px solid var(--line); }
.log pre { margin: 6px 0 0; padding: 10px 12px; background: var(--code-bg); color: var(--code-text); border-radius: 9px; white-space: pre-wrap; word-break: break-word; max-height: 260px; overflow: auto; font-size: 12.5px; }
.cards-print { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.cred { border: 1px dashed var(--line); border-radius: 10px; padding: 12px 14px; }
.cred .u, .cred .p { font-family: var(--mono); font-size: 15px; }

/* ---------- Login ---------- */
.login-page { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-hero { position: relative; overflow: hidden; padding: 56px; color: #e5ecf7; display: flex; flex-direction: column; justify-content: space-between;
  background: radial-gradient(1200px 600px at 10% 0%, #164e63 0%, transparent 60%), radial-gradient(900px 500px at 100% 100%, #3b0764 0%, transparent 55%), #070b16; }
.login-hero h1 { font-size: 42px; margin: 0 0 12px; letter-spacing: -.5px; }
.login-hero p { color: #a9b6cc; font-size: 17px; max-width: 46ch; }
.login-hero .brand { color: #e5ecf7; }
.login-hero .brand small { color: #93a1bb; }
.hero-code { font-family: var(--mono); font-size: 14px; background: rgba(15, 23, 42, .7); border: 1px solid #1f2b45; border-radius: 14px; padding: 18px 20px; color: #cbd5e1; max-width: 520px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.hero-code .k { color: #c4b5fd; font-weight: 700; } .hero-code .s { color: #86efac; } .hero-code .n { color: #fdba74; } .hero-code .c { color: #64748b; }
.hero-feats { display: flex; gap: 22px; flex-wrap: wrap; color: #a9b6cc; font-size: 14px; }
.login-side { display: grid; place-items: center; padding: 32px 18px; background: var(--bg); }
.login-box { width: min(380px, 100%); }
.login-box h2 { margin: 0 0 4px; font-size: 24px; }
.login-box .err { color: var(--err); min-height: 22px; margin-top: 10px; font-size: 14px; }

/* ---------- Responsiv ---------- */
@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; height: auto; }
  .side { border-right: 0; border-bottom: 1px solid var(--line); max-height: 320px; }
  .main { grid-template-rows: auto 300px auto; }
  .learn { grid-template-columns: 1fr; }
  .learn-nav { position: static; max-height: none; }
  .article { padding: 20px 16px; }
  .login-page { grid-template-columns: 1fr; }
  .login-hero { padding: 32px 20px; }
  .login-hero h1 { font-size: 30px; }
  .split { grid-template-columns: 1fr; }
  .topbar { gap: 10px; padding: 0 12px; }
  .brand small { display: none; }
}

@media print {
  .topbar, .no-print, .toast-wrap { display: none !important; }
  body { background: #fff; color: #000; }
  .page { padding: 0; }
  .card { box-shadow: none; border: 0; }
  .cred { break-inside: avoid; border: 1px dashed #999; }
}
