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

:root {
  --accent:       #4f6ef7;
  --accent-dark:  #3a56d4;
  --accent-light: #eef1fe;
  --bg:           #f5f6fa;
  --surface:      #ffffff;
  --sidebar-bg:   #1a1d2e;
  --sidebar-text: #c8cce0;
  --sidebar-muted:#6b7094;
  --text:         #1c1f36;
  --text-muted:   #7a7d96;
  --border:       #e4e6f0;
  --user-bubble:  #4f6ef7;
  --bot-bubble:   #ffffff;
  --shadow:       0 2px 16px rgba(79,110,247,.10);
  --radius:       14px;
  --sidebar-w:    270px;
}

html, body { height: 100%; font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); }

/* ── Layout ───────────────────────────────────────────────── */
body { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

/* Sidebar-Backdrop (nur Mobile sichtbar) */
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 90;
  -webkit-tap-highlight-color: transparent;
}
.sidebar-backdrop.active { display: block; }

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
  transition: transform .3s ease;
  flex-shrink: 0;
}

.sidebar-header { padding: 0 18px 20px; border-bottom: 1px solid #2d3050; }

.logo { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.logo-icon {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #7c8ff5);
  color: #fff; font-weight: 700; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
}
.logo-text { color: #fff; font-weight: 600; font-size: 15px; }

.new-chat-btn {
  width: 100%; padding: 9px 14px; border-radius: 8px;
  border: 1px dashed #3d4165; background: transparent;
  color: var(--sidebar-text); font-size: 13px; cursor: pointer;
  transition: background .2s, border-color .2s;
}
.new-chat-btn:hover { background: #2d3050; border-color: var(--accent); }

.sidebar-section { padding: 16px 18px 0; }
.sidebar-label { font-size: 11px; font-weight: 600; color: var(--sidebar-muted); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 10px; }

/* Doc list */
.doc-list { list-style: none; display: flex; flex-direction: column; gap: 4px; }
.doc-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px; cursor: default;
  transition: background .2s;
}
.doc-item:hover { background: #2d3050; }
.doc-icon { font-size: 15px; flex-shrink: 0; }
.doc-info { display: flex; flex-direction: column; }
.doc-name { color: var(--sidebar-text); font-size: 12.5px; font-weight: 500; }
.doc-pages { color: var(--sidebar-muted); font-size: 11px; }

/* History list */
.history-list { list-style: none; display: flex; flex-direction: column; gap: 2px; }
.history-item {
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
  color: var(--sidebar-text); font-size: 12.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background .2s;
}
.history-item:hover { background: #2d3050; }

/* ── Main ─────────────────────────────────────────────────── */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* Topbar */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 24px; background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.menu-btn { display: none; background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-muted); }
.topbar-title { font-weight: 600; font-size: 15px; flex: 1; }
.topbar-badge {
  font-size: 11px; font-weight: 600; padding: 3px 10px;
  border-radius: 20px; background: var(--accent-light); color: var(--accent);
}

/* Chat area */
.chat-area {
  flex: 1; overflow-y: auto; padding: 24px;
  display: flex; flex-direction: column;
  scroll-behavior: smooth;
}

/* Welcome */
.welcome {
  margin: auto;
  text-align: center;
  max-width: 540px;
  padding: 40px 0;
}
.welcome-avatar { font-size: 52px; margin-bottom: 16px; }
.welcome-title { font-size: 26px; font-weight: 700; margin-bottom: 8px; }
.welcome-sub { color: var(--text-muted); font-size: 14px; margin-bottom: 32px; }

.suggestions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.suggestion-btn {
  padding: 10px 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 13px; cursor: pointer;
  transition: border-color .2s, box-shadow .2s, background .2s;
  text-align: left;
}
.suggestion-btn:hover { border-color: var(--accent); background: var(--accent-light); box-shadow: var(--shadow); }

/* Messages */
.messages { display: flex; flex-direction: column; gap: 20px; max-width: 780px; width: 100%; margin: 0 auto; }

.message { display: flex; gap: 12px; align-items: flex-start; animation: fadeUp .25s ease; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.message.user { flex-direction: row-reverse; }

.avatar {
  width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700;
}
.avatar.user { background: linear-gradient(135deg, var(--accent), #7c8ff5); color: #fff; font-size: 13px; }
.avatar.bot  { background: var(--accent-light); color: var(--accent); }

.bubble {
  max-width: 72%; padding: 12px 16px; border-radius: var(--radius);
  font-size: 14px; line-height: 1.65; box-shadow: var(--shadow);
}
.message.user .bubble {
  background: var(--user-bubble);
  color: #fff;
  border-top-right-radius: 4px;
}
.message.bot .bubble {
  background: var(--bot-bubble);
  color: var(--text);
  border-top-left-radius: 4px;
  border: 1px solid var(--border);
}

/* Tool indicator */
.tool-indicator {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--text-muted);
  padding: 4px 0;
}
.tool-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }

/* Sources block */
.sources {
  margin-top: 14px; padding: 12px 14px;
  background: var(--accent-light); border-radius: 10px;
  border-left: 3px solid var(--accent);
  font-size: 12.5px; line-height: 1.7;
}
.sources strong { color: var(--accent); display: block; margin-bottom: 8px; font-size: 13px; }
.source-row { margin-bottom: 4px; }
.source-link {
  display: inline-flex; align-items: flex-start; gap: 6px;
  color: var(--accent); text-decoration: none;
  padding: 4px 8px; border-radius: 6px;
  transition: background .15s;
}
.source-link:hover { background: rgba(79,110,247,.12); text-decoration: underline; }
.src-icon  { flex-shrink: 0; }
.src-text  { font-size: 12.5px; }
.src-path  {
  display: block; font-size: 10.5px; color: var(--text-muted);
  font-family: 'Cascadia Code', 'Consolas', monospace;
  margin-top: 1px; word-break: break-all;
}

/* Markdown-rendered content */
.bubble-content p  { margin-bottom: 10px; }
.bubble-content p:last-child { margin-bottom: 0; }
.bubble-content ol,
.bubble-content ul  { padding-left: 20px; margin-bottom: 10px; }
.bubble-content li  { margin-bottom: 6px; line-height: 1.6; }
.bubble-content strong { font-weight: 600; }
.bubble-content em { font-style: italic; }

/* Typing cursor */
.cursor { display: inline-block; width: 2px; height: 14px; background: var(--accent); margin-left: 2px; vertical-align: middle; animation: blink .7s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ── Input area ───────────────────────────────────────────── */
.input-area {
  padding: 16px 24px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.input-box {
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--bg); border: 1.5px solid var(--border);
  border-radius: var(--radius); padding: 10px 10px 10px 16px;
  transition: border-color .2s, box-shadow .2s;
  max-width: 780px; margin: 0 auto;
}
.input-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,110,247,.12); }

.input-field {
  flex: 1; border: none; background: transparent; resize: none;
  font-size: 14px; font-family: inherit; color: var(--text);
  max-height: 140px; outline: none; line-height: 1.5;
}
.input-field::placeholder { color: var(--text-muted); }

.send-btn {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  background: var(--accent); border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .2s, transform .1s;
  color: #fff;
}
.send-btn:hover { background: var(--accent-dark); }
.send-btn:active { transform: scale(.95); }
.send-btn:disabled { background: var(--border); cursor: not-allowed; }
.send-btn svg { width: 17px; height: 17px; }

.input-hint { font-size: 11px; color: var(--text-muted); text-align: center; margin-top: 10px; max-width: 780px; margin-left: auto; margin-right: auto; }

/* ── Scrollbar ────────────────────────────────────────────── */
.chat-area::-webkit-scrollbar { width: 5px; }
.chat-area::-webkit-scrollbar-track { background: transparent; }
.chat-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 700px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    z-index: 100; transform: translateX(-100%);
    width: min(85vw, var(--sidebar-w));
    box-shadow: 4px 0 24px rgba(0,0,0,.25);
  }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: block; }
  .bubble { max-width: 88%; }

  .topbar { padding: 12px 16px; }
  .chat-area { padding: 16px; }
  .input-area { padding: 10px 12px 14px; }
  .input-box { padding: 8px 8px 8px 14px; }

  /* Welcome auf Mobile kompakter, damit nichts abgeschnitten wird */
  .welcome { padding: 20px 0; }
  .welcome-avatar { font-size: 40px; margin-bottom: 10px; }
  .welcome-title { font-size: 20px; }
  .welcome-sub { font-size: 13px; margin-bottom: 20px; }
}
