/*
=============================================================
Zenty Emite 2.0 · Revisión integral de interfaz
Menú lateral único, módulos embebidos y responsive real
=============================================================
*/

:root {
  --zenty-sidebar-width: 272px;
  --zenty-shell-border: #dbe7ea;
  --zenty-shell-surface: #ffffff;
  --zenty-shell-bg: #eef5f5;
  --zenty-shell-ink: #17343b;
  --zenty-shell-muted: #64787e;
  --zenty-shell-primary: #0f766e;
}

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

.app-sidebar {
  width: var(--zenty-sidebar-width) !important;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.app-main {
  width: calc(100% - var(--zenty-sidebar-width)) !important;
  margin-left: var(--zenty-sidebar-width) !important;
  min-width: 0;
}

.sidebar-nav {
  display: grid !important;
  gap: 0.38rem !important;
  overflow: visible !important;
}

.sidebar-link {
  min-width: 0;
  font-weight: 500 !important;
  text-decoration: none;
}

.sidebar-link > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.zenty-menu-section {
  margin: 0.85rem 0 0.15rem;
  padding: 0.65rem 0.75rem 0.35rem;
  border-top: 1px solid var(--zenty-shell-border);
  color: var(--zenty-shell-muted);
  font-size: 0.61rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.zenty-module-link.active,
.zenty-module-link[aria-current="page"],
.sidebar-link[data-zenty-module="caf"].active {
  color: var(--zenty-shell-primary) !important;
  background: #dff6f2 !important;
}

.zenty-module-link.active i,
.sidebar-link[data-zenty-module="caf"].active i {
  color: var(--zenty-shell-primary) !important;
}

.zenty-menu-toggle {
  display: none;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  padding: 0;
  border: 1px solid var(--zenty-shell-border);
  border-radius: 12px;
  color: var(--zenty-shell-primary);
  background: #ffffff;
  font-size: 1.15rem;
  box-shadow: 0 6px 16px rgba(24, 57, 66, 0.07);
}

.zenty-sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 998;
  display: none;
  background: rgba(10, 31, 35, 0.42);
  backdrop-filter: blur(3px);
}

.app-content.zenty-embed-active {
  padding: 1rem !important;
  overflow: hidden;
}

.app-content.zenty-embed-active > :not(.zenty-module-host) {
  display: none !important;
}

.zenty-module-host {
  position: relative;
  width: 100%;
  min-width: 0;
  min-height: calc(100dvh - 135px);
  overflow: hidden;
  border: 1px solid var(--zenty-shell-border);
  border-radius: 20px;
  background: #f3f8f8;
  box-shadow: 0 12px 34px rgba(24, 57, 66, 0.08);
}

.zenty-module-frame {
  display: block;
  width: 100%;
  height: calc(100dvh - 135px);
  min-height: 660px;
  border: 0;
  background: #f3f8f8;
}

.zenty-module-loader {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  color: var(--zenty-shell-muted);
  background: #f3f8f8;
  font-size: 0.78rem;
  transition: opacity 180ms ease, visibility 180ms ease;
}

.zenty-module-loader::before {
  width: 22px;
  height: 22px;
  margin-right: 9px;
  border: 2px solid #cfe0df;
  border-top-color: var(--zenty-shell-primary);
  border-radius: 50%;
  animation: zenty-shell-spin 700ms linear infinite;
  content: "";
}

.zenty-module-loader.is-hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

@keyframes zenty-shell-spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 991px) {
  body.zenty-sidebar-open {
    overflow: hidden;
  }

  .app-shell {
    display: block !important;
  }

  .app-sidebar {
    position: fixed !important;
    inset: 0 auto 0 0 !important;
    z-index: 999 !important;
    width: min(310px, 86vw) !important;
    min-height: 100dvh !important;
    padding: 0.85rem !important;
    border-right: 1px solid var(--zenty-shell-border) !important;
    border-bottom: 0 !important;
    background: rgba(255, 255, 255, 0.98) !important;
    box-shadow: 18px 0 42px rgba(15, 48, 54, 0.18);
    transform: translateX(-105%);
    transition: transform 210ms ease;
  }

  body.zenty-sidebar-open .app-sidebar {
    transform: translateX(0);
  }

  body.zenty-sidebar-open .zenty-sidebar-backdrop {
    display: block;
  }

  .sidebar-nav {
    display: grid !important;
    gap: 0.35rem !important;
    padding-bottom: 1rem !important;
    overflow: visible !important;
  }

  .sidebar-link {
    width: 100%;
    white-space: normal !important;
  }

  .app-main {
    width: 100% !important;
    margin-left: 0 !important;
  }

  .app-topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    display: grid !important;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 0.75rem !important;
    align-items: center !important;
    padding: 0.75rem 1rem !important;
    border-bottom: 1px solid var(--zenty-shell-border);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(14px);
  }

  .app-topbar > div:first-of-type {
    min-width: 0;
  }

  .app-topbar h1 {
    overflow: hidden;
    font-size: clamp(1rem, 4vw, 1.25rem) !important;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .app-topbar .eyebrow {
    display: none !important;
  }

  .topbar-user {
    width: auto !important;
    min-width: 0;
  }

  .zenty-menu-toggle {
    display: grid;
  }

  .app-content {
    padding: 0.75rem !important;
  }

  .app-content.zenty-embed-active {
    padding: 0.55rem !important;
  }

  .zenty-module-host {
    min-height: calc(100dvh - 76px);
    border-radius: 15px;
  }

  .zenty-module-frame {
    height: calc(100dvh - 76px);
    min-height: 580px;
  }
}

@media (max-width: 575px) {
  .app-topbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
    padding: 0.65rem 0.7rem !important;
  }

  .user-chip {
    padding: 0.35rem 0.5rem !important;
  }

  .user-chip > div,
  .app-topbar .btn span {
    display: none !important;
  }

  .app-topbar .btn {
    min-width: 38px;
    padding-left: 0.55rem !important;
    padding-right: 0.55rem !important;
  }

  .zenty-module-host {
    border-radius: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-sidebar,
  .zenty-module-loader,
  .zenty-menu-toggle {
    transition: none !important;
  }
}
