/* SimpleLiveChat - glassmorphic WhatsApp-style UI */

:root {
  --bg: #0b1220;
  --bg-2: #101a2e;
  --glass: rgba(255, 255, 255, 0.06);
  --glass-strong: rgba(255, 255, 255, 0.09);
  --glass-border: rgba(255, 255, 255, 0.14);
  --text: #e9eef8;
  --text-dim: #9fb0cc;
  --accent: #00d9a5;
  --accent-2: #21c063;
  --accent-soft: rgba(0, 217, 165, 0.14);
  --bubble-in: rgba(255, 255, 255, 0.10);
  --bubble-out: linear-gradient(135deg, #07c58c 0%, #0aa06e 100%);
  --danger: #ff5d6c;
  --radius-xl: 22px;
  --radius-lg: 18px;
  --radius-md: 14px;
  --shadow: 0 18px 50px rgba(2, 6, 16, 0.45);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #dfe9f5;
    --bg-2: #cfdcee;
    --glass: rgba(255, 255, 255, 0.55);
    --glass-strong: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(13, 32, 64, 0.10);
    --text: #0d2033;
    --text-dim: #51637d;
    --bubble-in: rgba(255, 255, 255, 0.75);
    --shadow: 0 18px 50px rgba(30, 50, 90, 0.18);
  }
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 800px at 85% -10%, #10315a 0%, transparent 60%),
    radial-gradient(1000px 700px at -10% 110%, #0d2a3d 0%, transparent 55%),
    linear-gradient(160deg, var(--bg) 0%, var(--bg-2) 100%);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Animated aurora blobs */
.aurora {
  position: fixed;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.5;
  pointer-events: none;
  z-index: 0;
}
.aurora-1 {
  width: 42vw; height: 42vw;
  background: #0f7a5f;
  top: -12vw; right: -8vw;
  animation: drift1 22s ease-in-out infinite alternate;
}
.aurora-2 {
  width: 36vw; height: 36vw;
  background: #274b8f;
  bottom: -10vw; left: -10vw;
  animation: drift2 26s ease-in-out infinite alternate;
}
.aurora-3 {
  width: 22vw; height: 22vw;
  background: #5b2b8f;
  bottom: 18vh; right: 12vw;
  opacity: 0.3;
  animation: drift3 30s ease-in-out infinite alternate;
}
@keyframes drift1 { to { transform: translate(-6vw, 5vh) scale(1.12); } }
@keyframes drift2 { to { transform: translate(7vw, -4vh) scale(1.08); } }
@keyframes drift3 { to { transform: translate(-4vw, -6vh) scale(1.2); } }
@media (prefers-reduced-motion: reduce) {
  .aurora { animation: none; }
}

.glass {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(22px) saturate(150%);
  -webkit-backdrop-filter: blur(22px) saturate(150%);
}

/* Layout */
.shell {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: min(720px, 100%);
  height: 100dvh;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom));
  gap: 10px;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
}

.avatar-wrap { position: relative; }

.avatar {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 19px;
  color: #04372a;
  background: linear-gradient(135deg, #3ef0b7 0%, #0fbf85 100%);
  box-shadow: 0 4px 14px rgba(15, 191, 133, 0.4);
}

.presence {
  position: absolute;
  right: 1px;
  bottom: 1px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent-2);
  border: 2px solid var(--bg);
  box-shadow: 0 0 8px rgba(33, 192, 99, 0.8);
}

.header-meta { flex: 1; min-width: 0; }

.header-title {
  margin: 0;
  font-size: 16.5px;
  font-weight: 650;
  letter-spacing: 0.1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-sub {
  margin: 2px 0 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-dim);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f5b02e;
  display: inline-block;
}
.status-dot.ok { background: var(--accent-2); box-shadow: 0 0 6px rgba(33,192,99,.7); }
.status-dot.err { background: var(--danger); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--text);
  cursor: pointer;
  transition: transform .15s ease, background .15s ease;
}
.icon-btn:hover { background: var(--glass-strong); transform: translateY(-1px); }
.icon-btn:active { transform: scale(.94); }
.icon-btn svg { width: 19px; height: 19px; }

/* Password gate */
.gate {
  margin: auto;
  width: min(420px, 100%);
  padding: 34px 30px 30px;
  border-radius: var(--radius-xl);
  text-align: center;
  box-shadow: var(--shadow);
}
.gate-icon { font-size: 40px; margin-bottom: 6px; }
.gate h2 { margin: 0 0 6px; font-size: 20px; }
.gate-hint { margin: 0 0 20px; color: var(--text-dim); font-size: 13.5px; line-height: 1.5; }

#gate-form { display: flex; flex-direction: column; gap: 10px; }

#gate-password {
  width: 100%;
  padding: 13px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border .15s ease, box-shadow .15s ease;
}
#gate-password:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
#gate-password::placeholder { color: var(--text-dim); }

.btn-primary {
  padding: 13px 16px;
  border: none;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #12e2a4 0%, #0aa06e 100%);
  color: #04372a;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .15s ease, filter .15s ease;
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:active { transform: scale(.98); }
.btn-primary:disabled { opacity: .6; cursor: default; }

.gate-error {
  margin: 4px 0 0;
  color: var(--danger);
  font-size: 13px;
}

/* Chat */
.chat {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  gap: 10px;
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 4px 4px;
  scroll-behavior: smooth;
}
.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-thumb {
  background: var(--glass-border);
  border-radius: 3px;
}

/* Bubbles */
.bubble-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 86%;
  animation: pop .18s ease-out;
}
@keyframes pop {
  from { opacity: 0; transform: translateY(6px) scale(.97); }
  to { opacity: 1; transform: none; }
}
.bubble-row.out { align-self: flex-end; flex-direction: row-reverse; }
.bubble-row.in { align-self: flex-start; }

.bubble-avatar {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  color: #04372a;
  background: linear-gradient(135deg, #3ef0b7 0%, #0fbf85 100%);
  margin-bottom: 2px;
}

.bubble {
  position: relative;
  padding: 9px 13px 7px;
  border-radius: var(--radius-lg);
  font-size: 14.8px;
  line-height: 1.45;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  border: 1px solid var(--glass-border);
}
.bubble-row.in .bubble {
  background: var(--bubble-in);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border-bottom-left-radius: 6px;
}
.bubble-row.out .bubble {
  background: var(--bubble-out);
  border-color: transparent;
  color: #06281d;
  border-bottom-right-radius: 6px;
  box-shadow: 0 6px 18px rgba(10, 160, 110, 0.28);
}
.bubble-row.error .bubble {
  background: rgba(255, 93, 108, 0.14);
  border-color: rgba(255, 93, 108, 0.4);
  color: var(--text);
}

.bubble a { color: inherit; text-decoration: underline; }
.bubble code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  background: rgba(127, 127, 127, 0.18);
  padding: 1px 5px;
  border-radius: 5px;
}
.bubble pre {
  margin: 6px 0;
  padding: 9px 11px;
  border-radius: 10px;
  background: rgba(6, 12, 24, 0.55);
  overflow-x: auto;
}
.bubble pre code { background: transparent; padding: 0; color: #cde3ff; }
.bubble strong { font-weight: 700; }
.bubble em { font-style: italic; }
.bubble ul, .bubble ol { margin: 4px 0 4px 0; padding-left: 20px; }

.bubble-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  margin-top: 3px;
  font-size: 10.5px;
  opacity: 0.75;
  user-select: none;
}

.tick {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tick.hidden-tick { display: none; }
.tick.second { margin-left: -11px; }
.tick.read { color: #53bdeb; }

/* Typing indicator */
.typing-bubble {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 13px 16px;
}
.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: blink 1.2s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: .15s; }
.typing-dot:nth-child(3) { animation-delay: .3s; }
@keyframes blink {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Suggestions */
.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 0 2px;
}
.suggestions:empty { display: none; }
.suggestion-chip {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: background .15s ease, transform .15s ease;
}
.suggestion-chip:hover { background: var(--accent-soft); transform: translateY(-1px); }

/* Composer */
.composer {
  border-radius: var(--radius-xl);
  padding: 9px 10px 7px;
  box-shadow: var(--shadow);
}
#composer-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
#input {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.4;
  max-height: 132px;
  padding: 8px 6px;
}
#input::placeholder { color: var(--text-dim); }

.send-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #12e2a4 0%, #0aa06e 100%);
  color: #04372a;
  cursor: pointer;
  transition: transform .15s ease, filter .15s ease, opacity .15s ease;
}
.send-btn:hover { filter: brightness(1.07); }
.send-btn:active { transform: scale(.92); }
.send-btn:disabled { opacity: .45; cursor: default; }
.send-btn svg { width: 20px; height: 20px; margin-left: 2px; }

.disclaimer {
  margin: 5px 4px 0;
  font-size: 10.5px;
  color: var(--text-dim);
  text-align: center;
}
.disclaimer:empty { display: none; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  z-index: 50;
  box-shadow: var(--shadow);
  animation: toast-in .2s ease-out;
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@media (max-width: 480px) {
  .shell { padding-left: 8px; padding-right: 8px; }
  .bubble-row { max-width: 92%; }
}
