/* =========================================================
   NATIVE APP CHROME — visual-only overlay
   Loaded after chatStyles.css (and every other stylesheet) so
   its rules win the cascade without editing the originals.
   Nothing here touches IDs/classes that JS depends on for
   behaviour — only how they look.
   ========================================================= */

/* ---------------------------------------------------------
   0. TOKENS — re-tune the existing variables. Because the
   whole app is already built on var(--primary-color) etc,
   redefining them here reshapes everything downstream for free.
   --------------------------------------------------------- */
:root {
  --primary-color: #2f6fed;
  --primary-gradient: linear-gradient(135deg, #3d7bf2 0%, #2358c4 100%);
  --sent-bubble-gradient: var(--primary-color);
  --secondary-bg: #f2f2f7;
  --white: #ffffff;
  --text-dark: #0b0b0f;
  --text-grey: #6e6e76;
  --border-color: rgba(60, 60, 67, 0.29);
  --success: #34c759;
  --danger: #ff3b30;
  --warning-bg: #fff6e0;
  --warning-text: #9a5b00;

  /* native surfaces have almost no drop-shadow — separation comes
     from hairlines and translucency, not elevation */
  --shadow-sm: none;
  --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.16);

  --glass-bg: rgba(255, 255, 255, 0.72);
  --hairline: rgba(60, 60, 67, 0.22);
  --fill-tertiary: rgba(120, 120, 128, 0.12);
  --fill-secondary: rgba(120, 120, 128, 0.16);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --ease-spring: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

body.dark-mode {
  --secondary-bg: #000000;
  --white: #1c1c1e;
  --text-dark: #f5f5f7;
  --text-grey: #98989f;
  --border-color: rgba(84, 84, 88, 0.6);
  --glass-bg: rgba(17, 17, 17, 0.72);
  --hairline: rgba(84, 84, 88, 0.55);
  --fill-tertiary: rgba(120, 120, 128, 0.24);
  --fill-secondary: rgba(120, 120, 128, 0.28);
}

/* ---------------------------------------------------------
   1. GLOBAL FEEL — system font stack, no tap-flash, no
   text selection on chrome, native momentum scrolling.
   --------------------------------------------------------- */
html {
  -webkit-tap-highlight-color: transparent;
}

body, input, textarea, select, button {
  font-family: -apple-system, "SF Pro Text", "Segoe UI Variable", "Segoe UI",
    Roboto, Helvetica, Arial, sans-serif;
}

body {
  background: var(--secondary-bg);
}

.container {
  background: var(--secondary-bg);
}

.container::before { content: none; } /* drop the graph-paper web pattern */
.container::after { opacity: 0.5; }

#overflow-menu, #chat-box, .settings-scroll, .profile-scroll,
#contacts-list, .sidebar-panel, .dialog-content.wide {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

#chat-box { background: transparent; }

button, a { -webkit-tap-highlight-color: transparent; }

:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

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

/* Tactile press feedback everywhere something is tappable */
.action-btn, .btn, .sidebar-tab, .bottom-nav-item, .menu-item, .contact-item,
.settings-action-btn, .choice-option, .add-contact-row button, #send-button,
.timer-option, .story-viewers-btn, .modal-actions button, .add-contact-btn,
.hover-action-btn, .view-once-toggle, .message-input-container button,
.forward-contact-row {
  transition: transform 0.15s var(--ease-spring), background 0.15s ease, opacity 0.15s ease, color 0.15s ease;
}
.action-btn:active, .btn:active, .add-contact-btn:active,
#send-button:active, .modal-actions button:active,
.add-contact-row button:active, .story-viewers-btn:active,
.hover-action-btn:active, .view-once-toggle:active {
  transform: scale(0.94);
}
.menu-item:active, .contact-item:active, .settings-action-btn:active,
.choice-option:active, .timer-option:active, .forward-contact-row:active {
  background: var(--fill-secondary) !important;
}

/* ---------------------------------------------------------
   2. SIDEBAR — frosted glass panel, large title, grouped
   toolbar row, segmented Chats/Contacts switcher.
   --------------------------------------------------------- */
#overflow-menu-Bar {
  background: var(--glass-bg);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-right: none;
  box-shadow: inset -1px 0 0 var(--hairline);
}

.menu-top-bar {
  background: transparent;
  border-bottom: none;
  padding: calc(14px + var(--safe-top)) 16px 12px;
  gap: 14px;
}

.menu-header-row .menu-title {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.6px;
  color: var(--text-dark);
}

#nav-secret-chats-btn.secret-entry-btn {
  background: var(--fill-tertiary) !important;
  border-radius: 50% !important;
  width: 38px; height: 38px;
}
#nav-secret-chats-btn.secret-entry-btn:hover,
#nav-secret-chats-btn.secret-entry-btn:active {
  background: var(--fill-secondary) !important;
}

.search-container input {
  background: var(--fill-tertiary);
  border-radius: 11px;
  padding: 9px 14px 9px 34px;
  font-size: 14.5px;
}
.search-container input:focus {
  background: var(--white);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.16);
}
.search-icon {
  left: 11px;
  right: auto;
  font-size: 17px;
}

/* Grouped icon toolbar (Settings / Contacts / My profile) */
.menu-actions {
  background: var(--fill-tertiary);
  border-radius: 12px;
  padding: 2px;
  gap: 0;
  margin-top: 0;
}
.menu-actions .action-btn {
  background: transparent !important;
  border-radius: 10px !important;
  color: var(--primary-color) !important;
  height: 40px;
  font-weight: 600;
}
.menu-actions .action-btn:hover { background: rgba(120, 120, 128, 0.14) !important; }
.menu-actions .action-btn:active { background: var(--fill-secondary) !important; transform: scale(0.96); }

/* Segmented Chats / Contacts control */
.sidebar-tabs {
  border-bottom: none;
  padding: 0 16px 12px;
  gap: 3px;
  background: transparent;
}
.sidebar-tab {
  background: var(--fill-tertiary);
  border-bottom: none !important;
  border-radius: 9px;
  padding: 7px 8px;
  font-size: 13px;
  margin: 0 1.5px;
}
.sidebar-tab.active {
  background: var(--white);
  color: var(--text-dark);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}
.sidebar-tab:not(.active):hover { color: var(--text-dark); }

#overflow-menu { padding: 0 0 8px; }
#contacts-panel { padding: 12px 16px; }

/* Edge-to-edge native list rows instead of floating rounded cards */
.menu-item, .contact-item {
  border-radius: 0;
  margin-bottom: 0;
  padding: 10px 16px;
  border-bottom: 1px solid var(--hairline);
}
.menu-item:hover, .contact-item:hover { background: var(--fill-tertiary); }
.menu-item.active { background: rgba(47, 111, 237, 0.1); }

.add-contact-btn {
  background: var(--fill-tertiary);
  border: none;
  color: var(--primary-color);
  border-radius: 12px;
}
.add-contact-btn:hover, .add-contact-btn:active { background: var(--fill-secondary); }

.add-contact-row, .forward-contact-row { border-radius: 12px; }
.add-contact-row button {
  border-radius: 16px;
  box-shadow: none;
}

/* ---------------------------------------------------------
   3. CHAT HEADER / VIEW HEADERS — translucent native nav bar
   --------------------------------------------------------- */
#user-info, .view-header {
  background: var(--glass-bg);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-bottom: 1px solid var(--hairline);
  padding-top: var(--safe-top);
  height: auto;
  min-height: 60px;
}
#selected-user { font-size: 15.5px; font-weight: 700; }
.view-header h2 { font-size: 19px; font-weight: 800; letter-spacing: -0.3px; }
.back-icon, #back-button { color: var(--primary-color); }

#profile-pic { border: none; box-shadow: 0 0 0 1px var(--hairline); }

/* ---------------------------------------------------------
   4. MESSAGE BUBBLES — flat native colours, plumper corners
   --------------------------------------------------------- */
.message {
  border-radius: 20px;
  box-shadow: none;
}
.sent .message {
  background: var(--primary-color);
  border-radius: 20px 20px 5px 20px;
}
.received .message {
  background: var(--white);
  border: none;
  border-radius: 20px 20px 20px 5px;
  box-shadow: 0 0 0 1px var(--hairline);
}
body.dark-mode .received .message { background: #1c1c1e; }

.hover-action-btn {
  background: var(--white);
  border: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.14);
}

.encryption-message, .date-divider span {
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  box-shadow: none;
  border-color: var(--hairline);
}

/* ---------------------------------------------------------
   5. COMPOSER — pill input, translucent footer, safe-area
   --------------------------------------------------------- */
.message-input-container {
  background: var(--glass-bg);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-top: 1px solid var(--hairline);
  padding-bottom: calc(12px + var(--safe-bottom));
}
.message-input-container input[type="text"] {
  background: var(--fill-tertiary);
  border-radius: 20px;
}
.message-input-container input[type="text"]:focus {
  background: var(--white);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.16);
}
#send-button {
  box-shadow: none;
  border-radius: 50%;
}
#send-button:active { transform: scale(0.9); }

.composer-preview-bar {
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--hairline);
}

.timer-popup {
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--hairline);
  backdrop-filter: blur(20px);
  background: var(--glass-bg);
}

/* ---------------------------------------------------------
   6. BOTTOM SHEETS — every .dialog becomes a native sheet
   that slides up from the bottom with a drag-handle grabber.
   Animation replays automatically each time JS flips the
   element from display:none to display:flex (no JS change
   required — a display toggle re-enters it into the render
   tree, which restarts any animation declared on it).
   --------------------------------------------------------- */
.dialog {
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(2px);
  animation: sheetBackdropIn 0.28s var(--ease-out);
}
.dialog-content {
  width: 100%;
  max-width: 480px;
  border-radius: 20px 20px 0 0;
  padding: 22px 20px calc(20px + var(--safe-bottom));
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.2);
  position: relative;
  animation: sheetSlideUp 0.34s var(--ease-spring);
}
.dialog-content.wide { max-width: 520px; }
.dialog-content::before {
  content: "";
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 36px;
  height: 5px;
  border-radius: 3px;
  background: var(--hairline);
}
.dialog-content.story-create-content::before { background: rgba(255, 255, 255, 0.4); }

@keyframes sheetSlideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
@keyframes sheetBackdropIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.dialog-header h3, .dialog-header { margin-top: 4px; }
.close-icon {
  background: var(--fill-tertiary);
  border-radius: 50%;
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}

.form-control {
  background: var(--fill-tertiary);
  border: none;
  border-radius: 12px;
}
.form-control:focus {
  background: var(--white);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.16);
}

.modal-actions button, .btn, .btn-primary, .btn-outline, .btn-secondary {
  border-radius: 14px;
  box-shadow: none;
}
.btn-outline, .btn-secondary { background: var(--fill-tertiary); border-color: transparent !important; }

/* Image lightbox — keep centred, just refine chrome */
#image-modal.modal, .modal {
  backdrop-filter: blur(16px);
}
#modal-close {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 50%;
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
}

/* Context-menu bottom sheet (JS-generated) */
.bottom-sheet {
  backdrop-filter: blur(6px);
}
.bottom-sheet .options {
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.2);
  padding-bottom: calc(16px + var(--safe-bottom));
  position: relative;
}
.bottom-sheet .options::before {
  content: "";
  position: absolute;
  top: 8px; left: 50%;
  transform: translateX(-50%);
  width: 36px; height: 5px;
  border-radius: 3px;
  background: var(--hairline);
}
.bottom-sheet .option, .bottom-sheet .close { border-radius: 12px; }

/* ---------------------------------------------------------
   7. TOASTS — native notification banner
   --------------------------------------------------------- */
.success-message, .error-message {
  top: calc(12px + var(--safe-top));
  border-radius: 16px;
  backdrop-filter: blur(24px);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
}
.success-message { background: rgba(28, 28, 30, 0.92); }
.error-message { background: rgba(255, 59, 48, 0.94); }

/* ---------------------------------------------------------
   8. PROFILE VIEW — flat surfaces, no card shadow
   --------------------------------------------------------- */
.profile-card {
  border: none;
  border-radius: 20px;
  box-shadow: 0 0 0 1px var(--hairline);
}
.avatar-wrapper { box-shadow: 0 0 0 1px var(--hairline); }
.status-badge { border: none; }
.profile-private-notice { background: var(--fill-tertiary); }

/* ---------------------------------------------------------
   9. SETTINGS VIEW — grouped list, no card shadow
   --------------------------------------------------------- */
.settings-section {
  border: none;
  box-shadow: none;
  border-radius: 14px;
  padding: 4px 16px;
}
.settings-action-btn:hover, .settings-action-btn:active { background: transparent; }

.choice-option {
  border: none;
  background: var(--fill-tertiary);
  border-radius: 12px;
}
.choice-option.selected {
  background: rgba(47, 111, 237, 0.14);
  border: none;
}

.switch { width: 46px; height: 27px; }
.slider::before { height: 21px; width: 21px; }
.switch input:checked + .slider::before { transform: translateX(19px); }

/* ---------------------------------------------------------
   10. STORIES BAR
   --------------------------------------------------------- */
.stories-bar { border-bottom: 1px solid var(--hairline); }

/* ---------------------------------------------------------
   11. BOTTOM NAVIGATION — frosted native tab bar
   --------------------------------------------------------- */
.bottom-nav {
  background: var(--glass-bg) !important;
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-top: 1px solid var(--hairline) !important;
  box-shadow: none !important;
  height: calc(58px + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
}
.bottom-nav-item .material-icons { transition: transform 0.15s var(--ease-spring); }
.bottom-nav-item.active .material-icons { transform: translateY(-1px) scale(1.05); }
.bottom-nav-item span.text-\[11px\] { font-weight: 600; }

/* ---------------------------------------------------------
   12. VOICE RECORDER / MISC FLOATING ELEMENTS
   --------------------------------------------------------- */
.vr-lock-track { box-shadow: var(--shadow-lg); border: none; background: var(--glass-bg); backdrop-filter: blur(16px); }
#timer-button.active-timer { background: rgba(47, 111, 237, 0.14); }
.view-once-toggle.active { box-shadow: none; }

/* ---------------------------------------------------------
   13. SCROLLBARS — thin, unobtrusive
   --------------------------------------------------------- */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: var(--fill-secondary); }

/* ---------------------------------------------------------
   14. INSTALL BANNER — "Add to Home Screen" prompt
   --------------------------------------------------------- */
.pwa-install-banner {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + var(--safe-bottom));
  z-index: 999;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 18px;
  background: var(--glass-bg);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
  border: 1px solid var(--hairline);
  transform: translateY(120%);
  opacity: 0;
  transition: transform 0.32s var(--ease-spring), opacity 0.32s var(--ease-out);
}
.pwa-install-banner.visible {
  transform: translateY(0);
  opacity: 1;
}
.pwa-install-icon {
  color: var(--primary-color);
  font-size: 26px;
  flex-shrink: 0;
}
.pwa-install-text {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}
.pwa-install-text strong {
  font-size: 14px;
  color: var(--text-dark);
}
.pwa-install-text span {
  font-size: 12px;
  color: var(--text-grey);
  line-height: 1.3;
}
.pwa-install-btn {
  flex-shrink: 0;
  background: var(--primary-color);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s var(--ease-spring), opacity 0.15s ease;
}
.pwa-install-btn:active { transform: scale(0.94); }
.pwa-install-dismiss {
  flex-shrink: 0;
  color: var(--text-grey);
  font-size: 18px;
  cursor: pointer;
  padding: 2px;
}

/* On desktop, don't stretch the banner edge-to-edge */
@media (min-width: 640px) {
  .pwa-install-banner {
    left: auto;
    right: 20px;
    bottom: calc(20px + var(--safe-bottom));
    width: 360px;
  }
}