/**
 * Shared header polish for base + portal/back-end shells.
 * Goals:
 * - Keep controls aligned on one baseline
 * - Prevent button/text spill from the header frame
 * - Keep layout compact while preserving responsive behavior
 */

.navbar .navbar-brand,
.topbar .navbar-brand,
.base-topbar .navbar-brand {
  min-width: 0;
  max-width: min(48vw, 640px);
}

.navbar .navbar-brand span,
.topbar .navbar-brand span,
.base-topbar .navbar-brand span {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 500px) minmax(0, 1fr);
  align-items: center;
  column-gap: 0.9rem;
  row-gap: 0.35rem;
  min-width: 0;
  width: 100%;
}

.base-topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-width: 0;
  flex-wrap: nowrap;
  justify-content: flex-end;
}

.topbar-actions > *,
.base-topbar-actions > * {
  flex: 0 0 auto;
  min-width: 0;
}

.topbar-context-strip {
  grid-column: 1;
  justify-self: start;
  width: 100%;
  min-width: 0;
  max-width: 680px;
}

.topbar-context-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
}

.topbar-context-row .topbar-context-strip {
  flex: 1 1 0;
  width: auto;
  min-width: 0;
  max-width: none;
}

.topbar-offline-status {
  flex: 0 0 auto;
  gap: 0.35rem !important;
  padding: 0.3rem 0.65rem !important;
  border: 1px solid rgba(255, 255, 255, 0.28);
  white-space: nowrap;
}

.topbar-offline-status #sms-offline-status-text {
  font-weight: 600;
}

.topbar-offline-status #sms-offline-status-last-synced {
  display: none !important;
}

.topbar-offline-status #sms-offline-sync-now-btn {
  margin-left: 0.22rem !important;
  font-size: 0.78rem !important;
}

.base-topbar-weather {
  flex: 0 1 460px;
  min-width: 240px;
  max-width: 560px;
}

.header-search-container {
  position: relative;
  grid-column: 2;
  justify-self: center;
  width: 100%;
  min-width: 280px;
  max-width: 500px;
}

.header-search-container .topbar-search-input {
  width: 100% !important;
  min-width: 0;
  padding-right: 4.8rem;
  background: rgba(255, 255, 255, 0.16) !important;
  border: 1px solid rgba(255, 255, 255, 0.3) !important;
  color: #fff !important;
}

.header-search-container .topbar-search-input::placeholder {
  color: rgba(255, 255, 255, 0.75);
}

.header-search-hint {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.85);
  pointer-events: none;
}

.topbar-search-kbd {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.68rem;
  line-height: 1;
  color: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.42);
  background: rgba(15, 23, 42, 0.34);
  border-radius: 999px;
  padding: 0.12rem 0.42rem;
  pointer-events: none;
  letter-spacing: 0.02em;
  font-weight: 700;
  max-width: 3.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  flex-wrap: nowrap;
  grid-column: 3;
  justify-self: end;
  justify-content: flex-end;
  width: max-content;
}

.topbar-controls > *,
.base-topbar-actions > * {
  flex-shrink: 0;
}

.topbar-controls .language-switcher {
  margin: 0 !important;
}

.topbar-lang-btn {
  border-radius: 999px;
  min-height: 2rem;
  padding: 0.28rem 0.72rem;
  white-space: nowrap;
}

.topbar-lang-btn > span {
  display: inline-block;
  max-width: 92px;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}

.topbar-icon-btn {
  width: 2rem;
  height: 2rem;
  min-width: 2rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
  font-size: 1.02rem;
}

.topbar-username {
  max-width: 130px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.base-topbar-actions {
  margin-left: auto;
}

.base-topbar-actions .btn-outline-light {
  min-height: 2rem;
}

.topbar .btn,
.topbar .btn-link,
.base-topbar .btn {
  white-space: nowrap;
}

.topbar .navbar-brand,
.base-topbar .navbar-brand {
  flex: 0 1 auto;
}

#portalHeader .container-fluid,
.base-topbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: nowrap;
  min-width: 0;
}

@media (max-width: 1399px) {
  .topbar-context-strip {
    max-width: 560px;
  }

  .base-topbar-weather {
    flex-basis: 320px;
    max-width: 360px;
  }
}

@media (max-width: 1279px) {
  .topbar-actions {
    grid-template-columns: minmax(0, 1fr) minmax(240px, 390px) minmax(0, 1fr);
  }

  .topbar-context-strip {
    max-width: 420px;
  }

  .base-topbar-weather {
    flex-basis: 320px;
    min-width: 220px;
    max-width: 360px;
  }

  .header-search-container {
    min-width: 240px;
    max-width: 390px;
  }

  .topbar-search-kbd {
    display: none;
  }

  .header-search-container .topbar-search-input {
    padding-right: 0.9rem;
  }

  .topbar-offline-status #sms-offline-sync-now-btn {
    display: none;
  }

  .header-search-hint {
    display: none;
  }

  .topbar-lang-btn > span {
    max-width: 68px;
  }

  .topbar-username {
    display: none !important;
  }
}

@media (max-width: 991px) {
  .topbar-actions {
    display: flex !important;
    flex-wrap: wrap;
    width: 100%;
    gap: 0.5rem;
  }

  .topbar-controls {
    order: 1;
    margin-left: auto;
  }

  .topbar-context-strip,
  .topbar-search,
  .header-search-container,
  .base-topbar-weather {
    order: 2;
    flex: 1 1 100%;
    max-width: 100%;
  }

  .base-topbar {
    flex-wrap: wrap;
  }

  .base-topbar-actions {
    width: 100%;
    justify-content: flex-end;
  }
}

@media (max-width: 575px) {
  .topbar-context-strip,
  .base-topbar-weather {
    display: none !important;
  }

  .topbar-username {
    display: none !important;
  }

  .topbar-icon-btn {
    width: 1.85rem;
    height: 1.85rem;
    min-width: 1.85rem;
    font-size: 0.95rem;
  }

  .topbar-search-kbd {
    display: none;
  }

  .header-search-container .topbar-search-input {
    padding-right: 0.75rem;
  }
}
