/* ==========================================================================
   Saldo Libre PRO — adaptación a pantallas
   Probado para 1920×1080, 1366×768, tablets y teléfonos (iPhone / Android).
   ========================================================================== */

/* Escritorio grande */
@media (min-width: 1680px) {
  .view { padding-left: 40px; padding-right: 40px; }
}

/* Laptops tipo 1366×768 */
@media (max-width: 1440px) {
  :root { --sidebar-w: 236px; }
  .card { padding: 20px; }
  .topbar { padding: 14px 24px; }
  .view { padding: 6px 24px 28px; }
  .folder-banner { margin: 0 24px 8px; }
  .app-footer { padding: 14px 24px 24px; }
  .strategy-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .compare-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .compare-arrow { display: none; }
}

/* Tabla de deudas: la primera columna ("Deuda") queda inmovilizada al desplazar hacia los lados */
@media (min-width: 761px) {
  .responsive-table thead th:first-child, .responsive-table tbody td:first-child, .responsive-table tfoot th:first-child {
    position: sticky; left: 0; z-index: 2; background: var(--surface);
    transition: box-shadow 0.2s;
  }
  /* La sombra aparece solo cuando la tabla se desplazó hacia la derecha */
  .table-scroll.is-scrolled .responsive-table thead th:first-child,
  .table-scroll.is-scrolled .responsive-table tbody td:first-child,
  .table-scroll.is-scrolled .responsive-table tfoot th:first-child { box-shadow: 10px 0 14px -12px rgba(17, 21, 46, 0.35); }
  .responsive-table thead th:first-child { background: var(--surface-2); z-index: 3; }
  .responsive-table tfoot th:first-child { background: var(--surface-2); }
  .responsive-table tbody tr:hover td:first-child, .responsive-table tbody tr:hover .actions-cell { background: var(--surface-2); }
  .responsive-table .debt-cell { min-width: 150px; }
}

/* Laptops: celdas un poco más compactas para que quepan todas las columnas */
@media (min-width: 761px) and (max-width: 1500px) {
  .responsive-table th, .responsive-table td { padding-left: 8px; padding-right: 8px; }
  .responsive-table thead th { font-size: 11px; letter-spacing: 0.03em; white-space: normal; line-height: 1.25; }
  .responsive-table thead th .th-sort { text-align: inherit; }
  .responsive-table thead th.num .th-sort { justify-content: flex-end; }
  .responsive-table thead th.num { white-space: normal; }
  .responsive-table .debt-color { width: 10px; }
  .responsive-table .debt-cell { gap: 10px; min-width: 132px; }
  .responsive-table .row-actions { gap: 0; }
  .responsive-table .actions-cell { padding-left: 4px; padding-right: 6px; }
}

@media (max-width: 1280px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-wide-left, .grid-wide-right { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .form-grid-4 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .action-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rp-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar-sub .dot-sep, .topbar-sub time { display: none; }
}

/* Tablets: menú lateral oculto → hamburguesa */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.28s var(--ease);
    box-shadow: var(--shadow-lg);
    width: min(300px, 86vw);
  }
  body.menu-open .sidebar { transform: none; }
  .scrim { position: fixed; inset: 0; z-index: 35; background: rgba(10, 12, 28, 0.45); opacity: 0; pointer-events: none; transition: opacity 0.25s; }
  body.menu-open .scrim { opacity: 1; pointer-events: auto; }
  body.menu-open { overflow: hidden; }
  .main { margin-left: 0; }
  .topbar .menu-toggle { display: inline-grid; }
  .grid-2, .grid-wide-left, .grid-wide-right { grid-template-columns: minmax(0, 1fr); }
  .flow-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .flow-cols { grid-template-columns: 1fr; }
  .flow-cols .fieldset:first-child .form-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* Teléfonos grandes y tablets verticales */
@media (max-width: 760px) {
  body { font-size: 14.5px; }
  .topbar { padding: 10px 14px; gap: 10px; }
  .topbar-title h1 { font-size: 19px; }
  .topbar-sub { display: none; }
  .topbar-actions { gap: 6px; }
  .save-status { display: none; }
  .theme-toggle button span { display: none; }
  .theme-toggle button { padding: 6px 9px; }
  #btn-add-debt span { display: none; }
  #btn-add-debt { padding: 9px 11px; }
  .view { padding: 4px 14px 24px; }
  .view > * + * { margin-top: 14px; }
  .folder-banner { margin: 0 14px 8px; }
  .app-footer { padding: 12px 14px 90px; }
  .card { padding: 16px; border-radius: 14px; }
  .kpi-grid, .kpi-grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi-value { margin-top: 10px; }
  .kpi-head { font-size: 11px; letter-spacing: 0.03em; }
  .kpi-icon { width: 28px; height: 28px; }
  .flow-grid { gap: 10px; }
  .flow-card b { font-size: 17px; }
  .strategy-grid { grid-template-columns: minmax(0, 1fr); }
  .form-grid, .form-grid-3, .form-grid-4 { grid-template-columns: minmax(0, 1fr); }
  .flow-cols .fieldset:first-child .form-grid { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .refi-cols, .refi-results { grid-template-columns: minmax(0, 1fr); }
  .compare-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .compare-arrow { display: none; }
  .compare-cell b { font-size: 16px; }
  .section-head { flex-direction: column; align-items: stretch; }
  .view > .section-head h2 { font-size: 19px; }
  .donut { flex-direction: column; }
  .donut-legend { width: 100%; }
  .progress-top { flex-direction: column-reverse; align-items: flex-start; gap: 6px; }
  .sim-amount { align-items: flex-start; }
  .mini-strategies { grid-template-columns: minmax(0, 1fr); }
  .rp-summary { grid-template-columns: minmax(0, 1fr); }
  .rp-title { text-align: left; }
  .action-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .formula { flex-direction: column; }
  .formula-op { justify-items: start; padding-left: 12px; }
  .search { max-width: none; }

  /* Tablas como tarjetas en móvil */
  .responsive-table thead { display: none; }
  .responsive-table, .responsive-table tbody, .responsive-table tr, .responsive-table td, .responsive-table tfoot, .responsive-table th { display: block; width: 100%; }
  .responsive-table tr { border: 1px solid var(--border); border-radius: 14px; margin-bottom: 10px; padding: 6px 4px; background: var(--surface); }
  .responsive-table tbody tr:hover { background: var(--surface); }
  .responsive-table td { border: 0; padding: 6px 10px; display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: right; }
  .responsive-table td::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 650; text-align: left; flex: none; }
  .responsive-table td:first-child { text-align: left; }
  .responsive-table td:first-child::before { display: none; }
  .responsive-table td.num { text-align: right; }
  .responsive-table .mini-progress { margin: 4px 0 0 auto; }
  .responsive-table .actions-cell { width: 100%; justify-content: flex-end; border-top: 1px solid var(--border); margin-top: 4px; padding-top: 8px; }
  .responsive-table .actions-cell::before { display: none; }
  .responsive-table tfoot tr { background: var(--surface-2); }
  .responsive-table tfoot td:empty, .responsive-table tfoot th { display: none; }
  .responsive-table tfoot td::before { content: none; }
  .debt-cell { min-width: 0; }
  .comment-cell { max-width: none; }
  .table-scroll { overflow: visible; }
  .table-scroll.tall { overflow: auto; }

  .due-item { grid-template-columns: auto 1fr auto; }
  .due-item .status { grid-column: 2; justify-self: start; }
  .due-item .btn { grid-column: 3; }
  .cal-cell { min-height: 58px; padding: 4px; }
  .cal-pill { font-size: 0; height: 8px; padding: 0; border-left-width: 0; background: var(--c); border-radius: 99px; }
  .cal-pill.is-paid { background: var(--success); }
  .cal-pill.is-overdue { background: var(--danger); }
  .cal-total { margin-left: 0; width: 100%; }

  .modal-backdrop { padding: 0; place-items: end center; }
  .modal { max-height: 94vh; border-radius: 20px 20px 0 0; }
  .modal-sm, .modal-md, .modal-lg, .modal-xl { max-width: 100%; }
  .modal-body { padding: 16px; }
  .modal-foot { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
  .modal-foot .btn { flex: 1; }
  .wizard-modal .modal-body { padding: 16px; }
  .wizard-steps small { display: none; }
  .wizard-debts li { grid-template-columns: auto 1fr auto; }
  .wizard-debts li span:nth-of-type(3) { display: none; }

  .wow { grid-template-columns: minmax(0, 1fr); grid-template-areas: "counter" "chart" "marks" "final"; }
  .wow-chart { height: 180px; }
  .wow-marks { flex-direction: row; flex-wrap: wrap; }
  .wow-marks li { padding: 4px 8px; font-size: 12px; }

  .toasts { left: 12px; right: 12px; bottom: 12px; max-width: none; }
  .tooltip-bubble { max-width: calc(100vw - 24px); }
}

/* Teléfonos pequeños */
@media (max-width: 400px) {
  .kpi-grid, .kpi-grid-3, .flow-grid, .action-grid { grid-template-columns: minmax(0, 1fr); }
  .compare-grid { grid-template-columns: minmax(0, 1fr); }
  .chip { padding: 7px 11px; font-size: 13px; }
  .hero-actions .btn, .wizard-choices .btn { width: 100%; }
}

/* Pantallas bajas (laptops 768 px de alto) */
@media (max-height: 800px) and (min-width: 1025px) {
  .sidebar { gap: 12px; padding-top: 16px; }
  .nav-link { padding: 8px 12px; }
}

/* ==========================================================================
   Pantallas táctiles (Android, iPhone, tablets): áreas de toque cómodas
   Referencia: ~44–48 px por control. No cambia nada con mouse.
   ========================================================================== */
@media (pointer: coarse) {
  .btn { min-height: 44px; }
  .btn-sm { min-height: 40px; }
  .icon-btn { width: 44px; height: 44px; }
  .chip { min-height: 40px; }
  .theme-toggle button { min-width: 42px; min-height: 38px; }
  .nav-link { padding: 12px 14px; }
  /* El "?" se ve igual, pero su zona de toque se amplía alrededor */
  .tip { position: relative; }
  .tip::before { content: ""; position: absolute; inset: -13px; }
  .rate-help-btn { min-height: 36px; padding: 6px 12px; }
  .debt-name-btn { padding: 8px 0; }
  .expand-btn { width: 34px; height: 34px; }
  .swatch { width: 30px; height: 30px; }
  /* Texto de 16 px en campos: legible y evita el zoom automático en iPhone */
  .field input, .field select, .field textarea, .inline-field select, .search input, .chip-input input { font-size: 16px; }
  input[type="range"]::-webkit-slider-thumb { width: 36px; height: 36px; }
}

/* Celulares: textos secundarios de las tarjetas de deudas en su propia línea */
@media (max-width: 760px) {
  .responsive-table td { flex-wrap: wrap; row-gap: 2px; }
  .responsive-table td .pay-eq { flex-basis: 100%; text-align: right; }
  /* Las tablas del reporte no se convierten en tarjetas: se desplazan dentro de su caja */
  .report .table-scroll { overflow-x: auto; }
}

@media (max-width: 760px) {
  /* Tarjetas de deuda: etiqueta a la izquierda y valor (con su "/ mes") junto a la derecha */
  .responsive-table td { display: flow-root; text-align: right; }
  .responsive-table td::before { float: left; margin-right: 12px; padding-top: 1px; }
  .responsive-table td:first-child { text-align: left; }
  .responsive-table td.num small { display: inline; margin-left: 3px; }
  .responsive-table td .pay-eq { display: block; margin-top: 2px; }
  .responsive-table .actions-cell { display: flex; }
  /* El título de la página ya está en la barra superior */
  .view > .section-head:first-child h2 { display: none; }
  .view > .section-head:first-child p { margin-top: 0; }
}

@media (max-width: 1440px) { .license-banner { margin: 0 24px 8px; } }
@media (max-width: 760px) { .license-banner { margin: 0 14px 8px; } .license-form textarea { font-size: 16px; } }
