/* =========================================================
   NexChat — Design tokens
   Identity: "aurora glass" — violet → teal gradient accent on
   a deep charcoal-blue base, warm amber reserved for
   unread/urgent signals only. Plus Jakarta Sans throughout,
   weight does the differentiating (not a second family).
   ========================================================= */

@import url('https://cdnjs.cloudflare.com/ajax/libs/fonts/plus-jakarta-sans/plus-jakarta-sans.min.css') layer(font-fallback);

:root {
  --font: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  --violet: #7C5CFC;
  --teal: #17D9C4;
  --amber: #FFB454;
  --danger: #FF5C77;
  --gradient: linear-gradient(135deg, var(--violet), var(--teal));

  /* dark theme (default) */
  --bg: #0B0E16;
  --bg-elevated: #11151F;
  --surface: rgba(255, 255, 255, 0.055);
  --surface-strong: rgba(255, 255, 255, 0.09);
  --surface-border: rgba(255, 255, 255, 0.09);
  --text: #ECEDF6;
  --text-dim: #9096AA;
  --text-faint: #5C6278;
  --bubble-in: #171C29;
  --bubble-out: #2C2470;
  --bubble-out-2: #1F5F63;

  --radius-lg: 26px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

[data-theme="light"] {
  --bg: #F3F4F9;
  --bg-elevated: #FFFFFF;
  --surface: rgba(255, 255, 255, 0.7);
  --surface-strong: #FFFFFF;
  --surface-border: rgba(20, 22, 40, 0.07);
  --text: #171923;
  --text-dim: #666E85;
  --text-faint: #9AA1B5;
  --bubble-in: #FFFFFF;
  --bubble-out: #7C5CFC;
  --bubble-out-2: #17B8A6;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  transition: background .3s ease, color .3s ease;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
img { max-width: 100%; display: block; }

::-webkit-scrollbar { width: 0; height: 0; }

:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
  border-radius: 8px;
}

/* ---------------------------------------------------------
   App shell
   --------------------------------------------------------- */

#app {
  max-width: 560px;
  margin: 0 auto;
  height: 100dvh;
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}

@media (min-width: 700px) {
  #app {
    height: 92dvh;
    margin-top: 4dvh;
    border-radius: 32px;
    box-shadow: 0 40px 100px rgba(0,0,0,.35);
    border: 1px solid var(--surface-border);
  }
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  transform: translateX(0);
  transition: transform .32s cubic-bezier(.22,.61,.36,1), opacity .32s ease;
}

.screen.screen--hidden { transform: translateX(100%); pointer-events: none; }
.screen.screen--behind { transform: translateX(-25%); opacity: .4; pointer-events: none; }

/* ---------------------------------------------------------
   Glass header
   --------------------------------------------------------- */

.glass-header {
  position: sticky;
  top: 0;
  z-index: 30;
  padding: calc(var(--safe-top) + 14px) 18px 12px;
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  border-bottom: 1px solid var(--surface-border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.glass-header h1 {
  font-size: 1.5rem;
  font-weight: 800;
  margin: 0;
  letter-spacing: -0.02em;
  flex: 1;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  border: none;
  background: var(--surface);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform .15s ease, background .2s ease;
}
.icon-btn:active { transform: scale(.9); }
.icon-btn svg { width: 20px; height: 20px; }

/* ---------------------------------------------------------
   Search
   --------------------------------------------------------- */

.search-bar {
  margin: 4px 18px 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  border-radius: 100px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
}
.search-bar input {
  border: none;
  background: transparent;
  outline: none;
  color: var(--text);
  font-size: .95rem;
  width: 100%;
  font-family: inherit;
}
.search-bar input::placeholder { color: var(--text-faint); }
.search-bar svg { width: 18px; height: 18px; color: var(--text-faint); flex-shrink: 0; }

/* ---------------------------------------------------------
   Chat list
   --------------------------------------------------------- */

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px calc(90px + var(--safe-bottom));
}

.chat-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 11px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  touch-action: pan-y;
}

.chat-row-content {
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  background: var(--bg);
  border-radius: var(--radius-md);
  transition: transform .25s cubic-bezier(.22,.61,.36,1), background .15s ease;
  position: relative;
  z-index: 1;
  padding: 2px;
}
.chat-row:active .chat-row-content { background: var(--surface); }

.chat-swipe-actions {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  padding-right: 8px;
  z-index: 0;
}
.chat-swipe-actions button {
  width: 46px; height: 46px;
  border-radius: 14px;
  border: none;
  display: grid;
  place-items: center;
  color: #fff;
  cursor: pointer;
}
.chat-swipe-actions svg { width: 19px; height: 19px; }

.avatar {
  width: 54px;
  height: 54px;
  border-radius: 18px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface);
}
.avatar-wrap { position: relative; flex-shrink: 0; }
.online-dot {
  position: absolute;
  bottom: -1px; right: -1px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--teal);
  border: 3px solid var(--bg);
}

.chat-row-body { flex: 1; min-width: 0; }
.chat-row-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.chat-row-name {
  font-weight: 700;
  font-size: .98rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-row-time { font-size: .75rem; color: var(--text-faint); flex-shrink: 0; }
.chat-row-time.unread { color: var(--teal); font-weight: 700; }

.chat-row-bottom { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 2px; }
.chat-row-preview {
  font-size: .87rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 4px;
}
.chat-row-preview.typing { color: var(--teal); font-weight: 600; }

.unread-badge {
  background: var(--gradient);
  color: #fff;
  font-size: .72rem;
  font-weight: 800;
  min-width: 20px;
  height: 20px;
  border-radius: 100px;
  display: grid;
  place-items: center;
  padding: 0 6px;
  flex-shrink: 0;
}

.pin-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--amber); }
.mute-icon { width: 14px; height: 14px; color: var(--text-faint); }

/* ---------------------------------------------------------
   Empty states
   --------------------------------------------------------- */

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
  gap: 14px;
}
.empty-state .empty-icon {
  width: 84px; height: 84px;
  border-radius: 28px;
  background: var(--gradient);
  display: grid; place-items: center;
  opacity: .9;
}
.empty-state .empty-icon svg { width: 38px; height: 38px; color: #fff; }
.empty-state h3 { margin: 0; font-size: 1.1rem; }
.empty-state p { margin: 0; color: var(--text-dim); font-size: .9rem; max-width: 240px; }

/* ---------------------------------------------------------
   Skeleton loading
   --------------------------------------------------------- */

.skeleton-row { display: flex; gap: 13px; padding: 11px 10px; }
.skeleton-block {
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-strong) 37%, var(--surface) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
.skeleton-avatar { width: 54px; height: 54px; border-radius: 18px; flex-shrink: 0; }
.skeleton-lines { flex: 1; display: flex; flex-direction: column; gap: 8px; justify-content: center; }
.skeleton-line { height: 11px; border-radius: 6px; }

/* ---------------------------------------------------------
   Bottom navigation
   --------------------------------------------------------- */

.bottom-nav {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  z-index: 30;
  display: flex;
  padding: 8px 8px calc(10px + var(--safe-bottom));
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  border-top: 1px solid var(--surface-border);
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 0 4px;
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  position: relative;
}
.nav-item svg { width: 22px; height: 22px; transition: transform .2s ease; }
.nav-item span { font-size: .66rem; font-weight: 600; }
.nav-item.active { color: var(--text); }
.nav-item.active svg { transform: translateY(-2px); color: var(--violet); }
.nav-badge {
  position: absolute;
  top: 0; right: 22%;
  background: var(--danger);
  color: #fff;
  font-size: .6rem;
  font-weight: 800;
  min-width: 15px; height: 15px;
  border-radius: 100px;
  display: grid; place-items: center;
  padding: 0 3px;
}

.fab {
  position: absolute;
  right: 18px;
  bottom: calc(84px + var(--safe-bottom));
  width: 58px; height: 58px;
  border-radius: 20px;
  border: none;
  background: var(--gradient);
  box-shadow: 0 12px 30px -8px rgba(124,92,252,.6);
  display: grid;
  place-items: center;
  cursor: pointer;
  z-index: 25;
  transition: transform .15s ease;
}
.fab:active { transform: scale(.92); }
.fab svg { width: 24px; height: 24px; color: #fff; }

/* ---------------------------------------------------------
   Chat screen
   --------------------------------------------------------- */

.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
}
.chat-header .avatar { width: 40px; height: 40px; border-radius: 13px; }
.chat-header-info { flex: 1; min-width: 0; cursor: pointer; }
.chat-header-name { font-weight: 700; font-size: .96rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-header-status { font-size: .76rem; color: var(--text-dim); }
.chat-header-status.typing { color: var(--teal); font-weight: 600; }
.chat-header h1 { display: none; }

.message-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px calc(96px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.day-divider {
  align-self: center;
  font-size: .72rem;
  color: var(--text-dim);
  background: var(--surface);
  padding: 5px 14px;
  border-radius: 100px;
  margin: 14px 0 8px;
}

.msg-row { display: flex; max-width: 82%; margin: 3px 0; animation: msgIn .25s ease; }
.msg-row.mine { align-self: flex-end; flex-direction: row-reverse; }
@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.bubble {
  padding: 9px 13px 8px;
  border-radius: var(--radius-md);
  position: relative;
  background: var(--bubble-in);
  border: 1px solid var(--surface-border);
}
.msg-row.mine .bubble {
  background: linear-gradient(135deg, var(--bubble-out), var(--bubble-out-2));
  border: none;
  color: #fff;
}
.msg-row:not(.mine) .bubble { border-bottom-left-radius: 6px; }
.msg-row.mine .bubble { border-bottom-right-radius: 6px; }

.bubble-reply {
  border-left: 3px solid var(--teal);
  background: rgba(255,255,255,.08);
  border-radius: 8px;
  padding: 5px 9px;
  margin-bottom: 6px;
  font-size: .8rem;
  opacity: .85;
}

.bubble-text { font-size: .93rem; line-height: 1.4; white-space: pre-wrap; word-break: break-word; }
.bubble-deleted { font-style: italic; opacity: .6; font-size: .88rem; }

.bubble-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  margin-top: 3px;
  font-size: .68rem;
  opacity: .75;
}
.bubble-meta svg { width: 14px; height: 14px; }
.bubble-meta .read { color: var(--teal); }

.tts-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: none;
  background: rgba(255,255,255,.12);
  color: inherit;
  border-radius: 100px;
  padding: 3px 9px 3px 7px;
  font-size: .72rem;
  font-weight: 600;
  margin-top: 6px;
  cursor: pointer;
}
.msg-row:not(.mine) .tts-btn { background: var(--surface-strong); color: var(--text); }
.tts-btn svg { width: 13px; height: 13px; }
.tts-btn.speaking { background: var(--gradient); color: #fff; }

.reaction-row { display: flex; gap: 3px; margin-top: 4px; flex-wrap: wrap; }
.reaction-chip {
  background: var(--surface-strong);
  border: 1px solid var(--surface-border);
  border-radius: 100px;
  padding: 1px 7px;
  font-size: .78rem;
}

.typing-indicator {
  display: inline-flex;
  gap: 3px;
  padding: 12px 14px;
  background: var(--bubble-in);
  border-radius: var(--radius-md);
  border-bottom-left-radius: 6px;
  border: 1px solid var(--surface-border);
  width: fit-content;
}
.typing-indicator span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-faint);
  animation: typingBounce 1.2s infinite ease-in-out;
}
.typing-indicator span:nth-child(2) { animation-delay: .15s; }
.typing-indicator span:nth-child(3) { animation-delay: .3s; }
@keyframes typingBounce { 0%,60%,100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }

/* ---------------------------------------------------------
   Composer
   --------------------------------------------------------- */

.composer {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  padding: 10px 12px calc(12px + var(--safe-bottom));
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  border-top: 1px solid var(--surface-border);
}

.reply-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  margin-bottom: 8px;
  border-left: 3px solid var(--teal);
}
.reply-preview-text { flex: 1; font-size: .82rem; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply-preview button { background: none; border: none; color: var(--text-faint); cursor: pointer; }

.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.composer-input-wrap {
  flex: 1;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  background: var(--surface);
  border-radius: 22px;
  padding: 6px 8px 6px 14px;
  border: 1px solid var(--surface-border);
}
.composer-input-wrap textarea {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  resize: none;
  color: var(--text);
  font-family: inherit;
  font-size: .93rem;
  max-height: 110px;
  padding: 7px 0;
  line-height: 1.35;
}
.composer-input-wrap textarea::placeholder { color: var(--text-faint); }

.composer-icon-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-dim);
  display: grid; place-items: center;
  cursor: pointer;
  flex-shrink: 0;
}
.composer-icon-btn svg { width: 20px; height: 20px; }

.send-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--gradient);
  display: grid; place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform .15s ease;
}
.send-btn:active { transform: scale(.9); }
.send-btn svg { width: 19px; height: 19px; color: #fff; }

/* ---------------------------------------------------------
   Auth screens
   --------------------------------------------------------- */

.auth-screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 32px 26px;
  max-width: 440px;
  margin: 0 auto;
}
.auth-logo {
  width: 64px; height: 64px;
  border-radius: 20px;
  background: var(--gradient);
  display: grid; place-items: center;
  margin-bottom: 22px;
  box-shadow: 0 16px 34px -12px rgba(124,92,252,.55);
}
.auth-logo svg { width: 30px; height: 30px; color: #fff; }
.auth-screen h1 { font-size: 1.7rem; margin: 0 0 6px; letter-spacing: -0.02em; }
.auth-screen p.subtitle { color: var(--text-dim); margin: 0 0 28px; font-size: .95rem; }

.field { margin-bottom: 15px; }
.field label { display: block; font-size: .82rem; font-weight: 600; margin-bottom: 6px; color: var(--text-dim); }
.field input {
  width: 100%;
  padding: 13px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--surface-border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: .95rem;
  outline: none;
  transition: border-color .2s ease;
}
.field input:focus { border-color: var(--violet); }

.btn-primary {
  width: 100%;
  padding: 14px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--gradient);
  color: #fff;
  font-weight: 700;
  font-size: .96rem;
  cursor: pointer;
  margin-top: 6px;
  transition: transform .15s ease, opacity .2s ease;
}
.btn-primary:active { transform: scale(.98); }
.btn-primary:disabled { opacity: .6; }

.auth-switch { text-align: center; margin-top: 22px; font-size: .88rem; color: var(--text-dim); }
.auth-switch a, .auth-switch button {
  color: var(--teal); font-weight: 700; background: none; border: none; cursor: pointer; font-family: inherit; font-size: inherit;
}

.form-error {
  background: rgba(255,92,119,.12);
  border: 1px solid rgba(255,92,119,.3);
  color: var(--danger);
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  margin-bottom: 16px;
  display: none;
}
.form-error.visible { display: block; }

/* ---------------------------------------------------------
   Bottom sheets & toasts
   --------------------------------------------------------- */

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease;
}
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }

.bottom-sheet {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  z-index: 41;
  background: var(--bg-elevated);
  border-radius: 26px 26px 0 0;
  padding: 10px 18px calc(24px + var(--safe-bottom));
  transform: translateY(100%);
  transition: transform .32s cubic-bezier(.22,.61,.36,1);
  border: 1px solid var(--surface-border);
  border-bottom: none;
}
.bottom-sheet.open { transform: translateY(0); }
.sheet-handle { width: 36px; height: 4px; border-radius: 100px; background: var(--surface-border); margin: 6px auto 14px; }
.sheet-title { font-weight: 700; font-size: 1rem; margin: 0 0 14px; }
.sheet-option {
  display: flex; align-items: center; gap: 14px;
  padding: 13px 4px;
  cursor: pointer;
  border-bottom: 1px solid var(--surface-border);
}
.sheet-option:last-child { border-bottom: none; }
.sheet-option-icon {
  width: 40px; height: 40px; border-radius: 13px;
  display: grid; place-items: center;
  background: var(--surface);
}
.sheet-option-icon svg { width: 19px; height: 19px; }
.sheet-option.danger { color: var(--danger); }

.toast-stack {
  position: absolute;
  top: calc(var(--safe-top) + 12px);
  left: 0; right: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--surface-border);
  color: var(--text);
  padding: 11px 18px;
  border-radius: 100px;
  font-size: .85rem;
  font-weight: 600;
  box-shadow: 0 14px 30px rgba(0,0,0,.25);
  animation: toastIn .25s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

/* ---------------------------------------------------------
   Placeholder / "coming soon" tab content
   --------------------------------------------------------- */

.coming-soon { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 40px; text-align: center; }
.coming-soon .badge-pill {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  color: var(--text-dim);
  font-size: .75rem;
  font-weight: 700;
  padding: 5px 14px;
  border-radius: 100px;
}

/* ---------------------------------------------------------
   Utility
   --------------------------------------------------------- */

.hidden { display: none !important; }
.spinner {
  width: 18px; height: 18px;
  border: 2.5px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
[data-theme="light"] .spinner-dark { border-color: rgba(0,0,0,.15); border-top-color: var(--violet); }
@keyframes spin { to { transform: rotate(360deg); } }

.pull-indicator {
  display: flex; justify-content: center; align-items: center;
  height: 0;
  overflow: hidden;
  color: var(--text-faint);
  font-size: .78rem;
  transition: height .2s ease;
}
