:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f1;
  --text: #1b2524;
  --muted: #5d6b69;
  --line: #d9e0de;
  --accent: #1f6f78;
  --accent-ink: #ffffff;
  --accent-soft: #dcecec;
  --rec: #c2412d;
  --rec-soft: #f8e1dc;
  --ok: #2f7a4b;
  --warn: #9a6a00;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 30, .06), 0 4px 16px rgba(20, 30, 30, .05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121817; --surface: #1a2221; --surface-2: #222c2b; --text: #e6eceb; --muted: #9aa9a7;
    --line: #2f3b3a; --accent: #4fb0b8; --accent-ink: #0d1514; --accent-soft: #1f3638;
    --rec: #ef6a52; --rec-soft: #3a2420; --ok: #6fc28f; --warn: #e0b04a;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); }
[hidden] { display: none !important; }
a { color: var(--accent); }
h2 { font-size: 1.05rem; margin: 0 0 .35rem; display: flex; align-items: center; gap: .5rem; }
kbd { font: 11px var(--mono); padding: 1px 5px; border: 1px solid currentColor; border-radius: 4px; opacity: .65; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* Buttons & Formulare */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .55rem .9rem; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.subtle { background: transparent; color: var(--muted); }
.btn.danger { color: var(--rec); }
.icon-btn { background: none; border: 0; color: var(--muted); cursor: pointer; padding: .25rem .4rem; border-radius: 6px; font-size: 1rem; }
.icon-btn:hover { color: var(--rec); background: var(--rec-soft); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: .55rem .7rem; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
label { display: block; font-weight: 500; }
label > input, label > select, label > textarea { margin-top: .3rem; font-weight: 400; }
.stack { display: grid; gap: .8rem; }
.stack.narrow { max-width: 420px; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.toggle { display: flex; align-items: center; gap: .5rem; font-weight: 400; font-size: .92rem; cursor: pointer; }
.toggle input { width: auto; margin: 0; accent-color: var(--accent); }

/* Anmeldung */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.auth-card .muted { margin: .2rem 0 1.4rem; }
.auth-links { display: flex; justify-content: space-between; font-size: .9rem; }
.msg { min-height: 1.2em; margin: 1rem 0 0; font-size: .9rem; }
.msg.error { color: var(--rec); }
.msg.ok { color: var(--ok); }

.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; letter-spacing: -.01em; }
.brand.big { font-size: 1.35rem; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--accent) url("icon.svg") center/cover; }

/* Kopfzeile */
.topbar {
  display: flex; align-items: center; gap: 1.5rem; padding: 0 20px; height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.tabs { display: flex; gap: 2px; height: 100%; }
.tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent; padding: 0 .9rem; height: 100%;
  font: inherit; color: var(--muted); cursor: pointer; white-space: nowrap;
}
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.user { margin-left: auto; color: var(--muted); font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Diktat-Ansicht */
.dictate { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; padding: 20px; height: calc(100vh - 56px); }
.editor-wrap { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
#editor {
  flex: 1; border: 0; border-radius: 0; resize: none; padding: 22px 26px;
  font: 17px/1.65 var(--font); background: transparent;
}
#editor:focus { outline: none; }
.editor-foot { display: flex; justify-content: space-between; padding: 8px 16px; border-top: 1px solid var(--line); font-size: .82rem; color: var(--muted); }

.side { display: flex; flex-direction: column; gap: 14px; overflow-y: auto; min-height: 0; }
.mic {
  display: flex; align-items: center; gap: .7rem; width: 100%; padding: 16px 18px;
  border-radius: 12px; border: 2px solid var(--accent); background: var(--accent); color: var(--accent-ink);
  font: 600 1.05rem var(--font); cursor: pointer; transition: background .15s, border-color .15s;
}
.mic svg { width: 26px; height: 26px; fill: currentColor; flex: none; }
.mic kbd { margin-left: auto; }
.mic[aria-pressed="true"] { background: var(--rec); border-color: var(--rec); color: #fff; animation: pulse 1.6s infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(194, 65, 45, .35); } 50% { box-shadow: 0 0 0 8px rgba(194, 65, 45, 0); } }
.level { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
#level-bar { height: 100%; width: 0; background: var(--ok); transition: width .08s linear; }
.status { font-size: .9rem; color: var(--muted); min-height: 1.4em; }
.status.busy { color: var(--warn); }
.warn-text { color: var(--warn); }
#speed-info::before { content: '· '; }
#speed-info:empty::before { content: ''; }
.status.error { color: var(--rec); }
.btn-group { display: grid; gap: 8px; }
.help { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; font-size: .88rem; }
.help summary { cursor: pointer; font-weight: 600; }
.help ul { list-style: none; padding: 0; margin: .5rem 0 0; display: grid; gap: 3px; }
.help li { display: flex; justify-content: space-between; gap: .6rem; }
.help li span:last-child { color: var(--muted); font-family: var(--mono); font-size: .8rem; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 45%; }

/* Verbessern */
.editor-bar { display: flex; align-items: center; gap: .8rem; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.editor-bar .small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.small-btn { padding: .35rem .7rem; font-size: .9rem; flex: none; }
.fix-float {
  position: fixed; z-index: 40; padding: .4rem .75rem; border-radius: 8px; border: 0;
  background: var(--accent); color: var(--accent-ink); font: 600 .9rem var(--font); cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,.18);
}
.dialog { border: 1px solid var(--line); border-radius: 14px; padding: 22px 24px; width: min(440px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.dialog::backdrop { background: rgba(10, 20, 20, .35); }
.fix-wrong { padding: .6rem .8rem; background: var(--rec-soft); border-radius: 8px; }
.warn { margin: 0; padding: .6rem .8rem; border-radius: 8px; background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--text); font-size: .9rem; }

/* Start-/Ladebildschirm Modell */
.gate { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px;
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(6px); }
.gate-card { width: min(460px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 32px 28px 22px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.18); display: grid; gap: 14px; }
.gate-card h2 { justify-content: center; font-size: 1.25rem; margin: 0; }
.gate-card p { margin: 0; }
.gate-card section { display: grid; gap: 12px; justify-items: center; }
.gate-icon { width: 64px; height: 64px; border-radius: 18px; background: var(--accent-soft); display: grid; place-items: center; margin: 0 auto 4px; }
.gate-icon svg { width: 34px; height: 34px; fill: var(--accent); }
.gate-btn { padding: .8rem 1.6rem; font-size: 1.05rem; min-width: 220px; }
.link-btn { background: none; border: 0; color: var(--muted); font: inherit; font-size: .85rem; text-decoration: underline; cursor: pointer; margin-top: 6px; }
.spinner { width: 38px; height: 38px; border-radius: 50%; border: 4px solid var(--accent-soft); border-top-color: var(--accent); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.progress { width: 100%; height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; position: relative; }
#gate-progress-bar { height: 100%; width: 0; background: var(--accent); border-radius: 4px; transition: width .4s ease; }
.progress.indeterminate #gate-progress-bar { width: 35%; position: absolute; animation: slide 1.4s ease-in-out infinite; }
@keyframes slide { from { left: -35%; } to { left: 100%; } }
.mic.not-ready { background: var(--surface); color: var(--accent); }

/* Verwaltung */
.setup-note { margin: 0; padding: .7rem .8rem; border-radius: 8px; background: var(--accent-soft); font-size: .9rem; }
.inline-form.wrap { flex-wrap: wrap; }
.inline-form.wrap input[type=email] { flex: 2 1 220px; }
.inline-form.wrap input[name=password] { flex: 1 1 200px; }
.inline-form.wrap select { flex: 0 0 auto; width: auto; }
.model-list { border: 0; padding: 0; margin: 0; }
.model-list legend { font-weight: 600; margin-bottom: .4rem; }
.model-opt { display: grid; grid-template-columns: auto 1fr; gap: .2rem .7rem; align-items: start; padding: .7rem .8rem;
  border: 1px solid var(--line); border-radius: 10px; margin-bottom: .5rem; cursor: pointer; font-weight: 400; }
.model-opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.model-opt input { width: auto; margin: .2rem 0 0; accent-color: var(--accent); grid-row: span 2; }
.model-opt strong { font-weight: 600; }
.model-opt small { color: var(--muted); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.role-select { width: auto; padding: .3rem .5rem; font-size: .88rem; }
.pw-box { display: flex; align-items: center; gap: .6rem; padding: .7rem .8rem; border-radius: 8px; background: var(--surface-2); }
.pw-box code { font: 600 1.15rem var(--mono); letter-spacing: .04em; flex: 1; }
.badge { font-size: .72rem; padding: 1px 6px; border-radius: 4px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }
@media (max-width: 820px) { .grid-2 { grid-template-columns: 1fr; } }

/* Seiten */
.page { max-width: 980px; margin: 0 auto; padding: 24px 20px 60px; display: grid; gap: 18px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow); }
.card > p.muted { margin: 0 0 1rem; font-size: .92rem; }
.inline-form { display: flex; gap: .6rem; align-items: center; margin-bottom: .8rem; }
.inline-form .arrow { color: var(--muted); }
.filter { margin: .2rem 0 .8rem; max-width: 320px; }
.table { width: 100%; border-collapse: collapse; font-size: .93rem; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; padding: .5rem; border-bottom: 1px solid var(--line); }
.table td { padding: .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table td.actions { text-align: right; white-space: nowrap; width: 1%; }
.table .val { font-family: var(--mono); font-size: .82rem; color: var(--muted); white-space: pre-wrap; max-height: 4.5em; overflow: hidden; display: block; }
.empty { text-align: center; padding: 1rem 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 2px; padding: 3px 4px 3px 10px; border-radius: 999px; background: var(--surface-2); font-size: .88rem; }
.chip.learned { background: var(--accent-soft); }
.chip .icon-btn { font-size: .85rem; padding: 0 .35rem; }
.pill { font-size: .78rem; font-weight: 500; color: var(--muted); background: var(--surface-2); border-radius: 999px; padding: 1px 8px; }
.tag { font-size: .72rem; padding: 1px 6px; border-radius: 4px; background: var(--surface-2); color: var(--muted); }

/* Hinweise */
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 50; max-width: min(420px, calc(100vw - 32px)); }
.toast {
  display: flex; align-items: center; gap: .8rem; padding: 10px 12px 10px 14px; border-radius: 10px;
  background: var(--text); color: var(--bg); box-shadow: 0 6px 24px rgba(0,0,0,.2); font-size: .9rem; animation: in .18s ease-out;
}
.toast button { background: none; border: 1px solid currentColor; color: inherit; border-radius: 6px; padding: 3px 8px; font: inherit; font-size: .82rem; cursor: pointer; white-space: nowrap; }
.toast.error { background: var(--rec); color: #fff; }
@keyframes in { from { transform: translateY(6px); opacity: 0; } }

@media (max-width: 820px) {
  .topbar { height: auto; flex-wrap: wrap; gap: .4rem 1rem; padding: 10px 16px 0; }
  .tabs { order: 3; width: 100%; overflow-x: auto; height: 42px; }
  .dictate { grid-template-columns: 1fr; height: auto; padding: 16px; }
  #editor { min-height: 50vh; }
  .inline-form { flex-wrap: wrap; }
  .inline-form .arrow { display: none; }
  .page { padding: 16px; }
}
