/* =========================================================
   Orion Central — panel.css (basado en BarberKings)
   Panel de administración: menú lateral, barra superior,
   paneles, indicadores, tablas, turnos y gráficas.
   ========================================================= */
body.admin { display: flex; min-height: 100vh; }

.sidebar {
    width: 240px; flex: none; background: var(--bg-2); border-right: 1px solid var(--border);
    padding: 20px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .brand { padding: 0 8px 20px; font-size: 20px; }
.sidebar-nav { display: grid; gap: 2px; }
.sidebar-nav a {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px;
    color: var(--muted); font-weight: 500;
}
.sidebar-nav a:hover { background: var(--surface); color: var(--text); }
.sidebar-nav a.active { background: rgba(200, 162, 74, .12); color: var(--gold); }
.nav-icon { width: 22px; text-align: center; }
.sidebar-backdrop { display: none; }

.admin-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    display: flex; align-items: center; gap: 14px; padding: 14px 28px; border-bottom: 1px solid var(--border);
    background: var(--bg); position: sticky; top: 0; z-index: 20;
}
.topbar-title { margin: 0; font-size: 1.4rem; flex: 1; }
.topbar-user { display: flex; align-items: center; gap: 10px; }
.user-name { font-weight: 600; }
.user-role { font-size: 12px; color: var(--gold); background: rgba(200, 162, 74, .12); padding: 2px 8px; border-radius: 999px; }
.admin-content { padding: 24px 28px 40px; display: grid; gap: 20px; align-content: start; grid-template-columns: minmax(0, 1fr); }
/* minmax(0, 1fr): la columna no crece con la tabla más ancha (en el celular las tablas se desplazan dentro de .table-wrap) */
.contenido { display: grid; gap: 20px; align-content: start; min-width: 0; grid-template-columns: minmax(0, 1fr); }

/* Hasta conocer el rol del usuario no se muestran el menú ni los elementos restringidos */
body.admin:not(.sesion-lista) .sidebar-nav,
body.admin:not(.sesion-lista) [data-solo-roles],
body.admin:not(.sesion-lista) .topbar-user { visibility: hidden; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; }
.panel.narrow { max-width: 760px; width: 100%; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 14px; }
.panel-head h2, .panel-title { margin: 0; font-size: 1.15rem; }
.panel-title { margin-bottom: 14px; }
.grid-sidebar { grid-template-columns: 320px minmax(0, 1fr); align-items: start; }

.toolbar { display: flex; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; gap: 14px; }
.toolbar > p { margin: 0; }
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
.filters input, .filters select { padding: 8px 10px; }
.actions { display: inline-flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; align-items: center; }
.inline-form { display: inline-flex; gap: 6px; margin: 0; }

/* ---------- Indicadores ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px 20px; display: grid; gap: 4px; border-top: 3px solid var(--gold); }
.stat-ok { border-top-color: var(--ok); }
.stat-bad { border-top-color: var(--bad); }
.stat-label { color: var(--muted); font-size: 13px; font-weight: 600; }
.stat-value { font: 600 1.8rem var(--font-title); }
.stat-foot { font-size: 12px; color: var(--muted); }

/* ---------- Tablas y listas ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: rgba(255, 255, 255, .02); }
.fila-inactivo { opacity: .5; }
.horario-table input[type="time"] { min-width: 110px; }

.list { list-style: none; margin: 0; padding: 0; }
.list-item { display: flex; align-items: center; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.list-main { flex: 1; display: grid; min-width: 0; }
.list-time { font: 600 1.05rem var(--font-title); color: var(--gold); min-width: 52px; }
.details-inline { grid-template-columns: repeat(4, 1fr); margin: 0; }

/* ---------- Turnos ---------- */
.turnos { display: grid; gap: 10px; }
.turno-card {
    display: grid; grid-template-columns: auto 1fr auto; gap: 6px 16px; align-items: center;
    padding: 14px 16px; border-radius: var(--radius); background: var(--bg-2); border: 1px solid var(--border);
    border-left: 4px solid var(--warn);
}
.turno-card .actions { grid-column: 1 / -1; justify-content: flex-start; }
.turno-llamado { border-left-color: var(--info); animation: pulso 2s infinite; }
.turno-atendiendo { border-left-color: var(--gold); }
.turno-num { font: 700 1.6rem var(--font-title); color: var(--gold); min-width: 54px; }
.turno-info { display: grid; }
.cerrados { margin-top: 18px; }
.cerrados summary { cursor: pointer; color: var(--muted); font-weight: 600; }
@keyframes pulso { 50% { box-shadow: 0 0 0 4px rgba(74, 144, 200, .2); } }

/* ---------- Gráficas de barras (CSS) ---------- */
.bars { display: flex; align-items: flex-end; gap: 8px; height: 220px; padding-top: 24px; overflow-x: auto; }
.bar { flex: 1; min-width: 34px; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; }
.bar-fill { width: 100%; max-width: 46px; background: linear-gradient(to top, var(--gold), var(--gold-2)); border-radius: 6px 6px 0 0; min-height: 2px; }
.bar-label { font-size: 11px; color: var(--muted); }
.bar-value { font-size: 10px; color: var(--muted); white-space: nowrap; }
.bar-pair { display: flex; align-items: flex-end; gap: 3px; width: 100%; height: calc(100% - 22px); justify-content: center; }
.bar-pair .bar-fill { max-width: 20px; }
.bar-out { background: linear-gradient(to top, #b8473a, var(--bad)); }
.legend { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }
.lg-in { background: var(--gold); }
.lg-out { background: var(--bad); margin-left: 8px; }

.meter { margin-bottom: 14px; }
.meter-head { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 6px; }
.meter-track { height: 8px; background: var(--bg-2); border-radius: 99px; overflow: hidden; }
.meter-track span { display: block; height: 100%; background: var(--gold); border-radius: 99px; }

/* ---------- Acceso (login / setup) ---------- */
body.acceso { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.acceso .card { width: 100%; max-width: 420px; }
.acceso .brand { justify-content: center; margin-bottom: 20px; }

@media (max-width: 960px) {
    .grid-sidebar { grid-template-columns: minmax(0, 1fr); }
    .details-inline { grid-template-columns: repeat(2, 1fr); }

    .sidebar { position: fixed; left: 0; top: 0; z-index: 100; transform: translateX(-100%); transition: transform .25s; }
    body.sidebar-open .sidebar { transform: none; }
    body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 90; }
    .topbar .nav-toggle { display: block; }
    .topbar { padding: 12px 16px; }
    .admin-content { padding: 16px; }
    .user-name { display: none; }
}

@media (max-width: 720px) {
    .toolbar { align-items: stretch; flex-direction: column; }
    .filters .field-inline { flex: 1 1 140px; }
    .user-role { display: none; }
}

/* =========================================================
   Orion Central — estados de licencia, conexión y comandos
   ========================================================= */
.badge-activa, .badge-completado, .badge-conectada { background: rgba(76, 195, 138, .15); color: var(--ok); }
.badge-suspendida, .badge-vencida, .badge-error, .badge-desconectada { background: rgba(229, 96, 79, .15); color: var(--bad); }
.badge-enviado { background: rgba(74, 144, 200, .15); color: #7db6e3; }
.badge-sin_conexion { background: rgba(224, 162, 59, .15); color: var(--warn); }

.llave {
    margin: 0; padding: 14px; border-radius: var(--radius); background: var(--bg-2); border: 1px dashed var(--gold);
    font: 13px/1.6 ui-monospace, SFMono-Regular, Consolas, monospace; white-space: pre-wrap; word-break: break-all;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-on { background: rgba(200, 162, 74, .15); color: var(--gold-2); }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
.checks .check { padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); }
.metricas { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.metrica { background: var(--bg-2); border-radius: var(--radius); padding: 10px 14px; }
.metrica dt { font-size: 12px; color: var(--muted); }
.metrica dd { margin: 2px 0 0; font: 600 1.3rem var(--font-title); }
.detalle-json { font-size: 12px; color: var(--muted); max-width: 420px; word-break: break-word; }

/* Operadores: acceso por grupo (un selector por grupo) */
.grupos-acceso { display: grid; gap: 8px; }
.grupo-acceso { display: flex; flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; margin: 0; }
.grupo-acceso > span { flex: 1; }
.grupo-acceso select { width: auto; min-width: 160px; }

/* ---------- Webapp: botón "Instalar app" (js/comun/pwa.js lo oculta si ya está instalada) ---------- */
.sidebar { display: flex; flex-direction: column; }
.sidebar-instalar {
    display: flex; align-items: center; gap: 10px; width: 100%; margin-top: auto; padding: 10px 12px;
    border: 1px dashed var(--border); border-radius: 8px; background: none; color: var(--muted);
    font: 500 14px var(--font); cursor: pointer; text-align: left;
}
.sidebar-instalar:hover { color: var(--gold); border-color: var(--gold); }
.sidebar-nav { margin-bottom: 16px; }
.acceso-instalar { margin-top: 12px; }

/* ---------- Ventas: prospectos y conversaciones del bot ---------- */
.badge-nuevo { background: rgba(154, 154, 163, .15); color: var(--muted); }
.badge-contactado { background: rgba(74, 144, 200, .15); color: #7db6e3; }
.badge-interesado { background: rgba(224, 162, 59, .15); color: var(--warn); }
.badge-demo { background: rgba(200, 162, 74, .18); color: var(--gold-2); }
.badge-cliente { background: rgba(76, 195, 138, .15); color: var(--ok); }
.badge-descartado { background: rgba(229, 96, 79, .15); color: var(--bad); }
.fila-pendiente td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
.contactos { display: flex; flex-wrap: wrap; gap: 6px; }

.estado-bot { display: flex; flex-wrap: wrap; gap: 8px; }
.conv-item { cursor: pointer; }
.conv-item.activa { background: var(--surface-2); border-radius: var(--radius); }
.conv-item .list-main span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contador { background: var(--gold); color: #111; border-radius: 999px; padding: 1px 8px; font-size: 12px; font-weight: 600; }

.chat { display: flex; flex-direction: column; gap: 8px; max-height: 60vh; min-height: 220px; overflow-y: auto; padding: 12px; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); }
.burbuja { max-width: 80%; padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.4; }
.burbuja small { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.burbuja-cliente { align-self: flex-start; background: var(--surface-2); }
.burbuja-bot { align-self: flex-end; background: rgba(74, 144, 200, .18); }
.burbuja-operador { align-self: flex-end; background: rgba(200, 162, 74, .2); }
.burbuja-sistema { align-self: center; background: transparent; border: 1px dashed var(--border); color: var(--muted); font-size: 13px; }
.chat-form { display: flex; gap: 8px; margin-top: 10px; align-items: flex-end; }
.chat-form textarea { flex: 1; min-height: 44px; resize: vertical; }
.precios { display: grid; gap: 12px; }
.precios h3 { margin: 0 0 4px; }
.precios ul { margin: 4px 0 0; padding-left: 18px; }

/* ---------- Licencias v2: ciclo comercial, topes, pagos, avisos y cobros ---------- */
.badge-en_gracia, .badge-cerca { background: rgba(224, 162, 59, .15); color: var(--warn); }
.badge-cancelada, .badge-excedido { background: rgba(229, 96, 79, .15); color: var(--bad); }
.badge-normal { background: rgba(76, 195, 138, .15); color: var(--ok); }
.badge-tipo-pagada { background: rgba(76, 195, 138, .15); color: var(--ok); }
.badge-tipo-prueba { background: rgba(74, 144, 200, .15); color: #7db6e3; }
.badge-tipo-demo { background: rgba(200, 162, 74, .18); color: var(--gold-2); }
.badge-tipo-cortesia, .badge-tipo-interna { background: rgba(154, 154, 163, .15); color: var(--muted); }

.grupo-campos { min-width: 0; margin: 4px 0 0; padding: 12px 14px 4px; border: 1px solid var(--border); border-radius: var(--radius); display: grid; gap: 12px; }
.grupo-campos legend { padding: 0 6px; font-size: 13px; color: var(--muted); }
.precio-grande { margin: 0 0 6px; font: 600 1.8rem var(--font-title); color: var(--gold-2); }
.barra { display: block; width: 100%; max-width: 180px; height: 8px; margin-top: 4px; }
.input-tope { max-width: 140px; }
.pago-anulado td { color: var(--muted); text-decoration: line-through; }
.pago-anulado td:last-child { text-decoration: none; }

.lista-avisos { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.aviso-item { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 10px 12px; border-radius: var(--radius); background: var(--bg-2); border-left: 3px solid #7db6e3; }
.aviso-item p { margin: 4px 0 0; }
.aviso-alerta { border-left-color: var(--warn); }
.aviso-urgente { border-left-color: var(--bad); }

.cobro-lista { list-style: none; margin: 0; padding: 0; }
.cobro-lista li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.cobro-lista li:last-child { border-bottom: 0; }
