/* =============================================================
   DPROMA Dashboard — Layout: rail lateral y grid principal
   © DPROMA. Todos los derechos reservados.
   ============================================================= */

/* ── Variables de layout ── */
:root {
  --rail-w:        240px;
  --rail-w-collapsed: 64px;
  --rail-transition: 220ms ease;
  --header-h:      56px;
}

/* ── Grid principal de la app ── */
.app-layout {
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
  grid-template-rows: 100dvh;
  overflow: hidden;
  transition: grid-template-columns var(--rail-transition);
}
.app-layout.rail-collapsed {
  grid-template-columns: var(--rail-w-collapsed) 1fr;
}

/* ══════════════════════════════════
   RAIL LATERAL
══════════════════════════════════ */
.app-rail {
  display: flex; flex-direction: column;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  overflow: hidden;
  transition: width var(--rail-transition);
  width: var(--rail-w);
  position: relative;
  z-index: 100;
}

/* Header del rail */
.rail-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1rem .75rem;
  border-bottom: 1px solid var(--border);
  min-height: var(--header-h);
  flex-shrink: 0;
}
.rail-logo {
  height: 32px; width: auto;
  object-fit: contain;
  transition: opacity var(--rail-transition);
}
.rail-collapsed .rail-logo { opacity: 0; width: 0; pointer-events: none; }
.rail-toggle {
  background: none; border: none;
  color: var(--text-muted); padding: .375rem;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
  flex-shrink: 0;
}
.rail-toggle:hover { color: var(--text); background: var(--bg-hover); }

/* Menú de navegación */
.rail-menu {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: .75rem .5rem;
  display: flex; flex-direction: column; gap: .25rem;
}
.nav-item {
  display: flex; align-items: center; gap: .75rem;
  padding: .625rem .875rem;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: var(--text-sm); font-weight: 500;
  cursor: pointer;
  transition: color var(--transition), background var(--transition);
  border: none; background: none;
  width: 100%; text-align: left;
  white-space: nowrap;
}
.nav-item:hover { color: var(--text); background: var(--bg-hover); }
.nav-item.active { color: var(--green); background: rgba(31,121,56,.12); }
.nav-item svg { flex-shrink: 0; width: 18px; height: 18px; }
.nav-item-label { transition: opacity var(--rail-transition); }
.rail-collapsed .nav-item-label { opacity: 0; width: 0; overflow: hidden; }
.rail-collapsed .nav-item { justify-content: center; padding: .625rem; }

/* Footer del rail */
.rail-footer {
  border-top: 1px solid var(--border);
  padding: .75rem .5rem;
  display: flex; flex-direction: column; gap: .5rem;
  flex-shrink: 0;
}
.user-chip {
  display: flex; align-items: center; gap: .75rem;
  padding: .5rem .75rem;
  border-radius: var(--radius);
  overflow: hidden;
}
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--green);
  color: #fff; font-size: var(--text-sm); font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.user-details { display: flex; flex-direction: column; min-width: 0; transition: opacity var(--rail-transition); }
.rail-collapsed .user-details { opacity: 0; width: 0; overflow: hidden; }
.user-name { font-size: var(--text-sm); font-weight: 500; color: var(--text); }
.user-role-badge {
  font-size: var(--text-xs); color: var(--green);
  text-transform: uppercase; letter-spacing: .04em;
}
.rail-footer-actions {
  display: flex; gap: .25rem;
  padding: 0 .25rem;
}
.rail-collapsed .rail-footer-actions { flex-direction: column; align-items: center; }

/* ══════════════════════════════════
   CONTENEDOR DE VISTAS
══════════════════════════════════ */
.view-container {
  overflow-y: auto;
  background: var(--bg-app);
  position: relative;
  animation: fadeIn .2s ease;
}
.view-content {
  padding: 1.5rem 2rem;
  max-width: 1400px;
  margin: 0 auto;
  animation: slideUp .25s ease;
}
.view-loader {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-app);
  z-index: 10;
}

/* ── Cabecera de vista ── */
.view-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap;
}
.view-title { font-size: var(--text-2xl); font-weight: 700; color: var(--text); }
.view-subtitle { font-size: var(--text-sm); color: var(--text-muted); margin-top: .25rem; }
.view-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ── Toast container ── */
.toast-container {
  position: fixed; bottom: 1.25rem; right: 1.25rem;
  z-index: 9990;
  display: flex; flex-direction: column; gap: .5rem;
  max-width: 360px; width: calc(100vw - 2.5rem);
  pointer-events: none;
}

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 9000;
  background: rgba(0,0,0,.65);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
  animation: fadeIn .2s ease;
}
.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%; max-width: 480px;
  max-height: 90vh;
  box-shadow: var(--shadow-lg);
  animation: slideUp .25s ease;
  overflow: hidden;
  display: flex; flex-direction: column;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.modal-title { font-size: var(--text-lg); font-weight: 600; color: var(--text); }
.modal-body { padding: 1.25rem 1.5rem; color: var(--text-muted); font-size: var(--text-sm); line-height: 1.6; flex: 1 1 auto; overflow-y: auto; }
.modal-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--border); display: flex; gap: .75rem; justify-content: flex-end; flex: 0 0 auto; flex-wrap: wrap; }

/* ══════════════════════════════════
   RESPONSIVE
══════════════════════════════════ */

/* Tablet 640–1024px */
@media (max-width: 1024px) {
  :root { --rail-w: 200px; }
  .view-content { padding: 1rem 1.25rem; }
}

/* Móvil < 640px */
@media (max-width: 640px) {
  .app-layout {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr var(--header-h);
    /* rail como barra inferior en móvil */
    direction: rtl;
  }
  .app-layout > * { direction: ltr; }

  .app-rail {
    width: 100%; height: var(--header-h);
    flex-direction: row;
    border-right: none;
    border-top: 1px solid var(--border);
    grid-row: 2;
    align-items: center;
    padding: 0 .75rem;
    overflow: visible;
  }
  .rail-header { display: none; }
  .rail-menu {
    flex-direction: row; padding: 0;
    gap: .25rem; overflow-x: auto; overflow-y: visible;
    align-items: center;
  }
  .nav-item { flex-direction: column; gap: .2rem; padding: .375rem .5rem; font-size: 10px; }
  .nav-item-label { font-size: 10px; opacity: 1 !important; width: auto !important; }
  .rail-footer { display: none; }

  .view-container { grid-row: 1; }
  .view-content { padding: .875rem 1rem; }
  .view-header { flex-direction: column; }

  .modal-box { max-width: 100%; border-radius: var(--radius-lg); }
  .toast-container { bottom: calc(var(--header-h) + .75rem); right: .75rem; left: .75rem; max-width: none; }
}
