/* SimpliMed-Chat (2.2.0): widget (iframe /widget/) and web interface (/) - docs/superpowers/specs/2026-09-30-chat-widget-design.md.
   Light theme in the house colour of simplimed-online.de (#007bb4), system fonts (no external requests), contrast >= 4.5:1
   for text, visible focus, no motion with prefers-reduced-motion. Everything the script sets at runtime goes through the
   CSSOM (heights of the input), which the CSP style-src 'self' allows. */

:root {
  color-scheme: light;
  --brand: #007bb4;
  --brand-dark: #005d8a;
  --brand-tint: #e6f2f8;
  --ink: #1a2530;
  --ink-soft: #4d5a66;
  --line: #d9e1e8;
  --line-soft: #e8edf2;
  --bg: #ffffff;
  --bg-soft: #f4f7fa;
  --accent: #c2561a;
  --accent-soft: #fff4ec;
  --warn-bg: #fff6e0;
  --warn-ink: #6b4500;
  --error-bg: #fdecea;
  --error-ink: #a51d12;
  --radius: 14px;
  --focus: 0 0 0 3px rgba(0, 123, 180, 0.35);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}

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

/* a component rule with display: flex must not show an element the app has hidden */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font: 15px/1.5 var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

html[data-mode="page"] body {
  background: var(--bg-soft);
}

button,
textarea,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: default;
}

:focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 2px;
}

a {
  color: var(--brand-dark);
  text-decoration: underline;
  text-underline-offset: 2px;
}

a:hover {
  color: var(--brand);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.chat-noscript {
  margin: 24px;
}

/* ── frame of the app ─────────────────────────────────────────────────────────────────────────────────────────────── */

.chat {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  background: var(--bg);
}

html[data-mode="page"] .chat {
  max-width: 820px;
  margin: 0 auto;
  box-shadow: 0 0 0 1px var(--line-soft), 0 8px 30px rgba(16, 24, 40, 0.08);
}

/* ── header ───────────────────────────────────────────────────────────────────────────────────────────────────────── */

.chat-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px 10px 14px;
  color: #fff;
  background: var(--brand);
}

.chat-header__logo {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  padding: 4px;
  border-radius: 50%;
  background: #fff;
}

.chat-header__logo img {
  display: block;
  width: 100%;
  height: 100%;
}

.chat-header__text {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.chat-header__title {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header__subtitle {
  font-size: 12.5px;
  color: #fff;
}

.chat-header__actions {
  flex: 0 0 auto;
  display: flex;
  gap: 2px;
}

.icon-button {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 10px;
  color: #fff;
  background: transparent;
}

.icon-button:hover {
  background: rgba(255, 255, 255, 0.16);
}

.icon-button:focus-visible {
  outline: 2px solid #fff;
  outline-offset: -2px;
}

.icon-button svg,
.chip svg,
.feedback button svg,
.send-button svg {
  width: 20px;
  height: 20px;
  display: block;
  pointer-events: none;
}

/* ── product line ─────────────────────────────────────────────────────────────────────────────────────────────────── */

.product-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 6px 14px;
  font-size: 13.5px;
  color: var(--ink-soft);
  background: var(--bg);
  border-bottom: 1px solid var(--line-soft);
}

.product-bar strong {
  color: var(--ink);
  font-weight: 600;
}

.link-button {
  margin-left: auto;
  padding: 2px 4px;
  border: 0;
  border-radius: 6px;
  color: var(--brand-dark);
  background: transparent;
  text-decoration: underline;
  text-underline-offset: 2px;
  font-size: 13.5px;
}

.link-button:hover {
  color: var(--brand);
}

/* ── conversation ─────────────────────────────────────────────────────────────────────────────────────────────────── */

.chat-log {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 14px 20px;
  background: var(--bg-soft);
  scroll-behavior: smooth;
}

.chat-log:focus-visible {
  outline-offset: -3px;
}

.msg {
  max-width: 88%;
  padding: 10px 13px;
  border-radius: var(--radius);
  overflow-wrap: anywhere;
  word-break: normal;
}

.msg p {
  margin: 0;
}

.msg p + p,
.msg p + ol,
.msg p + ul,
.msg ol + p,
.msg ul + p {
  margin-top: 8px;
}

.msg ol,
.msg ul {
  margin: 0;
  padding-left: 22px;
}

.msg li + li {
  margin-top: 3px;
}

.msg code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--bg-soft);
}

.msg--bot {
  align-self: flex-start;
  background: var(--bg);
  border: 1px solid var(--line-soft);
  border-bottom-left-radius: 4px;
}

.msg--user {
  align-self: flex-end;
  color: #fff;
  background: var(--brand);
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}

.msg--notice {
  align-self: stretch;
  max-width: none;
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--brand-tint);
  border: 0;
  border-radius: 10px;
}

.msg--system {
  align-self: center;
  max-width: 94%;
  padding: 6px 12px;
  font-size: 13px;
  color: var(--ink-soft);
  background: transparent;
  text-align: center;
}

.msg--error {
  align-self: stretch;
  max-width: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  font-size: 14px;
  color: var(--error-ink);
  background: var(--error-bg);
  border-radius: 10px;
}

.msg-note {
  align-self: flex-end;
  margin-top: -6px;
  font-size: 12px;
  color: var(--ink-soft);
}

/* ── choices: products, suggestions ──────────────────────────────────────────────────────────────────────────────── */

.choices {
  align-self: stretch;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 14px;
  font-size: 14px;
  line-height: 1.3;
  text-align: left;
  color: var(--brand-dark);
  background: var(--bg);
  border: 1px solid var(--brand);
  border-radius: 999px;
}

.chip:hover:not(:disabled) {
  background: var(--brand-tint);
}

.chip:disabled {
  opacity: 0.55;
}

.choices-label {
  align-self: stretch;
  margin: 4px 0 -4px;
  font-size: 12.5px;
  color: var(--ink-soft);
}

/* ── answer extras: sources, feedback, support, cut off ──────────────────────────────────────────────────────────── */

.sources {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--line-soft);
}

.sources__label {
  font-size: 12.5px;
  color: var(--ink-soft);
}

.source-button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 28px;
  padding: 3px 10px;
  font-size: 12.5px;
  color: var(--ink);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.source-button svg {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  color: var(--brand-dark);
}

.source-button:hover {
  border-color: var(--brand);
}

.source-button[aria-expanded="true"] {
  border-color: var(--brand);
  background: var(--brand-tint);
}

.source-panel {
  margin-top: 8px;
  padding: 10px 12px;
  max-height: 260px;
  overflow-y: auto;
  font-size: 13.5px;
  background: var(--bg-soft);
  border-left: 3px solid var(--brand);
  border-radius: 6px;
}

.source-panel__title {
  display: block;
  margin-bottom: 4px;
  font-weight: 600;
}

.answer-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  margin-top: 8px;
}

.feedback {
  display: inline-flex;
  gap: 2px;
}

.feedback button {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 8px;
  color: var(--ink-soft);
  background: transparent;
}

.feedback button svg {
  width: 17px;
  height: 17px;
}

.feedback button:hover {
  color: var(--brand-dark);
  background: var(--bg-soft);
}

.feedback button[aria-pressed="true"] {
  color: var(--brand-dark);
  background: var(--brand-tint);
}

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

.cut-off {
  font-size: 12px;
  color: var(--ink-soft);
}

.support {
  margin-top: 10px;
  padding: 9px 12px;
  font-size: 13.5px;
  color: var(--ink);
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
}

.support p,
.support ol,
.support ul {
  margin: 0;
}

.support > * + * {
  margin-top: 6px;
}

/* ── typing indicator ─────────────────────────────────────────────────────────────────────────────────────────────── */

.typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 22px;
}

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink-soft);
  opacity: 0.35;
  animation: chat-dot 1.1s infinite ease-in-out;
}

.typing span:nth-child(2) {
  animation-delay: 0.18s;
}

.typing span:nth-child(3) {
  animation-delay: 0.36s;
}

@keyframes chat-dot {
  0%, 80%, 100% { opacity: 0.25; }
  40% { opacity: 0.9; }
}

/* ── states without conversation: loading, unavailable ───────────────────────────────────────────────────────────── */

.chat-state {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  color: var(--ink-soft);
  background: var(--bg-soft);
}

.chat-state p {
  margin: 0;
  max-width: 34ch;
}

.chat-state .support {
  text-align: left;
  max-width: 36ch;
}

.button {
  min-height: 40px;
  padding: 8px 16px;
  border: 1px solid var(--brand);
  border-radius: 10px;
  color: var(--brand-dark);
  background: var(--bg);
  font-weight: 600;
  font-size: 14px;
}

.button:hover {
  background: var(--brand-tint);
}

/* ── composer ─────────────────────────────────────────────────────────────────────────────────────────────────────── */

.chat-composer {
  flex: 0 0 auto;
  padding: 10px 12px 8px;
  background: var(--bg);
  border-top: 1px solid var(--line-soft);
}

.chat-alert {
  margin: 0 0 8px;
  padding: 8px 11px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--warn-ink);
  background: var(--warn-bg);
  border-radius: 10px;
}

.composer-row {
  position: relative;
  display: flex;
}

.composer-row textarea {
  flex: 1 1 auto;
  display: block;
  width: 100%;
  min-height: 46px;
  max-height: 140px;
  padding: 11px 52px 11px 13px;
  font-size: 15px;
  line-height: 1.45;
  resize: none;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.composer-row textarea::placeholder {
  color: #6b7784;
}

.composer-row textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: var(--focus);
}

.composer-row textarea:disabled {
  background: var(--bg-soft);
}

.send-button {
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 10px;
  color: #fff;
  background: var(--brand);
}

.send-button:hover:not(:disabled) {
  background: var(--brand-dark);
}

.send-button:disabled {
  background: #9aa7b2;
}

.send-button svg {
  width: 18px;
  height: 18px;
}

.composer-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
  font-size: 11.5px;
  line-height: 1.35;
  color: var(--ink-soft);
}

.composer-meta a {
  color: var(--ink-soft);
}

.meta-item {
  white-space: nowrap;
}

.composer-counter {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
}

.composer-counter.is-near {
  color: var(--warn-ink);
}

/* ── small screens (the widget is full screen up to 640 px) ──────────────────────────────────────────────────────── */

@media (max-width: 640px) {
  .msg {
    max-width: 92%;
  }

  .composer-row textarea {
    font-size: 16px; /* iOS does not zoom into a field of at least 16 px */
  }

  .chat-composer {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-log {
    scroll-behavior: auto;
  }

  .typing span {
    animation: none;
    opacity: 0.6;
  }
}

@media (forced-colors: active) {
  .msg--user,
  .msg--bot,
  .chip,
  .source-button {
    border: 1px solid CanvasText;
  }
}
