/* Identidad RedesVIP (tomada de redesvip.com): índigo #1C0D66, morado #7F07A0→#B026D5, aguamarina #4FE0C0, fuente Nunito */
:root {
  --bg: #f6f3fb;
  --surface: #ffffff;
  --surface-2: #faf7fd;
  --border: #e7e1f0;
  --text: #1c1530;
  --muted: #6b6480;
  --primary: #7f07a0;
  --primary-hover: #6a0586;
  --primary-soft: #f3e3fa;
  --brand-dark: #1c0d66;
  --brand-grad: linear-gradient(135deg, #7f07a0 0%, #b026d5 100%);
  --accent: #4fe0c0;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --gray-soft: #e2e8f0;
  --sidebar: #1c0d66;
  --sidebar-text: #d8d0f0;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(28, 13, 102, .06), 0 2px 6px rgba(28, 13, 102, .07);
  font-family: "Nunito", "Nunito Sans", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }

.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px; flex-shrink: 0; background: var(--sidebar); color: var(--sidebar-text);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; color: #fff; font-weight: 700; font-size: 17px; }
.brand img { width: 32px; height: 32px; }
.brand small { font-weight: 700; color: var(--accent); font-size: 12px; }
nav { flex: 1; overflow-y: auto; padding: 4px 8px; }
nav .group { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #8f84b8; padding: 14px 10px 6px; }
nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: var(--sidebar-text); text-decoration: none; font-weight: 500;
}
nav a:hover { background: #2a1a80; color: #fff; text-decoration: none; }
nav a.active { background: var(--brand-grad); color: #fff; }
nav a .ic { width: 18px; text-align: center; }
.me { border-top: 1px solid #2f2190; padding: 12px 16px; font-size: 13px; }
.me b { color: #fff; display: block; }
.me .row { display: flex; gap: 12px; margin-top: 6px; }
.me a { color: var(--accent); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 14px 24px; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 19px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.menu-btn { display: none; }
.view { padding: 22px 24px 40px; max-width: 1400px; width: 100%; }

/* botones */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--brand-grad); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .6; cursor: wait; }
.icon-btn { border: 0; background: none; font-size: 20px; cursor: pointer; padding: 4px 8px; color: inherit; }

/* tarjetas */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-h h2 { font-size: 15px; margin: 0; }
.card-b { padding: 18px; }
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 16px; }
.kpi { padding: 16px 18px; }
.kpi .lbl { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi .val { font-size: 26px; font-weight: 700; margin-top: 6px; }
.kpi .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.cols-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

/* barras simples */
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 140px 1fr 48px; gap: 10px; align-items: center; font-size: 13px; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: var(--surface-2); border-radius: 4px; height: 10px; overflow: hidden; }
.bar-fill { background: var(--brand-grad); height: 100%; border-radius: 4px; }
.kpi { border-top: 3px solid var(--accent); }
.bar-row .n { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

/* filtros */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar .search { flex: 1; min-width: 220px; }
input, select, textarea {
  font: inherit; color: inherit; background: var(--surface); border: 1px solid #cbd5e1; border-radius: 8px;
  padding: 8px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
input[type=checkbox] { width: auto; }
.toolbar select { width: auto; min-width: 150px; }
textarea { min-height: 70px; resize: vertical; }

/* tablas */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--surface-2); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); white-space: nowrap; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
tbody tr:hover { background: #f8faff; }
tr.clickable { cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td .sub { color: var(--muted); font-size: 12px; }
.empty { text-align: center; color: var(--muted); padding: 36px 10px; }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; color: var(--muted); gap: 10px; flex-wrap: wrap; }
.pager .btns { display: flex; gap: 6px; align-items: center; }

/* etiquetas */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-activo { background: var(--ok-soft); color: var(--ok); }
.b-pendiente { background: var(--warn-soft); color: var(--warn); }
.b-suspendido { background: var(--danger-soft); color: var(--danger); }
.b-baja, .b-inactivo { background: var(--gray-soft); color: var(--muted); }
.b-rol { background: var(--primary-soft); color: var(--primary); }

/* formularios */
.form-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 14px 16px; }
.field { grid-column: span 4; display: flex; flex-direction: column; gap: 5px; }
.field.s2 { grid-column: span 2; } .field.s3 { grid-column: span 3; } .field.s6 { grid-column: span 6; } .field.s8 { grid-column: span 8; } .field.s12 { grid-column: span 12; }
.field label { font-weight: 600; font-size: 13px; }
.field label .req { color: var(--danger); }
.field .help { color: var(--muted); font-size: 12px; }
.field .err { color: var(--danger); font-size: 12px; }
.field.has-err input, .field.has-err select, .field.has-err textarea { border-color: var(--danger); }
.field.check { flex-direction: row; align-items: center; gap: 8px; padding-top: 24px; }
.form-section { grid-column: span 12; font-weight: 700; font-size: 13px; color: var(--primary); text-transform: uppercase; letter-spacing: .05em; border-bottom: 1px solid var(--border); padding: 10px 0 6px; margin-top: 6px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.form-error { background: var(--danger-soft); color: var(--danger); padding: 10px 12px; border-radius: 8px; margin-bottom: 14px; font-weight: 600; }

/* detalle */
.dl { display: grid; grid-template-columns: 150px 1fr; gap: 8px 14px; margin: 0; }
.dl dt { color: var(--muted); font-size: 13px; }
.dl dd { margin: 0; word-break: break-word; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.timeline li:last-child { border-bottom: 0; }
.timeline .when { color: var(--muted); font-size: 12px; }
.timeline .chg { color: var(--muted); font-size: 12px; margin-top: 3px; word-break: break-word; }

/* modal y aviso */
.modal { border: 0; border-radius: 14px; padding: 0; width: min(720px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal::backdrop { background: rgba(15, 23, 42, .45); }
.modal .card-b { max-height: 75vh; overflow-y: auto; }
.toast {
  position: fixed; bottom: 20px; right: 20px; background: var(--text); color: #fff; padding: 12px 18px;
  border-radius: 10px; box-shadow: var(--shadow); z-index: 100; max-width: 380px; font-weight: 500;
}
.toast.err { background: var(--danger); }

/* acceso */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; width: 100%; background: radial-gradient(circle at 20% 10%, #3a1a9a 0%, var(--brand-dark) 55%, #0e0640 100%); }
.view:has(.auth-wrap) { padding: 0; max-width: none; }
.auth-card { width: min(400px, 100%); }
.auth-card .brand { color: var(--text); justify-content: center; padding: 26px 0 6px; font-size: 22px; }
.auth-card .brand img { width: 44px; height: 44px; }
.auth-card p { color: var(--muted); text-align: center; margin: 0 0 6px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
.mono { font-family: Consolas, "Cascadia Mono", monospace; font-size: 13px; }

/* Fase 2: cobranza */
h3 { font-size: 14px; margin: 18px 0 8px; color: var(--primary); }
.cli-pick { display: flex; justify-content: space-between; width: 100%; margin-bottom: 6px; text-align: left; white-space: normal; }
#bres { display: flex; flex-direction: column; }
.recibo { max-width: 720px; }
.recibo-h { display: flex; gap: 14px; align-items: center; margin-bottom: 10px; font-size: 13px; }
.recibo-h img { width: 54px; height: 54px; }
.recibo h2 { font-size: 17px; margin: 10px 0; }
.recibo table { margin: 12px 0; }
tfoot th, tfoot td { background: var(--surface-2); }
.firmas { display: flex; justify-content: space-between; margin-top: 50px; gap: 20px; flex-wrap: wrap; }
label > input[type=date] { width: auto; margin-left: 6px; }
.wifi-box { padding: 10px 0; border-bottom: 1px solid var(--border); }
.wifi-box:last-child { border-bottom: 0; }
.wifi-red { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-top: 10px; }
.wifi-titulo { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.pw { display: flex; gap: 6px; }
.chk { display: flex; gap: 8px; align-items: center; padding: 4px 0; font-weight: 400; }
.mat-row { display: grid; grid-template-columns: 1fr 120px; gap: 10px; align-items: center; padding: 4px 0; }
.timeline li.muted { color: var(--muted); }
.onu-box { padding: 10px 0; border-bottom: 1px solid var(--border); }
.onu-box:last-child { border-bottom: 0; }
.onu-box .dl { margin: 8px 0; }
/* Conexión directa a la OLT */
.olt-card { margin-top: 16px; }
.olt-box { padding: 10px 0; border-bottom: 1px solid var(--border); }
.olt-box:last-child { border-bottom: 0; }
.olt-out:not(:empty) { margin-top: 10px; }
.olt-pre { white-space: pre; overflow: auto; max-height: 380px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; font-family: Consolas, "Cascadia Mono", monospace; font-size: 12px; line-height: 1.45; margin: 8px 0; }
.olt-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin-bottom: 10px; }
.olt-grid > div { display: flex; flex-direction: column; gap: 2px; }
.olt-pasos { margin: 6px 0 6px 18px; }
.olt-avisos { margin: 4px 0 10px 0; padding-left: 4px; list-style: none; color: var(--warn, #9a6700); }
.olt-avisos li { padding: 2px 0; }
.nowrap { white-space: nowrap; }
.sm-val { font-size: 16px !important; }
.msg-wa { max-width: 420px; font-size: 13px; white-space: pre-wrap; }
.acciones-wa { white-space: nowrap; }
.acciones-wa .btn { margin: 2px 0; }
form.plantilla + form.plantilla { margin-top: 10px; }
/* Mapa de clientes y cajas NAP */
.mapa { height: 70vh; min-height: 420px; border-radius: 12px; border: 1px solid var(--border); overflow: hidden; z-index: 0; }
.mapa-leyenda { gap: 16px; }
.mapa-leyenda .chk { padding: 2px 0; }
.punto { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.25); }
.punto-verde { background: #1f9d55; }
.punto-amarillo { background: #e5b301; }
.punto-purpura { background: #7F07A0; }
.punto-rojo { background: #d63031; }
.punto-gris { background: #8a8f98; }
.caja-nap { display: inline-block; width: 12px; height: 12px; background: #1C0D66; border: 2px solid #4FE0C0; border-radius: 2px; box-sizing: border-box; }
.leaflet-container .caja-nap { width: 14px; height: 14px; }
.leaflet-container .caja-nap.con-alarma { width: 18px; height: 18px; background: #d63031; border-color: #fff; box-shadow: 0 0 0 3px rgba(214,48,49,.45); animation: latido 1.4s ease-in-out infinite; }
@keyframes latido { 50% { box-shadow: 0 0 0 7px rgba(214,48,49,.15); } }
/* Alarmas de red */
.monitor-estado p { margin: 4px 0; }
.titulo-alarmas { margin: 22px 0 2px; font-size: 16px; }
.alarma { background: var(--card, #fff); border: 1px solid var(--border); border-left: 5px solid #8a8f98; border-radius: 10px; padding: 10px 14px; margin: 8px 0; }
.alarma > summary { cursor: pointer; line-height: 1.7; }
.alarma-troncal { border-left-color: #d63031; }
.alarma-caja, .alarma-grupo { border-left-color: #e17055; }
.alarma-fibra { border-left-color: #7F07A0; }
.alarma-apagon { border-left-color: #8a8f98; }
.alarma-senal { border-left-color: #e5b301; }
.tabla-compacta td, .tabla-compacta th { padding: 4px 8px; font-size: 13px; }
form.buscar { display: inline-flex; gap: 6px; margin-left: auto; }
form.buscar input { min-width: 260px; }
/* Panel de señal de la ONT */
.senal-panel { max-width: 560px; }
.senal-cab { display: flex; align-items: center; gap: 10px; }
.senal-dist { margin-left: auto; font-size: 16px; }
.pot-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pot-caja { border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; }
.pot-valor { font-size: 22px; font-weight: 700; }
.pot-valor small { font-size: 12px; font-weight: 400; color: var(--muted); }
.pot-verde { color: #1f9d55; } .pot-amarillo { color: #c99a00; } .pot-rojo { color: #d63031; } .pot-gris { color: #8a8f98; }
.pot-barra { position: relative; height: 6px; margin-top: 6px; border-radius: 3px; background: linear-gradient(90deg, #d63031 0 17%, #e5b301 17% 25%, #1f9d55 25% 100%); }
.pot-barra span { position: absolute; top: -4px; width: 3px; height: 14px; margin-left: -1px; background: #222; border-radius: 1px; }
.h24 { position: relative; height: 12px; border-radius: 4px; background: #1f9d55; overflow: hidden; margin-top: 4px; }
.h24-caida { position: absolute; top: 0; bottom: 0; background: #d63031; }
.h24-luz { background: #8a8f98; }
.h24-titulo { margin-top: 10px; }
.texto-alarma { color: #d63031; }
.h24-horas { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.senal-tabla { margin-top: 10px; width: 100%; }
@media (max-width: 520px) { .pot-grid { grid-template-columns: 1fr; } form.buscar input { min-width: 0; width: 100%; } }
@media print {
  .sidebar, .topbar, .toast, #modal { display: none !important; }
  body, .app, .main, .view { background: #fff; padding: 0; margin: 0; }
  .card { box-shadow: none; border: 0; }
  .badge { border: 1px solid #999; }
}

@media (max-width: 900px) {
  .sidebar { position: fixed; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-block; }
  .topbar { padding: 12px 16px; flex-wrap: wrap; }
  .view { padding: 16px; }
  .field, .field.s2, .field.s3, .field.s6, .field.s8 { grid-column: span 12; }
  .dl { grid-template-columns: 1fr; gap: 2px; }
  .dl dd { margin-bottom: 8px; }
  .bar-row { grid-template-columns: 100px 1fr 40px; }
}
