/* ===================================
   BetterRoofing - Unified Header Styles
   Mobile-first responsive design
   =================================== */

/* Header Container */
.header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-light);
    padding: 16px 24px;
    /* --ios-safe-top is injected by ViewController.swift (env() returns 0 when
       contentInsetAdjustmentBehavior = .never in the PWA shell WKWebView).
       Fallback chain: Swift variable → env() for browsers → 16px minimum. */
    padding-top: max(16px, var(--ios-safe-top, env(safe-area-inset-top, 0px)));
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 24px;
    flex: 1 1 0;
    min-width: 0;
}

/* Logo */
.logo {
    font-size: 24px;
    font-weight: 600;
    color: var(--brand-blue);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: opacity 0.2s;
}

.logo:hover {
    opacity: 0.8;
}

.logo-icon {
    font-size: 28px;
    line-height: 1;
}

.logo-text {
    line-height: 1;
}

/* Navigation Tabs */
.nav-tabs {
    display: flex;
    gap: clamp(2px, 0.5vw, 8px);
    align-items: center;
    flex: 1 1 0;
    min-width: 0;
}

.nav-tab {
    padding: 8px clamp(6px, 0.6vw, 16px);
    border-radius: 6px;
    cursor: pointer;
    font-size: clamp(12px, 0.85vw, 14px);
    color: var(--text-tertiary);
    text-decoration: none;
    transition: background 0.2s;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    height: fit-content;
}

.nav-tab:hover {
    background: var(--bg-hover);
}

.nav-tab.active {
    background: var(--brand-blue);
    color: var(--text-inverse);
}

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

.nav-dropdown .dropdown-toggle {
    background: none;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-tertiary);
    transition: background 0.2s;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    height: fit-content;
}

.nav-dropdown .dropdown-toggle:hover,
.nav-dropdown:hover .dropdown-toggle {
    background: var(--bg-hover);
}

.nav-dropdown .dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    min-width: 200px;
    margin-top: 0;
    padding: 12px 0 8px 0;
    z-index: 1000;
}

.nav-dropdown:hover .dropdown-menu {
    display: block;
}

.nav-dropdown .dropdown-item {
    display: block;
    padding: 10px 16px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 14px;
    transition: background 0.2s;
    white-space: nowrap;
}

.nav-dropdown .dropdown-item:hover {
    background: var(--bg-hover);
}

.nav-dropdown .dropdown-item.active {
    background: var(--brand-blue);
    color: var(--text-inverse);
}

/* Header Actions */
.header-actions {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-shrink: 0;
}

/* Search Box Wrapper */
.search-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    flex-shrink: 1;
    min-width: 0;
}

.search-box {
    padding: 8px 12px;
    border: 1px solid var(--input-border);
    border-radius: 6px;
    width: clamp(120px, 15vw, 300px);
    min-width: 0;
    flex-shrink: 1;
    font-size: 14px;
    background: var(--input-bg);
    color: var(--text-primary);
    transition: border-color 0.2s;
}

.search-box:focus {
    outline: none;
    border-color: var(--input-focus-border);
    box-shadow: 0 0 0 3px var(--input-focus-ring);
}

/* Global Search Results Dropdown */
.search-result-dropdown {
    display: none;
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    max-height: 320px;
    overflow-y: auto;
}

.search-result-item {
    display: flex;
    align-items: baseline;
    gap: 0;
    padding: 10px 14px;
    font-size: 13px;
    color: var(--text-primary);
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    transition: background 0.15s;
    outline: none;
}

.search-result-item:hover,
.search-result-item:focus {
    background: var(--bg-hover);
    box-shadow: inset 3px 0 0 var(--brand-blue);
}

.search-result-name {
    font-weight: 600;
    color: var(--text-primary);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 45%;
}

.search-result-sep {
    color: var(--text-tertiary);
    margin: 0 2px;
    flex-shrink: 0;
}

.search-result-detail {
    color: var(--text-secondary);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.search-result-loading,
.search-result-empty {
    color: var(--text-tertiary);
    font-style: italic;
    cursor: default;
}

.search-result-loading:hover,
.search-result-empty:hover {
    background: transparent;
}

/* Buttons */
.btn {
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    border: 1px solid var(--border-medium);
    background: var(--bg-secondary);
    color: var(--text-primary);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: opacity 0.2s;
}

.btn:hover {
    opacity: 0.9;
}

.btn-primary {
    background: var(--btn-primary-bg);
    color: var(--btn-primary-text);
    border-color: var(--btn-primary-bg);
}

/* Calendar Button with Badge */
.calendar-btn {
    position: relative;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 18px;
    color: var(--text-tertiary);
    text-decoration: none;
    border: none;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.calendar-btn:hover {
    background: var(--bg-hover);
}

.badge-notification {
    position: absolute;
    top: -8px;
    right: -8px;
    min-width: 18px;
    height: 18px;
    background: var(--btn-danger-bg);
    color: var(--btn-danger-text);
    font-size: 11px;
    font-weight: 700;
    border-radius: 10px;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    border: 2px solid var(--bg-secondary);
    z-index: 10;
}

.badge-notification.show {
    display: flex;
}

/* Theme Toggle Button */
.theme-toggle-btn,
.theme-toggle-btn-mobile {
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 18px;
    color: var(--text-tertiary);
    text-decoration: none;
    border: none;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background 0.2s, transform 0.2s;
}

.theme-toggle-btn:hover,
.theme-toggle-btn-mobile:hover {
    background: var(--bg-hover);
    transform: scale(1.05);
}

.theme-toggle-btn:active,
.theme-toggle-btn-mobile:active {
    transform: scale(0.95);
}

.theme-icon {
    display: inline-block;
    font-size: 18px;
    line-height: 1;
}

/* Settings Button */
.settings-btn {
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 18px;
    color: var(--text-tertiary);
    text-decoration: none;
    border: none;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.settings-btn:hover {
    background: var(--bg-hover);
}

.settings-btn.active {
    background: var(--brand-blue);
    color: var(--text-inverse);
}

/* Marketplace Button */
.marketplace-btn {
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 18px;
    color: var(--text-tertiary);
    text-decoration: none;
    border: none;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.marketplace-btn:hover {
    background: var(--bg-hover);
}

.marketplace-btn.active {
    background: var(--brand-blue);
    color: var(--text-inverse);
}

/* Mobile Menu Toggle (Hamburger) */
.mobile-menu-toggle {
    display: none;
    flex-direction: column;
    gap: 4px;
    padding: 8px;
    cursor: pointer;
    border: none;
    background: transparent;
    z-index: 101;
}

.mobile-menu-toggle span {
    display: block;
    width: 24px;
    height: 3px;
    background: var(--text-tertiary);
    border-radius: 2px;
    transition: all 0.3s ease;
}

.mobile-menu-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(6px, 6px);
}

.mobile-menu-toggle.active span:nth-child(2) {
    opacity: 0;
}

.mobile-menu-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(6px, -6px);
}

/* Mobile Menu Overlay */
.mobile-menu-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--overlay-bg);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-menu-overlay.show {
    display: block;
    opacity: 1;
}

/* Mobile Menu Panel */
.mobile-menu {
    display: none;
    position: fixed;
    top: 0;
    right: -300px;
    width: 300px;
    height: 100%;
    background: var(--bg-secondary);
    z-index: 1000;
    padding: 24px;
    box-shadow: var(--shadow-xl);
    overflow-y: auto;
    transition: right 0.3s ease;
}

.mobile-menu.show {
    display: block;
    right: 0;
}

.mobile-menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-light);
}

.mobile-menu-close {
    font-size: 24px;
    cursor: pointer;
    color: var(--text-tertiary);
    background: none;
    border: none;
    padding: 4px 8px;
}

/* Mobile Quick Icons Row (above search) */
.mobile-quick-icons {
    display: flex;
    align-items: center;
    justify-content: space-around;
    margin-bottom: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-light);
}

.mobile-appt-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
    font-size: 22px;
    text-decoration: none;
    color: var(--text-tertiary);
    background: none;
    padding: 8px;
    border-radius: 8px;
    transition: background 0.2s;
    min-height: 44px;
    min-width: 44px;
}

.mobile-appt-icon:hover {
    background: var(--bg-hover);
}

.mobile-appt-icon .badge-notification {
    position: absolute;
    top: -2px;
    right: -2px;
}

/* Reset browser-default button chrome for button-based mobile quick icon entries */
.mobile-quick-icons button.mobile-appt-icon {
    border: none;
    -webkit-appearance: none;
    appearance: none;
    font-family: inherit;
    cursor: pointer;
}

/* Mobile Search Container */
.mobile-search-container {
    margin-bottom: 16px;
}

.mobile-search-box {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--input-border);
    border-radius: 6px;
    font-size: 14px;
    background: var(--input-bg);
    color: var(--text-primary);
    box-sizing: border-box;
    transition: border-color 0.2s;
}

.mobile-search-box:focus {
    outline: none;
    border-color: var(--input-focus-border);
    box-shadow: 0 0 0 3px var(--input-focus-ring);
}

.mobile-menu-nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 24px;
}

.mobile-menu-nav .nav-tab {
    padding: 12px 16px;
    font-size: 16px;
    display: block;
    position: relative;
}

/* Reset browser-default button chrome for button-based mobile nav entries (e.g. Help).
   Without this, <button class="nav-tab"> renders with buttonface background and 1px border.
   Do NOT remove — this fix was regressed once by a PR review that missed the button vs anchor
   distinction. See AGENTS.md "Mobile nav-tab button reset" pitfall. */
.mobile-menu-nav button.nav-tab {
    border: none;
    background: transparent;
    -webkit-appearance: none;
    appearance: none;
    font-family: inherit;
    width: 100%;
    text-align: left;
    color: var(--text-tertiary);
}

/* Badge positioning within mobile menu */
.mobile-menu-nav .nav-tab .badge-notification {
    top: 50%;
    transform: translateY(-50%);
    right: 16px;
}

/* Mobile Navigation Item Container */
.mobile-nav-item {
    display: flex;
    flex-direction: column;
}

/* Mobile Inventory Toggle Button */
.mobile-inventory-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    text-align: left;
    border: none;
    background: transparent;
    cursor: pointer;
}

.mobile-inventory-toggle .chevron {
    font-size: 12px;
    transition: transform 0.3s ease;
    display: inline-block;
}

.mobile-inventory-toggle.expanded .chevron {
    transform: rotate(180deg);
}

/* Mobile Submenu */
.mobile-submenu {
    display: flex;
    flex-direction: column;
    padding-left: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.mobile-submenu[data-collapsed="true"] {
    display: none;
}

.mobile-submenu-item {
    padding: 10px 16px;
    padding-left: 32px;
    font-size: 14px;
    color: var(--text-primary);
    text-decoration: none;
    border-radius: 4px;
    transition: background 0.2s;
}

.mobile-submenu-item:hover {
    background: var(--bg-hover);
}

.mobile-submenu-item.active {
    background: var(--brand-blue);
    color: var(--text-inverse);
}

.mobile-menu-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-top: 24px;
    border-top: 1px solid var(--border-light);
}

.mobile-menu-actions .btn,
.mobile-menu-actions .calendar-btn,
.mobile-menu-actions .marketplace-btn,
.mobile-menu-actions .settings-btn {
    width: 100%;
    justify-content: flex-start;
    font-size: 16px;
    padding: 12px 16px;
}

/* ===================================
   RESPONSIVE BREAKPOINTS - Progressive Collapse
   =================================== */

/* Step 1: Below 1550px - Hide navigation tabs, show hamburger; hide settings cog and calendar
   (calendar moves to the mobile side panel at this breakpoint) */
@media (max-width: 1550px) {
    .nav-tabs {
        display: none;
    }

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

    .settings-btn {
        display: none;
    }

    .calendar-btn {
        display: none;
    }
}

/* Step 2: Below 1024px - Hide search box */
@media (max-width: 1024px) {
    .search-wrapper {
        display: none;
    }

    .header-actions {
        gap: 12px;
    }

    .logo {
        font-size: 20px;
    }
}

/* Step 3: Below 900px - Hide marketplace button */
@media (max-width: 900px) {
    .marketplace-btn {
        display: none;
    }

    .header {
        padding: 12px 16px;
    }
}

/* Step 4: Below 768px - Compact header spacing */
@media (max-width: 768px) {
    .header-actions {
        gap: 10px;
    }

    .logo {
        font-size: clamp(1rem, 2vw, 1.1875rem);
    }

    .logo-icon {
        font-size: 24px;
    }

    /* Make profile name shorter */
    .profile-name {
        max-width: 100px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

/* Step 5: Below 600px - Compact spacing */
@media (max-width: 600px) {
    .header-actions {
        gap: 8px;
    }

    /* Make profile name even shorter */
    .profile-name {
        max-width: 80px;
    }
}

/* Step 6: Below 480px - Minimal mobile view */
@media (max-width: 480px) {
    .header {
        padding: 10px 12px;
    }

    .logo {
        font-size: clamp(0.9rem, 4vw, 1.05rem);
    }

    .logo-icon {
        font-size: 22px;
    }

    .logo-text {
        max-width: clamp(8.5rem, 48vw, 11.5rem);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* On phone-width screens hide the profile button entirely — access profile
       via the hamburger menu.  The isolated blue avatar circle is confusing
       without a name label next to it (matches native-app header patterns). */
    .profile-btn {
        display: none;
    }

    .header-actions {
        gap: 6px;
    }

    .header-left {
        gap: 12px;
    }
}

/* Safe area insets for notched devices */
@supports (padding: max(0px)) {
    .header {
        padding-left: max(24px, env(safe-area-inset-left));
        padding-right: max(24px, env(safe-area-inset-right));
    }

    .mobile-menu {
        padding-left: max(24px, env(safe-area-inset-left));
        padding-right: max(24px, env(safe-area-inset-right));
    }

    @media (max-width: 768px) {
        .header {
            padding-left: max(16px, env(safe-area-inset-left));
            padding-right: max(16px, env(safe-area-inset-right));
        }
    }

    @media (max-width: 480px) {
        .header {
            padding-left: max(12px, env(safe-area-inset-left));
            padding-right: max(12px, env(safe-area-inset-right));
        }
    }
}

/* Touch target sizes (minimum 44px for accessibility) */
.nav-tab,
.btn,
.calendar-btn,
.settings-btn,
.mobile-menu-toggle {
    min-height: 44px;
    min-width: 44px;
}
/* ===================================
   Profile Menu Styles
   =================================== */

/* Profile Button */
.profile-menu {
    position: relative;
}

.profile-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px 6px 6px;
    background: transparent;
    border: 1px solid var(--border-light);
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 40px;
}

.profile-btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-medium);
}

.profile-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--brand-blue);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
}

.profile-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Profile Dropdown */
.profile-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 300px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    box-shadow: var(--shadow-xl);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s;
    z-index: 1000;
}

/* Marketing Studio header toggle (wired by marketing-studio.js; hidden on all other pages) */
.ms-header-toggle {
    background: none;
    border: 1.5px solid var(--border-light);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 16px;
    cursor: pointer;
    color: var(--text-secondary);
    min-height: 36px;
    min-width: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    order: -1; /* place before other action items */
}
.ms-header-toggle:hover { background: var(--bg-tertiary); }
.ms-header-toggle.initially-hidden { display: none; }

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

.profile-dropdown-header {
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.profile-avatar-large {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--brand-blue);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 600;
    flex-shrink: 0;
}

.profile-details {
    flex: 1;
    overflow: hidden;
}

.profile-full-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.profile-email {
    font-size: 13px;
    color: var(--text-tertiary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: 2px;
}

.profile-dropdown-divider {
    height: 1px;
    background: var(--border-light);
}

.profile-dropdown-body {
    padding: 8px;
}

.profile-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    color: var(--text-primary);
    text-decoration: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
    font-size: 14px;
}

.profile-menu-item:hover {
    background: var(--bg-hover);
}

.profile-menu-item .icon {
    width: 20px;
    font-size: 16px;
    text-align: center;
}

.profile-role-badge {
    display: inline-block;
    padding: 4px 10px;
    background: var(--status-complete-bg);
    color: var(--status-complete-text);
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    margin-top: 6px;
}

/* Sign in button */
.signin-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    background: var(--brand-blue);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
    margin: 8px 0;
}

.signin-btn:hover {
    background: #0066b8;
    transform: translateY(-1px);
}

.signin-btn .ms-logo {
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 3px;
    padding: 2px;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .profile-name {
        display: none;
    }

    .profile-btn {
        padding: 6px;
        border-radius: 50%;
        min-width: 40px;
    }

    .profile-dropdown {
        width: 280px;
    }
}

/* ===================================
   Impersonation Banner
   =================================== */
.impersonation-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    font-size: 14px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.impersonation-banner-inner {
    max-width: 1600px;
    margin: 0 auto;
    padding: 8px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.impersonation-banner-text {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.impersonation-banner-exit {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.4);
    padding: 4px 14px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s;
}

.impersonation-banner-exit:hover {
    background: rgba(255, 255, 255, 0.35);
}

@media (max-width: 600px) {
    .impersonation-banner-inner {
        flex-direction: column;
        gap: 6px;
        text-align: center;
        padding: 6px 16px;
    }
}
