@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500;600;700&family=Fira+Sans:wght@300;400;500;600;700&display=swap');

:root {
  --bg: #F1F5F9;
  --surface: #FFFFFF;
  --surface-2: #F8FAFC;
  --border: #E2E8F0;
  --text: #0F172A;
  --text-dim: #475569;
  --accent: #0891B2;
  --accent-bg: #ECFEFF;
  --ok: #16A34A;
  --ok-bg: #F0FDF4;
  --warn: #D97706;
  --warn-bg: #FFFBEB;
  --fail: #DC2626;
  --fail-bg: #FEF2F2;
  --radius: 14px;
  --sidebar-w: 230px;
  --shadow-sm: 0 1px 2px rgba(15,23,42,0.05);
  --shadow-md: 0 2px 6px rgba(15,23,42,0.06), 0 1px 2px rgba(15,23,42,0.05);
  --shadow-lg: 0 8px 24px rgba(15,23,42,0.10), 0 2px 6px rgba(15,23,42,0.06);
}

* { box-sizing: border-box; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Fira Sans", -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: "Fira Code", monospace; }

a { color: var(--accent); }

/* ---------------- Layout: sidebar + main ---------------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  padding: 18px 12px;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  display: flex;
  flex-direction: column;
  z-index: 20;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.sidebar .brand svg { color: var(--accent); flex-shrink: 0; }
.sidebar .brand span { font-weight: 700; font-size: 14px; letter-spacing: 0.3px; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  border-left: 3px solid transparent;
  background: none;
  width: 100%;
  text-align: left;
  transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
  font-family: inherit;
}
.nav-item svg { flex-shrink: 0; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.activo { background: var(--accent-bg); color: var(--accent); font-weight: 600; border-left-color: var(--accent); }

.sidebar .pie { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }
.pie-estado { width: 100%; justify-content: center; margin-bottom: 8px; }
.pie-salir { width: 100%; justify-content: center; }
.nav-badge { margin-left: auto; padding: 2px 8px; }

.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 28px 36px 48px;
  min-width: 0;
}
.vista.activa { max-width: 1320px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 22px; padding-bottom: 18px; gap: 14px; flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}
.btn-volver {
  display: inline-flex; align-items: center; gap: 6px;
  margin-bottom: 12px; font-size: 12.5px; padding: 6px 12px;
}
.topbar-titulo { display: flex; align-items: center; gap: 12px; }
.topbar-icono {
  display: flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  background: var(--accent-bg); color: var(--accent);
}
.topbar h1 { font-size: 19px; margin: 0; font-weight: 700; letter-spacing: -0.2px; }
.topbar .sub { font-size: 12.5px; color: var(--text-dim); margin-top: 3px; font-family: "Fira Sans", sans-serif; }

.vista { display: none; }
.vista.activa { display: block; }

.guia {
  background: var(--accent-bg);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--border));
  color: color-mix(in srgb, var(--accent) 70%, var(--text));
  box-shadow: var(--shadow-sm);
  border-radius: 10px;
  padding: 14px 18px;
  font-size: 13px;
  margin-bottom: 22px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.guia svg { flex-shrink: 0; margin-top: 1px; color: var(--accent); }

.filtro-banner {
  background: var(--surface);
  border: 1px solid var(--accent);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13px;
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.portal-pill-link:hover { color: var(--accent); }
.filtro-banner[hidden] { display: none; }

.card-head-dato { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.dato-vivo {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 600; color: var(--ok);
  background: var(--ok-bg); border: 1px solid color-mix(in srgb, var(--ok) 30%, var(--border));
  padding: 3px 9px; border-radius: 999px; white-space: nowrap;
}
.dato-vivo-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--ok);
  animation: pulso-vivo 2s ease-in-out infinite;
}
@keyframes pulso-vivo {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}
@media (prefers-reduced-motion: reduce) {
  .dato-vivo-dot { animation: none; }
}

.grid-fotos-perfil {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 8px; margin: 6px 0;
}
.foto-perfil-item { position: relative; }
.foto-perfil-item img, .foto-perfil-mini {
  width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px;
  border: 1px solid var(--border); display: block;
}
.foto-perfil-borrar {
  position: absolute; top: -6px; right: -6px; width: 22px; height: 22px;
  border-radius: 50%; padding: 0; line-height: 1; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}
.miga-link { cursor: pointer; color: var(--accent); }
.miga-link:hover { text-decoration: underline; }
.miga-sep { color: var(--text-dim); }

.buscador-tabla {
  width: 100%; max-width: 320px; margin-bottom: 14px;
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-family: "Fira Sans", sans-serif; font-size: 13px;
}

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--text); color: #fff; padding: 10px 20px; border-radius: 10px;
  font-size: 13px; box-shadow: var(--shadow-lg); z-index: 100;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
}
#toast.mostrado { opacity: 1; transform: translate(-50%, 0); }
#toast.fail { background: var(--fail); }

.aviso-exito {
  background: var(--ok-bg);
  border: 1px solid color-mix(in srgb, var(--ok) 35%, var(--border));
  color: color-mix(in srgb, var(--ok) 70%, var(--text));
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 13px;
  margin-bottom: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.aviso-exito[hidden] { display: none; }
.aviso-exito .acciones-aviso { display: flex; gap: 8px; flex-shrink: 0; }
.aviso-exito.fail {
  background: var(--fail-bg);
  border-color: color-mix(in srgb, var(--fail) 35%, var(--border));
  color: color-mix(in srgb, var(--fail) 70%, var(--text));
}

/* ---------------- Reusable components ---------------- */
.badge {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-family: "Fira Code", monospace;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.badge.ok { color: var(--ok); background: var(--ok-bg); border-color: color-mix(in srgb, var(--ok) 30%, var(--border)); }
.badge.warn { color: var(--warn); background: var(--warn-bg); border-color: color-mix(in srgb, var(--warn) 30%, var(--border)); }
.badge.fail { color: var(--fail); background: var(--fail-bg); border-color: color-mix(in srgb, var(--fail) 30%, var(--border)); }

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  border-radius: var(--radius);
  padding: 18px 20px;
  transition: border-color 150ms ease, box-shadow 150ms ease, transform 150ms ease;
}
.kpi:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.kpi .valor { font-size: 30px; font-weight: 700; font-family: "Fira Code", monospace; line-height: 1.2; }
.kpi .etiqueta { font-size: 12.5px; color: var(--text-dim); margin-top: 8px; line-height: 1.4; }

.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 24px; }
.charts .card { padding: 18px 20px 20px; }
.chart-wrap { position: relative; height: 240px; }
.chart-wrap canvas { max-height: 240px !important; }

.portales-chips { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 24px; }
.portal-chip {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm);
  border-radius: 999px;
  padding: 8px 16px; font-size: 12.5px; font-family: "Fira Code", monospace; cursor: pointer;
  transition: border-color 150ms ease, box-shadow 150ms ease, transform 150ms ease;
}
.portal-chip:hover { border-color: var(--accent); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.portal-chip .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.portal-chip .dot.ok { background: var(--ok); }
.portal-chip .dot.fallo { background: var(--fail); }
.portal-chip .dot.sin_acceso { background: #94A3B8; }

.kpi.clicable { cursor: pointer; }
.kpi.clicable:hover { border-color: var(--accent); box-shadow: 0 2px 8px rgba(8,145,178,0.12); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 18px;
}

h2 {
  font-size: 13px; margin: 0 0 16px 0; color: var(--text-dim); font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.6px; display: flex; align-items: center; gap: 8px;
  padding-bottom: 12px; border-bottom: 1px solid var(--border);
}
h2 .icon-btn { margin-left: auto; text-transform: none; letter-spacing: 0; }

.tabla-scroll {
  overflow-x: auto;
  background:
    linear-gradient(to right, var(--surface) 30%, rgba(255,255,255,0)) left,
    linear-gradient(to right, rgba(255,255,255,0), var(--surface) 70%) right;
  background-repeat: no-repeat;
  background-size: 24px 100%, 24px 100%;
  background-attachment: local, local;
}
.tabla-ancha { min-width: 760px; }
.grid-cards { display: grid; gap: 14px; }
.grid-cards-candidatas { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid-cards-pagos { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--text-dim); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; background: var(--surface-2); }
thead tr { border-bottom: 2px solid var(--border); }
tbody tr { transition: background-color 150ms ease; }
tbody tr:nth-child(even) { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
tbody tr:hover { background: var(--surface-2); }
td[data-label="Chica"], td:first-child { font-weight: 600; }

button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  margin-right: 6px;
  box-shadow: var(--shadow-sm);
  transition: filter 150ms ease, opacity 150ms ease, box-shadow 150ms ease, transform 100ms ease;
  font-family: inherit;
}
button:hover { filter: brightness(1.08); box-shadow: var(--shadow-md); }
button:active { filter: brightness(0.95); transform: translateY(1px); }
button.secundario { background: var(--surface); border: 1px solid var(--border); color: var(--text); }
button.secundario:hover { background: var(--surface-2); }
button.ok { background: var(--ok); }
button.fail { background: var(--fail); }
button:disabled { opacity: 0.45; cursor: default; }
.icon-btn { display: inline-flex; align-items: center; gap: 6px; }

select, input, textarea {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  margin-right: 6px;
  font-family: inherit;
  font-size: 13px;
}
select:focus, input:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.avatar {
  width: 38px; height: 38px; border-radius: 8px; object-fit: cover;
  flex-shrink: 0; display: block; background: var(--surface-2);
}
.avatar-vacio {
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim); border: 1px dashed var(--border);
}

.miniatura-candidata { width: 100%; height: 160px; object-fit: cover; border-radius: 8px; margin-bottom: 10px; display: block; }
.foto-fallback {
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2); color: var(--text-dim);
  border: 1px dashed var(--border); border-radius: 8px;
}
.foto-fallback.miniatura-candidata { width: 100%; height: 160px; margin-bottom: 10px; }
.foto-fallback.avatar { width: 38px; height: 38px; }

.estado-chip {
  font-size: 11px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border);
  font-family: "Fira Code", monospace;
}
.estado-chip.on { color: var(--ok); background: var(--ok-bg); border-color: color-mix(in srgb, var(--ok) 30%, var(--border)); }
.estado-chip.off { color: var(--text-dim); }
.estado-chip-btn {
  /* reset lo que hereda de la regla global `button` (fondo/color/padding solidos) -
     esto es un chip pastilla, no un boton de accion primaria */
  background: var(--surface-2); color: var(--text-dim); box-shadow: none;
  cursor: pointer; min-height: 26px; font-weight: 600; margin-right: 0;
  transition: filter 150ms ease, transform 100ms ease, background-color 150ms ease;
}
.estado-chip-btn.on { color: var(--ok); background: var(--ok-bg); border-color: color-mix(in srgb, var(--ok) 30%, var(--border)); }
.estado-chip-btn.off { color: var(--text-dim); background: var(--surface-2); }
.estado-chip-btn:hover { filter: brightness(0.96); }
.estado-chip-btn:active { transform: scale(0.97); }
.estado-chip-btn.off:hover { background: var(--border); }

.portales-cell { display: flex; flex-wrap: wrap; gap: 6px; }
.portal-pill {
  font-size: 11px; padding: 3px 9px; border-radius: 999px; font-family: "Fira Code", monospace;
  border: 1px solid var(--border); white-space: nowrap;
  display: inline-block; text-decoration: none;
}
.portal-pill.vivo { color: var(--ok); background: var(--ok-bg); border-color: color-mix(in srgb, var(--ok) 30%, var(--border)); font-weight: 600; }
.portal-pill.objetivo { color: var(--text-dim); background: var(--surface-2); }
a.portal-pill.vivo { cursor: pointer; }
a.portal-pill.vivo:hover { border-color: var(--ok); text-decoration: underline; }

.etiqueta { font-size: 12px; color: var(--text-dim); }

.lista-anuncios div { padding: 2px 0; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.lista-anuncios .estado-chip { flex-shrink: 0; }

/* ---- Modal ---- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,0.45); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-backdrop[hidden] { display: none; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; width: min(480px, 92vw); max-height: 85vh; overflow-y: auto; box-shadow: 0 20px 40px rgba(15,23,42,0.15); }
.modal label, .card form label { display: block; font-size: 12px; color: var(--text-dim); margin: 12px 0 4px; }
.card form input, .card form select { width: 100%; max-width: 420px; display: block; }
.card .acciones { margin-top: 14px; display: flex; align-items: center; gap: 10px; }
.modal input, .modal textarea, .modal select { width: 100%; }
.modal textarea { min-height: 70px; font-family: inherit; resize: vertical; }
.modal .acciones { margin-top: 18px; display: flex; justify-content: flex-end; gap: 8px; }

/* ---- Login ---- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px; width: min(320px, 90vw); text-align: center; box-shadow: 0 20px 40px rgba(15,23,42,0.08); }
.login-card h1 { margin-bottom: 4px; }
.login-card input { width: 100%; margin: 16px 0 8px; padding: 10px; }
.login-card button { width: 100%; padding: 10px; }
.error-msg { color: var(--fail); font-size: 13px; min-height: 18px; margin-top: 8px; }

/* ---- Hermes chat ---- */
.hermes-box { display: flex; flex-direction: column; gap: 10px; }
.hermes-box textarea { width: 100%; min-height: 90px; }
.hermes-log { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px; font-size: 12px; max-height: 160px; overflow-y: auto; }

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

.mobile-topbar { display: none; }
.mobile-overlay { display: none; }

@media (max-width: 900px) {
  .mobile-topbar {
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 40;
    background: var(--surface); border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    padding: 12px 16px;
  }
  .mobile-topbar-brand { display: flex; align-items: center; gap: 10px; color: var(--accent); font-weight: 700; font-size: 14px; }
  .mobile-topbar-brand svg { flex-shrink: 0; }
  .mobile-menu-btn {
    background: none; color: var(--text); box-shadow: none; margin: 0;
    padding: 8px; min-width: 44px; min-height: 44px;
    display: flex; align-items: center; justify-content: center;
  }
  .mobile-menu-btn:hover { background: var(--surface-2); filter: none; box-shadow: none; }

  .mobile-overlay[hidden] { display: none; }
  .mobile-overlay {
    display: block; position: fixed; inset: 0; top: 49px;
    background: rgba(15,23,42,0.4); z-index: 35;
  }

  .sidebar {
    display: none;
    position: fixed; top: 49px; left: 0; right: 0;
    width: 100%; height: auto; max-height: calc(100vh - 49px);
    overflow-y: auto;
    flex-direction: column; align-items: stretch;
    padding: 10px 12px 16px;
    border-right: none; border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    z-index: 36;
  }
  .sidebar.abierto { display: flex; }
  .sidebar .brand { display: none; }
  .nav-item {
    width: 100%; flex-shrink: 0;
    flex-direction: row; gap: 12px;
    padding: 12px 14px;
    font-size: 14px;
    min-height: 46px; justify-content: flex-start;
  }
  .nav-item .nav-label { white-space: nowrap; }
  .nav-badge { margin-left: auto !important; }
  .sidebar .pie {
    margin-top: 10px; padding-top: 12px; border-top: 1px solid var(--border);
    display: flex; flex-direction: column; align-items: stretch; gap: 8px;
  }
  .pie-estado { width: 100%; margin-bottom: 0; white-space: normal; justify-content: center; }
  .pie-salir { width: 100%; min-height: 44px; justify-content: center; }
  .pie-salir .nav-label { display: inline; }

  .app { flex-direction: column; }
  .main { margin-left: 0; padding: 14px; }

  .topbar h1 { font-size: 17px; }
  .kpis { grid-template-columns: repeat(auto-fit, minmax(145px, 1fr)); gap: 10px; }
  .kpi { padding: 12px 14px; }
  .kpi .valor { font-size: 21px; }
  .charts { grid-template-columns: 1fr; }
  .chart-wrap { height: 170px; }
  .chart-wrap canvas { max-height: 170px !important; }

  .grid-cards-candidatas, .grid-cards-pagos { grid-template-columns: 1fr; }

  .tabla-ancha { min-width: 0; }
  table, thead, tbody { display: block; width: 100%; }
  thead { display: none; }
  tr {
    display: block;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 10px;
  }
  td {
    border: none; padding: 6px 0;
    display: flex; flex-direction: column; gap: 4px;
    font-size: 14px;
  }
  td:not(:last-child) { border-bottom: 1px dashed var(--border); }
  td::before {
    content: attr(data-label);
    color: var(--text-dim); font-size: 10px;
    text-transform: uppercase; letter-spacing: 0.4px;
  }
  td select, td input { width: 100%; margin-right: 0; }
  td button { margin: 2px 6px 2px 0; }

  button { padding: 9px 14px; font-size: 13px; }
  select, input, textarea { font-size: 14px; padding: 8px 10px; }
}

@media (max-width: 480px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpi .valor { font-size: 19px; }
  .kpi .etiqueta { font-size: 11px; }
  .pie-estado { font-size: 11px; padding: 5px 10px; }
  .modal { padding: 18px; }
}
