/* =========================================================
   FINOVA Mobile — UI nativa exclusiva para teléfono
   Reemplaza por completo el look desktop bajo 900px.
   ========================================================= */

@media (max-width: 900px) {

  /* ====== Reset general ====== */
  body { font-size: 15px; }
  .app { display: block; }
  .sidebar { display: none !important; }

  /* ====== Header móvil ====== */
  .header {
    padding: 0 14px;
    height: 50px;
    border-bottom: none;
    background: transparent;
    backdrop-filter: none;
    position: relative;
    margin-bottom: 2px;
  }
  .header h1 {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -.3px;
  }
  .header h1::before {
    content: 'Hola,';
    display: block;
    font-size: 10px;
    font-weight: 500;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: 1.2px;
    margin-bottom: 1px;
  }
  .header-right .btn:not(.btn-ghost) { display: none; } /* el FAB toma el lugar */
  .header-right .btn.btn-ghost {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    padding: 0;
    justify-content: center;
    background: var(--bg-2);
    border-color: var(--line);
  }
  .header-right .btn.btn-ghost svg { width: 18px; height: 18px; margin: 0; }
  .header-right .btn.btn-ghost { font-size: 0; }
  .menu-toggle { display: none !important; }

  .content {
    padding: 0 14px;
    /* 70px del bottom-bar + safe-area + colchón para que no se corte la última card */
    padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px) + 24px);
    min-height: calc(100dvh - 50px);
  }
  .main {
    min-height: 100dvh;
    width: 100%;
    overflow-x: hidden;
  }

  /* ====== Section transitions estilo app ====== */
  .section.active { animation: slideUp .3s cubic-bezier(.2,.8,.2,1); }
  @keyframes slideUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: none; }
  }

  /* ====== Hero card del dashboard (estilo banca) ====== */
  .mobile-hero {
    display: block !important;
    margin: 0 0 14px;
    background: linear-gradient(135deg, #1f1503 0%, #3a2806 50%, #1a1306 100%);
    border: 1px solid rgba(251,191,36,.28);
    border-radius: 18px;
    padding: 16px 18px 14px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 10px 28px -10px rgba(251,191,36,.18), inset 0 1px 0 rgba(251,191,36,.15);
  }
  .mobile-hero::before {
    content: '';
    position: absolute;
    top: -40px; right: -40px;
    width: 180px; height: 180px;
    background: radial-gradient(circle, rgba(251,191,36,.18), transparent 70%);
    pointer-events: none;
  }
  .mobile-hero::after {
    content: '';
    position: absolute;
    bottom: -50px; left: -30px;
    width: 140px; height: 140px;
    background: radial-gradient(circle, rgba(217,119,6,.12), transparent 70%);
    pointer-events: none;
  }
  .mobile-hero .hero-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1.4px;
    color: var(--gold);
    opacity: .85;
    font-weight: 600;
  }
  .mobile-hero .hero-balance {
    font-family: var(--font-mono);
    font-size: 26px;
    font-weight: 700;
    color: #fff;
    margin: 4px 0 2px;
    letter-spacing: -.4px;
  }
  .mobile-hero .hero-sub {
    font-size: 11.5px;
    color: rgba(255,255,255,.55);
    display: flex;
    align-items: center;
    gap: 6px;
  }
  .mobile-hero .hero-tasa {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(251,191,36,.15);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11.5px;
  }
  .mobile-hero .hero-tasa .v {
    font-family: var(--font-mono);
    color: var(--gold);
    font-weight: 600;
  }

  /* ====== Period chips móviles ====== */
  #periodChips {
    margin: 0 -14px 12px;
    padding: 0 14px;
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
  }
  #periodChips::-webkit-scrollbar { display: none; }
  .chip {
    flex: none;
    padding: 7px 14px;
    font-size: 11.5px;
    font-weight: 600;
    border-radius: 999px;
  }

  /* ====== KPI tiles compactos (estilo banca) ====== */
  .kpis {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
    margin-bottom: 14px !important;
  }
  .kpi {
    padding: 11px 12px !important;
    border-radius: 14px;
    background: var(--bg-2);
    border: 1px solid var(--line);
    min-height: 0;
    overflow: hidden;
  }
  .kpi::before { display: none; }
  .kpi-label {
    font-size: 9.5px !important;
    letter-spacing: .7px !important;
    color: var(--text-mute);
    display: flex; align-items: center; gap: 6px;
  }
  .kpi-label::before {
    content: '';
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--gold);
    flex: none;
  }
  .kpi.green .kpi-label::before { background: var(--green); }
  .kpi.red .kpi-label::before { background: var(--red); }
  .kpi.violet .kpi-label::before { background: var(--violet); }
  .kpi.blue .kpi-label::before { background: var(--blue); }
  .kpi-value {
    font-size: 16px !important;
    margin-top: 4px !important;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .kpi-sub {
    font-size: 10px !important;
    margin-top: 2px;
    color: var(--text-mute);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* En el dashboard ocultamos KPIs ya cubiertos por el hero */
  .hide-on-mobile { display: none !important; }

  /* ====== Section title móvil ====== */
  .section-title, .card-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    text-transform: none;
    letter-spacing: -.2px;
  }
  .card-title svg { width: 16px; height: 16px; }

  /* ====== Card general ====== */
  .card {
    border-radius: 18px;
    padding: 16px;
    background: var(--bg-2);
    border: 1px solid var(--line);
  }
  .card-head { margin-bottom: 12px; }

  /* ====== Tablas → tarjetas (mobile) ====== */
  .tbl-wrap { overflow: visible; }
  .tbl, .tbl thead, .tbl tbody, .tbl tr, .tbl td, .tbl th {
    display: block;
  }
  .tbl thead { display: none; }
  .tbl tr {
    background: var(--bg-1);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px 14px;
    margin-bottom: 8px;
    position: relative;
  }
  .tbl tr:hover td { background: transparent; }
  .tbl td {
    border: none;
    padding: 2px 0;
    white-space: normal;
    font-size: 13px;
  }
  .tbl td.num { text-align: left; }
  .tbl td:empty { display: none; }

  /* fila de transacciones recientes en cards (data-label vía JS) */
  .mobile-trx {
    display: flex !important;
    align-items: center;
    gap: 12px;
    background: var(--bg-1);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px 14px;
    margin-bottom: 8px;
  }
  .mobile-trx .icn {
    width: 40px; height: 40px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    flex: none;
    color: #fff;
    font-weight: 700;
    font-size: 16px;
  }
  .mobile-trx .body {
    flex: 1;
    min-width: 0;
  }
  .mobile-trx .body .ttl {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .mobile-trx .body .meta {
    font-size: 11.5px;
    color: var(--text-mute);
    margin-top: 2px;
  }
  .mobile-trx .amount {
    text-align: right;
    flex: none;
  }
  .mobile-trx .amount .v {
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: 700;
  }
  .mobile-trx .amount .sub {
    font-size: 10.5px;
    color: var(--text-mute);
    margin-top: 1px;
  }
  .mobile-trx.ingreso .v { color: #6ee7b7; }
  .mobile-trx.gasto .v { color: #fca5a5; }
  .mobile-trx.ahorro .v { color: #c4b5fd; }
  .mobile-trx.ingreso .icn { background: linear-gradient(135deg, #10b981, #059669); }
  .mobile-trx.gasto .icn { background: linear-gradient(135deg, #ef4444, #b91c1c); }
  .mobile-trx.ahorro .icn { background: linear-gradient(135deg, #8b5cf6, #6d28d9); }

  /* deudas como cards móviles */
  .mobile-deuda {
    display: block !important;
    background: var(--bg-1);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 14px;
    margin-bottom: 10px;
  }
  .mobile-deuda .top {
    display: flex; justify-content: space-between; align-items: flex-start;
    margin-bottom: 10px;
  }
  .mobile-deuda .acreedor {
    font-weight: 700; font-size: 14px;
  }
  .mobile-deuda .desc {
    font-size: 11.5px; color: var(--text-mute); margin-top: 2px;
  }
  .mobile-deuda .saldo {
    text-align: right;
  }
  .mobile-deuda .saldo .v {
    font-family: var(--font-mono);
    font-size: 16px;
    font-weight: 700;
  }
  .mobile-deuda.por_pagar .saldo .v { color: #fca5a5; }
  .mobile-deuda.por_cobrar .saldo .v { color: #6ee7b7; }
  .mobile-deuda .progress {
    background: var(--bg-3);
    height: 6px;
    border-radius: 999px;
    overflow: hidden;
    margin: 10px 0 8px;
  }
  .mobile-deuda .progress > div {
    height: 100%;
    background: linear-gradient(90deg, var(--gold), var(--gold-3));
  }
  .mobile-deuda .footer {
    display: flex; justify-content: space-between; align-items: center;
    font-size: 11.5px; color: var(--text-mute);
  }

  /* ====== Quick actions del dashboard móvil ====== */
  .mobile-quick {
    display: grid !important;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    margin: 0 0 14px;
  }
  .mobile-quick button {
    background: var(--bg-2);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 10px 4px 9px;
    color: var(--text);
    cursor: pointer;
    display: flex; flex-direction: column;
    align-items: center;
    gap: 5px;
    font-size: 10.5px;
    font-weight: 600;
    transition: transform .12s;
  }
  .mobile-quick button:active { transform: scale(0.94); }
  .mobile-quick button .qicn {
    width: 32px; height: 32px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
  }
  .mobile-quick button .qicn svg { width: 17px; height: 17px; }
  .mobile-quick button.q-ing .qicn { background: linear-gradient(135deg,#10b981,#059669); }
  .mobile-quick button.q-gas .qicn { background: linear-gradient(135deg,#ef4444,#b91c1c); }
  .mobile-quick button.q-aho .qicn { background: linear-gradient(135deg,#8b5cf6,#6d28d9); }
  .mobile-quick button.q-conv .qicn { background: linear-gradient(135deg,#fbbf24,#d97706); }

  /* ocultar elementos solo-desktop */
  .desktop-only { display: none !important; }

  /* mostrar elementos solo-mobile (default oculto) */
  .mobile-only { display: block !important; }
  .mobile-quick.mobile-only { display: grid !important; }
  .mobile-trx.mobile-only { display: flex !important; }

  /* ====== Filtros (transacciones, deudas) más compactos ====== */
  .filters {
    border-radius: 16px;
    padding: 12px;
    flex-direction: column;
    align-items: stretch;
  }
  .filters .field { width: 100%; }
  .filters .btn { width: 100%; justify-content: center; }
  .chip-row { gap: 6px; }

  /* Inputs de fecha en móvil — más grandes, legibles, con icono visible.
     IMPORTANTE: font-size >= 16px para evitar el auto-zoom de iOS */
  .field input[type="date"] {
    font-size: 16px !important;
    min-height: 46px;
    padding: 12px 14px;
    -webkit-appearance: none;
    appearance: none;
    color-scheme: dark;
    line-height: 1.2;
    background-color: var(--bg-1);
  }
  /* WebKit: edita el formato y los placeholders del datetime */
  input[type="date"]::-webkit-date-and-time-value {
    text-align: left;
  }
  input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(0.8) sepia(1) hue-rotate(20deg) saturate(3);
    cursor: pointer;
    opacity: 0.9;
  }
  input[type="date"]::-webkit-datetime-edit {
    color: var(--text);
    padding: 0;
  }
  input[type="date"]::-webkit-datetime-edit-fields-wrapper {
    color: var(--text);
  }
  /* Resto de inputs en móvil — también >=16px */
  .field input, .field select, .field textarea {
    font-size: 16px !important;
  }

  /* ====== FAB (botón flotante de acción) ====== */
  .fab {
    position: fixed;
    right: 18px;
    bottom: 86px;
    width: 58px; height: 58px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--gold) 0%, var(--gold-3) 100%);
    border: none;
    color: #1a1306;
    box-shadow: 0 12px 28px rgba(251,191,36,.35), 0 4px 10px rgba(0,0,0,.4);
    display: flex !important;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 60;
    transition: transform .15s;
  }
  .fab:active { transform: scale(0.92); }
  .fab svg { width: 26px; height: 26px; }

  /* ====== Bottom nav rediseñada ====== */
  .mobile-bar {
    background: rgba(11,18,36,.92);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--line);
    padding: 8px 4px calc(env(safe-area-inset-bottom, 0px) + 8px);
    box-shadow: 0 -8px 24px rgba(0,0,0,.3);
    z-index: 50;
  }
  .fab {
    bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  }
  .mobile-bar button {
    padding: 6px 2px;
    font-size: 9.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .4px;
    border-radius: 12px;
    transition: background .15s;
  }
  .mobile-bar button.active {
    color: var(--gold);
  }
  .mobile-bar button.active svg {
    filter: drop-shadow(0 0 6px rgba(251,191,36,.5));
  }
  .mobile-bar svg { width: 22px; height: 22px; }

  /* ====== Bottom-sheet modal (en lugar de centrado) ====== */
  .modal-bg { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100%;
    width: 100%;
    border-radius: 24px 24px 0 0;
    border: none;
    border-top: 1px solid var(--line-strong);
    padding: 18px 18px calc(env(safe-area-inset-bottom, 0px) + 18px);
    animation: sheetUp .28s cubic-bezier(.2,.8,.2,1);
    max-height: 92vh;
    overflow-y: auto;
  }
  @keyframes sheetUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }
  .modal::before {
    content: '';
    display: block;
    width: 40px; height: 4px;
    background: var(--bg-4);
    border-radius: 999px;
    margin: -4px auto 14px;
  }
  .modal h3 {
    font-size: 17px;
    font-weight: 700;
    margin-bottom: 14px;
  }
  .form-grid { gap: 10px; }
  .field input, .field select, .field textarea {
    padding: 12px 14px;
    font-size: 15px;
    border-radius: 12px;
  }
  .field label {
    font-size: 11px;
  }
  .form-actions { flex-direction: column-reverse; gap: 8px; }
  .form-actions .btn { width: 100%; justify-content: center; padding: 13px; font-size: 14px; }

  /* dialog específico móvil */
  .dlg { max-width: 100%; }

  /* ====== Charts más compactos ====== */
  .charts { grid-template-columns: 1fr; gap: 12px; }
  canvas { max-height: 200px !important; }

  /* ====== Plan IA / Chat IA ====== */
  .ia-grid { grid-template-columns: 1fr; gap: 14px; }
  .plan-md { max-height: none; padding: 14px; font-size: 13px; }
  .chat { height: 480px; }

  /* ====== Conversor móvil ====== */
  .converter {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .swap-btn { justify-self: center; }

  /* ====== BCV pill flotante en header ====== */
  .mobile-bcv {
    display: inline-flex !important;
    align-items: center;
    gap: 6px;
    background: var(--bg-2);
    border: 1px solid var(--line);
    padding: 6px 11px;
    border-radius: 999px;
    font-size: 11.5px;
    font-family: var(--font-mono);
    color: var(--gold);
  }
  .mobile-bcv .dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 6px var(--green);
  }
}

/* ====== En desktop, ocultar todo lo mobile-only ====== */
@media (min-width: 901px) {
  .mobile-only { display: none !important; }
  .fab { display: none !important; }
}
