:root {
  --bg: #0d1117;
  --bg-panel: #131a24;
  --bg-card: #1a2332;
  --bg-input: #1e2a3a;
  --border: #2a3a4e;
  --accent: #4a9ebb;
  --accent-glow: rgba(74,158,187,0.15);
  --accent-warm: #d4956a;
  --text-primary: #e8dcc8;
  --text-secondary: #9aacbe;
  --text-muted: #5a7090;
  --user-bg: #1e3a2e;
  --user-border: #2d5a44;
  --error: #c0392b;
  --success: #27ae60;
}

body.light {
  --bg: #f5f0e8;
  --bg-panel: #ede8de;
  --bg-card: #e8e2d6;
  --bg-input: #ddd8cc;
  --border: #c8c0b0;
  --accent: #2e7da8;
  --accent-glow: rgba(46,125,168,0.12);
  --accent-warm: #a0622a;
  --text-primary: #2a2018;
  --text-secondary: #5a5040;
  --text-muted: #8a8070;
  --user-bg: #d8eedd;
  --user-border: #a8ccb0;
}

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

body {
  font-family: 'Source Sans 3', sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header ── */
header {
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.logo { display: flex; align-items: center; gap: 12px; }
.logo-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--accent), #2d7a9a);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.logo-text { font-family: 'Lora', serif; font-size: 18px; font-weight: 600; }
.logo-sub { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; }

/* Navigation Tabs */
.nav-tabs { display: flex; gap: 4px; background: var(--bg); padding: 4px; border-radius: 10px; border: 1px solid var(--border); }
.nav-tab {
  background: transparent; border: none; color: var(--text-secondary);
  padding: 6px 14px; border-radius: 7px; font-family: inherit; font-size: 13px;
  cursor: pointer; transition: all 0.2s;
}
.nav-tab.active, .nav-tab:hover { background: var(--bg-card); color: var(--text-primary); }

/* Controls */
.header-controls { display: flex; align-items: center; gap: 12px; }
.target-group-toggle { display: flex; background: var(--bg-input); border-radius: 8px; border: 1px solid var(--border); padding: 2px; }
.target-group-toggle button {
  background: transparent; border: none; color: var(--text-muted);
  padding: 4px 10px; font-size: 12px; cursor: pointer; border-radius: 6px; transition: all 0.2s;
}
.target-group-toggle button.active { background: var(--accent); color: white; font-weight: 600; }

.theme-toggle { background: transparent; border: 1px solid var(--border); color: var(--text-primary); border-radius: 8px; padding: 5px 8px; cursor: pointer; }
.status-indicator { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.status-dot.online { background: var(--success); box-shadow: 0 0 6px var(--success); }

/* ── Reset-Button Styling ── */
.btn-reset {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12px;
  padding: 5px 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn-reset:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-glow);
  transform: translateY(-1px);
}

.btn-reset:active {
  transform: translateY(0);
}

/* ── Container & Tabs ── */
.app-container { flex: 1; overflow: hidden; position: relative; }
.tab-content { display: none; height: 100%; flex-direction: column; padding: 24px; max-width: 900px; margin: 0 auto; }
.tab-content.active { display: flex; }

/* Welcome Screen */
.welcome-card { text-align: center; margin: auto; max-width: 500px; }
.welcome-icon { font-size: 48px; margin-bottom: 12px; }
.welcome-card h2 { font-family: 'Lora', serif; margin-bottom: 8px; }
.welcome-card p { font-size: 14px; color: var(--text-secondary); margin-bottom: 20px; line-height: 1.5; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.suggestions button {
  background: var(--bg-card); border: 1px solid var(--border); color: var(--text-secondary);
  padding: 8px 12px; border-radius: 20px; font-size: 12px; cursor: pointer; transition: all 0.2s;
}
.suggestions button:hover { border-color: var(--accent); color: var(--accent); }

/* Chat Messages */
.chat-messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; padding-bottom: 16px; }
.message { display: flex; gap: 12px; max-width: 80%; }
.message.user { align-self: flex-end; flex-direction: row-reverse; }
.avatar { width: 32px; height: 32px; border-radius: 8px; display: flex; align-items: center; justify-content: center; background: var(--bg-card); border: 1px solid var(--border); flex-shrink: 0; }
.message.assistant .avatar { background: linear-gradient(135deg, var(--accent), #2d7a9a); color: white; }
.bubble { background: var(--bg-card); border: 1px solid var(--border); padding: 12px 16px; border-radius: 12px; font-size: 14px; line-height: 1.6; }
.message.user .bubble { background: var(--user-bg); border-color: var(--user-border); }

/* Input Area */
.input-container { display: flex; gap: 8px; background: var(--bg-panel); padding: 12px; border-radius: 12px; border: 1px solid var(--border); margin-top: auto; }
textarea { flex: 1; background: var(--bg-input); border: 1px solid var(--border); border-radius: 8px; padding: 10px; color: var(--text-primary); font-family: inherit; font-size: 14px; resize: none; outline: none; }
textarea:focus { border-color: var(--accent); }
.btn-send { background: var(--accent); border: none; color: white; width: 42px; border-radius: 8px; cursor: pointer; font-size: 16px; }

/* Tool Views */
.tool-header { margin-bottom: 20px; }
.tool-header h2 { font-family: 'Lora', serif; font-size: 20px; margin-bottom: 4px; }
.tool-header p { font-size: 13px; color: var(--text-secondary); }

.med-list-builder { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.med-row { display: flex; gap: 8px; }
.med-row input { flex: 1; background: var(--bg-input); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; color: var(--text-primary); font-family: inherit; }
.btn-remove { background: transparent; border: 1px solid var(--border); color: var(--error); border-radius: 8px; width: 36px; cursor: pointer; }

.tool-actions { display: flex; gap: 12px; margin-bottom: 20px; }
.btn-primary { background: var(--accent); color: white; border: none; padding: 10px 18px; border-radius: 8px; font-family: inherit; font-weight: 600; cursor: pointer; }
.btn-secondary { background: transparent; border: 1px solid var(--border); color: var(--text-primary); padding: 10px 18px; border-radius: 8px; font-family: inherit; cursor: pointer; }

.tool-output { flex: 1; overflow-y: auto; background: var(--bg-panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px; min-height: 150px; }

.or-divider { text-align: center; font-size: 11px; color: var(--text-muted); margin: 12px 0; }

/* Markdown-Tabellen Styles */
.tool-output table {
  width: 100%;
  border-collapse: collapse;
  margin: 15px 0;
  font-size: 14px;
}

.tool-output th, .tool-output td {
  border: 1px solid #e2e8f0;
  padding: 10px 12px;
  text-align: left;
}

.tool-output th {
  background-color: #f8fafc;
  font-weight: 600;
  color: #1e293b;
}

.tool-output tr:nth-child(even) {
  background-color: #f9fbfd;
}

/* Headings im Output */
.tool-output h3 {
  margin-top: 20px;
  margin-bottom: 8px;
  color: #0f172a;
}

.disclaimer-box {
  background-color: #fffbeb;
  border-left: 4px solid #f59e0b;
  padding: 12px 16px;
  margin-bottom: 20px;
  font-size: 0.95rem;
  color: #78350f;
  line-height: 1.5;
}

.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin-bottom: 25px;
}

.custom-checkbox {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1.4;
}

.custom-checkbox input[type="checkbox"] {
  margin-top: 3px;
  width: 18px;
  height: 18px;
  accent-color: #0ea5e9;
}

.disclaimer-box {
  background-color: #fffbeb;
  border-left: 4px solid #f59e0b;
  padding: 12px 16px;
  margin-bottom: 20px;
  font-size: 0.95rem;
  color: #78350f;
  line-height: 1.5;
}

.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin-bottom: 25px;
}

.custom-checkbox {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1.4;
}

.custom-checkbox input[type="checkbox"] {
  margin-top: 3px;
  width: 18px;
  height: 18px;
  accent-color: #0ea5e9;
}

/* ── Tool Action Bar unter Ergebnissen ── */
.tool-action-bar {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.btn-sm {
  font-size: 12px !important;
  padding: 6px 12px !important;
}

/* ── Drop Zone / File Upload ── */
.upload-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 24px;
  text-align: center;
  background: var(--bg-panel);
  cursor: pointer;
  transition: all 0.2s ease;
}

.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-glow);
}

.drop-zone-icon {
  font-size: 32px;
  margin-bottom: 8px;
}

.drop-zone-text {
  font-size: 14px;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.drop-zone-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.drop-zone.has-file {
  border-color: var(--success);
  background: rgba(39, 174, 96, 0.1);
}

/* ── Permanent Footer ── */
.app-footer {
  margin-top: 40px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
  font-size: 12px;
  color: var(--text-muted);
}

.footer-content {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.footer-links {
  display: flex;
  align-items: center;
  gap: 8px;
}

.footer-links a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.2s;
}

.footer-links a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.sep {
  color: var(--border);
}

/* ── Modal Overlays ── */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 540px;
  padding: 24px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.3);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.legal-card {
  max-width: 720px;
  max-height: 80vh;
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
}

.modal-header h2 {
  font-size: 18px;
  margin: 0;
}

.modal-icon {
  font-size: 28px;
}

.btn-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
}

.legal-notice-box {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin: 12px 0;
}

.legal-notice-box h4 {
  margin: 0 0 8px 0;
  font-size: 13px;
  color: var(--accent);
}

.checkbox-label {
  display: flex;
  gap: 10px;
  font-size: 12px;
  color: var(--text-primary);
  line-height: 1.4;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  margin-top: 2px;
  accent-color: var(--accent);
}

.modal-intro {
  font-size: 13px;
  color: var(--text-secondary);
}

.modal-subtext {
  font-size: 11px;
  color: var(--text-muted);
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.legal-text-content {
  overflow-y: auto;
  max-height: 60vh;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-primary);
}

/* ── Über Medi Seite Styling ── */
.about-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  max-width: 850px;
  margin: 0 auto;
  box-shadow: 0 4px 20px rgba(0,0,0,0.05);
}

.about-header {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.about-avatar {
  font-size: 48px;
  background: var(--accent-glow);
  width: 80px;
  height: 80px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--accent);
}

.about-header h2 {
  margin: 0 0 4px 0;
  font-size: 24px;
}

.about-subtitle {
  color: var(--text-muted);
  margin: 0;
  font-size: 14px;
}

.about-body h3 {
  font-size: 16px;
  color: var(--accent);
  margin: 24px 0 12px 0;
}

.about-body p {
  line-height: 1.6;
  color: var(--text-primary);
  font-size: 14px;
}

.about-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 24px 0;
}

@media (max-width: 650px) {
  .about-grid {
    grid-template-columns: 1fr;
  }
}

.about-box {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.about-box h4 {
  margin: 0 0 12px 0;
  font-size: 14px;
}

.danger-box {
  border-color: rgba(231, 76, 60, 0.3);
  background: rgba(231, 76, 60, 0.03);
}

.about-box ul {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.6;
}

.about-box li {
  margin-bottom: 8px;
}

.about-closing {
  font-weight: 500;
  color: var(--accent);
  text-align: center;
  margin-top: 24px !important;
}

/* Eingabefeld über die volle Breite ziehen */
#brief-raw-input {
  width: 100%;
  box-sizing: border-border-box;
  min-height: 180px;
  resize: vertical;
  font-family: inherit;
  font-size: 14px;
  padding: 12px;
}

/* Status & Error Chips */
.status-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--accent); }
.spin { animation: spin 1s linear infinite; display: inline-block; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.error-msg { color: var(--error); font-size: 13px; margin-top: 8px; }

/* Quellen Area */
.quellen-container { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); font-size: 11px; }
.quellen-title { color: var(--text-muted); margin-bottom: 6px; letter-spacing: 0.5px; }
.quelle-item { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.quelle-item .badge { background: var(--accent-glow); color: var(--accent); padding: 1px 6px; border-radius: 4px; }
.quelle-item .titel { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-secondary); }
.quelle-item .score { color: var(--text-muted); }

/* Footer */
footer { background: var(--bg-panel); border-top: 1px solid var(--border); padding: 8px; text-align: center; font-size: 11px; color: var(--text-muted); flex-shrink: 0; }