/* ------------------------------------------------------------
   Theme tokens (DRK-ish): red accent, neutral surfaces
   ------------------------------------------------------------ */
:root {
  --accent: #c8102e;          /* DRK red-ish */
  --accent-2: #a10d24;
  --radius: 16px;

  /* Dark defaults */
  --bg: #0b1220;
  --bg2: #0f1a2e;
  --panel: rgba(255,255,255,0.06);
  --panel2: rgba(255,255,255,0.08);
  --border: rgba(255,255,255,0.12);
  --text: rgba(255,255,255,0.92);
  --muted: rgba(255,255,255,0.62);
  --shadow: 0 12px 40px rgba(0,0,0,0.35);

  --userBubble: color-mix(in srgb, var(--accent), black 55%);
  --userBorder: rgba(200, 16, 46, 0.45);
  --botBubble: rgba(255,255,255,0.08);

  --dangerBg: rgba(255, 91, 91, 0.12);
  --dangerBorder: rgba(255, 91, 91, 0.40);
}

/* Light theme override */
[data-theme="light"] {
  --bg: #f6f7fb;
  --bg2: #ffffff;
  --panel: rgba(0,0,0,0.03);
  --panel2: rgba(0,0,0,0.04);
  --border: rgba(0,0,0,0.10);
  --text: rgba(0,0,0,0.88);
  --muted: rgba(0,0,0,0.55);
  --shadow: 0 14px 40px rgba(0,0,0,0.12);

  --userBubble: color-mix(in srgb, var(--accent), white 75%);
  --userBorder: rgba(200, 16, 46, 0.35);
  --botBubble: rgba(0,0,0,0.04);

  --dangerBg: rgba(255, 91, 91, 0.10);
  --dangerBorder: rgba(255, 91, 91, 0.30);
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Arial, sans-serif;
  background: radial-gradient(1200px 800px at 18% 10%, color-mix(in srgb, var(--accent), transparent 85%), var(--bg));
  color: var(--text);
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.app {
  width: min(980px, 100%);
  /*height: min(820px, 100%);*/
  height: min(880px, 96vh);
  background: color-mix(in srgb, var(--bg2), transparent 0%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow);
}

header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: color-mix(in srgb, var(--bg2), transparent 0%);
}

header .title {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

header h1 {
  font-size: 16px;
  margin: 0;
  letter-spacing: 0.2px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  font-size: 12px;
  color: var(--muted);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--accent);
}

header .sub {
  font-size: 12px;
  color: var(--muted);
}

header .actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

button {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

button:hover { background: var(--panel2); }
button:disabled { opacity: 0.6; cursor: not-allowed; }

/* Layout: chat section + feedback section separated */
.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px;
  overflow: hidden;
  min-height: 0;
  background: linear-gradient(180deg, color-mix(in srgb, var(--bg2), transparent 0%), color-mix(in srgb, var(--bg2), transparent 5%));
}

.section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.section.chat-section {
  flex: 1 1 auto;          /* Chat darf wachsen */
  min-height: 0;           /* wichtig für Scroll im Chat */
}

.section.feedback-section {
  flex: 0 0 180px;         /* Feedback hat feste Höhe */
  min-height: 180px;
  max-height: 220px;
  transition: max-height 180ms ease, min-height 180ms ease, flex-basis 180ms ease;
}

.section-header {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: color-mix(in srgb, var(--panel), transparent 0%);
}

.section-header .label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

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

.info-trigger {
  border-color: color-mix(in srgb, var(--accent), transparent 55%);
  background: color-mix(in srgb, var(--accent), transparent 88%);
  color: var(--text);
  font-weight: 600;
}

.info-trigger:hover {
  background: color-mix(in srgb, var(--accent), transparent 82%);
}

.chat {
  flex: 1 1 auto;
  padding: 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  background: color-mix(in srgb, var(--bg2), transparent 6%);
}

.msg-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.msg-row.user { justify-content: flex-end; }
.msg-row.bot { justify-content: flex-start; }

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  overflow: hidden;
}

.avatar svg { width: 18px; height: 18px; opacity: 0.9; }
.avatar.user { background: color-mix(in srgb, var(--accent), transparent 88%); border-color: var(--userBorder); }

/* Avatar-Bot rot aussehen lassen */
.avatar.bot {
  background: color-mix(in srgb, var(--accent), transparent 90%);
  border-color: color-mix(in srgb, var(--accent), transparent 65%);
}

.msg {
  max-width: 78%;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  line-height: 1.35;
  font-size: 14px;
  word-break: break-word;
}

.msg.user {
  background: var(--userBubble);
  border-color: var(--userBorder);
  white-space: pre-wrap;
}

.msg.bot {
  background: var(--botBubble);
  white-space: normal;
}

.msg.meta {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  padding: 0;
  max-width: 100%;
  white-space: normal;
}

.msg.error {
  background: var(--dangerBg);
  border-color: var(--dangerBorder);
  white-space: normal;
}

/* Markdown styling */
.msg.bot p, .msg.error p { margin: 0.35em 0; }
.msg.bot ul, .msg.bot ol, .msg.error ul, .msg.error ol { margin: 0.35em 0 0.35em 1.2em; }
.msg.bot li, .msg.error li { margin: 0.2em 0; }

.msg.bot code, .msg.error code {
  background: color-mix(in srgb, var(--panel2), transparent 0%);
  padding: 2px 4px;
  border-radius: 6px;
}

.msg.bot pre, .msg.error pre {
  background: color-mix(in srgb, var(--bg), transparent 40%);
  padding: 10px;
  border-radius: 12px;
  overflow-x: auto;
  margin: 0.5em 0;
}

.msg.bot pre code, .msg.error pre code {
  background: transparent;
  padding: 0;
}

.msg.bot table, .msg.error table {
  border-collapse: collapse;
  width: 100%;
  margin-top: 8px;
  font-size: 13px;
}

.msg.bot th, .msg.bot td, .msg.error th, .msg.error td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  vertical-align: top;
}

.msg.bot th, .msg.error th {
  background: var(--panel2);
}

.msg.bot a, .msg.error a {
  color: color-mix(in srgb, var(--accent), white 35%);
}

.composer {
  border-top: 1px solid var(--border);
  padding: 10px 12px;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: color-mix(in srgb, var(--panel), transparent 0%);
}

textarea {
  flex: 1;
  resize: none;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg2), transparent 6%);
  color: var(--text);
  padding: 10px 12px;
  min-height: 44px;
  max-height: 80px;
  line-height: 1.4;
  font-size: 14px;
  outline: none;
  overflow-y: auto;
  scrollbar-width: thin;
}

textarea::placeholder { color: color-mix(in srgb, var(--muted), transparent 0%); }

.send {
  min-width: 120px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--accent), transparent 45%);
  background: #e11d3a;          /* helleres DRK-Rot */
  color: white;                 /* guter Kontrast */
  display: inline-flex;         /* Zentrierung */
  align-items: center;
  justify-content: center;
  font-weight: 600;
}

.send:hover { filter: brightness(1.06); }
.send:disabled { opacity: 0.65; }

/* Feedback section */
.feedback-body {
  padding: 12px;
  background: color-mix(in srgb, var(--bg2), transparent 6%);
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.feedback textarea {
  width: 100%;
  resize: vertical;
  min-height: 60px;
  max-height: 100px;
  flex: 1 1 auto;
  resize: none;
}

.feedback-row {
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.feedback-status {
  font-size: 12px;
  color: var(--muted);
}

/* Spinner */
.spinner {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 2px solid color-mix(in srgb, var(--muted), transparent 60%);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
  display: inline-block;
  vertical-align: middle;
}

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

.hint {
  padding: 0 2px 2px 2px;
  color: var(--muted);
  font-size: 12px;
}

.icon-btn svg { width: 16px; height: 16px; opacity: 0.9; }

.toggle {
  border-color: color-mix(in srgb, var(--accent), transparent 55%);
}

.info-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(5, 10, 20, 0.42);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
  z-index: 50;
}

.info-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.info-overlay.is-closing {
  opacity: 0;
}

.info-modal {
  position: relative;
  width: min(640px, calc(100vw - 32px));
  max-height: min(78vh, 720px);
  overflow: auto;
  padding: 24px 24px 20px;
  border-radius: 22px;
  border: 1px solid color-mix(in srgb, var(--accent), transparent 65%);
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--bg2), white 2%), color-mix(in srgb, var(--bg2), transparent 0%));
  box-shadow:
    0 30px 80px rgba(0, 0, 0, 0.32),
    inset 0 1px 0 rgba(255,255,255,0.06);
  transform-origin: center center;
  transition: transform 260ms cubic-bezier(0.22, 1, 0.36, 1), opacity 220ms ease;
}

.info-modal h2 {
  margin: 0 32px 14px 0;
  font-size: clamp(22px, 2.5vw, 30px);
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.info-eyebrow {
  margin-bottom: 10px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.info-copy {
  color: var(--text);
  line-height: 1.55;
  font-size: 15px;
}

.info-copy p {
  margin: 0 0 14px;
}

.info-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 999px;
  justify-content: center;
  font-size: 24px;
  line-height: 1;
}

@media (max-width: 720px) {
  header {
    flex-direction: column;
    align-items: stretch;
  }

  header .actions,
  .section-tools {
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .info-overlay {
    padding: 12px;
  }

  .info-modal {
    width: min(100vw - 24px, 640px);
    padding: 20px 18px 18px;
    max-height: calc(100vh - 24px);
  }
}

/* Collapsible feedback */
.section.feedback-section.collapsed {
  flex: 0 0 54px;     /* nur Header sichtbar */
  min-height: 54px;
  max-height: 54px;
}

.section.feedback-section.collapsed .feedback-body {
  display: none;      /* Body komplett weg */
}
