:root {
  color-scheme: light;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-muted: #eef2f7;
  --text: #152238;
  --muted: #5e6c80;
  --border: #d9e0e8;
  --primary: #174ea6;
  --primary-dark: #103d84;
  --success: #16794b;
  --danger: #b42318;
  --warning: #9a6700;
  --shadow: 0 10px 30px rgba(25, 44, 74, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.55; }
a { color: var(--primary); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.shell { width: min(1120px, calc(100% - 32px)); margin: 0 auto; }
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.header-inner { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.brand { display: flex; align-items: center; gap: 12px; font-weight: 750; }
.brand-mark { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--primary); color: white; font-weight: 800; }
.header-links { display: flex; flex-wrap: wrap; gap: 10px; }
main { padding: 36px 0 64px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); padding: 24px; }
.card + .card { margin-top: 20px; }
.hero { display: grid; gap: 12px; margin-bottom: 22px; }
h1, h2, h3 { line-height: 1.2; margin-top: 0; }
h1 { font-size: clamp(1.9rem, 4vw, 2.7rem); margin-bottom: 6px; }
h2 { font-size: 1.35rem; }
p { margin: 0 0 1rem; }
.muted { color: var(--muted); }
.notice { border-radius: 12px; padding: 14px 16px; margin: 14px 0; border: 1px solid var(--border); background: var(--surface-muted); }
.notice.error { border-color: #f0b9b4; background: #fff2f0; color: #7a271a; }
.notice.success { border-color: #a6d8bf; background: #edfdf3; color: #105c3a; }
.notice.warning { border-color: #ead49a; background: #fffaeb; color: #704d00; }
.hidden { display: none !important; }
.form-grid { display: grid; gap: 16px; }
label { display: grid; gap: 7px; font-weight: 650; }
input, textarea, select { width: 100%; border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px; background: white; color: var(--text); }
input:focus, textarea:focus, select:focus { outline: 3px solid rgba(23, 78, 166, .15); border-color: var(--primary); }
textarea { resize: vertical; min-height: 110px; }
.button-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.btn { border: 0; border-radius: 10px; padding: 11px 16px; font-weight: 700; background: var(--primary); color: white; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn:hover { background: var(--primary-dark); }
.btn.secondary { background: var(--surface-muted); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--danger); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.upload-box { border: 2px dashed #b8c4d4; border-radius: 14px; padding: 24px; text-align: center; background: #fafcff; }
.small { font-size: .9rem; }
.feedback { white-space: pre-wrap; font-size: 1.02rem; }
.feedback strong { font-weight: 800; }
.chat-list { display: grid; gap: 12px; margin-bottom: 16px; }
.chat-bubble { max-width: 88%; border-radius: 14px; padding: 12px 14px; white-space: pre-wrap; }
.chat-bubble.user { margin-left: auto; background: #dce8fb; }
.chat-bubble.assistant { background: var(--surface-muted); }
.spinner { display: inline-block; width: 18px; height: 18px; border: 3px solid rgba(255,255,255,.4); border-top-color: white; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.admin-layout { display: grid; grid-template-columns: 300px 1fr; gap: 20px; align-items: start; }
.profile-card { border: 1px solid var(--border); border-radius: 14px; padding: 16px; margin-bottom: 12px; }
.status-pill { display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 10px; font-size: .82rem; font-weight: 750; }
.status-pill.on { background: #dff7e9; color: #12613c; }
.status-pill.off { background: #fee4e2; color: #8a1c13; }
.toolbar { display: grid; grid-template-columns: 180px 1fr auto; gap: 10px; margin-bottom: 14px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .94rem; }
th, td { padding: 10px 11px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { background: var(--surface-muted); font-weight: 750; position: sticky; top: 0; }
tr.clickable:hover { background: #f7faff; cursor: pointer; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; }
.kv { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.kv b { display: block; font-size: .8rem; color: var(--muted); margin-bottom: 4px; }
pre { white-space: pre-wrap; overflow-wrap: anywhere; background: #0f172a; color: #e2e8f0; border-radius: 12px; padding: 14px; max-height: 440px; overflow: auto; font-size: .82rem; }
.login-wrap { min-height: calc(100vh - 72px); display: grid; place-items: center; padding: 32px 0; }
.login-card { width: min(520px, 100%); }
.login-title-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.login-links { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 850px) {
  .admin-layout { grid-template-columns: 1fr; }
  .toolbar { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
}

/* v2: robuste Karten, getrennte Uploadwege und Markdown */
.admin-layout > *, .detail-grid > *, .kv, .card { min-width: 0; }
.kv, .kv code, .kv a, .wrap-anywhere, .document-status span {
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: normal;
}
.kv code { display: inline; font-size: .82rem; }
.upload-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; align-items: stretch; }
.upload-option { display: flex; flex-direction: column; gap: 14px; min-width: 0; border: 1px solid var(--border); border-radius: 14px; padding: 18px; background: #fbfcfe; }
.upload-option.featured { border-color: #aebfda; background: #f7faff; }
.upload-option h3 { margin-bottom: 6px; }
.upload-option .upload-submit { margin-top: auto; width: 100%; }
.upload-box.compact { padding: 18px 12px; }
.upload-limit { margin: 16px 0 0; }
.active-documents { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.document-status { display: grid; gap: 5px; border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; min-width: 0; }
.feedback, .chat-bubble { white-space: normal; }
.markdown p { margin: 0 0 1rem; }
.markdown p:last-child { margin-bottom: 0; }
.markdown ul, .markdown ol { margin: .4rem 0 1rem 1.25rem; padding: 0; }
.markdown li + li { margin-top: .3rem; }
.markdown code { overflow-wrap: anywhere; word-break: break-word; background: rgba(15, 23, 42, .08); border-radius: 5px; padding: .08rem .28rem; }
.markdown h3, .markdown h4 { margin: 1rem 0 .5rem; }
@media (max-width: 980px) { .upload-options { grid-template-columns: 1fr; } }
@media (max-width: 600px) { .active-documents { grid-template-columns: 1fr; } }
