/* ── Reset & Basis ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:       #2563eb;
  --primary-h:     #1d4ed8;
  --primary-light: #eff6ff;
  --bg:            #f1f5f9;
  --surface:       #ffffff;
  --border:        #e2e8f0;
  --border-soft:   #f1f5f9;
  --text:          #0f172a;
  --text-muted:    #64748b;
  --text-subtle:   #94a3b8;
  --success:       #059669;
  --danger:        #dc2626;
  --user-bg:       #2563eb;
  --assistant-bg:  #ffffff;
  --radius:        14px;
  --radius-sm:     8px;
  --shadow:        0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:     0 4px 12px rgba(0,0,0,.08), 0 1px 3px rgba(0,0,0,.05);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Navbar ────────────────────────────────────────────────────────────────── */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  flex-shrink: 0;
  z-index: 10;
}
.navbar-brand {
  font-weight: 700;
  font-size: 16px;
  color: var(--primary);
  letter-spacing: -0.3px;
}
.navbar-user  { display: flex; align-items: center; gap: 12px; }
.navbar-email { font-size: 13px; color: var(--text-muted); }

.btn-logout {
  font-size: 13px; padding: 5px 14px;
  border: 1px solid var(--border); border-radius: 7px;
  background: transparent; cursor: pointer; color: var(--text);
  transition: background .15s, border-color .15s;
}
.btn-logout:hover { background: var(--bg); border-color: #cbd5e1; }

/* ── Auth-Karten ───────────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 40px 44px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-md);
}
.auth-card h1 { font-size: 22px; margin-bottom: 6px; font-weight: 700; letter-spacing: -0.4px; }
.auth-hint    { font-size: 13px; color: var(--text-muted); margin-bottom: 24px; }
.auth-link    { margin-top: 16px; font-size: 13px; text-align: center; color: var(--text-muted); }
.auth-link a  { color: var(--primary); text-decoration: none; font-weight: 500; }
.auth-link a:hover { text-decoration: underline; }

.icon-large   { font-size: 48px; margin-bottom: 16px; }

.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form label { font-size: 13px; font-weight: 600; color: var(--text); display: flex; flex-direction: column; gap: 5px; }
.hint { font-size: 11px; color: var(--text-muted); font-weight: 400; margin-top: 2px; }

.auth-form input[type="email"],
.auth-form input[type="password"] {
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  background: var(--surface);
  color: var(--text);
}
.auth-form input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn-primary {
  background: var(--primary); color: #fff;
  border: none; border-radius: 9px;
  padding: 11px 20px; font-size: 14px; font-weight: 600;
  cursor: pointer; margin-top: 4px;
  transition: background .15s, box-shadow .15s;
  box-shadow: 0 1px 3px rgba(37,99,235,.3);
}
.btn-primary:hover { background: var(--primary-h); box-shadow: 0 2px 6px rgba(37,99,235,.35); }

.btn-secondary {
  display: inline-block;
  margin-top: 16px;
  padding: 10px 20px;
  border: 1px solid var(--border); border-radius: 9px;
  font-size: 14px; color: var(--text); text-decoration: none;
  transition: background .15s;
}
.btn-secondary:hover { background: var(--bg); }

/* ── Alerts ────────────────────────────────────────────────────────────────── */
.alert {
  padding: 10px 14px; border-radius: 9px;
  font-size: 13px; margin-bottom: 14px;
}
.alert-error   { background: #fef2f2; border: 1px solid #fca5a5; color: var(--danger); }
.alert-success { background: #f0fdf4; border: 1px solid #86efac; color: var(--success); }

/* ── Chat-Seite: main überschreiben ────────────────────────────────────────── */
.main-content.chat-page {
  align-items: stretch;
  justify-content: flex-start;
  padding: 0;
  overflow: hidden;
}

/* ── Chat-Layout (Sidebar + Hauptbereich) ──────────────────────────────────── */
.chat-layout {
  display: flex;
  height: 100%;
  width: 100%;
  overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────────────────────────────── */
.chat-sidebar {
  width: 260px;
  flex-shrink: 0;
  background: #1e293b;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid #334155;
}

.sidebar-top {
  padding: 14px 12px;
  border-bottom: 1px solid #334155;
  flex-shrink: 0;
}

.btn-new-chat {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 13px;
  background: rgba(255,255,255,.07);
  border: 1px solid #475569;
  border-radius: 9px;
  color: #e2e8f0;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn-new-chat:hover { background: rgba(255,255,255,.13); border-color: #64748b; }

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.chat-list::-webkit-scrollbar { width: 4px; }
.chat-list::-webkit-scrollbar-track { background: transparent; }
.chat-list::-webkit-scrollbar-thumb { background: #475569; border-radius: 4px; }

.chat-item {
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: 8px;
  transition: background .12s;
  padding: 2px 2px 2px 0;
}
.chat-item:hover { background: rgba(255,255,255,.07); }
.chat-item.active { background: rgba(255,255,255,.12); }

.chat-item-link {
  flex: 1;
  padding: 7px 10px;
  color: #cbd5e1;
  font-size: 13px;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  border-radius: 6px;
  transition: color .12s;
}
.chat-item.active .chat-item-link { color: #f1f5f9; font-weight: 500; }
.chat-item:hover .chat-item-link  { color: #f1f5f9; }

.chat-delete-btn {
  flex-shrink: 0;
  padding: 5px 7px;
  background: none;
  border: none;
  border-radius: 6px;
  color: #64748b;
  cursor: pointer;
  opacity: 0;
  transition: opacity .12s, background .12s, color .12s;
}
.chat-item:hover .chat-delete-btn { opacity: 1; }
.chat-delete-btn:hover { background: rgba(220,38,38,.2); color: #f87171; }

/* ── Chat-Hauptbereich ──────────────────────────────────────────────────────── */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  align-self: stretch;
}

.chat-input-area {
  padding: 12px 20px 18px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg);
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  align-self: stretch;
}

/* ── Begrüßung ─────────────────────────────────────────────────────────────── */
.welcome-msg {
  display: flex;
  justify-content: flex-start;
}
.welcome-bubble {
  background: linear-gradient(135deg, #eff6ff 0%, #f0f9ff 100%);
  border: 1px solid #bfdbfe;
  border-left: 4px solid var(--primary);
  border-radius: var(--radius);
  border-bottom-left-radius: 4px;
  padding: 16px 20px;
  max-width: 100%;
  box-shadow: var(--shadow);
}
.welcome-bubble .welcome-icon { font-size: 28px; margin-bottom: 8px; }
.welcome-bubble .welcome-title {
  font-weight: 700; font-size: 15px; color: var(--primary);
  margin-bottom: 4px; letter-spacing: -0.2px;
}
.welcome-bubble .welcome-text { font-size: 14px; color: var(--text-muted); line-height: 1.5; }

/* ── Nachrichten ───────────────────────────────────────────────────────────── */
.msg { display: flex; align-items: flex-end; gap: 8px; }
.msg-user      { justify-content: flex-end; }
.msg-assistant { justify-content: flex-start; }

.msg-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; flex-shrink: 0; margin-bottom: 2px;
}
.msg-assistant .msg-avatar {
  background: var(--primary-light);
  border: 1px solid #bfdbfe;
  color: var(--primary);
}

.msg-bubble {
  max-width: 100%;
  padding: 14px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.6;
  box-shadow: var(--shadow);
}
.msg-user .msg-bubble {
  background: var(--user-bg);
  color: #fff;
  border-bottom-right-radius: 4px;
  font-weight: 450;
}
.msg-assistant .msg-bubble {
  background: var(--assistant-bg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  border-left: 3px solid var(--primary);
}
.msg-error { background: #fef2f2 !important; color: var(--danger); border-color: #fca5a5 !important; border-left-color: var(--danger) !important; }

/* ── Markdown-Rendering ────────────────────────────────────────────────────── */
.answer-text { line-height: 1.7; color: var(--text); }
.answer-text > *:first-child { margin-top: 0 !important; }
.answer-text > *:last-child  { margin-bottom: 0 !important; }
.answer-text p  { margin: 0 0 10px; }
.answer-text h1,.answer-text h2,.answer-text h3 {
  margin: 16px 0 6px; font-weight: 700; letter-spacing: -0.2px; color: var(--text);
}
.answer-text h1 { font-size: 1.1em; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.answer-text h2 { font-size: 1.0em; }
.answer-text h3 { font-size: 0.95em; color: var(--text-muted); }
.answer-text ul { padding-left: 0; margin: 8px 0; list-style: none; }
.answer-text ul li { padding-left: 16px; position: relative; margin: 5px 0; }
.answer-text ul li::before {
  content: ""; position: absolute; left: 2px; top: 9px;
  width: 5px; height: 5px; border-radius: 50%; background: var(--primary);
}
.answer-text ol { padding-left: 20px; margin: 8px 0; }
.answer-text ol li { margin: 5px 0; }
.answer-text strong { font-weight: 700; color: var(--text); }
.answer-text em { font-style: italic; color: var(--text-muted); }
.answer-text code {
  background: #f1f5f9; border-radius: 5px;
  padding: 1px 6px; font-size: 0.87em; font-family: "SF Mono", "Fira Code", monospace;
  color: #0f172a; border: 1px solid var(--border);
}
.answer-text blockquote {
  border-left: 3px solid var(--primary);
  padding: 6px 14px; margin: 10px 0;
  background: var(--primary-light); border-radius: 0 6px 6px 0;
  color: var(--text-muted); font-style: italic;
}

/* Tabellen */
.answer-text table {
  border-collapse: collapse; width: 100%; margin: 12px 0;
  font-size: 13px; border-radius: 8px; overflow: hidden;
  box-shadow: 0 0 0 1px var(--border);
}
.answer-text thead tr { background: var(--primary); color: #fff; }
.answer-text th {
  padding: 9px 13px; text-align: left; font-weight: 600;
  font-size: 12px; letter-spacing: 0.3px; text-transform: uppercase;
}
.answer-text td {
  padding: 8px 13px; border-bottom: 1px solid var(--border-soft); vertical-align: top;
}
.answer-text tbody tr:last-child td { border-bottom: none; }
.answer-text tbody tr:nth-child(even) td { background: #f8fafc; }
.answer-text tbody tr:hover td { background: #eff6ff; transition: background .1s; }

.answer-img {
  display: block;
  max-width: 100%;
  border-radius: 10px;
  margin: 12px 0;
  box-shadow: var(--shadow-md);
}

/* ── Quellen-Badges im Text ────────────────────────────────────────────────── */
.src-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid #bfdbfe;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  padding: 0 4px;
  min-width: 16px;
  line-height: 16px;
  cursor: pointer;
  vertical-align: super;
  transition: background .12s;
  user-select: none;
}
.src-badge:hover { background: #dbeafe; }

/* ── Quellen ───────────────────────────────────────────────────────────────── */
.sources {
  margin-top: 12px;
  font-size: 12px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.sources summary {
  cursor: pointer;
  color: var(--text-muted);
  user-select: none;
  padding: 2px 0;
  font-weight: 500;
  display: flex; align-items: center; gap: 4px;
}
.sources summary:hover { color: var(--text); }
.sources[open] summary { margin-bottom: 8px; }

.source-item {
  display: grid;
  grid-template-columns: auto auto auto 1fr auto;
  gap: 6px;
  align-items: baseline;
  padding: 5px 8px;
  border-radius: 6px;
  transition: background .1s;
}
.source-item:hover { background: var(--bg); }
.source-item.source-highlight { background: #eff6ff; transition: background .1s; }
.source-num     { font-weight: 700; color: var(--text-subtle); font-size: 11px; white-space: nowrap; }
.source-ampel   {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  margin-top: 2px; box-shadow: 0 0 0 2px rgba(0,0,0,.08);
}
.source-sop     { font-weight: 600; color: var(--primary); font-size: 11px; }
.source-heading { color: var(--text-muted); font-size: 11px; }
.source-score   {
  white-space: nowrap; font-size: 11px; font-weight: 700;
}
.source-download {
  margin-left: auto;
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
  opacity: 0.6;
  transition: opacity 0.15s;
}
.source-download:hover { opacity: 1; color: var(--primary); }

/* ── Rating ────────────────────────────────────────────────────────────────── */
.rating {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  align-items: center;
}
.rating::before {
  content: "Hilfreich?";
  font-size: 11px; color: var(--text-subtle); margin-right: 2px;
}
.rate-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 12px;
  font-size: 15px;
  cursor: pointer;
  transition: all .15s;
  line-height: 1.5;
}
.rate-btn:hover { background: var(--bg); border-color: #94a3b8; transform: scale(1.05); }
.rated { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 5px; }


.loading-indicator {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.loading-dots span {
  display: inline-block; width: 6px; height: 6px;
  background: var(--primary); border-radius: 50%;
  animation: bounce .9s ease-in-out infinite;
  margin: 0 1px;
}
.loading-dots span:nth-child(2) { animation-delay: .15s; }
.loading-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%,80%,100% { transform: scale(0.7); opacity:.5; } 40% { transform: scale(1); opacity:1; } }

.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.ask-form {
  display: flex;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 6px 6px 6px 16px;
  box-shadow: var(--shadow-md);
  transition: border-color .15s, box-shadow .15s;
}
.ask-form:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1), var(--shadow-md);
}
.ask-form input {
  flex: 1;
  padding: 8px 0;
  border: none;
  background: transparent;
  font-size: 14px;
  outline: none;
  color: var(--text);
}
.ask-form input::placeholder { color: var(--text-subtle); }
.ask-form input:disabled { opacity: 0.5; }

.btn-send {
  padding: 9px 20px;
  background: var(--primary); color: #fff;
  border: none; border-radius: 10px;
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s;
  flex-shrink: 0;
}
.btn-send:hover    { background: var(--primary-h); }
.btn-send:disabled { background: #93c5fd; cursor: not-allowed; }

/* ── Admin ──────────────────────────────────────────────────────────────────── */
.main-content.admin-page {
  align-items: flex-start;
  justify-content: flex-start;
  padding: 0;
  overflow-y: auto;
}

.admin-layout {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 28px 48px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.admin-nav { display: flex; gap: 4px; }
.admin-nav-link {
  padding: 5px 14px; border-radius: 7px;
  font-size: 13px; font-weight: 500; text-decoration: none;
  color: var(--text-muted); transition: background .12s, color .12s;
}
.admin-nav-link:hover { background: var(--bg); color: var(--text); }
.admin-nav-link.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }

.admin-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 16px;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 22px;
  box-shadow: var(--shadow);
}
.stat-value { font-size: 28px; font-weight: 700; color: var(--primary); line-height: 1; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; font-weight: 500; }

.admin-section { display: flex; flex-direction: column; gap: 12px; }
.admin-section-title { font-size: 15px; font-weight: 700; color: var(--text); }

.admin-table-wrap { overflow-x: auto; border-radius: var(--radius); box-shadow: var(--shadow); }
.admin-table {
  width: 100%; border-collapse: collapse;
  background: var(--surface); font-size: 13px;
}
.admin-table thead tr { background: var(--primary); color: #fff; }
.admin-table th { padding: 10px 14px; text-align: left; font-size: 11px; font-weight: 600; letter-spacing: .3px; text-transform: uppercase; white-space: nowrap; }
.admin-table td { padding: 10px 14px; border-bottom: 1px solid var(--border-soft); vertical-align: top; }
.admin-table tbody tr:last-child td { border-bottom: none; }
.admin-table tbody tr:hover td { background: #f8fafc; }
.interaction-row:hover td { background: #eff6ff !important; cursor: pointer; }

.td-muted    { color: var(--text-muted); }
.td-nowrap   { white-space: nowrap; }
.td-center   { text-align: center; }
.td-question { max-width: 200px; }
.td-answer   { max-width: 260px; }
.td-text-clip { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.role-badge {
  display: inline-block; padding: 2px 8px; border-radius: 99px;
  font-size: 11px; font-weight: 600;
}
.role-superadmin { background: #fde8ff; color: #7e22ce; }
.role-admin      { background: #fef3c7; color: #92400e; }
.role-user       { background: var(--primary-light); color: var(--primary); }

.role-select {
  font-size: 12px; padding: 3px 6px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface);
  cursor: pointer;
}

.rating-badge { font-size: 14px; }

.detail-row td { background: #f8fafc !important; }
.detail-cell { padding: 16px 20px !important; }
.detail-content { display: flex; flex-wrap: wrap; gap: 20px; }
.detail-col { flex: 1; min-width: 220px; }
.detail-col-full { flex: 100%; }
.detail-label { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .4px; margin-bottom: 6px; }
.detail-text { font-size: 13px; color: var(--text); line-height: 1.6; white-space: pre-wrap; }

/* Admin Settings */
.settings-grid { width: 100%; max-width: 860px; }
.settings-form { display: flex; flex-direction: column; gap: 20px; }
.settings-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px 28px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 18px;
}
.settings-card-title { font-size: 14px; font-weight: 700; color: var(--text); margin-bottom: 2px; }
.settings-label {
  display: flex; flex-direction: column; gap: 5px;
  font-size: 13px; font-weight: 600; color: var(--text);
}
.settings-input {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 9px;
  font-size: 14px; outline: none; background: var(--surface); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.settings-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.settings-input-sm { max-width: 140px; }
.settings-hint { font-size: 11px; color: var(--text-muted); font-weight: 400; }
.settings-actions { padding-top: 4px; }

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .chat-sidebar { width: 200px; }
}
@media (max-width: 600px) {
  .msg-bubble { max-width: 88%; }
  .auth-card  { padding: 28px 24px; }
  .chat-sidebar { display: none; }
  .chat-history, .chat-input-area { padding-left: 12px; padding-right: 12px; }
}
