/* ═══════════════════════════════════════════════════════════════════════════
   VIVA GERENCIA — Responsive + Performance CSS v3
   Mobile-first · Touch-optimized · PWA-ready · Pro level
   Breakpoints: 480 · 640 · 768 · 900 · 1100 · 1280
═══════════════════════════════════════════════════════════════════════════ */

/* ── PERFORMANCE BASE ──────────────────────────────────────────────────── */
*, *::before, *::after {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  height: -webkit-fill-available;
}
body {
  min-height: 100vh;
  min-height: -webkit-fill-available;
  overscroll-behavior-y: contain;
}
img, video { max-width: 100%; height: auto; }

/* ── PWA SAFE AREAS (iPhone notch / home bar) ─────────────────────────── */
.topbar {
  padding-top: env(safe-area-inset-top);
  padding-left: max(2rem, env(safe-area-inset-left));
  padding-right: max(2rem, env(safe-area-inset-right));
}
.shell {
  padding-bottom: max(2.5rem, env(safe-area-inset-bottom));
}

/* ── TOUCH TARGETS — min 44×44px ─────────────────────────────────────── */
button, [role="button"] { min-height: 44px; }
a:not(.tab):not(#modNav a) { min-height: 44px; display: inline-flex; align-items: center; }

/* ── ELEGANT SCROLLBARS ────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.14); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.28); }
* { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.14) transparent; }

/* ── FOCUS RINGS ───────────────────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid rgba(91,136,236,.8) !important;
  outline-offset: 2px !important;
}

/* ── TEXT SELECTION ────────────────────────────────────────────────────── */
::selection { background: rgba(59,130,246,.3); color: #fff; }

/* ── FORCE DARK (financial SaaS — always dark) ────────────────────────── */
html { color-scheme: dark; }


/* ══════════════════════════════════════════════════════════════════════════
   TOPBAR
══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  .topbar {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
    height: 56px !important;
  }
  .topbar-center, .live-badge { display: none !important; }
  .logo-text span:last-child { display: none; }
}
@media (max-width: 480px) {
  .topbar { padding-left: .75rem !important; padding-right: .75rem !important; }
  .topbar-right { gap: .25rem !important; }
  .btn-topbar { padding: .28rem .5rem !important; font-size: .65rem !important; }
  .btn-refresh { display: none !important; }
}


/* ══════════════════════════════════════════════════════════════════════════
   HAMBURGER BUTTON
══════════════════════════════════════════════════════════════════════════ */
#_vivaBurger {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  order: -1;
  margin-right: 4px;
  border-radius: 8px;
  transition: background .2s;
  min-height: 40px;
  align-items: center;
  justify-content: center;
}
#_vivaBurger:hover { background: rgba(255,255,255,.07); }
#_vivaBurger span {
  display: block;
  width: 21px;
  height: 2px;
  background: rgba(255,255,255,.8);
  border-radius: 2px;
  transition: all .28s cubic-bezier(.16,1,.3,1);
}
#_vivaBurger[aria-expanded="true"] span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
#_vivaBurger[aria-expanded="true"] span:nth-child(2) {
  opacity: 0;
  transform: scaleX(0);
}
#_vivaBurger[aria-expanded="true"] span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

@media (max-width: 768px) {
  #_vivaBurger { display: flex !important; }

  #modNav {
    position: fixed !important;
    top: 56px !important;
    left: 0 !important;
    bottom: 0 !important;
    width: min(290px, 88vw) !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    background: #060E1C !important;
    border-right: 1px solid #1A2E4A !important;
    padding: .75rem .5rem !important;
    padding-bottom: max(.75rem, env(safe-area-inset-bottom)) !important;
    gap: 2px !important;
    transform: translateX(-100%) !important;
    transition: transform .32s cubic-bezier(.16,1,.3,1) !important;
    z-index: 300 !important;
    height: auto !important;
    will-change: transform;
  }
  #modNav.nav-open { transform: translateX(0) !important; }

  #modNav a {
    display: flex !important;
    align-items: center !important;
    width: 100% !important;
    padding: 12px 14px !important;
    font-size: 13px !important;
    border-bottom: none !important;
    border-radius: 9px !important;
    white-space: nowrap !important;
    min-height: 46px !important;
  }
  #modNav a:hover, #modNav a.active { background: rgba(255,255,255,.07) !important; }
  #modNav [style*="flex:1"] { display: none !important; }

  #_vivaNavOverlay {
    display: block !important;
    position: fixed !important;
    inset: 0 !important;
    background: rgba(0,0,0,.5) !important;
    z-index: 299 !important;
    opacity: 0 !important;
    pointer-events: none !important;
    transition: opacity .32s !important;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
  }
  #_vivaNavOverlay.active { opacity: 1 !important; pointer-events: all !important; }
}

#modNav { scrollbar-width: none !important; -ms-overflow-style: none !important; }
#modNav::-webkit-scrollbar { display: none !important; }

@media (max-width: 900px) {
  #modNav { top: 56px !important; padding: 0 .5rem !important; }
  #modNav a { padding: 7px 11px !important; font-size: 10.5px !important; }
}


/* ══════════════════════════════════════════════════════════════════════════
   SHELL / LAYOUT
══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  .shell { padding: 0 1rem 2.5rem !important; }
  .tab-bar { padding: .9rem 1rem .5rem !important; gap: .4rem !important; flex-wrap: wrap !important; }
}
@media (max-width: 480px) {
  .shell { padding: 0 .6rem 2rem !important; }
  .tab-bar { padding: .75rem .6rem .4rem !important; }
  .tab { padding: .35rem .75rem !important; font-size: .7rem !important; }
}


/* ══════════════════════════════════════════════════════════════════════════
   KPI GRID
══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr) !important; }
}
@media (max-width: 640px) {
  .kpi-grid { grid-template-columns: 1fr 1fr !important; gap: .6rem !important; }
  .kpi-card { padding: .9rem 1rem !important; }
  .kpi-card .kpi-val { font-size: 1.4rem !important; }
}
@media (max-width: 380px) {
  .kpi-grid { grid-template-columns: 1fr !important; }
}


/* ══════════════════════════════════════════════════════════════════════════
   CHARTS
══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 1000px) {
  .charts-grid { grid-template-columns: 1fr !important; }
  [style*="grid-template-columns:2fr"],
  [style*="grid-template-columns: 2fr"] { grid-template-columns: 1fr !important; }
}
@media (max-width: 768px) {
  canvas { max-height: 220px !important; }
  .chart-card, .card-chart { padding: 1rem !important; }
}
@media (max-width: 480px) { canvas { max-height: 180px !important; } }


/* ══════════════════════════════════════════════════════════════════════════
   TABLES
══════════════════════════════════════════════════════════════════════════ */
.table-wrap, .users-table-wrap, .sa-table-wrap {
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch !important;
}
table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
@media print { table { display: table; overflow: visible; } }

@media (max-width: 768px) {
  th, td { padding: .5rem .65rem !important; font-size: .74rem !important; white-space: nowrap; }
}
@media (max-width: 480px) {
  th, td { padding: .4rem .55rem !important; font-size: .7rem !important; }
}


/* ══════════════════════════════════════════════════════════════════════════
   CONNECT BAR
══════════════════════════════════════════════════════════════════════════ */
.connect-bar { flex-wrap: wrap !important; }
@media (max-width: 640px) {
  .connect-bar {
    flex-direction: column !important;
    gap: .5rem !important;
    padding: .875rem !important;
  }
  .connect-bar input,
  .connect-bar button,
  .connect-bar a {
    width: 100% !important;
    box-sizing: border-box !important;
    min-height: 46px !important;
  }
}


/* ══════════════════════════════════════════════════════════════════════════
   MODAL — bottom sheet on mobile
══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
  .modal-card {
    padding: 1.5rem 1.25rem !important;
    border-radius: 20px 20px 0 0 !important;
    max-height: 92vh !important;
    overflow-y: auto !important;
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    margin: 0 !important;
    max-width: 100% !important;
  }
  .modal-card h2 { font-size: 1.2rem !important; }
}


/* ══════════════════════════════════════════════════════════════════════════
   LOGIN / AUTH PAGES
══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  .login-wrap { padding: .75rem !important; }
  .login-card { padding: 1.75rem 1.25rem 1.5rem !important; border-radius: 18px !important; }
  .logo-name { font-size: 18px !important; }
  .btn-login { padding: 14px !important; font-size: .82rem !important; min-height: 50px !important; }
}
@media (max-width: 360px) {
  .login-card { padding: 1.5rem 1rem 1.25rem !important; }
}


/* ══════════════════════════════════════════════════════════════════════════
   FORMS — iOS zoom prevention (font-size >= 16px)
══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="search"],
  input[type="url"],
  select, textarea {
    font-size: 16px !important;
    min-height: 46px !important;
  }
}


/* ══════════════════════════════════════════════════════════════════════════
   SECTION TITLES
══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  .section-title { font-size: .6rem !important; letter-spacing: 1.5px !important; }
}


/* ══════════════════════════════════════════════════════════════════════════
   PROFILE / USERS / SUPERADMIN
══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .profile-grid,
  [style*="grid-template-columns:1fr 1fr"]:not(.kpi-grid),
  [style*="grid-template-columns: 1fr 1fr"]:not(.kpi-grid) {
    grid-template-columns: 1fr !important;
  }
}


/* ══════════════════════════════════════════════════════════════════════════
   TRIAL BANNER
══════════════════════════════════════════════════════════════════════════ */
#_viva_trial_banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 99998;
  background: linear-gradient(90deg, #1A237E, #2563EB, #1A237E);
  background-size: 200%;
  animation: bannerShimmer 5s linear infinite;
  color: #fff;
  text-align: center;
  padding: 7px 1rem;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .4px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .75rem;
  flex-wrap: wrap;
}
#_viva_trial_banner a { color: #93C5FD; text-decoration: underline; font-weight: 700; }
@keyframes bannerShimmer {
  0% { background-position: 0% 50%; }
  100% { background-position: 200% 50%; }
}
@media (max-width: 480px) {
  #_viva_trial_banner { font-size: 10px; padding: 6px .75rem; }
}


/* ══════════════════════════════════════════════════════════════════════════
   SESSION TIMER
══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  #_viva_session_timer {
    bottom: max(6px, env(safe-area-inset-bottom)) !important;
    right: 6px !important;
    font-size: 9px !important;
    padding: 4px 8px !important;
  }
}


/* ══════════════════════════════════════════════════════════════════════════
   SKELETON LOADERS
══════════════════════════════════════════════════════════════════════════ */
.skeleton {
  background: linear-gradient(90deg, #0F1E38 25%, #162640 50%, #0F1E38 75%);
  background-size: 400% 100%;
  animation: skeletonPulse 1.4s ease infinite;
  border-radius: 6px;
  color: transparent !important;
  pointer-events: none;
}
@keyframes skeletonPulse {
  0% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}


/* ══════════════════════════════════════════════════════════════════════════
   REDUCED MOTION
══════════════════════════════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}


/* ══════════════════════════════════════════════════════════════════════════
   PRINT
══════════════════════════════════════════════════════════════════════════ */
@media print {
  .topbar, #modNav, .tab-bar, #connect-modal,
  #_viva_session_timer, #_vivaBurger, #_vivaNavOverlay,
  #_viva_trial_banner { display: none !important; }
  .shell { padding: 0 !important; max-width: 100% !important; }
  body { background: #fff !important; color: #000 !important; }
  canvas { max-height: none !important; }
  table { display: table; overflow: visible; }
}
