/* ============================================================
   🧠 Karpus Kids — Global Layout System
   Regla de oro: en móvil el scroll es del DOCUMENTO.
                 en desktop el scroll es del .main.
   ============================================================ */

/* ── 1. RESET ────────────────────────────────────────────────── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  overflow-x: hidden;
  max-width: 100%;
}

/* ── 2. APP SHELL ────────────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: row;
  min-height: 100dvh;
}

/* ── 3. WRAPPER CONTENIDO ────────────────────────────────────── */
.app-content-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100dvh;
}

/* Desktop: Flexbox — sidebar is in-flow, content fills remainder.
   No margin-left needed. Width transition on sidebar does the work.
   See css/karpus-modern.css SIDEBAR DESKTOP block. */
@media (min-width: 768px) {
  .app-content-wrapper { height: 100dvh; overflow: hidden; margin-left: 0 !important; }
}

/* Móvil: sin margin, sin overflow hidden */
@media (max-width: 767px) {
  .app-content-wrapper {
    margin-left: 0 !important;
    height: auto !important;
    overflow: visible !important;
  }
}

/* ── 4. HEADER ───────────────────────────────────────────────── */
.header {
  position: sticky;
  top: 0;
  z-index: 200;
  background: #fff;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 1px 0 rgba(0,0,0,0.06);
  flex-shrink: 0;
  min-height: 52px;
}

/* ── 5. MAIN ─────────────────────────────────────────────────── */

/* Desktop: scroll interno */
@media (min-width: 768px) {
  .main {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 24px 24px 32px;
    height: calc(100dvh - 52px);
  }
}

/* Móvil: scroll del documento (NO overflow-y en .main) */
@media (max-width: 767px) {
  .main {
    flex: 1;
    overflow: visible;
    padding: 16px 16px 80px;
    min-height: calc(100dvh - 52px);
  }
}

/* ── 6. SIDEBAR ──────────────────────────────────────────────── */
/* Only applies to panels with slide-in sidebar (directora, asistente, maestra) */
/* Panel padre uses a bottom-nav pattern — excluded via .panel-padre-body */
body:not(.panel-padre-body) aside#sidebar {
  position: fixed;
  top: 0;
  left: 0;
  height: 100dvh;
  z-index: 1050;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
  transition: transform 0.3s ease, width 0.3s ease;
  will-change: transform;
}
body:not(.panel-padre-body) aside#sidebar::-webkit-scrollbar { display: none; }

@media (max-width: 767px) {
  body:not(.panel-padre-body) aside#sidebar {
    transform: translateX(-100%);
    width: 280px !important;
  }
  body:not(.panel-padre-body) aside#sidebar.mobile-visible {
    transform: translateX(0) !important;
    box-shadow: 8px 0 32px rgba(0,0,0,0.25);
  }
}

/* ── 7. OVERLAY ──────────────────────────────────────────────── */
#sidebarOverlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1040;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  cursor: pointer;
  display: none;
}

/* ── 8. SECCIONES ────────────────────────────────────────────── */
.section { display: none; }
.section.active {
  display: block;
  animation: karpusFadeIn 0.25s ease-out;
}
@keyframes karpusFadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── 9. CARDS ────────────────────────────────────────────────── */
.card {
  background: #fff;
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

/* ── 10. TABLAS RESPONSIVE ───────────────────────────────────── */
.table-container,
.table-scroll-wrap,
.responsive-panel {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 12px;
}
.table-container table,
.table-scroll-wrap table,
.table-responsive {
  width: 100%;
  border-collapse: collapse;
  min-width: 560px;
}

/* ── 11. BOTONES ─────────────────────────────────────────────── */
.btn {
  border: none;
  border-radius: 12px;
  padding: 10px 16px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: linear-gradient(135deg, #0B63C7, #0850A0); color: #fff; box-shadow: 0 4px 14px rgba(11,99,199,.25); }
.btn-success { background: var(--sc-green, #28B54D); color: #fff; }
.btn-danger  { background: #ef4444; color: #fff; }
.btn-ghost   { background: #f1f5f9; color: #475569; }
@media (max-width: 480px) {
  .btn-mobile-full { width: 100%; justify-content: center; }
}

/* ── 12. GRIDS ───────────────────────────────────────────────── */
.responsive-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
  gap: 1rem;
}
.responsive-grid-sm {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr));
  gap: 0.75rem;
}
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr));
  gap: 1rem;
}

/* ── 13. SKELETON ────────────────────────────────────────────── */
@keyframes karpus-shimmer {
  0%   { background-position: -400px 0; }
  100% { background-position:  400px 0; }
}
.skeleton {
  background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
  background-size: 800px 100%;
  animation: karpus-shimmer 1.4s infinite linear;
  border-radius: 0.5rem;
}

/* ── 14. IMÁGENES LAZY ───────────────────────────────────────── */
.karpus-img-loading {
  background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
  background-size: 400px 100%;
  animation: karpus-shimmer 1.4s infinite linear;
}
.karpus-img { transition: filter 0.4s ease, opacity 0.4s ease; opacity: 0.7; }
.karpus-img-loaded { filter: none !important; opacity: 1 !important; animation: none !important; background: none !important; }
video.karpus-img-loading { background: #1e293b; }

/* ── 15. CHAT WHATSAPP ───────────────────────────────────────── */
.chat-shell {
  display: flex;
  height: calc(100dvh - 120px);
  min-height: 500px;
  border-radius: 20px;
  overflow: hidden;
  border: 1px solid #e2e8f0;
  box-shadow: 0 4px 24px -4px rgba(0,0,0,0.07);
  background: white;
}
.chat-list-col {
  width: 300px; flex-shrink: 0;
  display: flex; flex-direction: column;
  border-right: 1px solid #f1f5f9; background: #f8fafc;
}
.chat-conv-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-messages-scroll {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 1rem; display: flex; flex-direction: column; gap: 0.5rem; min-height: 200px;
}
.chat-input-sticky {
  position: sticky; bottom: 0; background: white;
  border-top: 1px solid #f1f5f9; padding: 0.75rem 1rem; z-index: 2;
}
@media (max-width: 768px) {
  .chat-shell { flex-direction: column; height: calc(100dvh - 100px); min-height: 400px; border-radius: 16px; }
  .chat-list-col { width: 100%; border-right: none; border-bottom: 1px solid #f1f5f9; }
  .chat-list-col.chat-hidden { display: none; }
  .chat-conv-col.chat-hidden { display: none; }
  .chat-conv-col { min-height: 60vh; }
}
@media (min-width: 769px) {
  .chat-conv-col { display: flex !important; }
  .chat-list-col { display: flex !important; }
}
