:root {
  --accent: #3AFFB7; --accent-fg: #06281c;
  --bg: #eef1f6; --panel: #ffffff; --panel-2: #f4f6fa; --line: #dfe4ec;
  --text: #15181d; --muted: #667085; --hover: #eceff5; --user-bubble: #eef1f6;
  --danger: #c0392b; --ok: #14804a; --warn: #9a6200; --link: #0b63c5;
  --shadow: 0 12px 40px rgba(20, 30, 50, .18);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0f0f; --panel: #1b1b1e; --panel-2: #232327; --line: #2f3036;
    --text: #eceef1; --muted: #9aa0ab; --hover: #2a2b30; --user-bubble: #27282d;
    --danger: #ff7b6b; --ok: #4ade80; --warn: #f5b942; --link: #7cc4ff;
    --shadow: 0 12px 40px rgba(0, 0, 0, .55); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e0f0f; --panel: #1b1b1e; --panel-2: #232327; --line: #2f3036;
  --text: #eceef1; --muted: #9aa0ab; --hover: #2a2b30; --user-bubble: #27282d;
  --danger: #ff7b6b; --ok: #4ade80; --warn: #f5b942; --link: #7cc4ff;
  --shadow: 0 12px 40px rgba(0, 0, 0, .55); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif; }
[hidden] { display: none !important; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; flex: none; }
a { color: var(--link); }
h1, h2, h3 { margin: 0; font-weight: 600; }
.muted { color: var(--muted); }
.error { color: var(--danger); margin: 0; }

input, textarea, select { font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; width: 100%; outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
label { display: grid; gap: 5px; font-size: 13px; color: var(--muted); }
label > input, label > textarea, label > select { color: var(--text); font-size: 15px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text); font: inherit;
  font-weight: 500; padding: 8px 14px; border-radius: 10px; white-space: nowrap; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; font-weight: 600; }
.btn.primary:hover { filter: brightness(.94); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { display: inline-grid; place-items: center; width: 32px; height: 32px; border: 0; cursor: pointer;
  background: transparent; color: var(--muted); border-radius: 8px; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.on { color: var(--accent-fg); background: var(--accent); }

/* Anmeldung */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 28px; display: grid; gap: 14px; box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 17px; }
.brand h1 { font-size: 20px; }
/* ROSE-Zeichen «R»: dunkles Feld mit hellem R, im dunklen Design umgekehrt */
.logo { width: 30px; height: 30px; border-radius: 9px; background: var(--text); flex: none; position: relative; }
.logo::after { content: ""; position: absolute; inset: 6px; background: var(--panel);
  -webkit-mask: url(/static/rose-r.svg) center / contain no-repeat; mask: url(/static/rose-r.svg) center / contain no-repeat; }
/* ROSE-Schriftzug, nimmt die Textfarbe des Designs an */
.wordmark { display: block; flex: none; width: 62px; height: 21px; background: var(--text);
  -webkit-mask: url(/static/rose-logo.svg) left center / contain no-repeat; mask: url(/static/rose-logo.svg) left center / contain no-repeat; }
.login-card .brand { flex-direction: column; align-items: flex-start; gap: 14px; }
.login-card .wordmark { width: 118px; height: 40px; }
.sidebar .brand #appName { font-size: 14px; font-weight: 600; color: var(--muted); padding-left: 10px; border-left: 1px solid var(--line); }

/* Aufbau */
.app { height: 100%; display: grid; grid-template-columns: 288px 1fr; gap: 14px; padding: 14px; }
.sidebar { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px 12px 12px;
  display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.sidebar .brand { padding: 0 6px 4px; }
.side-label { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 6px 8px 0; }
.chat-list { flex: 1; overflow-y: auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; align-content: start; min-height: 60px; }
.chat-item { display: flex; align-items: center; gap: 4px; padding: 0 4px 0 10px; border-radius: 9px; cursor: pointer; height: 36px; }
.nw { white-space: nowrap; }
.chat-item span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.chat-item:hover, .chat-item.active { background: var(--hover); }
.chat-item .icon-btn { visibility: hidden; width: 26px; height: 26px; }
.chat-item:hover .icon-btn, .chat-item.active .icon-btn { visibility: visible; }
.chat-item svg { width: 15px; height: 15px; }
.area-list { display: grid; gap: 2px; }
.area-list a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 9px; cursor: pointer; font-size: 14px; color: var(--text); }
.area-list a span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.area-list a:hover { background: var(--hover); }
.area-list a.active { background: color-mix(in srgb, var(--accent) 16%, transparent); box-shadow: inset 3px 0 0 var(--accent); font-weight: 600; }
.admin-nav { display: grid; gap: 2px; border-top: 1px solid var(--line); padding-top: 8px; }
.admin-nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 9px; cursor: pointer;
  font-size: 14px; color: var(--text); text-decoration: none; }
.admin-nav a:hover, .admin-nav a.active { background: var(--hover); }
.admin-nav a.active { box-shadow: inset 3px 0 0 var(--accent); }
.side-foot { border-top: 1px solid var(--line); padding-top: 10px; display: grid; gap: 6px; }
.side-foot .btn { justify-content: flex-start; border: 0; padding: 7px 10px; font-weight: 400; font-size: 14px; }
.user-row { display: flex; align-items: center; gap: 2px; padding-left: 10px; }
.user-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; color: var(--muted); }

.main { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; min-width: 0; min-height: 0;
  display: flex; flex-direction: column; overflow: hidden; }
.topbar { display: flex; align-items: center; gap: 8px; padding: 12px 20px; border-bottom: 1px solid var(--line); min-height: 54px; }
.topbar h2 { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#menuBtn { display: none; }
.view { flex: 1; min-height: 0; }
.scrim { display: none; }

/* Chat */
.chat-view { display: flex; flex-direction: column; }
.messages { flex: 1; overflow-y: auto; padding: 24px 20px 8px; scroll-behavior: smooth; }
.messages > * { max-width: 820px; margin-left: auto; margin-right: auto; }
.msg { display: flex; gap: 14px; padding: 12px 0; }
.avatar { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; flex: none;
  font-size: 13px; font-weight: 650; background: var(--user-bubble); color: var(--muted); }
.msg.assistant .avatar { background: var(--accent); color: var(--accent-fg); }
.msg-body { min-width: 0; flex: 1; }
.msg.user .msg-body { background: color-mix(in srgb, var(--accent) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 55%, var(--line)); border-radius: 14px; padding: 9px 14px; flex: 0 1 auto; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { flex-direction: row-reverse; }
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 4px; } .md > :last-child { margin-bottom: 4px; }
.md p { margin: 8px 0; } .md ul, .md ol { margin: 8px 0; padding-left: 22px; } .md li { margin: 3px 0; }
.md ol.steps { list-style: none; padding-left: 0; }
.md ol.steps li { display: grid; grid-template-columns: 1.7em 1fr; column-gap: 6px; margin: 2px 0; padding: 7px 10px; border-radius: 8px; }
.md ol.steps li::before { content: attr(data-n) "."; text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; }
.md ol.steps li.odd { background: var(--panel-2); }
.md h3 { font-size: 16px; margin: 14px 0 6px; } .md h4 { font-size: 15px; margin: 12px 0 4px; }
.md code { background: var(--panel-2); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; font-size: 13px; }
.md pre { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; overflow-x: auto; }
.md pre code { border: 0; padding: 0; background: none; }
.md table { border-collapse: collapse; margin: 10px 0; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 5px 10px; text-align: left; }
.md th { background: var(--panel-2); }
.cite { display: inline-grid; place-items: center; min-width: 19px; height: 19px; padding: 0 5px; margin: 0 1px;
  border-radius: 6px; border: 1px solid color-mix(in srgb, var(--accent) 55%, var(--line)); background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--text); font: 600 11px/1 inherit; cursor: pointer; vertical-align: 2px; }
.cite:hover { background: var(--accent); color: var(--accent-fg); }
.sources { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.src { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 4px 10px 4px 5px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text); font: inherit; font-size: 13px; cursor: pointer; }
.src:hover { border-color: var(--accent); }
.src b { display: inline-grid; place-items: center; min-width: 19px; height: 19px; border-radius: 6px; font-size: 11px;
  background: color-mix(in srgb, var(--accent) 22%, transparent); }
.src span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.src small { color: var(--muted); white-space: nowrap; }
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 2px 8px; border-radius: 99px;
  border: 1px solid var(--line); color: var(--muted); }
.badge.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, transparent); }
.badge.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.badge.bad { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.badge svg { width: 13px; height: 13px; }
.msg-actions { display: flex; align-items: center; gap: 2px; margin-top: 6px; opacity: .55; }
.msg:hover .msg-actions { opacity: 1; }
.msg-actions .icon-btn { width: 28px; height: 28px; } .msg-actions svg { width: 15px; height: 15px; }
.msg-actions .btn { margin-left: 6px; }
.typing { display: inline-flex; gap: 4px; padding: 10px 0; }
.typing i { width: 6px; height: 6px; 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; } }
@media (prefers-reduced-motion: reduce) { .typing i { animation: none; } .messages { scroll-behavior: auto; } }

.empty { text-align: center; padding: 9vh 0 20px; }
.empty .logo { width: 52px; height: 52px; border-radius: 16px; margin: 0 auto 16px; display: block; }
.empty .logo::after { inset: 11px; }
.empty h3 { font-size: 22px; margin-bottom: 6px; }
.suggest { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 10px; margin-top: 26px; text-align: left; }
.suggest button { text-align: left; white-space: normal; padding: 12px 14px; font-weight: 400; }
.notice { border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent); color: var(--warn); border-radius: 12px; padding: 10px 14px; margin-top: 18px; display: inline-block; }

.ask { padding: 8px 20px 14px; }
.ask-box { max-width: 820px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 16px; padding: 8px 8px 8px 16px; }
.ask-box:focus-within { border-color: var(--accent); }
.ask-box textarea { border: 0; background: transparent; padding: 6px 0; resize: none; max-height: 180px; box-shadow: none; }
.send { width: 36px; height: 36px; border-radius: 11px; border: 0; cursor: pointer; background: var(--accent); color: var(--accent-fg);
  display: grid; place-items: center; flex: none; }
.send:disabled { opacity: .45; cursor: default; }
.ask-note { max-width: 820px; margin: 7px auto 0; font-size: 12px; color: var(--muted); text-align: center; }

/* Verwaltung */
.admin-view { overflow-y: auto; padding: 22px 24px 40px; }
.admin-view > * { max-width: 980px; margin-left: auto; margin-right: auto; }
.lead { color: var(--muted); margin: 0 auto 18px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.toolbar .grow { flex: 1; }
.card { border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 12px; background: var(--panel); }
.card h3 { font-size: 15px; margin-bottom: 10px; }
.drop { border: 1.5px dashed var(--line); border-radius: 14px; padding: 26px; text-align: center; color: var(--muted);
  cursor: pointer; margin-bottom: 16px; background: var(--panel-2); }
.drop.over, .drop:hover { border-color: var(--accent); color: var(--text); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 14px; }
table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list th, table.list td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list th { font-size: 12px; color: var(--muted); font-weight: 500; background: var(--panel-2); white-space: nowrap; }
table.list tr:last-child td { border-bottom: 0; }
table.list td:first-child { min-width: 200px; }
.badge { white-space: nowrap; }
table.list td.num, table.list th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.list td.actions { white-space: nowrap; text-align: right; }
.switch { position: relative; width: 36px; height: 20px; display: inline-block; }
.switch input { opacity: 0; position: absolute; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; border-radius: 99px; background: var(--line); transition: .15s; }
.switch i::after { content: ""; position: absolute; width: 14px; height: 14px; left: 3px; top: 3px; border-radius: 50%; background: var(--panel); transition: .15s; }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { left: 19px; background: var(--accent-fg); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: end; }
.form { display: grid; gap: 12px; }
.row { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.row > label { flex: 1; min-width: 180px; }
.qa { display: grid; gap: 6px; }
.qa .q { font-weight: 600; }
.qa .a { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text); max-height: 7.6em; overflow: hidden; }
.qa.open .a { max-height: none; }
.qa .meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; font-size: 12px; color: var(--muted); }
.qa .meta .grow { flex: 1; }
.hint { font-size: 12.5px; color: var(--muted); margin: 0; }

/* Vorschau, Dialog, Hinweis */
.preview { position: fixed; z-index: 50; width: 330px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow); padding: 10px; pointer-events: none; }
.preview .ptitle { font-size: 13px; font-weight: 600; margin-bottom: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview .psub { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.preview img { width: 100%; display: block; border-radius: 6px; border: 1px solid var(--line); background: #fff; min-height: 180px; max-height: 420px; object-fit: contain; object-position: top; }
.preview p { margin: 0; font-size: 13px; }
.modal { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .55); display: grid; place-items: center; padding: 16px; }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
  width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 20px; display: grid; gap: 14px; }
.modal-card.viewer { width: min(980px, 100%); padding: 14px; grid-template-rows: auto 1fr; }
.modal-head { display: flex; align-items: center; gap: 8px; }
.modal-head h3 { flex: 1; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.viewer-img { overflow: auto; max-height: calc(100vh - 130px); border-radius: 8px; border: 1px solid var(--line); background: #fff; min-height: 300px; }
.viewer-img img { width: 100%; display: block; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 70; background: var(--text); color: var(--panel);
  padding: 9px 16px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; padding: 0; gap: 0; }
  .main { border-radius: 0; border: 0; }
  .sidebar { position: fixed; z-index: 40; inset: 0 auto 0 0; width: min(300px, 86vw); border-radius: 0 16px 16px 0;
    transform: translateX(-105%); transition: transform .2s; }
  .app.menu .sidebar { transform: none; }
  .app.menu .scrim { display: block; position: fixed; inset: 0; z-index: 39; background: rgba(0, 0, 0, .5); }
  #menuBtn { display: inline-grid; }
  .topbar { padding: 8px 12px; }
  .messages { padding: 14px 14px 4px; } .ask { padding: 6px 12px 10px; }
  .admin-view { padding: 16px 14px 32px; }
  .grid2 { grid-template-columns: 1fr; }
  .msg { gap: 10px; }
}

.app-version { font-size: 11px; color: var(--muted); padding: 2px 6px 0; }
/* niedrige Fenster: die Seitenleiste rollt, statt unten etwas abzuschneiden */
.app > .sidebar { min-height: 0; overflow-y: auto; }
.chat-list { min-height: 40px; flex-shrink: 1; }
.sidebar > :not(.chat-list) { flex-shrink: 0; }

/* Anleitungen im Dialog */
.help h4 { font-size: 14px; margin: 14px 0 6px; }
.help ol, .help ul { margin: 0; padding-left: 22px; display: grid; gap: 6px; }
.help a, .hint a { color: var(--link); }
.help code { background: var(--panel-2); border: 1px solid var(--line); border-radius: 5px; padding: 0 4px; font-size: 13px; }

.app-version a.link { cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.app-version a.link:hover { color: var(--text); }

/* Mehrfachauswahl als Aufklappfeld (Gruppen eines Benutzers) */
.multi { position: relative; display: inline-block; }
.multi > summary { list-style: none; cursor: pointer; padding: 5px 26px 5px 8px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--panel-2); max-width: 240px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; position: relative; }
.multi > summary::-webkit-details-marker { display: none; }
.multi > summary::after { content: ""; position: absolute; right: 10px; top: 50%; width: 6px; height: 6px; margin-top: -5px;
  border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); transform: rotate(45deg); }
.multi[open] > summary { border-color: var(--accent); }
.multi-list { position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; min-width: 200px; display: grid; gap: 6px; padding: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.multi-list label, .checks label { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; color: var(--text); }
.multi-list input, .checks input { width: auto; }
.checks-field { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.checks { display: grid; gap: 6px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); }
.table-wrap:has(.multi[open]) { overflow: visible; }

/* Konto ohne freigegebenen Bereich */
.no-area #askForm, .no-area #newChat, .no-area #areaList, .no-area #chatList, .no-area .sidebar > .side-label { display: none; }
.no-area .sidebar .side-foot { margin-top: auto; }
