:root {
  --navy: #0f1b33;
  --navy-light: #182a4d;
  --blue: #2f6fed;
  --blue-dark: #2457c4;
  --bg: #f4f6fb;
  --border: #e2e6f0;
  --text: #1c2333;
  --text-muted: #6b7280;
  --green: #1f9d55;
  --amber: #d97706;
  --red: #dc2626;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

html, body { height: 100%; }

.layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 230px;
  background: var(--navy);
  color: #cfd8ee;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  overflow: hidden;
  z-index: 100;
}
.sidebar .brand {
  padding: 18px 18px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sidebar .brand img {
  max-width: 100%;
  height: auto;
  max-height: 90px;
  border-radius: 6px;
}
.sidebar nav { flex: 1; padding: 10px 0; overflow-y: auto; }
.sidebar a {
  display: block;
  padding: 10px 18px;
  color: #b9c4e0;
  text-decoration: none;
  font-size: 14px;
  border-left: 3px solid transparent;
}
.sidebar a:hover { background: var(--navy-light); color: #fff; }
.sidebar a.active {
  background: var(--navy-light);
  color: #fff;
  border-left-color: var(--blue);
  font-weight: 600;
}
.sidebar .user-box {
  padding: 14px 18px;
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: 12.5px;
  color: #9fb0d6;
  flex-shrink: 0;
}
.sidebar .user-box strong { display: block; color: #fff; font-size: 13.5px; }
.menu-badge {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 6px;
  border-radius: 8px;
  background: rgba(255,255,255,.12);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .03em;
  vertical-align: middle;
}
.sidebar .role-badge {
  display: inline-block;
  margin-top: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(47,111,237,.25);
  color: #9fc0ff;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.sidebar .logout { color: #ff9d9d; font-size: 12.5px; }

/* Main */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; margin-left: 230px; }
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 16px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.topbar h1 { font-size: 19px; margin: 0; }
.content { padding: 24px 28px; flex: 1; }

/* Iconos y desplegables de la barra superior */
.topbar-icons { display: flex; align-items: center; gap: 6px; }
.icon-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 8px 10px;
  border-radius: 8px;
  text-decoration: none;
  font-family: inherit;
  font-size: 13px;
}
.icon-btn:hover { background: var(--bg); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; flex-shrink: 0; }
.icon-btn-label { font-weight: 600; white-space: nowrap; }
.icon-dropdown { position: relative; }
.dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(15,27,51,.12);
  min-width: 180px;
  padding: 6px;
  z-index: 200;
}
.dropdown-menu.open { display: block; }
.dropdown-menu a {
  display: block;
  padding: 9px 12px;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
}
.dropdown-menu a:hover { background: var(--bg); }


/* Cards / stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: #fff;
  border: 1px solid var(--border);
  border-left: 5px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  transition: transform .15s;
}
.stat-card:hover { transform: translateY(-2px); }
.stat-card .label { font-size: 12.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; }
.stat-card .value { font-size: 28px; font-weight: 800; margin-top: 4px; }

.stat-blue   { border-left-color: #2f6fed; } .stat-blue   .value { color: #2f6fed; }
.stat-green  { border-left-color: #0f9d58; } .stat-green  .value { color: #0f9d58; }
.stat-red    { border-left-color: #dc2626; } .stat-red    .value { color: #dc2626; }
.stat-purple { border-left-color: #9333ea; } .stat-purple .value { color: #9333ea; }
.stat-teal   { border-left-color: #0d9488; } .stat-teal   .value { color: #0d9488; }
.stat-amber  { border-left-color: #d97706; } .stat-amber  .value { color: #d97706; }

.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
}
.card h2 { margin-top: 0; font-size: 15px; }
a.card:hover { box-shadow: 0 4px 14px rgba(15,27,51,.1); border-color: var(--blue); }

/* Table */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; }
tr:hover td { background: #fafbff; }

/* Badges */
.badge { padding: 3px 9px; border-radius: 10px; font-size: 12px; font-weight: 600; display: inline-block; }
.badge-pendiente, .badge-nuevo, .badge-abierta, .badge-nulo, .badge-scoring, .badge-contactar { background: #fff3cd; color: var(--amber); }
.badge-activa, .badge-activo, .badge-convertido, .badge-cerrada, .badge-renovado, .badge-recuperado_misma_cia, .badge-recuperado_otra_cia { background: #d9f5e2; color: var(--green); }
.badge-baja, .badge-cancelada, .badge-perdida, .badge-incidencia { background: #fde2e2; color: var(--red); }
.badge-en_proceso, .badge-contactado, .badge-en_negociacion, .badge-renovada, .badge-pendiente_firma, .badge-pendiente_carga, .badge-en_activacion, .badge-agendado { background: #dde7ff; color: var(--blue-dark); }
.badge-administrador { background: #ffe1cf; color: #b5540c; }
.badge-jefe_equipo { background: #dde7ff; color: var(--blue-dark); }
.badge-comercial { background: #e6e9f2; color: #454b5c; }

/* Buttons & forms */
.btn {
  display: inline-block;
  padding: 9px 16px;
  border-radius: 7px;
  background: var(--blue);
  color: #fff;
  border: none;
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: var(--blue-dark); }
.btn-secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #f0f2f8; }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters select, .filters a { font-size: 12.5px; }
.filters select {
  width: auto;
  max-width: 150px;
  padding: 6px 8px;
}

form .field { margin-bottom: 14px; }
form label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: var(--text-muted); }
form input, form select, form textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 14px;
  font-family: inherit;
}
form textarea { min-height: 80px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-actions { margin-top: 18px; display: flex; gap: 10px; }

.flash { padding: 11px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.flash-success { background: #d9f5e2; color: var(--green); }
.flash-error { background: #fde2e2; color: var(--red); }

.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--navy);
}
.login-box { background: #fff; padding: 36px 32px; border-radius: 12px; width: 340px; }
.login-box h1 { font-size: 18px; margin-bottom: 4px; }
.login-box p.sub { color: var(--text-muted); font-size: 13px; margin-top: 0; margin-bottom: 22px; }

.empty { color: var(--text-muted); padding: 30px 0; text-align: center; font-size: 14px; }
a.link { color: var(--blue); text-decoration: none; font-size: 13.5px; }
a.link:hover { text-decoration: underline; }

/* Pop-up de noticias / avisos al abrir el CRM */
@keyframes noticiaEntrada {
  from { opacity: 0; transform: scale(.92) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes noticiaFondo {
  from { opacity: 0; }
  to { opacity: 1; }
}
.noticias-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 27, 51, .72);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: noticiaFondo .25s ease-out;
}
.noticias-modal {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 440px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 0 0 24px 0;
  box-shadow: 0 25px 60px rgba(0,0,0,.35);
  animation: noticiaEntrada .3s cubic-bezier(.34,1.56,.64,1);
  border: 3px solid var(--blue);
}
.noticias-header {
  background: linear-gradient(135deg, var(--navy) 0%, var(--blue) 100%);
  padding: 22px 24px 18px 24px;
  border-radius: 13px 13px 0 0;
  text-align: center;
}
.noticias-header .icono {
  font-size: 34px;
  display: block;
  margin-bottom: 6px;
}
.noticias-header h2 {
  color: #fff;
  margin: 0;
  font-size: 17px;
  letter-spacing: .02em;
  text-transform: uppercase;
}
.noticias-body { padding: 20px 24px 0 24px; }
.noticia-bloque {
  margin-bottom: 16px;
  background: #fff8e6;
  border-left: 4px solid var(--amber);
  border-radius: 8px;
  padding: 14px 16px;
}
.noticia-bloque:last-of-type { margin-bottom: 20px; }
.noticia-bloque h3 { margin: 0 0 10px 0; font-size: 15.5px; color: var(--text); }
.noticia-bloque ul { margin: 0; padding-left: 18px; }
.noticia-bloque li { font-size: 13.5px; color: var(--text); margin-bottom: 6px; line-height: 1.4; }
.noticia-imagenes { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.noticia-imagenes img { width: 100%; border-radius: 8px; display: block; box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.noticias-body .btn { font-size: 15px; padding: 12px; }

.badge-select {
  width: auto;
  font-size: 12.5px;
  padding: 5px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
}
