/* =====================================================================
   DISEÑO ADAPTATIVO: celular (≤ 760 px), tablet (761–1100 px), computador
   ===================================================================== */
.ico { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.icon-btn { display: inline-flex; align-items: center; gap: 6px; }
.mobile-only { display: none; }
.tabs { scrollbar-width: thin; scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch; }
.tabs button { scroll-snap-align: start; }
img, svg, canvas { max-width: 100%; }
.topbar { padding-top: max(12px, env(safe-area-inset-top)); padding-left: max(20px, env(safe-area-inset-left)); padding-right: max(20px, env(safe-area-inset-right)); }
main { padding-bottom: max(40px, calc(env(safe-area-inset-bottom) + 24px)); }

/* Tablet */
@media (min-width: 761px) and (max-width: 1100px) {
  .grid3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid3 > .card:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .top-controls { justify-content: flex-start; }
}

/* Pantallas táctiles: objetivos de al menos 44 px */
@media (pointer: coarse) {
  .btn { min-height: 44px; }
  .btn.sm { min-height: 40px; }
  .btn.link, .btn.icon { min-width: 44px; min-height: 44px; }
  .tabs button { padding: 14px 16px; }
  input[type=checkbox], input[type=radio] { width: 20px; height: 20px; }
  .th-btn { min-height: 36px; }
}

/* Celular */
@media (max-width: 760px) {
  body { font-size: 15px; }
  /* 16 px evita que el iPhone haga zoom al escribir */
  input, select, textarea { font-size: 16px; }

  /* Encabezado compacto: marca + íconos / mes + tasa / importar + descargar */
  .topbar { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-areas: "brand user" "month rate" "imp exp"; gap: 10px; padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); }
  .top-controls { display: contents; }
  .brand { grid-area: brand; min-width: 0; gap: 10px; }
  .brand .logo { width: 34px; height: 34px; font-size: 11px; border-radius: 8px; }
  .brand-title { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .brand-sub { display: none; }
  .brand > div:last-child { min-width: 0; }
  .user-box { grid-area: user; justify-self: end; flex-wrap: nowrap; }
  .user-label, .btn-label { display: none; }
  .icon-btn { padding: 8px 10px; }
  .ctl-month { grid-area: month; }
  .ctl-rate { grid-area: rate; }
  .top-import { grid-area: imp; }
  .top-export { grid-area: exp; }
  .top-import, .top-export { width: 100%; padding: 10px 8px; font-size: 14px; }
  .ctl { min-width: 0; }
  .ctl select, .ctl input { min-width: 0; width: 100%; }
  .ctl .inline { min-width: 0; }
  .ctl .inline input { flex: 1; }

  .tabs { padding: 0 6px; }
  .tabs button { padding: 12px 12px; font-size: 14px; }
  main { padding: 12px 12px 32px; }
  .card { padding: 14px 12px; border-radius: 10px; margin-bottom: 12px; }
  .grid2, .grid3 { gap: 12px; margin-bottom: 12px; }
  .card-h { margin-bottom: 10px; }
  .card-h .row-btns { width: 100%; }

  /* Indicadores en 2 columnas; el principal ocupa todo el ancho */
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
  .kpi { padding: 11px 12px; }
  .kpi.hl { grid-column: 1 / -1; }
  .kpi .k-label { font-size: 10.5px; }
  .kpi .k-value { font-size: 17px; overflow-wrap: anywhere; }
  .kpi.hl .k-value { font-size: 24px; }
  .kpi .k-sub { font-size: 11px; }
  .chart-box { height: 250px; }
  .chart-box.sm { height: 210px; }
  .sema { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .sema div { padding: 8px; }
  .sema .v { font-size: 18px; }
  .sema .t, .sema .d { font-size: 11px; }

  /* Filtros de transacciones en 2 columnas */
  .filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .filters input[type=search] { grid-column: 1 / -1; min-width: 0; }
  .filters .spacer { display: none; }
  .filters .btn { width: 100%; }
  .filters > * { min-width: 0; }
  .mobile-only { display: block; }

  /* Tabla de transacciones convertida en tarjetas */
  #tab-transacciones .table-wrap { max-height: none; overflow: visible; border: 0; }
  #txTable, #txTable tbody, #txTable tfoot, #txTable tr, #txTable td { display: block; width: 100%; }
  #txTable thead { display: none; }
  /* tarjeta compacta: dos columnas de dato + rótulo; el tercero arriba a todo lo ancho */
  #txTable tbody tr:not(.empty-row) { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 14px; row-gap: 6px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px; margin-bottom: 10px; padding: 10px 12px; box-shadow: var(--shadow); }
  #txTable tbody tr:hover { background: var(--surface); }
  #txTable td { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; border: 0; padding: 0; white-space: normal; text-align: left; min-width: 0; overflow-wrap: anywhere; }
  #txTable td::before { content: attr(data-label); color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .02em; }
  #txTable td:empty { display: none; }
  #txTable td.cell-tercero { grid-column: 1 / -1; order: -3; font-weight: 700; font-size: 15px; }
  #txTable td.cell-tercero::before { content: none; }
  #txTable td.cell-tipo { order: -2; }
  #txTable td.cell-fecha { order: -2; }
  #txTable td.cell-num { display: none; }
  #txTable td.cell-verificacion, #txTable td.cell-diferencia, #txTable td.cell-rend { font-size: 13px; color: var(--muted); }
  #txTable td.cell-actions { grid-column: 1 / -1; flex-direction: row; justify-content: flex-end; gap: 6px; border-top: 1px solid var(--border); margin-top: 2px; padding-top: 6px; }
  #txTable td.cell-actions::before { content: none; }
  #txTable tfoot tr { background: var(--surface2); border-radius: 10px; padding: 8px 12px; }
  #txTable tfoot td { position: static; display: flex; justify-content: space-between; padding: 3px 0; }
  #txTable tfoot td::before { content: attr(data-label); font-weight: 600; color: var(--muted); }
  #txTable .empty-row td { display: block; text-align: center; }
  #txTable .empty-row td::before { content: none; }
  .pager { justify-content: space-between; flex-wrap: wrap; }

  /* Tablas simples y formularios */
  table.simple td, table.simple th { padding: 7px 4px; }
  .num-input { width: 100%; max-width: 170px; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .span2, .full { grid-column: auto; }
  .map-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .opts { gap: 10px; }
  .opts > label, .opts > fieldset { width: 100%; flex-wrap: wrap; }
  .src-head { gap: 8px; }
  .drop { padding: 24px 14px; }
  .drop-title { font-size: 15px; }
  td.row-btns { white-space: normal; }

  /* Ventanas emergentes a pantalla completa */
  .modal { padding: 0; place-items: stretch; }
  .modal-card { width: 100%; max-height: none; height: 100%; border-radius: 0; padding: 16px 14px; padding-top: max(16px, env(safe-area-inset-top)); padding-bottom: max(16px, env(safe-area-inset-bottom)); }
  .settings-card { width: 100%; }
  .form-actions { position: sticky; bottom: calc(-1 * max(16px, env(safe-area-inset-bottom))); background: var(--surface); padding: 12px 0 max(4px, env(safe-area-inset-bottom)); margin-top: 16px; border-top: 1px solid var(--border); }
  .form-actions .btn { flex: 1; }
  .toast { left: 12px; right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); max-width: none; text-align: center; }
  .auth-screen { padding: 12px; align-items: start; padding-top: max(24px, env(safe-area-inset-top)); }
  .auth-card { padding: 20px 16px; }
  .info-list { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .info-list dd { margin-bottom: 8px; }
}

/* Celulares muy angostos (≤ 360 px) */
@media (max-width: 360px) {
  .kpis { grid-template-columns: minmax(0, 1fr); }
  .sema { grid-template-columns: minmax(0, 1fr); }
  .map-grid { grid-template-columns: minmax(0, 1fr); }
}

/* Celular en horizontal: encabezado en una sola franja */
@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
  .topbar { display: flex; padding: 6px 14px; }
  .brand-sub, .btn-label, .user-label { display: none; }
  .tabs { position: static; }
}

/* Impresión: solo el contenido */
@media print {
  .topbar, .tabs, .filters, .pager, .btn, .toast, .modal, .skip, #supForm, #mvForm { display: none !important; }
  body { background: #fff; color: #000; }
  .card, .kpi { box-shadow: none; border-color: #ccc; break-inside: avoid; }
  .table-wrap { max-height: none !important; overflow: visible !important; }
  main { max-width: none; padding: 0; }
}

/* Título corto en celular y botón de tasa acorde al encabezado oscuro */
.title-short { display: none; }
.topbar .btn.icon { background: rgba(255,255,255,.12); color: #fff; border-color: rgba(255,255,255,.3); }
@media (max-width: 760px) { .title-long { display: none; } .title-short { display: inline; } }

/* Tablas simples anchas: se desplazan dentro de su tarjeta sin ensanchar la página */
@media (max-width: 760px) {
  table.simple { display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  #cfgAccounts input, #cfgAccounts select { min-width: 110px; }
}

/* ---------- Perfiles ---------- */
.profile-chip { display: inline-block; margin-top: 3px; padding: 1px 8px; border-radius: 999px; background: rgba(255,255,255,.16); font-size: 11.5px; font-weight: 600; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.inline-form input { min-width: 220px; }
.profiles-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; margin-top: 12px; }
.profile-card { border: 1px solid var(--border); border-radius: 12px; padding: 14px; background: var(--surface2); display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.profile-card.current { border-color: var(--primary2); box-shadow: inset 0 0 0 1px var(--primary2); }
.profile-card header { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.profile-card h3 { font-size: 16px; overflow-wrap: anywhere; }
.profile-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; margin: 0; }
.profile-stats .wide { grid-column: 1 / -1; }
.profile-stats dt { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .02em; }
.profile-stats dd { margin: 2px 0 0; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.profile-card footer { margin-top: auto; }
@media (max-width: 760px) {
  .topbar { grid-template-areas: "brand user" "profile profile" "month rate" "imp exp"; }
  .ctl-profile { grid-area: profile; }
  .inline-form, .inline-form input { width: 100%; min-width: 0; }
  .profiles-grid { grid-template-columns: minmax(0, 1fr); }
}
