/* ============================================================
   GeoCenso · Monitoreo Global (Tablero TV estilo bolsa de valores)
   Dark por defecto · Modo claro con variables · compacto
   ============================================================ */

:root {
    --mg-bg: #080c16;
    --mg-bg-card: rgba(255,255,255,.028);
    --mg-border: rgba(255,255,255,.08);
    --mg-head-bg: #0d1220;
    --mg-row-border: rgba(255,255,255,.06);
    --mg-col-border: rgba(255,255,255,.14);
    --mg-hover: rgba(255,255,255,.04);
    --mg-chip-bg: rgba(255,255,255,.04);
    --mg-text: #e5e9f0;
    --mg-text-soft: #94a3b8;
    --mg-text-faint: #64748b;
    --mg-accent: #7dd3fc;
    --mg-clock: #c7d2fe;
    --mg-scroll: rgba(255,255,255,.14);
    --mg-shadow: 0 18px 40px -22px rgba(0,0,0,.7);
    --rol-vendedor: #38bdf8;
    --rol-promotor: #c084fc;
    --rol-supervisor: #34d399;
}

body.light-mode {
    --mg-bg: #eef2f7;
    --mg-bg-card: #ffffff;
    --mg-border: #e2e8f0;
    --mg-head-bg: #f1f5f9;
    --mg-row-border: #dbe2ec;
    --mg-col-border: #c3cddb;
    --mg-hover: #f1f5f9;
    --mg-chip-bg: #f1f5f9;
    --mg-text: #0f172a;
    --mg-text-soft: #475569;
    --mg-text-faint: #64748b;
    --mg-accent: #0369a1;
    --mg-clock: #4338ca;
    --mg-scroll: rgba(100,116,139,.35);
    --mg-shadow: 0 18px 40px -26px rgba(15,23,42,.35);
    --rol-vendedor: #0284c7;
    --rol-promotor: #9333ea;
    --rol-supervisor: #059669;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
    font-family: 'Outfit', system-ui, -apple-system, sans-serif;
    background:
        radial-gradient(1100px 500px at 15% -10%, rgba(79,70,229,.14), transparent 60%),
        radial-gradient(900px 400px at 100% 0%, rgba(168,85,247,.10), transparent 55%),
        var(--mg-bg);
    color: var(--mg-text);
    overflow: hidden;
    transition: background .3s, color .3s;
}

body.light-mode {
    background:
        radial-gradient(1100px 500px at 15% -10%, rgba(79,70,229,.08), transparent 60%),
        radial-gradient(900px 400px at 100% 0%, rgba(168,85,247,.06), transparent 55%),
        var(--mg-bg);
}

.mg-board {
    height: 100vh; width: 100%; display: flex; flex-direction: column;
    padding: 10px 16px 10px;
}

/* ---------- Barra superior ---------- */
.mg-topbar {
    display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap;
    padding-bottom: 10px; border-bottom: 1px solid var(--mg-border); margin-bottom: 12px;
}
.mg-brand { display: flex; align-items: center; gap: 11px; }
.mg-logo {
    width: 38px; height: 38px; border-radius: 11px; display: flex; align-items: center; justify-content: center;
    font-size: 18px; background: linear-gradient(135deg, #4338ca, #4F46E5 45%, #a855f7);
    box-shadow: 0 0 22px -4px rgba(124,58,237,.7);
}
.mg-title { font-size: 18px; font-weight: 800; letter-spacing: -.02em; }
.mg-subtitle { font-size: 11px; color: var(--mg-text-soft); margin-top: 1px; }

.mg-summary { display: flex; gap: 8px; flex-wrap: wrap; }
.mg-chip {
    display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600;
    padding: 4px 10px; border-radius: 999px; background: var(--mg-chip-bg); border: 1px solid var(--mg-border);
}
.mg-chip b { font-size: 13px; font-weight: 800; }
.mg-chip.verde b { color: #22c55e; }
.mg-chip.azul b { color: #38bdf8; }
.mg-chip.rojo b { color: #f87171; }
body.light-mode .mg-chip.verde b { color: #16a34a; }
body.light-mode .mg-chip.azul b { color: #2563eb; }
body.light-mode .mg-chip.rojo b { color: #dc2626; }

.mg-controls { display: flex; align-items: center; gap: 10px; }
.mg-clock {
    font-family: 'SF Mono', ui-monospace, monospace; font-size: 20px; font-weight: 700;
    letter-spacing: .02em; color: var(--mg-clock); text-shadow: 0 0 16px rgba(129,140,248,.45);
}
.mg-update { font-size: 10.5px; color: var(--mg-text-faint); }
.mg-auto { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--mg-text-soft); cursor: pointer; user-select: none; }
.mg-auto input { accent-color: #4F46E5; }
.mg-back {
    width: 34px; height: 34px; border-radius: 10px; display: flex; align-items: center; justify-content: center;
    font-size: 16px; color: var(--mg-text); text-decoration: none; background: var(--mg-chip-bg);
    border: 1px solid var(--mg-border); cursor: pointer; transition: background .15s, transform .15s;
}
.mg-back:hover { background: var(--mg-hover); transform: translateY(-1px); }

/* ---------- Tarjetas combinadas por empresa ---------- */
.mg-cards {
    flex: 1; min-height: 0;
    display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 8px; align-items: stretch;
}
.mg-card {
    background: var(--mg-bg-card); border: 1px solid var(--mg-border);
    border-radius: 14px; overflow: hidden; box-shadow: var(--mg-shadow);
    display: flex; flex-direction: column; min-height: 0;
}
.mg-card-head {
    display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap;
    padding: 8px 10px; border-bottom: 1px solid var(--mg-border);
    background: linear-gradient(135deg, rgba(79,70,229,.10), rgba(168,85,247,.04));
}
.mg-card-name { font-size: 12.5px; font-weight: 800; color: var(--mg-text); letter-spacing: 0; }
.mg-card-chips { display: flex; gap: 4px; }
.mg-card-chips .mg-chip { padding: 2px 6px; font-size: 9.5px; gap: 4px; }
.mg-card-chips .mg-chip b { font-size: 11px; }
.mg-card-table {
    flex: 1; min-height: 0; overflow: hidden; border: none; border-radius: 0; max-height: none;
}

/* ---------- Tablas ---------- */
.mg-table { width: 100%; border-collapse: collapse; font-size: 10.5px; min-width: 0; table-layout: fixed; }
.mg-table thead th {
    position: sticky; top: 0; z-index: 5; text-align: left; font-size: 9px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .03em; color: var(--mg-text-faint); padding: 4px 4px;
    background: var(--mg-head-bg); border-bottom: 1px solid var(--mg-border);
    border-right: 1px solid var(--mg-col-border);
}
.mg-table thead th:last-child { border-right: none; }
/* Anchos fijos para que todas las columnas (incluida Cierre) quepan siempre */
.mg-table thead th:first-child { width: 25%; }
.mg-table thead th:nth-child(2) { width: 8%; }
.mg-table thead th:nth-child(3) { width: 21%; }
.mg-table thead th:nth-child(4) { width: 18%; }
.mg-table thead th:nth-child(5) { width: 18%; }
.mg-table td { padding: 3px 4px; border-bottom: 1px solid var(--mg-row-border); border-right: 1px solid var(--mg-col-border); color: var(--mg-text); }
.mg-table td:last-child { border-right: none; }
.mg-table tbody tr { transition: background .2s; }
.mg-table tbody tr:hover { background: var(--mg-hover); }
.mg-table tbody tr:last-child td { border-bottom: none; }

.mg-col-user { min-width: 0; }
.mg-col-num { text-align: right !important; white-space: nowrap; }

.mg-user { display: flex; align-items: center; gap: 6px; font-weight: 600; color: var(--mg-text); font-size: 12px; min-width: 0; }
.mg-user-name { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.mg-user-nombre { font-size: 11.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mg-user-apellido { font-size: 10px; font-weight: 600; color: var(--mg-text-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mg-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.mg-dot.verde { background: #22c55e; box-shadow: 0 0 9px 1px rgba(34,197,94,.6); animation: pulseV 2s infinite; }
.mg-dot.azul { background: #3b82f6; box-shadow: 0 0 9px 1px rgba(59,130,246,.6); animation: pulseA 2s infinite; }
.mg-dot.naranja { background: #fb923c; box-shadow: 0 0 9px 1px rgba(251,146,60,.65); animation: pulseN 2s infinite; }
.mg-dot.rojo { background: #ef4444; box-shadow: 0 0 7px 1px rgba(239,68,68,.5); }
@keyframes pulseV { 0%,100% { box-shadow: 0 0 0 0 rgba(34,197,94,.55);} 50% { box-shadow: 0 0 0 6px rgba(34,197,94,0);} }
@keyframes pulseA { 0%,100% { box-shadow: 0 0 0 0 rgba(59,130,246,.55);} 50% { box-shadow: 0 0 0 6px rgba(59,130,246,0);} }
@keyframes pulseN { 0%,100% { box-shadow: 0 0 0 0 rgba(251,146,60,.6);} 50% { box-shadow: 0 0 0 6px rgba(251,146,60,0);} }

.mg-val { font-family: 'SF Mono', ui-monospace, monospace; font-variant-numeric: tabular-nums; font-weight: 700; color: var(--mg-text); }
.mg-val.hora { font-size: 11.5px; font-weight: 600; color: var(--mg-text-soft); }
.mg-val.destacado { color: var(--mg-accent); font-size: 15px; }

.mg-actividad-sup {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.1;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mg-val-detalle {
    display: inline;
    font-size: 8px;
    font-weight: 500;
    color: var(--mg-text-soft);
    font-family: 'SF Mono', ui-monospace, monospace;
    margin-left: 3px;
    letter-spacing: .02em;
}

.mg-rol { font-size: 8.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0; white-space: nowrap; }
.mg-rol.rol-vendedor, .mg-divider-txt.rol-vendedor { color: var(--rol-vendedor); }
.mg-rol.rol-promotor, .mg-divider-txt.rol-promotor { color: var(--rol-promotor); }
.mg-rol.rol-supervisor, .mg-divider-txt.rol-supervisor { color: var(--rol-supervisor); }

/* Fecha resaltada + hora en 1ª Visita / Cierre */
.mg-fecha-hora { display: inline-flex; flex-direction: column; align-items: flex-end; line-height: 1.15; }
.mg-val.fecha { font-size: 11px; font-weight: 800; color: var(--mg-accent); letter-spacing: .02em; }

/* Divisiones por tipo de usuario dentro de cada tarjeta */
.mg-divider td {
    background: var(--mg-head-bg); padding: 2px 4px;
    border-bottom: 1px solid var(--mg-border);
    border-right: none;
}
.mg-divider-txt {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 9px; font-weight: 800; text-transform: uppercase; letter-spacing: .03em;
}
.mg-divider-txt em { font-style: normal; font-weight: 700; opacity: .7; margin-left: 2px; }

.mg-vacio { text-align: center; color: var(--mg-text-faint); padding: 26px 16px !important; font-size: 13px; }

/* Flash al actualizar (por brillo, compatible con filas con color de fondo) */
.mg-flash { animation: flashRow .6s ease; }
@keyframes flashRow { 0% { filter: brightness(1.35); } 100% { filter: brightness(1); } }

/* ============================================================
   Resaltado de fila por semáforo (usuario) · estilo "Barra degradada"
   ============================================================ */
.mg-row.verde { background: linear-gradient(90deg, rgba(34,197,94,.16), rgba(34,197,94,.05) 55%, transparent); }
.mg-row.verde td:first-child { border-left: 4px solid #22c55e; box-shadow: inset 0 0 14px -6px rgba(34,197,94,.55); }
.mg-row.verde:hover { background: linear-gradient(90deg, rgba(34,197,94,.26), rgba(34,197,94,.08) 55%, transparent); }
.mg-row.azul { background: linear-gradient(90deg, rgba(59,130,246,.16), rgba(59,130,246,.05) 55%, transparent); }
.mg-row.azul td:first-child { border-left: 4px solid #3b82f6; box-shadow: inset 0 0 14px -6px rgba(59,130,246,.55); }
.mg-row.azul:hover { background: linear-gradient(90deg, rgba(59,130,246,.26), rgba(59,130,246,.08) 55%, transparent); }
.mg-row.rojo { background: linear-gradient(90deg, rgba(239,68,68,.16), rgba(239,68,68,.05) 55%, transparent); }
.mg-row.rojo td:first-child { border-left: 4px solid #ef4444; box-shadow: inset 0 0 14px -6px rgba(239,68,68,.55); }
.mg-row.rojo:hover { background: linear-gradient(90deg, rgba(239,68,68,.26), rgba(239,68,68,.08) 55%, transparent); }

/* En oficina / base (supervisores) */
.mg-row.naranja { background: linear-gradient(90deg, rgba(251,146,60,.18), rgba(251,146,60,.05) 55%, transparent); }
.mg-row.naranja td:first-child { border-left: 4px solid #fb923c; box-shadow: inset 0 0 14px -6px rgba(251,146,60,.6); }
.mg-row.naranja:hover { background: linear-gradient(90deg, rgba(251,146,60,.28), rgba(251,146,60,.08) 55%, transparent); }

/* Botón de acceso a RADAR */
.mg-btn-radar {
    display: inline-flex; align-items: center; gap: 6px;
    text-decoration: none; font-weight: 800; font-size: 12px; color: #fff;
    padding: 8px 14px; border-radius: 10px; border: 1px solid rgba(255,255,255,.12);
    background: linear-gradient(135deg, #0891b2 0%, #0e7490 55%, #4F46E5 120%);
    box-shadow: 0 0 16px -4px rgba(8,145,178,.7), inset 0 0 0 1px rgba(255,255,255,.08);
    transition: transform .15s, box-shadow .15s;
}
.mg-btn-radar:hover { transform: translateY(-1px); box-shadow: 0 0 24px -2px rgba(8,145,178,.9); }

.mg-footer { text-align: center; font-size: 10px; color: var(--mg-text-faint); margin-top: 8px; }

/* ---------- Scrollbar ---------- */
.mg-table-wrap::-webkit-scrollbar { width: 6px; height: 6px; }
.mg-table-wrap::-webkit-scrollbar-thumb { background: var(--mg-scroll); border-radius: 999px; }
.mg-table-wrap::-webkit-scrollbar-track { background: transparent; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    body { overflow: auto; }
    .mg-board { height: auto; min-height: 100vh; }
    .mg-topbar { gap: 10px; }
    .mg-clock { font-size: 16px; }
    .mg-cards { grid-template-columns: 1fr 1fr; }
    .mg-card-table { overflow-x: auto; }
    .mg-card-table .mg-table { min-width: 520px; }
}
@media (max-width: 560px) {
    .mg-cards { grid-template-columns: 1fr; }
    .mg-card-table .mg-table { min-width: 480px; }
}
