/* ==========================================================================
   Tema visual v2 — capa final de diseño (se carga DESPUÉS de styles.css).

   Objetivo: aspecto de SaaS financiero sobrio, mobile-first, con una sola
   escala de tokens. Solo cambia presentación: no altera lógica ni datos.
   Si hay que revertir el rediseño basta con quitar el <link> a este archivo.

   Escala:  espacio 4/8/12/16/20/24 · radio 10 (controles) / 16 (tarjetas)
            texto 12/13/14/16/20/28 · cifras con números tabulares
   Color con significado: verde = recibido/positivo, rojo = deuda/mora/error,
   ámbar = advertencia, primario = acciones, gris = secundario.
   ========================================================================== */

:root {
    --bg: #f3f5f7;
    --panel: #ffffff;
    --panel-soft: #f7f9fa;
    --panel-strong: #ffffff;
    --surface-2: #f5f7f8;
    --text: #12202a;
    --muted: #5a6b74;
    --primary: #0f7f6e;
    --primary-2: #0b6658;
    --primary-soft: #e3f3ef;
    --line: #e2e8eb;
    --line-strong: #cfd9dd;
    --danger: #c23a32;
    --danger-soft: #fdecea;
    --warning: #a86a12;
    --warning-soft: #fdf3e1;
    --ok: #157a52;
    --ok-soft: #e4f4ec;
    --info: #3d5a66;
    --shadow: 0 1px 2px rgba(16, 32, 42, 0.05), 0 4px 16px rgba(16, 32, 42, 0.05);
    --shadow-soft: 0 1px 2px rgba(16, 32, 42, 0.05);
    --shadow-deep: 0 12px 40px rgba(16, 32, 42, 0.18);
    --radius-card: 16px;
    --radius-control: 10px;
    --control-height: 44px;
    --card-padding: 16px;
    --modal-padding: 16px;
}

:root[data-theme="dark"] {
    --bg: #0c1317;
    --panel: #131e25;
    --panel-soft: #172530;
    --panel-strong: #131e25;
    --surface-2: #19272f;
    --text: #e6eef1;
    --muted: #9cb0b8;
    --primary: #3cc4a9;
    --primary-2: #2fa58e;
    --primary-soft: #16352f;
    --line: #233540;
    --line-strong: #2e4552;
    --danger: #ff8a80;
    --danger-soft: #3a1f1f;
    --warning: #f3c26b;
    --warning-soft: #3a2f17;
    --ok: #6fd49f;
    --ok-soft: #173326;
    --info: #a7bec6;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 20px rgba(0, 0, 0, 0.25);
    --shadow-soft: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-deep: 0 16px 44px rgba(0, 0, 0, 0.5);
}

/* ---------- Base --------------------------------------------------------- */

body {
    background: var(--bg);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
}

/* Fondos decorativos: más discretos (antes competían con el contenido). */
.bg-grid {
    display: none;
}

.bg-shape {
    opacity: 0.18;
}

:root[data-theme="dark"] .bg-shape {
    opacity: 0.08;
}

/* Superficies sólidas: el efecto vidrio con desenfoque era costoso en
   celulares de gama media y daba contraste irregular. */
.glass,
.card,
.topbar,
.cliente-floating,
.caja-modal,
.alert-modal {
    background: var(--panel);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
}

h1, h2, h3, h4, h5 {
    color: var(--text);
    letter-spacing: -0.01em;
}

h3 { font-size: 1.125rem; }
h4 { font-size: 1rem; }

.muted {
    color: var(--muted);
}

/* Cifras financieras alineadas y legibles. */
strong,
.metric strong,
.caja-row dd,
.route-amount strong,
.focus-kpi strong,
.detail-mov-amount,
.caja-hero-value {
    font-variant-numeric: tabular-nums;
}

/* Foco visible y consistente para teclado. */
:is(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    box-shadow: none;
}

/* ---------- Controles ---------------------------------------------------- */

:is(.primary-btn, .ghost-btn, .danger-btn) {
    min-height: var(--control-height);
    border-radius: var(--radius-control);
    font-weight: 700;
    font-size: 0.875rem;
    letter-spacing: 0;
    box-shadow: none;
    transform: none;
}

.primary-btn {
    background: var(--primary);
    border: 1px solid var(--primary);
    color: #fff;
}

:root[data-theme="dark"] .primary-btn {
    color: #06231d;
}

@media (hover: hover) and (pointer: fine) {
.primary-btn:hover {
    background: var(--primary-2);
    border-color: var(--primary-2);
}
}

.ghost-btn {
    background: var(--panel);
    border: 1px solid var(--line-strong);
    color: var(--text);
}

@media (hover: hover) and (pointer: fine) {
.ghost-btn:hover {
    background: var(--surface-2);
}
}

.danger-btn {
    background: transparent;
    border: 1px solid color-mix(in srgb, var(--danger) 45%, var(--line));
    color: var(--danger);
}

.icon-btn {
    width: 44px;
    min-width: 44px;
    height: 44px;
    padding: 0;
    display: inline-grid;
    place-items: center;
    font-size: 1.15rem;
}

:is(input, select, textarea) {
    background: var(--panel);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-control);
    color: var(--text);
    min-height: var(--control-height);
}

:is(input, select, textarea):focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}

.field-label {
    color: var(--muted);
    font-weight: 700;
}

.field-help {
    color: var(--muted);
    font-size: 0.78rem;
    line-height: 1.35;
}

/* Píldoras de estado con color de significado. */
.status-pill {
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.75rem;
    padding: 4px 10px;
    width: auto;
    max-width: 100%;
}

.status-pill.status-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.status-pill.status-danger,
.status-pill.payment-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.status-pill.status-warning,
.status-pill.payment-warning { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.status-pill.payment-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.status-pill.status-neutral,
.status-pill.status-cancelado { background: var(--surface-2); color: var(--muted); border-color: transparent; }

/* Montos y textos con tono: solo color, sin recuadro (la regla antigua
   .status-* les ponía borde y fondo de píldora). */
:is(dd, strong, .route-status, .detail-mov-amount):is(.status-ok, .status-danger, .status-warning, .status-cancelado) {
    background: transparent;
    border: 0;
    padding: 0;
}

.status-ok:not(.status-pill) { color: var(--ok); }
.status-danger:not(.status-pill) { color: var(--danger); }
.status-warning:not(.status-pill) { color: var(--warning); }

/* ---------- Indicadores (KPI) ------------------------------------------- */

.metric {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px;
    min-height: 0;
    gap: 4px;
    box-shadow: none;
}

@media (hover: hover) and (pointer: fine) {
.metric:hover {
    transform: none;
    box-shadow: none;
}
}

.metric p {
    font-size: 0.75rem;
    color: var(--muted);
    font-weight: 600;
}

.metric strong {
    font-size: 1.125rem;
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.metric-ok strong { color: var(--ok); }
.metric-danger strong { color: var(--danger); }

#analyticsMercanciaSection .analytics-mini-kpis .metric,
#analyticsPrestamoSection .analytics-mini-kpis .metric {
    background: var(--surface-2);
    border-color: var(--line);
}

/* ---------- Cabecera ----------------------------------------------------- */

.topbar {
    border-radius: 0 0 var(--radius-card) var(--radius-card);
    border-top: 0;
    padding: 10px 16px;
    gap: 10px;
}

.brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    box-shadow: none;
}

.brand-title {
    font-size: 1rem;
}

.user-badge {
    background: var(--surface-2);
    border: 0;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 600;
}

/* ---------- Inicio: resumen del día y lista de cobros -------------------- */

.home-summary {
    padding: 16px;
    display: grid;
    gap: 12px;
}

.home-summary-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.home-summary-head h3 {
    margin: 0;
}

.home-kpis {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.metric-sub {
    font-size: 0.72rem;
    color: var(--muted);
}

.panel-left {
    padding: 16px;
}

.cobro-group {
    border: 0;
    background: transparent;
    box-shadow: none;
    padding: 0;
    margin: 0 0 12px;
}

.cobro-group-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 2px 8px;
}

.cobro-group-head h4 {
    margin: 0;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}

.cobro-count {
    background: var(--surface-2);
    color: var(--muted);
    border: 0;
    font-size: 0.75rem;
}

.cobro-group .list {
    display: grid;
    gap: 8px;
}

.list-item.cobro-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: var(--panel);
    box-shadow: none;
    text-align: left;
    cursor: pointer;
    transform: none;
}

.list-item.cobro-row.active {
    border-color: color-mix(in srgb, var(--primary) 45%, var(--line));
    background: var(--panel);
}
@media (hover: hover) and (pointer: fine) {
.list-item.cobro-row:hover {
    border-color: color-mix(in srgb, var(--primary) 45%, var(--line));
    background: var(--panel);
}
}

.cobro-row-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    font-size: 1.2rem;
    background: var(--primary-soft);
    color: var(--primary);
}

.cobro-row-icon.status-warning {
    background: var(--warning-soft);
    color: var(--warning);
}

.cobro-row .list-item-info {
    min-width: 0;
    text-align: left;
}

.cobro-row .list-item-info strong {
    display: block;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cobro-row .list-item-info p {
    margin: 2px 0 0;
    font-size: 0.8rem;
}

.cobro-row .list-item-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-direction: row;
}

.cobro-row-chevron {
    color: var(--muted);
    font-size: 1.3rem;
}

/* ---------- Pestañas ----------------------------------------------------- */

.section-tabs {
    background: var(--panel);
    border: 1px solid var(--line);
    box-shadow: var(--shadow-soft);
}

.tab-view {
    border: 0;
    background: transparent;
    color: var(--muted);
    font-weight: 700;
}

.tab-view.active {
    background: var(--primary-soft);
    color: var(--primary);
    box-shadow: none;
}

/* ---------- Espacio de trabajo del cobro --------------------------------- */

.detail-header {
    padding: 16px;
}

.detail-header .panel-header {
    display: grid;
    gap: 12px;
}

.detail-header-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 8px;
}

.section-title-icon {
    background: var(--primary-soft);
    color: var(--primary);
    border: 0;
}

#cobroWorkspaceSubtitle {
    text-transform: capitalize;
}

.insights-toggle {
    min-height: 56px;
}

.insights-arrow {
    color: var(--muted);
}

.insights-groups {
    display: grid;
    gap: 16px;
    padding-top: 8px;
}

.insights-group h5 {
    margin: 0 0 8px;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}

.insights-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 8px;
}

/* ---------- Ruta: tarjeta de cliente ------------------------------------- */

.route-board {
    padding: 16px;
}

.route-toolbar {
    background: var(--panel);
    border: 0;
    box-shadow: none;
    padding: 0 0 8px;
    margin: 0 0 4px;
}

.route-hint {
    font-size: 0.78rem;
    margin: 4px 2px 10px;
}

.route-list {
    display: grid;
    gap: 8px;
}

.route-card {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    padding: 12px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: var(--panel);
    box-shadow: none;
}

.route-card.active,
.route-card.expanded {
    border-color: color-mix(in srgb, var(--primary) 50%, var(--line));
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 10%, transparent);
}

.route-index {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--muted);
    background: var(--surface-2);
    border: 0;
    margin-top: 2px;
    cursor: grab;
}

.route-main {
    min-width: 0;
    display: grid;
    gap: 8px;
}

.route-card .route-head {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 8px;
}

.route-client-main {
    min-width: 0;
    display: grid;
    gap: 4px;
}

.route-name {
    font-size: 0.98rem;
    line-height: 1.25;
}

.route-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--muted);
    min-width: 0;
}

.route-status.payment-danger,
.route-status.status-danger { color: var(--danger); }
.route-status.payment-warning,
.route-status.status-warning { color: var(--warning); }
.route-status.payment-ok,
.route-status.status-ok { color: var(--ok); }

.route-card .route-status .puntaje-dot {
    order: -1 !important;
    width: 8px;
    height: 8px;
    min-width: 8px;
    box-shadow: none;
    animation: none;
    margin: 0 !important;
    border: 0;
}

.route-amount {
    text-align: right;
    display: grid;
    line-height: 1.1;
}

.route-amount small {
    font-size: 0.68rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.route-amount strong {
    font-size: 1.05rem;
    color: var(--text);
    white-space: nowrap;
}

.route-menu-toggle {
    width: 44px;
    min-width: 44px;
    height: 44px;
    padding: 0;
    display: inline-grid !important;
    place-items: center;
    font-size: 1.2rem;
    border-color: transparent;
    background: transparent;
}

.route-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.route-meta-chip {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0 10px;
    border-radius: 999px;
    background: var(--surface-2);
    border: 0;
    color: var(--muted);
    font-size: 0.78rem;
}

.route-meta-whatsapp {
    color: var(--ok);
}

.route-reason {
    font-size: 0.82rem;
    color: var(--muted);
    margin: 0;
}

.route-menu {
    background: var(--panel);
    border: 1px solid var(--line);
    box-shadow: var(--shadow-deep);
    border-radius: 12px;
    padding: 6px;
    min-width: 168px;
}

.route-menu-item {
    justify-content: flex-start;
    width: 100%;
}

/* El bloque de cabecera antiguo reordenaba los hijos con flex/order en
   celular (el monto quedaba antes del nombre). Se restablece el orden. */
.route-card .route-head > * {
    order: 0 !important;
    flex: initial !important;
    margin: 0 !important;
}

.route-card .route-status {
    background: transparent;
    border: 0;
    padding: 0;
    border-radius: 0;
}

.route-card .route-main {
    gap: 0;
}

.route-card .route-meta {
    margin-top: 8px;
}

.route-expand {
    margin-top: 0;
    display: grid;
    gap: 10px;
}

.route-expand.is-open {
    margin-top: 10px;
}

/* Al tocar la tarjeta se muestran sus acciones (lo que indica la ayuda de la
   ruta). El menú ⋮ sigue disponible con las mismas acciones. */
.route-card .route-expand.is-open .route-actions {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
    gap: 8px;
    margin: 0;
}

.route-card .route-actions .route-btn {
    min-height: 44px;
    width: 100%;
    justify-content: center;
}

/* ---------- Ficha del cliente -------------------------------------------- */

.cliente-focus-shell {
    display: grid;
    gap: 12px;
}

.cliente-focus-shell .focus-name {
    display: flex !important;
    flex-direction: row !important;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.focus-name-stack h4 {
    font-size: 1.2rem;
    margin: 2px 0;
}

.cliente-context-tag {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--primary);
    background: transparent;
    border: 0;
    padding: 0;
}

.cliente-focus-shell .focus-strip {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: wrap;
    gap: 6px;
}

.cliente-focus-shell .focus-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 8px;
}

.focus-kpi {
    background: var(--surface-2);
    border: 0;
    border-radius: 12px;
    padding: 10px;
    box-shadow: none;
}

.focus-kpi p {
    margin: 0 0 2px;
    font-size: 0.72rem;
    color: var(--muted);
    font-weight: 600;
}

.focus-kpi strong {
    /* Una cifra nunca se parte en dos líneas: se reduce el tamaño en pantallas angostas. */
    font-size: clamp(0.8rem, 3.6vw, 0.98rem);
    white-space: nowrap;
    overflow-wrap: normal;
}

/* La fecha del próximo pago es texto: puede ocupar dos líneas. */
.focus-kpi.state strong {
    white-space: normal;
}

.focus-kpi.debt strong {
    color: var(--danger);
}

.focus-kpi.paid strong {
    color: var(--ok);
}

.focus-meta-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px;
}

.focus-data {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 16px;
    margin: 0;
    padding: 12px;
    border-radius: 12px;
    background: var(--surface-2);
}

.focus-data div {
    min-width: 0;
}

.focus-data .focus-data-wide {
    grid-column: 1 / -1;
}

.focus-data dt {
    font-size: 0.72rem;
    color: var(--muted);
    font-weight: 600;
}

.focus-data dd {
    margin: 2px 0 0;
    font-size: 0.88rem;
    overflow-wrap: anywhere;
}

.detail-mov-item {
    border-radius: 12px;
    border: 1px solid var(--line);
    background: var(--panel);
    box-shadow: none;
}

.detail-mov-amount {
    font-size: 1rem;
}

.detail-mov-amount.status-ok { color: var(--ok); }
.detail-mov-amount.status-danger { color: var(--danger); }
.detail-mov-amount.status-warning { color: var(--warning); }

/* ---------- Modales ------------------------------------------------------ */

.floating-overlay {
    background: rgba(8, 18, 24, 0.5);
    backdrop-filter: none;
}

.cliente-floating,
.caja-modal {
    border-radius: 18px;
    box-shadow: var(--shadow-deep);
}

/* Encabezado normal (no fijo): un encabezado "sticky" dentro del modal podía
   tapar el campo obligatorio que el navegador señala al intentar guardar. */
.floating-head {
    padding-bottom: 10px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--line);
    min-width: 0;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.floating-head h4 {
    margin: 0;
}

.floating-head .muted {
    margin: 2px 0 0;
    font-size: 0.82rem;
}

/* ---------- Caja --------------------------------------------------------- */

.caja-hero-card {
    border-radius: 16px;
    padding: 16px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    box-shadow: none;
    display: grid;
    gap: 6px;
}

.caja-hero-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
}

.caja-hero-kicker {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--muted);
    text-transform: none;
    letter-spacing: 0;
}

.caja-hero-value {
    font-size: 2rem;
    line-height: 1.1;
}

.caja-hero-support {
    font-size: 0.8rem;
    color: var(--muted);
    margin: 0;
}

.caja-health-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 0.75rem;
    font-weight: 700;
    border: 0;
}

.caja-health-badge.ok { background: var(--ok-soft); color: var(--ok); }
.caja-health-badge.warning { background: var(--warning-soft); color: var(--warning); }
.caja-health-badge.danger { background: var(--danger-soft); color: var(--danger); }

.caja-balance-diff {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.82rem;
    font-weight: 700;
    margin: 0;
    width: fit-content;
    background: transparent;
    border: 0;
    padding: 0;
}

.caja-blocks {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 12px;
    margin-top: 12px;
}

.caja-block {
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px 14px;
}

.caja-block h4 {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0 0 6px;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}

.caja-block dl {
    margin: 0;
}

.caja-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 0;
    border-bottom: 1px solid var(--line);
}

.caja-row:last-child {
    border-bottom: 0;
}

.caja-row dt {
    font-size: 0.88rem;
    display: grid;
    min-width: 0;
}

.caja-row dt small {
    font-size: 0.72rem;
    color: var(--muted);
}

.caja-row dd {
    margin: 0;
    font-weight: 700;
    white-space: nowrap;
}

.caja-row dd.is-total {
    font-size: 1.05rem;
}

.caja-dashboard {
    padding: 16px;
}

.caja-page-header {
    padding: 16px;
}

.caja-header-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 8px;
}

.gasto-item {
    border-radius: 12px;
    border: 1px solid var(--line);
    box-shadow: none;
    background: var(--panel);
    padding: 12px;
    display: grid;
    gap: 4px;
}

.gasto-item .history-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.gasto-item .history-row strong {
    font-size: 1rem;
}

.gasto-item p {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text);
    overflow-wrap: anywhere;
}

.gasto-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
    font-size: 0.75rem;
    color: var(--muted);
}

/* Filtro de fecha sin tarjeta dentro de tarjeta. */
.caja-page-header :is(.caja-toolbar, .caja-filter-fields) {
    border: 0;
    background: transparent;
    box-shadow: none;
    padding: 0;
}

/* Liquidación: indicadores en dos columnas. */
.liq-dashboard-grid .caja-card-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)) !important;
    gap: 8px;
}

.caja-card {
    border-radius: 12px;
    box-shadow: none;
    background: var(--surface-2);
    border: 1px solid var(--line);
}

/* ---------- Empleados y admin -------------------------------------------- */

.employee-card {
    border-radius: 14px;
    border: 1px solid var(--line);
    background: var(--panel);
    box-shadow: none;
    padding: 14px;
}

.employee-actions {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.admin-details {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 0 12px;
}

.admin-details > summary {
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 44px;
    font-weight: 700;
    cursor: pointer;
}

.admin-details > summary::-webkit-details-marker {
    display: none;
}

.admin-details[open] > summary i {
    transform: rotate(180deg);
}

.admin-details[open] {
    padding-bottom: 12px;
}

.admin-actions-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
}

/* ---------- Historial ---------------------------------------------------- */

.history-item,
.history-list > article {
    border-radius: 12px;
    border: 1px solid var(--line);
    background: var(--panel);
    box-shadow: none;
}

/* ==========================================================================
   Celular (≤ 760 px)
   ========================================================================== */
@media (max-width: 760px) {
    body {
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .layout {
        padding-inline: 12px;
    }

    /* Cabecera en una sola fila: marca a la izquierda, acciones de ícono a la
       derecha. El rol y nombre van en una línea pequeña debajo. */
    .topbar {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr) auto auto auto;
        align-items: center;
        gap: 8px;
        width: auto;
        padding: 8px 12px;
        margin: 0 0 12px;
        border-radius: 0 0 16px 16px;
    }

    .topbar .brand-lockup {
        display: contents;
    }

    .topbar .brand-copy {
        min-width: 0;
        text-align: left;
    }

    .topbar .topbar-actions {
        display: contents;
    }

    .topbar .user-badge {
        grid-row: 2;
        grid-column: 1 / -1;
        justify-self: stretch;
        min-width: 0;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        display: block;
        padding: 0;
        background: transparent;
        min-height: 0;
        font-size: 0.75rem;
    }

    .topbar :is(#backToHomeBtn, #logoutBtn, a.ghost-btn) {
        width: 44px;
        min-width: 44px;
        padding: 0;
        justify-content: center;
    }

    .topbar :is(#backToHomeBtn, #logoutBtn, a.ghost-btn) span {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }

    .topbar :is(#backToHomeBtn, #logoutBtn, a.ghost-btn) i {
        font-size: 1.2rem;
        margin: 0;
    }

    /* Inicio: resumen del día arriba, luego la lista de cobros. */
    .app-shell:not(.screen-cobro) {
        display: flex;
        flex-direction: column;
    }

    .app-shell:not(.screen-cobro) #homeStack {
        order: -1;
    }

    .home-kpis {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    /* Menú de secciones arriba y fijo al desplazarse. Abajo quedaba en la franja
       que Safari (iPhone) usa para mostrar su barra: el primer toque solo hacía
       aparecer la barra de Safari y había que tocar otra vez. */
    .app-shell:not(.screen-cobro) .section-tabs {
        position: sticky;
        top: 0;
        z-index: 20;
        margin: 0 0 12px;
        display: flex;
        overflow-x: auto;
        gap: 2px;
        padding: 4px;
        border-radius: 14px;
        scrollbar-width: none;
        overscroll-behavior-x: contain;
    }

    .app-shell:not(.screen-cobro) .section-tabs::-webkit-scrollbar {
        display: none;
    }

    .app-shell:not(.screen-cobro) .section-tabs .tab-view {
        flex: 1 0 auto;
        min-width: 64px;
        min-height: 48px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        padding: 4px 8px;
        font-size: 0.7rem;
        border-radius: 10px;
        white-space: nowrap;
    }

    .app-shell:not(.screen-cobro) .section-tabs .tab-view i {
        font-size: 1.2rem;
        margin: 0;
    }

    .app-shell:not(.screen-cobro) .section-tabs .tab-view.hidden {
        display: none;
    }

    /* Formularios: nunca más altos que el área visible real (en iPhone 100vh
       incluye la zona detrás de la barra de Safari y el botón Guardar podía
       quedar debajo de ella). */
    .cliente-floating,
    .caja-modal {
        max-height: calc(100vh - 24px) !important;
        max-height: calc(100dvh - 24px) !important;
        padding-bottom: 20px !important;
    }

    /* Los modales conservan su posición original (centrados). Como hoja pegada
       al borde inferior, en iPhone el botón Guardar quedaba en la franja que
       Safari usa para su barra y el toque no llegaba al formulario. */
    .cliente-floating .floating-head .ghost-btn,
    .caja-modal .floating-head .ghost-btn {
        min-width: 44px;
    }

    /* Los grupos de botones de acción quedan lado a lado (no apilados). */
    .detail-header-actions,
    .caja-header-actions {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .insights-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .caja-hero-value {
        font-size: 1.75rem;
    }

    .liq-dashboard-grid .caja-card-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    /* Historial sin scroll anidado: la página es la que se desplaza. */
    .history-card .history-list,
    #historyList {
        max-height: none;
        overflow: visible;
    }
}

@media (max-width: 360px) {
    .cliente-focus-shell .focus-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    .cliente-focus-shell .focus-grid .focus-kpi.state {
        grid-column: 1 / -1;
    }

    .route-amount strong {
        font-size: 0.95rem;
    }

    .home-kpis,
    .insights-grid {
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }
}


.gasto-item {
    grid-template-columns: minmax(0, 1fr) !important;
}

.gasto-item > div {
    min-width: 0;
    width: 100%;
}

.caja-filter-fields-single .inputGroup {
    width: 100%;
    max-width: 260px;
}

.caja-filter-fields-single .inputGroup input[type="date"] {
    max-width: none;
}

@media (max-width: 760px) {
    .caja-header-actions,
    .detail-header-actions {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    .caja-header-actions > *,
    .detail-header-actions > * {
        width: 100% !important;
        min-width: 0 !important;
        padding-inline: 8px;
    }
}

/* ==========================================================================
   Tableta y escritorio (≥ 761 px)
   ========================================================================== */
@media (min-width: 761px) {
    /* Cabecera en una fila: marca a la izquierda, sesión y acciones a la derecha. */
    .topbar {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        align-items: center !important;
        justify-content: space-between !important;
        text-align: left !important;
        padding: 10px 20px !important;
    }

    .topbar .brand-lockup {
        display: flex !important;
        flex-direction: row !important;
        align-items: center;
        gap: 10px;
        width: auto !important;
        justify-content: flex-start !important;
    }

    .topbar .topbar-actions {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        align-items: center;
        justify-content: flex-end !important;
        gap: 10px;
        width: auto !important;
    }

    .detail-header-actions,
    .caja-header-actions {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 220px)) !important;
        justify-content: start;
    }

    .detail-header-actions > *,
    .caja-header-actions > * {
        width: 100% !important;
    }
}

@media (min-width: 761px) and (max-width: 1100px) {
    /* En tableta la columna es única: primero pestañas y resumen del día. */
    .app-shell:not(.screen-cobro) {
        display: flex !important;
        flex-direction: column;
    }

    .app-shell:not(.screen-cobro) #homeStack {
        order: -1;
    }

    .app-shell:not(.screen-cobro) > * {
        width: 100% !important;
        max-width: none !important;
    }
}

@media (min-width: 761px) {
    .section-tabs .tab-view {
        display: inline-flex;
        align-items: center;
        gap: 6px;
    }
}

/* Si el rol solo tiene una acción (empleado: sin "Ver Caja"), ocupa el ancho. */
@media (max-width: 760px) {
    .detail-header-actions:has(> .hidden) > :not(.hidden) {
        grid-column: 1 / -1;
    }
}

/* 901–1100 px: una sola columna, igual que en celular la lista de cobros no
   empuja hacia abajo el cobro abierto (se vuelve con "Volver"). */
@media (min-width: 901px) and (max-width: 1100px) {
    .app-shell.screen-cobro .panel-left,
    .app-shell[data-active-view]:not([data-active-view="resumen"]) .panel-left {
        display: none;
    }
}

/* ==========================================================================
   Comportamiento táctil (celulares)
   ========================================================================== */

/* Barra fina de carga: aparece mientras se consultan datos, sin bloquear toques
   (la capa que bloquea la pantalla queda solo para cuando se guarda algo). */
body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    z-index: 95;
    pointer-events: none;
    background: linear-gradient(90deg, transparent, var(--primary), transparent);
    background-size: 50% 100%;
    background-repeat: no-repeat;
    opacity: 0;
    transition: opacity 0.2s ease;
}

body.is-loading::after {
    opacity: 1;
    animation: loading-bar 1s linear infinite;
}

@keyframes loading-bar {
    from { background-position: -50% 0; }
    to { background-position: 150% 0; }
}

/* Sin retraso de "doble toque para zoom" en controles. */
:is(a, button, input, select, textarea, label, summary, [role="button"], .route-card, .list-item) {
    touch-action: manipulation;
}

@media (hover: none), (pointer: coarse) {
    /* Desplazamiento natural del teléfono: el "suave" forzado peleaba con el dedo. */
    html {
        scroll-behavior: auto;
    }

    body {
        overscroll-behavior-y: auto;
    }

    /* Respuesta visual inmediata al tocar (antes el botón no cambiaba y se volvía a tocar). */
    :is(.primary-btn, .ghost-btn, .danger-btn, .chip, .tab-view, .icon-btn):active {
        transform: scale(0.97);
        filter: brightness(0.94);
        transition: transform 0.05s ease;
    }

    :is(.list-item.cobro-row, .route-card):active {
        background: var(--surface-2);
    }

    /* Tarjetas: sin "agarrar" (el reordenamiento táctil es desde el número). */
    .route-card {
        cursor: default;
    }

    .route-index {
        touch-action: none;
    }
}

/* En iPhone, overflow-x: hidden en body altera el desplazamiento con el dedo;
   clip recorta igual sin crear un contenedor de scroll. */
@supports (overflow: clip) {
    body {
        overflow-x: clip;
    }
}
