:root {
  --ic-azul: #3d3d99;
  --ic-azul-oscuro: #2b2b73;
  --ic-azul-profundo: #1e1e52;
  --ic-azul-claro: #eef0fa;
  --ic-borde: #e3e6f4;
  --ic-texto: #23254a;
  --ic-gris: #6b6e8c;
  --verde: #1e8e4e;
  --amarillo: #c98a00;
  --rojo: #c0392b;
  --lateral: 250px;
  --sombra-s: 0 1px 2px rgba(35, 37, 74, .05), 0 2px 8px rgba(35, 37, 74, .05);
  --sombra-m: 0 4px 12px rgba(35, 37, 74, .08), 0 12px 32px rgba(61, 61, 153, .10);
  --sombra-l: 0 12px 40px rgba(30, 30, 82, .18);
  --radio: 16px;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(1100px 500px at 90% -10%, rgba(61, 61, 153, .08), transparent 60%),
    radial-gradient(900px 420px at -10% 40%, rgba(122, 122, 224, .07), transparent 60%),
    #f2f4fb;
  color: var(--ic-texto);
  min-height: 100vh;
}
a { color: var(--ic-azul); transition: color .15s; }
a:hover { color: var(--ic-azul-oscuro); }

::selection { background: var(--ic-azul); color: #fff; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c9ccdf; border-radius: 99px; border: 2px solid #f2f4fb; }
::-webkit-scrollbar-thumb:hover { background: var(--ic-azul); }

/* ---------- Barra lateral ---------- */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: var(--lateral); z-index: 200;
  display: flex; flex-direction: column;
  background:
    radial-gradient(400px 260px at 110% 0%, rgba(122, 122, 224, .28), transparent 65%),
    linear-gradient(185deg, #232659 0%, var(--ic-azul-profundo) 45%, #15173d 100%);
  color: #cfd2f5;
  box-shadow: 4px 0 28px rgba(21, 23, 61, .28);
}
.sidebar .marca {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 18px 16px; color: #fff; text-decoration: none;
  font-weight: 800; font-size: 16px; letter-spacing: .02em;
  border-bottom: 1px solid rgba(255, 255, 255, .09);
}
.sidebar .marca img {
  height: 40px; background: #fff; border-radius: 11px; padding: 3px;
  box-shadow: 0 3px 12px rgba(0, 0, 0, .3);
  transition: transform .25s;
}
.sidebar .marca:hover { color: #fff; }
.sidebar .marca:hover img { transform: scale(1.07) rotate(-3deg); }
.sidebar .marca small { display: block; font-size: 10.5px; font-weight: 500; color: #9a9ed6; letter-spacing: .06em; }

.sidebar nav { flex: 1; overflow-y: auto; padding: 12px 12px 8px; }
.sidebar nav::-webkit-scrollbar { width: 6px; }
.sidebar nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border: none; }

.nav-grupo {
  font-size: 10.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .14em;
  color: #7d81bd; padding: 16px 12px 6px;
}
.sidebar nav a {
  display: flex; align-items: center; gap: 11px;
  color: #c3c6ef; text-decoration: none; font-size: 14px; font-weight: 500;
  padding: 9px 12px; border-radius: 11px; margin-bottom: 2px;
  position: relative; transition: background .18s, color .18s, transform .18s;
}
.sidebar nav a svg { width: 18px; height: 18px; flex: none; opacity: .8; transition: opacity .18s, transform .18s; }
.sidebar nav a:hover { background: rgba(255, 255, 255, .09); color: #fff; transform: translateX(2px); }
.sidebar nav a:hover svg { opacity: 1; }
.sidebar nav a.activo {
  background: linear-gradient(100deg, rgba(122, 122, 224, .38), rgba(122, 122, 224, .16));
  color: #fff; font-weight: 700;
  box-shadow: inset 0 0 0 1px rgba(160, 163, 235, .35);
}
.sidebar nav a.activo::before {
  content: ''; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 4px;
  border-radius: 0 4px 4px 0; background: linear-gradient(180deg, #a3a6ff, #7a7ae0);
}
.sidebar nav a.activo svg { opacity: 1; }

.sidebar .pie {
  border-top: 1px solid rgba(255, 255, 255, .09);
  padding: 14px; display: flex; align-items: center; gap: 11px;
}
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #7a7ae0, #4a4ab8);
  color: #fff; font-weight: 800; font-size: 14px; letter-spacing: .03em;
  box-shadow: 0 3px 10px rgba(0, 0, 0, .3);
}
.sidebar .pie .quien { flex: 1; min-width: 0; }
.sidebar .pie .quien .nombre { color: #fff; font-size: 13.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rol {
  display: inline-block; background: linear-gradient(120deg, #fff, #dfe2ff); color: var(--ic-azul-oscuro);
  font-size: 10px; font-weight: 800; padding: 2px 8px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: .05em; margin-top: 2px;
}
.sidebar .pie a.salir {
  color: #9a9ed6; display: flex; padding: 8px; border-radius: 10px; transition: background .18s, color .18s;
}
.sidebar .pie a.salir:hover { background: rgba(255, 99, 99, .16); color: #ffb3b3; }
.sidebar .pie a.salir svg { width: 18px; height: 18px; }

/* ---------- Barra superior móvil ---------- */
.appbar-movil {
  display: none; position: sticky; top: 0; z-index: 150;
  background: linear-gradient(120deg, var(--ic-azul-profundo), var(--ic-azul-oscuro));
  color: #fff; align-items: center; gap: 12px; padding: 10px 14px;
  box-shadow: 0 4px 20px rgba(30, 30, 82, .3);
}
.appbar-movil img { height: 32px; background: #fff; border-radius: 8px; padding: 2px; }
.appbar-movil .titulo { font-weight: 700; font-size: 15px; }
.btn-menu {
  background: rgba(255, 255, 255, .12); border: 0; color: #fff; border-radius: 10px;
  width: 40px; height: 40px; font-size: 20px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.capa-movil { display: none; position: fixed; inset: 0; background: rgba(21, 23, 61, .55); z-index: 190; backdrop-filter: blur(2px); }

/* ---------- Contenido ---------- */
.principal { margin-left: var(--lateral); min-height: 100vh; }
.contenido { max-width: 1240px; margin: 0 auto; padding: 30px 28px 48px; animation: entrada .3s ease; }
@keyframes entrada { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
h1 { font-size: 25px; margin: 0 0 4px; font-weight: 800; letter-spacing: -.02em; }
.sub { color: var(--ic-gris); font-size: 14px; margin: 0 0 22px; }

/* ---------- Tarjetas ---------- */
.tarjeta {
  background: #fff; border: 1px solid var(--ic-borde); border-radius: var(--radio);
  padding: 22px; margin-bottom: 22px;
  box-shadow: var(--sombra-s);
  transition: box-shadow .25s, transform .25s;
  animation: entrada .35s ease both;
}
.tarjeta:hover { box-shadow: var(--sombra-m); }
.fila-tarjetas { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 22px; }
.kpi {
  background: #fff; border: 1px solid var(--ic-borde); border-radius: var(--radio);
  padding: 18px 20px; position: relative; overflow: hidden;
  box-shadow: var(--sombra-s);
  transition: transform .22s, box-shadow .22s;
  animation: entrada .4s ease both;
}
.fila-tarjetas .kpi:nth-child(2) { animation-delay: .05s; }
.fila-tarjetas .kpi:nth-child(3) { animation-delay: .1s; }
.fila-tarjetas .kpi:nth-child(4) { animation-delay: .15s; }
.kpi::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 4px;
  background: linear-gradient(90deg, var(--ic-azul), #7a7ae0);
  opacity: .85;
}
.kpi::after {
  content: ''; position: absolute; right: -30px; bottom: -30px; width: 110px; height: 110px;
  border-radius: 50%; background: radial-gradient(circle, rgba(61, 61, 153, .07), transparent 70%);
}
.kpi:hover { transform: translateY(-4px); box-shadow: var(--sombra-m); }
.kpi .valor { font-size: 26px; font-weight: 800; color: var(--ic-azul); letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .etiqueta { font-size: 12.5px; color: var(--ic-gris); margin-top: 4px; font-weight: 500; }

/* ---------- Tablas ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; color: var(--ic-gris); font-size: 11.5px; text-transform: uppercase;
  letter-spacing: .07em; font-weight: 700; padding: 10px;
  border-bottom: 2px solid var(--ic-borde); background: #fafbfe;
  position: sticky; top: 0; z-index: 5;
}
th:first-child { border-radius: 8px 0 0 0; }
th:last-child { border-radius: 0 8px 0 0; }
td { padding: 12px 10px; border-bottom: 1px solid #f0f1f9; vertical-align: top; }
tr:last-child td { border-bottom: none; }
tbody tr, table tr { transition: background .12s; }
tr:hover td { background: var(--ic-azul-claro); }

/* Filtro instantáneo que se inyecta sobre las tablas grandes */
.filtro-tabla {
  display: flex; align-items: center; gap: 9px; margin-bottom: 12px;
  background: #f7f8fd; border: 1.5px solid var(--ic-borde); border-radius: 11px; padding: 9px 13px;
  transition: border-color .15s, box-shadow .15s;
}
.filtro-tabla:focus-within { border-color: var(--ic-azul); box-shadow: 0 0 0 4px rgba(61, 61, 153, .1); background: #fff; }
.filtro-tabla svg { width: 16px; height: 16px; color: var(--ic-gris); flex: none; }
.filtro-tabla input { border: 0; background: transparent; padding: 0; font-size: 14px; box-shadow: none; }
.filtro-tabla input:focus { box-shadow: none; }
.filtro-tabla .cuenta { font-size: 12px; color: var(--ic-gris); white-space: nowrap; }

/* ---------- Formularios ---------- */
form.panel { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 20px; }
form.panel .ancho { grid-column: 1 / -1; }
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: var(--ic-texto); }
input, select, textarea {
  width: 100%; padding: 10px 13px; border: 1.5px solid var(--ic-borde); border-radius: 10px;
  font-size: 14px; font-family: inherit; background: #fff; color: var(--ic-texto);
  transition: border-color .15s, box-shadow .15s;
}
input:hover, select:hover, textarea:hover { border-color: #c4c8e8; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--ic-azul);
  box-shadow: 0 0 0 4px rgba(61, 61, 153, .12);
}
.boton {
  display: inline-block; background: linear-gradient(135deg, var(--ic-azul), var(--ic-azul-oscuro));
  color: #fff; border: 0; border-radius: 10px;
  padding: 11px 20px; font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none;
  box-shadow: 0 3px 12px rgba(61, 61, 153, .3);
  transition: transform .15s, box-shadow .15s, filter .15s;
}
.boton:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(61, 61, 153, .4); filter: brightness(1.05); color: #fff; }
.boton:active { transform: translateY(0); }
.boton.secundario {
  background: #fff; color: var(--ic-azul); border: 1.5px solid #c9cdf0; box-shadow: var(--sombra-s);
}
.boton.secundario:hover { border-color: var(--ic-azul); background: var(--ic-azul-claro); box-shadow: var(--sombra-s); color: var(--ic-azul); }
.boton.pequeno { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.acciones { display: flex; gap: 10px; margin-top: 6px; align-items: center; flex-wrap: wrap; }
.encabezado-pagina { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; }

/* ---------- Avisos y estados ---------- */
.aviso { padding: 13px 16px; border-radius: 12px; font-size: 14px; margin-bottom: 16px; box-shadow: var(--sombra-s); animation: entrada .3s ease; }
.aviso.error { background: #fdf0ef; color: #9c2e23; border: 1px solid #f3cdc8; }
.aviso.ok { background: #ebf8f0; color: #14683a; border: 1px solid #c2e8d1; }
.aviso.info { background: linear-gradient(120deg, #eef0fa, #f4f5fd); color: var(--ic-azul-oscuro); border: 1px solid #dde1f5; }

.chip {
  font-size: 12px; font-weight: 700; padding: 4px 11px; border-radius: 999px; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 5px;
}
.chip::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .7; }
.chip.activo { background: #e6f6ec; color: var(--verde); }
.chip.no_renovara { background: #fdf3e0; color: var(--amarillo); }
.chip.terminado { background: #f0f0f5; color: var(--ic-gris); }
.chip.vivienda { background: var(--ic-azul-claro); color: var(--ic-azul); }
.chip.comercial { background: #f4e9fd; color: #7a3ba3; }

.semaforo {
  width: 13px; height: 13px; border-radius: 50%; display: inline-block; margin-right: 6px; vertical-align: -2px;
  box-shadow: 0 0 0 3px rgba(0,0,0,.06);
}
.semaforo.verde { background: var(--verde); box-shadow: 0 0 8px rgba(30, 142, 78, .5); }
.semaforo.amarillo { background: var(--amarillo); box-shadow: 0 0 8px rgba(201, 138, 0, .5); }
.semaforo.rojo { background: var(--rojo); box-shadow: 0 0 8px rgba(192, 57, 43, .55); animation: latido 1.6s infinite; }
@keyframes latido { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.18); } }

/* ---------- Búsqueda ---------- */
.buscador { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.buscador input, .buscador select { flex: 1; min-width: 200px; font-size: 15px; padding: 12px 14px; }
.buscador .boton { font-size: 15px; }

/* ---------- Expediente ---------- */
.seccion-titulo {
  font-size: 14px; font-weight: 800; color: var(--ic-azul); margin: 0 0 12px;
  text-transform: uppercase; letter-spacing: .05em;
  border-bottom: 2px solid var(--ic-azul-claro); padding-bottom: 8px;
}
.datos { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px 22px; font-size: 14px; }
.datos .campo .nombre { font-size: 11px; color: var(--ic-gris); text-transform: uppercase; letter-spacing: .06em; font-weight: 700; }
.datos .campo .valor { font-weight: 600; margin-top: 2px; }

/* ---------- Login ---------- */
.login-fondo {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(800px 500px at 20% 20%, rgba(122, 122, 224, .35), transparent 60%),
    radial-gradient(700px 500px at 85% 80%, rgba(61, 61, 153, .5), transparent 60%),
    linear-gradient(150deg, var(--ic-azul-profundo) 0%, var(--ic-azul-oscuro) 55%, var(--ic-azul) 100%);
}
.login-caja {
  background: rgba(255, 255, 255, .97); border-radius: 22px; padding: 40px; width: 400px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .4), 0 0 0 1px rgba(255,255,255,.4);
  animation: entradaLogin .4s ease;
}
@keyframes entradaLogin { from { opacity: 0; transform: translateY(16px) scale(.98); } to { opacity: 1; transform: none; } }
.login-caja img { display: block; margin: 0 auto 12px; height: 92px; filter: drop-shadow(0 4px 12px rgba(61,61,153,.2)); }
.login-caja h1 { text-align: center; font-size: 18px; margin: 0 0 2px; }
.login-caja p { text-align: center; color: var(--ic-gris); font-size: 13px; margin-top: 4px; }
.login-caja label { margin-top: 14px; }
.login-caja .boton { width: 100%; margin-top: 22px; padding: 13px; font-size: 15px; }

/* ---------- Notas del expediente ---------- */
#notas form.buscador input { font-size: 14px; }
#tabla-residentes input { padding: 8px 10px; }

/* ---------- Impresión ---------- */
@media print {
  .sidebar, .appbar-movil, .capa-movil, .filtro-tabla { display: none !important; }
  .principal { margin-left: 0; }
  body { background: #fff; }
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-105%); transition: transform .28s ease; box-shadow: none; width: 280px; }
  body.menu-abierto .sidebar { transform: translateX(0); box-shadow: 4px 0 40px rgba(21, 23, 61, .5); }
  body.menu-abierto .capa-movil { display: block; animation: aparecerCapa .25s ease; }
  @keyframes aparecerCapa { from { opacity: 0; } to { opacity: 1; } }
  .appbar-movil { display: flex; }
  .principal { margin-left: 0; }
  .contenido { padding: 18px 14px 40px; }
  form.panel { grid-template-columns: 1fr; }
}
