:root {
  --wa-bg: #e5ddd5;
  --wa-bg-pattern: #d9d0c7;
  --bubble-in: #ffffff;
  --bubble-out: #dcf8c6;
  --bubble-note: #f0f4f9;
  --quote-bar: #06b66d;
  --text: #111b21;
  --muted: #667781;
  --header: #075e54;
  --header-text: #ffffff;
  --shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--wa-bg);
  color: var(--text);
  line-height: 1.45;
}

.faq-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--header);
  color: var(--header-text);
  padding: 0.75rem 1rem 0.5rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.faq-header h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.faq-header p {
  margin: 0.15rem 0 0.6rem;
  font-size: 0.78rem;
  opacity: 0.9;
}

.faq-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}

.faq-toolbar label {
  font-size: 0.72rem;
  opacity: 0.9;
}

.faq-toolbar select,
.faq-toolbar button {
  border: 0;
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
  background: #ffffff;
  color: #111;
}

.faq-toolbar button {
  cursor: pointer;
}

.faq-toolbar button:hover {
  background: rgba(255, 255, 255, 0.28);
}

.faq-home-link {
  color: #fff;
  text-decoration: none;
  font-size: 0.78rem;
  margin-right: auto;
  opacity: 0.95;
}

.faq-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: calc(100vh - 110px);
}

.faq-sidebar {
  background: #fff;
  border-right: 1px solid #d1d7db;
  padding: 0.75rem;
  overflow: auto;
}

.faq-sidebar h2 {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.faq-topic-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.faq-topic-list button {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 0.45rem 0.35rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.82rem;
}

.faq-topic-list button:hover,
.faq-topic-list button.active {
  background: #f0f2f5;
}

.faq-chat {
  padding: 1rem 0.75rem 2rem;
  background:
    linear-gradient(180deg, rgba(229, 221, 213, 0.35), rgba(229, 221, 213, 0.35)),
    repeating-linear-gradient(
      45deg,
      var(--wa-bg) 0,
      var(--wa-bg) 12px,
      var(--wa-bg-pattern) 12px,
      var(--wa-bg-pattern) 24px
    );
}

.message {
  display: flex;
  margin: 0.35rem 0;
  scroll-margin-top: 7rem;
}

.message.incoming {
  justify-content: flex-start;
}

.message.outgoing {
  justify-content: flex-end;
}

.message.note,
.message.misc {
  justify-content: flex-start;
}

.message.note .bubble,
.message.misc .bubble {
  background: var(--bubble-note);
  width: 100%;
  max-width: 100%;
}

.bubble {
  max-width: min(88%, 720px);
  padding: 0.45rem 0.65rem 0.35rem;
  border-radius: 8px;
  box-shadow: var(--shadow);
  position: relative;
}

.incoming .bubble {
  background: var(--bubble-in);
  border-top-left-radius: 0;
}

.outgoing .bubble {
  background: var(--bubble-out);
  border-top-right-radius: 0;
}

.bubble.highlight {
  outline: 2px solid #f5c542;
  outline-offset: 2px;
}

.bubble-meta {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.2rem;
  font-size: 0.68rem;
  color: var(--muted);
}

.bubble-meta .ref {
  font-weight: 700;
  color: #128c7e;
}

.bubble-meta .role {
  font-weight: 600;
}

.reply-quote {
  display: block;
  border-left: 4px solid var(--quote-bar);
  background: rgba(6, 182, 109, 0.08);
  padding: 0.3rem 0.45rem;
  margin-bottom: 0.35rem;
  border-radius: 4px;
  color: #1f2d2a;
  font-size: 0.78rem;
  cursor: pointer;
  text-align: left;
  width: 100%;
}

.reply-quote:hover {
  background: rgba(6, 182, 109, 0.16);
}

.bubble-text {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.92rem;
}

.bubble-text a {
  color: #027eb5;
}

.bubble-images {
  margin-top: 0.5rem;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.message.note .bubble-images,
.message.misc .bubble-images {
  display: block;
}

.bubble-images img {
  max-width: 240px;
  height: auto;
  display: block;
  border-radius: 6px;
  box-shadow: 0 1px 0 rgba(0,0,0,0.06);
}

.message.note .bubble-images img,
.message.misc .bubble-images img {
  max-width: 100%;
  width: 100%;
}

.backrefs {
  margin-top: 0.35rem;
  font-size: 0.7rem;
  color: var(--muted);
}

.backrefs button {
  border: 0;
  background: transparent;
  color: #027eb5;
  cursor: pointer;
  padding: 0;
  font-size: inherit;
}

.message.hidden {
  display: none;
}

.faq-status {
  text-align: center;
  padding: 2rem;
  color: var(--muted);
}

@media (max-width: 900px) {
  .faq-layout {
    grid-template-columns: 1fr;
  }

  .faq-sidebar {
    border-right: 0;
    border-bottom: 1px solid #d1d7db;
    max-height: 180px;
  }
}

@media print {
  body {
    background: #fff;
  }

  .faq-header,
  .faq-sidebar,
  .faq-toolbar,
  .backrefs button {
    display: none !important;
  }

  .faq-layout {
    display: block;
  }

  .faq-chat {
    background: none;
    padding: 0;
  }

  .bubble {
    box-shadow: none;
    border: 1px solid #ccc;
    break-inside: avoid;
    max-width: 100% !important;
  }

  .message.note .bubble,
  .message.misc .bubble {
    min-height: 45vh;
  }

  .message.note .bubble-images img,
  .message.misc .bubble-images img {
    max-width: 100%;
    width: 100%;
  }

  .reply-quote::after {
    content: " (see " attr(data-print-ref) ")";
    font-style: italic;
    color: #444;
  }

  .bubble-meta .ref::before {
    content: "[";
  }

  .bubble-meta .ref::after {
    content: "]";
  }

  .message.hidden {
    display: flex !important;
  }
}
