:root {
  --bg: #f4f2ee;
  --panel: #ffffff;
  --panel-2: #faf8f4;
  --text: #1d1c1a;
  --muted: #6b675f;
  --line: #e2ddd3;
  --accent: #c8501e;
  --accent-2: #e8a33d;
  --accent-soft: #fbeee6;
  --ok: #2f7d4a;
  --ok-soft: #e5f3ea;
  --warn: #9a6a00;
  --warn-soft: #fbf1d9;
  --bad: #b3261e;
  --bad-soft: #fbe6e4;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  --radius: 12px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --mono: "Cascadia Mono", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161514; --panel: #201f1d; --panel-2: #1b1a18; --text: #ece8e1; --muted: #a29d93;
    --line: #34312d; --accent: #ef7440; --accent-2: #f0b552; --accent-soft: #3a261c;
    --ok: #6cc38b; --ok-soft: #1f3226; --warn: #e6b955; --warn-soft: #3a311b;
    --bad: #f08a80; --bad-soft: #3d2120; --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.55 var(--font); }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- Kopfzeile */
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 10px 20px; flex-wrap: wrap;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .2px; text-decoration: none; color: var(--text); }
/* Logo: schlichte Stufenheck-Limousine im Seitenprofil (Form per Maske, Farbe = Akzentfarbe) */
.brand .stripe { width: 40px; height: 20px; background: var(--accent);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 48 24'%3E%3Cpath fill-rule='evenodd' d='M2 17.5V13.2c0-1 .7-1.8 1.7-2l8.6-1.4 5.4-5.2c.6-.6 1.4-.9 2.2-.9h10.6c.8 0 1.6.3 2.1.9l5.2 5.2 6.6 1.2c1 .2 1.6 1 1.6 2v4.5H44a5 5 0 0 0-10 0H16a5 5 0 0 0-10 0H2zM18.7 6.3l-4.3 4h9V5.8h-3.3c-.5 0-1 .2-1.4.5zM25.3 5.8v4.5h11.3l-3.8-4c-.3-.3-.8-.5-1.3-.5h-6.2z'/%3E%3Ccircle cx='11' cy='18.5' r='3.6'/%3E%3Ccircle cx='39' cy='18.5' r='3.6'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 48 24'%3E%3Cpath fill-rule='evenodd' d='M2 17.5V13.2c0-1 .7-1.8 1.7-2l8.6-1.4 5.4-5.2c.6-.6 1.4-.9 2.2-.9h10.6c.8 0 1.6.3 2.1.9l5.2 5.2 6.6 1.2c1 .2 1.6 1 1.6 2v4.5H44a5 5 0 0 0-10 0H16a5 5 0 0 0-10 0H2zM18.7 6.3l-4.3 4h9V5.8h-3.3c-.5 0-1 .2-1.4.5zM25.3 5.8v4.5h11.3l-3.8-4c-.3-.3-.8-.5-1.3-.5h-6.2z'/%3E%3Ccircle cx='11' cy='18.5' r='3.6'/%3E%3Ccircle cx='39' cy='18.5' r='3.6'/%3E%3C/svg%3E") center / contain no-repeat; }
.brand small { font-weight: 400; color: var(--muted); }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--muted); font-size: 14px; }

/* ---------- Knoepfe & Formulare */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel);
  padding: 7px 14px; border-radius: 8px; cursor: pointer; text-decoration: none; color: var(--text); font-size: 14px; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 3px 9px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=password], input[type=url], input[type=number], input[type=search], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-2); outline-offset: -1px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
label.check { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 160px; }

/* ---------- Karten */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.card h2, .card h3 { margin: 0 0 8px; }
.muted { color: var(--muted); }
.error { color: var(--bad); min-height: 1.2em; font-size: 14px; }
.notice { padding: 10px 14px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); font-size: 14px; margin: 10px 0; }

/* ---------- Login / Setup */
.center-page { min-height: 100%; display: grid; place-items: center; padding: 20px; }
.center-page .card { width: 100%; max-width: 400px; }

/* ---------- Chat */
.chat-wrap { max-width: 860px; margin: 0 auto; padding: 0 16px; display: flex; flex-direction: column; height: calc(100vh - 57px); }
.messages { flex: 1; overflow-y: auto; padding: 24px 0 12px; }
.welcome { text-align: center; padding: 40px 10px 10px; }
.welcome h1 { margin: 0 0 6px; font-size: 28px; }
.welcome p { color: var(--muted); max-width: 560px; margin: 0 auto 18px; }
.examples { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.examples button { border: 1px solid var(--line); background: var(--panel); padding: 7px 12px; border-radius: 999px; cursor: pointer; font-size: 14px; }
.examples button:hover { border-color: var(--accent); color: var(--accent); }
.msg { margin: 14px 0; display: flex; }
.msg.user { justify-content: flex-end; }
.bubble { max-width: 85%; padding: 10px 14px; border-radius: 14px; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.bot .bubble { background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 4px; box-shadow: var(--shadow); }
.msg.bot .bubble p { margin: 0 0 8px; } .msg.bot .bubble p:last-child { margin: 0; }
.msg.bot .bubble ul, .msg.bot .bubble ol { margin: 4px 0 8px; padding-left: 22px; }
.msg.bot .bubble table { border-collapse: collapse; margin: 6px 0; font-size: 14px; }
.msg.bot .bubble td, .msg.bot .bubble th { border: 1px solid var(--line); padding: 3px 8px; }
.msg.bot.noinfo .bubble { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.msg.bot.err .bubble { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
sup.cite a { text-decoration: none; font-weight: 600; font-size: 11px; padding: 0 2px; }
.sources { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 8px; font-size: 13px; }
.sources summary { cursor: pointer; color: var(--muted); }
.sources ol { margin: 6px 0 0; padding-left: 22px; }
.sources li { margin: 4px 0; }
.sources .ausz { color: var(--muted); font-size: 12px; display: block; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin: 10px 0 4px; }
.gallery figure { margin: 0; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.gallery img { display: block; width: 100%; height: 130px; object-fit: cover; background: var(--line); }
.gallery figcaption { font-size: 12px; padding: 6px 8px; color: var(--muted); line-height: 1.35; }
.excerpts { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; margin: 12px 0 4px; }
.excerpts figure { margin: 0; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.excerpts img { display: block; width: 100%; height: 240px; object-fit: cover; object-position: top; background: #fff; border-bottom: 1px solid var(--line); }
.excerpts figcaption { font-size: 12px; padding: 8px; color: var(--muted); line-height: 1.4; }
.excerpts figcaption b { color: var(--text); font-weight: 600; }
.ex-btns { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.downloads { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 2px; }
.downloads .btn { white-space: normal; text-align: left; }
.srcthumb { width: 56px; height: 42px; object-fit: cover; border-radius: 4px; vertical-align: middle; margin-right: 6px; border: 1px solid var(--line); }
.typing { display: inline-flex; gap: 4px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.composer { display: flex; gap: 8px; padding: 12px 0 18px; align-items: flex-end; }
.composer textarea { resize: none; min-height: 46px; max-height: 180px; border-radius: 12px; padding: 12px 14px; background: var(--panel); }
.composer .btn { height: 46px; padding: 0 20px; border-radius: 12px; }
.composer .photobtn { padding: 0 14px; font-size: 20px; cursor: pointer; display: inline-flex; align-items: center; }
.photochip { display: flex; align-items: center; gap: 10px; margin-top: 10px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); font-size: 13px; color: var(--muted); }
.photochip img { height: 48px; width: auto; border-radius: 6px; }
.photochip span { flex: 1; }
.userphoto { display: block; max-width: 260px; max-height: 200px; border-radius: 8px; margin-bottom: 6px; }
.reading { margin-bottom: 10px; }
.reading pre { margin: 4px 0 0; padding: 8px 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.footnote { text-align: center; font-size: 12px; color: var(--muted); padding-bottom: 8px; margin-top: -10px; }

/* ---------- Admin */
.admin { display: grid; grid-template-columns: 220px 1fr; min-height: calc(100vh - 57px); }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 14px 10px; }
.side button { display: flex; width: 100%; justify-content: space-between; text-align: left; border: 0; background: none; padding: 9px 12px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.side button:hover { background: var(--panel-2); }
.side button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side .badge { background: var(--accent); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 7px; line-height: 18px; }
.main { padding: 22px 26px 60px; min-width: 0; }
.main h1 { margin: 0 0 4px; font-size: 22px; }
.main > .muted { margin: 0 0 18px; }
.stack > * + * { margin-top: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat b { display: block; font-size: 26px; }
.stat span { color: var(--muted); font-size: 13px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.toolbar input, .toolbar select { width: auto; min-width: 160px; }
table.list { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; font-size: 14px; }
table.list th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; background: var(--panel-2); }
table.list th, table.list td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tr:last-child td { border-bottom: 0; }
table.list td.actions { white-space: nowrap; text-align: right; }
table.list .title { font-weight: 600; }
table.list .sub { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.pill { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill.aktiv, .pill.fertig { background: var(--ok-soft); color: var(--ok); }
.pill.pruefen, .pill.laeuft, .pill.wartet, .pill.abbrechen { background: var(--warn-soft); color: var(--warn); }
.pill.abgelehnt, .pill.fehler, .pill.abgebrochen, .pill.inaktiv { background: var(--bad-soft); color: var(--bad); }
.pill.kind { background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); font-weight: 500; }
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 22px; text-align: center; color: var(--muted); cursor: pointer; background: var(--panel-2); }
.drop.over { border-color: var(--accent); color: var(--accent); }
.queue { margin-top: 10px; font-size: 14px; }
.queue div { padding: 4px 0; border-bottom: 1px dotted var(--line); }
pre.log { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; max-height: 360px; overflow: auto; font: 12px/1.45 var(--mono); white-space: pre-wrap; margin: 0; }
.permgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 2px 16px; }
dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--text); padding: 20px 22px; width: min(760px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog h3 { margin-top: 0; }
dialog .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.chunk { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 6px 0; font-size: 13px; white-space: pre-wrap; background: var(--panel-2); max-height: 220px; overflow: auto; }
.toast { position: fixed; right: 18px; bottom: 18px; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; transform: translateY(10px); transition: .2s; pointer-events: none; z-index: 50; }
.toast.show { opacity: 1; transform: none; }
.toast.bad { background: var(--bad); color: #fff; }

@media (max-width: 760px) {
  .admin { grid-template-columns: 1fr; }
  .side { display: flex; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 6px; gap: 4px; }
  .side button { width: auto; white-space: nowrap; }
  .main { padding: 16px; }
  .topbar { padding: 10px 14px; }
  .brand small { display: none; }
  table.list .hide-sm { display: none; }
}
