/* ═══════════════════════════════════════════════════
   LA VASQUITA — TEMA BOUTIQUE CÁLIDO (Opción C)
   Inspiración: café gourmet / pastelería parisina
   ═══════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500&family=Raleway:wght@300;400;500;600;700&display=swap');

:root {
    /* Paleta cálida boutique */
    --bq-bg:              #F5EFE7;  /* fondo crema oscura */
    --bq-bg-soft:         #FAF6F1;
    --bq-card:            #FFFFFF;
    --bq-card-warm:       #FFFCF7;
    --bq-cream:           #EBDAC6;
    --bq-cream-light:     #F5EFE7;
    --bq-brown-deep:      #292017;  /* marrón muy oscuro */
    --bq-brown:           #886644;  /* marrón principal */
    --bq-brown-mid:       #A99886;
    --bq-brown-soft:      #6B5340;
    --bq-tan:             #C9B89E;
    --bq-text:            #292017;
    --bq-text-muted:      #886644;
    --bq-text-light:      #A99886;
    --bq-border:          #EBDAC6;
    --bq-border-strong:   #C9B89E;
    
    /* Estados */
    --bq-success:         #5A7A3F;
    --bq-success-bg:      #ECF4DF;
    --bq-warning:         #C7811A;
    --bq-warning-bg:      #FFF8EA;
    --bq-danger:          #C7212C;
    --bq-danger-bg:       #FEE2E2;
    
    /* Tipografías */
    --bq-serif:           'Playfair Display', 'Times New Roman', serif;
    --bq-sans:            'Raleway', -apple-system, sans-serif;
    
    /* Radios generosos */
    --bq-r-sm:            10px;
    --bq-r-md:            14px;
    --bq-r-lg:            18px;
    --bq-r-pill:          999px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bq-bg);
    color: var(--bq-text);
    font-family: var(--bq-sans);
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--bq-brown); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ═══════════════════════════════════════════════════
   TOPBAR (cabecera oscura redondeada)
   ═══════════════════════════════════════════════════ */
.topbar {
    background: var(--bq-brown-deep);
    color: white;
    padding: 18px 0;
    margin-bottom: 22px;
}
.topbar-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 28px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: nowrap;       /* En móvil pasamos a column abajo */
}
.topbar h1 {
    font-family: var(--bq-serif);
    font-size: 22px;
    font-weight: 500;
    margin: 0;
    color: white;
    letter-spacing: 0.02em;
    white-space: nowrap;
}
.topbar-subtitle {
    font-size: 12px;
    color: var(--bq-tan);
    font-style: italic;
    margin: 2px 0 0;
    letter-spacing: 0.05em;
}
.topbar-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: nowrap;        /* En escritorio: todo en línea como en repostera/mensajero */
    justify-content: flex-end;
    margin-left: auto;
}
@media (max-width: 900px) {
    .topbar-content { flex-wrap: wrap; }
    .topbar-actions { width: 100%; justify-content: flex-start; flex-wrap: wrap; }
    .topbar h1 { font-size: 18px; white-space: normal; }
}
.btn-link {
    color: white;
    text-decoration: none;
    padding: 8px 16px;
    background: rgba(255,255,255,0.08);
    border-radius: var(--bq-r-pill);
    font-size: 13px;
    font-weight: 500;
    transition: 0.15s;
}
.btn-link:hover {
    background: rgba(255,255,255,0.18);
    text-decoration: none;
}
.role-badge {
    background: var(--bq-brown);
    color: white;
    padding: 4px 14px;
    border-radius: var(--bq-r-pill);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

/* ═══════════════════════════════════════════════════
   CONTENIDO
   ═══════════════════════════════════════════════════ */
.contenido {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 28px 60px;
}

/* ═══════════════════════════════════════════════════
   CARDS (tarjetas blancas elegantes)
   ═══════════════════════════════════════════════════ */
.card, .seccion, .resumen-card, .pedido-card, .dia-card, .stat-card,
.suc-card, .persona-card {
    background: var(--bq-card);
    border-radius: var(--bq-r-md);
    border: none;
    box-shadow: 0 2px 8px rgba(41, 32, 23, 0.04);
    transition: 0.2s;
}
.card:hover, .seccion:hover {
    box-shadow: 0 4px 16px rgba(41, 32, 23, 0.07);
}

/* ═══════════════════════════════════════════════════
   STATS / NÚMEROS GRANDES
   ═══════════════════════════════════════════════════ */
.stats-grid, .stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}
.stat-card {
    text-align: center;
    padding: 22px 16px;
}
.stat-card .num {
    font-family: var(--bq-serif);
    font-size: 32px;
    font-weight: 500;
    color: var(--bq-brown);
    line-height: 1;
    margin-bottom: 6px;
}
.stat-card .label, .stat-card .lbl {
    font-size: 12px;
    color: var(--bq-brown-soft);
    letter-spacing: 0.04em;
    text-transform: none;
    font-weight: 500;
}
.stat-card.urgente { background: var(--bq-warning-bg); }
.stat-card.urgente .num { color: var(--bq-warning); }
.stat-card.alerta .num { color: var(--bq-warning); }
.stat-card.success .num { color: var(--bq-success); }

/* ═══════════════════════════════════════════════════
   BOTONES Y ACCIONES
   ═══════════════════════════════════════════════════ */
.btn-primary, .btn-guardar, .btn-procesar, .btn-confirmar, .btn-enviar,
.btn-importar {
    background: var(--bq-brown);
    color: white !important;
    border: none;
    padding: 12px 28px;
    border-radius: var(--bq-r-pill);
    font-weight: 500;
    cursor: pointer;
    font-family: var(--bq-sans);
    font-size: 14px;
    letter-spacing: 0.02em;
    text-decoration: none;
    display: inline-block;
    transition: 0.15s;
}
.btn-primary:hover, .btn-guardar:hover, .btn-procesar:hover,
.btn-confirmar:hover, .btn-enviar:hover, .btn-importar:hover {
    background: var(--bq-brown-deep);
    text-decoration: none;
}
.btn-confirmar:disabled, .btn-enviar:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.btn-cancelar, .btn-cerrar, .modal-cerrar, .btn-cerrar-cal {
    background: white;
    color: var(--bq-brown-soft);
    border: 1px solid var(--bq-border);
    padding: 10px 22px;
    border-radius: var(--bq-r-pill);
    font-family: var(--bq-sans);
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    font-size: 14px;
}
.btn-cancelar:hover, .btn-cerrar:hover, .modal-cerrar:hover {
    background: var(--bq-cream-light);
    text-decoration: none;
}
.btn-eliminar-todo {
    background: var(--bq-danger);
    color: white;
    border: none;
    padding: 12px 22px;
    border-radius: var(--bq-r-pill);
    font-weight: 500;
    cursor: pointer;
    font-family: var(--bq-sans);
    font-size: 14px;
}

/* Botones de acción tipo grid (panel) */
.accion-btn, .accion-tartas {
    background: white;
    color: var(--bq-text) !important;
    border: none;
    padding: 22px 18px;
    border-radius: var(--bq-r-md);
    font-weight: 500;
    text-decoration: none;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    transition: 0.15s;
    box-shadow: 0 2px 8px rgba(41, 32, 23, 0.04);
    font-family: var(--bq-sans);
}
.accion-btn:hover, .accion-tartas:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(41, 32, 23, 0.1);
    text-decoration: none;
}
.accion-btn .icon, .accion-tartas .icon {
    font-size: 26px;
}
.accion-btn .titulo, .accion-tartas .titulo {
    font-family: var(--bq-serif);
    font-size: 16px;
    font-weight: 500;
    color: var(--bq-text);
}
.accion-btn .sub, .accion-tartas .sub {
    font-size: 12px;
    color: var(--bq-brown-soft);
    font-weight: 400;
    font-style: italic;
}
.accion-btn.principal, .accion-tartas.principal {
    background: var(--bq-brown-deep);
    color: white !important;
}
.accion-btn.principal .titulo, .accion-tartas.principal .titulo {
    color: white;
}
.accion-btn.principal .sub, .accion-tartas.principal .sub {
    color: var(--bq-tan);
}
.acciones-grid, .acciones-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

/* ═══════════════════════════════════════════════════
   TIPOGRAFÍA SECCIONES
   ═══════════════════════════════════════════════════ */
.seccion-header, .card-header, .resumen-header {
    padding: 16px 22px;
    background: linear-gradient(to right, var(--bq-cream-light), white);
    border-bottom: 1px solid var(--bq-border);
    border-radius: var(--bq-r-md) var(--bq-r-md) 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.seccion-header h2, .seccion-header h3, .card-header,
.resumen-titulo h3 {
    font-family: var(--bq-serif);
    font-size: 16px;
    font-weight: 500;
    margin: 0;
    color: var(--bq-text);
    letter-spacing: 0.01em;
}
.section-title {
    font-family: var(--bq-serif);
    font-size: 18px;
    font-weight: 500;
    color: var(--bq-text);
    margin: 24px 0 14px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--bq-border);
    letter-spacing: 0.02em;
}

/* ═══════════════════════════════════════════════════
   BADGES (píldoras)
   ═══════════════════════════════════════════════════ */
.suc-badge, .badge-stats, .estado-badge, .total-tartas-pill,
.cnt, .badge-count {
    background: var(--bq-cream);
    color: var(--bq-brown-soft);
    padding: 5px 14px;
    border-radius: var(--bq-r-pill);
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.02em;
    text-transform: none;
}
.estado-badge {
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.06em;
}
.estado-pendiente { background: #FFF8EA; color: #C7811A; }
.estado-enviado { background: var(--bq-success-bg); color: var(--bq-success); }
.estado-procesando { background: #DBEAFE; color: #1E40AF; }
.estado-recibido { background: var(--bq-cream); color: var(--bq-brown-soft); }

.codigo, .codigo-mini {
    font-family: 'Courier New', monospace;
    font-size: 12px;
    background: var(--bq-cream-light);
    padding: 3px 10px;
    border-radius: var(--bq-r-sm);
    color: var(--bq-brown-soft);
    font-weight: 500;
}

/* ═══════════════════════════════════════════════════
   FORMULARIOS
   ═══════════════════════════════════════════════════ */
input[type="text"], input[type="number"], input[type="date"],
input[type="time"], input[type="email"], input[type="password"],
select, textarea {
    padding: 11px 16px;
    border: 1px solid var(--bq-border);
    border-radius: var(--bq-r-sm);
    font-family: var(--bq-sans);
    font-size: 14px;
    background: white;
    color: var(--bq-text);
    transition: 0.15s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--bq-brown);
    box-shadow: 0 0 0 3px rgba(136, 102, 68, 0.08);
}
.form-group {
    margin-bottom: 14px;
}
.form-group label {
    display: block;
    font-size: 12px;
    color: var(--bq-brown-soft);
    margin-bottom: 6px;
    font-weight: 500;
    letter-spacing: 0.02em;
}

/* ═══════════════════════════════════════════════════
   ALERTAS
   ═══════════════════════════════════════════════════ */
.alert {
    padding: 14px 20px;
    border-radius: var(--bq-r-md);
    margin-bottom: 16px;
    font-size: 14px;
    font-weight: 500;
}
.alert-ok, .alert-success {
    background: var(--bq-success-bg);
    color: var(--bq-success);
    border-left: 4px solid var(--bq-success);
}
.alert-err, .alert-error {
    background: var(--bq-danger-bg);
    color: var(--bq-danger);
    border-left: 4px solid var(--bq-danger);
}
.alert-warn, .alert-warning {
    background: var(--bq-warning-bg);
    color: var(--bq-warning);
    border-left: 4px solid var(--bq-warning);
}
.info-banner {
    background: var(--bq-warning-bg);
    border-left: 3px solid var(--bq-warning);
    padding: 14px 18px;
    border-radius: var(--bq-r-sm);
    color: var(--bq-warning);
    font-size: 13px;
    margin-bottom: 16px;
    line-height: 1.5;
}

/* ═══════════════════════════════════════════════════
   TABLAS
   ═══════════════════════════════════════════════════ */
.tabla, .items-tabla, .tabla-tartas {
    width: 100%;
    border-collapse: collapse;
}
.tabla thead th, .items-tabla thead th, .tabla-tartas thead th {
    background: var(--bq-cream-light);
    padding: 12px 16px;
    text-align: left;
    font-family: var(--bq-serif);
    font-weight: 500;
    color: var(--bq-text);
    font-size: 13px;
    letter-spacing: 0.02em;
    border-bottom: 1px solid var(--bq-border);
}
.tabla td, .items-tabla td, .tabla-tartas td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--bq-cream-light);
    font-size: 14px;
}
.tabla tr:last-child td { border-bottom: none; }
.tabla tr.clickable { cursor: pointer; transition: 0.1s; }
.tabla tr.clickable:hover { background: var(--bq-cream-light); }

/* ═══════════════════════════════════════════════════
   LOGO
   ═══════════════════════════════════════════════════ */
.brand-logo {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    line-height: 1;
}
.brand-logo .brand-name {
    font-family: var(--bq-serif);
    font-size: 24px;
    font-weight: 500;
    letter-spacing: 0.15em;
}
.brand-logo .brand-tagline {
    font-size: 10px;
    letter-spacing: 0.25em;
    opacity: 0.85;
    margin-top: 4px;
}
.brand-logo.small .brand-name { font-size: 16px; }
.brand-logo.small .brand-tagline { font-size: 8px; }
.brand-logo.large .brand-name { font-size: 32px; }
.brand-logo.large .brand-tagline { font-size: 12px; margin-top: 5px; }
.brand-logo .brand-stripes {
    display: flex;
    flex-direction: column;
    margin-top: 4px;
    gap: 0;
    width: 68px;
}
.brand-logo.small .brand-stripes { width: 50px; }
.brand-logo.large .brand-stripes { width: 90px; margin-top: 5px; }
.brand-logo .brand-stripes .red { background: #C7212C; height: 3px; }
.brand-logo .brand-stripes .yellow { background: #FFBF2F; height: 5px; }
.brand-logo.small .brand-stripes .red { height: 2px; }
.brand-logo.small .brand-stripes .yellow { height: 3px; }

/* ═══════════════════════════════════════════════════
   ÍTEMS DE LISTA
   ═══════════════════════════════════════════════════ */
.pedido-item, .desglose-item, .tarta-row, .item-row, .ing-item,
.suc-row, .stock-item, .tarta-row {
    transition: 0.1s;
}
.pedido-item, .item-row {
    padding: 16px 22px;
    border-bottom: 1px solid var(--bq-cream-light);
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}
.pedido-item:last-child, .item-row:last-child { border-bottom: none; }

/* ═══════════════════════════════════════════════════
   FILTROS / TABS
   ═══════════════════════════════════════════════════ */
.filtros, .tabs-pedido {
    background: white;
    border-radius: var(--bq-r-md);
    padding: 12px;
    margin-bottom: 18px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    box-shadow: 0 2px 8px rgba(41, 32, 23, 0.04);
}
.filtros a, .tabs-pedido a {
    padding: 9px 18px;
    border-radius: var(--bq-r-pill);
    text-decoration: none;
    color: var(--bq-brown-soft);
    font-weight: 500;
    font-size: 13px;
    background: transparent;
    transition: 0.15s;
}
.filtros a:hover, .tabs-pedido a:hover { background: var(--bq-cream-light); }
.filtros a.activo, .filtros a.activa, .tabs-pedido a.activa {
    background: var(--bq-brown);
    color: white;
}

/* ═══════════════════════════════════════════════════
   EMPTY STATE
   ═══════════════════════════════════════════════════ */
.empty, .empty-mini, .empty-hero, .empty-ing {
    padding: 50px 30px;
    text-align: center;
    color: var(--bq-text-light);
    font-style: italic;
    font-size: 14px;
}

/* ═══════════════════════════════════════════════════
   TOAST
   ═══════════════════════════════════════════════════ */
#toast, .toast {
    position: fixed;
    bottom: 28px;
    right: 28px;
    padding: 14px 22px;
    border-radius: var(--bq-r-md);
    font-weight: 500;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s;
    z-index: 1000;
    box-shadow: 0 10px 30px rgba(41, 32, 23, 0.2);
    max-width: 360px;
    background: var(--bq-card);
    color: var(--bq-text);
}

#toast.show, .toast.show {
    transform: translateY(0);
    opacity: 1;
}
#toast.toast-success, .toast.toast-success {
    background: #059669;
    color: white;
    border-left: 4px solid #047857;
}
#toast.toast-error, .toast.toast-error {
    background: #DC2626;
    color: white;
    border-left: 4px solid #991B1B;
}
#toast.toast-info, .toast.toast-info {
    background: #2563EB;
    color: white;
    border-left: 4px solid #1E40AF;
}

/* ═══════════════════════════════════════════════════
   TOOLBAR
   ═══════════════════════════════════════════════════ */
.toolbar {
    background: white;
    padding: 14px 22px;
    border-radius: var(--bq-r-md);
    margin: 0 0 16px;
    box-shadow: 0 2px 8px rgba(41, 32, 23, 0.04);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

/* ═══════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════ */
@media (max-width: 700px) {
    .contenido { padding: 0 16px 40px; }
    .topbar-content { padding: 0 16px; }
    .topbar h1 { font-size: 18px; }
    .stat-card .num { font-size: 26px; }
    .acciones-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}

/* Print */
@media print {
    .topbar, .topbar-actions, .filtros, .tabs-pedido,
    .barra-confirmar, .acciones-pedido, .nav-fechas, .nav-semana {
        display: none !important;
    }
    body { background: white; }
}

/* ═══════════════════════════════════════════════════
   RESPONSIVE EXTENDIDO (cgA142)
   Capas: tablet ≤900px · móvil ≤700px · móvil pequeño ≤420px
   Cubre selectores comunes del design system. Pantallas
   con CSS inline propio pueden necesitar ajustes finos
   en cgA siguientes.
   ═══════════════════════════════════════════════════ */

/* Capa tablet — pantallas medianas */
@media (max-width: 900px) {
    .topbar-content { flex-wrap: wrap; gap: 12px 16px; }
    .topbar h1 { font-size: 20px; }
    .topbar-actions { flex-wrap: wrap; gap: 6px; }
    .acciones-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
    .filtros-bar, .filtros, .filtros-card { flex-wrap: wrap; gap: 10px; }
    table { font-size: 13px; }
}

/* Capa móvil estándar */
@media (max-width: 700px) {
    body { font-size: 14px; }
    .contenido { padding: 14px; }
    .topbar { padding: 10px 0; }
    .topbar-content { padding: 0 14px; flex-direction: column; align-items: flex-start; }
    .topbar h1 { font-size: 17px; }
    .topbar-subtitle { font-size: 11px; }
    .topbar-actions { width: 100%; justify-content: flex-end; }
    .btn-link {
        padding: 10px 14px;
        font-size: 12px;
        min-height: 38px;
        box-sizing: border-box;
        display: inline-flex;
        align-items: center;
    }
    .accion-btn, .accion-btn-grande, .accion-tartas {
        min-height: 60px;
        font-size: 14px;
        padding: 12px 16px;
    }
    .acciones-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
    .section-title { font-size: 16px; margin: 18px 0 10px; }
    .stat-card .num { font-size: 22px; }
    .stats-row { grid-template-columns: 1fr 1fr; gap: 8px; }

    /* Tablas: hacer scroll horizontal en lugar de desbordar */
    .tabla-wrapper, .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    table {
        font-size: 12px;
        white-space: nowrap;
    }
    table th, table td { padding: 8px 10px; }

    /* Inputs y selects más fáciles de tocar */
    input, select, textarea {
        font-size: 16px; /* evita zoom auto en iOS */
        min-height: 40px;
        padding: 10px 12px;
    }
    button, .btn, .btn-completar, .btn-crear, .btn-guardar, .btn-mini, .btn-filtro {
        min-height: 40px;
        padding: 10px 14px;
        font-size: 13px;
    }
    .btn-mini { min-height: 32px; padding: 6px 10px; font-size: 11px; }

    /* Filtros y rangos: que ocupen ancho completo */
    .filtros-bar, .filtros, .filtros-card {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        padding: 12px 14px;
    }
    .filtros-bar > *, .filtros > * { width: 100%; }

    /* Cards de pedido y bloques: una columna */
    .pedido-card {
        grid-template-columns: 1fr !important;
        gap: 8px !important;
    }
    .pedido-card .acciones {
        grid-column: 1 / -1;
        justify-content: flex-end;
        flex-wrap: wrap;
    }
    .bloque { padding: 10px 12px; }
    .bloque-head { padding: 10px 12px; flex-wrap: wrap; gap: 8px; }
    .bloque-head h2 { font-size: 15px; }

    /* Modales: ocupan más pantalla */
    .modal-card {
        width: 96% !important;
        max-width: 96% !important;
        max-height: 92vh;
        overflow-y: auto;
        padding: 22px 18px !important;
    }

    /* Notif bell y campanita */
    .notif-panel {
        position: fixed !important;
        top: 60px !important;
        right: 8px !important;
        left: 8px !important;
        width: auto !important;
        max-height: 75vh !important;
    }
}

/* Capa móvil pequeño (< 420px) */
@media (max-width: 420px) {
    .acciones-grid { grid-template-columns: 1fr; }
    .stats-row { grid-template-columns: 1fr; }
    .topbar h1 { font-size: 15px; }
    .section-title { font-size: 14px; }
    .stat-card .num { font-size: 20px; }
    .accion-btn, .accion-tartas {
        min-height: 56px;
        font-size: 13px;
    }
}

/* ═══════════════════════════════════════════════════
   RESPONSIVE AGRESIVO (cgA144)
   Capa que ataca estilos INLINE y layouts custom que
   cgA142 no pillaba por especificidad. Solo se activa
   en pantallas pequeñas; el escritorio queda intacto.
   ═══════════════════════════════════════════════════ */

@media (max-width: 700px) {

    /* === LAYOUT ROOT === */
    /* cgA145: clip en html, NO en body — overflow:hidden bloqueaba scroll horizontal interno de tablas */
    html { overflow-x: clip; max-width: 100vw; }
    body { max-width: 100vw; }
    main, .contenido, .container, .wrap, .wrapper {
        padding-left: 12px !important;
        padding-right: 12px !important;
        max-width: 100vw !important;
        box-sizing: border-box;
    }

    /* === GRIDS INLINE → UNA COLUMNA === */
    /* Cualquier elemento con grid-template-columns en inline cae a 1 columna */
    [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }
    /* Excepción suave: si el inline declara repeat(auto-fit/fill, minmax(...))
       y el minmax es <= 150px, mantenerlo (chips, badges en fila). El selector de arriba
       lo aplastaría: lo reintroducimos para minmax pequeños usando 2 cols como compromiso */
    [style*="minmax(120px"], [style*="minmax(130px"], [style*="minmax(140px"], [style*="minmax(150px"] {
        grid-template-columns: 1fr 1fr !important;
    }
    /* Stats / KPI con minmax pequeño: 2 cols se ve mejor que 1 */
    [style*="minmax(160px"], [style*="minmax(180px"] {
        grid-template-columns: 1fr 1fr !important;
    }
    [style*="minmax(200px"], [style*="minmax(220px"], [style*="minmax(240px"],
    [style*="minmax(260px"], [style*="minmax(280px"], [style*="minmax(300px"] {
        grid-template-columns: 1fr !important;
    }

    /* === FLEXBOX HORIZONTAL → WRAP === */
    /* Bloques con display:flex inline que no especifican flex-direction se envuelven */
    [style*="display: flex"]:not([style*="flex-direction: column"]):not([style*="flex-direction:column"]) {
        flex-wrap: wrap !important;
    }
    [style*="display:flex"]:not([style*="flex-direction: column"]):not([style*="flex-direction:column"]) {
        flex-wrap: wrap !important;
    }

    /* === ANCHOS FIJOS INLINE → 100% === */
    [style*="width: 600px"], [style*="width:600px"],
    [style*="width: 700px"], [style*="width:700px"],
    [style*="width: 800px"], [style*="width:800px"],
    [style*="width: 500px"], [style*="width:500px"],
    [style*="width: 400px"], [style*="width:400px"],
    [style*="max-width: 600px"], [style*="max-width:600px"],
    [style*="max-width: 700px"], [style*="max-width:700px"],
    [style*="max-width: 800px"], [style*="max-width:800px"],
    [style*="max-width: 900px"], [style*="max-width:900px"],
    [style*="max-width: 1000px"], [style*="max-width:1000px"],
    [style*="max-width: 1100px"], [style*="max-width:1100px"],
    [style*="max-width: 1200px"], [style*="max-width:1200px"],
    [style*="max-width: 1300px"], [style*="max-width:1300px"],
    [style*="max-width: 1400px"], [style*="max-width:1400px"] {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box;
    }
    /* Min-width fijo amplio rompe layout en móvil */
    [style*="min-width: 600px"], [style*="min-width:600px"],
    [style*="min-width: 500px"], [style*="min-width:500px"],
    [style*="min-width: 400px"], [style*="min-width:400px"],
    [style*="min-width: 350px"], [style*="min-width:350px"],
    [style*="min-width: 300px"], [style*="min-width:300px"] {
        min-width: 0 !important;
    }

    /* === TABLAS GLOBAL === */
    /* Cualquier <table> que no esté ya dentro de un wrapper con scroll
       puede romper el viewport. Forzamos display block + overflow */
    table {
        max-width: 100% !important;
        font-size: 12px !important;
    }
    /* Wrapper inline que muchas pantallas usan */
    div[style*="overflow-x"] table,
    .tabla-wrap table,
    .tabla-wrapper table,
    .table-responsive table {
        white-space: nowrap;
    }
    /* Tabla sin wrapper: la convertimos en bloque con scroll propio */
    main > table,
    .contenido > table,
    main > form > table,
    main > div > table:not(.no-mobile-scroll) {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }

    /* === FORMS / INPUTS TOUCH-FRIENDLY === */
    input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
    select, textarea {
        font-size: 16px !important;  /* iOS no hace zoom */
        min-height: 44px !important;
        max-width: 100% !important;
        box-sizing: border-box;
    }
    textarea { min-height: 80px !important; }
    /* Inputs con width inline fijo: que ocupen el ancho */
    input[style*="width:"] , select[style*="width:"], textarea[style*="width:"] {
        width: 100% !important;
    }
    /* Labels en formularios */
    label { display: block; margin-bottom: 4px; }

    /* === BOTONES === */
    button, .btn, a.btn, input[type="submit"], input[type="button"] {
        min-height: 44px !important;
        padding: 10px 16px !important;
        font-size: 14px !important;
        box-sizing: border-box;
    }
    /* Botones agrupados en línea: que envuelvan */
    .btn-group, .acciones, .actions, .toolbar {
        flex-wrap: wrap !important;
        gap: 8px !important;
    }

    /* === TOPBAR CUSTOM (no clase .topbar) === */
    header:not(.topbar) {
        flex-wrap: wrap !important;
    }
    /* H1/H2 grandes inline en cabeceras */
    h1[style*="font-size"], h2[style*="font-size"] {
        font-size: 18px !important;
    }

    /* === MODALES (cualquiera) === */
    .modal, .modal-overlay, [class*="modal-"] {
        max-width: 96vw !important;
    }
    .modal-content, .modal-box, .modal-card {
        width: 96vw !important;
        max-width: 96vw !important;
        margin: 8px auto !important;
    }

    /* === IMAGES === */
    img, video, iframe {
        max-width: 100% !important;
        height: auto;
    }
    /* Excepción: logos de topbar y avatares pequeños */
    .topbar img, .brand-logo img, .avatar img { height: auto; }

    /* === PRE / CODE / blocks que sobresalen === */
    pre, code { white-space: pre-wrap !important; word-break: break-word; }

    /* === GAPS de bloques contigues === */
    /* Algunas pantallas dejan padding/margin gigante inline */
    [style*="padding: 30px"], [style*="padding:30px"],
    [style*="padding: 40px"], [style*="padding:40px"],
    [style*="padding: 50px"], [style*="padding:50px"] {
        padding: 14px !important;
    }
    [style*="padding: 24px"], [style*="padding:24px"] {
        padding: 12px !important;
    }
}

/* Capa móvil pequeño (≤420) sobre cgA144 */
@media (max-width: 420px) {
    /* En móvil pequeño todo a 1 columna, sin excepciones de cgA144 */
    [style*="grid-template-columns"],
    [style*="minmax(120px"], [style*="minmax(130px"], [style*="minmax(140px"], [style*="minmax(150px"],
    [style*="minmax(160px"], [style*="minmax(180px"] {
        grid-template-columns: 1fr !important;
    }
    main, .contenido { padding-left: 8px !important; padding-right: 8px !important; }
    table { font-size: 11px !important; }
    button, .btn { font-size: 13px !important; padding: 10px 12px !important; }
}
