/* ============================================================
   chat.247ch.at — full-page chat client
   Mobile-first. Iframe-friendly. Mirrors the widget's bubble +
   color tokens but renders as a fullscreen single-column app
   instead of a floating launcher bubble.
   ============================================================ */

:root {
  --c247-brand: #287ff0;
  --c247-brand-dark: #0753b7;
  --c247-brand-fg: #ffffff;
  --c247-ink: #10213f;
  --c247-ink-soft: #58708b;
  --c247-bg: #ffffff;
  --c247-bg-soft: #f5f9ff;
  --c247-line: #e6eff8;
  --c247-bubble-them: #eef3f9;
  --c247-bubble-them-fg: #10213f;
  --c247-radius-md: 14px;
  --c247-radius-sm: 10px;
  --c247-shadow-bubble: 0 2px 8px rgba(0,0,0,0.08);
  --c247-shadow-header: 0 1px 0 rgba(0,0,0,0.06);
  --c247-header-h: 52px;
}

html.chat247-theme-dark,
html.chat247-theme-auto {
  /* auto = honor system preference; dark overrides */
}

@media (prefers-color-scheme: dark) {
  html.chat247-theme-auto {
    --c247-ink: #e8eef7;
    --c247-ink-soft: #93a6c2;
    --c247-bg: #0f1620;
    --c247-bg-soft: #161f2c;
    --c247-line: #243349;
    --c247-bubble-them: #1d2a3c;
    --c247-bubble-them-fg: #e8eef7;
  }
}
html.chat247-theme-dark {
  --c247-ink: #e8eef7;
  --c247-ink-soft: #93a6c2;
  --c247-bg: #0f1620;
  --c247-bg-soft: #161f2c;
  --c247-line: #243349;
  --c247-bubble-them: #1d2a3c;
  --c247-bubble-them-fg: #e8eef7;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;  /* the thread scrolls, not the page */
  background: var(--c247-bg);
  color: var(--c247-ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Arial, Helvetica, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

/* In embed mode the parent already paints the bg — keep transparent so the
   iframe wrapper isn't doubled. */
html.chat247-embed,
html.chat247-embed body { background: transparent; }

/* ---------------------------------------------------------------- App shell */
.chat247-app {
  display: flex;
  flex-direction: column;
  height: 100dvh;          /* dvh for iOS Safari address-bar correctness */
  height: 100vh;            /* fallback */
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  background: var(--c247-bg);
  position: relative;
}

@media (min-width: 801px) {
  body { background: var(--c247-bg-soft); }
  html.chat247-embed body { background: transparent; }
  .chat247-app {
    box-shadow: 0 0 0 1px var(--c247-line);
  }
}

/* ---------------------------------------------------------------- Header */
.chat247-app-header {
  height: var(--c247-header-h);
  flex: 0 0 var(--c247-header-h);
  display: flex;
  align-items: center;
  padding: 0 14px;
  border-bottom: 1px solid var(--c247-line);
  background: var(--c247-bg);
  box-shadow: var(--c247-shadow-header);
  gap: 8px;
  z-index: 2;
}

.chat247-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
}

.chat247-brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--c247-brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c247-brand) 25%, transparent);
  flex: 0 0 auto;
}

.chat247-brand-name {
  font-weight: 600;
  font-size: 15px;
  color: var(--c247-ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.chat247-status {
  font-size: 12px;
  color: var(--c247-ink-soft);
  margin-left: 4px;
  flex: 0 0 auto;
}
.chat247-status[data-status="online"]::before { content: "● "; color: #20c764; }
.chat247-status[data-status="connecting"]::before { content: "● "; color: #f0a020; }
.chat247-status[data-status="offline"]::before { content: "● "; color: #d04040; }

.chat247-header-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

/* ---------------------------------------------------------------- Buttons */
.chat247-btn {
  border: 0;
  background: transparent;
  cursor: pointer;
  font: inherit;
  color: inherit;
  padding: 8px;
  border-radius: var(--c247-radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 120ms ease;
}
.chat247-btn:hover { background: var(--c247-bg-soft); }
.chat247-btn:active { background: var(--c247-line); }
.chat247-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.chat247-btn-icon svg {
  width: 20px;
  height: 20px;
  display: block;
}

.chat247-btn-send {
  background: var(--c247-brand);
  color: var(--c247-brand-fg);
  width: 40px;
  height: 40px;
  padding: 0;
  flex: 0 0 40px;
}
.chat247-btn-send:hover:not(:disabled) { background: var(--c247-brand-dark); }
.chat247-btn-send:disabled { background: var(--c247-line); color: var(--c247-ink-soft); }
.chat247-btn-send svg { width: 18px; height: 18px; }

.chat247-only-embed { display: none; }
html.chat247-embed .chat247-only-embed { display: inline-flex; }

/* ---------------------------------------------------------------- Thread */
.chat247-thread {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 14px 4px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.chat247-date-divider {
  align-self: center;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--c247-ink-soft);
  background: var(--c247-bg-soft);
  padding: 4px 10px;
  border-radius: 999px;
  margin: 10px 0 4px;
}

.chat247-row {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  gap: 2px;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 180ms ease, transform 180ms ease;
}
.chat247-row.in { opacity: 1; transform: translateY(0); }

.chat247-row.visitor { align-self: flex-end; align-items: flex-end; }
.chat247-row.operator,
.chat247-row.system { align-self: flex-start; align-items: flex-start; }

.chat247-name {
  font-size: 11px;
  color: var(--c247-ink-soft);
  margin: 0 8px 2px;
  font-weight: 500;
}

.chat247-bubble {
  padding: 9px 13px;
  border-radius: var(--c247-radius-md);
  background: var(--c247-bubble-them);
  color: var(--c247-bubble-them-fg);
  box-shadow: var(--c247-shadow-bubble);
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  line-height: 1.42;
  font-size: 15px;
  max-width: 100%;
}

.chat247-row.visitor .chat247-bubble {
  background: var(--c247-brand);
  color: var(--c247-brand-fg);
  border-bottom-right-radius: 4px;
}
.chat247-row.operator .chat247-bubble {
  border-bottom-left-radius: 4px;
}
.chat247-row.system .chat247-bubble {
  background: transparent;
  color: var(--c247-ink-soft);
  font-style: italic;
  box-shadow: none;
  font-size: 13px;
  padding: 4px 8px;
}

.chat247-bubble a {
  color: inherit;
  text-decoration: underline;
}
.chat247-bubble img {
  max-width: 100%;
  border-radius: var(--c247-radius-sm);
  margin: 6px 0;
  display: block;
}

.chat247-time {
  font-size: 11px;
  color: var(--c247-ink-soft);
  margin: 2px 8px 0;
}

/* On wide screens timestamps hide until hover for a cleaner look. */
@media (min-width: 801px) {
  .chat247-time { opacity: 0; transition: opacity 120ms ease; }
  .chat247-row:hover .chat247-time { opacity: 1; }
}

/* ---------------------------------------------------------------- Typing */
.chat247-typing {
  flex: 0 0 auto;
  padding: 0 18px 4px;
  height: 22px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--c247-ink-soft);
  visibility: hidden;
  opacity: 0;
  transition: opacity 150ms ease;
}
.chat247-typing.active { visibility: visible; opacity: 1; }

.chat247-typing-dots {
  display: inline-flex;
  gap: 3px;
}
.chat247-typing-dots span {
  width: 5px;
  height: 5px;
  background: currentColor;
  border-radius: 50%;
  display: inline-block;
  animation: chat247-typing-bounce 1.2s infinite ease-in-out;
}
.chat247-typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.chat247-typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat247-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%           { transform: translateY(-3px); opacity: 1; }
}

/* ---------------------------------------------------------------- Composer */
.chat247-composer {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0));
  border-top: 1px solid var(--c247-line);
  background: var(--c247-bg);
  position: relative;
}

.chat247-attach-input { display: none; }

.chat247-chips {
  position: absolute;
  bottom: 100%;
  left: 10px;
  right: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0;
  pointer-events: none;
}
.chat247-chips.has-files {
  padding: 8px 0;
  pointer-events: auto;
}

.chat247-chip {
  background: var(--c247-bg-soft);
  border: 1px solid var(--c247-line);
  border-radius: 999px;
  font-size: 12px;
  padding: 4px 8px 4px 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--c247-ink);
}
.chat247-chip-x {
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
  color: var(--c247-ink-soft);
  display: inline-flex;
  width: 16px;
  height: 16px;
}
.chat247-chip-x svg { width: 14px; height: 14px; }

.chat247-input {
  flex: 1 1 auto;
  min-width: 0;
  border: 1px solid var(--c247-line);
  background: var(--c247-bg-soft);
  color: var(--c247-ink);
  border-radius: 20px;
  padding: 10px 14px;
  font: inherit;
  font-size: 15px;
  line-height: 1.4;
  resize: none;
  max-height: 120px;
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.chat247-input:focus {
  border-color: var(--c247-brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c247-brand) 18%, transparent);
}

/* ---------------------------------------------------------------- Footer */
.chat247-footer {
  flex: 0 0 auto;
  text-align: center;
  font-size: 11px;
  color: var(--c247-ink-soft);
  padding: 4px 0 6px;
  background: var(--c247-bg);
}
.chat247-footer a {
  color: var(--c247-ink-soft);
  text-decoration: none;
}
.chat247-footer a:hover { text-decoration: underline; }
.chat247-footer[hidden] { display: none; }

/* ---------------------------------------------------------------- Toast */
.chat247-toast {
  position: absolute;
  left: 50%;
  bottom: 80px;
  transform: translateX(-50%) translateY(20px);
  background: rgba(16, 33, 63, 0.95);
  color: #fff;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 180ms ease, transform 180ms ease;
  z-index: 5;
  max-width: 80%;
  text-align: center;
}
.chat247-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------------------------------------------------------------- Error screen */
.chat247-error-screen {
  position: absolute;
  inset: 0;
  background: var(--c247-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 10;
}
.chat247-error-card {
  max-width: 320px;
  text-align: center;
  color: var(--c247-ink);
}
.chat247-error-card h2 {
  margin: 0 0 10px;
  font-size: 18px;
}
.chat247-error-card p {
  margin: 0;
  color: var(--c247-ink-soft);
  font-size: 14px;
}
.chat247-error-card code {
  background: var(--c247-bg-soft);
  padding: 2px 5px;
  border-radius: 4px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
}
