/* ============================================================
   B2BConnect Dashboard Frontend — v4.0
   Shortcode: [b2bconnect_dashboard]
   ============================================================ */

:root {
    --b2bd-primary:    #D9534F;
    --b2bd-primary-hv: #C9302C;
    --b2bd-green:      #5CB85C;
    --b2bd-orange:     #F0AD4E;
    --b2bd-blue:       #5BC0DE;
    --b2bd-red:        #D9534F;
    --b2bd-grey:       #9ca3af;
    --b2bd-bg:         #f4f6f9;
    --b2bd-card-bg:    #ffffff;
    --b2bd-border:     #e5e7eb;
    --b2bd-text:       #1f2937;
    --b2bd-text-soft:  #6b7280;
    --b2bd-radius:     10px;
    --b2bd-shadow:     0 2px 12px rgba(0,0,0,0.07);
    --b2bd-transition: all 0.2s ease;
}

/* ── Contenedor ─────────────────────────────────────────────── */
.b2b-dash-container {
    max-width: 1200px;
    margin: 32px auto;
    padding: 0 16px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--b2bd-text);
}

/* ── Alertas ────────────────────────────────────────────────── */
.b2b-dash-alert {
    padding: 16px 20px;
    border-radius: var(--b2bd-radius);
    margin-bottom: 20px;
    font-size: 14px;
}
.b2b-dash-alert-warning { background: #fffbeb; border: 1px solid #fde68a; color: #78350f; }
.b2b-dash-alert-danger  { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }

/* ── Cabecera ───────────────────────────────────────────────── */
.b2b-dash-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 28px;
    flex-wrap: wrap;
    gap: 16px;
}
.b2b-dash-title {
    margin: 0;
    font-size: 26px;
    font-weight: 700;
    color: var(--b2bd-text);
    letter-spacing: -0.02em;
}
.b2b-dash-subtitle {
    margin: 4px 0 0;
    font-size: 14px;
    color: var(--b2bd-text-soft);
}

/* ── Botones ────────────────────────────────────────────────── */
.b2b-dash-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 10px 22px;
    border-radius: 7px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: var(--b2bd-transition);
    line-height: 1.4;
    text-decoration: none;
}
.b2b-dash-btn-sm { padding: 6px 14px; font-size: 13px; }

.b2b-dash-btn-primary { background: var(--b2bd-primary); color: #fff; box-shadow: 0 2px 8px rgba(217,83,79,0.28); }
.b2b-dash-btn-primary:hover {
    background: var(--b2bd-primary-hv);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(217,83,79,0.35);
}
.b2b-dash-btn-primary:active { transform: translateY(0); }

.b2b-dash-btn-secondary { background: #374151; color: #fff; }
.b2b-dash-btn-secondary:hover { background: #1f2937; color: #fff; }

.b2b-dash-btn-ghost {
    background: transparent;
    color: var(--b2bd-text-soft);
    border: 1.5px solid var(--b2bd-border);
}
.b2b-dash-btn-ghost:hover { background: var(--b2bd-bg); color: var(--b2bd-text); border-color: #d1d5db; }

.b2b-dash-btn-export {
    background: #f0fdf4;
    color: #15803d;
    border: 1.5px solid #bbf7d0;
    font-weight: 600;
}
.b2b-dash-btn-export:hover    { background: #dcfce7; color: #166534; }
.b2b-dash-btn-export:disabled { opacity: 0.6; cursor: not-allowed; }

/* ── Grid de estadísticas — 4 columnas por defecto ──────────── */
.b2b-dash-stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

/* Modificador: 3 columnas (dashboard usa solo 3 stats) */
.b2b-dash-stats-grid.b2b-stats-3 {
    grid-template-columns: repeat(3, 1fr);
}

.b2b-dash-stat-card {
    background: var(--b2bd-card-bg);
    border: 1px solid var(--b2bd-border);
    border-radius: var(--b2bd-radius);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--b2bd-shadow);
    transition: var(--b2bd-transition);
}
.b2b-dash-stat-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,0.09); }

.b2b-dash-stat-icon {
    width: 46px;
    height: 46px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}
.b2b-icon-blue   { background: rgba(91,192,222,0.12);  color: #0284c7; }
.b2b-icon-green  { background: rgba(92,184,92,0.12);   color: #16a34a; }
.b2b-icon-orange { background: rgba(240,173,78,0.12);  color: #d97706; }
.b2b-icon-red    { background: rgba(217,83,79,0.12);   color: var(--b2bd-primary); }

.b2b-dash-stat-body  { display: flex; flex-direction: column; }
.b2b-dash-stat-value { font-size: 28px; font-weight: 800; line-height: 1; color: var(--b2bd-text); letter-spacing: -0.03em; }
.b2b-dash-stat-label { font-size: 12px; color: var(--b2bd-text-soft); margin-top: 4px; }

/* ── Tarjetas ───────────────────────────────────────────────── */
.b2b-dash-card {
    background: var(--b2bd-card-bg);
    border: 1px solid var(--b2bd-border);
    border-radius: var(--b2bd-radius);
    padding: 24px;
    box-shadow: var(--b2bd-shadow);
    margin-bottom: 24px;
}
.b2b-dash-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--b2bd-border);
    flex-wrap: wrap;
    gap: 8px;
}
.b2b-dash-card-title    { margin: 0; font-size: 16px; font-weight: 700; color: var(--b2bd-text); }
.b2b-dash-card-subtitle { font-size: 13px; color: var(--b2bd-text-soft); }

.b2b-dash-live-badge {
    font-size: 11px;
    color: var(--b2bd-green);
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 5px;
    animation: b2b-pulse 2.4s ease-in-out infinite;
}
@keyframes b2b-pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.45; }
}

/* ── Filtro por usuario (admin+) ────────────────────────────── */
.b2b-user-filter-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    padding: 10px 14px;
    background: #f8f9ff;
    border: 1px solid #e0e4f5;
    border-radius: 8px;
    flex-wrap: wrap;
}
.b2b-user-filter-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--b2bd-text-soft);
    white-space: nowrap;
    flex-shrink: 0;
}
.b2b-user-select {
    flex: 1 1 200px;
    min-width: 160px;
    max-width: 340px !important;
    height: 34px;
    padding: 5px 10px;
    border: 1.5px solid var(--b2bd-border);
    border-radius: 6px;
    font-size: 13px;
    color: var(--b2bd-text);
    background: #fff;
    cursor: pointer;
    transition: border-color 0.15s;
}
.b2b-user-select:focus {
    outline: none;
    border-color: var(--b2bd-primary);
    box-shadow: 0 0 0 3px rgba(217,83,79,0.1);
}

/* ── Selector de registros por página ───────────────────────── */
.b2b-perpage-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}
.b2b-perpage-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--b2bd-text-soft);
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.b2b-perpage-btns {
    display: flex;
    gap: 4px;
}
.b2b-perpage-btn {
    min-width: 38px;
    height: 28px;
    padding: 0 8px;
    border: 1.5px solid var(--b2bd-border);
    border-radius: 5px;
    background: #fff;
    font-size: 12px;
    font-weight: 600;
    color: var(--b2bd-text-soft);
    cursor: pointer;
    transition: var(--b2bd-transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.b2b-perpage-btn:hover {
    border-color: var(--b2bd-primary);
    color: var(--b2bd-primary);
    background: #fff5f5;
}
.b2b-perpage-btn.b2b-perpage-active {
    background: var(--b2bd-primary);
    color: #fff;
    border-color: var(--b2bd-primary);
    box-shadow: 0 2px 6px rgba(217,83,79,0.3);
}

/* ── Tabs ───────────────────────────────────────────────────── */
.b2b-dash-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--b2bd-border);
    margin-bottom: 16px;
}
.b2b-dash-tab {
    padding: 9px 22px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    font-size: 13px;
    font-weight: 500;
    color: var(--b2bd-text-soft);
    cursor: pointer;
    transition: var(--b2bd-transition);
    position: relative;
}
.b2b-dash-tab:hover { color: var(--b2bd-text); }
.b2b-dash-tab-active {
    color: var(--b2bd-primary);
    border-bottom-color: var(--b2bd-primary);
    font-weight: 700;
}

/* ── Filtros ────────────────────────────────────────────────── */
.b2b-dash-filters { margin-bottom: 14px; }
.b2b-dash-filters-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
}
.b2b-dash-filter-input {
    padding: 7px 10px;
    border: 1.5px solid var(--b2bd-border);
    border-radius: 6px;
    font-size: 13px;
    color: var(--b2bd-text);
    background: #fff;
    height: 34px;
    box-sizing: border-box;
    flex: 1 1 130px;
    min-width: 90px;
    max-width: 190px;
    transition: border-color 0.15s;
}
.b2b-dash-filter-input:focus {
    outline: none;
    border-color: var(--b2bd-primary);
    box-shadow: 0 0 0 3px rgba(217,83,79,0.1);
}
.b2b-dash-export-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* ── Panel scrollable solicitudes / líneas ──────────────────── */
.b2b-dash-requests-scroll {
    max-height: 520px;
    overflow-y: auto;
    padding-right: 6px;
    scroll-behavior: smooth;
}
.b2b-dash-requests-scroll::-webkit-scrollbar       { width: 5px; }
.b2b-dash-requests-scroll::-webkit-scrollbar-track { background: #f3f4f6; border-radius: 3px; }
.b2b-dash-requests-scroll::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }
.b2b-dash-requests-scroll::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* ── Filas de solicitudes / líneas ──────────────────────────── */
.b2b-req-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    background: var(--b2bd-bg);
    border-radius: 8px;
    border-left: 4px solid transparent;
    margin-bottom: 8px;
    transition: var(--b2bd-transition);
    flex-wrap: nowrap;
    gap: 12px;
    position: relative;
}

/* Color de borde izquierdo por estado */
.b2b-req-item.b2b-status-orange { border-left-color: #F0AD4E; }
.b2b-req-item.b2b-status-green  { border-left-color: #5CB85C; }
.b2b-req-item.b2b-status-red    { border-left-color: #D9534F; }
.b2b-req-item.b2b-status-grey   { border-left-color: #9ca3af; }

/* Tarjetas de línea: borde azul fijo */
.b2b-line-card { border-left-color: #5BC0DE; }

.b2b-req-clickable { cursor: pointer; }
.b2b-req-clickable:hover {
    background: #fff;
    box-shadow: 0 4px 14px rgba(0,0,0,0.08);
    transform: translateX(3px);
}
.b2b-req-clickable:focus {
    outline: 2px solid var(--b2bd-primary);
    outline-offset: 2px;
}

.b2b-req-left  { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; }
.b2b-req-right { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; flex-shrink: 0; }

/* Lado derecho específico de líneas: un poco más ancho para acomodar consumo + botón */
.b2b-line-right {
    min-width: 110px;
    align-items: flex-end;
}

.b2b-req-line   { font-weight: 700; font-size: 15px; font-family: 'Courier New', monospace; color: var(--b2bd-text); }
.b2b-req-tipo   { font-size: 12px; color: var(--b2bd-text-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.b2b-req-tariff { font-size: 12px; color: #0284c7; font-weight: 600; }
.b2b-req-fecha  { font-size: 11px; color: var(--b2bd-text-soft); white-space: nowrap; }

/* Chevron de "clic para ver" */
.b2b-req-chevron {
    font-size: 20px;
    color: #d1d5db;
    flex-shrink: 0;
    transition: var(--b2bd-transition);
    margin-left: 4px;
    line-height: 1;
}
.b2b-req-clickable:hover .b2b-req-chevron { color: var(--b2bd-primary); transform: translateX(2px); }

/* ── Metadata de línea (ICCID · PIN · PUK inline) ───────────── */
.b2b-line-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    margin-top: 2px;
}
.b2b-line-meta-item {
    font-size: 11px;
    color: var(--b2bd-text-soft);
    display: inline-flex;
    align-items: center;
    gap: 3px;
}
.b2b-line-meta-item strong {
    color: var(--b2bd-text);
    font-weight: 600;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.b2b-line-meta-sep {
    color: #d1d5db;
    font-size: 12px;
    line-height: 1;
}

/* Texto monoespaciado compacto para datos inline */
.b2b-mono-sm {
    font-family: 'Courier New', monospace;
    font-size: 11px;
    letter-spacing: 0.02em;
    color: #374151;
}

/* ── Badges de estado ───────────────────────────────────────── */
.b2b-req-badge, .b2b-dash-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
    letter-spacing: 0.01em;
}
.b2b-badge-green  { background: rgba(92,184,92,0.12);   color: #15803d; }
.b2b-badge-orange { background: rgba(240,173,78,0.12);  color: #b45309; }
.b2b-badge-red    { background: rgba(217,83,79,0.12);   color: #b91c1c; }
.b2b-badge-blue   { background: rgba(91,192,222,0.12);  color: #0284c7; }
.b2b-badge-grey   { background: rgba(156,163,175,0.12); color: #4b5563; }

/* ── Empty state ────────────────────────────────────────────── */
.b2b-empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--b2bd-text-soft);
}
.b2b-empty-icon {
    font-size: 42px;
    margin-bottom: 12px;
    opacity: 0.5;
}
.b2b-empty-state p {
    font-size: 14px;
    margin: 0;
    line-height: 1.5;
}

/* ── Paginación ─────────────────────────────────────────────── */
.b2b-dash-pagination { padding: 14px 0 4px; }
.b2b-dash-pages {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}
.b2b-page-btn {
    min-width: 34px;
    height: 34px;
    padding: 0 10px;
    border: 1.5px solid var(--b2bd-border);
    border-radius: 6px;
    background: #fff;
    font-size: 13px;
    cursor: pointer;
    color: var(--b2bd-text);
    transition: var(--b2bd-transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.b2b-page-btn:hover   { border-color: var(--b2bd-primary); color: var(--b2bd-primary); }
.b2b-page-active      { background: var(--b2bd-primary) !important; color: #fff !important; border-color: var(--b2bd-primary) !important; font-weight: 700; }
.b2b-page-dots        { font-size: 13px; color: var(--b2bd-text-soft); padding: 0 2px; }

/* ── Spinner / Loading ──────────────────────────────────────── */
.b2b-dash-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 28px;
    color: var(--b2bd-text-soft);
    font-size: 14px;
}
.b2b-dash-spinner {
    width: 22px;
    height: 22px;
    border: 3px solid var(--b2bd-border);
    border-top-color: var(--b2bd-primary);
    border-radius: 50%;
    animation: b2b-spin 0.65s linear infinite;
    flex-shrink: 0;
}
.b2b-spinner-sm {
    width: 14px !important;
    height: 14px !important;
    border-width: 2px !important;
    display: inline-block;
}
@keyframes b2b-spin { to { transform: rotate(360deg); } }

/* ── Columna de consumo ─────────────────────────────────────── */
.b2b-consumo-val {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: rgba(91,192,222,0.12);
    color: #0284c7;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 10px;
    border-radius: 12px;
    white-space: nowrap;
    border: 1px solid rgba(91,192,222,0.25);
    transition: all 0.2s;
}
/* < 60% — teal (default, sin clase extra) */
.b2b-consumo-val.b2b-consumo-ok {
    background: rgba(20,184,166,0.12);
    color: #0f766e;
    border-color: rgba(20,184,166,0.30);
}
/* 60–90% — naranja */
.b2b-consumo-val.b2b-consumo-alerta {
    background: rgba(245,158,11,0.12);
    color: #b45309;
    border-color: rgba(245,158,11,0.30);
}
/* > 90% — rojo */
.b2b-consumo-val.b2b-consumo-critico {
    background: rgba(220,38,38,0.12);
    color: #b91c1c;
    border-color: rgba(220,38,38,0.25);
}
.b2b-consumo-pct {
    font-weight: 500;
    opacity: 0.80;
}
.b2b-consumo-empty {
    color: var(--b2bd-text-soft);
    font-size: 11px;
    font-style: italic;
}

/* ── Botón "Actualizar consumo" ─────────────────────────────── */
.b2b-btn-consumo {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: #f0fdf4;
    color: #15803d;
    border: 1.5px solid #bbf7d0;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--b2bd-transition);
    white-space: nowrap;
    line-height: 1.4;
}
.b2b-btn-consumo:hover {
    background: #dcfce7;
    color: #166534;
    border-color: #86efac;
    transform: translateY(-1px);
}
.b2b-btn-consumo:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* ── Modales ────────────────────────────────────────────────── */
.b2b-modal-content {
    border-radius: var(--b2bd-radius);
    overflow: hidden;
    border: none;
    box-shadow: 0 24px 64px rgba(0,0,0,0.18);
}
.b2b-modal-header {
    background: linear-gradient(135deg, var(--b2bd-primary) 0%, var(--b2bd-primary-hv) 100%);
    color: #fff;
    padding: 16px 22px;
    border-bottom: none;
}
.b2b-modal-header .modal-title { font-size: 16px; font-weight: 700; }
.b2b-modal-body { padding: 24px; background: #fff; }

/* ── Detail list ────────────────────────────────────────────── */
.b2b-detail-list {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 11px 18px;
    margin: 0;
    font-size: 14px;
}
.b2b-detail-list dt {
    font-weight: 700;
    color: var(--b2bd-text-soft);
    white-space: nowrap;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding-top: 2px;
}
.b2b-detail-list dd {
    margin: 0;
    color: var(--b2bd-text);
    word-break: break-word;
}

/* Datos sensibles en el detalle (PIN, PUK) */
.b2b-detail-sensitive {
    background: #f3f4f6;
    padding: 2px 8px;
    border-radius: 5px;
    letter-spacing: 0.08em;
    font-size: 13px;
    display: inline-block;
}

/* Comentarios del admin */
.b2b-detail-comment {
    background: #fffbeb;
    border-left: 3px solid #fde68a;
    padding: 6px 10px;
    border-radius: 0 5px 5px 0;
    font-size: 13px;
    color: #78350f;
    line-height: 1.5;
    display: block;
}

/* ── Misc ───────────────────────────────────────────────────── */
.b2b-mono        { font-family: 'Courier New', monospace; letter-spacing: 0.03em; }
.b2b-text-danger { color: #b91c1c; font-size: 14px; text-align: center; padding: 20px 0; margin: 0; }

.b2b-dash-empty-msg {
    text-align: center;
    color: var(--b2bd-text-soft);
    font-size: 14px;
    padding: 28px 0;
    margin: 0;
}
.b2b-dash-filter-empty {
    font-size: 13px;
    text-align: center;
    color: var(--b2bd-text-soft);
    padding: 16px 0;
    margin: 0;
}

/* ── Animación fade polling ─────────────────────────────────── */
.b2b-fade-out { opacity: 0; transition: opacity 0.2s ease; }

/* ════════════════════════════════════════════════════════════
   MEJORAS GLOBALES — TOUCH & ACCESIBILIDAD
   (Sin media query: aplican en todos los breakpoints)
   ════════════════════════════════════════════════════════════ */

/* Elimina el retraso 300ms y el highlight azul en iOS/Android */
.b2b-dash-btn,
.b2b-perpage-btn,
.b2b-page-btn,
.b2b-dash-tab,
.b2b-btn-consumo,
.b2b-req-clickable,
.b2b-dash-filter-input,
.b2b-user-select {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* Tabs: scroll horizontal sin scrollbar visible */
.b2b-dash-tabs {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.b2b-dash-tabs::-webkit-scrollbar { display: none; }

/* ════════════════════════════════════════════════════════════
   RESPONSIVE — BREAKPOINTS
   ════════════════════════════════════════════════════════════ */

/* ── Tablet grande (≤ 1024px) ───────────────────────────── */
@media (max-width: 1024px) {
    .b2b-dash-container { margin: 24px auto; }
    .b2b-dash-title     { font-size: 22px; }
}

/* ── Tablet (≤ 900px) ───────────────────────────────────── */
@media (max-width: 900px) {
    .b2b-dash-stats-grid             { grid-template-columns: repeat(3, 1fr); }
    .b2b-dash-stats-grid.b2b-stats-3 { grid-template-columns: repeat(3, 1fr); }
    .b2b-dash-card                   { padding: 18px; }
}

/* ── Tablet pequeña / landscape (≤ 768px) ───────────────── */
@media (max-width: 768px) {
    .b2b-dash-container { margin: 16px auto; padding: 0 12px; }
    .b2b-dash-title     { font-size: 20px; }
    .b2b-dash-stat-value { font-size: 24px; }

    .b2b-dash-stats-grid,
    .b2b-dash-stats-grid.b2b-stats-3 { grid-template-columns: repeat(3, 1fr); gap: 10px; }
    .b2b-dash-stat-card  { padding: 14px 12px; gap: 10px; }
    .b2b-dash-stat-icon  { width: 38px; height: 38px; font-size: 16px; }

    .b2b-dash-card               { padding: 16px; }
    .b2b-dash-requests-scroll    { max-height: 420px; }

    .b2b-user-filter-row         { padding: 8px 12px; }
    .b2b-user-select             { max-width: 100% !important; }

    /* Filtros: grid 2 columnas en tablet */
    .b2b-dash-filters-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        align-items: end;
    }
    .b2b-dash-filter-input { max-width: 100%; width: 100%; min-height: 40px; }

    /* Targets táctiles mínimos 40px */
    .b2b-perpage-btn { min-width: 40px; height: 40px; }
    .b2b-page-btn    { min-width: 40px; height: 40px; }

    .b2b-dash-tab  { padding: 8px 14px; font-size: 12px; }
    .b2b-req-item  { padding: 10px 12px; gap: 8px; }
    .b2b-req-line  { font-size: 14px; }

    /* Modal nueva solicitud: casi pantalla completa en tablet */
    #modalNuevaSolicitud .modal-dialog { max-width: 95vw; margin: 8px auto; }
}

/* ── Móvil (≤ 600px) ────────────────────────────────────── */
@media (max-width: 600px) {
    .b2b-dash-container { margin: 12px auto; padding: 0 10px; }

    /* ── Cabecera ── */
    .b2b-dash-header { flex-direction: column; align-items: stretch; gap: 12px; }
    .b2b-dash-header .b2b-dash-btn {
        width: 100%;
        justify-content: center;
        padding: 14px 22px;
        font-size: 15px;
        letter-spacing: 0.02em;
    }

    /* ── Stats: 2 columnas; el 3.º se expande ── */
    .b2b-dash-stats-grid,
    .b2b-dash-stats-grid.b2b-stats-3 { grid-template-columns: 1fr 1fr; gap: 8px; }
    .b2b-dash-stats-grid.b2b-stats-3 .b2b-dash-stat-card:last-child { grid-column: span 2; }
    .b2b-dash-stat-card  { padding: 12px 10px; gap: 10px; }
    .b2b-dash-stat-value { font-size: 22px; }
    .b2b-dash-stat-label { font-size: 11px; }
    .b2b-dash-stat-icon  { width: 34px; height: 34px; font-size: 14px; border-radius: 8px; }

    /* ── Cards ── */
    .b2b-dash-card        { padding: 14px 12px; margin-bottom: 16px; }
    .b2b-dash-card-header { margin-bottom: 12px; padding-bottom: 10px; }
    .b2b-dash-card-title  { font-size: 15px; }

    /* ── Filtro usuario ── */
    .b2b-user-filter-row { flex-direction: column; align-items: flex-start; gap: 6px; }
    .b2b-user-select     { width: 100%; max-width: 100% !important; min-height: 44px; }

    /* ── Per-page ── */
    .b2b-perpage-row   { gap: 8px; flex-wrap: wrap; }
    .b2b-perpage-label { flex-basis: 100%; }          /* etiqueta en su propia fila */
    .b2b-perpage-btn   { min-width: 46px; height: 46px; font-size: 13px; border-radius: 8px; }

    /* ── Tabs ── */
    .b2b-dash-tabs { overflow-x: auto; }
    .b2b-dash-tab  { padding: 9px 18px; font-size: 12px; white-space: nowrap; flex-shrink: 0; }

    /* ── Filtros: columna única ── */
    .b2b-dash-filters-row { display: flex; flex-direction: column; gap: 8px; }
    .b2b-dash-filter-input {
        max-width: 100%;
        width: 100%;
        min-height: 44px;
        font-size: 16px;   /* CRÍTICO: evita zoom automático en iOS Safari */
        box-sizing: border-box;
    }
    .b2b-dash-filters-row .b2b-dash-btn {
        width: 100%;
        justify-content: center;
        min-height: 44px;
    }

    /* ── Export buttons: iguales en ancho ── */
    .b2b-dash-export-row                  { gap: 8px; }
    .b2b-dash-export-row .b2b-dash-btn    { flex: 1; justify-content: center; }

    /* ── Scroll panels ── */
    .b2b-dash-requests-scroll { max-height: 360px; padding-right: 2px; }

    /* ── Items de solicitudes / líneas ── */
    .b2b-req-item  { flex-wrap: wrap; padding: 10px; gap: 8px; }
    .b2b-req-left  { flex: 1 1 100%; min-width: 0; }   /* ocupa fila completa primero */
    .b2b-req-right { width: 100%; flex-direction: row; align-items: center; justify-content: space-between; gap: 8px; }
    .b2b-line-right { min-width: unset; flex-direction: row; align-items: center; justify-content: space-between; gap: 8px; }
    .b2b-req-chevron { display: none; }

    /* ICCID / PIN / PUK: fuente reducida para evitar overflow */
    .b2b-mono-sm { font-size: 10px; letter-spacing: 0; }

    /* Metadata de línea: columna */
    .b2b-line-meta     { flex-direction: column; gap: 3px; align-items: flex-start; }
    .b2b-line-meta-sep { display: none; }

    /* ── Paginación ── */
    .b2b-dash-pages { gap: 4px; }
    .b2b-page-btn   { min-width: 36px; height: 36px; font-size: 12px; }

    /* ── Modales: bottom-sheet ── */
    #modalNuevaSolicitud .modal-dialog,
    #modalRequestDetail  .modal-dialog,
    #modalLineDetail     .modal-dialog {
        max-width: 100%;
        margin: 0;
        min-height: 100dvh;
        align-items: flex-end;
    }
    #modalNuevaSolicitud .modal-content,
    #modalRequestDetail  .modal-content,
    #modalLineDetail     .modal-content {
        border-radius: var(--b2bd-radius) var(--b2bd-radius) 0 0;
        max-height: 92dvh;
        overflow-y: auto;
    }
    /* Handle bar visible (dentro del header degradado) */
    .b2b-modal-header {
        position: relative;
        padding-top: 28px;    /* espacio para la barra */
    }
    .b2b-modal-header::before {
        content: '';
        position: absolute;
        top: 10px;
        left: 50%;
        transform: translateX(-50%);
        width: 36px;
        height: 4px;
        background: rgba(255, 255, 255, 0.42);
        border-radius: 2px;
    }

    /* ── Detail list: columna única ── */
    .b2b-detail-list                    { grid-template-columns: 1fr; gap: 4px 0; }
    .b2b-detail-list dt                 { margin-top: 12px; }
    .b2b-detail-list dt:first-child     { margin-top: 0; }
}

/* ── Móvil pequeño (≤ 480px) ─────────────────────────── */
@media (max-width: 480px) {
    .b2b-dash-container { padding: 0 8px; margin: 8px auto; }
    .b2b-dash-title     { font-size: 18px; }
    .b2b-dash-subtitle  { font-size: 12px; }

    /* Stats: columna única con layout horizontal por tarjeta */
    .b2b-dash-stats-grid,
    .b2b-dash-stats-grid.b2b-stats-3 { grid-template-columns: 1fr; gap: 6px; }
    .b2b-dash-stats-grid.b2b-stats-3 .b2b-dash-stat-card:last-child { grid-column: span 1; }
    .b2b-dash-stat-card  { flex-direction: row; padding: 14px 16px; gap: 14px; }
    .b2b-dash-stat-value { font-size: 26px; }
    .b2b-dash-stat-label { font-size: 12px; }
    .b2b-dash-stat-icon  { width: 42px; height: 42px; font-size: 18px; border-radius: 10px; flex-shrink: 0; }

    .b2b-dash-card            { padding: 12px 10px; }
    .b2b-dash-requests-scroll { max-height: 300px; }

    /* Per-page ligeramente más pequeño */
    .b2b-perpage-btn { min-width: 42px; height: 42px; }

    /* Consumo badge más compacto */
    .b2b-consumo-val { font-size: 12px; padding: 3px 8px; }
    .b2b-btn-consumo { font-size: 11px; padding: 5px 10px; }
}

/* ── Móvil muy pequeño (≤ 380px) ────────────────────── */
@media (max-width: 380px) {
    .b2b-dash-title   { font-size: 16px; }
    .b2b-perpage-btns { flex-wrap: wrap; }
    .b2b-perpage-btn  { min-width: 40px; height: 40px; }
    .b2b-dash-stat-value { font-size: 24px; }
}

/* ── Landscape en móvil (pantalla alta → pantalla ancha) ─ */
@media (max-height: 500px) and (orientation: landscape) {
    /* Stats: 3 columnas para aprovechar el ancho */
    .b2b-dash-stats-grid,
    .b2b-dash-stats-grid.b2b-stats-3 { grid-template-columns: repeat(3, 1fr); gap: 8px; }
    .b2b-dash-stats-grid.b2b-stats-3 .b2b-dash-stat-card:last-child { grid-column: span 1; }
    .b2b-dash-stat-card  { flex-direction: row; padding: 10px 12px; gap: 10px; }
    .b2b-dash-stat-icon  { width: 30px; height: 30px; font-size: 13px; }
    .b2b-dash-stat-value { font-size: 20px; }

    /* Scroll reducido */
    .b2b-dash-requests-scroll { max-height: 200px; }

    /* Modales: centrados en landscape (no bottom-sheet) */
    #modalNuevaSolicitud .modal-dialog,
    #modalRequestDetail  .modal-dialog,
    #modalLineDetail     .modal-dialog { min-height: unset; align-items: center; margin: 12px auto; max-width: 90vw; }
    #modalNuevaSolicitud .modal-content,
    #modalRequestDetail  .modal-content,
    #modalLineDetail     .modal-content { border-radius: var(--b2bd-radius); max-height: 85dvh; }

    /* Ocultar handle bar en landscape */
    .b2b-modal-header          { padding-top: 16px; }
    .b2b-modal-header::before  { display: none; }
}

/* ── Safe-area (iPhone Dynamic Island / home bar) ──────── */
@supports (padding: env(safe-area-inset-bottom)) {
    .b2b-dash-container {
        padding-left:  max(10px, env(safe-area-inset-left));
        padding-right: max(10px, env(safe-area-inset-right));
    }

    @media (max-width: 600px) {
        .b2b-dash-container {
            padding-bottom: env(safe-area-inset-bottom);
        }
        /* El body del modal recibe el safe-area para que el contenido no quede tapado */
        #modalNuevaSolicitud .modal-body,
        #modalRequestDetail  .modal-body,
        #modalLineDetail     .modal-body {
            padding-bottom: calc(24px + env(safe-area-inset-bottom));
        }
    }
}

/* ── Select2: prevenir zoom automático en iOS (font-size < 16px) ── */
@media (max-width: 768px) {
    .select2-container .select2-selection--single { min-height: 40px; }
    .select2-container .select2-selection__rendered { line-height: 38px; font-size: 16px !important; }
    .select2-container .select2-search__field      { font-size: 16px !important; }
    .select2-container .select2-selection__arrow   { height: 38px; }
}

/* ── Formulario dentro del modal: eliminar padding redundante ── */
@media (max-width: 600px) {
    .b2b-modal-body .b2bconnect-frontend-form { padding: 0; }
    .b2b-modal-body .b2bconnect-frontend-form .b2b-form-header { display: none; }

    /* Scroll suave en modal body */
    .b2b-modal-body { -webkit-overflow-scrolling: touch; }

    /* Botón "Enviar" del form: ancho completo en móvil */
    .b2b-modal-body .b2bconnect-frontend-form .btn-primary,
    .b2b-modal-body .b2bconnect-frontend-form [type="submit"] {
        width: 100%;
    }
}
