/**
 * Nivvo — Mobile shell (iPhone / PWA)
 * Carregado por último (após Tailwind CDN) via server.js
 * Ativo somente com html.nv-mobile (classe definida no boot)
 */

/* ── Base ─────────────────────────────────────────────────────────────────── */
html.nv-mobile,
html.nv-mobile body {
  overflow-x: hidden;
  max-width: 100vw;
}

html.nv-mobile body.app-macos-shell {
  -webkit-text-size-adjust: 100%;
  padding: 0;
}

html.nv-mobile body.nv-sidebar-drawer-open {
  overflow: hidden;
  touch-action: none;
}

/* ── Sidebar drawer ───────────────────────────────────────────────────────── */
html.nv-mobile #app-sidebar {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  bottom: 0 !important;
  width: min(300px, 88vw) !important;
  max-width: 88vw !important;
  height: 100dvh !important;
  margin: 0 !important;
  transform: translate3d(-110%, 0, 0) !important;
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1) !important;
  z-index: 200 !important;
  box-shadow: 16px 0 48px rgba(15, 23, 42, 0.2) !important;
  padding-top: env(safe-area-inset-top, 0px) !important;
  padding-bottom: env(safe-area-inset-bottom, 0px) !important;
}

html.nv-mobile #app-sidebar.nv-mobile-open {
  transform: translate3d(0, 0, 0) !important;
}

html.nv-mobile #app-sidebar .sidebar-cmd-kbd {
  display: none !important;
}

html.nv-mobile #sidebar-toggle {
  display: none !important;
}

html.nv-mobile .nv-sidebar-overlay {
  position: fixed;
  inset: 0;
  z-index: 190;
  background: rgba(20, 20, 25, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

html.nv-mobile .nv-sidebar-overlay.is-visible {
  opacity: 1;
  pointer-events: auto;
}

/* ── Header compacto ──────────────────────────────────────────────────────── */
html.nv-mobile #app-shell-header {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  width: 100% !important;
  margin: 0 !important;
  height: calc(3rem + env(safe-area-inset-top, 0px)) !important;
  min-height: calc(3rem + env(safe-area-inset-top, 0px)) !important;
  padding-top: env(safe-area-inset-top, 0px) !important;
  padding-left: max(12px, env(safe-area-inset-left, 0px)) !important;
  padding-right: max(12px, env(safe-area-inset-right, 0px)) !important;
  padding-bottom: 0 !important;
  gap: 8px !important;
  z-index: 120 !important;
  overflow: hidden !important;
  flex-wrap: nowrap !important;
}

html.nv-mobile #app-shell-header .nv-crumbs,
html.nv-mobile #app-shell-header > .flex-1,
html.nv-mobile #nv-shell-history-nav,
html.nv-mobile #btn-layout-undo,
html.nv-mobile #btn-layout-redo,
html.nv-mobile #layout-switcher,
html.nv-mobile #btn-lock-layout,
html.nv-mobile #btn-customizar-cards,
html.nv-mobile #header-user,
html.nv-mobile #app-shell-header .nv-theme-toggle {
  display: none !important;
}

html.nv-mobile .nv-mobile-menu-btn {
  display: inline-grid !important;
  place-items: center;
  flex-shrink: 0;
  width: 38px;
  height: 38px;
}

html.nv-mobile .nv-mobile-page-title {
  display: block !important;
  flex: 1;
  min-width: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

html.nv-mobile #app-shell-header .nv-btn-primary {
  flex-shrink: 0;
  padding: 8px 10px !important;
  font-size: 0 !important;
  gap: 0 !important;
  min-width: 38px;
  justify-content: center;
}

html.nv-mobile #app-shell-header .nv-btn-primary .material-symbols-rounded,
html.nv-mobile #app-shell-header .nv-btn-primary .material-symbols-outlined {
  font-size: 20px !important;
}

/* ── Main full width ────────────────────────────────────────────────────── */
html.nv-mobile #app-shell-main {
  margin-left: 0 !important;
  margin-right: 0 !important;
  left: 0 !important;
  width: 100% !important;
  max-width: 100vw !important;
  min-height: 100dvh !important;
  padding-top: calc(3rem + env(safe-area-inset-top, 0px)) !important;
  padding-bottom: calc(4.75rem + env(safe-area-inset-bottom, 0px)) !important;
  overflow-x: hidden !important;
  box-sizing: border-box !important;
}

html.nv-mobile #app-shell-main > div {
  max-width: 100% !important;
  width: 100% !important;
  padding-left: max(14px, env(safe-area-inset-left, 0px)) !important;
  padding-right: max(14px, env(safe-area-inset-right, 0px)) !important;
  padding-top: 12px !important;
  padding-bottom: 24px !important;
  box-sizing: border-box !important;
}

/* ── Bottom tab bar ───────────────────────────────────────────────────────── */
html.nv-mobile #nv-bottom-nav {
  position: fixed !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  z-index: 300 !important;
  display: grid !important;
  grid-template-columns: repeat(5, 1fr);
  gap: 0;
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom, 0px));
  background: rgba(255, 255, 255, 0.94);
  border-top: 1px solid var(--hairline);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  box-shadow: 0 -6px 28px rgba(20, 20, 25, 0.08);
}

html.dark.nv-mobile #nv-bottom-nav {
  background: rgba(20, 20, 26, 0.92);
}

html.nv-mobile #nv-bottom-nav a,
html.nv-mobile #nv-bottom-nav button {
  display: flex !important;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  padding: 4px 2px;
  border: 0;
  background: transparent;
  color: var(--text-3);
  font-size: 10px;
  font-weight: 700;
  text-decoration: none;
  border-radius: 10px;
  -webkit-tap-highlight-color: transparent;
}

html.nv-mobile #nv-bottom-nav .nv-tab-icon {
  font-size: 18px;
  line-height: 1;
  font-weight: 700;
}

html.nv-mobile #nv-bottom-nav .nv-tab-label {
  font-size: 10px;
  line-height: 1.1;
  letter-spacing: -0.01em;
}

html.nv-mobile #nv-bottom-nav .is-active {
  color: var(--accent) !important;
  background: var(--accent-soft);
}

/* ── Hero / dashboard home ────────────────────────────────────────────────── */
html.nv-mobile .nv-home-hero {
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  gap: 14px !important;
  padding: 16px !important;
  grid-template-columns: 1fr !important;
}

html.nv-mobile .nv-home-hero > div:last-child {
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  justify-content: flex-start !important;
  gap: 8px !important;
}

html.nv-mobile .nv-home-hero .nv-btn {
  width: 100%;
  justify-content: center;
}

html.nv-mobile #saldo-total,
html.nv-mobile .nv-display {
  font-size: clamp(26px, 8.5vw, 38px) !important;
  line-height: 1.05 !important;
  word-break: break-word;
  overflow-wrap: anywhere;
}

html.nv-mobile #saldo-sub {
  font-size: 11px !important;
  line-height: 1.35 !important;
}

html.nv-mobile #dashboard-cards {
  display: flex !important;
  flex-direction: column !important;
  gap: 12px !important;
}

html.nv-mobile #dashboard-cards > * {
  width: 100% !important;
  max-width: 100% !important;
  grid-column: auto !important;
}

html.nv-mobile #card-kpis {
  display: grid !important;
  grid-template-columns: 1fr 1fr !important;
  gap: 8px !important;
}

html.nv-mobile .nv-kpi {
  padding: 12px !important;
  min-width: 0 !important;
}

html.nv-mobile .nv-kpi .nv-kpi-value {
  font-size: clamp(15px, 4.5vw, 19px) !important;
  word-break: break-word;
}

html.nv-mobile .nv-kpi .nv-kpi-label {
  font-size: 9px !important;
  letter-spacing: 0.04em !important;
}

html.nv-mobile .nv-card {
  padding: 14px !important;
  min-width: 0 !important;
  overflow: visible !important;
}

html.nv-mobile .nv-card.p-6 {
  padding: 14px !important;
}

html.nv-mobile .nv-card-head {
  flex-direction: column;
  align-items: flex-start !important;
  gap: 6px !important;
}

html.nv-mobile #ai-bullets {
  grid-template-columns: 1fr !important;
}

html.nv-mobile #investimentos-overview {
  grid-template-columns: 1fr !important;
}

html.nv-mobile .nv-ai-bullet {
  grid-template-columns: 22px 1fr !important;
}

/* Esconde atalhos de teclado no rodapé da home */
html.nv-mobile #app-shell-main .mt-6.flex.items-center.justify-between {
  display: none !important;
}

/* Barra de rotina — texto menor */
html.nv-mobile .nv-home-hero + div {
  font-size: 11px !important;
  line-height: 1.45 !important;
  padding: 10px 12px !important;
}

/* ── Tabelas → cards empilhados na home ─────────────────────────────────── */
html.nv-mobile #card-lancamentos .overflow-x-auto {
  overflow: visible !important;
}

html.nv-mobile #card-lancamentos table,
html.nv-mobile #card-lancamentos thead {
  display: none !important;
}

html.nv-mobile #card-lancamentos tbody {
  display: block !important;
}

html.nv-mobile #card-lancamentos tbody tr {
  display: block !important;
  padding: 12px 14px !important;
  border-bottom: 1px solid var(--hairline) !important;
}

html.nv-mobile #card-lancamentos tbody td {
  display: block !important;
  padding: 2px 0 !important;
  border: 0 !important;
  text-align: left !important;
}

html.nv-mobile #card-lancamentos tbody td:first-child {
  display: none !important;
}

html.nv-mobile #card-lancamentos tbody td:last-child {
  font-size: 16px !important;
  font-weight: 800 !important;
  margin-top: 4px !important;
}

/* ── Transações — cards da listagem ───────────────────────────────────────── */
html.nv-mobile #list-wrap article > .flex {
  flex-direction: column !important;
  align-items: stretch !important;
  gap: 10px !important;
}

html.nv-mobile #list-wrap article .min-w-\[160px\] {
  min-width: 0 !important;
  width: 100% !important;
  text-align: left !important;
}

html.nv-mobile #list-wrap article .text-right {
  text-align: left !important;
}

html.nv-mobile #list-wrap article h3 {
  white-space: normal !important;
  word-break: break-word;
}

html.nv-mobile #list-wrap article .mb-1.flex {
  flex-wrap: wrap !important;
}

/* Filtros transações */
html.nv-mobile #app-shell-main section.mb-5.flex.flex-col.gap-5 .flex.flex-wrap {
  flex-direction: column !important;
  align-items: stretch !important;
}

html.nv-mobile #app-shell-main .min-w-\[260px\] {
  min-width: 0 !important;
  width: 100% !important;
}

html.nv-mobile #app-shell-main .min-w-\[10rem\] {
  min-width: 0 !important;
  flex: 1 1 100% !important;
}

/* Botões de ação em páginas internas */
html.nv-mobile #app-shell-main section.mb-8 .flex.flex-wrap,
html.nv-mobile #app-shell-main .flex.flex-wrap.items-center.justify-end.gap-2 {
  flex-direction: column !important;
  align-items: stretch !important;
}

html.nv-mobile #app-shell-main section.mb-8 .nv-btn,
html.nv-mobile #app-shell-main .flex.flex-wrap .nv-btn {
  width: 100%;
  justify-content: center;
}

/* ── Tipografia geral ─────────────────────────────────────────────────────── */
html.nv-mobile #app-shell-main h2 {
  font-size: 1.375rem !important;
  line-height: 1.2 !important;
  word-break: break-word;
}

html.nv-mobile #app-shell-main p,
html.nv-mobile #app-shell-main span,
html.nv-mobile #app-shell-main a,
html.nv-mobile #app-shell-main label {
  overflow-wrap: anywhere;
}

html.nv-mobile #app-shell-main .grid > *,
html.nv-mobile #app-shell-main .flex > * {
  min-width: 0;
}

html.nv-mobile canvas,
html.nv-mobile svg,
html.nv-mobile img {
  max-width: 100% !important;
  height: auto;
}

/* Tabelas genéricas */
html.nv-mobile #app-shell-main .overflow-x-auto {
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

html.nv-mobile #app-shell-main table.nv-table {
  min-width: 480px;
}

/* Calendário / merchants grids inline */
html.nv-mobile .nv-event-row,
html.nv-mobile .merchant-row {
  grid-template-columns: 1fr !important;
  gap: 8px !important;
}

/* Modais */
html.nv-mobile .nv-assistant-modal {
  padding: 0 !important;
  align-items: stretch !important;
}

html.nv-mobile .nv-assistant-panel {
  width: 100% !important;
  max-height: none !important;
  height: 100dvh !important;
  border-radius: 0 !important;
}

html.nv-mobile #modal-cards > div {
  margin: 0 !important;
  max-height: 90dvh;
  overflow-y: auto;
}

@media (max-width: 380px) {
  html.nv-mobile #card-kpis {
    grid-template-columns: 1fr !important;
  }
}
