/* =========================================================
 * SL Chat — styles.css
 * Design system on top of Tailwind (CDN build).
 * Brand colors are driven by CSS variables so the admin
 * Appearance page can re-theme the whole site live.
 * ========================================================= */

:root {
  --sl-primary: #7c3aed;
  --sl-secondary: #ec4899;
  --sl-dark-bg: #0d0a16;
  --sl-light-bg: #faf8ff;
  --sl-radius: 1rem;
}

html {
  scroll-behavior: smooth;
}

body {
  background-color: var(--sl-light-bg);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    'Segoe UI',
    Roboto,
    'Noto Sans Sinhala',
    'Noto Sans Tamil',
    sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.dark body {
  background-color: var(--sl-dark-bg);
}

/* ---------- brand helpers ---------- */

.btn-primary {
  background-image: linear-gradient(135deg, var(--sl-primary), color-mix(in srgb, var(--sl-secondary) 55%, var(--sl-primary)));
  border-radius: calc(var(--sl-radius) * 0.75);
}
.btn-primary:hover {
  filter: brightness(1.08);
}

.text-brand {
  color: var(--sl-primary);
}
.bg-brand-soft {
  background-color: color-mix(in srgb, var(--sl-primary) 12%, transparent);
}
.border-brand-soft {
  border-color: color-mix(in srgb, var(--sl-primary) 35%, transparent);
}

.brand-gradient-text {
  background-image: linear-gradient(120deg, var(--sl-primary), var(--sl-secondary));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: calc(var(--sl-radius) * 0.7);
  color: #fff;
  font-size: 1.15rem;
  background-image: linear-gradient(135deg, var(--sl-primary), var(--sl-secondary));
  box-shadow: 0 8px 20px -8px color-mix(in srgb, var(--sl-primary) 70%, transparent);
  flex-shrink: 0;
}
.logo-mark.sm {
  width: 2rem;
  height: 2rem;
  font-size: 1rem;
}

.card {
  border-radius: var(--sl-radius);
}

/* ---------- glassmorphism (used sparingly) ---------- */

.glass {
  background-color: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
}
.dark .glass {
  background-color: rgba(15, 23, 42, 0.66);
}

.glass-strong {
  background-color: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(18px) saturate(1.5);
  -webkit-backdrop-filter: blur(18px) saturate(1.5);
}
.dark .glass-strong {
  background-color: rgba(13, 19, 33, 0.94);
}

/* ---------- hero glow / aurora background ---------- */

.hero-bg {
  position: relative;
  overflow: hidden;
}
.hero-bg::before,
.hero-bg::after {
  content: '';
  position: absolute;
  border-radius: 9999px;
  filter: blur(90px);
  opacity: 0.5;
  pointer-events: none;
}
.hero-bg::before {
  width: 480px;
  height: 480px;
  top: -180px;
  left: -120px;
  background: color-mix(in srgb, var(--sl-primary) 45%, transparent);
}
.hero-bg::after {
  width: 420px;
  height: 420px;
  bottom: -200px;
  right: -100px;
  background: color-mix(in srgb, var(--sl-secondary) 40%, transparent);
}
.dark .hero-bg::before,
.dark .hero-bg::after {
  opacity: 0.28;
}

/* ---------- chat bubbles ---------- */

.bubble {
  max-width: min(78%, 560px);
  padding: 0.55rem 0.85rem;
  border-radius: 1.1rem;
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
  position: relative;
  font-size: 0.925rem;
}
.bubble-in {
  align-self: flex-start;
  background-color: #fff;
  color: #1e293b;
  border: 1px solid rgb(226 232 240);
  border-bottom-left-radius: 0.35rem;
}
.dark .bubble-in {
  background-color: #1e293b;
  color: #e2e8f0;
  border-color: rgb(51 65 85);
}
.bubble-out {
  align-self: flex-end;
  color: #fff;
  border-bottom-right-radius: 0.35rem;
  background-image: linear-gradient(135deg, var(--sl-primary), color-mix(in srgb, var(--sl-secondary) 40%, var(--sl-primary)));
}
.bubble-sys {
  align-self: center;
  max-width: 92%;
  text-align: center;
  font-size: 0.75rem;
  padding: 0.3rem 0.9rem;
  border-radius: 9999px;
  background-color: rgba(100, 116, 139, 0.12);
  color: #64748b;
}
.msg-meta {
  font-size: 0.65rem;
  opacity: 0.65;
  margin-top: 0.2rem;
  display: inline-flex;
  gap: 0.4rem;
  align-items: center;
}
.bubble-out .msg-meta {
  color: rgba(255, 255, 255, 0.85);
}
.bubble-in .msg-meta {
  color: #94a3b8;
}

/* ---------- typing indicator ---------- */

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

/* ---------- matching screen ---------- */

.pulse-ring {
  position: relative;
}
.pulse-ring::before,
.pulse-ring::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 9999px;
  border: 2px solid color-mix(in srgb, var(--sl-primary) 60%, transparent);
  animation: pulse-ring 2.2s cubic-bezier(0.4, 0, 0.2, 1) infinite;
  pointer-events: none;
}
.pulse-ring::after {
  animation-delay: 1.1s;
}
@keyframes pulse-ring {
  0% {
    transform: scale(0.85);
    opacity: 0.9;
  }
  80%,
  100% {
    transform: scale(1.7);
    opacity: 0;
  }
}

.orbit {
  animation: orbit-spin 1.4s linear infinite;
}
@keyframes orbit-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- animations ---------- */

.animate-fade-in {
  animation: fade-in 0.25s ease-out both;
}
.animate-modal-up {
  animation: modal-up 0.28s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.animate-toast-in {
  animation: toast-in 0.25s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.animate-toast-out {
  animation: toast-out 0.18s ease-in forwards;
}
.animate-rise {
  animation: rise 0.45s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.animate-pop {
  animation: pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.animate-msg-in {
  animation: msg-in 0.22s ease-out both;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}
@keyframes modal-up {
  from {
    opacity: 0;
    transform: translateY(24px) scale(0.97);
  }
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.96);
  }
}
@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(6px) scale(0.98);
  }
}
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
}
@keyframes pop {
  from {
    opacity: 0;
    transform: scale(0.6);
  }
}
@keyframes msg-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* staggered landing entrance */
.stagger > * {
  animation: rise 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.stagger > *:nth-child(1) { animation-delay: 0.02s; }
.stagger > *:nth-child(2) { animation-delay: 0.08s; }
.stagger > *:nth-child(3) { animation-delay: 0.14s; }
.stagger > *:nth-child(4) { animation-delay: 0.2s; }
.stagger > *:nth-child(5) { animation-delay: 0.26s; }
.stagger > *:nth-child(6) { animation-delay: 0.32s; }

/* ---------- scrollbars ---------- */

.slim-scroll::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
.slim-scroll::-webkit-scrollbar-thumb {
  background: rgba(100, 116, 139, 0.35);
  border-radius: 999px;
}
.slim-scroll::-webkit-scrollbar-track {
  background: transparent;
}
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(100, 116, 139, 0.35) transparent;
}

/* ---------- accessibility ---------- */

:focus-visible {
  outline: 2px solid var(--sl-primary);
  outline-offset: 2px;
  border-radius: 6px;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
}
.skip-link:focus {
  left: 8px;
  top: 8px;
  padding: 8px 14px;
  background: var(--sl-primary);
  color: #fff;
  border-radius: 8px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- mobile app feel for the chat page ---------- */

.chat-shell {
  /* iPhone notch / home indicator */
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.chat-messages {
  overscroll-behavior: contain;
}

/* keep iOS from zooming when focusing the input */
@media (max-width: 640px) {
  input[type='text'],
  textarea,
  select {
    font-size: 16px;
  }
}

/* ---------- shared icon button ---------- */

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: calc(var(--sl-radius) * 0.6);
  color: rgb(100 116 139);
  transition: background-color 0.15s, color 0.15s, transform 0.1s;
}
.icon-btn:hover {
  background-color: rgba(148, 163, 184, 0.18);
  color: rgb(51 65 85);
}
.dark .icon-btn {
  color: rgb(148 163 184);
}
.dark .icon-btn:hover {
  background-color: rgba(71, 85, 105, 0.35);
  color: rgb(226 232 240);
}
.icon-btn:active {
  transform: scale(0.92);
}

/* ---------- tables (admin) ---------- */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.data-table th {
  text-align: left;
  font-weight: 600;
  padding: 0.65rem 0.85rem;
  white-space: nowrap;
  color: #475569;
  background: rgba(148, 163, 184, 0.08);
  cursor: pointer;
  user-select: none;
}
.data-table th .sort-ind {
  opacity: 0.4;
  font-size: 0.7em;
}
.data-table th[data-active-sort='true'] .sort-ind {
  opacity: 1;
}
.data-table td {
  padding: 0.65rem 0.85rem;
  border-top: 1px solid rgba(148, 163, 184, 0.18);
  vertical-align: middle;
}
.dark .data-table td {
  border-top-color: rgba(51, 65, 85, 0.6);
}
.data-table tbody tr:hover {
  background: color-mix(in srgb, var(--sl-primary) 6%, transparent);
}

/* ---------- form controls shared look ---------- */

.input {
  width: 100%;
  border-radius: calc(var(--sl-radius) * 0.65);
  border: 1px solid rgb(203 213 225);
  background: #fff;
  padding: 0.62rem 0.85rem;
  font-size: 0.925rem;
  color: #0f172a;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus {
  outline: none;
  border-color: var(--sl-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--sl-primary) 22%, transparent);
}
.dark .input {
  background: rgb(15 23 42);
  border-color: rgb(51 65 85);
  color: #e2e8f0;
}
.dark .input:focus {
  border-color: var(--sl-primary);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border-radius: 999px;
  padding: 0.14rem 0.6rem;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}
