/* Top Header – padding and safe-area; layout lives in .header-row */
.top-header {
    background: linear-gradient(135deg, #0b2c4a 0%, #0b2c4a 100%);
    color: white;
    padding: 0.2rem 1rem;
    padding-top: max(0.2rem, constant(safe-area-inset-top));
    padding-top: max(0.2rem, env(safe-area-inset-top));
    padding-bottom: 0.2rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: padding 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-sizing: border-box;
    /* iOS PWA: cancel app-container top padding so header extends into safe area; center row vertically */
    margin-top: calc(-1 * constant(safe-area-inset-top));
    margin-top: calc(-1 * env(safe-area-inset-top, 0px));
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* When search overlay is open, keep extra padding but preserve iOS PWA safe-area */
.top-header:has(.header-search-overlay.open) {
    padding: 1rem;
    padding-top: calc(1rem + constant(safe-area-inset-top));
    padding-top: calc(1rem + env(safe-area-inset-top));
}

/* Single row: fixed height and centering; overlay is same size as this for reliable vertical center */
.header-row {
    display: flex;
    align-items: center;
    position: relative;
    width: 100%;
    min-height: 52px;
    box-sizing: border-box;
}

/* Header main row – menu, logo, profile; centered in .header-row */
.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 100%;
    position: relative;
    flex: 1;
    min-width: 0;
}

.header-menu-wrapper {
    position: relative;
    z-index: 110;
}

.header-profile-btn,
.header-menu-btn {
    background: transparent;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    padding: 0;
    position: relative;
}

.header-profile-btn:active,
.header-menu-btn:active {
    animation: popUpClick 0.35s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.profile-icon,
.menu-icon {
    width: 20px;
    height: 20px;
    color: white;
}

/* Profile Verification Badge */
.verification-badge {
    position: absolute;
    top: 0px;
    right: -10px;
    width: 16px;
    height: 16px;
    background: #28a745;
    border: 2px solid white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 10;
}

.verification-badge.active {
    opacity: 1;
    visibility: visible;
}

.verification-badge-icon {
    width: 10px;
    height: 10px;
    color: white;
    stroke: white;
    stroke-width: 3;
    fill: none;
}

/* Header Menu Dropdown */
.header-menu-dropdown {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    background: white;
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    min-width: 180px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.3s ease;
    z-index: 1000;
    overflow: hidden;
}

.header-menu-dropdown.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.header-menu-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.5rem;
    background: transparent;
    border: none;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: right;
}

.header-menu-item:last-child {
    border-bottom: none;
}

.header-menu-item:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

.header-menu-item .menu-item-icon {
    width: 20px;
    height: 20px;
    color: #2c5aa0;
    stroke: #2c5aa0;
    stroke-width: 2;
    flex-shrink: 0;
}

.header-menu-item .menu-item-text {
    font-size: var(--font-size-base);
    font-weight: 500;
    color: #333;
    flex: 1;
}

.logo {
    font-size: var(--spacing-md);
    font-weight: 400;
    margin: 0;
    flex: 1;
    text-align: center;
}

/* Overlay clip: exactly same size as .header-row so overlay height is deterministic */
.header-search-overlay-clip {
    position: absolute;
    inset: 0;
    overflow: hidden;
    z-index: 50;
    pointer-events: none;
}

.header-search-overlay-clip:has(.header-search-overlay.open) {
    z-index: 150;
    pointer-events: auto;
}

/* Overlay: fills clip, flex centers inner vertically and horizontally (reliable on iOS) */
.header-search-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0b2c4a 0%, #0b2c4a 100%);
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 150;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    box-sizing: border-box;
}

.header-search-overlay.open,
.header-search-overlay[aria-hidden="false"] {
    transform: translateX(0);
}

/* Search row: single flex child of overlay, so always centered in overlay on all devices */
.header-search-overlay-inner {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    max-width: 100%;
    flex-shrink: 0;
    box-sizing: border-box;
}

.header-search-input {
    flex: 1;
    min-width: 0;
    height: 40px;
    padding: 0 1rem;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-radius: 9999px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 1rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s ease, background 0.2s ease;
    direction: ltr;
    text-align: left;
    -webkit-appearance: none;
    appearance: none;
}

.header-search-input::-webkit-search-cancel-button,
.header-search-input::-webkit-search-decoration {
    -webkit-appearance: none;
    appearance: none;
    display: none;
}

.header-search-input::placeholder {
    color: rgba(255, 255, 255, 0.7);
    direction: rtl;
    text-align: right;
}

.header-search-input:focus {
    border-color: rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.18);
}

.header-search-submit {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.15);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    padding: 0;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.header-search-submit:hover,
.header-search-submit:focus {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
}

.header-search-submit-icon {
    width: 20px;
    height: 20px;
    color: white;
    stroke: white;
}

.header-search-close {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.15);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    padding: 0;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.header-search-close:hover,
.header-search-close:focus {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
}

.header-search-close-icon {
    width: 20px;
    height: 20px;
    color: white;
    stroke: white;
}