/* =====================================================================
   Design tokens
   Light / Dark / Night themes share the same structure; only the color
   values change. "Night" sits on top of dark mode with warmer, dimmer
   tones intended for late-night use.
   ===================================================================== */

:root {
  --app-bg: #f4f5f9;
  --app-surface: #ffffff;
  --app-surface-alt: #f9fafc;
  --app-border: #e5e7ef;
  --app-text: #1a1c23;
  --app-text-muted: #6b7280;
  --app-accent: #6c5ce7;
  --app-accent-hover: #5b4bd6;
  --app-accent-soft: #efecfd;
  --app-danger: #e5484d;
  --app-success: #2fb380;
  --app-warning: #d68a1c;
  --app-shadow: 0 1px 2px rgba(20, 20, 30, 0.04), 0 6px 20px rgba(20, 20, 30, 0.06);
  --app-shadow-sm: 0 1px 2px rgba(20, 20, 30, 0.05);
  --app-radius-sm: 10px;
  --app-radius: 16px;
  --app-radius-lg: 22px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

html[data-bs-theme="dark"] {
  --app-bg: #101116;
  --app-surface: #1a1b22;
  --app-surface-alt: #202129;
  --app-border: #2b2d38;
  --app-text: #eceef3;
  --app-text-muted: #9599a8;
  --app-accent: #9b8cf5;
  --app-accent-hover: #ab9ef7;
  --app-accent-soft: #262340;
  --app-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
  --app-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
}

html[data-theme-variant="night"] {
  --app-bg: #0a0a0d;
  --app-surface: #131317;
  --app-surface-alt: #17171c;
  --app-border: #202024;
  --app-text: #dcdce0;
  --app-text-muted: #7c7c86;
  --app-accent: #a48cf7;
  --app-accent-hover: #b39ef9;
  --app-accent-soft: #201c33;
}

/* =====================================================================
   Base
   ===================================================================== */

* { scrollbar-width: thin; }

html, body {
  height: 100%;
}

body {
  font-family: var(--font-sans);
  background-color: var(--app-bg);
  color: var(--app-text);
  color-scheme: light dark;
  font-size: 0.975rem;
  line-height: 1.55;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--app-text);
}

a { color: var(--app-accent); text-decoration: none; }
a:hover { color: var(--app-accent-hover); }

.text-muted-app { color: var(--app-text-muted) !important; }

/* Bootstrap overrides for a cohesive palette */
.btn {
  border-radius: var(--app-radius-sm);
  font-weight: 600;
  letter-spacing: -0.01em;
  padding-top: 0.55rem;
  padding-bottom: 0.55rem;
  transition: transform 0.08s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn-sm { padding-top: 0.35rem; padding-bottom: 0.35rem; border-radius: 8px; }

.btn-primary {
  background-color: var(--app-accent);
  border-color: var(--app-accent);
}
.btn-primary:hover, .btn-primary:focus {
  background-color: var(--app-accent-hover);
  border-color: var(--app-accent-hover);
}
.btn-outline-primary {
  color: var(--app-accent);
  border-color: var(--app-accent);
}
.btn-outline-primary:hover {
  background-color: var(--app-accent);
  border-color: var(--app-accent);
}

.text-primary { color: var(--app-accent) !important; }
.bg-primary { background-color: var(--app-accent) !important; }
.link-primary, a.text-primary:hover { color: var(--app-accent-hover) !important; }

/* Bootstrap's grey secondary ignores the theme tokens */
.btn-secondary,
.btn-outline-secondary {
  border-color: var(--app-border);
  color: var(--app-text);
  background-color: transparent;
}
.btn-secondary { background-color: var(--app-surface-alt); }
.btn-secondary:hover,
.btn-outline-secondary:hover,
.btn-outline-secondary:focus {
  background-color: var(--app-surface-alt);
  border-color: var(--app-accent);
  color: var(--app-text);
}
.btn-check:checked + .btn-outline-secondary { background-color: var(--app-accent); color: #fff; }

.form-control, .form-select {
  background-color: var(--app-surface);
  border: 1px solid var(--app-border);
  color: var(--app-text);
  border-radius: var(--app-radius-sm);
  padding: 0.6rem 0.85rem;
  font-size: 0.95rem;
}

/* Leave room for the caret so it never sits on top of the selected label */
.form-select { padding-right: 2.4rem; background-position: right 0.85rem center; }
.form-select-sm { padding-right: 2.1rem; background-position: right 0.7rem center; }
.form-control:focus, .form-select:focus {
  background-color: var(--app-surface);
  color: var(--app-text);
  border-color: var(--app-accent);
  box-shadow: 0 0 0 3px var(--app-accent-soft);
}
.form-label {
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 0.4rem;
  color: var(--app-text);
}
.form-text { color: var(--app-text-muted); font-size: 0.8rem; }

.card {
  background-color: var(--app-surface);
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius);
}
.shadow-sm { box-shadow: var(--app-shadow) !important; }

.alert { border-radius: var(--app-radius-sm); border: 1px solid transparent; font-size: 0.9rem; }

.badge { font-weight: 600; letter-spacing: 0.01em; padding: 0.4em 0.65em; border-radius: 6px; }

.nav-pills .nav-link {
  color: var(--app-text-muted);
  font-weight: 600;
  font-size: 0.88rem;
  border-radius: 999px;
  padding: 0.45rem 1rem;
  margin-right: 0.35rem;
}
.nav-pills .nav-link.active {
  background-color: var(--app-accent);
  color: #fff;
}

.table {
  color: var(--app-text);
  --bs-table-bg: transparent;
}
.table thead th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--app-text-muted);
  border-bottom: 1px solid var(--app-border);
  font-weight: 700;
  padding-top: 0.9rem;
  padding-bottom: 0.9rem;
}
.table td { border-color: var(--app-border); padding-top: 0.8rem; padding-bottom: 0.8rem; }

.modal-content {
  background-color: var(--app-surface);
  color: var(--app-text);
  border-radius: var(--app-radius);
  border: 1px solid var(--app-border);
}
.modal-header, .modal-footer { border-color: var(--app-border); }

/* =====================================================================
   Navbar
   ===================================================================== */
.app-navbar {
  background-color: var(--app-surface);
  border-bottom: 1px solid var(--app-border);
  padding-top: 0.7rem;
  padding-bottom: 0.7rem;
  backdrop-filter: saturate(180%) blur(8px);
}

.navbar-brand {
  font-weight: 800;
  letter-spacing: -0.03em;
  font-size: 1.35rem;
  color: var(--app-text) !important;
  background: linear-gradient(135deg, var(--app-accent), #ff7bd4);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.navbar .nav-link {
  color: var(--app-text-muted);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
}
.navbar .nav-link:hover { color: var(--app-text); background-color: var(--app-surface-alt); }

.theme-switcher .theme-btn {
  border-color: var(--app-border);
  color: var(--app-text-muted);
  padding: 0.3rem 0.55rem;
}
.theme-switcher .theme-btn.active {
  background-color: var(--app-accent);
  color: #fff;
  border-color: var(--app-accent);
}

/* =====================================================================
   Layout
   ===================================================================== */
.app-content {
  max-width: 1180px;
  margin: 0 auto;
  padding-left: 1rem;
  padding-right: 1rem;
  padding-bottom: 3.5rem;
}

/* Auth page cards get a touch more presence */
.app-content .card.rounded-4 {
  border-radius: var(--app-radius-lg) !important;
}

/* =====================================================================
   Chat
   ===================================================================== */
.chat-shell {
  display: flex;
  height: calc(100vh - 100px);
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius-lg);
  overflow: hidden;
  background-color: var(--app-surface);
  box-shadow: var(--app-shadow);
}

.chat-sidebar {
  width: 320px;
  flex-shrink: 0;
  border-right: 1px solid var(--app-border);
  overflow-y: auto;
  background-color: var(--app-surface-alt);
}

#userSearchResults {
  background-color: var(--app-surface);
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius-sm);
  overflow: hidden;
  box-shadow: var(--app-shadow);
}
#userSearchResults .list-group-item {
  background-color: var(--app-surface);
  color: var(--app-text);
  border: none;
  border-bottom: 1px solid var(--app-border);
}
#userSearchResults .list-group-item:last-child { border-bottom: none; }
#userSearchResults .list-group-item-action:hover,
#userSearchResults .list-group-item-action:focus {
  background-color: var(--app-surface-alt);
  color: var(--app-text);
}

.chat-sidebar .list-group-item {
  background-color: transparent;
  border: none;
  border-bottom: 1px solid var(--app-border);
  color: var(--app-text);
  padding: 0.85rem 1rem;
  transition: background-color 0.12s ease;
}
.chat-sidebar .list-group-item:hover { background-color: var(--app-surface); }

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background-color: var(--app-surface);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
}

.chat-bubble {
  max-width: 72%;
  padding: 0.15rem 0.1rem;
  margin-bottom: 0.65rem;
  word-wrap: break-word;
  position: relative;
  font-size: 0.92rem;
  line-height: 1.45;
  background: none;
  box-shadow: none;
}

.chat-bubble.mine {
  margin-left: auto;
  text-align: right;
  color: var(--app-accent);
}

.chat-bubble.theirs {
  margin-right: auto;
  color: var(--app-text);
}

.chat-bubble .delete-countdown {
  font-size: 0.68rem;
  opacity: 0.7;
  margin-top: 3px;
  display: block;
  letter-spacing: 0.01em;
  color: var(--app-text-muted);
}

/* Photo/video messages: no padding needed since there's no card to pad —
   only the countdown label keeps a small pill so it stays readable over
   any image. */
.chat-bubble.has-media {
  padding: 0;
}
.chat-bubble.has-media img,
.chat-bubble.has-media video {
  display: block;
  border-radius: 0.9rem;
}
.chat-bubble.mine.has-media img,
.chat-bubble.mine.has-media video { margin-left: auto; }
.chat-bubble.has-media .delete-countdown {
  display: inline-block;
  margin-top: 0.35rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background-color: var(--app-surface-alt);
  color: var(--app-text-muted);
  box-shadow: var(--app-shadow-sm);
}

.chat-input-bar {
  border-top: 1px solid var(--app-border);
  padding: 0.85rem;
  background-color: var(--app-surface);
}

.chat-input-bar textarea {
  resize: none;
}

/* =====================================================================
   Feed
   ===================================================================== */
.feed-post {
  border-radius: var(--app-radius);
  margin-bottom: 1rem;
}

.feed-expiry-badge {
  font-size: 0.72rem;
  font-weight: 600;
}

.feed-expiry-badge.text-danger {
  animation: pulse-warn 1.5s infinite;
}

@keyframes pulse-warn {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* =====================================================================
   Calling
   ===================================================================== */
.incoming-call-banner {
  position: fixed;
  top: 16px;
  right: 16px;
  left: 16px;
  max-width: 360px;
  margin-left: auto;
  z-index: 2000;
  background-color: var(--app-surface);
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--app-shadow);
  animation: slide-in 0.25s ease;
}

@keyframes slide-in {
  from { transform: translateY(-16px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.call-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(8, 8, 12, 0.94);
  z-index: 2100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.call-overlay-inner {
  width: 100%;
  max-width: 480px;
  padding: 1rem;
  color: #fff;
}

.call-video-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background-color: #000;
  border-radius: var(--app-radius);
  overflow: hidden;
}

.call-remote-video { width: 100%; height: 100%; object-fit: cover; }

.call-local-video {
  position: absolute;
  bottom: 12px;
  right: 12px;
  width: 96px;
  height: 128px;
  object-fit: cover;
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, 0.4);
}

.call-controls {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-top: 1.25rem;
}
.call-controls .btn {
  width: 56px; height: 56px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.25rem;
}
.call-controls .btn.active-off { background-color: var(--app-danger); color: #fff; }

/* =====================================================================
   Mobile responsiveness
   ===================================================================== */
@media (max-width: 768px) {
  .app-navbar { padding-top: 0.5rem; padding-bottom: 0.5rem; }

  .chat-shell {
    height: calc(100vh - 64px);
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  .chat-sidebar {
    position: fixed;
    top: 60px;
    left: 0;
    bottom: 0;
    width: 85%;
    max-width: 320px;
    z-index: 1030;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .chat-sidebar.open { transform: translateX(0); box-shadow: var(--app-shadow); }

  .chat-bubble { max-width: 85%; }

  .app-content { padding-left: 0.6rem; padding-right: 0.6rem; }

  .call-overlay-inner { max-width: 100%; padding: 0.5rem; }
}

@media (max-width: 480px) {
  .chat-bubble { max-width: 90%; font-size: 0.9rem; }
  .navbar-brand { font-size: 1.15rem; }
}

/* =====================================================================
   Mobile settings sheet + floating bottom navigation
   Shown below the lg breakpoint only, matching .d-lg-none on the markup.
   ===================================================================== */
@media (max-width: 991.98px) {

  /* The collapsed navbar reads as a settings panel rather than a link list */
  .app-navbar .navbar-collapse {
    margin-top: 0.7rem;
    padding: 0.85rem;
    background-color: var(--app-surface-alt);
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius);
    box-shadow: var(--app-shadow);
  }

  .navbar-toggler {
    border-color: var(--app-border);
    border-radius: var(--app-radius-sm);
    padding: 0.3rem 0.55rem;
  }
  .navbar-toggler:focus { box-shadow: 0 0 0 3px var(--app-accent-soft); }

  /* Floating pill navigation, pinned to the bottom of the viewport */
  .mobile-bottom-nav {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
    width: calc(100% - 1.5rem);
    max-width: 340px;
    z-index: 1035;
    display: flex;
    gap: 0.25rem;
    padding: 0.35rem;
    background-color: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius-lg);
    box-shadow: var(--app-shadow);
    backdrop-filter: saturate(180%) blur(10px);
  }

  .mbn-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    padding: 0.5rem 0.25rem;
    border: none;
    background: none;
    border-radius: var(--app-radius-sm);
    color: var(--app-text-muted);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0;
    text-decoration: none;
    transition: color 0.15s ease, background-color 0.15s ease;
  }
  .mbn-item i { font-size: 1.2rem; line-height: 1; }
  .mbn-item:active { transform: scale(0.97); }
  .mbn-item:focus-visible { outline: 2px solid var(--app-accent); outline-offset: 2px; }
  .mbn-item.active,
  .mbn-item[aria-expanded="true"] {
    color: #fff;
    background-color: var(--app-accent);
  }

  /* Keep the last conversation reachable above the floating bar */
  body.has-bottom-nav .chat-sidebar {
    padding-bottom: 5.5rem;
  }

  /* Keep page content clear of the floating bar */
  body.has-bottom-nav .app-content {
    padding-bottom: calc(5.5rem + env(safe-area-inset-bottom, 0px));
  }

  /* Chat fills the space between the navbar and the floating bar */
  body.has-bottom-nav .chat-shell {
    height: calc(100vh - 64px - 6rem - env(safe-area-inset-bottom, 0px));
  }
}

@media (prefers-reduced-motion: reduce) {
  .mbn-item, .btn { transition: none; }
}

/* =====================================================================
   Feed live-update controls
   ===================================================================== */
.feed-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.new-posts-banner {
  display: none;
  width: 100%;
  margin-bottom: 1rem;
  padding: 0.6rem 1rem;
  border: 1px solid var(--app-border);
  border-radius: 999px;
  background-color: var(--app-surface);
  color: var(--app-accent);
  font-weight: 600;
  font-size: 0.88rem;
  box-shadow: var(--app-shadow-sm);
}
.new-posts-banner.show { display: block; }

.feed-post.is-new {
  animation: feed-post-in 0.3s ease;
}

@keyframes feed-post-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .feed-post.is-new { animation: none; }
}

.feed-sync-state {
  font-size: 0.78rem;
  color: var(--app-text-muted);
}


/* =====================================================================
   Settings menu — shared by the desktop dropdown and the mobile sheet
   ===================================================================== */
.nav-settings-toggle {
  background-color: transparent;
  border: 1px solid var(--app-border);
  color: var(--app-text);
  font-weight: 600;
  font-size: 0.88rem;
  padding: 0.35rem 0.8rem;
  border-radius: var(--app-radius-sm);
}
.nav-settings-toggle:hover,
.nav-settings-toggle[aria-expanded="true"] {
  background-color: var(--app-surface-alt);
  color: var(--app-text);
  border-color: var(--app-accent);
}
.nav-settings-toggle::after { margin-left: 0.45rem; opacity: 0.6; }

.dropdown-menu.settings-panel {
  min-width: 268px;
  padding: 0.85rem;
  margin-top: 0.5rem;
  background-color: var(--app-surface);
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius);
  box-shadow: var(--app-shadow);
}

.settings-group + .settings-group {
  margin-top: 0.85rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--app-border);
}

.settings-heading {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--app-text-muted);
  margin-bottom: 0.45rem;
}

.settings-panel .theme-switcher .btn {
  flex: 1;
  font-size: 0.82rem;
  padding: 0.5rem 0.25rem;
  background-color: var(--app-surface-alt);
  border-color: var(--app-border);
  color: var(--app-text-muted);
}
.settings-panel .theme-switcher .btn.active {
  background-color: var(--app-accent);
  border-color: var(--app-accent);
  color: #fff;
}

.settings-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  padding: 0.65rem 0.6rem;
  border: none;
  background: none;
  text-align: left;
  border-radius: var(--app-radius-sm);
  color: var(--app-text);
  font-weight: 600;
  font-size: 0.92rem;
  text-decoration: none;
}
.settings-item i:first-child { font-size: 1.05rem; color: var(--app-text-muted); }
.settings-item:hover,
.settings-item:focus-visible {
  background-color: var(--app-surface-alt);
  color: var(--app-text);
}
.settings-item-danger,
.settings-item-danger i:first-child { color: var(--app-danger); }
.settings-item-danger:hover { color: var(--app-danger); background-color: var(--app-surface-alt); }

/* Inside the mobile sheet the panel itself is surface-alt, so flip the hover */
.mobile-settings .settings-item:hover,
.mobile-settings .settings-item:focus-visible { background-color: var(--app-surface); }
.mobile-settings .settings-panel .theme-switcher .btn,
.mobile-settings .theme-switcher .btn { background-color: var(--app-surface); }
.mobile-settings .theme-switcher .btn.active { background-color: var(--app-accent); }

/* =====================================================================
   About
   ===================================================================== */
.about-body { font-size: 0.93rem; }
.about-body h6 {
  margin-top: 1.25rem;
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
  color: var(--app-text-muted);
}
.about-body ul { padding-left: 1.1rem; margin-bottom: 0; }
.about-body li { margin-bottom: 0.35rem; }

/* =====================================================================
   Floating post composer
   ===================================================================== */
.compose-fab {
  position: fixed;
  right: 1.25rem;
  bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
  z-index: 1040;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.8rem 1.35rem;
  border: none;
  border-radius: 999px;
  background-color: var(--app-accent);
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
  box-shadow: 0 6px 20px rgba(108, 92, 231, 0.35);
}
.compose-fab:hover { background-color: var(--app-accent-hover); color: #fff; }
.compose-fab:focus-visible { outline: 3px solid var(--app-accent-soft); outline-offset: 2px; }
.compose-fab i { font-size: 1.1rem; }

@media (max-width: 991.98px) {
  /* Clear the floating bottom bar */
  .compose-fab {
    bottom: calc(5.25rem + env(safe-area-inset-bottom, 0px));
    padding: 0.75rem 1.1rem;
  }
}


/* =====================================================================
   Chat header — hidden until a conversation is open
   ===================================================================== */
.chat-header-bar { display: none; }
.chat-header-bar.is-open { display: flex; }

/* Delete control on a conversation row, revealed on hover or focus */
.conv-row { position: relative; }
.conv-delete-btn {
  border: none;
  background: none;
  color: var(--app-text-muted);
  padding: 0.3rem 0.45rem;
  border-radius: 8px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.12s ease, color 0.12s ease;
}
.conv-row:hover .conv-delete-btn,
.conv-delete-btn:focus-visible { opacity: 1; }
.conv-delete-btn:hover { color: var(--app-danger); background-color: var(--app-surface-alt); }

/* Touch devices have no hover, so keep it visible */
@media (hover: none) {
  .conv-delete-btn { opacity: 1; }
}

/* =====================================================================
   Feed post owner controls
   ===================================================================== */
.post-owner-actions .btn { white-space: nowrap; }
