/* Simple247 Web AI chat — full-viewport, mobile-first conversation shell.
   Modelled on the service-booking-ai widget but without a launcher or tabs:
   this page IS the conversation, opened from the missed-call link SMS. */

:root {
  --s247-primary: #0284c7;
  --s247-primary-dark: #0c4a6e;
  --s247-ink: #0f172a;
  --s247-muted: #475569;
  --s247-border: #e2e8f0;
  --s247-bg: #f1f5f9;
  --s247-surface: #ffffff;
  --s247-ai-bg: #ffffff;
  --s247-you-bg: linear-gradient(135deg, #0284c7, #0c4a6e);
  --s247-you-ink: #ffffff;
  --s247-warn: #b45309;
  --s247-ok: #047857;
  --s247-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --s247-primary: #38bdf8;
    --s247-primary-dark: #0ea5e9;
    --s247-ink: #e2e8f0;
    --s247-muted: #94a3b8;
    --s247-border: #1e293b;
    --s247-bg: #0b1220;
    --s247-surface: #0f172a;
    --s247-ai-bg: #1e293b;
    --s247-you-bg: linear-gradient(135deg, #0284c7, #0369a1);
    --s247-you-ink: #f8fafc;
    --s247-warn: #fbbf24;
    --s247-ok: #34d399;
    --s247-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  }
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--s247-bg);
  color: var(--s247-ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

.app {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  height: 100dvh;
  min-height: 100vh;
  background: var(--s247-bg);
}

/* Header */
.app-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  padding-top: calc(14px + env(safe-area-inset-top));
  background: linear-gradient(135deg, var(--s247-primary-dark), var(--s247-primary));
  color: #fff;
}

@media (prefers-color-scheme: dark) {
  .app-header {
    background: linear-gradient(135deg, #082f49, #0c4a6e);
  }
}

.app-mark {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.18);
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.02em;
}

.app-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Thread */
.thread {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 18px 16px 6px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bubble {
  max-width: 84%;
  padding: 10px 14px;
  border-radius: 16px;
  box-shadow: var(--s247-shadow);
  animation: rise 0.18s ease-out;
}

.bubble p {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.bubble-ai {
  align-self: flex-start;
  background: var(--s247-ai-bg);
  color: var(--s247-ink);
  border: 1px solid var(--s247-border);
  border-bottom-left-radius: 5px;
}

.bubble-you {
  align-self: flex-end;
  background: var(--s247-you-bg);
  color: var(--s247-you-ink);
  border-bottom-right-radius: 5px;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}

/* Typing indicator */
.bubble-typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 14px 16px;
}

.bubble-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--s247-muted);
  opacity: 0.5;
  animation: blink 1.2s infinite ease-in-out;
}

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

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

@keyframes blink {
  0%, 80%, 100% {
    transform: scale(0.7);
    opacity: 0.4;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Notice (expired / unknown link) */
.notice {
  margin: 24px 12px;
  padding: 18px 18px;
  border-radius: 14px;
  background: var(--s247-surface);
  border: 1px solid var(--s247-border);
  color: var(--s247-ink);
  text-align: center;
  box-shadow: var(--s247-shadow);
}

.notice p {
  margin: 0;
}

/* Status line */
.status {
  flex: 0 0 auto;
  margin: 0;
  padding: 6px 18px;
  font-size: 13px;
  color: var(--s247-muted);
  text-align: center;
}

.status-warn {
  color: var(--s247-warn);
}

.status-ok {
  color: var(--s247-ok);
}

.status[hidden] {
  display: none;
}

/* Composer */
.composer {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  background: var(--s247-surface);
  border-top: 1px solid var(--s247-border);
}

.composer[hidden] {
  display: none;
}

#message {
  flex: 1 1 auto;
  resize: none;
  max-height: 140px;
  padding: 11px 14px;
  border: 1px solid var(--s247-border);
  border-radius: 20px;
  background: var(--s247-bg);
  color: var(--s247-ink);
  font: inherit;
  line-height: 1.4;
  outline: none;
}

#message:focus {
  border-color: var(--s247-primary);
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.18);
}

#message:disabled {
  opacity: 0.7;
}

#send {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--s247-primary), var(--s247-primary-dark));
  color: #fff;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.15s ease;
}

#send:hover:not(:disabled) {
  transform: translateY(-1px);
}

#send:disabled {
  opacity: 0.45;
  cursor: default;
}

#send:focus-visible {
  outline: 2px solid var(--s247-primary);
  outline-offset: 2px;
}

.app-foot {
  flex: 0 0 auto;
  margin: 0;
  padding: 6px 0 8px;
  padding-bottom: calc(6px + env(safe-area-inset-bottom));
  text-align: center;
  font-size: 11px;
  letter-spacing: 0.03em;
  color: var(--s247-muted);
  background: var(--s247-surface);
}

/* When the composer is hidden (terminal state) the footer sits on its own. */
.composer[hidden] + .app-foot {
  border-top: 1px solid var(--s247-border);
  padding-top: 10px;
}

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