*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --bg2: #1a1d27;
  --bg3: #222636;
  --border: #2e3347;
  --accent: #e63e1c;
  --accent2: #ff6b47;
  --text: #e8eaf0;
  --text2: #8b90a7;
  --text3: #5c6178;
  --user-bg: #1e2a3a;
  --bot-bg: #1a1d27;
  --radius: 12px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.layout {
  display: flex;
  height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  font-size: 28px;
  line-height: 1;
}

.logo-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.02em;
}

.logo-sub {
  font-size: 11px;
  color: var(--text3);
  margin-top: 2px;
}

.sidebar-section {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text3);
  margin-bottom: 10px;
}

/* Upload */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 20px 12px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--accent);
  background: rgba(230, 62, 28, 0.05);
}

.upload-icon { font-size: 22px; margin-bottom: 6px; }
.upload-text { font-size: 13px; font-weight: 600; color: var(--text2); }
.upload-hint { font-size: 11px; color: var(--text3); margin-top: 3px; }

.uploaded-files { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }

.file-chip {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text2);
}

.file-chip .file-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-chip .file-id {
  font-size: 10px;
  color: var(--text3);
  font-family: monospace;
}

/* Examples */
.example-list { display: flex; flex-direction: column; gap: 6px; }

.example-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  color: var(--text2);
  text-align: left;
  cursor: pointer;
  transition: all 0.15s;
  line-height: 1.4;
}

.example-btn:hover {
  border-color: var(--accent);
  color: var(--text);
  background: var(--bg);
}

.sidebar-footer {
  margin-top: auto;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-clear {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text3);
  font-size: 12px;
  padding: 7px 12px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
}

.btn-clear:hover { border-color: var(--accent); color: var(--accent); }

.counter-status {
  font-size: 11px;
  color: var(--text3);
  padding: 0 2px;
}

/* ── Main ── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
}

.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Welcome */
.welcome {
  max-width: 640px;
  margin: 40px auto;
  text-align: center;
  color: var(--text2);
}

.welcome-icon { font-size: 48px; margin-bottom: 16px; }
.welcome h2 { font-size: 22px; font-weight: 700; color: var(--text); margin-bottom: 12px; }
.welcome p { font-size: 14px; line-height: 1.7; margin-bottom: 8px; }

/* Messages */
.msg {
  display: flex;
  gap: 12px;
  max-width: 900px;
  width: 100%;
}

.msg.user { flex-direction: row-reverse; margin-left: auto; }

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  margin-top: 2px;
}

.msg.user .msg-avatar { background: var(--accent); }
.msg.bot .msg-avatar { background: var(--bg3); border: 1px solid var(--border); }

.msg-bubble {
  background: var(--bot-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  font-size: 14px;
  line-height: 1.7;
  max-width: calc(100% - 44px);
}

.msg.user .msg-bubble {
  background: var(--user-bg);
  border-color: #2a3d57;
}

/* Markdown im Bot-Bubble */
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 {
  color: var(--text);
  margin: 16px 0 8px;
  font-weight: 700;
}
.msg-bubble h1 { font-size: 18px; }
.msg-bubble h2 { font-size: 16px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.msg-bubble h3 { font-size: 14px; color: var(--accent2); }

.msg-bubble p { margin-bottom: 8px; }
.msg-bubble ul, .msg-bubble ol { padding-left: 20px; margin-bottom: 8px; }
.msg-bubble li { margin-bottom: 4px; }

.msg-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 13px;
}
.msg-bubble th {
  background: var(--bg3);
  color: var(--text);
  padding: 8px 12px;
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid var(--accent);
}
.msg-bubble td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text2);
}
.msg-bubble tr:hover td { background: rgba(255,255,255,0.02); }

.msg-bubble code {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
}

.msg-bubble pre {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  margin: 8px 0;
}
.msg-bubble pre code { background: none; border: none; padding: 0; }

.msg-bubble strong { color: var(--text); font-weight: 600; }
.msg-bubble blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  color: var(--text2);
  margin: 8px 0;
  font-style: italic;
}

/* Tool-Call-Indicator */
.tool-indicator {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  color: var(--text3);
  margin-bottom: 4px;
  max-width: 680px;
}

.tool-indicator .tool-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
  margin-top: 2px;
}

.tool-indicator .tool-body { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.tool-indicator .tool-name { color: var(--accent2); font-weight: 600; font-family: monospace; }

.sql-details { margin-top: 4px; }
.sql-details summary {
  cursor: pointer;
  font-size: 11px;
  color: var(--accent2);
  user-select: none;
  opacity: 0.8;
}
.sql-details summary:hover { opacity: 1; }
.sql-pre {
  margin-top: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 11px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  color: var(--text2);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 200px;
  overflow-y: auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Thinking indicator */
.thinking-msg {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.thinking-dots {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 14px 18px;
  background: var(--bot-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.thinking-dots span {
  width: 6px;
  height: 6px;
  background: var(--text3);
  border-radius: 50%;
  animation: bounce 1.2s ease-in-out infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.8); opacity: 0.4; }
  40% { transform: scale(1.2); opacity: 1; }
}

/* Input */
.input-area {
  padding: 16px 32px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.input-wrapper {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

#chatInput {
  flex: 1;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  padding: 12px 16px;
  resize: none;
  outline: none;
  transition: border-color 0.2s;
  max-height: 180px;
  overflow-y: auto;
}

#chatInput:focus { border-color: var(--accent); }
#chatInput::placeholder { color: var(--text3); }

.send-btn {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--accent);
  border: none;
  color: white;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.send-btn:hover { background: var(--accent2); transform: scale(1.05); }
.send-btn:disabled { background: var(--bg3); color: var(--text3); cursor: not-allowed; transform: none; }

.input-hint {
  font-size: 11px;
  color: var(--text3);
  margin-top: 6px;
  padding-left: 2px;
}

/* Loading spinner in send button */
.btn-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ── Thesen-System ─────────────────────────────────────────────────────────── */
.thesen-wrap {
  max-width: 900px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.thesen-header {
  padding: 16px 20px;
  background: linear-gradient(135deg, var(--bg2), var(--bg3));
  border: 1px solid var(--accent);
  border-radius: var(--radius);
}

.thesen-title { font-size: 16px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.thesen-subtitle { font-size: 12px; color: var(--text2); }

.thesen-list { display: flex; flex-direction: column; gap: 10px; }

.these-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.2s;
}

.these-card.status-approved { border-color: #22c55e; background: rgba(34,197,94,0.04); }
.these-card.status-rejected { border-color: #ef4444; background: rgba(239,68,68,0.04); opacity: 0.6; }
.these-card.refining { opacity: 0.7; pointer-events: none; }

.these-top {
  display: flex;
  gap: 12px;
  padding: 14px 16px;
  align-items: flex-start;
}

.these-num {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.status-approved .these-num { background: #22c55e; }
.status-rejected .these-num { background: #ef4444; }

.these-content { flex: 1; min-width: 0; }
.diese-titel { font-size: 14px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.diese-text { font-size: 13px; color: var(--text2); line-height: 1.6; margin-bottom: 8px; }

.diese-tabelle { font-size: 12px; margin: 8px 0; overflow-x: auto; }
.diese-tabelle table { width: auto; }
.diese-tabelle th { font-size: 11px; padding: 5px 10px; }
.diese-tabelle td { font-size: 11px; padding: 4px 10px; }

.diese-quelle {
  font-size: 11px;
  color: var(--text3);
  font-style: italic;
  margin-top: 6px;
}

.these-btns {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.btn-approve, .btn-reject, .btn-refine {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text3);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.btn-approve:hover, .btn-approve.active { background: #22c55e; border-color: #22c55e; color: white; }
.btn-reject:hover, .btn-reject.active  { background: #ef4444; border-color: #ef4444; color: white; }
.btn-refine:hover { background: var(--accent); border-color: var(--accent); color: white; }

.refine-area {
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: var(--bg3);
}

.refine-input {
  flex: 1;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  padding: 8px 12px;
  resize: none;
  outline: none;
  min-height: 60px;
}
.refine-input:focus { border-color: var(--accent); }

.btn-refine-send {
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 13px;
  padding: 8px 14px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-refine-send:hover { background: var(--accent2); }

.thesen-actions {
  display: flex;
  gap: 10px;
  padding: 4px 0;
}

.btn-approve-all {
  background: #22c55e;
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 13px;
  font-weight: 600;
  padding: 10px 18px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-approve-all:hover { opacity: 0.85; }

.btn-pdf {
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 13px;
  font-weight: 600;
  padding: 10px 18px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-pdf:hover { opacity: 0.85; }
.btn-pdf:disabled { opacity: 0.5; cursor: not-allowed; }
