:root {
  --fondo: #f4f5f7;
  --tarjeta: #ffffff;
  --texto: #1c1f26;
  --suave: #6b7280;
  --borde: #e5e7eb;
  --menu: #14161c;
  --menu-texto: #c9ccd3;
  --acento: #f97316;
  --acento-osc: #ea580c;
  --ok: #16a34a;
  --mal: #dc2626;
  --resalte: #fff4cc;
  --sombra: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radio: 12px;

  /* Un color por nodo, igual en toda la app */
  --n-central: #6366f1;
  --n-personas: #0ea5e9;
  --n-empleados: #10b981;
  --n-membresias: #f59e0b;
  --n-sucursales: #ef4444;
  --n-clases: #a855f7;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--fondo);
  color: var(--texto);
  font-size: 14px;
  line-height: 1.45;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
code, pre, .mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }
.oculto { display: none !important; }

/* ---------- inicio de sesión */
.login {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: radial-gradient(circle at 30% 20%, #2a1c12, var(--menu) 60%);
  padding: 16px;
}
.login-caja {
  background: var(--tarjeta); border-radius: 16px; padding: 32px; width: 100%; max-width: 360px;
  display: flex; flex-direction: column; gap: 14px; text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,.35);
}
.login-logo { font-size: 44px; }
.login-caja p { color: var(--suave); margin: 0; }
.login-caja label { text-align: left; }

/* ---------- estructura */
.app { display: flex; min-height: 100vh; }
.menu {
  width: 248px; flex-shrink: 0; background: var(--menu); color: var(--menu-texto);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.marca { color: #fff; font-weight: 700; font-size: 20px; padding: 20px 20px 12px; display: flex; gap: 8px; align-items: center; }
.menu nav { display: flex; flex-direction: column; padding: 0 10px; flex: 1; }
.menu-grupo { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #7c818c; padding: 16px 10px 6px; }
.menu nav a {
  color: var(--menu-texto); text-decoration: none; padding: 9px 10px; border-radius: 8px; display: flex; gap: 10px; align-items: center;
}
.menu nav a i { font-style: normal; width: 20px; text-align: center; }
.menu nav a:hover { background: #22252d; color: #fff; }
.menu nav a.activo { background: var(--acento); color: #fff; }
.salir { margin: 0 12px 12px; color: var(--menu-texto) !important; border-color: #2c3038 !important; }
.usuario-actual { margin: 12px 12px 8px; padding: 10px 12px; border-radius: 10px; background: #1d2027; font-size: 12.5px; }
.usuario-actual b { color: #fff; display: block; font-size: 13.5px; }
.menu-grupo.vacio-grupo { display: none; }
.vista-item { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; border: 1px solid var(--borde); border-radius: 10px; cursor: pointer; background: #fff; }
.vista-item:hover { border-color: #fdba74; }
.vista-item.sel { border-color: var(--acento); background: #fff7ed; }
.lecturas { display: flex; flex-wrap: wrap; gap: 8px; }
.lectura { border: 1px solid var(--borde); border-radius: 8px; padding: 6px 10px; display: flex; gap: 8px; align-items: center; font-size: 12.5px; background: #fff; }

.principal { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.barra {
  display: flex; align-items: center; gap: 12px; padding: 18px 28px; background: var(--tarjeta);
  border-bottom: 1px solid var(--borde); position: sticky; top: 0; z-index: 5;
}
.barra > div { flex: 1; min-width: 0; }
.barra h1 { font-size: 20px; }
.subtitulo { margin: 2px 0 0; color: var(--suave); font-size: 13px; }
.vista { padding: 24px 28px 48px; display: flex; flex-direction: column; gap: 20px; }

/* ---------- elementos */
.btn {
  border: 1px solid var(--borde); background: var(--tarjeta); color: var(--texto); border-radius: 8px;
  padding: 8px 14px; font: inherit; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #c7cad1; }
.btn:disabled { opacity: .55; cursor: wait; }
.btn-primario { background: var(--acento); border-color: var(--acento); color: #fff; font-weight: 600; }
.btn-primario:hover { background: var(--acento-osc); border-color: var(--acento-osc); }
.btn-peligro { color: var(--mal); }
.btn-fantasma { background: transparent; }
.btn-chico { padding: 4px 10px; font-size: 12px; }
.btn-sql { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.cuenta { background: var(--menu); color: #fff; border-radius: 999px; padding: 1px 7px; margin-left: 4px; }

input, select, textarea {
  width: 100%; font: inherit; padding: 8px 10px; border: 1px solid var(--borde); border-radius: 8px; background: #fff; color: var(--texto);
}
textarea { font-family: ui-monospace, Consolas, monospace; min-height: 120px; resize: vertical; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: #374151; }
.error-texto { color: var(--mal); min-height: 18px; font-size: 13px; }

.tarjeta { background: var(--tarjeta); border-radius: var(--radio); box-shadow: var(--sombra); padding: 18px 20px; min-width: 0; }
.tarjeta-cab { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.tarjeta-cab h2 { font-size: 16px; }
.tarjeta-cab p { margin: 2px 0 0; color: var(--suave); font-size: 13px; }
.rejilla { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.rejilla-2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.fila { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.fila > input, .fila > select { width: auto; flex: 1; min-width: 160px; }

.kpis { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.kpi { background: var(--tarjeta); border-radius: var(--radio); box-shadow: var(--sombra); padding: 16px 18px; }
.kpi span { color: var(--suave); font-size: 12px; }
.kpi strong { display: block; font-size: 26px; margin-top: 4px; }
.kpi small { color: var(--suave); }

.barras { display: flex; flex-direction: column; gap: 10px; }
.barra-fila { display: grid; grid-template-columns: 130px 1fr 70px; gap: 10px; align-items: center; font-size: 13px; }
.barra-fila .pista { background: #f1f2f4; border-radius: 6px; height: 12px; overflow: hidden; }
.barra-fila .relleno { background: var(--acento); height: 100%; border-radius: 6px; }
.barra-fila b { text-align: right; }

.tabla-caja { overflow: auto; max-height: 560px; border: 1px solid var(--borde); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th { position: sticky; top: 0; background: #f9fafb; text-align: left; font-weight: 600; color: #374151; z-index: 1; }
th, td { padding: 8px 12px; border-bottom: 1px solid var(--borde); white-space: nowrap; }
tbody tr:hover { background: #fafafa; }
tr.resaltada td { background: var(--resalte); }
tr.resaltada td:first-child { box-shadow: inset 3px 0 0 var(--acento); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.vacio { padding: 24px; text-align: center; color: var(--suave); }

.chip { display: inline-block; border-radius: 999px; padding: 2px 9px; font-size: 11px; font-weight: 600; background: #f1f2f4; color: #374151; }
.chip.ok { background: #dcfce7; color: #166534; }
.chip.mal { background: #fee2e2; color: #991b1b; }
.chip.propia { background: #e0e7ff; color: #3730a3; }
.chip.copia { background: #dcfce7; color: #166534; }
.chip.fragmento { background: #fef3c7; color: #92400e; }
.chip.foranea { background: #e0f2fe; color: #075985; }
.chip.vista { background: #f3e8ff; color: #6b21a8; }
.chip.original { background: #ffedd5; color: #9a3412; }

.nodo { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.nodo::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--c, #999); }
.n-central { --c: var(--n-central); } .n-personas { --c: var(--n-personas); } .n-empleados { --c: var(--n-empleados); }
.n-membresias { --c: var(--n-membresias); } .n-sucursales { --c: var(--n-sucursales); } .n-clases { --c: var(--n-clases); }
.borde-nodo { border-top: 4px solid var(--c, #ddd); }

.pestanas { display: flex; gap: 6px; border-bottom: 1px solid var(--borde); flex-wrap: wrap; }
.pestanas button { border: 0; background: none; padding: 10px 14px; font: inherit; cursor: pointer; color: var(--suave); border-bottom: 2px solid transparent; }
.pestanas button.activa { color: var(--texto); border-bottom-color: var(--acento); font-weight: 600; }

.explica { background: #fff7ed; border: 1px solid #fed7aa; border-radius: 10px; padding: 12px 14px; color: #7c2d12; font-size: 13px; }
.explica b { color: #431407; }
pre.codigo { background: #0f1117; color: #e6e6e6; padding: 12px 14px; border-radius: 10px; overflow: auto; font-size: 12.5px; margin: 0; white-space: pre-wrap; }

/* Lista "¿dónde se guardó?" */
.donde { display: flex; flex-direction: column; gap: 8px; }
.donde-item { display: grid; grid-template-columns: 140px 190px 1fr auto; gap: 10px; align-items: center; padding: 10px 12px; border: 1px solid var(--borde); border-radius: 10px; background: #fff; }
.donde-item .mono { font-size: 12.5px; }

/* Tablas crudas */
.crudas { display: grid; grid-template-columns: 300px 1fr; gap: 16px; align-items: start; }
.lista-nodos { display: flex; flex-direction: column; gap: 10px; max-height: calc(100vh - 140px); overflow: auto; position: sticky; top: 90px; }
.lista-nodos details { background: var(--tarjeta); border-radius: 10px; box-shadow: var(--sombra); }
.lista-nodos summary { padding: 10px 12px; cursor: pointer; list-style: none; display: flex; justify-content: space-between; align-items: center; }
.lista-nodos summary::-webkit-details-marker { display: none; }
.lista-nodos .t-item { display: flex; justify-content: space-between; gap: 8px; padding: 6px 12px; cursor: pointer; border-top: 1px solid #f3f4f6; font-size: 13px; }
.lista-nodos .t-item:hover { background: #fafafa; }
.lista-nodos .t-item.sel { background: #fff7ed; }
.lista-nodos .t-item small { color: var(--suave); }

/* Nodos */
.nodo-tarjeta h3 { font-size: 15px; display: flex; justify-content: space-between; align-items: center; }
.nodo-tarjeta dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 10px 0 0; font-size: 13px; }
.nodo-tarjeta dt { color: var(--suave); }
.nodo-tarjeta dd { margin: 0; font-weight: 600; }

/* Panel SQL */
.panel-sql {
  position: fixed; top: 0; right: 0; height: 100vh; width: min(520px, 100vw); background: #0f1117; color: #e6e6e6;
  transform: translateX(100%); transition: transform .2s ease; z-index: 30; display: flex; flex-direction: column; padding: 16px;
  box-shadow: -10px 0 30px rgba(0,0,0,.25);
}
.panel-sql.abierto { transform: none; }
.panel-sql-cab { display: flex; justify-content: space-between; align-items: center; }
.panel-sql .btn { color: #e6e6e6; border-color: #2c3038; }
.panel-sql .ayuda { color: #9aa0aa; font-size: 12px; margin: 6px 0 12px; }
#lista-sql { overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.sql-item { background: #171a22; border-radius: 10px; padding: 10px 12px; border-left: 4px solid var(--c, #555); }
.sql-item .meta { display: flex; justify-content: space-between; font-size: 12px; color: #9aa0aa; margin-bottom: 6px; }
.sql-item .nodo { color: #fff; }
.sql-item pre { margin: 0; white-space: pre-wrap; font-size: 12px; color: #e6e6e6; }
.sql-item .err { color: #fca5a5; font-size: 12px; margin-top: 6px; }
.sql-item .params { color: #fbbf24; font-size: 11.5px; margin-top: 6px; }

/* Modal y avisos */
.modal { position: fixed; inset: 0; background: rgba(15, 17, 23, .55); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal-caja { background: var(--tarjeta); border-radius: 14px; width: 100%; max-width: 900px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.modal-cab { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--borde); }
.modal-cab h2 { font-size: 17px; }
.modal-cuerpo { padding: 18px 20px; overflow: auto; display: flex; flex-direction: column; gap: 14px; }
.form { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.form .ancho { grid-column: 1 / -1; }
.acciones { display: flex; gap: 10px; justify-content: flex-end; }
.avisos { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.aviso { background: var(--menu); color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--sombra); max-width: 90vw; }
.aviso.mal { background: var(--mal); }

.cargando { color: var(--suave); padding: 24px; text-align: center; }
.solo-movil { display: none; }

@media (max-width: 900px) {
  .menu { position: fixed; left: 0; top: 0; z-index: 20; transform: translateX(-100%); transition: transform .2s ease; }
  .menu.abierto { transform: none; }
  .solo-movil { display: inline-block; }
  .barra { padding: 12px 16px; }
  .vista { padding: 16px 16px 40px; }
  .crudas { grid-template-columns: 1fr; }
  .lista-nodos { position: static; max-height: none; }
  .rejilla-2 { grid-template-columns: 1fr; }
  .donde-item { grid-template-columns: 1fr; }
  .barra-fila { grid-template-columns: 90px 1fr 60px; }
  .btn-sql { padding: 6px 8px; }
}
