:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1b1f24;
  --muted: #4d5560;
  --border: #c4cad2;
  --accent: #0b5cad;
  --accent-text: #ffffff;
  --ok: #17663a;
  --warn: #8a4b00;
  --error: #a31b1b;
  --removed: #a31b1b;
  --added-bg: #dff3e6;
  --added: #0f4f2b;
  --focus: #e8a400;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181c;
    --surface: #1e2227;
    --text: #e8eaed;
    --muted: #a9b1bb;
    --border: #3d444d;
    --accent: #5aa2ee;
    --accent-text: #0b1520;
    --ok: #6fd39a;
    --warn: #f0b35a;
    --error: #ff8a8a;
    --removed: #ff8a8a;
    --added-bg: #173a26;
    --added: #9be8b9;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.45; }
main { max-width: 96rem; margin: 0 auto; padding: 1.5rem clamp(1rem, 5vw, 4rem) 3rem; }

/* Zweispaltig: links Kürzen, rechts Merkliste und Bausteine */
.layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.5rem; align-items: start; }
@media (min-width: 64rem) {
  .layout { grid-template-columns: minmax(0, 3fr) minmax(20rem, 2fr); gap: 2.5rem; }
  .col-side { position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow-y: auto; padding-right: .25rem; }
}
.col-side .memo:first-child { margin-top: 0; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .5rem; }
.hint { color: var(--muted); margin: 0 0 1rem; font-size: .95rem; }

.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .75rem; }
label { font-weight: 600; }
textarea, input {
  font: inherit; font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: .95rem;
  padding: .55rem .65rem; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text); width: 100%;
}
textarea { resize: vertical; }
.count { margin: 0; color: var(--muted); font-size: .85rem; }
.row { display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; }
.field.small { width: 12rem; margin-bottom: 0; }

button {
  font: inherit; cursor: pointer; border-radius: 6px; padding: .5rem 1rem;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.secondary { margin-top: 1rem; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.error { color: var(--error); font-weight: 600; min-height: 1.2em; margin: .5rem 0 0; }
.warning { color: var(--warn); font-weight: 600; }
.ki-status { color: var(--muted); font-size: .9rem; min-height: 1.2em; }

.variants { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; }
.variant {
  display: grid; grid-template-columns: 1fr auto; gap: .5rem 1rem; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .65rem .8rem;
}
.variant.best { border: 2px solid var(--ok); }
.variant .text { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: .92rem; overflow-wrap: anywhere; }
.variant del { color: var(--removed); text-decoration: line-through; text-decoration-thickness: 2px; }
.variant ins { text-decoration: none; font-weight: 700; color: var(--added); background: var(--added-bg); border-radius: 3px; padding: 0 .15rem; }
.variant .meta { grid-column: 1; color: var(--muted); font-size: .85rem; display: flex; gap: .6rem; flex-wrap: wrap; }
.variant .actions { grid-column: 2; grid-row: 1 / span 2; }
.badge { border: 1px solid var(--border); border-radius: 4px; padding: 0 .35rem; font-size: .75rem; font-weight: 700; }
.too-long { color: var(--warn); font-weight: 600; }

.refine { margin-top: 1rem; padding: .8rem; border: 1px dashed var(--border); border-radius: 8px; background: var(--surface); }
.terms { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .8rem; }
.term { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: .9rem; padding: .3rem .55rem; }
.term[data-state="keep"] { border: 2px solid var(--ok); }
.term[data-state="drop"] { border: 2px dashed var(--removed); text-decoration: line-through; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 40rem) {
  .variant { grid-template-columns: 1fr; }
  .variant .actions { grid-column: 1; grid-row: auto; }
}

/* Merkliste */
.memo { margin: 1.25rem 0; padding: .6rem .8rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.memo summary { cursor: pointer; font-weight: 600; padding: .2rem 0; }
.memo[open] summary { margin-bottom: .5rem; }
.memo-form { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: flex-end; }
.memo-form .field { flex: 1 1 14rem; margin-bottom: 0; }
.prio { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .15rem; }
.prio legend { font-weight: 600; padding: 0; margin-bottom: .2rem; }
.prio label { font-weight: 400; display: flex; align-items: center; gap: .45rem; cursor: pointer; }
.prio input[type="radio"] { width: auto; margin: 0; flex: none; accent-color: var(--accent); }
.prio-hint { color: var(--muted); font-size: .85rem; }
.learn input[type="checkbox"] { width: auto; margin: 0; }
.memo-form .warning, .memo-form .error { flex-basis: 100%; margin: 0; min-height: 0; }
.memo-list { list-style: none; padding: 0; margin: .75rem 0 0; display: grid; gap: .35rem; }
.memo-list li { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.memo-term { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; flex: 1 1 10rem; overflow-wrap: anywhere; }
.memo-prio { font-size: .85rem; padding: .2rem .6rem; }
.memo-prio[data-priority="primaer"] { border: 2px solid var(--ok); }
.memo-prio[data-priority="notfall"] { border: 2px dashed var(--warn); }
.memo-list button { font-size: .85rem; padding: .2rem .6rem; }

/* Nachfrage nach dem Kopieren */
.learn { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: .4rem .9rem; align-items: center;
  border-top: 1px dashed var(--border); padding-top: .5rem; font-size: .9rem; }
.learn-title { font-weight: 600; }
.learn label { display: inline-flex; gap: .3rem; align-items: center; font-weight: 400; }
.learn-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.learn-actions button { font-size: .85rem; padding: .2rem .6rem; }

/* Bewertung, Komma, Bausteine */
.actions { display: flex; gap: .35rem; flex-wrap: wrap; justify-content: flex-end; }
.rate { min-width: 2.4rem; font-weight: 700; }
.rate.good { border-color: var(--ok); color: var(--ok); }
.rate.bad { border-color: var(--removed); color: var(--removed); }
.feedback { grid-column: 1 / -1; font-size: .85rem; color: var(--muted); }
.variant .text button.comma { font: inherit; font-weight: 700; padding: 0 .3rem; margin-left: -.1rem; border: 1px dashed var(--ok); color: var(--ok); background: transparent; }
.variant .text button.comma-off { font: inherit; padding: 0; border: 1px dashed var(--border); background: transparent; color: inherit; }
.join { padding: .15rem .4rem; font-size: .8rem; border-style: dashed; color: var(--muted); }
.memo-prio[data-priority="nie"] { border: 2px solid var(--removed); }

/* Wörter auswählen → Baustein */
.variant { position: relative; }
.variant .text button.word { font: inherit; color: inherit; background: transparent; border: 1px solid transparent;
  border-radius: 3px; padding: 0 .15rem; margin: 0 -.15rem; cursor: pointer; }
.variant .text button.word:hover, .variant .text button.word:focus-visible { background: var(--added-bg); border-color: var(--border); }
.variant .text button.word.selected { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.variant .text button.word.selected del { color: inherit; }
.join-bar { position: absolute; left: .6rem; bottom: calc(100% - .4rem); z-index: 2; display: flex; gap: .4rem;
  flex-wrap: wrap; padding: .35rem; background: var(--surface); border: 1px solid var(--accent); border-radius: 6px;
  box-shadow: 0 2px 8px rgb(0 0 0 / .18); }
.join-bar[hidden] { display: none; }
.join-bar button { font-size: .85rem; padding: .25rem .7rem; }

/* KI-Status mit Ladeanzeige */
.ki-status { display: flex; align-items: center; gap: .5rem; padding: .35rem .6rem; border-radius: 6px; margin: 0 0 .6rem; }
.ki-status:empty, .ki-status[data-state="idle"] { display: none; }
.ki-status[data-state="loading"] { background: var(--surface); border: 1px solid var(--border); color: var(--text); }
.ki-status[data-state="loading"]::before { content: ""; width: .9rem; height: .9rem; flex: none; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent); animation: ki-spin .8s linear infinite; }
.ki-status[data-state="done"] { background: var(--added-bg); color: var(--added); }
.ki-status[data-state="error"], .ki-status[data-state="empty"] { background: var(--surface); border: 1px solid var(--warn); color: var(--warn); }
@keyframes ki-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .ki-status[data-state="loading"]::before { animation: none; } }

/* Kopfleiste */
.topbar { display: flex; justify-content: space-between; align-items: center; gap: .75rem 1.5rem; flex-wrap: wrap;
  padding: .6rem clamp(1rem, 5vw, 4rem); border-bottom: 1px solid var(--border); background: var(--surface); }
.topbar:empty { display: none; }
.topbar-left, .topbar-right { display: flex; align-items: center; gap: .9rem; min-width: 0; }
.topbar-home { color: var(--accent); font-weight: 600; text-decoration: none; }
.topbar-home:hover { text-decoration: underline; }
.topbar-title { font-weight: 600; }
.topbar-user { color: var(--muted); }
.topbar-right button { padding: .35rem .8rem; font-size: .9rem; }

/* Login und Passwort */
.auth { max-width: 26rem; margin: 0 auto; padding: 3rem 1rem; }
.auth-card { display: grid; gap: .9rem; padding: 1.5rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.auth-card h1 { margin: 0; }
.auth-card .field { margin: 0; }
.hint-inline { font-weight: 400; color: var(--muted); font-size: .85rem; }

/* Menü */
.menu-page h1 { margin-bottom: 1rem; }
.menu-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); gap: 1rem; }
.menu-card { display: grid; gap: .4rem; padding: 1.25rem 1.4rem; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); text-decoration: none; transition: border-color .15s, transform .15s; }
.menu-card:hover, .menu-card:focus-visible { border-color: var(--accent); transform: translateY(-1px); }
.menu-name { font-size: 1.15rem; font-weight: 700; color: var(--accent); }
.menu-text { color: var(--muted); font-size: .92rem; }
@media (prefers-reduced-motion: reduce) { .menu-card { transition: none; } .menu-card:hover { transform: none; } }

/* Benutzer-Tabelle */
.table-wrap { overflow-x: auto; margin-bottom: 1.5rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
table.users { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.users th, table.users td { padding: .55rem .7rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.users th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
table.users tr:last-child td { border-bottom: 0; }
table.users input[type="checkbox"] { width: auto; }
table.users tr.is-disabled td { color: var(--muted); }
.row-actions { display: flex; gap: .35rem; flex-wrap: wrap; }
.row-actions button, .inline-confirm button { font-size: .82rem; padding: .25rem .6rem; }
.inline-confirm { display: flex; gap: .35rem; align-items: center; flex-wrap: wrap; }
.inline-confirm input { width: 14rem; padding: .3rem .5rem; }
.feedback-line { color: var(--ok); min-height: 1.2em; margin: 0 0 .25rem; }
.memo h2 { margin-top: 0; font-size: 1.05rem; }
.prio input[type="checkbox"] { width: auto; margin: 0; flex: none; }
