/* ── Kinly App — Mobile-first Design System ──────────────────────────────── */

:root {
  --purple:       #7C6FCD;
  --purple-dark:  #6457b8;
  --purple-deep:  #4a3fa0;
  --purple-light: #ede9fb;
  --purple-bg:    #EEEEF8;
  --white:        #ffffff;
  --text:         #1a1a2e;
  --text-muted:   #6b7280;
  --border:       #d8d8ee;
  --card-bg:      #ffffff;
  --danger:       #ef4444;
  --success:      #22c55e;
  --radius:       14px;
  --radius-lg:    20px;
  --shadow-sm:    0 2px 8px rgba(124,111,205,0.10);
  --shadow-md:    0 6px 24px rgba(124,111,205,0.15);
  --shadow-lg:    0 16px 48px rgba(0,0,0,0.14);
  --nav-h:        56px;
  --touch:        48px; /* minimum touch target */
}

/* ── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  /* System fonts: SF Pro on iOS/macOS, Segoe UI on Windows, Roboto on Android — all instant, zero network */
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
  color: var(--text);
  background: var(--purple-bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: var(--purple); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg { display: block; max-width: 100%; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; }

/* ── Logo ────────────────────────────────────────────────────────────────── */
.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none !important;
}
.logo-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--purple);
  color: #fff;
  font-weight: 800;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.logo-text {
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.5px;
}
.logo--white .logo-text { color: #fff; }
.logo--white .logo-mark { background: rgba(255,255,255,0.25); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--touch);
  padding: 0 22px;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  text-decoration: none !important;
  transition: background 0.18s, transform 0.12s, box-shadow 0.18s;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--purple);
  color: #fff !important;
  box-shadow: 0 2px 10px rgba(124,111,205,0.35);
}
.btn-primary:hover { background: var(--purple-dark); }

.btn-outline {
  background: transparent;
  color: var(--purple) !important;
  border: 2px solid var(--purple);
}
.btn-outline:hover { background: var(--purple-light); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted) !important;
  border: 1.5px solid var(--border);
  min-height: 40px;
}
.btn-ghost:hover { background: #f3f4f6; }

.btn-white {
  background: #fff;
  color: var(--purple) !important;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.btn-white:hover { background: #f5f3ff; }

.btn-full { width: 100%; }
.btn-sm { min-height: 36px; padding: 0 14px; font-size: 0.85rem; }
.btn-xs { min-height: 30px; padding: 0 10px; font-size: 0.78rem; border-radius: 8px; }
.btn-danger { color: var(--danger) !important; border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; }

.btn-spinner {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  flex-shrink: 0;
}
.btn.loading .btn-text { opacity: 0.7; }
.btn.loading .btn-spinner { display: inline-block; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.auth-method-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.check-success { text-align: center; padding: 12px 0; }

.inline-form { display: inline; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Form fields ─────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; }

.field label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.field-link { font-weight: 400; font-size: 0.82rem; color: var(--purple); }
.field-hint { font-weight: 400; font-size: 0.78rem; color: var(--text-muted); }

/* iOS fix: font-size 16px prevents auto-zoom on focus */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="url"],
input[type="tel"],
textarea,
select {
  width: 100%;
  min-height: var(--touch);
  padding: 0 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px; /* prevents iOS zoom */
  color: var(--text);
  background: #fafafa;
  transition: border-color 0.18s, box-shadow 0.18s;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(124,111,205,0.12);
  background: #fff;
}
input.error { border-color: var(--danger); }
input::placeholder { color: #b0b8cc; }

.input-with-toggle { position: relative; }
.input-with-toggle input { padding-right: 50px; }
.pw-toggle {
  position: absolute;
  right: 0;
  top: 0;
  height: 100%;
  width: 48px;
  background: none;
  border: none;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.pw-toggle svg { width: 20px; height: 20px; }
.pw-toggle:hover { color: var(--purple); }

.field-error { font-size: 0.78rem; color: var(--danger); min-height: 1.1em; }
.form-error {
  font-size: 0.875rem;
  color: var(--danger);
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 10px;
  padding: 12px 14px;
  display: none;
  line-height: 1.5;
}
.form-error.visible { display: block; }

/* ── Join pages (talker + creator) ───────────────────────────────────────── */
.join-page {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Hero section — top half */
.join-hero {
  padding: 48px 24px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0;
}
.join-hero .logo { margin-bottom: 32px; }
.join-role-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 16px;
}
.join-role-pill--talker  { background: #dbeafe; color: #1d4ed8; }
.join-role-pill--creator { background: var(--purple-light); color: var(--purple-deep); }

.join-headline {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.5px;
  margin-bottom: 12px;
}
.join-sub {
  font-size: 1rem;
  color: var(--text-muted);
  line-height: 1.6;
  max-width: 340px;
  margin-bottom: 0;
}

/* Talker hero — warm gradient */
.join-hero--talker {
  background: linear-gradient(160deg, #f0eeff 0%, #e8e0ff 60%, #ddd4ff 100%);
}
/* Creator hero — deeper purple */
.join-hero--creator {
  background: linear-gradient(160deg, #7C6FCD 0%, #6457b8 60%, #4a3fa0 100%);
  color: #fff;
}
.join-hero--creator .join-sub { color: rgba(255,255,255,0.8); }
.join-hero--creator .logo-text { color: #fff; }

/* Form section — bottom half (white card) */
.join-form-section {
  flex: 1;
  background: var(--white);
  border-radius: 24px 24px 0 0;
  margin-top: -20px;
  padding: 32px 24px 48px;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.06);
}

.join-form-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 6px;
}
.join-form-sub {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.join-form { display: flex; flex-direction: column; gap: 16px; }

.join-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: 0.8rem;
  margin: 4px 0;
}
.join-divider::before,
.join-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.join-footer {
  text-align: center;
  margin-top: 20px;
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* Perks list */
.join-perks {
  list-style: none;
  margin: 20px 0 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.join-perks li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.9rem;
}
.join-perks li .perk-icon {
  font-size: 1.1rem;
  flex-shrink: 0;
  margin-top: 1px;
}

/* ── Auth pages (login, reset, magic link, etc.) ─────────────────────────── */
.auth-page {
  min-height: 100dvh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 0;
  background: linear-gradient(160deg, #EEEEF8 0%, #ddd8f8 100%);
}

.auth-container {
  width: 100%;
  max-width: 440px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px 20px;
}

.auth-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  box-shadow: var(--shadow-lg);
}
.auth-card--center { text-align: center; }

.auth-logo { margin-bottom: 28px; }

.auth-heading {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
  line-height: 1.2;
}
.auth-sub {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 28px;
  line-height: 1.5;
}
.auth-form { display: flex; flex-direction: column; gap: 16px; }

.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  color: var(--text-muted);
  font-size: 0.8rem;
}
.auth-divider::before,
.auth-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.auth-footer {
  text-align: center;
  margin-top: 20px;
  font-size: 0.875rem;
  color: var(--text-muted);
}
.check-email-icon { font-size: 3.5rem; margin-bottom: 16px; }

/* ── Top nav ─────────────────────────────────────────────────────────────── */
.top-nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--white);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  box-shadow: var(--shadow-sm);
}
.nav-inner {
  height: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.nav-logo .logo-mark { width: 30px; height: 30px; font-size: 15px; border-radius: 8px; }
.nav-logo .logo-text { font-size: 18px; }

.nav-right { display: flex; align-items: center; gap: 10px; }
.nav-name { font-size: 0.85rem; font-weight: 500; color: var(--text-muted); }

/* ── Role badges ─────────────────────────────────────────────────────────── */
.role-badge {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.role-talker  { background: #dbeafe; color: #1d4ed8; }
.role-creator { background: var(--purple-light); color: var(--purple-deep); }
.role-admin   { background: #fef3c7; color: #92400e; }

/* ── Dashboard layout ────────────────────────────────────────────────────── */
.dashboard-page { background: var(--purple-bg); min-height: 100dvh; }
.dashboard-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: calc(var(--nav-h) + 24px) 16px 40px;
}

.page-header { margin-bottom: 24px; }
.page-title  { font-size: 1.5rem; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.page-sub    { color: var(--text-muted); font-size: 0.9rem; }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.empty-icon { font-size: 3rem; margin-bottom: 16px; }
.empty-state h2 { font-size: 1.1rem; font-weight: 600; margin-bottom: 8px; }
.empty-state p  { color: var(--text-muted); font-size: 0.9rem; }

/* ── Admin grid ──────────────────────────────────────────────────────────── */
.admin-grid { display: flex; flex-direction: column; gap: 16px; }

.admin-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.admin-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.admin-card-header h2 {
  font-size: 0.95rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.count-badge {
  background: var(--purple-light);
  color: var(--purple);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
}

/* ── User list ───────────────────────────────────────────────────────────── */
.user-list, .invite-list { list-style: none; }
.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  border-bottom: 1px solid #f3f4f6;
  flex-wrap: wrap;
}
.user-row:last-child { border-bottom: none; }
.user-info  { flex: 1; min-width: 0; }
.user-name  { display: block; font-size: 0.88rem; font-weight: 600; }
.user-email { display: block; font-size: 0.78rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.user-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.status-badge { padding: 2px 8px; border-radius: 20px; font-size: 0.72rem; font-weight: 600; }
.status-active   { background: #dcfce7; color: #15803d; }
.status-inactive { background: #f3f4f6; color: #6b7280; }
.status-pending  { background: #fef9c3; color: #a16207; }

.invite-row { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-bottom: 1px solid #f3f4f6; flex-wrap: wrap; }
.invite-row:last-child { border-bottom: none; }
.invite-used { opacity: 0.5; }
.invite-info { flex: 1; }
.invite-for     { display: block; font-size: 0.88rem; font-weight: 500; }
.invite-expires { font-size: 0.78rem; color: var(--text-muted); }
.invite-actions { display: flex; gap: 6px; }
.empty-list { padding: 20px; color: var(--text-muted); font-size: 0.875rem; }

/* ── Settings list ───────────────────────────────────────────────────────── */
.settings-list { list-style: none; }
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid #f3f4f6;
}
.settings-row:last-child { border-bottom: none; }
.settings-info { flex: 1; }
.settings-label { display: block; font-size: 0.9rem; font-weight: 500; margin-bottom: 2px; }
.settings-desc  { font-size: 0.78rem; color: var(--text-muted); }

/* iOS-style toggle switch */
.toggle-switch { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: #d1d5db;
  border-radius: 24px;
  cursor: pointer;
  transition: background 0.2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle-switch input:checked + .toggle-slider { background: #7C6FCD; }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ── Modals ──────────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end; /* bottom sheet on mobile */
  justify-content: center;
  padding: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.modal.open { opacity: 1; pointer-events: auto; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(2px);
}
.modal-box {
  position: relative;
  background: var(--white);
  border-radius: 24px 24px 0 0;
  padding: 28px 24px 40px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
  transform: translateY(40px);
  transition: transform 0.25s cubic-bezier(.34,1.2,.64,1);
}
.modal.open .modal-box { transform: translateY(0); }

.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 20px;
}
.modal-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 6px; }
.modal-sub   { color: var(--text-muted); font-size: 0.875rem; margin-bottom: 20px; }
.modal-form  { display: flex; flex-direction: column; gap: 14px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; padding-top: 4px; }

.copy-row { display: flex; gap: 8px; align-items: center; }
.copy-row input { flex: 1; font-size: 0.82rem; }
.invite-result { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.invite-result label { font-size: 0.82rem; font-weight: 600; }

/* ── Toast ───────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  width: calc(100vw - 32px);
  max-width: 360px;
}
.toast {
  padding: 13px 18px;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 500;
  color: #fff;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
  animation: toast-in 0.22s ease;
  pointer-events: auto;
  text-align: center;
}
.toast-success { background: #16a34a; }
.toast-error   { background: var(--danger); }
.toast-info    { background: var(--purple); }
.toast-out     { animation: toast-out 0.22s ease forwards; }

@keyframes toast-in  { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(12px); } }

/* ── Utilities ───────────────────────────────────────────────────────────── */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
.text-center { text-align: center; }

/* ── Tablet+ (min-width: 640px) ──────────────────────────────────────────── */
@media (min-width: 640px) {
  .join-hero { padding: 56px 40px 48px; }
  .join-headline { font-size: 2.4rem; }
  .join-form-section { padding: 40px 40px 56px; border-radius: 28px 28px 0 0; }

  .auth-page { padding: 24px 16px; align-items: center; }
  .auth-container { min-height: auto; }
  .auth-card { padding: 40px 36px; }

  .modal { align-items: center; padding: 16px; }
  .modal-box { border-radius: var(--radius-lg); transform: translateY(10px) scale(0.97); }
  .modal.open .modal-box { transform: translateY(0) scale(1); }
  .modal-handle { display: none; }

  .admin-grid { display: grid; grid-template-columns: 1fr 1fr; }
  .admin-card--full { grid-column: 1 / -1; }

  .dashboard-main { padding-left: 24px; padding-right: 24px; }

  #toast-container { left: auto; right: 20px; transform: none; width: auto; }
  .toast { text-align: left; }
}

@media (min-width: 1024px) {
  .join-page { flex-direction: row; min-height: 100dvh; }
  .join-hero {
    flex: 0 0 42%;
    min-height: 100dvh;
    border-radius: 0;
    padding: 48px 48px;
    justify-content: center;
    text-align: left;
    align-items: flex-start;
  }
  .join-hero .logo { margin-bottom: 48px; }
  .join-hero--talker { background: linear-gradient(160deg, #e8e4ff 0%, #d4ccff 100%); }
  .join-sub { max-width: 360px; }
  .join-perks { margin-top: 32px; }

  .join-form-section {
    flex: 1;
    margin-top: 0;
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px;
    box-shadow: none;
    min-height: 100dvh;
  }
  .join-form-inner {
    width: 100%;
    max-width: 400px;
  }

  .nav-name { display: flex; }
}

/* ── Conversation cards (talker/creator dashboards) ─────────────────────── */
.conv-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0 16px 32px;
}
.conv-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--white);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  text-decoration: none !important;
  color: var(--text);
  transition: box-shadow 0.15s, transform 0.15s;
}
.conv-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.conv-card:active { transform: translateY(0); }

.conv-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--purple);
  color: #fff;
  font-size: 1.2rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.conv-avatar--talker { background: #5ba4cf; }

.conv-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.conv-name { font-weight: 600; font-size: 1rem; }
.conv-sub  { font-size: 0.8rem; color: var(--text-muted); }
.conv-arrow { color: var(--text-muted); flex-shrink: 0; }

/* ── Chat room ───────────────────────────────────────────────────────────── */

.chat-page {
  display: flex;
  height: 100dvh;
  background: var(--purple-bg);
  overflow: hidden;
}

/* ── Chat layout: sidebar + main ─────────────────────────────────────────── */

/* Sidebar (desktop only) */
.chat-sidebar {
  display: none;
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100dvh;
  overflow: hidden;
  background: var(--purple-bg);
}

/* Desktop: sidebar visible, main area in a card */
@media (min-width: 900px) {
  .chat-page {
    background: #2d2249;
  }
  .chat-sidebar {
    display: flex;
    flex-direction: column;
    width: 280px;
    flex-shrink: 0;
    background: #231b38;
    color: #e0d9f5;
    padding: 24px 0;
    height: 100dvh;
  }
  .sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 20px 24px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    margin-bottom: 16px;
  }
  .sidebar-logo .logo-mark { background: var(--purple); }
  .sidebar-logo .logo-text { color: #fff; }
  .sidebar-nav { padding: 0 12px; margin-bottom: 16px; }
  .sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    color: rgba(255,255,255,0.6);
    font-size: 0.9rem;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
  }
  .sidebar-link:hover { background: rgba(255,255,255,0.08); color: #fff; text-decoration: none; }
  .sidebar-conv-list { flex: 1; padding: 0 12px; overflow-y: auto; }
  .sidebar-conv {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 12px;
    cursor: default;
    transition: background 0.15s;
  }
  .sidebar-conv.active { background: rgba(124,111,205,0.25); }
  .sidebar-conv .chat-avatar { width: 38px; height: 38px; font-size: 0.95rem; flex-shrink: 0; }
  .sidebar-conv-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
  .sidebar-conv-name { font-size: 0.9rem; font-weight: 600; color: #fff; }
  .sidebar-conv-role { font-size: 0.75rem; color: rgba(255,255,255,0.45); }

  .chat-main {
    background: #f7f5fc;
    height: 100dvh;
  }
  .chat-header { border-radius: 0; border-bottom: 1px solid var(--border); background: #fff; }
  .chat-messages { background: #f2f0fa; }
  .chat-input-bar { background: #fff; border-top: 1px solid var(--border); }
}

/* ── Chat header ─────────────────────────────────────────────────────────── */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  padding-top: max(13px, env(safe-area-inset-top));
  background: #fff;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}
/* Hide back arrow on desktop (sidebar has home link) */
@media (min-width: 900px) { .chat-back { display: none; } }

.chat-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: 50%;
  color: var(--purple);
  flex-shrink: 0;
  transition: background 0.15s;
}
.chat-back:hover { background: var(--purple-bg); text-decoration: none; }

.chat-header-info { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.chat-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--purple), var(--purple-deep));
  color: #fff;
  font-weight: 700; font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.chat-header-text { display: flex; flex-direction: column; min-width: 0; }
.chat-header-name {
  font-weight: 700; font-size: 1rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-header-status {
  display: flex; align-items: center; gap: 5px;
  font-size: 0.72rem; color: var(--text-muted);
}
.status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #cbd5e1; flex-shrink: 0; transition: background 0.3s;
}
.status-dot--online  { background: var(--success); }
.status-dot--offline { background: #cbd5e1; }

/* ── Messages area ───────────────────────────────────────────────────────── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  -webkit-overflow-scrolling: touch;
}
.chat-empty {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 8px;
  color: var(--text-muted); font-size: 0.9rem;
  padding-bottom: 40px;
}
.chat-empty-icon { font-size: 2.5rem; }

/* Date separator */
.date-sep {
  text-align: center;
  margin: 10px 0 6px;
}
.date-sep span {
  display: inline-block;
  font-size: 0.7rem;
  color: var(--text-muted);
  background: rgba(0,0,0,0.06);
  border-radius: 10px;
  padding: 2px 10px;
}

/* ── Bubbles ─────────────────────────────────────────────────────────────── */
.bubble-row {
  display: flex; flex-direction: column;
  max-width: 75%;
  gap: 1px;
  margin-bottom: 1px;
}
.bubble-mine   { align-self: flex-end;   align-items: flex-end; }
.bubble-theirs { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 9px 13px;
  border-radius: 18px;
  font-size: 0.94rem; line-height: 1.5;
  word-break: break-word; white-space: pre-wrap;
}
.bubble-mine   .bubble {
  background: var(--purple); color: #fff;
  border-bottom-right-radius: 4px;
}
.bubble-theirs .bubble {
  background: #fff; color: var(--text);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.bubble-time {
  font-size: 0.67rem;
  color: var(--text-muted);
  padding: 1px 4px;
  opacity: 0;
  transition: opacity 0.15s;
}
.bubble-row:hover .bubble-time { opacity: 1; }

/* Typing indicator */
.bubble-typing {
  display: flex !important; align-items: center;
  gap: 4px; padding: 11px 14px !important;
}
.bubble-typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: #b0a9c8;
  animation: typing-bounce 1.2s infinite;
}
.bubble-typing span:nth-child(2) { animation-delay: 0.2s; }
.bubble-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-bounce {
  0%,60%,100% { transform: translateY(0); opacity:0.4; }
  30%         { transform: translateY(-5px); opacity:1; }
}

/* ── Audio bubble (native <audio> + animated bars) ───────────────────────── */
.bubble-audio {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  width: 230px;
  cursor: default;
}
.bubble-audio audio { display: none; } /* hidden — controlled by JS */

.audio-play-btn {
  width: 34px; height: 34px;
  border-radius: 50%; border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: transform 0.1s, opacity 0.15s;
}
.audio-play-btn:active { transform: scale(0.9); }
.bubble-mine   .audio-play-btn { background: rgba(255,255,255,0.25); color: #fff; }
.bubble-theirs .audio-play-btn { background: var(--purple-light);    color: var(--purple); }

/* Waveform bars */
.audio-bars {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 2px;
  height: 28px;
  overflow: hidden;
}
.audio-bars span {
  display: block;
  width: 3px;
  border-radius: 2px;
  flex-shrink: 0;
  transition: background 0.08s;
}
.bubble-mine   .audio-bars span         { background: rgba(255,255,255,0.35); }
.bubble-mine   .audio-bars span.filled  { background: rgba(255,255,255,0.95); }
.bubble-theirs .audio-bars span         { background: #d0c8f0; }
.bubble-theirs .audio-bars span.filled  { background: var(--purple); }

.audio-dur {
  font-size: 0.7rem;
  white-space: nowrap;
  flex-shrink: 0;
}
.bubble-mine   .audio-dur { color: rgba(255,255,255,0.75); }
.bubble-theirs .audio-dur { color: var(--text-muted); }

/* ── Input bar ───────────────────────────────────────────────────────────── */
.chat-input-bar {
  padding: 10px 12px;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  background: #fff;
  border-top: 1px solid #e8e4f4;
  flex-shrink: 0;
}

/* Recording bar */
.recording-bar {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 8px 16px;
  background: #fff5f5;
  border-radius: 26px;
  border: 1.5px solid #fecaca;
}
.recording-bar.active { display: flex; }
.rec-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--danger); flex-shrink: 0;
  animation: rec-blink 1s ease-in-out infinite;
}
@keyframes rec-blink { 0%,100%{opacity:1} 50%{opacity:0.3} }

.rec-waveform {
  flex: 1; height: 28px;
  display: flex; align-items: center; gap: 2px;
}
.rec-waveform span {
  display: block; width: 3px; height: 4px;
  border-radius: 2px;
  background: var(--danger); opacity: 0.85;
  transition: height 0.05s ease;
  transform-origin: center;
}
.rec-timer {
  font-size: 0.88rem; font-weight: 600;
  color: var(--danger); white-space: nowrap; flex-shrink: 0;
}
.rec-btn {
  width: 34px; height: 34px; min-height: unset;
  border-radius: 50%; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; padding: 0; transition: opacity 0.15s;
}
.rec-cancel-btn { background: #fee2e2; color: #dc2626; }
.rec-send-btn   { background: var(--purple); color: #fff; }
.rec-btn:hover  { opacity: 0.8; }

/* ── Chat input ──────────────────────────────────────────────────────────── */
.chat-input-form {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #edeaf8;
  border-radius: 24px;
  padding: 10px 10px 10px 20px;
  border: none;
  outline: none;
}
@media (min-width: 900px) {
  .chat-input-bar  { padding: 12px 20px 16px; }
}
.chat-input {
  flex: 1;
  border: none;
  background: transparent !important;
  -webkit-appearance: none;
  resize: none;
  overflow: hidden;
  font-size: 16px;
  line-height: 22px;
  /* rows="1" forces browser-internal padding that shifts text upward.
     We removed rows attr and lock height here instead. */
  height: 22px !important;
  min-height: 0 !important;
  max-height: 110px;
  padding: 0 2px !important; /* 2px left/right so cursor isn't clipped by overflow:hidden */
  margin: 0;
  outline: none !important;
  box-shadow: none !important;
  color: var(--text);
  font-family: inherit;
  vertical-align: middle;
}
.chat-input::placeholder { color: #b0a9c8; }

.chat-icon-btn {
  width: 36px; height: 36px; min-height: unset;
  border-radius: 50%; border: none;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; padding: 0; cursor: pointer;
  transition: background 0.15s, opacity 0.15s, transform 0.1s;
}
.chat-mic-btn  { background: transparent; color: #9b8fc4; }
.chat-mic-btn:hover { background: var(--purple-bg); color: var(--purple); }
.chat-send-btn { background: var(--purple); color: #fff; }
.chat-send-btn:disabled { opacity: 0.35; cursor: default; }
.chat-send-btn:not(:disabled):hover  { background: var(--purple-dark); }
.chat-send-btn:not(:disabled):active { transform: scale(0.9); }
