:root {
  --bg: #f5f6f8;
  --surface: rgba(255, 255, 255, 0.72);
  --surface-strong: rgba(255, 255, 255, 0.88);
  --surface-soft: rgba(255, 255, 255, 0.52);

  --text: #111827;
  --text-muted: #6b7280;

  --border: rgba(17, 24, 39, 0.08);
  --border-light: rgba(255, 255, 255, 0.65);

  --shadow-soft: 0 18px 50px rgba(15, 23, 42, 0.08);
  --shadow-card: 0 24px 70px rgba(15, 23, 42, 0.10);

  --accent: #111827;
  --accent-hover: #1f2937;

  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;

  --transition: 180ms ease;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  margin: 0;
  padding: 0;
  overflow-x: hidden;

  font-family:
    -apple-system,
    BlinkMacSystemFont,
    "SF Pro Display",
    "SF Pro Text",
    "Segoe UI",
    Roboto,
    Arial,
    sans-serif;

  color: var(--text);

  background:
    radial-gradient(circle at 18% 4%, rgba(191, 219, 254, 0.48), transparent 34%),
    radial-gradient(circle at 84% 3%, rgba(221, 214, 254, 0.42), transparent 32%),
    radial-gradient(circle at 64% 76%, rgba(207, 250, 254, 0.34), transparent 40%),
    linear-gradient(180deg, #f8fafc 0%, #f3f6fb 52%, #f7f8fb 100%);
}

/* Dezentes Premium-Grid */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;

  background-image:
    linear-gradient(rgba(255, 255, 255, 0.30) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.30) 1px, transparent 1px);
  background-size: 58px 58px;

  opacity: 0.55;

  mask-image: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.48),
    rgba(0, 0, 0, 0.28) 45%,
    transparent 82%
  );
}

/* Header */

.header {
  max-width: 900px;
  display: flex;
  justify-content: center;
  align-items: center;

  margin: 30px auto 18px auto;
  padding: 14px 24px;

  border-radius: 999px;

  background: rgba(255, 255, 255, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.55);

  box-shadow: 0 14px 44px rgba(15, 23, 42, 0.06);

  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
}

.logo {
  max-height: 72px;
  width: auto;
  display: block;
  background: transparent;
  filter: drop-shadow(0 8px 18px rgba(15, 23, 42, 0.06));
}

/* Hauptkarte */

.chat {
  position: relative;

  width: min(900px, calc(100% - 32px));
  margin: 28px auto 54px auto;
  padding: 34px 34px 32px;

  border-radius: var(--radius-xl);
  border: 1px solid var(--border-light);

  background: rgba(255, 255, 255, 0.72);

  box-shadow: var(--shadow-card);

  backdrop-filter: blur(26px) saturate(150%);
  -webkit-backdrop-filter: blur(26px) saturate(150%);

  overflow: hidden;
}

/* Sehr dezenter Lichtverlauf innerhalb der Karte */
.chat::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;

  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.48),
    rgba(255, 255, 255, 0.08)
  );
}

.chat > * {
  position: relative;
  z-index: 1;
}

h2 {
  margin: 0 0 24px 0;

  font-size: clamp(1.65rem, 3vw, 2.35rem);
  line-height: 1.08;
  letter-spacing: -0.045em;
  font-weight: 760;

  color: #111827;
}

h2::after {
  content: "KI-gestützte juristische Assistenz";
  display: block;

  margin-top: 10px;

  font-size: 0.92rem;
  line-height: 1.4;
  letter-spacing: 0;
  font-weight: 500;

  color: var(--text-muted);
}

/* Nachrichten */

.messages {
  display: flex;
  flex-direction: column;
  gap: 14px;

  margin-bottom: 22px;
}

.msg {
  margin-bottom: 0;
  animation: messageIn 220ms ease both;
}

.question {
  align-self: flex-end;

  max-width: 82%;
  padding: 14px 16px;

  border-radius: 20px 20px 6px 20px;

  color: #ffffff;
  font-weight: 650;
  line-height: 1.5;
  white-space: pre-wrap;

  background: #1f2937;

  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.16);
}

.answer {
  align-self: flex-start;

  max-width: 92%;
  padding: 17px 18px;

  white-space: pre-wrap;
  line-height: 1.65;

  border-radius: 20px 20px 20px 6px;
  border: 1px solid rgba(17, 24, 39, 0.06);

  background: rgba(255, 255, 255, 0.74);

  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.06);

  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
}

/* Eingabe */

textarea {
  width: 100%;
  min-height: 104px;

  margin-bottom: 14px;
  padding: 17px 18px;

  resize: vertical;

  border: 1px solid rgba(17, 24, 39, 0.09);
  border-radius: 20px;
  outline: none;

  color: var(--text);
  font: inherit;
  line-height: 1.55;

  background: rgba(255, 255, 255, 0.70);

  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.75),
    0 10px 28px rgba(15, 23, 42, 0.045);

  backdrop-filter: blur(14px) saturate(135%);
  -webkit-backdrop-filter: blur(14px) saturate(135%);

  transition:
    border-color var(--transition),
    box-shadow var(--transition),
    background var(--transition);
}

textarea::placeholder {
  color: rgba(100, 116, 139, 0.72);
}

textarea:focus {
  border-color: rgba(17, 24, 39, 0.18);
  background: rgba(255, 255, 255, 0.88);

  box-shadow:
    0 0 0 4px rgba(17, 24, 39, 0.045),
    0 16px 38px rgba(15, 23, 42, 0.075);
}

/* Buttons */

.row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

button {
  appearance: none;

  border: 0;
  border-radius: 999px;

  padding: 12px 20px;

  cursor: pointer;

  font: inherit;
  font-weight: 650;
  letter-spacing: -0.01em;

  transition:
    transform var(--transition),
    box-shadow var(--transition),
    background var(--transition),
    color var(--transition),
    opacity var(--transition);
}

button:hover {
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0) scale(0.985);
}

button:focus-visible {
  outline: 4px solid rgba(17, 24, 39, 0.10);
  outline-offset: 3px;
}

#askBtn {
  color: #ffffff;
  background: #1f2937;
  box-shadow: 0 14px 30px rgba(15, 23, 42, 0.18);
}

#askBtn:hover {
  background: #111827;
  box-shadow: 0 18px 36px rgba(15, 23, 42, 0.22);
}

#promptBtn,
.modal-actions button {
  color: #111827;

  background: rgba(255, 255, 255, 0.68);

  border: 1px solid rgba(17, 24, 39, 0.075);

  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.78),
    0 10px 24px rgba(15, 23, 42, 0.055);

  backdrop-filter: blur(14px) saturate(135%);
  -webkit-backdrop-filter: blur(14px) saturate(135%);
}

#promptBtn:hover,
.modal-actions button:hover {
  background: rgba(255, 255, 255, 0.86);

  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.86),
    0 14px 30px rgba(15, 23, 42, 0.08);
}

/* Quellen */

.sources {
  margin-top: 14px;
  padding-top: 12px;

  font-size: 0.9em;
  color: var(--text-muted);

  border-top: 1px solid rgba(17, 24, 39, 0.075);
}

.sources strong {
  color: #374151;
}

.sources ul {
  margin: 8px 0 0 18px;
  padding: 0;
}

.sources li {
  margin: 4px 0;
}

/* Klickbare Quellen */

.source-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;

  width: auto;
  padding: 6px 12px;

  border: 1px solid rgba(17, 24, 39, 0.10);
  border-radius: 12px;

  font: inherit;
  font-size: 1em;
  font-weight: 500;
  text-align: left;
  color: #1d4ed8;

  background: rgba(255, 255, 255, 0.55);
  box-shadow: none;

  cursor: pointer;
}

.source-link:hover {
  color: #1e40af;
  border-color: rgba(29, 78, 216, 0.35);
  background: rgba(219, 234, 254, 0.55);
  transform: none;
}

.source-link-icon {
  flex: none;
  font-size: 0.95em;
}

/* Inline-Quellenmarker im Antworttext */

.source-ref {
  display: inline;
  padding: 1px 6px;
  margin: 0 1px;

  border: 1px solid rgba(29, 78, 216, 0.22);
  border-radius: 8px;

  font: inherit;
  font-size: 0.88em;
  font-weight: 600;
  color: #1d4ed8;

  background: rgba(219, 234, 254, 0.45);
  box-shadow: none;

  cursor: pointer;
  white-space: nowrap;
}

.source-ref:hover {
  color: #1e40af;
  background: rgba(191, 219, 254, 0.75);
  border-color: rgba(29, 78, 216, 0.45);
  transform: none;
}

/* PDF-Fundstellen-Viewer (Side-Panel) */

.pdf-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;

  width: min(760px, 100vw);

  display: flex;
  flex-direction: column;

  z-index: 9000;

  border-left: 1px solid rgba(255, 255, 255, 0.65);

  background: rgba(248, 250, 252, 0.92);

  box-shadow: -24px 0 70px rgba(15, 23, 42, 0.22);

  backdrop-filter: blur(26px) saturate(150%);
  -webkit-backdrop-filter: blur(26px) saturate(150%);

  transform: translateX(105%);
  transition: transform 260ms ease;
}

.pdf-panel.open {
  transform: translateX(0);
}

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

  padding: 14px 18px;

  border-bottom: 1px solid rgba(17, 24, 39, 0.08);

  background: rgba(255, 255, 255, 0.66);
}

.pdf-panel-titles {
  min-width: 0;
}

.pdf-panel-title {
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #111827;

  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pdf-panel-subtitle {
  margin-top: 2px;

  font-size: 0.82em;
  color: var(--text-muted);

  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pdf-panel-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
}

.pdf-ctrl {
  display: inline-flex;
  align-items: center;
  justify-content: center;

  min-width: 34px;
  height: 34px;
  padding: 0 10px;

  border: 1px solid rgba(17, 24, 39, 0.10);
  border-radius: 10px;

  font: inherit;
  font-size: 0.95em;
  font-weight: 600;
  color: #111827;
  text-decoration: none;

  background: rgba(255, 255, 255, 0.72);
  box-shadow: none;

  cursor: pointer;
}

.pdf-ctrl:hover {
  background: rgba(255, 255, 255, 0.95);
  transform: none;
}

.pdf-ctrl:disabled {
  opacity: 0.4;
  cursor: default;
}

.pdf-jump {
  color: #92400e;
  border-color: rgba(217, 119, 6, 0.35);
  background: rgba(254, 243, 199, 0.75);
}

.pdf-jump:hover {
  background: rgba(253, 230, 138, 0.9);
}

.pdf-close {
  font-size: 1.25em;
}

.pdf-page-indicator {
  padding: 0 4px;

  font-size: 0.85em;
  font-weight: 600;
  color: var(--text-muted);

  white-space: nowrap;
}

.pdf-viewport {
  flex: 1;
  overflow: auto;

  padding: 18px;
}

.pdf-status {
  display: none;

  margin: 0 auto 12px auto;
  padding: 10px 14px;

  max-width: 640px;

  border: 1px solid rgba(217, 119, 6, 0.25);
  border-radius: 12px;

  font-size: 0.88em;
  color: #92400e;

  background: rgba(254, 243, 199, 0.8);
}

.pdf-status.error {
  color: #b91c1c;
  border-color: rgba(185, 28, 28, 0.25);
  background: rgba(254, 226, 226, 0.85);
}

.pdf-page-wrap {
  position: relative;
  margin: 0 auto;

  background: #ffffff;

  box-shadow: 0 14px 44px rgba(15, 23, 42, 0.16);
  border-radius: 4px;
}

.pdf-page-wrap canvas {
  display: block;
  border-radius: 4px;
}

/* PDF.js-Text-Layer (unsichtbarer, selektierbarer Text über dem Canvas) */

.textLayer {
  position: absolute;
  inset: 0;

  overflow: hidden;

  line-height: 1;
  text-align: initial;

  forced-color-adjust: none;
}

.textLayer span,
.textLayer br {
  position: absolute;

  color: transparent;
  white-space: pre;

  cursor: text;

  transform-origin: 0% 0%;
}

/* Hervorhebung der Fundstelle */

.textLayer span.pdf-hl {
  background: rgba(255, 213, 64, 0.85);
  mix-blend-mode: multiply;

  border-radius: 3px;
  box-shadow: 0 0 0 2px rgba(255, 213, 64, 0.85);
}

/* Modal */

.modal-backdrop {
  position: fixed;
  inset: 0;

  display: none;
  align-items: center;
  justify-content: center;

  padding: 24px;

  z-index: 9999;

  background: rgba(15, 23, 42, 0.34);

  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);

  animation: fadeIn 180ms ease both;
}

.modal {
  width: min(900px, 100%);

  padding: 24px;

  border-radius: var(--radius-xl);
  border: 1px solid rgba(255, 255, 255, 0.68);

  background: rgba(255, 255, 255, 0.82);

  box-shadow: 0 30px 90px rgba(15, 23, 42, 0.22);

  backdrop-filter: blur(28px) saturate(150%);
  -webkit-backdrop-filter: blur(28px) saturate(150%);

  animation: modalIn 220ms ease both;
}

.modal h3 {
  margin: 0 0 14px 0;

  font-size: 1.35rem;
  letter-spacing: -0.035em;

  color: #111827;
}

.modal textarea {
  min-height: 180px;
  margin-bottom: 14px;
  font-family: inherit;
}

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

.hint {
  margin-top: 12px;

  font-size: 0.9em;
  line-height: 1.5;

  color: var(--text-muted);
}

.status {
  min-height: 1.2em;

  margin-right: auto;

  align-self: center;

  font-size: 0.9em;
  font-weight: 600;

  color: #059669;
}

/* Scrollbar */

::-webkit-scrollbar {
  width: 12px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(15, 23, 42, 0.16);
  border: 4px solid transparent;
  border-radius: 999px;
  background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(15, 23, 42, 0.25);
  border: 4px solid transparent;
  background-clip: content-box;
}

/* Animationen */

@keyframes messageIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Responsive */

@media (max-width: 720px) {
  .header {
    width: min(100% - 20px, 900px);
    margin-top: 18px;
    padding: 14px 18px;
  }

  .logo {
    max-height: 58px;
  }

  .chat {
    width: min(100% - 20px, 900px);
    margin: 18px auto 28px auto;
    padding: 22px;
    border-radius: 24px;
  }

  .question,
  .answer {
    max-width: 100%;
  }

  .row {
    align-items: stretch;
  }

  button {
    width: 100%;
  }

  .modal {
    padding: 20px;
    border-radius: 24px;
  }

  .modal-actions {
    flex-direction: column;
  }

  .status {
    margin-right: 0;
  }

  /* Viewer-Bedienelemente behalten ihre kompakte Breite */
  .pdf-ctrl,
  .source-ref,
  .source-link {
    width: auto;
  }

  .pdf-panel {
    width: 100vw;
  }

  .pdf-panel-header {
    flex-wrap: wrap;
  }

  .pdf-viewport {
    padding: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    scroll-behavior: auto !important;
    transition: none !important;
  }
}