/* Sistema de diseño Atlas — alineado con la web de las apps (bateria_web_excesos). */
:root {
  --bg:      #f4f5f7;
  --surface: #ffffff;
  --border:  #dde1e7;
  --text:    #1a1f2e;
  --muted:   #6b7280;
  --primary: #c31667;
  --accent:  #a01255;
  --success: #16a34a;
  --warning: #d97706;
  --danger:  #dc2626;
  --radius:  8px;
  --shadow:  0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

header.appbar {
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  box-shadow: 0 2px 8px rgba(163, 18, 85, .35);
}
.appbar-inner {
  padding: 0.5rem 2rem 0.5rem 1rem;
  display: flex; align-items: center; gap: 1rem;
}
.appbar-logo { height: 66px; width: auto; display: block; }
.appbar-sep { width: 1px; height: 26px; background: rgba(255,255,255,.35); }
.appbar-titulos { display: flex; flex-direction: column; }
.appbar-titulos h1 { color: #fff; font-size: 0.95rem; font-weight: 700; letter-spacing: .02em; line-height: 1.3; }
.appbar-titulos .lema { color: rgba(255,255,255,.75); font-size: 0.65rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 600; }
@media (max-width: 560px) {
  .appbar-inner { gap: 0.6rem; padding: 0.5rem 1rem; }
  .appbar-logo { height: 28px; }
}

/* Barra de navegación bajo la cabecera */
.nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 1.5rem;
  padding: 0 2rem; height: 48px;
  line-height: normal;
}
.nav a.navlink {
  color: var(--text); font-weight: 600; font-size: 0.8rem;
  text-transform: uppercase; letter-spacing: 0.04em;
  padding: 0.4rem 0; border-bottom: 2px solid transparent;
}
.nav a.navlink:hover { color: var(--primary); text-decoration: none; }
/* Desplegable de navegación (Estudios) — el botón imita a .navlink */
.nav .navdd { position: relative; display: inline-flex; align-items: center; }
.nav .navdd-btn {
  background: none; border: none; cursor: pointer; font-family: inherit;
  color: var(--text); font-weight: 600; font-size: 0.8rem;
  text-transform: uppercase; letter-spacing: 0.04em;
  padding: 0.4rem 0; border-bottom: 2px solid transparent;
}
.nav .navdd-btn .caret { font-size: 0.7rem; }
.nav .navdd:hover .navdd-btn,
.nav .navdd:focus-within .navdd-btn { color: var(--primary); }
.nav .navdd-menu {
  display: none; position: absolute; top: 100%; left: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  min-width: 230px; padding: 0.4rem; z-index: 100;
}
.nav .navdd:hover .navdd-menu,
.nav .navdd:focus-within .navdd-menu { display: flex; flex-direction: column; }
.nav .navdd-menu a {
  color: var(--text); font-size: 0.82rem; font-weight: 500;
  padding: 0.5rem 0.7rem; border-radius: 6px;
}
.nav .navdd-menu a:hover { background: #fdf4ff; color: var(--primary); text-decoration: none; }
.nav .navdd-menu .sep { border-top: 1px solid var(--border); margin: 0.3rem 0; }

.nav .spacer { flex: 1; }
.nav .user { color: var(--muted); font-size: 0.8rem; }
.nav .user strong { color: var(--text); }
.nav a.logout {
  font-size: 0.75rem; font-weight: 600; color: var(--muted);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.3rem 0.8rem; text-transform: uppercase; letter-spacing: 0.04em;
}
.nav a.logout:hover { color: var(--primary); border-color: var(--primary); text-decoration: none; }

.container { max-width: 1280px; margin: 0 auto; padding: 2rem; }
.container h1 { font-size: 1.4rem; margin-bottom: 1.25rem; }
.crumb { font-size: 0.8rem; margin-bottom: 0.75rem; }

/* Tarjetas KPI */
.cards {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem; margin-bottom: 1.5rem;
}
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow);
}
.card .label { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.card .value { font-size: 1.5rem; font-weight: 700; margin-top: 0.25rem; }
.card.green .value { color: var(--success); }
.card.blue  .value { color: #2563eb; }

/* Secciones */
.section {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.5rem; margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}
.section h2 {
  font-size: 0.7rem; font-weight: 600; margin-bottom: 1.25rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.05em;
}
.section.placeholder { background: #fafbfc; border-style: dashed; }
.section.placeholder p { color: var(--muted); }

/* Ficha clave-valor */
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 0.5rem 1rem; }
.kv dt { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.kv dd { margin: 0; }

/* Tablas */
table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
th {
  background: #fafbfc; padding: 0.5rem 0.75rem; text-align: left;
  color: var(--muted); font-weight: 600; font-size: 0.7rem;
  text-transform: uppercase; letter-spacing: 0.04em; border-bottom: 1px solid var(--border);
}
td { padding: 0.55rem 0.75rem; text-align: left; border-bottom: 1px solid #f3f4f6; }
tbody tr.clickable:hover td { background: #fdf4ff; cursor: pointer; }
td a { font-weight: 500; }

.pill { display: inline-block; padding: 0.1rem 0.6rem; border-radius: 999px; font-size: 0.7rem; font-weight: 700; }
.pill-activo { background: #dcfce7; color: #16a34a; }
.pill-lead   { background: #fef9c3; color: #a16207; }
.pill-baja   { background: #fee2e2; color: #b91c1c; }

.muted { color: var(--muted); }
.small { font-size: 0.78rem; }

/* Búsqueda */
.search { display: flex; gap: 0.5rem; margin-bottom: 1.25rem; align-items: center; }
.search input {
  flex: 0 0 340px; background: #fafbfc; border: 1px solid var(--border);
  padding: 0.6rem 0.75rem; border-radius: var(--radius); font-size: 0.875rem;
}
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(195,22,103,.12); }

button.primary, .search button {
  background: var(--primary); color: #fff; border: none;
  padding: 0.6rem 1.5rem; border-radius: var(--radius);
  font-size: 0.875rem; font-weight: 600; cursor: pointer; transition: background .15s;
}
button.primary:hover, .search button:hover { background: var(--accent); }
.search .clear { font-size: 0.8rem; }

/* Login */
.login-wrap { display: flex; justify-content: center; padding-top: 3rem; }
.login {
  width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 2rem;
}
.login h1 { font-size: 1.2rem; margin-bottom: 0.25rem; }
.login .muted { margin-bottom: 1rem; }
.login label { display: block; font-size: 0.7rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; margin: 1rem 0 0.35rem; }
.login input {
  width: 100%; background: #fafbfc; border: 1px solid var(--border);
  padding: 0.6rem 0.75rem; border-radius: var(--radius); font-size: 0.875rem;
}
.login input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(195,22,103,.12); }
.login button { width: 100%; margin-top: 1.5rem; }
.login .logo { text-align: center; margin-bottom: 1rem; }
.login .logo img { height: 44px; }
.error {
  background: #fff5f5; border: 1px solid var(--danger); border-left: 3px solid var(--danger);
  border-radius: var(--radius); padding: 0.75rem 1rem; color: #991b1b; font-size: 0.875rem; margin-top: 0.75rem;
}

/* Formularios de módulo */
.form-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem; margin-bottom: 1rem;
}
.form-group { display: flex; flex-direction: column; gap: 0.35rem; }
.form-group label {
  font-size: 0.7rem; color: var(--muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.form-group input, .form-group select {
  background: #fafbfc; border: 1px solid var(--border);
  padding: 0.6rem 0.75rem; border-radius: var(--radius); font-size: 0.875rem;
}
.form-group input:focus, .form-group select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(195,22,103,.12);
}
.form-divider {
  font-size: 0.7rem; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.05em;
  border-top: 1px solid var(--border); padding-top: 1rem; margin: 1rem 0 0.75rem;
}
.form-note { margin-top: 0.5rem; }

/* Botones de módulo (lanzar desde ficha) */
.btn-module {
  display: inline-block; background: var(--primary); color: #fff;
  padding: 0.45rem 1.1rem; border-radius: var(--radius);
  font-size: 0.8rem; font-weight: 600; text-decoration: none;
}
.btn-module:hover { background: var(--accent); text-decoration: none; }

/* Colores de ahorro en tabla */
.green { color: var(--success); font-weight: 600; }

/* SIPS — cabecera de punto de suministro y rejilla de potencias */
.ps-head {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.ps-head .cups {
  font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
  font-size: 1.05rem; font-weight: 700; letter-spacing: 0.02em;
  background: #fafbfc; border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.4rem 0.7rem;
}
.tag {
  display: inline-block; padding: 0.25rem 0.7rem; border-radius: 999px;
  font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
  background: #fdf4ff; color: var(--primary);
}
.tag.gray { background: #f1f3f5; color: var(--muted); }

/* Rejilla compacta de potencias (P1-P6) */
.pot-grid {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 0.6rem;
  margin-top: 0.25rem;
}
.pot-grid .pot {
  background: #fafbfc; border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.7rem 0.5rem; text-align: center;
}
.pot-grid .pot .p { font-size: 0.68rem; color: var(--muted); font-weight: 600; letter-spacing: 0.04em; }
.pot-grid .pot .v { font-size: 1.15rem; font-weight: 700; margin-top: 0.15rem; }
.pot-grid .pot .v .u { font-size: 0.7rem; font-weight: 500; color: var(--muted); }
@media (max-width: 720px) { .pot-grid { grid-template-columns: repeat(3, 1fr); } }

.pot-grid.pot-grid-7 { grid-template-columns: repeat(7, 1fr); gap: 0.4rem; }
.pot-grid.pot-grid-7 .pot { padding: 0.5rem 0.3rem; }
.pot-grid.pot-grid-7 .pot .v { font-size: 0.92rem; }
.pot-grid.pot-grid-7 .pot .v .u { font-size: 0.6rem; }
.pot-grid .pot.total {
  background: #fdf4ff; border-color: var(--primary);
}
.pot-grid .pot.total .p { color: var(--primary); }
@media (max-width: 560px) { .pot-grid.pot-grid-7 { grid-template-columns: repeat(4, 1fr); } }

.section .subhead {
  font-size: 0.7rem; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.05em;
  margin: 1.5rem 0 0.6rem;
}
.section .subhead:first-child { margin-top: 0; }

.section-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1.25rem;
}
.section-head h2 { margin-bottom: 0; }
.section-head h1 { margin-bottom: 0; }

/* Facturas archivadas (desplegable por CUPS) */
details.facturas { margin-bottom: .5rem; }
details.facturas > summary {
  cursor: pointer; padding: .4rem 0; font-weight: 600;
}
details.facturas[open] > summary { margin-bottom: .5rem; }

/* Pill para tipo de módulo */
.pill-modulo { background: #fdf4ff; color: var(--primary); }

/* ── Fase 6: pipeline comercial ──────────────────────────────────────────── */

/* Selector dentro de la barra de búsqueda */
.search select {
  background: #fafbfc; border: 1px solid var(--border);
  padding: 0.6rem 0.75rem; border-radius: var(--radius); font-size: 0.875rem;
}

/* Pills de estado (leads y oportunidades) */
.pill.estado-nuevo,       .pill.estado-abierta     { background: #e0f2fe; color: #0369a1; }
.pill.estado-contactado,  .pill.estado-propuesta   { background: #ede9fe; color: #6d28d9; }
.pill.estado-cualificado                           { background: #fef9c3; color: #a16207; }
.pill.estado-negociacion                           { background: #ffedd5; color: #c2410c; }
.pill.estado-convertido,  .pill.estado-ganada      { background: #dcfce7; color: #16a34a; }
.pill.estado-descartado,  .pill.estado-perdida     { background: #fee2e2; color: #b91c1c; }

.danger-text { color: var(--danger); }

/* Rejillas y utilidades de formulario */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }
.stack { display: flex; flex-direction: column; gap: 0.6rem; margin-bottom: 1rem; }
.form-row { display: flex; gap: 0.6rem; }
.stack input, .stack select, .stack textarea {
  background: #fafbfc; border: 1px solid var(--border);
  padding: 0.55rem 0.7rem; border-radius: var(--radius); font-size: 0.85rem; font-family: inherit;
}
label.inline { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; }

/* Timeline de actividades */
.timeline { list-style: none; margin-top: 1rem; }
.timeline li { padding: 0.6rem 0; border-bottom: 1px solid #f3f4f6; }
.timeline li:last-child { border-bottom: none; }

/* Lista de tareas */
.tasklist { list-style: none; margin-top: 1rem; }
.tasklist li { display: flex; align-items: center; gap: 0.5rem; padding: 0.45rem 0; border-bottom: 1px solid #f3f4f6; }
.tasklist li.done .t-titulo { text-decoration: line-through; color: var(--muted); }
.tasklist .t-titulo { flex: 1; }
button.check {
  background: none; border: none; cursor: pointer; font-size: 1.05rem; line-height: 1;
  color: var(--primary); padding: 0;
}
tr.overdue td { background: #fff5f5; }
tr.done td { color: var(--muted); }

/* Pestañas */
.tabs { display: flex; gap: 0.4rem; }
.tabs .tab {
  font-size: 0.78rem; font-weight: 600; color: var(--muted);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0.35rem 0.9rem;
  text-transform: uppercase; letter-spacing: 0.03em;
}
.tabs .tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.tabs .tab:hover { text-decoration: none; }

/* Tablero kanban de oportunidades */
.kanban { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.75rem; align-items: start; }
@media (max-width: 1100px) { .kanban { grid-template-columns: repeat(2, 1fr); } }
.kanban-col { background: #fafbfc; border: 1px solid var(--border); border-radius: var(--radius); padding: 0.6rem; min-height: 120px; }
.kanban-head {
  display: flex; justify-content: space-between; font-size: 0.7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted);
  padding: 0.2rem 0.3rem 0.6rem;
}
.kanban-card {
  display: block; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.6rem; margin-bottom: 0.5rem; box-shadow: var(--shadow);
}
.kanban-card:hover { border-color: var(--primary); text-decoration: none; }
.kanban-card .t { font-weight: 600; font-size: 0.85rem; color: var(--text); }
.kanban-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 0.4rem; }
.kanban-foot .val { font-weight: 700; font-size: 0.85rem; }
.kanban-empty { text-align: center; padding: 0.5rem; }

/* Rejilla de permisos (admin usuarios) */
.perm-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0.5rem 1rem; }
.perm-grid .perm { padding: 0.3rem 0; }
