/* ============================================
   CobranzaEscolar · styles.css
   Diseño: Profesional, limpio, refinado
   Fuentes: Sora (display) + DM Sans (body)
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Sora:wght@400;600;700&family=DM+Sans:wght@400;500;600&display=swap');

/* ── Variables ───────────────────────────── */
:root {
  --bg:           #f4f6fa;
  --surface:      #ffffff;
  --surface-2:    #f9fafc;
  --border:       #e3e8f0;
  --border-light: #eef1f7;

  --accent:       #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: #eff6ff;

  --text:         #0f172a;
  --text-secondary: #475569;
  --text-muted:   #94a3b8;

  /* Estado colors */
  --green:        #16a34a;
  --green-light:  #f0fdf4;
  --green-border: #bbf7d0;

  --yellow:       #ca8a04;
  --yellow-light: #fefce8;
  --yellow-border:#fde68a;

  --red:          #dc2626;
  --red-light:    #fef2f2;
  --red-border:   #fecaca;

  --blue:         #2563eb;
  --blue-light:   #eff6ff;

  --purple:       #7c3aed;
  --purple-light: #f5f3ff;

  /* Layout */
  --sidebar-w:    240px;
  --sidebar-w-collapsed: 64px;
  --topbar-h:     57px;
  --radius:       12px;
  --radius-sm:    8px;
  --shadow:       0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.04);
  --shadow-md:    0 4px 12px rgba(0,0,0,.10), 0 8px 32px rgba(0,0,0,.06);
  --shadow-lg:    0 8px 32px rgba(0,0,0,.14);

  --font-display: 'Sora', sans-serif;
  --font-body:    'DM Sans', sans-serif;

  --transition:   0.18s cubic-bezier(.4,0,.2,1);
}

/* ── Reset ───────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; scroll-behavior: smooth; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { text-decoration: none; color: inherit; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, select, textarea { font-family: inherit; }
img { display: block; max-width: 100%; }
svg { display: inline-block; vertical-align: middle; }

/* ── Utilities ───────────────────────────── */
.hidden { display: none !important; }
.mt-lg { margin-top: 2rem; }
.text-muted { color: var(--text-muted); font-size: .875rem; }

/* ── Screens ─────────────────────────────── */
.screen { display: none; }
.screen.active { display: flex; }

/* ============================================
   LOGIN
   ============================================ */
#login-screen {
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #1e40af 100%);
}

.login-bg {
  position: absolute; inset: 0;
  pointer-events: none;
}
.login-grid {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.04) 1px, transparent 1px);
  background-size: 48px 48px;
}

.login-card {
  position: relative;
  background: var(--surface);
  border-radius: 20px;
  padding: 2.5rem;
  width: 420px;
  max-width: calc(100vw - 2rem);
  box-shadow: var(--shadow-lg);
  animation: slideUp .4s cubic-bezier(.22,1,.36,1) both;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2rem;
}
.logo-icon { width: 48px; height: 48px; flex-shrink: 0; }
.logo-icon svg { width: 48px; height: 48px; }
.login-title {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}
.login-sub { font-size: .8rem; color: var(--text-muted); margin-top: .15rem; }

.login-form { display: flex; flex-direction: column; gap: 1rem; }

.field-group { display: flex; flex-direction: column; gap: .35rem; }
.field-group label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.input, .login-form input[type="email"], .login-form input[type="password"] {
  width: 100%;
  padding: .65rem .85rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .95rem;
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.input:focus, .login-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.login-error {
  color: var(--red);
  font-size: .85rem;
  background: var(--red-light);
  border: 1px solid var(--red-border);
  padding: .5rem .75rem;
  border-radius: var(--radius-sm);
}

.login-footer {
  margin-top: 1.5rem;
  font-size: .78rem;
  color: var(--text-muted);
  text-align: center;
}
.login-footer code {
  background: var(--bg);
  border-radius: 4px;
  padding: .1em .35em;
  font-size: .75rem;
}

/* ============================================
   BUTTONS
   ============================================ */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  padding: .65rem 1.25rem;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-weight: 600;
  font-family: var(--font-body);
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  cursor: pointer;
}
.btn-primary:hover { background: var(--accent-hover); box-shadow: 0 2px 8px rgba(37,99,235,.3); }
.btn-primary:active { transform: scale(.97); }
.btn-primary svg { width: 16px; height: 16px; }

.btn-primary.btn-full { width: 100%; justify-content: center; padding: .8rem; font-size: 1rem; }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  padding: .6rem 1.1rem;
  background: var(--surface);
  color: var(--text);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 500;
  font-family: var(--font-body);
  transition: all var(--transition);
  cursor: pointer;
}
.btn-secondary:hover { background: var(--bg); border-color: var(--accent); color: var(--accent); }
.btn-secondary svg { width: 15px; height: 15px; }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: all var(--transition);
}
.btn-icon:hover { background: var(--bg); color: var(--text); }
.btn-icon svg { width: 18px; height: 18px; }

.btn-sm {
  padding: .38rem .75rem !important;
  font-size: .8rem !important;
}

.btn-danger {
  background: var(--red);
  color: #fff;
}
.btn-danger:hover { background: #b91c1c; }

/* ============================================
   APP LAYOUT
   ============================================ */
#app-screen {
  min-height: 100vh;
  flex-direction: row;
}

/* ── Sidebar ─────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--text);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0; top: 0; bottom: 0;
  z-index: 100;
  transition: width var(--transition);
  overflow: hidden;
}
.sidebar.collapsed { width: var(--sidebar-w-collapsed); }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.07);
  flex-shrink: 0;
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: .7rem;
  overflow: hidden;
  white-space: nowrap;
}
.sidebar-logo svg { width: 32px; height: 32px; flex-shrink: 0; }
.sidebar-logo span {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: .95rem;
  color: #fff;
  transition: opacity var(--transition);
}
.sidebar.collapsed .sidebar-logo span { opacity: 0; }

.sidebar-toggle {
  color: #94a3b8;
  width: 28px; height: 28px;
  border-radius: 6px;
  font-size: 1.1rem;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}
.sidebar-toggle:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar.collapsed .sidebar-toggle { transform: rotate(180deg); }

.sidebar-nav {
  flex: 1;
  padding: 1rem .75rem;
  display: flex;
  flex-direction: column;
  gap: .25rem;
  overflow-y: auto;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem .75rem;
  border-radius: var(--radius-sm);
  color: #94a3b8;
  font-size: .875rem;
  font-weight: 500;
  white-space: nowrap;
  transition: all var(--transition);
  cursor: pointer;
}
.nav-item:hover { background: rgba(255,255,255,.07); color: #e2e8f0; }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item span { transition: opacity var(--transition); }
.sidebar.collapsed .nav-item span { opacity: 0; }
.sidebar.collapsed .nav-item { justify-content: center; }

.sidebar-footer {
  padding: 1rem .75rem;
  border-top: 1px solid rgba(255,255,255,.07);
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-shrink: 0;
  overflow: hidden;
}
.user-info {
  display: flex;
  align-items: center;
  gap: .6rem;
  flex: 1;
  overflow: hidden;
  min-width: 0;
}
.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: .85rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.user-details {
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: opacity var(--transition);
}
.sidebar.collapsed .user-details { opacity: 0; }
.user-details span { font-size: .8rem; color: #94a3b8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-details span:first-child { color: #e2e8f0; font-weight: 500; }
.user-role {
  font-size: .7rem !important;
  text-transform: uppercase;
  letter-spacing: .05em;
}

/* ── Main ────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left var(--transition);
}
.sidebar.collapsed ~ .main-content { margin-left: var(--sidebar-w-collapsed); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: .85rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.page-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  flex: 1;
}
.topbar-actions { display: flex; align-items: center; gap: .5rem; }

.mobile-only { display: none; }

/* ── Sections ────────────────────────────── */
.section { display: none; padding: 1.5rem; flex-direction: column; gap: 1.25rem; }
.section.active { display: flex; }

/* ============================================
   DASHBOARD
   ============================================ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
}
.kpi-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow);
  border: 1.5px solid var(--border-light);
  transition: transform var(--transition), box-shadow var(--transition);
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.kpi-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.kpi-icon svg { width: 22px; height: 22px; }

.kpi-red   .kpi-icon { background: var(--red-light);    color: var(--red); }
.kpi-green .kpi-icon { background: var(--green-light);  color: var(--green); }
.kpi-yellow .kpi-icon{ background: var(--yellow-light); color: var(--yellow); }
.kpi-blue  .kpi-icon { background: var(--blue-light);   color: var(--blue); }
.kpi-purple .kpi-icon{ background: var(--purple-light); color: var(--purple); }

.kpi-label { font-size: .78rem; color: var(--text-muted); font-weight: 500; margin-bottom: .2rem; }
.kpi-value {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
}

.chart-row {
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  gap: 1rem;
}
.chart-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  border: 1.5px solid var(--border-light);
}
.chart-title {
  font-family: var(--font-display);
  font-size: .95rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--text);
}

.alert-row { display: flex; flex-direction: column; gap: .5rem; }
.alert-item {
  padding: .6rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.alert-warn { background: var(--yellow-light); border: 1px solid var(--yellow-border); color: #92400e; }
.alert-info { background: var(--blue-light);   border: 1px solid #bfdbfe;              color: #1e40af; }

/* ============================================
   FILTERS BAR
   ============================================ */
.filters-bar {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow);
  border: 1.5px solid var(--border-light);
  display: flex;
  flex-direction: column;
  gap: .75rem;
  position: sticky;
  top: var(--topbar-h);
  z-index: 40;
}
.search-wrap {
  position: relative;
}
.search-icon {
  position: absolute;
  left: .85rem;
  top: 50%;
  transform: translateY(-50%);
  width: 17px; height: 17px;
  color: var(--text-muted);
  pointer-events: none;
}
.search-input {
  width: 100%;
  padding: .65rem .9rem .65rem 2.5rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .925rem;
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.10);
}
.filter-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .6rem;
}
.filter-select {
  padding: .5rem .75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .85rem;
  font-family: var(--font-body);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition);
}
.filter-select:focus { border-color: var(--accent); }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .85rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: .4rem .6rem;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.checkbox-label:hover { background: var(--bg); }
.checkbox-label input { cursor: pointer; accent-color: var(--accent); }

/* ============================================
   TARJETAS GRID
   ============================================ */
.tarjetas-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 1rem;
}

.empty-state {
  grid-column: 1/-1;
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}
.empty-state svg { width: 64px; height: 64px; opacity: .4; }
.empty-state p { font-size: .95rem; }

/* ── Tarjeta Sostenedor ──────────────────── */
.tarjeta {
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1.5px solid var(--border-light);
  overflow: hidden;
  transition: transform var(--transition), box-shadow var(--transition);
  animation: fadeIn .3s both;
}
.tarjeta:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.tarjeta-deudor     { background: var(--red-light);    border-color: var(--red-border); }
.tarjeta-abono_parcial { background: var(--yellow-light); border-color: var(--yellow-border); }
.tarjeta-pagado     { background: var(--green-light);  border-color: var(--green-border); }

.tarjeta-header {
  padding: 1.1rem 1.25rem .85rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: .75rem;
}
.tarjeta-info { flex: 1; min-width: 0; }
.tarjeta-nombre {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
  margin-bottom: .25rem;
}
.tarjeta-rut { font-size: .78rem; color: var(--text-secondary); }
.tarjeta-estado {
  padding: .25rem .65rem;
  border-radius: 99px;
  font-size: .73rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  white-space: nowrap;
  flex-shrink: 0;
}
.estado-deudor      { background: var(--red);    color: #fff; }
.estado-abono_parcial{ background: var(--yellow); color: #fff; }
.estado-pagado      { background: var(--green);  color: #fff; }

.tarjeta-meta {
  padding: 0 1.25rem .85rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .4rem .75rem;
  font-size: .82rem;
}
.tarjeta-meta-item { display: flex; align-items: center; gap: .4rem; color: var(--text-secondary); }
.tarjeta-meta-item svg { width: 13px; height: 13px; flex-shrink: 0; }

.tarjeta-montos {
  padding: .75rem 1.25rem;
  border-top: 1px solid rgba(0,0,0,.06);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.tarjeta-monto-total {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
}
.tarjeta-monto-sub { font-size: .75rem; color: var(--text-muted); }
.tarjeta-cuotas {
  text-align: right;
  font-size: .82rem;
  color: var(--text-secondary);
}
.tarjeta-cuotas strong { display: block; font-size: 1.1rem; color: var(--text); }

.tarjeta-alumnos {
  padding: .75rem 1.25rem;
  border-top: 1px solid rgba(0,0,0,.06);
}
.tarjeta-alumno-chip {
  display: inline-flex;
  align-items: center;
  background: rgba(0,0,0,.05);
  border-radius: 99px;
  padding: .2rem .65rem;
  font-size: .75rem;
  margin: .2rem .15rem;
  gap: .35rem;
}
.tarjeta-alumno-chip .chip-monto { font-weight: 600; }

.tarjeta-actions {
  padding: .75rem 1.25rem;
  border-top: 1px solid rgba(0,0,0,.06);
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
}
.tarjeta-actions .btn-sm {
  flex: 1;
  min-width: 0;
  justify-content: center;
  white-space: nowrap;
}

/* ============================================
   UPLOAD SECTION
   ============================================ */
.upload-wrapper { display: flex; flex-direction: column; gap: 1.5rem; }
.section-subtitle {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .06em;
  padding-top: .5rem;
  border-top: 1px solid var(--border);
}

.upload-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.master-card { border-color: var(--accent); }
.master-card .upload-card-header { background: var(--accent-light); }

.upload-card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-light);
}
.upload-card-header h3 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: .95rem;
  margin: .35rem 0 .2rem;
}
.upload-card-header p { font-size: .82rem; color: var(--text-muted); }

.upload-badge {
  display: inline-block;
  padding: .2rem .6rem;
  border-radius: 99px;
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
}
.upload-badge.master { background: var(--accent); color: #fff; }
.upload-badge.mes    { background: var(--bg);     color: var(--text-secondary); border: 1px solid var(--border); }

.upload-zone {
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: background var(--transition);
  border-bottom: 1px solid var(--border-light);
}
.upload-zone:hover { background: var(--bg); }
.upload-zone.drag-over { background: var(--accent-light); }
.upload-zone svg { width: 48px; height: 48px; margin: 0 auto .75rem; opacity: .8; }
.upload-zone p { font-size: .9rem; color: var(--text-secondary); margin-bottom: .25rem; }
.upload-hint { font-size: .78rem !important; color: var(--text-muted) !important; }
.link-label { color: var(--accent); cursor: pointer; font-weight: 600; }
.link-label:hover { text-decoration: underline; }
.file-input { position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none; }

.upload-status {
  padding: .75rem 1.25rem;
  font-size: .85rem;
}
.upload-status.success { color: var(--green); background: var(--green-light); }
.upload-status.error   { color: var(--red);   background: var(--red-light);   }

.months-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}
.month-card .upload-zone { padding: 1.25rem; }
.month-card .upload-zone svg { width: 32px; height: 32px; }
.month-files {
  padding: .75rem 1.25rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem;
}
.month-file-slot {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: .6rem .85rem;
  font-size: .8rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}
.month-file-slot:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }
.month-file-slot.loaded { border-color: var(--green); color: var(--green); border-style: solid; background: var(--green-light); }
.month-file-slot label { cursor: pointer; font-weight: 500; display: block; }
.month-file-slot .slot-name { font-size: .72rem; margin-top: .15rem; opacity: .8; word-break: break-all; }
.process-btn {
  margin: .75rem 1.25rem;
}

/* ============================================
   TEMPLATES
   ============================================ */
.templates-wrapper { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
@media (max-width: 860px) { .templates-wrapper { grid-template-columns: 1fr; } }

.template-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.template-card h3 {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
}

.textarea {
  width: 100%;
  padding: .65rem .85rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .875rem;
  resize: vertical;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.5;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.10); }

.variables-hint {
  font-size: .78rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  align-items: center;
  background: var(--bg);
  padding: .6rem .85rem;
  border-radius: var(--radius-sm);
}
.variables-hint code {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: .1em .4em;
  font-size: .75rem;
  color: var(--accent);
  cursor: pointer;
  transition: background var(--transition);
}
.variables-hint code:hover { background: var(--accent-light); }

/* ============================================
   USERS
   ============================================ */
.users-wrapper { display: flex; flex-direction: column; gap: 1.25rem; }
.users-header { display: flex; align-items: center; justify-content: space-between; }
.users-header h3 { font-family: var(--font-display); font-size: 1.1rem; font-weight: 700; }
.users-list { display: flex; flex-direction: column; gap: .5rem; }

.user-row {
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  padding: .85rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow);
}
.user-row-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: .9rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.user-row-info { flex: 1; }
.user-row-name { font-weight: 600; font-size: .9rem; }
.user-row-email { font-size: .78rem; color: var(--text-muted); }
.user-row-role {
  padding: .2rem .55rem;
  border-radius: 99px;
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.role-admin { background: var(--accent); color: #fff; }
.role-user  { background: var(--bg);     color: var(--text-secondary); border: 1px solid var(--border); }

/* ============================================
   REPORTS
   ============================================ */
.reportes-wrapper { display: flex; flex-direction: column; gap: 1.5rem; max-width: 700px; }
.reportes-wrapper h3 { font-family: var(--font-display); font-size: 1.1rem; font-weight: 700; }
.report-options { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 600px) { .report-options { grid-template-columns: 1fr; } }

.audit-log {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  padding: 1rem;
  max-height: 340px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: .4rem;
  box-shadow: var(--shadow);
}
.audit-entry {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  padding: .55rem .75rem;
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-size: .83rem;
}
.audit-ts { color: var(--text-muted); white-space: nowrap; flex-shrink: 0; }
.audit-user { font-weight: 600; color: var(--accent); flex-shrink: 0; }
.audit-msg  { color: var(--text-secondary); }

/* ============================================
   MODALS
   ============================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 200;
  padding: 2rem 1rem;
  overflow-y: auto;
  backdrop-filter: blur(2px);
  animation: fadeOverlay .15s both;
}
@keyframes fadeOverlay {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  animation: slideModal .2s cubic-bezier(.22,1,.36,1) both;
}
.modal-lg { max-width: 760px; }

@keyframes slideModal {
  from { opacity: 0; transform: translateY(-20px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
}
.modal-close {
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.modal-close:hover { background: var(--bg); color: var(--text); }

.modal-body { padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: .75rem;
  padding-top: .5rem;
}

/* Modal detalle sostenedor */
.detalle-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem .75rem;
  margin-bottom: 1rem;
}
.detalle-field label { font-size: .75rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; }
.detalle-field span  { display: block; font-size: .9rem; font-weight: 500; color: var(--text); }

.detalle-alumnos-title {
  font-family: var(--font-display);
  font-size: .9rem;
  font-weight: 700;
  margin: .5rem 0;
  padding-top: .75rem;
  border-top: 1px solid var(--border);
}

.alumno-detalle {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: .75rem 1rem;
  margin-bottom: .5rem;
}
.alumno-detalle-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .5rem;
}
.alumno-detalle-nombre { font-weight: 700; font-size: .9rem; }
.alumno-detalle-monto  { font-weight: 700; color: var(--red); }

.cuotas-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .8rem;
  margin-top: .35rem;
}
.cuotas-table th {
  text-align: left;
  padding: .3rem .5rem;
  background: var(--border-light);
  color: var(--text-muted);
  font-weight: 600;
  font-size: .72rem;
  text-transform: uppercase;
}
.cuotas-table td {
  padding: .35rem .5rem;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-secondary);
}
.cuotas-table tr:last-child td { border-bottom: none; }

.status-pill {
  padding: .1rem .45rem;
  border-radius: 99px;
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
}
.pill-pagado      { background: var(--green-light); color: var(--green); }
.pill-abono_parcial{ background: var(--yellow-light); color: var(--yellow); }
.pill-deudor      { background: var(--red-light);   color: var(--red); }

/* Gestión historial */
.gestion-historial {
  max-height: 200px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: .4rem;
}
.gestion-entry {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: .6rem .85rem;
  font-size: .82rem;
}
.gestion-entry-header {
  display: flex;
  justify-content: space-between;
  font-size: .75rem;
  color: var(--text-muted);
  margin-bottom: .2rem;
}
.gestion-tipo-badge {
  padding: .1rem .4rem;
  border-radius: 99px;
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  background: var(--border-light);
  color: var(--text-secondary);
}

.gestion-entry-body {
  margin-top: .1rem;
}
.gestion-action-btn {
  background: none;
  border: none;
  padding: .1rem .25rem;
  border-radius: 4px;
  font-size: .78rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--transition), background var(--transition);
  line-height: 1;
}
.gestion-entry:hover .gestion-action-btn {
  opacity: 1;
}
.gestion-action-btn:hover {
  background: var(--border-light);
}
.gestion-action-delete:hover {
  background: var(--red-light);
}

/* Email preview */
.email-preview-header {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: .75rem 1rem;
  font-size: .87rem;
  display: flex;
  flex-direction: column;
  gap: .3rem;
}
.email-body-preview {
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1.25rem;
  font-size: .9rem;
  line-height: 1.65;
  color: var(--text);
  white-space: pre-wrap;
  max-height: 320px;
  overflow-y: auto;
}

/* WhatsApp bubble */
.wa-bubble {
  background: #dcf8c6;
  border-radius: 12px 12px 0 12px;
  padding: 1rem 1.25rem;
  font-size: .9rem;
  line-height: 1.6;
  color: #0f172a;
  white-space: pre-wrap;
  max-height: 300px;
  overflow-y: auto;
  align-self: flex-end;
  box-shadow: 0 1px 2px rgba(0,0,0,.1);
}

/* ============================================
   TOAST
   ============================================ */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  background: var(--text);
  color: #fff;
  padding: .75rem 1.5rem;
  border-radius: 99px;
  font-size: .875rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: toastIn .2s cubic-bezier(.22,1,.36,1) both;
  white-space: nowrap;
}
.toast.success { background: var(--green); }
.toast.error   { background: var(--red); }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 900px) {
  .chart-row { grid-template-columns: 1fr; }
  .tarjetas-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform var(--transition); }
  .sidebar.mobile-open { transform: translateX(0); }
  .main-content { margin-left: 0 !important; }
  .mobile-only { display: flex !important; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .detalle-grid { grid-template-columns: 1fr; }
  .months-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .filter-controls { flex-direction: column; align-items: stretch; }
  .filter-select { width: 100%; }
}

/* ── Scrollbar ───────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Selection ───────────────────────────── */
::selection { background: rgba(37,99,235,.18); }

/* ============================================
   SNAPSHOT UPLOAD (nuevo modelo de cargas)
   ============================================ */

.snapshots-history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: .25rem;
}

/* Preview panel */
.snapshot-preview {
  border-top: 1px solid var(--border-light);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  animation: fadeIn .25s both;
}

.snapshot-preview-info {
  display: flex;
  align-items: center;
  gap: .85rem;
}
.preview-file-icon {
  font-size: 2rem;
  flex-shrink: 0;
}
.preview-filename {
  font-weight: 700;
  font-size: .95rem;
  color: var(--text);
}
.preview-sub {
  font-size: .8rem;
  color: var(--text-muted);
  margin-top: .15rem;
}

.snapshot-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: .5rem;
}
.snapshot-stat-pill {
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .5rem .85rem;
  display: flex;
  flex-direction: column;
  gap: .1rem;
}
.snapshot-stat-pill .sp-label { font-size: .72rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; }
.snapshot-stat-pill .sp-value { font-family: var(--font-display); font-size: 1.05rem; font-weight: 700; }
.sp-red    { border-color: var(--red-border);    background: var(--red-light); }
.sp-green  { border-color: var(--green-border);  background: var(--green-light); }
.sp-yellow { border-color: var(--yellow-border); background: var(--yellow-light); }
.sp-blue   { border-color: #bfdbfe; background: var(--blue-light); }

/* Comparison diff block */
.snapshot-compare {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: .85rem 1rem;
  font-size: .85rem;
  display: flex;
  flex-direction: column;
  gap: .35rem;
}
.snapshot-compare h4 {
  font-size: .82rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: .25rem;
}
.compare-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .25rem 0;
  border-bottom: 1px solid var(--border-light);
}
.compare-row:last-child { border-bottom: none; }
.compare-icon { font-size: 1rem; flex-shrink: 0; }
.compare-name { flex: 1; font-weight: 500; color: var(--text); }
.compare-prev { color: var(--text-muted); text-decoration: line-through; font-size: .8rem; }
.compare-arrow { color: var(--text-muted); }
.compare-curr { font-weight: 700; }
.compare-curr.paid    { color: var(--green); }
.compare-curr.partial { color: var(--yellow); }
.compare-curr.higher  { color: var(--red); }
.compare-curr.new     { color: var(--blue); }
.compare-delta {
  font-size: .78rem;
  padding: .1rem .45rem;
  border-radius: 99px;
  font-weight: 700;
}
.delta-down  { background: var(--green-light);  color: var(--green); }
.delta-up    { background: var(--red-light);    color: var(--red); }
.delta-new   { background: var(--blue-light);   color: var(--blue); }
.delta-same  { background: var(--bg);           color: var(--text-muted); }

.snapshot-actions {
  display: flex;
  gap: .75rem;
  justify-content: flex-end;
  padding-top: .25rem;
}

/* Historial de cargas */
.snapshots-list {
  display: flex;
  flex-direction: column;
  gap: .6rem;
}

.snapshot-item {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: all var(--transition);
}
.snapshot-item:hover { border-color: var(--accent); background: var(--accent-light); }
.snapshot-item.active-snap { border-color: var(--accent); background: var(--accent-light); }

.snapshot-item-icon {
  font-size: 1.6rem;
  flex-shrink: 0;
}
.snapshot-item-info { flex: 1; min-width: 0; }
.snapshot-item-date {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: .95rem;
  color: var(--text);
}
.snapshot-item-meta { font-size: .78rem; color: var(--text-muted); margin-top: .15rem; }

.snapshot-item-badges {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  align-items: center;
}
.snap-badge {
  padding: .18rem .55rem;
  border-radius: 99px;
  font-size: .72rem;
  font-weight: 700;
}
.snap-badge-latest { background: var(--accent); color: #fff; }
.snap-badge-count  { background: var(--bg); color: var(--text-secondary); border: 1px solid var(--border); }

.snapshot-item-actions {
  display: flex;
  gap: .35rem;
  flex-shrink: 0;
}
.snapshot-item-actions .btn-icon { color: var(--text-muted); }
.snapshot-item-actions .btn-icon:hover { color: var(--red); background: var(--red-light); }

/* Confirm delete modal content */
.confirm-delete-info {
  background: var(--red-light);
  border: 1.5px solid var(--red-border);
  border-radius: var(--radius-sm);
  padding: .85rem 1rem;
  font-size: .875rem;
  color: var(--red);
}


/* ============================================
   DASHBOARD TABLES / EXECUTIVE SUMMARY
   ============================================ */
.dashboard-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.dashboard-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
}

.dashboard-card-header {
  margin-bottom: .85rem;
}

.dashboard-card-header h3 {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: .2rem;
}

.dashboard-card-header p {
  color: var(--text-muted);
  font-size: .82rem;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.table-modern {
  width: 100%;
  border-collapse: collapse;
  min-width: 520px;
}

.table-modern th {
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  text-align: left;
  padding: .7rem .75rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table-modern td {
  padding: .72rem .75rem;
  border-bottom: 1px solid var(--border-light);
  font-size: .88rem;
  color: var(--text);
  vertical-align: top;
}

.table-modern tbody tr:hover {
  background: var(--surface-2);
}

.rank-cell {
  width: 44px;
  color: var(--text-muted) !important;
  font-weight: 700;
}

.table-subtext {
  margin-top: .15rem;
  color: var(--text-muted);
  font-size: .75rem;
  font-weight: 400;
}

.money-cell {
  text-align: right;
  font-weight: 700;
  white-space: nowrap;
}

.money-cell.danger { color: var(--red); }
.money-cell.success { color: var(--green); }

.table-empty {
  color: var(--text-muted) !important;
  text-align: center;
  padding: 1rem !important;
}

@media (max-width: 980px) {
  .dashboard-grid-2 {
    grid-template-columns: 1fr;
  }
}

/* ============================================
   DASHBOARD AJUSTADO: KPIs FIJOS + MODAL CURSO
   ============================================ */
#section-dashboard .kpi-grid {
  position: sticky;
  top: 64px;
  z-index: 45;
  background: var(--bg);
  padding: .25rem 0 .75rem;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
}

.detail-cell {
  text-align: center;
  white-space: nowrap;
}

.btn-lupa {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-light);
  color: var(--accent);
  border: 1px solid rgba(37,99,235,.18);
  font-size: 1rem;
  transition: transform var(--transition), box-shadow var(--transition), background var(--transition);
}

.btn-lupa:hover {
  background: #dbeafe;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(37,99,235,.18);
}

.modal-xl {
  max-width: 920px;
}

.course-modal {
  overflow: hidden;
}

.mac-modal-header {
  align-items: flex-start;
}

.modal-subtitle {
  color: var(--text-muted);
  font-size: .82rem;
  margin-top: .15rem;
}

.mac-close {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ff5f57;
  border: 1px solid rgba(0,0,0,.12);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.25);
  flex-shrink: 0;
  margin-top: .2rem;
}

.mac-close:hover {
  filter: brightness(.92);
  transform: scale(1.08);
}

@media (max-width: 1180px) {
  #section-dashboard .kpi-grid {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
  }
}

@media (max-width: 640px) {
  #section-dashboard .kpi-grid {
    position: static;
    grid-template-columns: 1fr;
  }
}

/* Alertas clicables con detalle */
.alert-item {
  width: 100%;
  text-align: left;
}
.alert-clickable {
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), filter var(--transition);
}
.alert-clickable:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 10px rgba(15, 23, 42, .08);
  filter: brightness(.99);
}


/* Comparativo mensual estilo resumen ejecutivo */
#comparativo-body .comparison-row td {
  padding: 1rem .95rem;
  vertical-align: middle;
}

#comparativo-body .comparison-row.danger-row {
  background: #f7f5ee;
}

#comparativo-body .month-summary-cell strong {
  display: block;
  margin-bottom: .42rem;
  font-size: .92rem;
}

.month-progress-track {
  display: block;
  width: 160px;
  max-width: 100%;
  height: 4px;
  background: #eeece5;
  border-radius: 999px;
  overflow: hidden;
}

.month-progress {
  display: block;
  height: 100%;
  border-radius: 999px;
}

.month-progress.success { background: #53c59a; }
.month-progress.danger { background: #ef4f58; }

.diff-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: .22rem .55rem;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 800;
  line-height: 1;
}

.diff-pill.success {
  color: #087456;
  background: #dff7ec;
}

.diff-pill.danger {
  color: #c81e3a;
  background: #ffe9ec;
}

.diff-pill.neutral {
  color: var(--text-muted);
  background: var(--surface-2);
}

.dashboard-card:has(#comparativo-body) {
  border: 1px solid #ddd8ce;
  background: #fffdf8;
}

.dashboard-card:has(#comparativo-body) .table-modern th {
  background: #f6f4ee;
  color: #4b4b45;
}

.dashboard-card:has(#comparativo-body) .table-modern td {
  border-bottom-color: #ddd8ce;
}

.dashboard-card:has(#comparativo-body) .table-modern tbody tr:last-child td {
  border-bottom: none;
}

/* Ajuste final: comparativo por mes más angosto, centrado y alineado */
.comparativo-card {
  width: min(1120px, 100%);
  margin-left: auto;
  margin-right: auto;
  border: 1px solid #ddd8ce;
  background: #fffdf8;
}

.comparativo-header {
  text-align: center;
  justify-content: center;
  align-items: center;
}

.comparativo-header h3,
.comparativo-header p {
  width: 100%;
  text-align: center;
}

.comparativo-card .table-responsive {
  overflow-x: auto;
}

.comparativo-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
}

.comparativo-table th,
.comparativo-table td {
  text-align: center;
  vertical-align: middle;
}

.comparativo-table th:first-child,
.comparativo-table td:first-child {
  text-align: left;
  width: 28%;
}

.comparativo-table th:nth-child(2),
.comparativo-table th:nth-child(3),
.comparativo-table th:nth-child(4),
.comparativo-table td:nth-child(2),
.comparativo-table td:nth-child(3),
.comparativo-table td:nth-child(4) {
  width: 24%;
}

.comparativo-table .money-cell,
.comparativo-table .diff-cell {
  text-align: center;
}

.comparativo-table .diff-cell {
  display: flex;
  justify-content: center;
  align-items: center;
}

.comparativo-table .month-summary-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
}

.comparativo-table .month-progress-track {
  width: 160px;
}

@media (max-width: 900px) {
  .comparativo-card {
    width: 100%;
  }

  .comparativo-table {
    min-width: 760px;
  }
}
