* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica Neue, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
/* Nur auf der Chat-Seite: globale Scrollbar aus */
body.chat-page { overflow: hidden; }

/* ---------- Topbar ---------- */
.top {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 50;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.top-left, .top-right { display: flex; align-items: center; gap: 8px; }
.top-center { position: absolute; left: 50%; transform: translateX(-50%); }
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 700; font-size: 16px; }
.brand .logo { font-size: 20px; }
.pill { display: inline-flex; align-items: center; gap: 6px; background: var(--card); border: 1px solid var(--border); color: var(--muted); padding: 6px 10px; border-radius: 999px; font-size: 12px; }
.select { border: 1px solid var(--border); background: var(--card); color: var(--text); padding: 6px 10px; border-radius: 8px; }
.btn { border: 1px solid var(--border); background: var(--card); color: var(--text); padding: 8px 12px; border-radius: 10px; cursor: pointer; text-decoration: none; display: inline-block; text-align: center; }
.btn:hover { opacity: 0.9; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-600); border-color: var(--primary-600); }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(1px, 1px, 1px, 1px); }

/* ---------- Bottombar ---------- */
.bottom {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 40;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.bottom .link { color: var(--text); text-decoration: none; }
.bottom .link:hover { text-decoration: underline; }

/* ---------- Seiten-Inhalt (dynamische Abstände zu Bars) ---------- */
.page-content {
  padding-top: var(--topbar-h, 64px);
  padding-bottom: var(--bottombar-h, 56px);
}

/* ---------- Chat + Sidebar (zentriert, fixe Höhe, interne Scrolls) ---------- */
:root{
  --space-v: 25px;
  --chat-gap: 10px;
  --sidebar-w: 300px;
  --content-max: 1400px;
  --content-pad: 16px;
}
.chat-container {
  width: min(var(--content-max), calc(100% - (var(--content-pad) * 2)));
  margin: 0 auto;                 /* horizontal zentriert */
  padding: var(--space-v) var(--content-pad); /* 25px oben/unten als Padding */
  display: flex;
  gap: var(--chat-gap);
  /* Höhe = Viewport minus Bars; padding ist durch border-box inkludiert */
  height: calc(100vh - var(--topbar-h, 64px) - var(--bottombar-h, 56px));
  align-items: stretch;
  box-sizing: border-box;
  overflow: hidden;               /* Seite bleibt ohne Scrollbar */
}
.chat-container main { flex: 1; min-width: 0; }

/* Sidebar: eigener Scroll */
.sidebar {
  width: var(--sidebar-w);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  overflow-y: auto;
  height: 100%;
}
.sidebar-header { padding: 10px; }
.chat-list { flex: 1; margin: 0; padding: 0 10px; list-style: none; overflow-y: auto; }
.chat-entry { display: flex; align-items: center; justify-content: space-between; padding: 4px 0; }
.chat-entry.active { background: var(--chip); border-radius: 8px; padding: 6px 8px; }
.chat-entry a { color: var(--text); text-decoration: none; }
.chat-entry a:hover { text-decoration: underline; }
.icon-btn { background: none; border: none; color: var(--muted); cursor: pointer; padding: 4px; }
.icon-btn:hover { opacity: 0.7; }
.sidebar-footer { border-top: 1px solid var(--border); padding: 10px; text-align: center; }
.sidebar-footer a { color: var(--text); text-decoration: none; }
.sidebar-footer a:hover { text-decoration: underline; }

/* Chat: interner Scroll im Body */
.chatbar {
  margin: 0;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  height: 100%;
  display: flex; flex-direction: column;
  overflow: hidden; /* nur Body scrollt */
}
.chat-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.chat-title { font-weight: 600; font-size: 14px; }
.mini { font-size: 12px; color: var(--muted); margin-top: 4px; }
.chat-body { padding: 12px; overflow-y: auto; flex: 1; }
.chat-input { border-top: 1px solid var(--border); padding: 10px 12px; display: flex; gap: 8px; }
.input { flex: 1; min-width: 200px; font-size: 15px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--card); color: var(--text); }

/* Avatare */
.msg { display: flex; gap: 10px; margin-bottom: 10px; align-items: flex-start; }
.av { width: 38px; height: 38px; display: flex; align-items: center; justify-content: center; border-radius: 0; background: transparent; color: inherit; font-size: 32px; flex: 0 0 38px; }
.av-img{width:100%;height:100%;object-fit:contain;display:block;border-radius:0 !important}
.msg.assistant .av { background: transparent; color: inherit; }

/* Bubbles & Quellen */
.bubble { background: #f8fafc; border: 1px solid var(--border); padding: 10px 12px; border-radius: 12px; }
.msg.user .bubble { background: #eff6ff; border-color: #bfdbfe; }
.ans-meta{font-size:12px;color:var(--muted);margin-top:6px}
.sources { margin-top: 8px; }
.sources a { color: var(--primary); text-decoration: none; }
.sources a:hover { text-decoration: underline; }
.sources-group { margin-top: 10px; padding: 10px; border: 1px dashed var(--border); border-radius: 10px; }
.sources-group h4 { margin: 0 0 6px; font-size: 13px; color: var(--muted); }
.sources-group ol { margin: 0 0 0 18px; }
.hidden-source { display: none; }
.conf { color: var(--muted); font-size: 12px; margin-left: 6px; }

/* Busy/Thinking */
.thinking{ display:flex; align-items:center; gap:8px; padding:6px 0; }
.chat-spin{ width:18px; height:18px; border:2px solid var(--border); border-top-color:var(--primary); border-radius:50%; display:inline-block; vertical-align:middle; animation:chat-spin .8s linear infinite; }
@keyframes chat-spin{ to{ transform:rotate(360deg) } }

/* Hero (Startseite) */
.hero { min-height: 100vh; display: grid; place-items: center; padding: 80px 16px; }
.hero-title { font-size: clamp(36px, 7vw, 64px); margin: 0 0 24px 0; display: flex; align-items: center; gap: 16px; }
.hero-actions { display: flex; gap: 12px; justify-content: center; }

/* Theme Variablen */
:root {
  --bg: #f7fafc; --card: #ffffff; --text: #111827; --muted: #6b7280; --border: #e5e7eb;
  --primary: #2563eb; --primary-600: #1d4ed8; --chip: #eef2ff; --shadow: 0 10px 30px rgba(2,6,23,0.04);
}

/* Responsive */
@media(max-width: 767px) {
  .sidebar {
    display: none;
    position: fixed;
    left: 16px; right: 16px;
    top: calc(var(--topbar-h, 64px) + 25px);
    bottom: calc(var(--bottombar-h, 56px) + 25px);
    border-radius: 16px;
    box-shadow: var(--shadow);
    z-index: 45;
  }
  .sidebar.open { display: flex; }

  .chat-container { width: calc(100% - 32px); }
}
