/* Paleta Netfit: cian (--accent) y morado (--sec, segundo color de las gráficas). */
:root {
  --bg: #f2f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #5b6678;
  --line: #e1e7ef;
  --accent: #0891b2;
  --on-accent: #ffffff;
  --accent-soft: #e0f6fa;
  --sec: #8b5cf6;
  --ok: #15803d;
  --ok-soft: #e6f5eb;
  --warn: #b45309;
  --warn-soft: #fef3e2;
  --bad: #c62828;
  --bad-soft: #fdecec;
  --side: #0f1729;
  --side-text: #b8c4d9;
  --side-resalte: #22d3ee;
  --side-activo: rgba(34, 211, 238, .14);
  --radius: 12px;
}
/* Oscuro: elegido a mano (data-theme="dark") o automático si el sistema está en oscuro
   y no se eligió claro. El tema se guarda por navegador (ver base.html). */
:root[data-theme="dark"] {
  --bg: #0b1020;
  --card: #131a2e;
  --text: #e6ebf5;
  --muted: #93a0b8;
  --line: #222c45;
  --accent: #22d3ee;
  --on-accent: #04121a;
  --accent-soft: #0e2a3a;
  --sec: #a78bfa;
  --ok: #4ade80;
  --ok-soft: #13291c;
  --warn: #fbbf24;
  --warn-soft: #2d2410;
  --bad: #f87171;
  --bad-soft: #2f1717;
  --side: #080c18;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1020;
    --card: #131a2e;
    --text: #e6ebf5;
    --muted: #93a0b8;
    --line: #222c45;
    --accent: #22d3ee;
    --on-accent: #04121a;
    --accent-soft: #0e2a3a;
    --sec: #a78bfa;
    --ok: #4ade80;
    --ok-soft: #13291c;
    --warn: #fbbf24;
    --warn-soft: #2d2410;
    --bad: #f87171;
    --bad-soft: #2f1717;
    --side: #080c18;
    color-scheme: dark;
  }
}

/* Logo: el de letras oscuras en tema claro y el de letras blancas en oscuro. */
.login img.logo-tema-claro { display: block; }
.logo-tema-oscuro { display: none; }
:root[data-theme="dark"] .logo-tema-claro { display: none; }
:root[data-theme="dark"] .logo-tema-oscuro { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .logo-tema-claro { display: none; }
  :root:not([data-theme="light"]) .logo-tema-oscuro { display: block; }
}

/* Selector de tema (pie del menú y login). */
.tema { display: flex; gap: 2px; background: rgba(255,255,255,.06); border-radius: 8px; padding: 3px; margin: 0 0 8px; }
.tema button {
  flex: 1; font: inherit; font-size: 12px; border: 0; border-radius: 6px; padding: 5px 4px; cursor: pointer;
  background: transparent; color: var(--side-text);
}
.tema button.activo { background: rgba(34, 211, 238, .2); color: #fff; }
.login .tema { background: var(--bg); border: 1px solid var(--line); margin: 14px 0 0; }
.login .tema button { color: var(--muted); }
.login .tema button.activo { background: var(--accent-soft); color: var(--accent); }
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Estructura --- */
.app { display: flex; min-height: 100vh; }
.side {
  width: 220px; flex-shrink: 0; background: var(--side); color: var(--side-text);
  padding: 18px 12px; position: sticky; top: 0; height: 100vh; height: 100dvh;
  /* Columna: logo arriba, menú con su propio scroll en medio, pie siempre debajo (nunca encima). */
  display: flex; flex-direction: column;
}
.side .marca { color: #fff; font-weight: 700; font-size: 17px; padding: 4px 10px 18px; }
.side nav a {
  display: block; color: var(--side-text); padding: 9px 12px; border-radius: 8px; margin-bottom: 2px;
}
.side nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.side nav a.activo { background: var(--side-activo); color: #fff; box-shadow: inset 3px 0 0 var(--side-resalte); }
.side .marca { padding: 0 6px 14px; }
.side .marca img { display: block; width: 100%; max-width: 180px; height: auto; }
.logo-menu-claro { display: none !important; }  /* el menú es oscuro: logo de letras blancas */
.side .marca { flex-shrink: 0; }
.side nav { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.side details.grupo { margin-bottom: 2px; }
.side details.grupo summary {
  list-style: none; cursor: pointer; padding: 9px 12px; border-radius: 8px; color: var(--side-text);
  display: flex; justify-content: space-between; align-items: center;
}
.side details.grupo summary::-webkit-details-marker { display: none; }
.side details.grupo summary::after { content: "+"; font-size: 16px; opacity: .7; }
.side details.grupo[open] summary::after { content: "−"; }
.side details.grupo[open] summary { color: #fff; font-weight: 600; }
.side details.grupo summary:hover { background: rgba(255,255,255,.06); }
.side details.grupo a { padding: 7px 12px 7px 24px; font-size: 14px; }
.side .pie { flex-shrink: 0; margin-top: 10px; padding-top: 10px; border-top: 1px solid rgba(255,255,255,.08); font-size: 13px; }
.side .pie a { color: var(--side-text); padding: 6px 12px; display: inline-block; }
.main { flex: 1; min-width: 0; padding: 24px 28px 48px; }
.topbar { display: none; }

@media (max-width: 860px) {
  .app { display: block; }
  .side { display: none; position: fixed; inset: 0 auto 0 0; z-index: 20; width: 240px; }
  .side.abierto { display: flex; }
  .topbar {
    display: flex; align-items: center; gap: 12px; background: var(--side); color: #fff;
    padding: 10px 16px; position: sticky; top: 0; z-index: 10;
  }
  .topbar button { background: none; border: 0; color: #fff; font-size: 22px; cursor: pointer; }
  .main { padding: 16px; }
}

/* --- Componentes --- */
h1 { font-size: 22px; margin: 0 0 4px; }
.sub { color: var(--muted); margin: 0 0 20px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px;
}
.card h2 { font-size: 15px; margin: 0 0 14px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.grid { display: grid; gap: 16px; }
.grid > * { min-width: 0; } /* sin esto las gráficas ensanchan la columna en pantallas angostas */
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: 1fr; } }
@media (max-width: 700px) { .g4, .g2 { grid-template-columns: 1fr; } }

/* Tarjeta completa clicable: resalta al pasar el mouse y muestra "ver gráficas →". */
a.card-link { display: block; color: inherit; transition: border-color .15s, box-shadow .15s, transform .15s; }
a.card-link:hover { text-decoration: none; border-color: var(--accent); box-shadow: 0 6px 20px rgba(8, 145, 178, .14); transform: translateY(-1px); }
.card-link .ir { float: right; font-size: 12px; text-transform: none; letter-spacing: 0; color: var(--accent); opacity: 0; transition: opacity .15s; }
a.card-link:hover .ir, a.card-link:focus .ir { opacity: 1; }
@media (hover: none) { .card-link .ir { opacity: 1; } } /* en celular siempre visible */

/* Métrica compacta: nombre y valor, barra de uso y minigráfica (tarjetas del escritorio). */
.metrica { margin-bottom: 14px; }
.metrica:last-child { margin-bottom: 0; }
.m-cab { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 14px; color: var(--muted); }
.m-cab strong { color: var(--text); }
.m-barra { height: 6px; border-radius: 999px; background: var(--line); margin: 6px 0 4px; overflow: hidden; }
.m-barra i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.m-barra.alto i { background: var(--sec); }
.spark { position: relative; height: 42px; margin-top: 4px; }
.spark-alta { height: 70px; }
.zona-grafica { position: relative; height: 110px; margin: 8px 0 4px; }
.zona-franja { display: block; width: 100%; height: 6px; border-radius: 3px; margin-bottom: 6px; }

/* Tarjeta de salidas a internet */
.wan-sep { padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.wan-datos { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 8px; }
.wan-datos span { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.wan-datos strong { display: block; font-size: 14px; }
.wan-datos small { color: var(--muted); font-size: 12px; }
.nodos { display: grid; gap: 16px; }
/* a.card-link fija display:block; con más especificidad aquí para que la tarjeta sea de dos columnas. */
a.card-link.nodo { display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); gap: 24px; align-items: center; }
.nodo-grafica { min-width: 0; }
.nodo .grafica-nodo { height: 190px; }
@media (max-width: 900px) { a.card-link.nodo { grid-template-columns: 1fr; } .nodo .grafica-nodo { height: 160px; } }
.grafica-nodo { position: relative; height: 170px; margin: 6px 0 4px; }
.enlaces { margin-top: 10px; display: grid; gap: 4px; }
.enlace { display: flex; align-items: center; gap: 6px; font-size: 13px; min-width: 0; }
.enlace .punto { flex-shrink: 0; margin: 0; }
.enlace-nombre { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.enlace small { flex-shrink: 0; font-weight: 600; }
.wan-estado { font-size: 13px; font-weight: 600; margin: -2px 0 6px 16px; }
.wan-estado.bien { color: var(--ok); }
.wan-estado.mal { color: var(--bad); }
.wan-caida { margin: 6px 0 0; padding: 10px 12px; border-radius: 8px; background: var(--bad-soft); color: var(--bad); font-size: 13px; }
.wan-total { margin: 14px 0 0; padding-top: 12px; border-top: 1px solid var(--line); }

/* Ficha del cliente: «Vista factura». */
.resumen { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: 16px; }
@media (max-width: 860px) { .resumen { grid-template-columns: 1fr; } }
.res-saldo { display: flex; flex-direction: column; justify-content: center; gap: 6px; padding: 24px 26px; border-radius: 14px; border: 1px solid; }
.res-ok { background: var(--ok-soft); border-color: var(--ok); }
.res-debe { background: var(--bad-soft); border-color: var(--bad); }
.res-titulo { font-size: 15px; font-weight: 600; }
.res-monto { font-size: 34px; font-weight: 700; line-height: 1.1; }
.res-ok .res-monto { color: var(--ok); }
.res-debe .res-monto { color: var(--bad); }
.res-pie { color: var(--muted); font-size: 14px; }
.res-datos { margin: 0; }
.res-h2 { text-transform: none; letter-spacing: 0; font-size: 17px; color: var(--text); }

/* Ventana flotante (Registrar pago). */
dialog.ventana { width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 24px); padding: 0; overflow: auto; margin: auto;
  background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 24px 60px rgba(5, 8, 20, .35); }
dialog.ventana::backdrop { background: rgba(5, 8, 20, .55); }
dialog.ventana form { padding: 24px 26px; }
dialog.ventana h2 { margin: 0; font-size: 20px; text-transform: none; letter-spacing: 0; color: var(--text); }
.v-sub { margin: 4px 0 16px; font-size: 14px; }
.v-metodos { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.v-filas { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.v-filas[hidden], .form-fila[hidden] { display: none; }
.v-abona { margin: 4px 0 16px; padding: 12px 14px; border-radius: 10px; background: var(--accent-soft); }
.v-botones { display: flex; justify-content: flex-end; gap: 10px; }
.v-botones .btn[disabled] { opacity: .5; cursor: not-allowed; }
@media (max-width: 520px) { .v-filas { grid-template-columns: 1fr; } dialog.ventana form { padding: 20px 18px; } }

/* Tarjetas del escritorio: título, ícono, número y detalle. */
.tarjetas { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 16px; margin-bottom: 28px; }
@media (max-width: 1280px) { .tarjetas { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 860px) { .tarjetas { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 480px) { .tarjetas { grid-template-columns: 1fr; } }
.tarjeta { --t: var(--accent); --t-soft: var(--accent-soft); display: flex; flex-direction: column; gap: 8px; min-width: 0;
  padding: 18px 20px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; color: var(--text);
  text-decoration: none; transition: border-color .15s, box-shadow .15s, transform .15s; }
a.tarjeta:hover { border-color: var(--t); box-shadow: 0 6px 18px rgba(15, 23, 42, .08); transform: translateY(-1px); }
.tarjeta.t-ok { --t: var(--ok); --t-soft: var(--ok-soft); }
.tarjeta.t-warn { --t: var(--warn); --t-soft: var(--warn-soft); }
.tarjeta.t-bad { --t: var(--bad); --t-soft: var(--bad-soft); }
.t-cab { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 13px; font-weight: 600; }
.t-cab i { flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 11px; background: var(--t-soft); color: var(--t); }
.t-cab svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.t-num { font-size: 30px; font-weight: 700; line-height: 1.1; letter-spacing: -.01em; }
.t-pie { color: var(--muted); font-size: 12.5px; line-height: 1.35; }
.t-resalte { background: var(--t-soft); border-color: var(--t); }
.t-resalte .t-cab i { background: var(--t); color: var(--card); }
.t-mrr { background: var(--accent-soft); border-color: var(--accent); }
.t-mrr .t-cab i { background: var(--accent); color: var(--on-accent); }

.kpi { padding: 16px 18px; }
.kpi .num { font-size: 28px; font-weight: 700; line-height: 1.1; }
.kpi .lab { color: var(--muted); font-size: 13px; }
.kpi a { color: inherit; }

.tabla-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
tbody tr:hover { background: var(--accent-soft); }
td.num, th.num { text-align: right; }
th a.ordenar { color: inherit; text-decoration: none; white-space: nowrap; }
th a.ordenar span { opacity: .35; font-size: 11px; }
th a.ordenar:hover, th a.ordenar.activa { color: var(--accent); }
th a.ordenar.activa span, th a.ordenar:hover span { opacity: 1; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.b-ok { background: var(--ok-soft); color: var(--ok); }
.b-warn { background: var(--warn-soft); color: var(--warn); }
.b-bad { background: var(--bad-soft); color: var(--bad); }
.b-gris { background: var(--line); color: var(--muted); }
.punto { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.p-ok { background: var(--ok); }
.p-bad { background: var(--bad); }
.p-gris { background: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chip {
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card);
  color: var(--text); font-size: 13px;
}
.chip.activo { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.chip:hover { text-decoration: none; border-color: var(--accent); }

.barra { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
input:not([type]), input[type=text], input[type=search], input[type=email], input[type=number], input[type=password],
input[type=date], input[type=datetime-local], input[type=time], select, textarea {
  font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; min-width: 0;
}textarea { width: 100%; min-height: 90px; }
.barra input[type=search] { flex: 1; min-width: 220px; }
.btn {
  display: inline-block; font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); cursor: pointer;
}
.btn:hover { text-decoration: none; border-color: var(--accent); }
.btn-pri { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 10px 14px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.activo { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--text); }

.datos { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px 24px; }
.datos div span { display: block; color: var(--muted); font-size: 12px; }
.datos div strong { font-weight: 600; word-break: break-word; }

.lista-log { list-style: none; margin: 0; padding: 0; }
.lista-log li { padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.lista-log li:last-child { border-bottom: 0; }
.lista-log small { color: var(--muted); }

.grafica { position: relative; height: 260px; }
.rango { display: flex; gap: 6px; margin-bottom: 10px; }
.muted { color: var(--muted); }
.aviso { padding: 12px 14px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); margin-bottom: 16px; font-size: 14px; }
.paginas { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; color: var(--muted); font-size: 14px; }
.form-fila { margin-bottom: 14px; }
.form-fila label { display: block; font-weight: 600; margin-bottom: 4px; font-size: 14px; }
.form-fila input, .form-fila select { width: 100%; }
/* Las casillas no se estiran: van pegadas a su texto. */
.form-fila input[type=checkbox], .form-fila input[type=radio] { width: auto; flex: 0 0 auto; margin: 0; }
.form-fila .ayuda { color: var(--muted); font-size: 12px; }
.errorlist { color: var(--bad); margin: 4px 0 0; padding-left: 18px; font-size: 13px; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login { width: 100%; max-width: 380px; }
