/* ==========================================================================
   mobile.css — Experiencia móvil / app instalada (PWA).
   Se carga después de styles.css y solo ajusta pantallas pequeñas, la barra
   de navegación inferior, las zonas seguras del iPhone y el aviso de
   instalación.
   ========================================================================== */

:root { --bnav-h: 64px; }

html { -webkit-text-size-adjust: 100%; }
body { overscroll-behavior-y: none; }
.btn, .nav-item, .bnav-item { -webkit-tap-highlight-color: transparent; }

.mobile-only { display: none; }

/* Los campos de correo no tenían estilo propio */
input[type=email] {
  background: var(--bg-elev); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 10px; font-size: 13.5px; width: 100%;
}

/* Barra de navegación inferior: solo en móvil */
.bottom-nav { display: none; }

/* Tabla de movimientos: en escritorio se ve como tabla normal */
.filters-details > summary { display: none; }

/* Aviso de instalación (Android / iPhone) */
.pwa-banner {
  position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 2500; background: var(--bg-elev); color: var(--text); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow-lg); padding: 14px 14px 12px;
  display: flex; gap: 12px; align-items: flex-start; max-width: 520px; margin: 0 auto;
  animation: pwaIn .25s ease-out;
}
.pwa-banner img { width: 44px; height: 44px; border-radius: 11px; flex-shrink: 0; }
.pwa-banner .pwa-text { flex: 1; font-size: 13.5px; line-height: 1.4; }
.pwa-banner .pwa-text strong { display: block; font-size: 14.5px; margin-bottom: 2px; }
.pwa-banner .pwa-actions { display: flex; gap: 8px; margin-top: 10px; }
.pwa-banner .pwa-close { background: none; border: none; font-size: 20px; line-height: 1; color: var(--text-muted); padding: 0 2px; }
.pwa-share-icon { display: inline-block; vertical-align: -3px; width: 16px; height: 16px; }
@keyframes pwaIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* App instalada: respetar notch y barra de estado del iPhone */
@media (display-mode: standalone) {
  .topbar { padding-top: calc(12px + env(safe-area-inset-top)); }
  .sidebar { padding-top: calc(18px + env(safe-area-inset-top)); }
}

@media (max-width: 860px) {
  /* Evita el zoom automático de iOS al enfocar campos */
  input, select, textarea { font-size: 16px !important; }
  .mobile-only { display: inline; }

  .content { padding: 14px 12px calc(var(--bnav-h) + 24px + env(safe-area-inset-bottom)); }
  .topbar { padding-left: 12px; padding-right: 12px; flex-wrap: nowrap; }
  .topbar h2 { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar-controls .lang-switch { display: inline-flex; flex-shrink: 0; }
  .topbar-controls .lang-switch button { padding: 5px 8px; font-size: 12px; }
  .topbar > div:first-child { min-width: 0; }
  .topbar-controls { gap: 4px; flex-shrink: 0; }
  .sidebar { z-index: 1200; padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
  .overlay-scrim { z-index: 1150; }
  .toast { left: 12px; right: 12px; bottom: calc(var(--bnav-h) + 14px + env(safe-area-inset-bottom)); text-align: center; }

  /* ---- Barra inferior ---- */
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr); align-items: end;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1100;
    height: calc(var(--bnav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
    -webkit-backdrop-filter: saturate(180%) blur(14px); backdrop-filter: saturate(180%) blur(14px);
    border-top: 1px solid var(--border);
  }
  .bnav-item {
    border: none; background: none; color: var(--text-muted); height: var(--bnav-h);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    font-size: 10.5px; font-weight: 600; padding: 0;
  }
  .bnav-item .icon { font-size: 20px; line-height: 1; display: inline-flex; opacity: .7; }
  .bnav-item.active { color: var(--brand-3); }
  .bnav-item.active .icon { opacity: 1; }
  .bnav-add { display: flex; align-items: center; justify-content: center; height: var(--bnav-h); }
  .bnav-add button {
    width: 54px; height: 54px; border-radius: 50%; border: none; color: #fff; font-size: 28px; line-height: 1;
    background: var(--brand-1); box-shadow: 0 6px 18px rgba(11, 107, 79, .35);
    transform: translateY(-12px);
  }

  /* ---- Panel principal ---- */
  .dash-greeting { margin-bottom: 12px; }
  .dash-greeting h1 { font-size: 24px; }
  /* el botón + de la barra inferior reemplaza a "Agregar/Nuevo movimiento" */
  .content .btn-primary[data-action="open-tx-modal"] { display: none; }
  .kpi-v2-grid { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
  .kpi-v2-card { padding: 12px; }
  .kpi-v2-card .kpi-v2-icon { width: 30px; height: 30px; font-size: 14px; margin-bottom: 6px; }
  .kpi-v2-card .value { font-size: 16px; word-break: break-word; }
  .kpi-v2-trend { font-size: 11px; }
  .kpi-v2-trend .muted { display: none; }
  .card { padding: 14px; }
  .banner { flex-direction: column; align-items: flex-start; gap: 8px; font-size: 13px; }
  .tx-search-row { flex-direction: column; align-items: stretch; }
  .tx-search-row select, .tx-search-row input[type=text] { width: 100%; }

  /* ---- Filtros plegables ---- */
  .filters-details { margin-bottom: 12px; }
  .filters-details > summary {
    display: flex; align-items: center; justify-content: space-between; list-style: none; cursor: pointer;
    padding: 11px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-elev);
    font-weight: 600; font-size: 14px;
  }
  .filters-details > summary::-webkit-details-marker { display: none; }
  .filters-details > summary::after { content: "▾"; color: var(--text-muted); }
  .filters-details[open] > summary::after { content: "▴"; }
  .filters-details[open] > .filters-bar { margin-top: 10px; }
  .filters-bar .field { min-width: 0; flex: 1 1 calc(50% - 10px); }
  .filters-bar .field select, .filters-bar .field input { width: 100%; }

  /* ---- Tabla de movimientos como tarjetas ---- */
  .tx-table thead { display: none; }
  .tx-table, .tx-table tbody { display: block; }
  .tx-table tr {
    display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 2px 10px; padding: 12px 2px;
    border-bottom: 1px solid var(--border);
  }
  .tx-table td { display: block; padding: 0; border: none; font-size: 13px; color: var(--text-muted); }
  .tx-table td[data-col="desc"] { grid-column: 1; grid-row: 1; color: var(--text); font-weight: 600; font-size: 14.5px; }
  .tx-table td[data-col="amount"] { grid-column: 2; grid-row: 1; text-align: right; font-weight: 700; font-size: 15px; color: var(--text); }
  .tx-table td.amount-income { color: var(--success); }
  .tx-table td.amount-expense { color: var(--danger); }
  .tx-table td[data-col="cat"] { grid-column: 1; grid-row: 2; }
  .tx-table td[data-col="date"] { grid-column: 2; grid-row: 2; text-align: right; font-size: 12px; }
  .tx-table td[data-col="meta"] { grid-column: 1; grid-row: 3; font-size: 12px; align-self: center; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tx-table td[data-col="desc"], .tx-table td[data-col="cat"] { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .tx-table td[data-col="actions"] { grid-column: 2; grid-row: 3; display: flex; gap: 6px; justify-content: flex-end; }
  .tx-table td[data-col="actions"] .btn { padding: 5px 8px; font-size: 13px; }
  .tx-table td[data-col="actions"]:empty { display: none; }
  .tx-table td.tx-hide-mobile { display: none; }
  .tx-table td[data-col="meta"] .tag-pill { margin-top: 4px; }

  /* ---- Ventanas emergentes como hoja inferior ---- */
  .modal-backdrop { align-items: flex-end; padding: 0; z-index: 1300; }
  body:has(.modal-backdrop) .bottom-nav, body:has(.modal-backdrop) .pwa-banner { display: none; }
  .modal {
    max-width: none; border-radius: 20px 20px 0 0; max-height: 92vh; overflow-y: auto;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  }
  .modal-actions { position: sticky; bottom: calc(-18px - env(safe-area-inset-bottom)); background: var(--bg-elev); padding: 12px 0 4px; margin-top: 12px; }
  .modal-actions .btn { flex: 1; justify-content: center; padding: 12px; }

  /* ---- Botones y listas más cómodos al tacto ---- */
  .btn { padding: 10px 14px; }
  .btn-sm { padding: 7px 10px; }
  .list-item { flex-wrap: wrap; gap: 8px; }
  .settings-section .lang-switch, .settings-section .theme-switch { margin-bottom: 8px; }
  .cards-grid { grid-template-columns: 1fr; }

  body:has(#appShell) .pwa-banner { bottom: calc(var(--bnav-h) + 12px + env(safe-area-inset-bottom)); }
}

@media (max-width: 640px) { .ui-dialog-backdrop { align-items: flex-end; } .ui-dialog { border-radius: 18px 18px 0 0; padding-bottom: calc(22px + env(safe-area-inset-bottom)); } }
