#header {
  position: sticky;
  top: 0;
  z-index: 999;
}

#navbar {
  background-color: var(--card-background);
  box-shadow: var(--shadow);
  border-radius: 0 0 var(--border-radius) var(--border-radius);
  overflow: hidden;
  margin: 0;
  padding: 0 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  position: relative;
  height: 64px;
  transition: var(--transition);
}

#navbar a {
  color: var(--text-color);
  text-decoration: none;
  padding: 8px 16px;
  font-weight: 500;
  transition: var(--transition);
  border-radius: var(--border-radius);
}

#navbar a:hover {
  color: var(--primary-color);
  background-color: rgba(55, 120, 194, 0.1);
}

#navbar .home-link {
  margin-right: auto;
}

#navbar .center-link {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

#navbar .auth-links {
  margin-left: auto;
  display: flex;
}

#user-part {
  display: flex;
  align-items: center;
  margin-left: auto;
}

#user-picture {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  margin-right: 12px;
  border: 2px solid var(--primary-color);
}

#user-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background-color: var(--primary-color);
  color: white;
  margin-right: 12px;
}

#user-icon > i {
  font-style: normal;
  font-weight: 600;
  font-size: 16px;
}

#navbar .icon {
  display: none;
  cursor: pointer;
  padding: 8px;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  position: absolute;
  right: 16px;
  top: 12px;
  z-index: 1000;
  background: transparent;
  border-radius: 0;
}

/* Hide any existing icons in the menu button to prevent duplicates */
#navbar .icon i {
  display: none;
}

@media (max-width: 768px) {
  #navbar {
    padding: 0 12px;
    height: 60px;
    min-height: 60px;
    overflow: visible;
    flex-direction: column;
    align-items: flex-start;
  }

  #navbar .center-link,
  #navbar .auth-links,
  #navbar #user-part {
    display: none;
  }

  #navbar .home-link {
    height: 60px;
    display: flex;
    align-items: center;
    margin-right: auto;
  }

  #navbar .icon {
    display: flex;
    z-index: 10;
  }

  #navbar .icon:before {
    content: "";
    display: block;
    width: 24px;
    height: 24px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23333333'%3E%3Cpath d='M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
  }

  /* Simple mobile menu */
  #navbar.open {
    height: auto;
    padding-bottom: 0;
  }

  /* Mobile menu items - when open */
  #navbar.open .center-link {
    display: block;
    width: 100%;
    position: static;
    transform: none;
    padding: 15px 16px;
    margin: 0;
    border-top: 1px solid var(--border-color);
    border-radius: 0;
  }

  #navbar.open .auth-links {
    display: block;
    width: 100%;
    margin: 0;
    padding: 0;
  }

  #navbar.open .auth-links a {
    display: block;
    width: 100%;
    padding: 15px 16px;
    margin: 0;
    border-top: 1px solid var(--border-color);
    border-radius: 0;
    text-align: left;
  }

  #navbar.open #user-part {
    display: flex;
    width: 100%;
    padding: 12px 16px;
    margin: 0;
    border-top: 1px solid var(--border-color);
    align-items: center;
  }

  #navbar.open #user-part a {
    margin-left: auto;
    padding: 8px 16px;
  }

  /* Close button (X) */
  #navbar.open .icon {
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    padding: 8px;
    position: absolute;
    right: 12px;
    top: 12px;
    z-index: 120;
  }

  #navbar.open .icon:before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23333333'%3E%3Cpath d='M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z'/%3E%3C/svg%3E");
    width: 24px;
    height: 24px;
    background-position: center;
    background-size: contain;
    background-repeat: no-repeat;
  }
}

@media (prefers-color-scheme: dark) {
  #navbar {
    background-color: var(--card-background);
  }

  #user-icon {
    background-color: var(--primary-color);
  }

  #navbar .icon:before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23e0e0e0'%3E%3Cpath d='M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z'/%3E%3C/svg%3E");
  }

  #navbar.open .icon:before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23e0e0e0'%3E%3Cpath d='M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z'/%3E%3C/svg%3E");
  }
}
