/* ========================================
   EmbàsDF — Header / Navegació Compartida
   ======================================== */

.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1002;
  height: 60px;
  background: var(--surface-glass);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.4), 0 6px 20px -12px rgb(15 42 58 / 0.25);
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  gap: 0.75rem;
}

.app-header.hidden {
  display: none;
}

.app-header__brand {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.app-header__logo {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  text-decoration: none;
}

.app-header__logo img {
  width: 34px;
  height: 34px;
  object-fit: contain;
  filter: drop-shadow(0 2px 4px rgb(15 42 58 / 0.18));
  transition: transform 0.3s var(--ease-out);
}

.app-header__logo:hover img {
  transform: rotate(-6deg) scale(1.05);
}

.brand-wordmark {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--brand-deep);
  line-height: 1;
}

.brand-wordmark b {
  font-weight: 800;
  color: var(--brand-green);
}

html.dark .brand-wordmark {
  color: #E6F1F7;
}

.app-header__nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-left: 1.75rem;
  flex: 1;
}

.app-header__nav .nav-link,
.app-header__nav .nav-dropdown__toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-full);
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s, color 0.15s;
  white-space: nowrap;
}

.app-header__nav .nav-link:hover,
.app-header__nav .nav-dropdown__toggle:hover,
.app-header__nav .nav-dropdown__toggle[aria-expanded="true"] {
  background: var(--surface-3);
  color: var(--text-strong);
}

.app-header__nav .nav-link.active {
  background: var(--primary-light);
  color: var(--primary-dark);
  font-weight: 600;
}

.app-header__nav .nav-link i,
.app-header__nav .nav-dropdown__toggle i {
  font-size: 0.85rem;
}

.app-header__nav .nav-link.active i {
  color: var(--primary);
}

/* Desplegables */
.nav-dropdown {
  position: relative;
}

.nav-dropdown__menu,
.user-dropdown__menu {
  position: absolute;
  top: calc(100% + 8px);
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  padding: 0.4rem;
  display: none;
  flex-direction: column;
  gap: 0.125rem;
  z-index: 1003;
  transform-origin: top;
}

.nav-dropdown__menu {
  left: 0;
}

.user-dropdown__menu {
  right: 0;
  min-width: 240px;
}

.nav-dropdown__menu.show,
.user-dropdown__menu.show {
  display: flex;
  animation: dropdown-in 0.18s var(--ease-out);
}

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

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

.dropdown-item:hover,
.dropdown-item.active {
  background: var(--surface-3);
  color: var(--text-strong);
}

.dropdown-item.active {
  color: var(--primary-dark);
}

.dropdown-item i {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: var(--primary-light);
  color: var(--primary);
  font-size: 0.8rem;
  flex-shrink: 0;
}

.dropdown-item--danger {
  color: var(--error);
}

.dropdown-item--danger i {
  background: var(--error-bg);
  color: var(--error);
}

.dropdown-item--danger:hover {
  background: var(--error-bg);
  color: var(--error);
}

html.dark .dropdown-item--danger,
html.dark .dropdown-item--danger i {
  color: var(--error-text);
}

/* Accions dreta */
.app-header__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
}

/* Desplegable d'usuari */
.user-dropdown {
  position: relative;
}

.user-dropdown__toggle {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  height: 42px;
  padding: 0 0.6rem 0 0.3rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}

.user-dropdown__toggle:hover,
.user-dropdown__toggle[aria-expanded="true"] {
  background: var(--surface-3);
  border-color: var(--border-strong);
}

.user-dropdown__meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.15;
  max-width: 150px;
}

.user-dropdown__label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-strong);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-dropdown__sub {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.user-dropdown__chevron {
  font-size: 0.65rem;
  color: var(--text-muted);
  transition: transform 0.2s;
}

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

.user-dropdown__info {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.65rem 0.7rem 0.75rem;
  margin-bottom: 0.25rem;
  border-bottom: 1px solid var(--border);
}

.user-dropdown__name {
  font-weight: 700;
  font-size: var(--text-sm);
  color: var(--text-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

/* Etiqueta de rol (header i menú mòbil) */
.role-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  align-self: flex-start;
  padding: 0.15rem 0.55rem;
  border-radius: var(--radius-full);
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--surface-3);
  color: var(--text-muted);
}

.role-tag.role-gestor {
  background: var(--error-bg);
  color: var(--error-text);
}

.role-tag.role-control {
  background: var(--warning-bg);
  color: var(--warning-text);
}

.role-tag.role-normal {
  background: var(--success-bg);
  color: var(--success-text);
}

.header-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-full);
  cursor: pointer;
  font-size: 0.95rem;
  transition: background-color 0.15s, color 0.15s, transform 0.3s var(--ease-out);
  flex-shrink: 0;
}

.header-btn:hover {
  background: var(--surface-3);
  color: var(--text-strong);
}

#darkModeToggle:hover i {
  transform: rotate(-20deg);
}

#darkModeToggle i {
  transition: transform 0.3s var(--ease-out);
}

html.dark #darkModeToggle {
  color: #FCD34D;
}

.header-btn--menu {
  display: none;
}

/* Separadors */
.nav-divider {
  width: 1px;
  height: 22px;
  background: var(--border);
  margin: 0 0.35rem;
}

/* ========================================
   Menú mòbil
   ======================================== */

.mobile-menu {
  position: fixed;
  inset: 0;
  z-index: 1005;
  display: none;
  justify-content: flex-end;
}

.mobile-menu.show {
  display: flex;
}

.mobile-menu__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 20, 28, 0.5);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fade-in 0.2s ease;
}

.mobile-menu__panel {
  position: relative;
  width: 300px;
  max-width: 86vw;
  height: 100%;
  background: var(--surface);
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  animation: mobile-panel-in 0.3s var(--ease-out);
}

@keyframes mobile-panel-in {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.mobile-menu__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1rem 1rem 1.25rem;
}

.mobile-menu__title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: var(--text-lg);
  color: var(--text-strong);
}

.mobile-menu__user {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin: 0 1rem 0.5rem;
  padding: 1rem;
  border-radius: var(--radius-lg);
  background: var(--brand-gradient);
  color: #fff;
  box-shadow: var(--shadow-md);
}

.mobile-menu__user .avatar {
  width: 44px;
  height: 44px;
  font-size: 0.95rem;
  background: rgba(255, 255, 255, 0.18);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.35);
}

.mobile-menu__user-name {
  font-weight: 700;
  font-size: var(--text-base);
}

.mobile-menu__user-role {
  display: inline-block;
  margin-top: 0.2rem;
  padding: 0.1rem 0.5rem;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.2);
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.mobile-menu__body {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0.75rem 1rem;
}

.mobile-menu__nav {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.mobile-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 48px;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius);
  color: var(--text);
  font-size: var(--text-base);
  font-weight: 500;
  text-decoration: none;
  background: transparent;
  border: none;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: background-color 0.15s;
}

.mobile-link:hover {
  background: var(--surface-3);
}

.mobile-link.active {
  background: var(--primary-light);
  color: var(--primary-dark);
  font-weight: 600;
}

.mobile-link i {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  color: var(--primary);
  font-size: 0.9rem;
  flex-shrink: 0;
}

.mobile-link.active i {
  background: var(--primary);
  color: #fff;
}

.mobile-link--danger {
  color: var(--error);
  margin-top: 0.5rem;
}

.mobile-link--danger i {
  background: var(--error-bg);
  color: var(--error);
}

html.dark .mobile-link--danger,
html.dark .mobile-link--danger i {
  color: var(--error-text);
}

.mobile-link-group {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.mobile-link-group__title {
  padding: 0.5rem 0.75rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  font-weight: 700;
}

/* ========================================
   Responsive
   ======================================== */

@media (max-width: 768px) {
  .app-header__nav {
    display: none;
  }

  .user-dropdown {
    display: none;
  }

  .header-btn--menu {
    display: inline-flex;
  }

  .app-header {
    padding: 0 0.75rem;
  }
}

@media (max-width: 480px) {
  .app-header {
    height: 56px;
  }

  .brand-wordmark {
    font-size: 1.1rem;
  }

  .app-header__logo img {
    width: 30px;
    height: 30px;
  }
}

/* Ocultar elements segons rol (gestionat per JS) */
.nav-hidden {
  display: none !important;
}

/* Espai per al header fix en pàgines secundàries */
body.has-nav-header {
  padding-top: 60px;
}

@media (max-width: 480px) {
  body.has-nav-header {
    padding-top: 56px;
  }
}
