header {
  --kg-header-safe-top: var(--kg-safe-top, env(safe-area-inset-top, 0px));
  --kg-header-frame-bottom: var(--kg-screen-top-frame-offset, var(--kg-shell-top, var(--klevby-app-available-top, 0px)));
  position: sticky;
  top: 0;
  z-index: 1000;
  padding: 14px 0;
  background: rgba(2, 6, 5, 0.58);
  border-bottom: 0;
  box-shadow: none;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.header-inner {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 14px;
}

.logo {
  font-size: 26px;
  font-weight: 800 !important;
  letter-spacing: -0.5px;
  white-space: nowrap;
  color: var(--text);
  text-shadow: 0 10px 30px rgba(0,0,0,0.35);
}

.logo.app-header-logo {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  width: 52px;
  height: 52px;
  min-width: 52px;
  min-height: 52px;
  margin-left: 4px;
  font-size: 0;
  line-height: 0;
  letter-spacing: 0;
  white-space: normal;
  text-shadow: none;
}

.logo.app-header-logo img {
  display: block;
  width: 52px;
  height: 52px;
  object-fit: contain;
  object-position: center;
}

.app-header-brand-copy {
  display: none;
}

header[data-chrome-mode="home"] .logo.app-header-logo {
  width: auto;
  min-width: 0;
  gap: 11px;
}

header[data-chrome-mode="home"] .app-header-brand-copy {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  font-family: inherit;
  line-height: 1;
  text-shadow: 0 4px 14px rgba(0, 0, 0, 0.28);
}

header[data-chrome-mode="home"] .app-header-brand-name {
  color: #ffffff;
  font-size: 19px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.1px;
  white-space: nowrap;
}

header[data-chrome-mode="home"] .app-header-brand-main {
  color: #ffffff;
}

header[data-chrome-mode="home"] .app-header-brand-accent {
  color: #f47a2b;
}

header[data-chrome-mode="home"] .app-header-brand-tagline {
  color: rgba(255, 244, 220, 0.72);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.burger-btn,
.mobile-menu-item,
.mobile-profile-btn,
.home-float-btn {
  appearance: none;
}

.mobile-header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  justify-self: end;
  position: relative;
  z-index: 2100;
}

.mobile-profile-btn {
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  padding: 0 !important;
  border: 1px solid rgba(244,178,74,0.16);
  border-radius: 17px;
  background:
    radial-gradient(circle at 30% 0%, rgba(244,178,74,0.18), transparent 44%),
    rgba(255,255,255,0.08);
  color: #fff8ea;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  cursor: pointer;
  overflow: hidden;
  box-shadow:
    0 12px 30px rgba(0,0,0,0.30),
    inset 0 1px 0 rgba(255,255,255,0.08);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  transition:
    transform 0.16s ease,
    filter 0.16s ease,
    border-color 0.16s ease,
    box-shadow 0.16s ease;
}

.mobile-profile-btn:hover {
  filter: brightness(1.06);
  border-color: rgba(244,178,74,0.28);
}

.mobile-profile-btn:active {
  transform: scale(0.94);
  filter: brightness(0.94);
  box-shadow:
    0 7px 18px rgba(0,0,0,0.32),
    inset 0 2px 8px rgba(0,0,0,0.24);
}

.mobile-profile-btn.has-avatar {
  background: rgba(8,14,13,0.96);
}

/* Жёстко растягиваем аватар на всю кнопку, даже если внутри стоит маленький круг */
.mobile-profile-btn img,
.mobile-profile-btn picture,
.mobile-profile-btn span,
.mobile-profile-btn div,
.mobile-profile-btn .profile-avatar-image,
.mobile-profile-btn .mobile-profile-avatar-image,
.mobile-profile-btn .profile-avatar-fallback,
.mobile-profile-btn .mobile-profile-avatar-fallback,
.mobile-profile-btn .profile-avatar-wrap,
.mobile-profile-btn .mobile-profile-avatar,
.mobile-profile-btn .mobile-profile-avatar-inner {
  width: 100% !important;
  height: 100% !important;
  min-width: 100% !important;
  min-height: 100% !important;
  max-width: 100% !important;
  max-height: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
  border-radius: inherit !important;
  border: 0 !important;
  object-fit: cover !important;
  object-position: center !important;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.mobile-profile-btn img,
.mobile-profile-btn .profile-avatar-image,
.mobile-profile-btn .mobile-profile-avatar-image {
  display: block;
  object-fit: cover !important;
  object-position: center !important;
}

.mobile-profile-btn .hidden {
  display: none !important;
}

.mobile-profile-avatar-fallback,
.mobile-profile-btn .profile-avatar-fallback {
  background:
    radial-gradient(circle at 30% 10%, rgba(255,255,255,0.22), transparent 38%),
    linear-gradient(135deg, var(--gold), var(--gold2));
  color: #1b1004;
  font-size: 20px;
  line-height: 1;
  font-weight: 900;
  letter-spacing: -0.4px;
}

.mobile-menu-wrap {
  display: block;
  position: relative;
  justify-self: end;
}

.burger-btn {
  width: 48px;
  height: 48px;
  border: 1px solid rgba(244,178,74,0.16);
  border-radius: 17px;
  background: rgba(255,255,255,0.08);
  color: #ffffff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
  box-shadow:
    0 12px 30px rgba(0,0,0,0.30),
    inset 0 1px 0 rgba(255,255,255,0.08);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  transition:
    transform 0.16s ease,
    filter 0.16s ease,
    border-color 0.16s ease,
    box-shadow 0.16s ease;
}

.burger-btn:hover {
  filter: brightness(1.06);
  border-color: rgba(244,178,74,0.28);
}

.burger-btn:active {
  transform: scale(0.94);
  filter: brightness(0.94);
  box-shadow:
    0 7px 18px rgba(0,0,0,0.32),
    inset 0 2px 8px rgba(0,0,0,0.24);
}

.burger-btn span {
  width: 20px;
  height: 2px;
  border-radius: 999px;
  background: rgba(255,248,234,0.92);
  display: block;
  transition: 0.22s ease;
}

.burger-btn.open span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.burger-btn.open span:nth-child(2) {
  opacity: 0;
}

.burger-btn.open span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

.mobile-menu {
  position: absolute;
  right: 0;
  top: 58px;
  width: min(82vw, 320px);
  display: none;
  grid-template-columns: 1fr;
  gap: 8px;
  padding: 12px;
  border-radius: 20px;
  background: rgba(8,14,13,0.96);
  border: 1px solid rgba(244,178,74,0.16);
  box-shadow: 0 22px 60px rgba(0,0,0,0.45);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.mobile-menu.open {
  display: grid;
}

.mobile-menu-item {
  min-height: 46px;
  width: 100%;
  padding: 0 14px;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  background: rgba(255,255,255,0.055);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  transition:
    transform 0.16s ease,
    filter 0.16s ease,
    background 0.16s ease,
    border-color 0.16s ease;
}

.mobile-menu-item:hover {
  filter: brightness(1.06);
  border-color: rgba(244,178,74,0.18);
}

.mobile-menu-item:active {
  transform: scale(0.98);
  filter: brightness(0.94);
  background: rgba(244,178,74,0.10);
}

.mobile-tabbar,
.mobile-weather-title {
  display: none;
}

.home-float-btn {
  position: fixed;
  top: 84px;
  right: 18px;
  z-index: 1250;
  min-height: 42px;
  padding: 0 15px;
  border: 1px solid rgba(244,178,74,0.16);
  border-top-color: rgba(255,255,255,0.16);
  border-radius: 999px;
  background:
    radial-gradient(circle at 20% 0%, rgba(244,178,74,0.20), transparent 42%),
    rgba(17, 24, 21, 0.84);
  color: #fff8ea;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: -0.1px;
  cursor: pointer;
  box-shadow:
    0 14px 34px rgba(0,0,0,0.36),
    inset 0 1px 0 rgba(255,255,255,0.08);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-10px) scale(0.96);
  transition:
    opacity 0.24s ease,
    visibility 0.24s ease,
    transform 0.24s ease,
    background 0.24s ease,
    border-color 0.24s ease,
    filter 0.16s ease;
}

.home-float-btn.show {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.home-float-btn.show:active {
  transform: translateY(0) scale(0.94);
  filter: brightness(0.94);
}

.app-header-leading {
  display: flex;
  align-items: center;
  min-width: 0;
}

.app-header-back-btn {
  appearance: none;
  -webkit-appearance: none;
  display: none;
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 17px;
  background: rgba(8, 14, 18, 0.72);
  color: #ffe2a5;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.app-header-back-btn:active {
  transform: scale(0.94);
  filter: brightness(0.94);
}

.app-header-back-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}

.app-header-back-icon img {
  display: block;
  width: 20px;
  height: 20px;
}

header[data-chrome-mode="home"] .app-header-back-btn {
  display: none;
}

header[data-chrome-mode="feed"] .logo.app-header-logo,
header[data-chrome-mode="inner"] .logo.app-header-logo,
header[data-chrome-mode="map"] .logo.app-header-logo,
header[data-chrome-mode="trips"] .logo.app-header-logo {
  display: none !important;
}

header[data-chrome-mode="feed"] .app-header-back-btn,
header[data-chrome-mode="inner"] .app-header-back-btn,
header[data-chrome-mode="map"] .app-header-back-btn,
header[data-chrome-mode="trips"] .app-header-back-btn {
  display: inline-flex;
}

header[data-chrome-mode="feed"] .mobile-menu-wrap {
  display: none !important;
}

header[data-chrome-mode="feed"] .mobile-actions {
  width: 100%;
  justify-content: flex-end;
}

@media (max-width: 900px) {
  body[data-app-chrome-mode="home"] header {
    padding: calc(var(--kg-header-safe-top, env(safe-area-inset-top, 0px)) - 6px) 0 5px;
  }

  body[data-app-chrome-mode="home"] header .header-inner {
    transform: translateY(-6px);
  }

  .mobile-header-actions {
    gap: 10px;
  }
}

@media (max-width: 520px) {
  .mobile-header-actions {
    gap: 8px;
  }

  .mobile-profile-btn,
  .burger-btn {
    width: 46px;
    height: 46px;
    min-width: 46px;
    min-height: 46px;
    border-radius: 18px;
  }

  .mobile-profile-avatar-fallback,
  .mobile-profile-btn .profile-avatar-fallback {
    font-size: 19px;
  }
}

@media (max-width: 380px) {
  .mobile-header-actions {
    gap: 7px;
  }

  header[data-chrome-mode="home"] .app-header-brand-name {
    font-size: 18px;
  }

  header[data-chrome-mode="home"] .app-header-brand-tagline {
    font-size: 11.5px;
  }

  .mobile-profile-btn,
  .burger-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border-radius: 17px;
  }

  .mobile-profile-avatar-fallback,
  .mobile-profile-btn .profile-avatar-fallback {
    font-size: 18px;
  }
}

/* Internal water-body detail keeps only the global map back action. */
header[data-water-body-detail="true"] {
  background: transparent !important;
  background-color: transparent !important;
  background-image: none !important;
  border-bottom: 0;
  box-shadow: none;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

header[data-water-body-detail="true"]::before,
header[data-water-body-detail="true"]::after,
header[data-water-body-detail="true"] .header-inner::before,
header[data-water-body-detail="true"] .header-inner::after {
  content: none !important;
  display: none !important;
}

header[data-water-body-detail="true"] .header-inner {
  background: transparent !important;
}

header[data-water-body-detail="true"] .mobile-actions {
  display: none !important;
}

header[data-water-body-detail="true"] .app-header-back-btn {
  background: rgba(27, 31, 35, 0.94);
  border-color: rgba(148, 163, 184, 0.18);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.22);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

@media (max-width: 900px) {
  body:has(#waterBodyDetailSection:not(.hidden)) header[data-water-body-detail="true"] {
    padding-bottom: 0;
  }
}
