/* VELTRIX OS — Mobile-First CSS v3.0
 * Bottom nav, touch targets, pull-to-refresh, safe areas, PWA polish
 */

/* ── SAFE AREA & ROOT ────────────────────────────────────────────────────── */

:root {
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);
  --bottom-nav-height: 60px;
}

/* ── BOTTOM NAVIGATION (mobile only) ────────────────────────────────────── */

.vx-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--bottom-nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: #111118;
  border-top: 1px solid rgba(255,255,255,.08);
  z-index: 900;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.vx-bottom-nav-inner {
  display: flex;
  height: var(--bottom-nav-height);
  align-items: stretch;
}

.vx-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  border: none;
  background: none;
  color: #64748b;
  font-size: 10px;
  font-weight: 500;
  text-decoration: none;
  position: relative;
  transition: color .15s;
  -webkit-tap-highlight-color: transparent;
  padding: 0;
  min-height: 44px;
}

.vx-tab .tab-icon {
  font-size: 22px;
  line-height: 1;
}

.vx-tab.active {
  color: #7c3aed;
}

.vx-tab.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 20%;
  right: 20%;
  height: 2px;
  background: #7c3aed;
  border-radius: 0 0 3px 3px;
}

.vx-tab-badge {
  position: absolute;
  top: 6px;
  right: calc(50% - 16px);
  min-width: 16px;
  height: 16px;
  background: #ef4444;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  border-radius: 8px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* ── MOBILE FAB ─────────────────────────────────────────────────────────── */

.vx-mobile-fab {
  display: none;
  position: fixed;
  bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 16px);
  right: 20px;
  width: 52px;
  height: 52px;
  background: linear-gradient(135deg, #7c3aed, #a855f7);
  border-radius: 50%;
  border: none;
  color: #fff;
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(124,58,237,.4);
  z-index: 901;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: transform .15s;
}

.vx-mobile-fab:active {
  transform: scale(.93);
}

.vx-fab-menu {
  display: none;
  position: fixed;
  bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 80px);
  right: 16px;
  flex-direction: column;
  gap: 10px;
  z-index: 901;
}

.vx-fab-item {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-end;
}

.vx-fab-label {
  background: #1a1a24;
  border: 1px solid rgba(255,255,255,.1);
  color: #f1f5f9;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.vx-fab-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: #1a1a24;
  border: 1px solid rgba(124,58,237,.4);
  color: #f1f5f9;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

/* ── TOUCH TARGET MINIMUM 44×44 ─────────────────────────────────────────── */

@media (max-width: 768px) {
  button, .btn, a.btn, [role="button"],
  input[type="checkbox"], input[type="radio"],
  select, .toggle-sw {
    min-height: 44px;
    touch-action: manipulation;
  }

  input[type="text"],
  input[type="email"],
  input[type="number"],
  input[type="tel"],
  input[type="password"],
  input[type="date"],
  textarea, select {
    font-size: 16px !important; /* Prevent iOS zoom */
    min-height: 44px;
    padding: 10px 14px !important;
  }

  /* ── GLOBAL FONT READABILITY ── */
  body, p, li, label, .form-label { font-size: 14px; }
  small, .text-xs, .font-xs { font-size: 12px !important; }

  /* ── LAYOUT ── */
  .sidebar  { display: none !important; }
  .sb       { display: none !important; }   /* unified sidebar */

  /* Sidebar mobile-open toggle */
  .sb.mobile-open { display: flex !important; position: fixed; left: 0; top: 0; bottom: 0; width: 260px; z-index: 950; overflow-y: auto; }

  .main {
    padding-bottom: calc(var(--bottom-nav-height) + var(--safe-bottom));
    /* no left margin on mobile — sidebar hidden */
    margin-left: 0 !important;
  }

  .content {
    padding: 16px !important;
  }

  /* ── TOPBAR MOBILE ── */
  .topbar {
    padding: 0 14px !important;
    padding-top: var(--safe-top) !important;
    height: calc(52px + var(--safe-top)) !important;
  }

  .topbar-title {
    font-size: 14px !important;
  }

  /* ── GRIDS COLLAPSE ── */
  .metrics-row,
  .stats-grid,
  .featured-grid,
  [class*="-grid"],
  .form-row,
  .form-grid {
    grid-template-columns: 1fr !important;
  }

  /* ── TABLES → CARD VIEW ── */
  table { display: block; width: 100%; }
  thead { display: none; }
  tbody { display: flex; flex-direction: column; gap: 10px; }
  tr {
    display: flex;
    flex-direction: column;
    background: #111118;
    border: 1px solid rgba(255,255,255,.08);
    border-radius: 10px;
    padding: 12px;
  }
  td {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 4px 0 !important;
    border-bottom: none !important;
    font-size: 13px;
  }
  td::before {
    content: attr(data-label);
    font-size: 10px;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: .5px;
    min-width: 80px;
    flex-shrink: 0;
    margin-top: 1px;
  }

  /* ── DRAWER FULL SCREEN ON MOBILE ── */
  .drawer {
    width: 100vw !important;
    border-left: none !important;
  }

  /* ── MODALS FULL SCREEN ── */
  .modal {
    width: 100vw !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    margin: 0 !important;
  }

  .wizard {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
  }

  /* ── TABS SCROLL ── */
  .tab-nav {
    width: 100% !important;
    overflow-x: auto !important;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tab-nav::-webkit-scrollbar { display: none; }

  .tab-btn {
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* ── CATEGORY CHIPS SCROLL ── */
  .cat-chips {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 4px;
  }
  .cat-chips::-webkit-scrollbar { display: none; }
  .cat-chip { flex-shrink: 0; }

  /* ── CARDS ── */
  .plugin-card, .biz-card, .featured-card {
    width: 100%;
  }

  .featured-grid {
    display: flex !important;
    flex-direction: column !important;
  }

  /* ── HERO SECTION ── */
  .hero-search {
    padding: 20px 16px !important;
  }
  .hero-search h2 {
    font-size: 20px !important;
  }

  /* SHOW BOTTOM NAV & FAB */
  .vx-bottom-nav { display: flex !important; }
  .vx-mobile-fab { display: flex !important; }

  /* ── NO HORIZONTAL OVERFLOW ── */
  body, .content, .main { max-width: 100vw; overflow-x: hidden; }
  .twrap, .touter { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* ── FORMS FULL WIDTH ── */
  .form-row, .form-grid, .form-group { grid-template-columns: 1fr !important; }
  .form-input, input, select, textarea { width: 100% !important; box-sizing: border-box; }

  /* ── BUSINESS SWITCHER MOBILE ── */
  .vx-biz-chip .biz-name {
    max-width: 100px !important;
  }

  /* ── FONT SIZES ── */
  .metric-value, .stat-value { font-size: 22px !important; }
  .section-title { font-size: 13px !important; }
}

/* ── SWIPE GESTURES (CSS hint) ─────────────────────────────────────────── */

.swipe-hint {
  pointer-events: none;
  user-select: none;
}

/* ── PULL-TO-REFRESH ────────────────────────────────────────────────────── */

.vx-ptr {
  text-align: center;
  padding: 12px;
  font-size: 13px;
  color: #64748b;
  position: absolute;
  top: -50px;
  left: 0;
  right: 0;
  transition: top .2s;
}

.vx-ptr.active { top: 0; }

/* ── SKELETON LOADING ───────────────────────────────────────────────────── */

.skeleton {
  background: linear-gradient(90deg, #1a1a24 25%, #22222f 50%, #1a1a24 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s infinite;
  border-radius: 6px;
}

@keyframes skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-text  { height: 14px; margin-bottom: 8px; }
.skeleton-title { height: 20px; width: 60%; margin-bottom: 12px; }
.skeleton-card  { height: 120px; border-radius: 12px; }

/* ── BOTTOM SHEET (mobile alternative to modal) ─────────────────────────── */

.bottom-sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 800;
  display: none;
}

.bottom-sheet-overlay.open { display: block; }

.bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #1a1a24;
  border-top: 1px solid rgba(255,255,255,.1);
  border-radius: 20px 20px 0 0;
  padding: 16px 20px calc(20px + var(--safe-bottom));
  z-index: 801;
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(.34,1.56,.64,1);
  max-height: 85vh;
  overflow-y: auto;
}

.bottom-sheet.open {
  transform: translateY(0);
}

.bottom-sheet-handle {
  width: 36px;
  height: 4px;
  background: rgba(255,255,255,.2);
  border-radius: 2px;
  margin: 0 auto 16px;
}

/* ── MOMENTUM SCROLLING ─────────────────────────────────────────────────── */

.content,
.sidebar-nav,
.drawer,
.vxdd-list,
.modal,
.wizard-body {
  -webkit-overflow-scrolling: touch;
}

/* ── PWA STANDALONE MODE ────────────────────────────────────────────────── */

@media all and (display-mode: standalone) {
  .topbar {
    padding-top: var(--safe-top) !important;
    height: calc(56px + var(--safe-top)) !important;
  }

  /* Hide browser-only elements */
  .browser-only { display: none !important; }
}

/* ── LANDSCAPE MOBILE ───────────────────────────────────────────────────── */

@media (max-width: 768px) and (orientation: landscape) {
  .vx-bottom-nav {
    height: calc(48px + var(--safe-bottom));
  }
  .vx-tab {
    font-size: 9px;
  }
  .vx-tab .tab-icon {
    font-size: 18px;
  }
}

/* ── DARK MODE SYSTEM ───────────────────────────────────────────────────── */

@media (prefers-color-scheme: dark) {
  /* Already dark — no overrides needed */
}

/* ── REDUCED MOTION ─────────────────────────────────────────────────────── */

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