:root {
  --sj-ink: #342d3c;
  --sj-muted: #716a79;
  --sj-purple: #9279ac;
  --sj-rose: #f3d8db;
  --sj-sage: #dcebe4;
}

html.sj-chat-active,
body.sj-chat-active {
  overflow: hidden !important;
  margin: 0 !important;
}

.sj-app,
.sj-app * {
  box-sizing: border-box;
}

.sj-app {
  position: fixed !important;
  inset: 0 !important;
  z-index: 2147483000 !important;
  display: block !important;
  width: 100vw !important;
  max-width: none !important;
  height: 100vh !important;
  height: 100dvh !important;
  min-height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
  transform: none !important;
  color: var(--sj-ink);
  background: linear-gradient(135deg, #fff8f4 0%, #f8f1fb 54%, #eff8f4 100%);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
  isolation: isolate;
}

body.admin-bar .sj-app {
  top: 32px !important;
  height: calc(100dvh - 32px) !important;
}

.sj-app button,
.sj-app textarea {
  font: inherit;
}

.sj-layout {
  display: grid;
  grid-template-columns: clamp(238px, 17vw, 295px) minmax(0, 1fr);
  width: 100%;
  height: 100%;
}

/* Linke Gesprächsleiste */
.sj-rail {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  padding: clamp(24px, 2.3vw, 38px) clamp(18px, 1.8vw, 28px);
  border-right: 1px solid rgba(72, 57, 91, .09);
  background:
    radial-gradient(circle at 5% 12%, rgba(220, 235, 228, .70), transparent 17rem),
    linear-gradient(165deg, rgba(255,255,255,.54), rgba(255,255,255,.18));
}

.sj-rail-head {
  display: grid;
  gap: 20px;
}

.sj-brand-name {
  display: block;
  color: var(--sj-ink);
  font-size: clamp(1.15rem, 1.45vw, 1.42rem);
  font-weight: 800;
  letter-spacing: -.035em;
}

.sj-new-chat {
  display: flex;
  width: 100%;
  min-height: 49px;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 10px 15px;
  border: 1px solid rgba(255,255,255,.92);
  border-radius: 17px;
  color: var(--sj-ink);
  background: rgba(255,255,255,.76);
  box-shadow: 0 8px 22px rgba(72,57,91,.055);
  cursor: pointer;
  transition: transform .16s ease, background .16s ease, box-shadow .16s ease;
}

.sj-new-chat:hover {
  transform: translateY(-1px);
  background: rgba(255,255,255,.96);
  box-shadow: 0 10px 26px rgba(72,57,91,.08);
}

.sj-new-chat svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
}

.sj-history-wrap {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  margin-top: 30px;
}

.sj-history-label {
  margin: 0 3px 10px;
  color: #8a8090;
  font-size: .69rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.sj-history {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 7px;
  overflow-y: auto;
  padding: 2px 3px 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(142,120,173,.28) transparent;
}

.sj-history-item {
  display: grid;
  width: 100%;
  gap: 3px;
  padding: 12px 13px;
  border: 1px solid transparent;
  border-radius: 15px;
  color: var(--sj-ink);
  text-align: left;
  background: transparent;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .15s ease;
}

.sj-history-item:hover {
  transform: translateX(2px);
  background: rgba(255,255,255,.62);
}

.sj-history-item.is-active {
  border-color: rgba(146,121,172,.13);
  background: rgba(255,255,255,.86);
  box-shadow: 0 7px 18px rgba(72,57,91,.05);
}

.sj-history-item:disabled {
  cursor: wait;
  opacity: .7;
}

.sj-history-item strong,
.sj-history-item small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sj-history-item strong {
  font-size: .88rem;
  font-weight: 700;
}

.sj-history-item small {
  color: #938a99;
  font-size: .68rem;
}

.sj-history-empty {
  margin: 2px 4px;
  color: #938a99;
  font-size: .8rem;
}

.sj-history-empty[hidden] {
  display: none;
}

.sj-rail-footer {
  margin-top: 18px;
  color: #8a8090;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .075em;
  text-transform: uppercase;
}

/* Hauptbereich */
.sj-chat-panel {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-rows: minmax(0, 1fr) auto auto;
  padding: clamp(10px, 1.45vw, 22px);
  background: rgba(255,255,255,.18);
}

.sj-conversation {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  gap: 18px;
  overflow: auto;
  padding: clamp(20px, 3vw, 44px);
  border: 1px solid rgba(255,255,255,.88);
  border-radius: 34px 34px 20px 20px;
  background: rgba(255,255,255,.62);
  box-shadow: 0 14px 44px rgba(72,57,91,.08);
  scrollbar-width: thin;
  scrollbar-color: rgba(142,120,173,.35) transparent;
}

.sj-empty {
  display: grid;
  max-width: 720px;
  margin: auto;
  place-items: center;
  color: var(--sj-muted);
  text-align: center;
}

.sj-empty-mark {
  display: grid;
  width: 54px;
  height: 54px;
  margin-bottom: 18px;
  place-items: center;
  border-radius: 18px;
  color: #6e5a8d;
  background: linear-gradient(145deg, #f8edf3, #e7daf3);
  font-size: 1.18rem;
}

.sj-empty h2 {
  max-width: 700px;
  margin: 0;
  color: var(--sj-ink);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.9rem, 3.15vw, 3rem);
  font-weight: 500;
  letter-spacing: -.04em;
  line-height: 1.16;
}

.sj-empty p {
  margin: 14px 0 0;
  font-size: clamp(1rem, 1.3vw, 1.2rem);
}

.sj-avatar {
  display: grid;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 13px;
  color: #65547d;
  background: linear-gradient(145deg, #f7f0fb, #dfd0ef);
  box-shadow: 0 5px 13px rgba(85,66,111,.1);
  font-size: .68rem;
  font-weight: 800;
}

.sj-message {
  display: flex;
  align-items: flex-start;
  gap: 11px;
}

.sj-message.is-user {
  justify-content: flex-end;
}

.sj-bubble {
  max-width: min(84%, 900px);
  padding: 15px 18px;
  border-radius: 7px 22px 22px;
  overflow-wrap: anywhere;
  background: rgba(255,255,255,.96);
  box-shadow: 0 6px 18px rgba(72,57,91,.06);
}

.sj-message.is-user .sj-bubble {
  border-radius: 22px 7px 22px 22px;
  background: linear-gradient(135deg, #eee3f6, #f8e2da);
}

.sj-bubble > :first-child { margin-top: 0; }
.sj-bubble > :last-child { margin-bottom: 0; }
.sj-bubble p { margin: .62em 0; }
.sj-bubble h3,
.sj-bubble h4 {
  margin: 1.05em 0 .42em;
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1.2;
}
.sj-bubble h3 { font-size: 1.38rem; }
.sj-bubble h4 { font-size: 1.17rem; }
.sj-bubble ul,
.sj-bubble ol { margin: .68em 0; padding-left: 1.25em; }
.sj-bubble li + li { margin-top: .32em; }
.sj-bubble code { padding: .12em .34em; border-radius: 6px; background: rgba(90,72,111,.09); }
.sj-time { display: block; margin-top: 7px; color: rgba(69,59,79,.46); font-size: .67rem; }
.sj-error { border: 1px solid rgba(185,91,104,.17); color: #774751; background: #fff1f2; }

.sj-typing {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 12px 20px 0;
}

.sj-typing[hidden] { display: none; }

.sj-typing-bubble {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 15px;
  border-radius: 7px 19px 19px;
  background: rgba(255,255,255,.96);
}

.sj-typing-bubble i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #a995bc;
  animation: sj-typing 1.05s ease-in-out infinite;
}

.sj-typing-bubble i:nth-child(2) { animation-delay: .14s; }
.sj-typing-bubble i:nth-child(3) { animation-delay: .28s; }
.sj-typing-bubble em { margin-left: 6px; color: var(--sj-muted); font-size: .77rem; font-style: normal; }

@keyframes sj-typing {
  0%, 70%, 100% { opacity: .35; transform: translateY(0); }
  35% { opacity: 1; transform: translateY(-3px); }
}

.sj-composer {
  padding: 15px 2px 0;
}

.sj-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 9px 9px 9px 18px;
  border: 1px solid rgba(141,120,173,.2);
  border-radius: 24px;
  background: rgba(255,255,255,.94);
  box-shadow: 0 10px 28px rgba(72,57,91,.08);
}

.sj-input-wrap:focus-within {
  border-color: rgba(141,120,173,.48);
  box-shadow: 0 0 0 4px rgba(217,202,238,.2);
}

.sj-input-wrap textarea {
  flex: 1;
  max-height: 150px;
  min-height: 46px;
  margin: 0;
  padding: 11px 0 8px;
  resize: none;
  border: 0;
  outline: 0;
  color: var(--sj-ink);
  background: transparent;
  font: inherit;
  line-height: 1.45;
}

.sj-input-wrap textarea::placeholder { color: #aaa2b1; }

.sj-send {
  display: flex;
  min-width: 112px;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 18px;
  border: 0;
  border-radius: 17px;
  color: #fff;
  background: linear-gradient(135deg, var(--sj-purple), #a77790);
  box-shadow: 0 7px 16px rgba(112,81,129,.2);
  cursor: pointer;
}

.sj-send:disabled { cursor: wait; opacity: .6; }
.sj-send svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.sj-composer > p { margin: 9px 8px 0; color: #857d8c; text-align: center; font-size: .7rem; }

@media (max-width: 820px) {
  .sj-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .sj-rail {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    gap: 9px 12px;
    padding: 10px 12px;
    border-right: 0;
    border-bottom: 1px solid rgba(72,57,91,.08);
    background: rgba(255,255,255,.60);
  }

  .sj-rail-head {
    display: contents;
  }

  .sj-brand-name {
    align-self: center;
  }

  .sj-new-chat {
    grid-column: 2;
    grid-row: 1;
    width: auto;
    min-height: 42px;
    padding: 8px 13px;
    border-radius: 999px;
  }

  .sj-history-wrap {
    grid-column: 1 / -1;
    grid-row: 2;
    margin-top: 0;
  }

  .sj-history-label,
  .sj-history-empty {
    display: none;
  }

  .sj-history {
    flex-direction: row;
    gap: 7px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0 0 2px;
  }

  .sj-history-item {
    min-width: 155px;
    max-width: 210px;
    padding: 9px 11px;
  }

  .sj-rail-footer {
    display: none;
  }

  .sj-chat-panel {
    padding: 8px 10px 10px;
  }
}

@media (max-width: 600px) {
  body.admin-bar .sj-app {
    top: 46px !important;
    height: calc(100dvh - 46px) !important;
  }

  .sj-rail {
    padding: 8px 10px;
  }

  .sj-brand-name {
    font-size: 1rem;
  }

  .sj-new-chat span {
    display: none;
  }

  .sj-new-chat {
    width: 42px;
    height: 42px;
    min-height: 42px;
    justify-content: center;
    padding: 0;
  }

  .sj-history-item {
    min-width: 138px;
    max-width: 180px;
  }

  .sj-chat-panel {
    padding: 6px 8px 8px;
  }

  .sj-conversation {
    padding: 18px 12px;
    border-radius: 24px 24px 16px 16px;
  }

  .sj-empty h2 {
    font-size: clamp(1.55rem, 8vw, 2.15rem);
  }

  .sj-bubble {
    max-width: 88%;
    padding: 13px 15px;
  }

  .sj-send {
    min-width: 48px;
    width: 48px;
    padding: 0;
  }

  .sj-send span {
    display: none;
  }

  .sj-composer > p {
    font-size: .64rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sj-typing-bubble i {
    animation: none;
  }
}

/* PDF-Export rechts unten im Chat */
.sj-chat-panel {
  position: relative;
}

.sj-pdf-button {
  position: absolute;
  right: clamp(22px, 2vw, 34px);
  bottom: 105px;
  z-index: 8;
  display: inline-flex;
  min-width: 66px;
  height: 42px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 13px;
  border: 1px solid rgba(255,255,255,.92);
  border-radius: 15px;
  color: #665276;
  background: rgba(255,255,255,.9);
  box-shadow: 0 9px 24px rgba(72,57,91,.12);
  cursor: pointer;
  backdrop-filter: blur(12px);
  transition: transform .16s ease, background .16s ease, box-shadow .16s ease;
}

.sj-pdf-button:hover {
  transform: translateY(-2px);
  background: #fff;
  box-shadow: 0 12px 28px rgba(72,57,91,.16);
}

.sj-pdf-button:disabled {
  cursor: wait;
  opacity: .55;
  transform: none;
}

.sj-pdf-button[hidden] {
  display: none !important;
}

.sj-pdf-button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sj-pdf-button span {
  font-size: .73rem;
  font-weight: 800;
  letter-spacing: .05em;
}

@media (max-width: 600px) {
  .sj-pdf-button {
    right: 17px;
    bottom: 98px;
    width: 42px;
    min-width: 42px;
    padding: 0;
    border-radius: 14px;
  }

  .sj-pdf-button span {
    display: none;
  }
}
