/* ============================================================
   assets/css/app.css — Gestión Inicial
   Sistema de diseño global
   ============================================================ */

/* Tipografía del sistema para evitar dependencias externas y reducir CLS */

/* Variables */
:root {
  /* ── Paleta Gestión Inicial ─────────────────────────── */
  --brand:        #2b2353;   /* Violeta oscuro — principal */
  --brand-dark:   #1e1840;   /* Violeta más oscuro — hover */
  --brand-light:  #f0eef8;   /* Violeta muy claro — fondos */
  --brand-mid:    #3d3478;   /* Violeta medio */

  --yellow:       #eaa41c;   /* Amarillo/dorado */
  --yellow-light: #fdf5e0;
  --yellow-dark:  #c48a14;

  --red:          #be264e;   /* Rojo/rosa */
  --red-light:    #fde8ee;
  --red-dark:     #9c1d3f;

  --blue:         #1f9ef3;   /* Azul claro */
  --blue-light:   #e6f4fe;
  --blue-dark:    #1480cc;

  /* ── Textos ─────────────────────────────────────────── */
  --text-1:       #111827;
  --text-2:       #4B5563;   /* era #6B7280 — subido para pasar WCAG AA sobre fondo blanco */
  --text-3:       #6B7280;   /* era #9CA3AF — subido para pasar WCAG AA (ratio 4.6:1) */

  /* ── Neutros ────────────────────────────────────────── */
  --border:       #E5E7EB;
  --border-dark:  #D1D5DB;
  --bg:           #F9FAFB;
  --bg-2:         #F3F4F6;
  --white:        #FFFFFF;

  /* ── Semánticos (usan la paleta) ────────────────────── */
  --success:      #059669;
  --success-bg:   #ECFDF5;
  --error:        var(--red);
  --error-bg:     var(--red-light);
  --warning:      var(--yellow-dark);
  --warning-bg:   var(--yellow-light);
  --info:         var(--blue);
  --info-bg:      var(--blue-light);

  /* ── Layout ─────────────────────────────────────────── */
  --sidebar-w:    220px;
  --topbar-h:     60px;
  --radius:       10px;
  --radius-sm:    6px;
  --radius-lg:    14px;
  --shadow-sm:    0 1px 3px rgba(0,0,0,0.06);
  --shadow:       0 4px 16px rgba(0,0,0,0.06);
  --shadow-lg:    0 8px 32px rgba(0,0,0,0.08);
}

/* Reset base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  color: var(--text-1);
  background: var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
/* Links dentro de texto corrido: subrayado para no depender solo del color (WCAG 1.4.1) */
p a, td a, li a, .text-link { text-decoration: underline; text-underline-offset: 2px; }
p a:hover, td a:hover, li a:hover, .text-link:hover { text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; display: block; }

.skip-link { position:absolute; left:16px; top:-56px; z-index:999; background:var(--white); color:var(--brand); border:2px solid var(--brand); border-radius:10px; padding:10px 14px; font-weight:700; text-decoration:none; box-shadow:var(--shadow); transition:top .15s ease; }
.skip-link:focus { top:12px; }

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid rgba(43,35,83,0.28);
  outline-offset: 2px;
}

/* ============================================================
   Auth pages (login, recuperar, reset)
   ============================================================ */

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(ellipse 800px 600px at 25% 15%, rgba(43,35,83,0.07) 0%, transparent 60%),
    radial-gradient(ellipse 600px 500px at 80% 85%, rgba(31,158,243,0.06) 0%, transparent 60%),
    var(--bg);
}

.login-wrap {
  width: 100%;
  max-width: 420px;
  animation: fadeUp 0.35s ease both;
}

.brand {
  text-align: center;
  margin-bottom: 28px;
}
.brand > img {
  display: block;
  margin: 0 auto 12px;
}
/* Legado por si queda en algún template */
.brand-icon {
  width: 52px; height: 52px;
  background: var(--brand);
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
  box-shadow: 0 8px 24px rgba(43,35,83,0.25);
}
.brand-icon svg { width: 26px; height: 26px; fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.brand h1 { font-size: 21px; font-weight: 700; color: var(--text-1); letter-spacing: -0.3px; }
.brand p  { font-size: 14px; color: var(--text-2); margin-top: 3px; }

.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px;
  box-shadow: var(--shadow-lg);
}
.card h2 { font-size: 17px; font-weight: 700; color: var(--text-1); margin-bottom: 22px; }

/* Form fields */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--text-1); margin-bottom: 5px; }
.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 10px 13px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text-1);
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  /* Evitar zoom automático en iOS (requiere min 16px) */
  touch-action: manipulation;
}
@media (max-width: 768px) {
  .field input,
  .field select,
  .field textarea { font-size: 16px; }
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(43,35,83,0.15);
}
.field input::placeholder,
.field textarea::placeholder { color: var(--text-3); }
.field textarea { resize: vertical; min-height: 90px; }
.field select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }

.field-hint { font-size: 12px; color: var(--text-2); margin-top: 4px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* Botones */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; padding: 12px;
  font-size: 15px; font-weight: 700; font-family: inherit;
  color: #fff; background: var(--brand);
  border: none; border-radius: 8px;
  cursor: pointer; transition: background 0.15s, transform 0.1s;
  letter-spacing: 0.1px;
}
.btn-primary:hover  { background: var(--brand-dark); text-decoration: none; }
.btn-primary:active { transform: scale(0.98); }

.btn-secondary {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 18px;
  font-size: 14px; font-weight: 600; font-family: inherit;
  color: var(--text-1); background: var(--white);
  border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer; transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn-secondary:hover { background: var(--bg-2); border-color: var(--border-dark); text-decoration: none; }

.btn-danger {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 18px;
  font-size: 14px; font-weight: 600; font-family: inherit;
  color: #fff; background: var(--error);
  border: none; border-radius: 8px;
  cursor: pointer; transition: background 0.15s;
}
.btn-danger:hover { background: #B91C1C; text-decoration: none; }

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-icon-only { width: 36px; height: 36px; padding: 0; }

.forgot { text-align: center; margin-top: 18px; font-size: 13px; color: var(--text-2); }
.forgot a { color: var(--brand); font-weight: 600; }

/* Alerts / Flash */
.flash, .alert-error, .alert-success, .alert-warning, .alert-info {
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 18px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.flash--error,  .alert-error   { background: var(--error-bg);   border: 1px solid #FECACA; color: #B91C1C; }
.flash--success,.alert-success { background: var(--success-bg); border: 1px solid #A7F3D0; color: #065F46; }
.flash--warning,.alert-warning { background: var(--warning-bg); border: 1px solid #FCD34D; color: #92400E; }
.flash--info,   .alert-info    { background: var(--info-bg);    border: 1px solid #a8d8f8; color: #1266a8; }

/* ============================================================
   Layout principal (sidebar + content)
   ============================================================ */

.layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--white);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
  z-index: 100;
}
.sidebar-brand {
  padding: 16px 18px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
/* Soporte para logo PNG directo (sin .s-icon) */
.sidebar-brand > img {
  width: 36px; height: 36px;
  object-fit: contain; flex-shrink: 0;
}
/* Soporte legado para .s-icon */
.sidebar-brand .s-icon {
  width: 34px; height: 34px;
  background: var(--brand);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.sidebar-brand .s-icon svg { width: 18px; height: 18px; stroke: #fff; fill: none; stroke-width: 2; }
.sidebar-brand .s-name { font-size: 13px; font-weight: 700; color: var(--text-1); line-height: 1.2; }
.sidebar-brand .s-inst { font-size: 10px; color: var(--text-2); margin-top: 1px; }

.sidebar-nav { flex: 1; padding: 12px 10px; overflow-y: auto; min-height: 0; }
.nav-section { margin-bottom: 2px; }
.nav-section-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
  padding: 6px 8px 3px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  text-decoration: none;
}
.nav-item:hover { background: var(--bg-2); color: var(--text-1); text-decoration: none; }
.nav-item.active { background: var(--brand-light); color: var(--brand); font-weight: 600; }
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.sidebar-footer {
  padding: 12px 10px;
  border-top: 1px solid var(--border);
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
}
.sidebar-user:hover { background: var(--bg-2); text-decoration: none; }
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  flex-shrink: 0;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.sidebar-user-info .name  { font-size: 13px; font-weight: 600; color: var(--text-1); }
.sidebar-user-info .rol   { font-size: 11px; color: var(--text-2); }

/* Main content */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.topbar {
  height: var(--topbar-h);
  background: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 28px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-title { font-size: 16px; font-weight: 700; color: var(--text-1); flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.content, main.content { padding: 28px; flex: 1; }

/* ============================================================
   Componentes de UI
   ============================================================ */

/* Tabla */
.table-wrap { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
thead th {
  background: var(--bg-2);
  padding: 12px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 13px 16px;
  font-size: 14px;
  color: var(--text-1);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--bg); }

/* Cards de contenido */
.page-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
}
.page-card h3 { font-size: 15px; font-weight: 700; color: var(--text-1); margin-bottom: 16px; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.stat-card .stat-label { font-size: 12px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; color: var(--text-1); line-height: 1.1; margin-top: 6px; }
.stat-card .stat-sub   { font-size: 12px; color: var(--text-3); margin-top: 4px; }

/* Badge / chips */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-green   { background: #DCFCE7; color: #166534; }
.badge-red     { background: var(--red-light); color: var(--red-dark); }
.badge-yellow  { background: var(--yellow-light); color: var(--yellow-dark); }
.badge-blue    { background: var(--blue-light); color: var(--blue-dark); }
.badge-gray    { background: var(--bg-2); color: var(--text-2); }
.badge-purple  { background: #ede9fa; color: var(--brand); }

/* Paginación */
.pagination { display: flex; align-items: center; gap: 6px; margin-top: 20px; }
.pagination a, .pagination span {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-2);
  border: 1px solid var(--border);
  text-decoration: none;
  transition: background 0.12s;
}
.pagination a:hover { background: var(--bg-2); text-decoration: none; }
.pagination .current { background: var(--brand); color: #fff; border-color: var(--brand); }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-2);
}
.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state p { font-size: 15px; color: var(--text-2); }
.empty-state .empty-title { font-size: 16px; font-weight: 600; color: var(--text-1); margin-bottom: 6px; }

/* Acciones de fila en tabla */
.row-actions { display: flex; align-items: center; gap: 6px; }
.btn-row {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--white);
  color: var(--text-2);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  text-decoration: none;
}
.btn-row:hover { background: var(--bg-2); border-color: var(--border-dark); color: var(--text-1); text-decoration: none; }
.btn-row.danger:hover { background: var(--error-bg); border-color: #FECACA; color: var(--error); }
.btn-row svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Formularios en page-card */
.form-actions { display: flex; align-items: center; gap: 10px; margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--border); }
.form-actions .btn-primary { width: auto; }

/* Animaciones */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Responsive básico */
/* ============================================================
   RESPONSIVE — Mobile first desde 768px
   ============================================================ */

/* Botón hamburguesa — visible siempre en mobile, oculto en desktop */
.menu-toggle {
  display: none;
  background: none; border: none; cursor: pointer;
  padding: 8px; border-radius: 8px;
  color: var(--text-1);
  align-items: center; justify-content: center;
  flex-shrink: 0;
  min-width: 40px; min-height: 40px;
}
.menu-toggle svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.45); z-index: 199;
  -webkit-tap-highlight-color: transparent;
}

/* DESKTOP: sidebar visible fijo */
@media (min-width: 769px) {
  .sidebar { position: fixed; transform: none !important; }
  .main { margin-left: var(--sidebar-w); }
  .menu-toggle { display: none !important; }
}

/* MOBILE: sidebar oculto, hamburguesa visible */
@media (max-width: 768px) {
  .sidebar {
    position: fixed !important;
    top: 0; left: 0; bottom: 0;
    transform: translateX(-100%) !important;
    transition: transform .28s cubic-bezier(.4,0,.2,1);
    z-index: 200;
    width: 270px !important;
    box-shadow: 4px 0 28px rgba(0,0,0,.18);
  }
  .sidebar.open { transform: translateX(0) !important; }
  .sidebar-overlay.open { display: block; }
  .main { margin-left: 0 !important; width: 100% !important; }
  .menu-toggle { display: flex !important; }
  .topbar { padding: 0 12px; gap: 10px; }
  .topbar-title { font-size: 15px; }
  .content, main.content { padding: 14px; }
  .field-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-wrap table { min-width: 540px; }
  .topbar-actions .btn-secondary { display: none; }
  .form-actions { flex-direction: column; }
  .form-actions .btn-primary,
  .form-actions .btn-secondary { width: 100%; justify-content: center; }
  /* Inputs: evitar zoom iOS */
  .field input, .field select, .field textarea { font-size: 16px; }
  /* Touch targets */
  .btn-primary, .btn-secondary { min-height: 44px; }
  .nav-item { min-height: 44px; }
  .btn-row { min-height: 36px; min-width: 36px; }
  .hide-mobile { display: none !important; }
}

@media (max-width: 480px) {
  .content, main.content { padding: 10px; }
  .page-card { padding: 14px; border-radius: 10px; }
  .stat-value { font-size: 22px; }
  .stat-label { font-size: 10px; }
  .topbar { padding: 0 8px; }
  [style*="grid-template-columns:1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr"],
  [style*="grid-template-columns:1fr 280px"],
  [style*="grid-template-columns:1fr 240px"],
  [style*="grid-template-columns:280px 1fr"],
  [style*="grid-template-columns:320px 1fr"],
  [style*="grid-template-columns:380px 1fr"],
  [style*="grid-template-columns:1fr 360px"] {
    grid-template-columns: 1fr !important;
  }
}

/* ============================================================
   Notificaciones (portal familia)
   ============================================================ */

.notif-list { display: flex; flex-direction: column; gap: 0; }
.notif-item {
  display: flex; align-items: flex-start; gap: 14px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--bg); }
.notif-item--unread { background: var(--brand-light); }
.notif-item--unread:hover { background: #E0E7FF; }

/* ============================================================
   TOUCH — Tamaños mínimos para mobile (44px touch target)
   ============================================================ */
@media (max-width: 768px) {
  /* Botones con área de toque mínima */
  .btn-primary, .btn-secondary { min-height: 44px; }
  .btn-sm { min-height: 36px; }
  .btn-row { min-height: 36px; min-width: 36px; }

  /* Nav items táctiles */
  .nav-item { padding: 10px; min-height: 44px; }

  /* Tablas más legibles */
  .table-wrap table { font-size: 13px; }
  .table-wrap th { font-size: 11px; }

  /* Ocultar columnas secundarias */
  .hide-mobile { display: none !important; }
}
