:root {
  --azul: #1e3a5f;
  --azul-claro: #2d5580;
  --azul-suave: #eef3f8;
  --verde: #1a7f4b;
  --verde-suave: #e6f4ec;
  --ambar: #b8791a;
  --ambar-suave: #fdf3e2;
  --rojo: #b3261e;
  --rojo-suave: #fbeceb;
  --gris: #6b7280;
  --gris-claro: #f5f6f8;
  --borde: #dfe3e8;
  --texto: #1f2933;
  --radio: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  color: var(--texto);
  background: var(--gris-claro);
  line-height: 1.5;
}

/* ---------- Barra superior ---------- */
.topbar {
  background: var(--azul);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
}
.topbar-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: .7rem 1.2rem;
  display: flex;
  align-items: center;
  gap: 1.4rem;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .55rem; color: #fff; text-decoration: none; font-weight: 600; }
.brand-mark {
  background: rgba(255,255,255,.16);
  width: 2rem; height: 2rem;
  display: grid; place-items: center;
  border-radius: 50%;
  font-weight: 700;
}
.nav { display: flex; gap: .3rem; flex-wrap: wrap; flex: 1; }
.nav a {
  color: #dce6f2; text-decoration: none;
  padding: .42rem .75rem; border-radius: var(--radio);
  font-size: .92rem;
}
.nav a:hover { background: rgba(255,255,255,.12); color: #fff; }
.userbox { display: flex; align-items: center; gap: .7rem; font-size: .85rem; }
.user-name { font-weight: 600; }
.user-role {
  background: rgba(255,255,255,.16);
  padding: .15rem .55rem; border-radius: 999px;
  text-transform: uppercase; font-size: .68rem; letter-spacing: .04em;
}
.userbox .link { color: #cfe0f2; text-decoration: none; border-bottom: 1px dotted #8fb0d0; }
.userbox .link:hover { color: #fff; }

/* ---------- Contenedor ---------- */
.container { max-width: 1240px; margin: 0 auto; padding: 1.5rem 1.2rem 3rem; }
.footer { text-align: center; padding: 1.4rem; color: var(--gris); font-size: .8rem; }

/* ---------- Mensajes ---------- */
.flash-area { margin-bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; }
.flash { padding: .7rem .95rem; border-radius: var(--radio); font-size: .93rem; border-left: 4px solid; }
.flash-exito { background: var(--verde-suave); border-color: var(--verde); color: #14532d; }
.flash-error  { background: var(--rojo-suave);  border-color: var(--rojo);  color: #7f1d1d; }
.flash-aviso  { background: var(--ambar-suave); border-color: var(--ambar); color: #78350f; }

/* ---------- Tarjetas ---------- */
.card {
  background: #fff;
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  padding: 1.15rem 1.25rem;
  margin-bottom: 1.1rem;
}
.card-title {
  margin: 0 0 .9rem;
  font-size: 1.02rem;
  color: var(--azul);
  border-bottom: 2px solid var(--azul-suave);
  padding-bottom: .5rem;
  display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap;
}
.card-title small { color: var(--gris); font-weight: 400; font-size: .82rem; }

/* ---------- Métricas ---------- */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(178px, 1fr));
  gap: .85rem;
  margin-bottom: 1.2rem;
}
.metric {
  background: #fff;
  border: 1px solid var(--borde);
  border-left: 4px solid var(--azul);
  border-radius: var(--radio);
  padding: .85rem 1rem;
}
.metric-label { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--gris); }
.metric-value { font-size: 1.5rem; font-weight: 700; color: var(--azul); line-height: 1.25; }
.metric-note { font-size: .78rem; color: var(--gris); }
.metric.ok   { border-left-color: var(--verde); }
.metric.ok .metric-value { color: var(--verde); }
.metric.warn { border-left-color: var(--ambar); }
.metric.warn .metric-value { color: var(--ambar); }
.metric.bad  { border-left-color: var(--rojo); }
.metric.bad .metric-value { color: var(--rojo); }

/* ---------- Barra de progreso ---------- */
.progress {
  height: 9px;
  background: #e6e9ee;
  border-radius: 999px;
  overflow: hidden;
  min-width: 90px;
}
.progress-fill { height: 100%; background: var(--verde); border-radius: 999px; transition: width .3s; }
.progress-fill.warn { background: var(--ambar); }
.progress-fill.bad  { background: var(--rojo); }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}
table.data th, table.data td {
  padding: .58rem .6rem;
  border-bottom: 1px solid var(--borde);
  text-align: left;
  white-space: nowrap;
}
table.data thead th {
  background: var(--azul-suave);
  color: var(--azul);
  font-size: .76rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  font-weight: 700;
  position: sticky; top: 0;
}
table.data tbody tr:hover { background: #f9fbfd; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tfoot td { font-weight: 700; background: var(--azul-suave); border-top: 2px solid var(--azul); }
.table-meses td.mes-celda { text-align: center; padding: .45rem .3rem; }
.mes-pagada   { background: var(--verde-suave); color: #14532d; font-weight: 600; }
.mes-parcial  { background: var(--ambar-suave); color: #78350f; font-weight: 600; }
.mes-pendiente{ background: var(--rojo-suave);  color: #7f1d1d; }
.mes-no_aplica{ background: #f2f4f7; color: #9aa3af; }
/* Alias heredados */
.mes-pagado   { background: var(--verde-suave); color: #14532d; }
.mes-futuro   { background: #f2f4f7; color: #9aa3af; }

/* ---------- Insignias de estado ---------- */
.badge {
  display: inline-block;
  padding: .16rem .55rem;
  border-radius: 999px;
  font-size: .74rem;
  font-weight: 600;
  border: 1px solid transparent;
}
.badge-al_dia    { background: var(--verde-suave); color: #14532d; border-color: #bfe3cd; }
.badge-atrasado  { background: var(--rojo-suave);  color: #7f1d1d; border-color: #f0c2be; }
.badge-sin_cuotas{ background: var(--gris-claro);  color: #4b5563; border-color: var(--borde); }
.badge-parcial   { background: var(--ambar-suave); color: #78350f; border-color: #f0dcb4; }
.badge-pendiente { background: var(--rojo-suave);  color: #7f1d1d; border-color: #f0c2be; }
.badge-pagado    { background: var(--verde-suave); color: #14532d; border-color: #bfe3cd; }

/* ---------- Formularios ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: .9rem; }
.field { display: flex; flex-direction: column; gap: .3rem; }
.field label { font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--gris); }
.field input, .field select, .field textarea {
  padding: .5rem .6rem;
  border: 1px solid var(--borde);
  border-radius: 6px;
  font-size: .93rem;
  font-family: inherit;
  background: #fff;
  color: var(--texto);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--azul-claro);
  outline-offset: 1px;
  border-color: var(--azul-claro);
}
.field input[readonly] { background: #f3f5f8; color: var(--gris); }
.field-full { grid-column: 1 / -1; }

.btn {
  display: inline-block;
  padding: .52rem 1.05rem;
  border-radius: 6px;
  border: 1px solid transparent;
  font-size: .92rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
}
.btn-primary { background: var(--azul); color: #fff; }
.btn-primary:hover { background: var(--azul-claro); }
.btn-secondary { background: #fff; color: var(--azul); border-color: var(--borde); }
.btn-secondary:hover { background: var(--azul-suave); }
.btn-danger { background: #fff; color: var(--rojo); border-color: #f0c2be; }
.btn-danger:hover { background: var(--rojo-suave); }
.btn-sm { padding: .3rem .6rem; font-size: .8rem; }
.btn-row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-top: 1rem; }

/* ---------- Login ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.auth-card {
  background: #fff;
  border: 1px solid var(--borde);
  border-radius: 12px;
  padding: 2rem 2.1rem;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 8px 30px rgba(30,58,95,.10);
}
.auth-card h1 { margin: 0 0 .3rem; font-size: 1.35rem; color: var(--azul); }
.auth-card .sub { color: var(--gris); font-size: .9rem; margin: 0 0 1.3rem; }
.auth-card .field { margin-bottom: .95rem; }
.auth-card input { width: 100%; }
.hint { font-size: .8rem; color: var(--gris); margin-top: .9rem; line-height: 1.5; }

/* ---------- Filtros ---------- */
.filters {
  display: flex; gap: .55rem; flex-wrap: wrap; align-items: center;
  margin-bottom: 1.1rem;
}
.filters a, .filters button {
  padding: .38rem .8rem; border-radius: 999px; font-size: .85rem;
  text-decoration: none; border: 1px solid var(--borde); background: #fff; color: var(--gris);
}
.filters a:hover { background: var(--azul-suave); color: var(--azul); }
.filters a.activo { background: var(--azul); color: #fff; border-color: var(--azul); }
.filters input[type="search"] {
  padding: .38rem .7rem; border: 1px solid var(--borde); border-radius: 999px;
  font-size: .87rem; font-family: inherit;
}
.filters .espacio { flex: 1; }

/* ---------- Utilidades ---------- */
.muted { color: var(--gris); }
.small { font-size: .82rem; }
.mono { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.stack { display: flex; flex-direction: column; gap: .5rem; }
.inline { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.mt-1 { margin-top: .8rem; }
.mb-0 { margin-bottom: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1.1rem; }
.tarjeta-alumno {
  border: 1px solid var(--borde); border-radius: var(--radio);
  padding: .85rem 1rem; background: #fff;
}
.tarjeta-alumno h3 { margin: 0 0 .35rem; font-size: 1rem; color: var(--azul); }

@media (max-width: 700px) {
  .topbar-inner { flex-direction: column; align-items: flex-start; gap: .6rem; }
  .nav { order: 3; }
  .container { padding: 1rem .8rem 2rem; }
}
