:root {
  --azul: #1f4e79;
  --azul-claro: #2f6fa8;
  --gris: #f4f6f8;
  --gris-borde: #d8dee4;
  --texto: #1c2b36;
  --rojo: #c0392b;
  --verde: #1e8449;
  --amarillo: #b9770e;
  --sombra: 0 1px 4px rgba(0,0,0,.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--gris);
  color: var(--texto);
  font-size: 16px;
}

.hidden { display: none !important; }
.cargando { text-align: center; padding: 40px; color: #666; }

/* Topbar */
#topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  background: #fff; color: var(--texto);
  padding: 8px 12px; box-shadow: var(--sombra);
  border-bottom: 1px solid var(--gris-borde);
}
.logo-top { height: 64px; width: auto; }
#topTitle { flex: 1; font-weight: 600; font-size: 1rem; color: var(--texto); }
.logo-login { display: block; height: 90px; margin: 0 auto 8px; }
.icon-btn {
  background: transparent; border: 1px solid var(--gris-borde);
  color: var(--texto); border-radius: 6px; padding: 6px 10px;
  font-size: 1rem; cursor: pointer;
}

/* Sidebar */
#sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 50;
  width: 240px; background: #fff; box-shadow: var(--sombra);
  transform: translateX(0); transition: transform .2s;
  padding-top: 12px; overflow-y: auto;
}
#sidebar.cerrado { transform: translateX(-260px); }
#navList { list-style: none; margin: 0; padding: 0; }
#navList li a {
  display: block; padding: 14px 18px; color: var(--texto);
  text-decoration: none; border-bottom: 1px solid var(--gris);
}
#navList li a.activo { background: var(--gris); font-weight: 600; color: var(--azul); }
#overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40;
}

/* Main */
#app { padding: 16px; max-width: 1100px; margin: 0 auto; }

h1 { font-size: 1.3rem; margin: 0 0 16px; }
h2 { font-size: 1.1rem; margin: 20px 0 10px; }

/* Cards */
.card {
  background: #fff; border-radius: 10px; padding: 16px;
  box-shadow: var(--sombra); margin-bottom: 16px;
}
.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-kpi { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

.kpi { background:#fff; border-radius:10px; padding:14px; box-shadow:var(--sombra); }
.kpi .num { font-size: 1.6rem; font-weight: 700; color: var(--azul); }
.kpi .lbl { font-size: .8rem; color: #666; }

/* Gráficos: cuadrícula compacta */
.grid-charts { display: grid; gap: 12px; grid-template-columns: 1fr; }
.graf-card { background:#fff; border-radius:10px; padding:12px; box-shadow:var(--sombra); }
.graf-card h2 { margin: 0 0 8px; font-size: .95rem; }
.graf-box { position: relative; height: 200px; }
@media (min-width: 768px) {
  .grid-charts { grid-template-columns: repeat(3, 1fr); }
  .graf-box { height: 220px; }
}

/* Forms */
label { display: block; font-size: .85rem; font-weight: 600; margin: 10px 0 4px; }
input, select, textarea, button {
  font-size: 1rem; font-family: inherit;
}
input, select, textarea {
  width: 100%; padding: 10px; border: 1px solid var(--gris-borde);
  border-radius: 8px; background: #fff;
}
textarea { min-height: 70px; resize: vertical; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 120px; }
.check-row { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.check-row input { width: auto; }

button.btn {
  background: var(--azul); color: #fff; border: none;
  border-radius: 8px; padding: 12px 16px; cursor: pointer; font-weight: 600;
}
button.btn:active { background: var(--azul-claro); }
button.btn.sec { background: #fff; color: var(--azul); border: 1px solid var(--azul); }
button.btn.danger { background: var(--rojo); }
button.btn.full { width: 100%; }
button.btn.sm { padding: 6px 10px; font-size: .85rem; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--gris-borde); }
th { color: #555; font-size: .8rem; text-transform: uppercase; }
.tabla-scroll { overflow-x: auto; }

/* Timeline */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li {
  border-left: 3px solid var(--azul-claro); padding: 8px 0 12px 14px;
  margin-left: 8px; position: relative;
}
.timeline li::before {
  content: ""; position: absolute; left: -7px; top: 12px;
  width: 10px; height: 10px; border-radius: 50%; background: var(--azul);
}
.timeline .meta { font-size: .75rem; color: #777; }
.timeline .tags { margin-top: 4px; }

/* Tags / badges */
.tag {
  display: inline-block; font-size: .7rem; padding: 2px 8px;
  border-radius: 12px; background: var(--gris); margin: 2px 4px 2px 0;
}
.tag.interno { background: #fdebd0; color: var(--amarillo); }
.tag.externo { background: #d6eaf8; color: var(--azul); }

.msg { padding: 10px; border-radius: 8px; margin: 10px 0; }
.msg.error { background: #fdecea; color: var(--rojo); }
.msg.ok { background: #eafaf1; color: var(--verde); }

/* Login */
.login-wrap {
  max-width: 360px; margin: 40px auto; padding: 24px;
  background: #fff; border-radius: 12px; box-shadow: var(--sombra);
}
.login-wrap h1 { text-align: center; }

/* Desktop */
@media (min-width: 768px) {
  #sidebar { transform: translateX(0) !important; }
  #overlay { display: none !important; }
  #topbar { margin-left: 256px; }
  #app { margin-left: 256px; }
  #btnMenu { display: none; }
}
