/* Question page (/): one card that fills the window, so it also fits an iframe next to a video. */
:root {
  --c-bg: #eef3f1;
  --c-card: #fff;
  --c-line: #e8eeec;
  --c-text: #1d2b29;
  --c-strong: #123331;
  --c-muted: #6b7c79;
  --c-accent: #17B066;
  --c-accent-ink: #0f7a4a;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: 'Noto Sans Thai', system-ui, sans-serif;
}

/* inside an iframe the page has no outer margin */
.ch {
  height: 100%;
  padding: clamp(0px, 2vw, 24px);
  display: flex;
  justify-content: center;
}

.ch-card {
  width: 100%;
  max-width: 760px;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--c-card);
  border-radius: clamp(0px, 2vw, 18px);
  box-shadow: 0 12px 40px -24px rgba(18, 51, 49, .45);
  overflow: hidden;
}

.ch-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--c-line);
}

.ch-head h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--c-strong);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ch-head i {
  color: var(--c-accent);
}

.ch-me {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: 13px;
  color: var(--c-muted);
}

.ch-me[hidden] {
  display: none;
}

.ch-me__name {
  max-width: 34vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--c-strong);
  font-weight: 500;
}

.ch-link {
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  color: var(--c-accent-ink);
  text-decoration: underline;
  cursor: pointer;
}

.ch-pin {
  padding: 10px 16px;
  background: #fff8e6;
  border-bottom: 1px solid #f3e3b8;
  font-size: 14px;
}

.ch-pin[hidden] {
  display: none;
}

.ch-pin__label {
  font-size: 11.5px;
  font-weight: 600;
  color: #9a6b00;
  letter-spacing: .04em;
}

.ch-pin__text {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.ch-pin.is-open .ch-pin__text {
  -webkit-line-clamp: unset;
}

.ch-pin__more {
  border: 0;
  background: none;
  padding: 0;
  font-size: 12.5px;
  color: #9a6b00;
  text-decoration: underline;
}

.ch-pin__more[hidden] {
  display: none;
}

.ch-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 0;
  overscroll-behavior: contain;
}

.ch-msg {
  display: flex;
  gap: 10px;
  padding: 8px 16px;
}

.ch-avatar {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--c-line);
  color: #3d4f4c;
  font-size: 12px;
  font-weight: 600;
}

.ch-msg.is-admin .ch-avatar {
  background: var(--c-strong);
  color: #fff;
}

.ch-msg__meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--c-muted);
}

.ch-msg__name {
  font-weight: 600;
  color: var(--c-strong);
}

.ch-msg.is-mine .ch-msg__name {
  color: var(--c-accent-ink);
}

.ch-msg__text {
  font-size: 14.5px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.ch-msg__text a {
  color: var(--c-accent-ink);
}

.ch-msg.is-pending {
  opacity: .7;
}

.ch-tag {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: #fff3d6;
  color: #9a6b00;
}

.ch-empty {
  text-align: center;
  color: #8a9a97;
  padding: 40px 16px;
  font-size: 14px;
}

.ch-compose {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--c-line);
  background: #fafcfb;
}

.ch-compose[hidden],
.ch-closed[hidden],
.ch-name[hidden] {
  display: none;
}

.ch-compose textarea,
.ch-name input {
  flex: 1;
  min-width: 0;
  border: 1px solid #cfe0db;
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  font-size: 14.5px;
  line-height: 1.4;
  color: var(--c-text);
  background: #fff;
}

.ch-compose textarea {
  resize: none;
  height: 44px;
  max-height: 120px;
}

.ch-compose textarea:focus,
.ch-name input:focus {
  outline: none;
  border-color: var(--c-accent);
  box-shadow: 0 0 0 3px rgba(23, 176, 102, .15);
}

.ch-send {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border: 0;
  border-radius: 12px;
  background: var(--c-accent);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}

.ch-send:disabled {
  opacity: .5;
}

/* first visit: ask for the name */
.ch-name {
  padding: 14px 16px 16px;
  border-top: 1px solid var(--c-line);
  background: #fafcfb;
}

.ch-name label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--c-strong);
  margin-bottom: 8px;
}

.ch-name__row {
  display: flex;
  gap: 8px;
}

.ch-btn {
  flex-shrink: 0;
  border: 0;
  border-radius: 12px;
  padding: 0 18px;
  min-height: 44px;
  background: var(--c-accent);
  color: #fff;
  font: inherit;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
}

.ch-closed {
  padding: 14px 16px;
  border-top: 1px solid var(--c-line);
  background: #fafcfb;
  text-align: center;
  color: var(--c-muted);
  font-size: 14px;
}

.ch-toasts {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 380px);
}

.ch-toast {
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--c-strong);
  color: #fff;
  font-size: 14px;
  box-shadow: 0 12px 30px -12px rgba(0, 0, 0, .5);
  animation: chIn .2s ease-out;
}

@keyframes chIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .ch-toast {
    animation: none;
  }
}
