/* ============================================================================
   NICHAT - THEME (Dark, X/Twitter-inspired)
   Pure black base, high contrast, minimal borders, no heavy gradients.
   ============================================================================ */

:root {
  /* --- Core surfaces --- */
  --n-bg:            #000000;   /* app background — pure black */
  --n-bg-elevated:    #16181c;  /* cards, modals */
  --n-bg-hover:       #080808;  /* hover surface on black */
  --n-bg-input:        #202327; /* input fields */
  --n-border:          #2f3336; /* subtle dividers */
  --n-border-soft:     #1c1f23;

  /* --- Text --- */
  --n-text:            #e7e9ea; /* primary text - high contrast */
  --n-text-secondary:  #71767b; /* muted gray */
  --n-text-tertiary:   #536471;

  /* --- Brand / Accent --- */
  --n-accent:          #1d9bf0; /* X blue */
  --n-accent-hover:    #1a8cd8;
  --n-accent-soft:     rgba(29, 155, 240, 0.1);

  /* --- Status colors --- */
  --n-green:           #00ba7c; /* online / success */
  --n-red:             #f4212e; /* destructive / errors */
  --n-yellow:          #ffd400; /* premium / verified accent option */
  --n-purple:          #7856ff;

  /* --- Radii & spacing --- */
  --n-radius-sm:       8px;
  --n-radius-md:       14px;
  --n-radius-lg:       18px;
  --n-radius-full:     999px;

  /* --- Shadows (very light use — minimal glassmorphism only) --- */
  --n-shadow-sm:       0 1px 2px rgba(0,0,0,0.4);
  --n-shadow-md:       0 4px 16px rgba(0,0,0,0.5);

  /* --- Typography --- */
  --n-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  /* --- Layout --- */
  --n-header-height:   53px;
  --n-bottomnav-height: 56px;
  --n-max-width:       600px;
}

/* ============================================================================
   RESET & BASE
   ============================================================================ */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--n-bg);
  color: var(--n-text);
  font-family: var(--n-font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  /* Was "none", which also disables the browser/PWA's native
     pull-to-refresh gesture (that gesture is implemented by the browser
     as an overscroll bounce at the very top of the document, so blocking
     document-level overscroll blocks it too). "auto" restores native
     pull-to-refresh on any page that scrolls the document itself (feed,
     chats list, discover, profile, settings, wallet, ...). Pages that
     scroll an inner container instead of the document (e.g. chat.html's
     .n-messages) are unaffected either way since body itself never
     scrolls there — see overscroll-behavior: contain on those inner
     scroll containers below/in their own stylesheets, which stops a
     message list's own scroll from chaining into the page behind it. */
  overscroll-behavior-y: auto;
}

body {
  font-size: 15px;
  line-height: 1.4;
  padding-bottom: calc(var(--n-bottomnav-height) + env(safe-area-inset-bottom));
}

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

img, video { max-width: 100%; display: block; }

button {
  font-family: inherit;
  cursor: pointer;
}

input, textarea, select {
  font-family: inherit;
  background: var(--n-bg-input);
  border: 1px solid transparent;
  color: var(--n-text);
  border-radius: var(--n-radius-sm);
}

input::placeholder, textarea::placeholder {
  color: var(--n-text-secondary);
}

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

/* Visible focus rings for accessibility */
:focus-visible {
  outline: 2px solid var(--n-accent);
  outline-offset: 2px;
}

/* ============================================================================
   SCROLLBAR (minimal, dark)
   ============================================================================ */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--n-border); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--n-text-tertiary); }

/* ============================================================================
   TYPOGRAPHY UTILITIES
   ============================================================================ */

.n-text-xs   { font-size: 12px; }
.n-text-sm   { font-size: 13px; }
.n-text-base { font-size: 15px; }
.n-text-lg   { font-size: 17px; }
.n-text-xl   { font-size: 20px; }
.n-text-2xl  { font-size: 24px; }

.n-font-bold      { font-weight: 700; }
.n-font-semibold  { font-weight: 600; }
.n-font-extrabold { font-weight: 800; }

.n-muted     { color: var(--n-text-secondary); }
.n-tertiary  { color: var(--n-text-tertiary); }

/* ============================================================================
   LAYOUT SHELL
   ============================================================================ */

.n-app {
  max-width: var(--n-max-width);
  margin: 0 auto;
  min-height: 100vh;
  border-left: 1px solid var(--n-border-soft);
  border-right: 1px solid var(--n-border-soft);
  position: relative;
}

.n-header {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--n-header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: rgba(0,0,0,0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--n-border-soft);
}

.n-header h1 {
  font-size: 19px;
  font-weight: 800;
  margin: 0;
  letter-spacing: -0.2px;
}

.n-page { padding-bottom: 24px; }

/* ============================================================================
   BOTTOM NAVIGATION
   ============================================================================ */

.n-bottomnav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  max-width: var(--n-max-width);
  margin: 0 auto;
  height: calc(var(--n-bottomnav-height) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(0,0,0,0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--n-border-soft);
  display: flex;
  align-items: center;
  justify-content: space-around;
}

.n-navitem {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  flex: 1;
  height: 100%;
  color: var(--n-text-secondary);
  background: none;
  border: none;
  position: relative;
  transition: color .15s ease;
}

.n-navitem svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
}

.n-navitem.active {
  color: var(--n-text);
}

.n-navitem.active svg {
  fill: currentColor;
  stroke: none;
}

.n-badge {
  background: var(--n-accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

.n-navitem .n-badge {
  position: absolute;
  top: 4px;
  right: 22%;
  min-width: 16px;
  height: 16px;
  font-size: 10px;
}

/* ============================================================================
   BUTTONS
   ============================================================================ */

.n-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-weight: 700;
  font-size: 15px;
  border-radius: var(--n-radius-full);
  border: 1px solid transparent;
  padding: 10px 20px;
  transition: opacity .15s ease, background .15s ease, transform .05s ease;
  white-space: nowrap;
}

.n-btn:active { transform: scale(0.98); }

.n-btn-primary {
  background: var(--n-text);
  color: #000;
}
.n-btn-primary:hover { opacity: 0.88; }
.n-btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.n-btn-accent {
  background: var(--n-accent);
  color: #fff;
}
.n-btn-accent:hover { background: var(--n-accent-hover); }

.n-btn-outline {
  background: transparent;
  border: 1px solid var(--n-border);
  color: var(--n-text);
}
.n-btn-outline:hover { background: var(--n-bg-hover); }

.n-btn-danger {
  background: transparent;
  border: 1px solid var(--n-red);
  color: var(--n-red);
}
.n-btn-danger:hover { background: rgba(244, 33, 46, 0.1); }

.n-btn-ghost {
  background: transparent;
  color: var(--n-text);
}
.n-btn-ghost:hover { background: var(--n-bg-hover); }

.n-btn-block { width: 100%; }
.n-btn-sm { padding: 6px 14px; font-size: 13px; }
.n-btn-icon { padding: 8px; border-radius: 999px; }

/* Standalone icon-only button (post card menu, composer header back arrow,
   etc.) — previously had no global definition, so it silently fell back to
   the browser's default <button> chrome (white box + border) on every page
   except create-post.html, which had its own scoped override. */
.n-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 999px;
  color: var(--n-text-secondary);
  transition: background .15s ease, color .15s ease, transform .05s ease;
}
.n-icon-btn:hover { background: var(--n-bg-hover); color: var(--n-text); }
.n-icon-btn:active { transform: scale(0.92); }

/* ============================================================================
   FORMS
   ============================================================================ */

.n-field { margin-bottom: 16px; }

.n-field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--n-text-secondary);
  margin-bottom: 6px;
}

.n-input, .n-textarea, .n-select {
  width: 100%;
  padding: 13px 14px;
  font-size: 16px; /* 16px prevents iOS auto-zoom on focus */
  border: 1px solid var(--n-border);
  background: var(--n-bg-input);
  border-radius: var(--n-radius-sm);
}

.n-input:focus, .n-textarea:focus, .n-select:focus {
  border-color: var(--n-accent);
  outline: none;
}

.n-input.error, .n-textarea.error {
  border-color: var(--n-red);
}

.n-error-text {
  color: var(--n-red);
  font-size: 12px;
  margin-top: 4px;
}

.n-help-text {
  color: var(--n-text-secondary);
  font-size: 12px;
  margin-top: 4px;
}

/* ============================================================================
   CARDS
   ============================================================================ */

.n-card {
  background: var(--n-bg-elevated);
  border: 1px solid var(--n-border);
  border-radius: var(--n-radius-md);
  padding: 16px;
}

.n-card-borderless {
  background: transparent;
  border-bottom: 1px solid var(--n-border-soft);
  padding: 12px 16px;
}

.n-card-borderless:hover {
  background: var(--n-bg-hover);
}

/* ============================================================================
   AVATARS
   ============================================================================ */

.n-avatar {
  border-radius: 50%;
  object-fit: cover;
  background: var(--n-bg-input);
  flex-shrink: 0;
}
.n-avatar-xs { width: 28px; height: 28px; }
.n-avatar-sm { width: 36px; height: 36px; }
.n-avatar-md { width: 48px; height: 48px; }
.n-avatar-lg { width: 64px; height: 64px; }
.n-avatar-xl { width: 96px; height: 96px; }

.n-avatar-ring {
  border: 2px solid var(--n-accent);
  padding: 2px;
}

/* online dot */
.n-avatar-wrap { position: relative; display: inline-block; }
.n-online-dot {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--n-green);
  border: 2px solid var(--n-bg);
}

/* ============================================================================
   BADGES
   ============================================================================ */

.n-verified-badge {
  display: inline-flex;
  width: 18px;
  height: 18px;
  vertical-align: middle;
  color: var(--n-accent);
}
.n-verified-badge svg { width: 100%; height: 100%; fill: currentColor; }

.n-premium-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 700;
  color: #000;
  background: linear-gradient(135deg, #ffd400, #ffb700);
  padding: 2px 8px;
  border-radius: 999px;
}

.n-sponsored-tag {
  font-size: 12px;
  color: var(--n-text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
}

.n-ad-card {
  border: 1px solid var(--n-border-soft);
}

.n-ad-embed-frame {
  width: 100%;
  min-height: 250px;
  border: none;
  border-radius: 12px;
  display: block;
  background: var(--n-surface-2, #16181c);
  overflow: hidden;
}

.n-ad-engagement-disabled {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 8px;
  color: var(--n-muted);
  font-size: 12px;
}

.n-story-ad-slide {
  position: relative;
  width: 100%;
  height: 100%;
  background: #000;
}
.n-story-ad-slide img, .n-story-ad-slide video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* ============================================================================
   SKELETON / LOADING
   ============================================================================ */

.n-skeleton {
  background: linear-gradient(90deg, var(--n-bg-input) 25%, var(--n-border) 37%, var(--n-bg-input) 63%);
  background-size: 400% 100%;
  animation: n-shimmer 1.4s ease infinite;
  border-radius: var(--n-radius-sm);
}
@keyframes n-shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

.n-spinner {
  width: 22px;
  height: 22px;
  border: 2.5px solid var(--n-border);
  border-top-color: var(--n-accent);
  border-radius: 50%;
  animation: n-spin 0.7s linear infinite;
}
@keyframes n-spin { to { transform: rotate(360deg); } }

/* ============================================================================
   TOAST
   ============================================================================ */

.n-toast-container {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 92%;
  max-width: 420px;
}

.n-toast {
  background: var(--n-bg-elevated);
  border: 1px solid var(--n-border);
  border-radius: var(--n-radius-sm);
  padding: 12px 16px;
  font-size: 14px;
  box-shadow: var(--n-shadow-md);
  animation: n-toast-in .25s ease;
}
.n-toast.success { border-color: var(--n-green); }
.n-toast.error { border-color: var(--n-red); }

.n-toast-notify {
  border-color: var(--n-accent);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.n-toast-notify-title { font-weight: 700; color: var(--n-text); }
.n-toast-notify-body {
  color: var(--n-text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

/* ============================================================================
   MODAL / SHEET
   ============================================================================ */

.n-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
@media (min-width: 600px) {
  .n-modal-overlay { align-items: center; }
}

.n-modal {
  background: var(--n-bg-elevated);
  border: 1px solid var(--n-border);
  border-radius: var(--n-radius-lg) var(--n-radius-lg) 0 0;
  width: 100%;
  max-width: var(--n-max-width);
  max-height: 85vh;
  overflow-y: auto;
  /* Stop this sheet's own scroll from chaining into whatever page is
     behind it now that document-level overscroll is allowed again (for
     native pull-to-refresh) — without this, scrolling to the top/bottom
     of a long modal could bounce/refresh the page underneath it. */
  overscroll-behavior-y: contain;
  animation: n-sheet-up .2s ease;
  padding: 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
}
@media (min-width: 600px) {
  .n-modal { border-radius: var(--n-radius-lg); }
}

@keyframes n-sheet-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.n-modal-dialog {
  border-radius: var(--n-radius-lg) !important;
  max-width: 380px;
  animation: n-dialog-in .15s ease;
}
@keyframes n-dialog-in {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

/* ============================================================================
   UTILITY CLASSES
   ============================================================================ */

.n-flex { display: flex; }
.n-flex-col { display: flex; flex-direction: column; }
.n-items-center { align-items: center; }
.n-justify-between { justify-content: space-between; }
.n-justify-center { justify-content: center; }
.n-gap-1 { gap: 4px; }
.n-gap-2 { gap: 8px; }
.n-gap-3 { gap: 12px; }
.n-gap-4 { gap: 16px; }
.n-w-full { width: 100%; }
.n-text-center { text-align: center; }
.n-mt-1 { margin-top: 4px; }
.n-mt-2 { margin-top: 8px; }
.n-mt-3 { margin-top: 12px; }
.n-mt-4 { margin-top: 16px; }
.n-mt-6 { margin-top: 24px; }
.n-mb-1 { margin-bottom: 4px; }
.n-mb-2 { margin-bottom: 8px; }
.n-mb-3 { margin-bottom: 12px; }
.n-mb-4 { margin-bottom: 16px; }
.n-mb-6 { margin-bottom: 24px; }
.n-p-4 { padding: 16px; }
.n-hidden { display: none !important; }
.n-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.n-divider { height: 1px; background: var(--n-border-soft); border: none; margin: 0; }
.n-sticky-top { position: sticky; top: var(--n-header-height); z-index: 30; }

/* ============================================================================
   GLOBAL MOBILE UI TOUCH BEHAVIOR
   Prevent accidental text selection/highlighting when tapping/pressing UI.
   Editable fields remain selectable so typing/cursor movement still works.
   ============================================================================ */
html, body,
button, a, label,
.n-card, .n-post, .n-story, .n-story-card,
.n-bottom-nav, .n-topbar, .n-header, .n-modal,
svg, img, video, canvas {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

html {
  -webkit-tap-highlight-color: transparent;
}

/* Keep text selection/copying available inside editable controls. */
input,
textarea,
select,
[contenteditable="true"],
[contenteditable=""] {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

/* Interactive controls should feel like app controls rather than selectable text. */
button,
a,
[role="button"] {
  -webkit-tap-highlight-color: transparent;
}


/* Global unread-chat entry: independent of the Chats page FAB. */
#nichatGlobalChatFab {
  position: fixed;
  right: max(14px, calc((100vw - var(--n-max-width)) / 2 + 14px));
  bottom: calc(var(--n-bottomnav-height) + 16px + env(safe-area-inset-bottom, 0px));
  width: 54px;
  height: 54px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--n-accent, #e53935);
  color: #fff;
  text-decoration: none;
  box-shadow: 0 6px 18px rgba(0,0,0,.30);
  z-index: 1000;
  isolation: isolate;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
  will-change: left, top;
  transition: left .22s cubic-bezier(.2,.8,.2,1), top .22s cubic-bezier(.2,.8,.2,1), box-shadow .16s ease, transform .16s ease;
}
#nichatGlobalChatFab.nichat-fab-dragging {
  transition: none;
  cursor: grabbing;
  box-shadow: 0 8px 22px rgba(0,0,0,.34);
}
#nichatGlobalChatFab.nichat-fab-pressing {
  transform: scale(.97);
}
#nichatGlobalChatFab.nichat-fab-snapping {
  transition: left .24s cubic-bezier(.22,.9,.28,1), top .24s cubic-bezier(.22,.9,.28,1), box-shadow .16s ease, transform .16s ease;
}
#nichatGlobalChatFab[hidden] { display: none !important; }
#nichatGlobalChatFab svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; }
#nichatGlobalChatFab svg path { fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; }
#nichatGlobalChatFab #globalChatBadge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 21px;
  height: 21px;
  padding: 0 5px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  background: #f04444;
  color: #fff;
  border: 2px solid var(--n-bg, #000);
  font: 800 10px/1 system-ui, sans-serif;
}
#nichatGlobalChatFab #globalChatBadge[hidden] { display: none !important; }
@media (max-width: 380px) {
  #nichatGlobalChatFab { width: 50px; height: 50px; right: 12px; }
  #nichatGlobalChatFab svg { width: 24px; height: 24px; }
}

/* ============================================================================
   V28 Tori menu + expanded primary navigation
   ============================================================================ */
.n-tori-header {
  min-height: var(--n-header-height);
}
.n-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.n-header-action {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  transition: background .15s ease, transform .12s ease;
}
.n-header-action:active {
  transform: scale(.95);
  background: var(--n-bg-input);
}
.n-bottomnav--expanded {
  gap: 0;
}
.n-bottomnav--expanded .n-navitem {
  min-width: 0;
  padding: 4px 2px;
  gap: 2px;
}
.n-bottomnav--expanded .n-navlabel {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 10px;
  line-height: 12px;
  font-weight: 600;
}
.n-bottomnav--expanded .n-navitem svg {
  width: 22px;
  height: 22px;
}
.n-nav-icon-wrap {
  position: relative;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
}
.n-nav-icon-wrap > svg {
  width: 22px;
  height: 22px;
}
.n-bottomnav--expanded .n-badge {
  position: absolute;
  top: -7px;
  right: -10px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  font-size: 9px;
  line-height: 16px;
  box-shadow: 0 0 0 2px rgba(0,0,0,.92);
}
@media (max-width: 390px) {
  .n-bottomnav--expanded .n-navlabel { font-size: 9px; }
  .n-bottomnav--expanded .n-navitem svg,
  .n-bottomnav--expanded .n-nav-icon-wrap > svg {
    width: 21px;
    height: 21px;
  }
}

/* V29 profile/menu polish */
.n-profile-actions .n-btn{min-width:112px}
@media(max-width:390px){.n-profile-actions .n-btn{min-width:0}.menu-invite{min-height:86px;padding:14px}.menu-invite-copy strong{font-size:17px}.menu-invite-copy small{font-size:12px}}
