/* Top bar: menu button, page title, global search, date range and the profile menu.
   Markup: index.php. */

/* Relative so the notification panel hangs from the bar's own top-right
   rather than from the viewport. The profile's sign-out menu anchors to
   .topbar-profile, which is positioned in its own right, so it is unaffected. */
.topbar {
    position: relative;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
}

.topbar-title {
    font-size: var(--fs-lg);
    font-weight: 600;
    letter-spacing: -.011em;
    color: var(--text);
}

.search {
    flex: 1;
    max-width: 380px;
    position: relative;
}

.search input {
    width: 100%;
    height: 36px;
    padding: 7px 12px 7px 36px;
    border: 1px solid var(--line-strong);
    border-radius: var(--r-sm);
    font-size: var(--fs-sm);
    font-family: inherit;
    background: var(--surface-2);
    color: var(--text);
    outline: none;
    transition: border-color .15s, box-shadow .15s, background-color .15s;
}

.search input:focus {
    border-color: var(--primary);
    background: var(--surface);
    box-shadow: var(--focus-ring);
}

.search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
}

.topbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--fs-xs);
    font-weight: 700;
    color: #fff;
    cursor: pointer;
}

.date-range {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: var(--fs-xs);
    color: var(--muted);
    cursor: pointer;
    background: var(--card);
}

.role-badge {
    display: inline-block;
    font-size: var(--fs-2xs);
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 5px;
    text-transform: uppercase;
    letter-spacing: .03em;
    margin-top: 2px;
}

.role-badge.admin {
    background: var(--primary-soft);
    color: var(--accent);
}

.date-range {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

#datePicker {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.menu-toggle-btn:hover {
    background-color: var(--surface-3);
}

@media (max-width: 768px) {
    /* Topbar responsiveness */
    .topbar {
        padding: 0 12px !important;
        gap: 8px !important;
    }

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

    .search {
        max-width: 160px !important;
    }

    .date-range {
        padding: 6px 8px !important;
    }

    .date-range span {
        display: none !important; /* Hide date range text on mobile, keep calendar icon */
    }

    .topbar-profile .profile-details {
        display: none !important; /* Hide user name/role text next to avatar */
    }
}

@media (max-width: 480px) {
    .search {
        max-width: 120px !important;
    }
}

/* Formerly inline styles in index.php. */

/* .topbar keeps this above .menu-toggle-btn:hover, which the inline background: none also beat. */
.topbar .menu-toggle-btn {
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: background-color 0.2s;
}

/* Room on the right of the box for the clear button. */
.search .search-input {
    padding-right: 32px;
}

/* Clear button inside the search box. Hidden: no script shows it yet. */
.search .search-clear {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    color: var(--faint-ink);
    display: none;
    align-items: center;
    justify-content: center;
    outline: none;
}

.topbar .topbar-profile {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    position: relative;
}

.topbar-profile .profile-name {
    font-size: var(--fs-xs);
    font-weight: 700;
}

/* Opened and closed by toggleUserMenu() through style.display. */
.topbar-profile .user-menu {
    position: absolute;
    top: 46px;
    right: 0;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    min-width: 140px;
    z-index: 50;
    overflow: hidden;
}

.user-menu .user-menu-item {
    padding: 10px 14px;
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--red);
    cursor: pointer;
}

/* The rule above beats a plain :hover, so the hover state is restated here. */
.topbar .menu-toggle-btn:hover {
    background: var(--surface-3);
}

/* The job title under the name, above the role badge. The badge says
   what they may do; this says what they are. */
.profile-desig {
    font-size: var(--fs-2xs);
    line-height: 1.3;
    color: var(--muted, #64748B);
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* The badge sets its own display, so the UA rule for [hidden] loses.
   patShowDesignation() hides it for anyone whose designation says more. */
.role-badge[hidden] {
    display: none;
}

/* ─────────────────────────────────────────────────────────────
   The impersonation bar. Deliberately loud and across the whole
   window: the one thing worse than not being able to see as
   somebody else is forgetting that you are.
   ───────────────────────────────────────────────────────────── */
.imp-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    flex-wrap: wrap;
    min-height: 38px;
    padding: 7px 16px;
    background: #92400E;
    color: #FFFBEB;
    font-size: 13px;
    line-height: 1.4;
    text-align: center;
}
.imp-bar b {
    font-weight: 700;
    color: #fff;
}
.imp-bar__back {
    flex: none;
    padding: 4px 12px;
    border: 1px solid rgba(255, 255, 255, .6);
    border-radius: 999px;
    background: transparent;
    font: inherit;
    font-weight: 600;
    color: #fff;
    cursor: pointer;
}
.imp-bar__back:hover {
    background: #fff;
    color: #92400E;
}
/* The shell moves down to make room, rather than sitting under it. */
.app-shell.is-impersonating {
    padding-top: 38px;
}
.app-shell.is-impersonating .sidebar {
    top: 38px;
}
