/**
 * Zyphra — Shell de aplicación (sidebar, header, componentes base)
 */

@import url("https://fonts.googleapis.com/css2?family=Manrope:wght@500;600;700;800&family=Space+Grotesk:wght@500;700&display=swap");

html, body {
  font-family: var(--zy-font);
  color: var(--zy-text);
  background: var(--zy-bg);
}

body.bg-gray-100 {
  background: var(--zy-bg) !important;
}

/* -------------------------------------------------------------------------
   Layout
   ------------------------------------------------------------------------- */
.app-layout {
  display: flex;
  min-height: 100vh;
  background: var(--zy-bg);
}

.sidebar {
  width: var(--zy-sidebar-width);
  flex-shrink: 0;
  background: var(--zy-night);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 40;
  transition: width var(--zy-transition);
  box-shadow: 4px 0 24px rgba(11, 25, 48, 0.18);
}

.main-content-wrap {
  flex: 1;
  margin-left: var(--zy-sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
  transition: margin-left var(--zy-transition);
  background: var(--zy-bg);
}

.main-container {
  flex: 1;
  width: 100%;
  margin: 0;
  padding: 1.25rem 1.5rem 2rem;
  background-color: var(--zy-bg);
  min-height: calc(100vh - var(--zy-header-height));
  box-sizing: border-box;
  overflow-x: hidden;
}

body.sidebar-collapsed .sidebar {
  width: var(--zy-sidebar-collapsed);
}

body.sidebar-collapsed .main-content-wrap {
  margin-left: var(--zy-sidebar-collapsed);
}

body.sidebar-collapsed .sidebar-brand-text,
body.sidebar-collapsed .sidebar-section-title,
body.sidebar-collapsed .sidebar-link-label,
body.sidebar-collapsed .sidebar-user-meta,
body.sidebar-collapsed .sidebar-chevron {
  display: none !important;
}

body.sidebar-collapsed .sidebar-link {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

body.sidebar-collapsed .sidebar-link i {
  margin-right: 0;
}

body.sidebar-collapsed .sidebar-brand {
  padding: 1rem 0.5rem;
  justify-content: center;
}

body.sidebar-collapsed .sidebar-brand-logo {
  /* Marca compacta: recorta al isotipo de las 3 barras */
  width: 44px;
  height: 36px;
  object-fit: cover;
  object-position: left center;
}

body.sidebar-collapsed .sidebar-collapse-btn {
  margin: 0 auto 0.5rem;
}

body.sidebar-collapsed .sidebar-user-btn {
  justify-content: center;
}

body.sidebar-collapsed .sidebar-avatar {
  margin: 0;
}

/* -------------------------------------------------------------------------
   Sidebar brand
   ------------------------------------------------------------------------- */
.sidebar-brand {
  padding: 1.15rem 1.1rem 0.85rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.65rem;
}

.sidebar-brand-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
}

.sidebar-brand-logo {
  width: min(100%, 168px);
  height: auto;
  display: block;
}

.sidebar-brand-text {
  display: none; /* el SVG light ya incluye wordmark + subtítulo */
}

.sidebar-collapse-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--zy-text-nav);
  cursor: pointer;
  transition: background var(--zy-transition), color var(--zy-transition);
  margin-left: auto;
  flex-shrink: 0;
}

.sidebar-collapse-btn:hover {
  background: var(--zy-hover-nav);
  color: #fff;
}

.sidebar-close-mobile {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin-left: auto;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
}

/* -------------------------------------------------------------------------
   Nav
   ------------------------------------------------------------------------- */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.85rem 0.7rem 1rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

.sidebar-section {
  margin-bottom: 1rem;
}

.sidebar-section-title {
  font-family: var(--zy-font-display);
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(185, 197, 215, 0.55);
  padding: 0.35rem 0.75rem 0.5rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-link {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0.55rem 0.85rem;
  margin-bottom: 2px;
  color: var(--zy-text-nav);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.3;
  border-radius: var(--zy-radius-sm);
  position: relative;
  transition: background var(--zy-transition), color var(--zy-transition);
}

.sidebar-link i {
  width: 1.35rem;
  flex-shrink: 0;
  margin-right: 0.75rem;
  text-align: center;
  font-size: 1rem;
  color: var(--zy-text-nav-icon);
  transition: color var(--zy-transition);
}

.sidebar-link:hover {
  background: var(--zy-hover-nav);
  color: #fff;
}

.sidebar-link:hover i {
  color: var(--zy-violet-light);
}

.sidebar-link.active {
  background: var(--zy-violet-active-bg);
  color: #fff;
}

.sidebar-link.active i {
  color: var(--zy-violet-icon);
}

.sidebar-link.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--zy-violet-light);
}

.sidebar-link-sub {
  padding-left: 1.1rem;
  font-size: 0.85rem;
}

.sidebar-link-sub i {
  width: 1.15rem;
  margin-right: 0.55rem;
  font-size: 0.85rem;
}

/* -------------------------------------------------------------------------
   Footer usuario
   ------------------------------------------------------------------------- */
.sidebar-footer {
  padding: 0.85rem 0.75rem 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar-user-btn {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 0.45rem 0.5rem;
  color: rgba(255, 255, 255, 0.92);
  font-size: 0.875rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--zy-radius-sm);
  cursor: pointer;
  text-align: left;
  gap: 0.65rem;
  transition: background var(--zy-transition);
}

.sidebar-user-btn:hover {
  background: var(--zy-hover-nav);
  color: #fff;
}

.sidebar-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--zy-violet) 0%, var(--zy-violet-light) 100%);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.sidebar-user-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.sidebar-user-name {
  font-weight: 700;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: 0.7rem;
  color: var(--zy-text-nav);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-chevron {
  margin-left: auto;
  font-size: 0.7rem;
  color: var(--zy-text-nav-icon);
  transition: transform var(--zy-transition);
}

.sidebar-chevron-open {
  transform: rotate(180deg);
}

.sidebar-footer-dropdown {
  margin-top: 0.45rem;
  padding: 0.35rem;
  border-radius: var(--zy-radius-sm);
  background: rgba(0, 0, 0, 0.22);
}

.sidebar-footer-dropdown .sidebar-link {
  min-height: 40px;
  font-size: 0.82rem;
}

/* -------------------------------------------------------------------------
   Header superior
   ------------------------------------------------------------------------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: var(--zy-header-height);
  height: var(--zy-header-height);
  padding: 0 1.5rem;
  background: var(--zy-surface);
  border-bottom: 1px solid var(--zy-border);
  position: sticky;
  top: 0;
  z-index: 30;
}

.app-header-left {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.app-header-title {
  margin: 0;
  font-family: var(--zy-font-display);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--zy-text);
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-header-crumb {
  margin: 0;
  font-size: 0.75rem;
  color: var(--zy-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-header-crumb a {
  color: var(--zy-text-secondary);
  text-decoration: none;
}

.app-header-crumb a:hover {
  color: var(--zy-violet);
}

.app-header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.app-header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--zy-violet-soft);
  color: var(--zy-violet);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.85rem;
  border: 1px solid #e4daf8;
}

/* Mobile topbar */
.mobile-topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 35;
  align-items: center;
  gap: 0.75rem;
  min-height: 56px;
  padding: 0.5rem 0.85rem;
  background: var(--zy-night);
  color: #fff;
  box-shadow: 0 2px 12px rgba(11, 25, 48, 0.2);
}

.mobile-topbar-brand {
  font-family: var(--zy-font-display);
  font-size: 1.05rem;
  font-weight: 700;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mobile-menu-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  min-width: 44px;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  cursor: pointer;
  font-size: 1.1rem;
}

.mobile-menu-btn:hover,
.mobile-menu-btn:focus-visible {
  background: rgba(255, 255, 255, 0.18);
  outline: none;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(11, 25, 48, 0.55);
  z-index: 39;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.sidebar-backdrop.is-visible {
  display: block;
  opacity: 1;
}

/* -------------------------------------------------------------------------
   Componentes compartidos
   ------------------------------------------------------------------------- */
.zy-card {
  background: var(--zy-surface);
  border: 1px solid var(--zy-border);
  border-radius: var(--zy-radius);
  box-shadow: var(--zy-shadow);
}

.zy-btn-primary,
.btn-primary {
  background-color: var(--zy-violet) !important;
  border-color: var(--zy-violet) !important;
}

.zy-btn-primary:hover,
.btn-primary:hover {
  background-color: #5a2bc4 !important;
  border-color: #5a2bc4 !important;
}

.zy-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.zy-badge-success { background: #e8f7f1; color: var(--zy-success); }
.zy-badge-warning { background: #fff6e8; color: #b7791f; }
.zy-badge-danger { background: #fdecef; color: var(--zy-danger); }
.zy-badge-info { background: #eaf2fb; color: var(--zy-info); }
.zy-badge-neutral { background: #eef1f5; color: var(--zy-neutral); }
.zy-badge-violet { background: var(--zy-violet-soft); color: var(--zy-violet); }

/* Tablas institucionales */
.table thead th,
table.dataTable thead th {
  background: #f3f5f9 !important;
  color: var(--zy-text-secondary) !important;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--zy-border) !important;
  border-top: none !important;
}

.table tbody tr:hover,
table.dataTable tbody tr:hover {
  background: #f8fafc !important;
}

.table,
table.dataTable {
  border-color: var(--zy-border) !important;
}

.card {
  border-color: var(--zy-border) !important;
  border-radius: var(--zy-radius) !important;
  box-shadow: var(--zy-shadow) !important;
}

.form-control:focus,
.form-select:focus {
  border-color: var(--zy-violet-light) !important;
  box-shadow: 0 0 0 0.2rem rgba(105, 54, 217, 0.18) !important;
}

/* -------------------------------------------------------------------------
   Responsive
   ------------------------------------------------------------------------- */
@media (max-width: 991.98px) {
  .mobile-topbar {
    display: flex;
  }

  .app-header {
    display: none;
  }

  .sidebar-collapse-btn {
    display: none !important;
  }

  body.sidebar-collapsed .sidebar {
    width: min(300px, 86vw);
  }

  body.sidebar-collapsed .main-content-wrap,
  .main-content-wrap {
    margin-left: 0;
  }

  body.sidebar-collapsed .sidebar-brand-text,
  body.sidebar-collapsed .sidebar-section-title,
  body.sidebar-collapsed .sidebar-link-label,
  body.sidebar-collapsed .sidebar-user-meta,
  body.sidebar-collapsed .sidebar-chevron {
    display: initial !important;
  }

  body.sidebar-collapsed .sidebar-link {
    justify-content: flex-start;
    padding-left: 0.85rem;
    padding-right: 0.85rem;
  }

  body.sidebar-collapsed .sidebar-link i {
    margin-right: 0.75rem;
  }

  .sidebar {
    width: min(300px, 86vw);
    transform: translateX(-105%);
    transition: transform 0.25s ease;
    z-index: 50;
  }

  .sidebar.is-open {
    transform: translateX(0);
    box-shadow: 8px 0 28px rgba(0, 0, 0, 0.28);
  }

  .sidebar-brand {
    flex-direction: row;
    align-items: center;
    padding: 0.85rem 1rem;
  }

  .sidebar-brand-logo {
    width: 140px;
  }

  .sidebar-close-mobile {
    display: inline-flex;
  }

  .main-container {
    padding: 12px;
    min-height: calc(100vh - 56px);
  }

  body.sidebar-open {
    overflow: hidden;
  }
}

@media (max-width: 575.98px) {
  .main-container {
    padding: 10px;
  }
}
