:root {
  --azul: #1d4ed8;
  --azul-osc: #1e3a8a;
  --gris-fondo: #f4f5f7;
  --gris-borde: #dde1e6;
  --texto: #1f2430;
  --texto-suave: #616a76;
  --verde: #1a7f4b;
  --rojo: #c0392b;
  --naranja: #b7791f;
  --blanco: #ffffff;
  --radius: 8px;
}

* { box-sizing: border-box; }

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

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

.oculto { display: none !important; }

/* ---- login ---- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--azul-osc), var(--azul) 60%);
}
.login-card {
  background: var(--blanco);
  padding: 40px 36px;
  border-radius: 12px;
  width: 340px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.login-card h1 {
  font-size: 20px;
  margin: 0 0 4px;
}
.login-card p.sub {
  margin: 0 0 24px;
  color: var(--texto-suave);
  font-size: 13px;
}

/* ---- layout general ---- */
.topbar {
  background: var(--azul-osc);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
}
.topbar .marca { font-weight: 700; letter-spacing: .3px; }
.topbar nav a {
  color: rgba(255,255,255,.85);
  text-decoration: none;
  margin-left: 18px;
  font-size: 14px;
}
.topbar nav a.activo, .topbar nav a:hover { color: white; text-decoration: underline; }
.topbar .usuario-info { font-size: 13px; color: rgba(255,255,255,.8); }
.topbar button.link {
  background: none; border: none; color: rgba(255,255,255,.85); cursor: pointer; font-size: 13px; margin-left: 14px;
  text-decoration: underline;
}

.contenido { max-width: 1180px; margin: 0 auto; padding: 24px; }

/* ---- form controls ---- */
label { display: block; font-size: 13px; color: var(--texto-suave); margin: 12px 0 4px; }
input, select, textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--gris-borde);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  background: white;
}
textarea { resize: vertical; min-height: 70px; }
button {
  cursor: pointer;
  border: none;
  border-radius: 6px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
}
button.primario { background: var(--azul); color: white; }
button.primario:hover { background: var(--azul-osc); }
button.secundario { background: var(--gris-borde); color: var(--texto); }
button.secundario:hover { background: #cfd4db; }
button.peligro { background: #fdeceb; color: var(--rojo); }
button:disabled { opacity: .5; cursor: default; }
.error-msg { color: var(--rojo); font-size: 13px; margin-top: 8px; min-height: 16px; }
.ok-msg { color: var(--verde); font-size: 13px; margin-top: 8px; min-height: 16px; }

/* ---- tarjetas / paneles ---- */
.panel {
  background: white;
  border: 1px solid var(--gris-borde);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 20px;
}
.panel h2 { margin-top: 0; font-size: 16px; }

/* ---- dashboard stat cards ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.stat-card {
  background: white;
  border: 1px solid var(--gris-borde);
  border-left: 4px solid var(--azul);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.stat-card .num { font-size: 26px; font-weight: 700; }
.stat-card .label { font-size: 12px; color: var(--texto-suave); text-transform: uppercase; letter-spacing: .04em; }
.stat-card.alerta { border-left-color: var(--rojo); }
.stat-card.alerta .num { color: var(--rojo); }

/* ---- filtros ---- */
.filtros { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 16px; }
.filtros .campo { min-width: 150px; }
.filtros label { margin: 0 0 4px; }

/* ---- tabla ---- */
table { width: 100%; border-collapse: collapse; background: white; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--gris-borde); font-size: 13.5px; }
th { background: #fafbfc; color: var(--texto-suave); font-weight: 600; text-transform: uppercase; font-size: 11.5px; letter-spacing: .04em; }
tr:hover td { background: #fbfcfe; }
tr.vencido td { background: #fdeceb; }
tr.vencido:hover td { background: #fbdedb; }

.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: #e8edfb;
  color: var(--azul-osc);
}
.pill.final { background: #e6f4ea; color: var(--verde); }

.acciones-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  border-left: 2px solid var(--gris-borde);
  padding: 4px 0 16px 16px;
  margin-left: 4px;
  position: relative;
}
.timeline li::before {
  content: '';
  position: absolute; left: -6px; top: 6px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--azul);
}
.timeline .meta { font-size: 12px; color: var(--texto-suave); }

.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.tabs { display: flex; gap: 6px; margin-bottom: 16px; border-bottom: 1px solid var(--gris-borde); }
.tabs button {
  background: none; border-radius: 0; padding: 10px 14px; font-weight: 600; color: var(--texto-suave);
  border-bottom: 2px solid transparent;
}
.tabs button.activo { color: var(--azul); border-bottom-color: var(--azul); }

.fila-flex { display: flex; gap: 10px; }
.fila-flex > * { flex: 1; }

.chip-lista { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  background: #eef1f5; padding: 4px 10px; border-radius: 999px; font-size: 12px;
  display: flex; align-items: center; gap: 6px;
}
.chip button { background: none; padding: 0; font-size: 13px; color: var(--rojo); font-weight: 700; }

/* ---- impresion ---- */
@media print {
  .topbar, .tabs, .acciones-top button, .filtros, #panelMover, #btnGuardarDetalle,
  #btnSubirImagen, input[type="file"], #wrapAcciones, .no-imprimir { display: none !important; }
  body { background: white; }
  .panel { border: none; box-shadow: none; padding: 0; margin-bottom: 14px; }
  textarea, input, select { border: none; background: none; padding: 2px 0; }
  .contenido { max-width: 100%; padding: 0; }
}

/* ---- menu desplegable del topbar ---- */
.topbar nav { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; }
.menu-grupo { position: relative; }
.menu-grupo .menu-sub {
  display: none; position: absolute; top: 100%; left: 0; z-index: 20; min-width: 200px;
  background: var(--azul-osc); padding: 8px 0; border-radius: 0 0 var(--radius) var(--radius); box-shadow: 0 8px 20px rgba(0,0,0,.2);
}
.menu-grupo:hover .menu-sub, .menu-grupo:focus-within .menu-sub { display: block; }
.menu-grupo .menu-sub a { display: block; padding: 6px 14px; }

/* ---- componentes de los modulos nuevos ---- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--gris-borde); color: var(--texto); }
.badge.ok { background: #e6f4ea; color: var(--verde); }
.badge.alerta { background: #fdeceb; color: var(--rojo); }
.badge.aviso { background: #fff4e0; color: var(--naranja); }
.badge.info { background: #e8efff; color: var(--azul); }
.texto-suave { color: var(--texto-suave); font-size: 13px; }
.aviso-caja { background: #fff8e6; border: 1px solid #f3d9a4; border-radius: var(--radius); padding: 12px 14px; font-size: 13.5px; margin-bottom: 16px; }
.aviso-caja.info { background: #eef3ff; border-color: #c8d6fb; }
.tabla-scroll { overflow-x: auto; }
.matriz td, .matriz th { text-align: center; padding: 6px 8px; }
.matriz td:first-child, .matriz th:first-child { text-align: left; }
.matriz select { padding: 4px 6px; font-size: 12.5px; min-width: 120px; }
.check-linea { display: flex; align-items: center; gap: 8px; margin: 10px 0; font-size: 13.5px; color: var(--texto); }
.check-linea input { width: auto; margin: 0; }
.dias-semana { display: flex; gap: 4px; }
.dias-semana label { display: flex; flex-direction: column; align-items: center; margin: 0; font-size: 12px; }
.dias-semana input { width: auto; }
.modal-fondo { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow-y: auto; }
.modal { background: white; border-radius: 12px; width: 100%; max-width: 720px; padding: 24px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal h2 { margin-top: 0; font-size: 18px; }
.modal .pie { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.arbol { list-style: none; margin: 0; padding-left: 0; }
.arbol ul { list-style: none; margin: 0; padding-left: 18px; border-left: 1px dashed var(--gris-borde); }
.arbol .nodo { display: flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 6px; cursor: pointer; font-size: 14px; }
.arbol .nodo:hover { background: #f1f4f9; }
.arbol .nodo.sel { background: #e8efff; color: var(--azul-osc); font-weight: 600; }
.arbol .nodo .cuenta { margin-left: auto; font-size: 12px; color: var(--texto-suave); }
.arbol .nodo.inactivo { opacity: .5; }
.grid-org { display: grid; grid-template-columns: minmax(260px, 340px) 1fr; gap: 20px; align-items: start; }
.codigo-secreto { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 17px; letter-spacing: 1px; background: #f4f5f7; padding: 10px 12px; border-radius: 6px; text-align: center; user-select: all; }
@media (max-width: 860px) {
  .grid-org, .grid-2 { grid-template-columns: 1fr; }
  .fila-flex { flex-wrap: wrap; }
  .fila-flex > * { min-width: 200px; }
  .contenido { padding: 16px; }
}
.modal.ancho { max-width: 1000px; }
.menu-grupo .menu-sub { right: auto; }

/* ---- menu en celular ---- */
.boton-menu { display: none; color: white; background: none; font-size: 24px; padding: 0 4px; line-height: 1; }
@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; padding: 10px 16px; }
  .boton-menu { display: block; }
  .topbar nav { display: none; width: 100%; flex-direction: column; align-items: stretch; gap: 0; padding-top: 8px; }
  .topbar.menu-abierto nav { display: flex; }
  .topbar nav > .menu-grupo { display: block; }
  .topbar nav > a, .topbar nav > .menu-grupo > a, .topbar nav > button.link { display: block; padding: 10px 2px; border-top: 1px solid rgba(255,255,255,.12); text-align: left; }
  .menu-grupo .menu-sub { position: static; display: none; box-shadow: none; background: rgba(255,255,255,.06); border-radius: 6px; padding: 4px 0; }
  .menu-grupo:hover .menu-sub, .menu-grupo:focus-within .menu-sub { display: none; }
  .menu-grupo.abierto .menu-sub { display: block; }
}
