/* ============================================================
   layout.css — Shell de la app: header fijo + cuerpo + footer
   Rediseño pen.dev: header blanco elevado con buscador global,
   sidebar navy profundo con iconos lucide y glow índigo.
   ============================================================ */

.app-layout {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
  overflow: hidden;
}

/* ----- Header fijo (blanco, elevado) ----- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px;
  background: #ffffff;
  border-bottom: 1px solid var(--c-border);
  box-shadow: var(--shadow-sm);
}

/* Marca: logo gradiente índigo + nombre */
.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.header-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #4338ca);
  box-shadow: var(--shadow-primary);
  color: #fff;
  flex-shrink: 0;
}

.header-logo svg {
  width: 18px;
  height: 18px;
}

.header-brand-text {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--c-navy);
}

/* ----- Buscador global ----- */
.header-search {
  flex: 1;
  max-width: 520px;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 12px;
  background: #f1f5f9;
  border: 1px solid var(--c-border);
  border-radius: 10px;
  color: var(--c-muted);
  transition: border-color var(--t-fast), background var(--t-fast), box-shadow var(--t-fast);
}

.header-search:focus-within {
  background: #fff;
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.header-search-ico {
  width: 16px;
  height: 16px;
  color: #94a3b8;
  flex-shrink: 0;
}

.header-search input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--c-text);
  outline: none;
}

.header-search input::placeholder {
  color: #94a3b8;
}

.header-search-kbd {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border: 1px solid var(--c-border);
  border-radius: 6px;
  background: #fff;
  color: #64748b;
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
  flex-shrink: 0;
}

/* ----- Acciones del header ----- */
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.header-btn-nuevo {
  flex-shrink: 0;
}

.header-btn-nuevo svg {
  width: 15px;
  height: 15px;
}

.header-btn-nuevo span {
  margin-left: 7px;
}

.header-divider {
  width: 1px;
  height: 28px;
  background: var(--c-border);
  flex-shrink: 0;
}

/* Botón icono (campana) */
.icon-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--c-border);
  border-radius: 10px;
  background: #f8fafc;
  color: #475569;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast), transform var(--t-fast);
}

.icon-btn:hover {
  background: var(--c-primary-soft);
  color: var(--c-primary);
  border-color: #c7d2fe;
  transform: translateY(-1px);
}

.icon-btn svg {
  width: 17px;
  height: 17px;
}

.icon-btn .nav-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: var(--bad);
  color: #fff;
  border: 2px solid #fff;
  border-radius: 10px;
  padding: 0 5px;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.5;
  min-width: 17px;
  text-align: center;
}

/* ----- Menú de usuario en el header (dropdown) ----- */
.header-user {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 0;
}

.user-menu {
  position: relative;
}

.user-menu-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px 3px 3px;
  border: 1px solid var(--c-border);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
}

.user-menu-trigger:hover {
  border-color: #c7d2fe;
  background: var(--c-primary-soft);
  box-shadow: var(--shadow-xs);
}

.user-menu-trigger .user-avatar {
  width: 30px;
  height: 30px;
  font-size: 11.5px;
  border-radius: 8px;
  background: linear-gradient(135deg, #6366f1, #4338ca);
  color: #fff;
  box-shadow: var(--shadow-primary);
}

.user-menu-caret {
  width: 14px;
  height: 14px;
  color: #64748b;
  transition: transform var(--t-fast);
}

.user-menu-trigger[aria-expanded="true"] .user-menu-caret {
  transform: rotate(180deg);
}

.user-menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 60;
  width: 260px;
  background: #fff;
  border: 1px solid var(--c-border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  padding: 8px;
  animation: crm-menu-in 0.14s ease;
}

@keyframes crm-menu-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}

.user-menu-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
}

.user-menu-avatar {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 11px;
  background: linear-gradient(135deg, #6366f1, #4338ca);
  color: #fff;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  box-shadow: var(--shadow-primary);
}

.user-menu-id {
  min-width: 0;
}

.user-menu-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--c-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-menu-inst {
  font-size: 11.5px;
  color: var(--c-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-menu-rol {
  padding: 2px 10px 8px;
}

.user-menu-sep {
  height: 1px;
  background: var(--c-border);
  margin: 4px 0;
}

.user-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--c-text);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}

.user-menu-item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: #64748b;
}

.user-menu-item:hover {
  background: var(--c-primary-soft);
  color: var(--c-primary);
}

.user-menu-item:hover svg {
  color: var(--c-primary);
}

.user-menu-item-danger {
  color: #b91c1c;
}

.user-menu-item-danger svg {
  color: #b91c1c;
}

.user-menu-item-danger:hover {
  background: #fee2e2;
  color: #b91c1c;
}

.user-menu-item-danger:hover svg {
  color: #b91c1c;
}

/* En pantallas chicas el header es compacto: se achica el menú de usuario */
@media (max-width: 900px) {
  .header-search {
    display: none;
  }
  .user-menu-trigger {
    padding: 2px;
    border: none;
    background: transparent;
  }
  .user-menu-trigger .user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 9px;
  }
  .user-menu-caret {
    display: none;
  }
  .user-menu-panel {
    width: 240px;
  }
}

/* ----- Cuerpo (sidebar + área principal) ----- */
.app-body {
  display: flex;
  min-height: 0;
  overflow: hidden;
}

/* ----- Sidebar (solo navegación; desktop) ----- */
.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: linear-gradient(180deg, #0b1220 0%, #0a1a30 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 20px 14px 14px;
  gap: 8px;
  overflow-y: auto;
}

.sidebar-section-label {
  padding: 0 12px;
  margin: 2px 0 6px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: #64748b;
}

#main-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#main-nav button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  padding: 11px 12px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: #94a3b8;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast), transform var(--t-fast), box-shadow var(--t-med);
}

#main-nav button .nav-ico {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

#main-nav button:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  transform: translateX(2px);
}

#main-nav button:active {
  transform: translateX(2px) scale(0.98);
}

#main-nav button.active {
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
}

.sidebar-reset {
  width: 100%;
  justify-content: flex-start;
  color: #94a3b8 !important;
  border-color: #2a3a5c !important;
  background: transparent !important;
}

.sidebar-reset:hover {
  color: #fff !important;
  background: rgba(255, 255, 255, 0.06) !important;
}

/* ----- Área principal ----- */
.main-area {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* El área principal ES el contenedor: aprovecha todo el ancho disponible
   entre el borde derecho de la sidebar y el borde derecho de la página.
   Márgenes mínimos para aprovechar el ancho de pantalla. */
.container {
  max-width: none;
  margin: 0;
  padding: 18px 22px 24px;
}

/* ----- Footer fijo / barra de navegación inferior ----- */
.app-footer {
  position: sticky;
  bottom: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  background: #ffffff;
  border-top: 1px solid var(--c-border);
  color: var(--c-muted);
  font-size: 12px;
}

/* Por defecto (desktop/tablet) la barra inferior está oculta;
   solo se muestra como navegación en pantallas chicas. */
.bottom-nav {
  display: none;
}

/* ----- Grillas reutilizables por las vistas ----- */
.grid {
  display: grid;
  gap: 18px;
}

.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }

@media (max-width: 900px) {
  .grid-cols-3,
  .grid-cols-4 {
    grid-template-columns: 1fr;
  }
  .grid-cols-2 {
    grid-template-columns: 1fr;
  }
}

/* ============================================================
   Móvil: sidebar oculta + header compacto + bottom-nav
   ============================================================ */
@media (max-width: 900px) {
  .app-layout {
    grid-template-rows: auto 1fr auto;
  }

  .app-header {
    padding: 8px 12px;
  }

  .header-brand-text {
    font-size: 15px;
  }
  .header-logo {
    width: 30px;
    height: 30px;
    border-radius: 8px;
  }
  .header-logo svg {
    width: 15px;
    height: 15px;
  }

  .header-btn-nuevo span {
    display: none;
  }
  .header-btn-nuevo {
    padding: 8px 10px;
  }
  .header-btn-nuevo svg {
    margin: 0;
  }
  .header-btn-nuevo span {
    margin-left: 0;
  }

  .icon-btn {
    width: 36px;
    height: 36px;
  }

  .sidebar {
    display: none;
  }

  .app-body {
    display: block;
    overflow-y: auto;
  }

  .main-area {
    overflow-y: visible;
  }

  .container {
    padding: 16px 14px 24px;
  }

  /* Footer pasa a ser la barra de navegación inferior */
  .app-footer {
    justify-content: stretch;
    padding: 0;
    background: #ffffff;
    border-top: 1px solid #e2e8f0;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.06);
  }

  .footer-info {
    display: none;
  }

  .bottom-nav {
    display: flex;
    width: 100%;
  }

  .bottom-nav button {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 4px 6px;
    border: none;
    background: transparent;
    color: #64748b;
    font-family: inherit;
    font-size: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.2s;
  }

  .bottom-nav button .nav-ico {
    width: 19px;
    height: 19px;
    line-height: 1;
  }

  .bottom-nav button.active {
    color: var(--c-primary);
  }

  .bottom-nav .nav-badge {
    position: absolute;
    top: 2px;
    right: calc(50% - 24px);
    background: var(--bad);
    color: #fff;
    border-radius: 10px;
    padding: 1px 6px;
    font-size: 10px;
    line-height: 1.4;
  }

  .bottom-nav button {
    position: relative;
  }
}
