/* ============================================================
   B2BConnect Dashboard Frontend — v3.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 ───────────────────────────────────── */
.b2b-dash-stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}
.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; }
}

/* ── 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 ───────────────────────────── */
.b2b-dash-requests-scroll {
    max-height: 500px;
    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 ───────────────────────────────────── */
.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; }

.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; }

.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); }

/* ── 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); } }

/* .b2b-dash-bottom-grid — eliminado; líneas y gráfico son ahora tarjetas full-width independientes */
/* Las tarjetas de líneas y gráfico ya tienen margin-bottom via .b2b-dash-card */

/* ── Filtros de líneas ──────────────────────────────────────── */
.b2b-dash-line-filters {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.b2b-dash-line-filters .b2b-dash-filter-input { max-width: none; flex: 1 1 110px; }

/* ── Tabla de líneas ────────────────────────────────────────── */
.b2b-dash-table-wrap { overflow-x: auto; }
.b2b-dash-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.b2b-dash-table th {
    text-align: left;
    padding: 9px 12px;
    font-size: 11px;
    font-weight: 700;
    color: var(--b2bd-text-soft);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 2px solid var(--b2bd-border);
    background: var(--b2bd-bg);
    white-space: nowrap;
}
.b2b-dash-table td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--b2bd-border);
    vertical-align: middle;
}
.b2b-dash-table tr:last-child td { border-bottom: none; }
.b2b-dash-table tr.b2b-line-row {
    cursor: pointer;
    transition: var(--b2bd-transition);
}
.b2b-dash-table tr.b2b-line-row:hover td {
    background: #fef2f2;
}
.b2b-dash-table tr.b2b-line-row:hover .b2b-dash-line-number { color: var(--b2bd-primary); }

.b2b-dash-line-number { font-weight: 700; font-family: 'Courier New', monospace; font-size: 14px; }
.b2b-dash-iccid       { font-family: 'Courier New', monospace; font-size: 11px; color: var(--b2bd-text-soft); }
.b2b-dash-pin-puk     { font-family: 'Courier New', monospace; font-size: 12px; color: #374151; letter-spacing: 0.04em; }
.b2b-dash-filter-empty { font-size: 13px; text-align: center; color: var(--b2bd-text-soft); padding: 16px 0; margin: 0; }

/* ── Columna de consumo ─────────────────────────────────────── */
.b2b-dash-consumo-cell { white-space: nowrap; }
.b2b-consumo-val {
    display: inline-block;
    background: rgba(91,192,222,0.10);
    color: #0284c7;
    font-size: 12px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 12px;
    white-space: nowrap;
}
.b2b-consumo-empty { color: var(--b2bd-text-soft); font-size: 13px; }

/* ── Botón "Actualizar consumo" ─────────────────────────────── */
.b2b-dash-btn-consumo-cell { white-space: nowrap; }
.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: 12px;
    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;
}

/* ── 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;
}

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

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 900px) {
    .b2b-dash-stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
    .b2b-dash-stats-grid      { grid-template-columns: 1fr 1fr; }
    .b2b-dash-header          { flex-direction: column; align-items: flex-start; }
    .b2b-dash-stat-value      { font-size: 22px; }
    .b2b-dash-filters-row     { flex-direction: column; }
    .b2b-dash-filter-input    { max-width: 100%; }
    .b2b-dash-requests-scroll { max-height: 380px; }
    .b2b-detail-list          { grid-template-columns: 1fr; gap: 6px 0; }
    .b2b-detail-list dt       { margin-top: 10px; }
    .b2b-req-item             { flex-wrap: wrap; }
    .b2b-req-chevron          { display: none; }
}
