/* Tablero de gestión. Dos temas (claro / oscuro) definidos solo con variables: para ajustar colores se toca únicamente este bloque. */

article.content:has(> .tb) { padding: 0 !important; }

.tb {
    --tb-bg: #f3f7fa;
    --tb-panel: #ffffff;
    --tb-panel-2: #f7fafc;
    --tb-bd: #d9e4ec;
    --tb-tx: #18364f;
    --tb-mu: #63788a;
    --tb-ac: #176da8;   --tb-ac-s: #e3eef7;
    --tb-ok: #1a7f5a;   --tb-ok-s: #e2f3ec;
    --tb-wa: #b54708;   --tb-wa-s: #fdf0e3;
    --tb-rd: #b42318;   --tb-rd-s: #fdeceb;
    --tb-gr: #63788a;   --tb-gr-s: #eef2f5;
    --tb-radius: 12px;
    --tb-hover: rgba(23, 109, 168, .06);
    --tb-skel: #e8eef3;

    background: var(--tb-bg);
    color: var(--tb-tx);
    min-height: calc(100vh - 3.5rem);
    padding: 1.25rem 1.5rem 2.5rem;
    font-size: 14px;
}

html[data-tablero-tema="oscuro"] .tb {
    --tb-bg: #0f1720;
    --tb-panel: #16212d;
    --tb-panel-2: #121b25;
    --tb-bd: #243445;
    --tb-tx: #e6edf3;
    --tb-mu: #8da2b5;
    --tb-ac: #4da3e6;   --tb-ac-s: #173a57;
    --tb-ok: #3fb98a;   --tb-ok-s: #14392e;
    --tb-wa: #e8a03c;   --tb-wa-s: #40300f;
    --tb-rd: #f06a62;   --tb-rd-s: #4a1d1b;
    --tb-gr: #8da2b5;   --tb-gr-s: #1d2b3a;
    --tb-radius: 8px;
    --tb-hover: rgba(255, 255, 255, .05);
    --tb-skel: #1d2b3a;
}

.tb * { box-sizing: border-box; }
.tb a { color: var(--tb-ac); text-decoration: none; }
.tb a:hover { text-decoration: underline; }

/* ── Encabezado ── */
.tb-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.tb-title { font-size: 1.35rem; font-weight: 600; margin: 0; letter-spacing: -.01em; }
.tb-sub { color: var(--tb-mu); font-size: 12px; }
.tb-tools { display: flex; align-items: center; gap: 8px; }

.tb-btn {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--tb-panel); color: var(--tb-tx); border: 1px solid var(--tb-bd);
    border-radius: calc(var(--tb-radius) - 2px); padding: 5px 10px; font-size: 13px; cursor: pointer; line-height: 1.2;
}
.tb-btn:hover { background: var(--tb-hover); border-color: var(--tb-mu); }
.tb-btn.tb-primary { background: var(--tb-ac); color: #fff; border-color: var(--tb-ac); }
.tb-btn.tb-danger { color: var(--tb-rd); }

.tb-seg { display: inline-flex; border: 1px solid var(--tb-bd); border-radius: calc(var(--tb-radius) - 2px); overflow: hidden; background: var(--tb-panel); }
.tb-seg button { border: 0; background: transparent; color: var(--tb-mu); padding: 5px 10px; font-size: 13px; cursor: pointer; display: inline-flex; gap: 5px; align-items: center; }
.tb-seg button.on { background: var(--tb-ac-s); color: var(--tb-ac); font-weight: 600; }

/* ── Resumen ── */
.tb-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.tb-kpi {
    background: var(--tb-panel); border: 1px solid var(--tb-bd); border-radius: var(--tb-radius);
    padding: 10px 12px; text-align: left; cursor: pointer; display: block; width: 100%; color: inherit;
}
.tb-kpi:hover { border-color: var(--tb-mu); }
.tb-kpi-l { color: var(--tb-mu); font-size: 12px; display: flex; gap: 6px; align-items: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-kpi-n { font-size: 1.7rem; font-weight: 600; line-height: 1.15; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tb-kpi.c-ac .tb-kpi-n { color: var(--tb-ac); }
.tb-kpi.c-ok .tb-kpi-n { color: var(--tb-ok); }
.tb-kpi.c-wa .tb-kpi-n { color: var(--tb-wa); }
.tb-kpi.c-rd .tb-kpi-n { color: var(--tb-rd); }
.tb-kpi.c-cero .tb-kpi-n { color: var(--tb-mu); font-weight: 500; }

/* ── Tarjetas ── */
.tb-grid { display: grid; gap: 12px; margin-bottom: 12px; }
.tb-grid.dos { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tb-grid.tres { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tb-card { background: var(--tb-panel); border: 1px solid var(--tb-bd); border-radius: var(--tb-radius); padding: 12px 14px; min-width: 0; }
.tb-card-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.tb-card-t { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 7px; min-width: 0; }
.tb-card-t i { color: var(--tb-ac); font-size: 17px; }
.tb-badge { font-size: 11px; padding: 1px 8px; border-radius: 99px; background: var(--tb-ac-s); color: var(--tb-ac); font-weight: 600; white-space: nowrap; }
.tb-badge.c-rd { background: var(--tb-rd-s); color: var(--tb-rd); }
.tb-badge.c-wa { background: var(--tb-wa-s); color: var(--tb-wa); }
.tb-badge.c-ok { background: var(--tb-ok-s); color: var(--tb-ok); }
.tb-badge.c-gr { background: var(--tb-gr-s); color: var(--tb-gr); }
.tb-badge.c-ac { background: var(--tb-ac-s); color: var(--tb-ac); }

/* ── Filas ── */
.tb-row { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--tb-bd); min-width: 0; }
.tb-row:first-of-type { border-top: 0; }
.tb-av { width: 28px; height: 28px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; background: var(--tb-ac-s); color: var(--tb-ac); }
.tb-av.c-rd { background: var(--tb-rd-s); color: var(--tb-rd); }
.tb-av.c-wa { background: var(--tb-wa-s); color: var(--tb-wa); }
.tb-av.c-ok { background: var(--tb-ok-s); color: var(--tb-ok); }
.tb-av.c-gr { background: var(--tb-gr-s); color: var(--tb-gr); }
.tb-rb { min-width: 0; flex: 1; }
.tb-r1 { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-r2 { font-size: 12px; color: var(--tb-mu); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-rt { font-size: 11px; color: var(--tb-mu); flex: none; white-space: nowrap; }
.tb-row a.tb-r1 { color: var(--tb-tx); }
.tb-row:hover { background: var(--tb-hover); }

.tb-empty { color: var(--tb-mu); font-size: 13px; padding: 10px 0; display: flex; gap: 8px; align-items: center; }
.tb-warn { color: var(--tb-wa); font-size: 12px; margin: 4px 0; }
.tb-err { color: var(--tb-rd); font-size: 12px; margin: 4px 0; }
.tb-note { color: var(--tb-mu); font-size: 12px; background: var(--tb-panel-2); border: 1px dashed var(--tb-bd); border-radius: calc(var(--tb-radius) - 2px); padding: 8px 10px; margin-top: 8px; }

/* ── Temas de correo ── */
.tb-temas { display: flex; flex-direction: column; gap: 6px; }
.tb-tema { padding: 4px 0; min-width: 0; }
.tb-tema-h { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
.tb-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--tb-ac); flex: none; }
.tb-dot.c-rd { background: var(--tb-rd); } .tb-dot.c-wa { background: var(--tb-wa); } .tb-dot.c-ok { background: var(--tb-ok); } .tb-dot.c-gr { background: var(--tb-gr); }
.tb-tema-n { font-weight: 600; font-size: 13px; }
.tb-cuenta { color: var(--tb-mu); font-size: 12px; margin: 2px 0 6px; }

/* ── Cifras de pagos ── */
.tb-cifras { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 4px 0 8px; }
.tb-cifra { background: var(--tb-panel-2); border: 1px solid var(--tb-bd); border-radius: calc(var(--tb-radius) - 2px); padding: 6px 9px; }
.tb-cifra-l { font-size: 11px; color: var(--tb-mu); }
.tb-cifra-n { font-size: 1.05rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.tb-cifra-s { font-size: 11px; color: var(--tb-mu); }

/* ── Cargando ── */
.tb-skel { height: 12px; border-radius: 6px; background: var(--tb-skel); margin: 10px 0; animation: tb-pulso 1.3s ease-in-out infinite; }
@keyframes tb-pulso { 50% { opacity: .45; } }

/* ── Ventana de configuración ── */
.tb-modal-fondo { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 1060; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 12px; overflow: auto; }
.tb-modal { background: var(--tb-panel); color: var(--tb-tx); border: 1px solid var(--tb-bd); border-radius: var(--tb-radius); width: min(720px, 100%); padding: 16px 18px; }
.tb-modal h3 { font-size: 1.05rem; margin: 0 0 4px; }
.tb-field { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 8px 0; }
.tb-field select, .tb-field input { background: var(--tb-panel-2); color: var(--tb-tx); border: 1px solid var(--tb-bd); border-radius: 6px; padding: 5px 8px; font-size: 13px; }

@media (max-width: 900px) {
    .tb { padding: 14px 12px 28px; }
    .tb-grid.dos, .tb-grid.tres { grid-template-columns: minmax(0, 1fr); }
    .tb-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* La barra superior del sitio también sigue el tema cuando se está en el tablero */
html[data-tablero-tema="oscuro"] main:has(.tb) > .top-row { background: #0f1720; border-bottom-color: #243445; }
html[data-tablero-tema="oscuro"] main:has(.tb) > .top-row a { color: #4da3e6; }

/* ── Bloques plegables ── */
.tb-clic { cursor: pointer; user-select: none; }
.tb-chev { font-size: 15px !important; color: var(--tb-mu) !important; }
.tb-plegada > :not(.tb-card-h):not(.tb-tema-h):not(.tb-sec-h) { display: none !important; }
.tb-plegada > .tb-card-h { margin-bottom: 0; }
.tb-sec { margin-top: 10px; }
.tb-sec-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }

/* ── Accesos rápidos y buscador de clientes ── */
.tb-accesos { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.tb-acceso, .tb-accion {
    display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--tb-bd);
    border-radius: calc(var(--tb-radius) - 2px); background: var(--tb-panel-2); color: var(--tb-tx) !important; text-decoration: none !important; font-size: 13px;
}
.tb-acceso i, .tb-accion i { color: var(--tb-ac); font-size: 17px; }
.tb-acceso:hover, .tb-accion:hover { border-color: var(--tb-ac); background: var(--tb-hover); }
.tb-accion-p { background: var(--tb-ac); border-color: var(--tb-ac); color: #fff !important; }
.tb-accion-p i { color: #fff; }
.tb-input {
    width: 100%; background: var(--tb-panel-2); color: var(--tb-tx); border: 1px solid var(--tb-bd);
    border-radius: calc(var(--tb-radius) - 2px); padding: 8px 10px; font-size: 14px; margin-bottom: 6px;
}
.tb-input:focus { outline: 2px solid var(--tb-ac); outline-offset: -1px; }
.tb-ficha { margin-top: 4px; }
.tb-acciones { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-top: 8px; }

/* ── Bandeja de WhatsApp ── */
.wa-wrap { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 12px; height: calc(100vh - 170px); min-height: 480px; }
.wa-lista, .wa-hilo { display: flex; flex-direction: column; min-height: 0; padding: 10px 12px; }
.wa-filtros { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.wa-chip { border: 1px solid var(--tb-bd); background: var(--tb-panel-2); color: var(--tb-mu); border-radius: 99px; padding: 3px 11px; font-size: 12px; cursor: pointer; }
.wa-chip.on { background: var(--tb-ac-s); color: var(--tb-ac); border-color: var(--tb-ac); font-weight: 600; }
.wa-busqueda { display: grid; gap: 4px; }
.wa-filas { overflow-y: auto; flex: 1; margin: 0 -6px; padding: 0 6px; }
.wa-fila { padding: 9px 6px; border-radius: 8px; }
.wa-activa { background: var(--tb-ac-s); }
.wa-chips { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 3px; }
.wa-chips .tb-badge { font-size: 10px; padding: 0 6px; }
.wa-punto { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--tb-wa); margin-top: 6px; }
.wa-cab { display: flex; align-items: center; gap: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--tb-bd); }
.wa-volver { display: none; }
.wa-menu-et { display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 8px 4px; border-bottom: 1px solid var(--tb-bd); }
.wa-et-op { font-size: 13px; display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.wa-mensajes { flex: 1; overflow-y: auto; padding: 10px 2px; display: flex; flex-direction: column; gap: 6px; }
.wa-burbuja-fila { display: flex; }
.wa-izq { justify-content: flex-start; }
.wa-der { justify-content: flex-end; }
.wa-burbuja { max-width: min(78%, 560px); padding: 7px 10px; border-radius: 12px; font-size: 14px; border: 1px solid var(--tb-bd); }
.wa-in { background: var(--tb-panel-2); }
.wa-out { background: var(--tb-ac-s); border-color: transparent; }
.wa-bot { background: var(--tb-gr-s); border-color: transparent; }
.wa-meta { font-size: 11px; color: var(--tb-mu); margin-top: 3px; text-align: right; }
.wa-img { max-width: 260px; max-height: 260px; border-radius: 8px; display: block; margin-bottom: 4px; }
.wa-compositor { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; align-items: end; padding-top: 8px; border-top: 1px solid var(--tb-bd); }
.wa-compositor .tb-input { margin-bottom: 0; resize: vertical; min-height: 44px; }
.wa-aviso { margin-top: 8px; }

@media (max-width: 900px) {
    .wa-wrap { grid-template-columns: minmax(0, 1fr); height: calc(100vh - 150px); }
    .wa-wrap.wa-con-hilo .wa-lista { display: none; }
    .wa-wrap:not(.wa-con-hilo) .wa-hilo { display: none; }
    .wa-volver { display: inline-flex; }
}

/* ── Correos: tilde, mail completo y respuesta ── */
.tb-mini { padding: 2px 6px; }
.tb-ok-msg { color: var(--tb-ok); font-size: 13px; margin: 4px 0; }
.tb-modal.ancho { width: min(900px, 100%); }
.tb-mail-cab { background: var(--tb-panel-2); border: 1px solid var(--tb-bd); border-radius: calc(var(--tb-radius) - 2px); padding: 8px 10px; margin: 8px 0; font-size: 13px; word-break: break-word; }
.tb-mail-cuerpo { white-space: pre-wrap; word-break: break-word; font-size: 14px; max-height: 40vh; overflow: auto; padding: 8px 2px; }
.tb-mail-html { width: 100%; height: 40vh; border: 1px solid var(--tb-bd); border-radius: calc(var(--tb-radius) - 2px); background: #fff; }
.tb-mail-adj { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 8px 0; }
.tb-mail-adj .tb-btn { text-decoration: none; }
.tb-mail-resp { border-top: 1px solid var(--tb-bd); margin-top: 10px; padding-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.tb-mail-resp textarea { width: 100%; resize: vertical; }

/* ── WhatsApp: respuestas rápidas y botones de acción bajo el compositor ── */
.wa-rapidas { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; }
.wa-chip { padding: 3px 10px; font-size: 12px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wa-acciones { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--tb-bd); }
.wa-acciones .tb-btn { text-decoration: none; }
.wa-rr-fila { display: flex; flex-direction: column; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--tb-bd); }
.wa-rr-fila textarea { width: 100%; resize: vertical; }
