/* ==========================================================================
   Shell
   The frame around every staff page: print rules, the navbar, the main
   area, the footer, the loading overlay, HTMX indicators, the
   impersonation banner, and the brand mark in the navbar.

   The navbar's widths are budgeted by hand to fit the expanded bar in
   Spanish; tests/playwright_tests/test_staff_navbar_fits.py measures it.
   Besides bootstrap-theme.css, the only staff sheet allowed to restyle a
   Bootstrap class, and only inside the shell's own elements: the staff UI
   checker exempts rules rooted at .staff-navbar, .navbar-nav, .staff-footer,
   .global-loading-overlay and .impersonation-banner.
   ========================================================================== */

@media print {
    .staff-navbar,
    .staff-footer {
        display: none !important;
    }

    .main-content {
        padding: 0 !important;
    }

    .services-table-container {
        box-shadow: none !important;
        border: 1px solid #ddd !important;
    }

    .services-table-header {
        background: #f5f5f5 !important;
        color: black !important;
    }
}

/* ==========================================================================
   App Shell (navbar, footer, alerts, dropdowns, loading)
   Moved out of base.html's inline <style> block.
   ========================================================================== */

/* Navigation */
.staff-navbar {
    background: var(--bg-primary) !important;
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 1030;
    isolation: isolate;
    min-height: 56px;
    padding: 0;
}

.staff-navbar-brand {
    font-weight: var(--font-weight-black);
    color: var(--text-primary) !important;
    font-size: var(--font-size-base);
    display: flex;
    align-items: center;
    gap: 8px !important;
    padding: 0;
    margin-right: var(--space-8) !important;
}

.navbar-nav {
    gap: 4px !important;
}

.staff-navbar .nav-link {
    color: var(--text-nav) !important;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    padding: 6px 12px !important;
    border-radius: var(--radius-md);
    transition: color var(--transition-fast), background-color var(--transition-fast);
    display: flex;
    align-items: center;
    gap: var(--space-2) !important;
    margin: 0 !important;
    /* A label that wraps makes the whole bar taller ("Panel de control" took
       three lines). The bar is budgeted to fit on one; see the xl block below. */
    white-space: nowrap;
}

/* A long username must not push the bar past the container. */
.staff-nav-username {
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* The expanded bar needs about 1260px in Spanish: brand, six labelled links,
   three icons and the account. The xxl container (1296px inside) holds that;
   the xl one (1116px) does not, and flex items do not shrink below their
   content, so the bar ran past the container and every page scrolled
   sideways. Between the two the account shows its avatar alone and the links
   sit closer. Below xl the bar collapses to the hamburger (navbar-expand-xl). */
@media (min-width: 1200px) and (max-width: 1399.98px) {
    .staff-navbar-brand {
        margin-right: var(--space-4) !important;
    }

    .staff-navbar .nav-link {
        padding: 6px 10px !important;
    }

    /* Still the toggle's accessible name: clipped, not display: none. */
    .staff-nav-username {
        position: absolute;
        width: 1px;
        height: 1px;
        margin: -1px;
        clip-path: inset(50%);
    }
}

/* The unread pill must not grow the link: every label is the same height,
   and test_staff_navbar_fits.py reads a taller one as a wrapped label. */
.nav-unread-pill {
    font-size: 0.7em;
    line-height: 1;
    vertical-align: text-top;
}

.staff-navbar .nav-link:hover {
    color: var(--text-primary) !important;
    background-color: var(--bg-accent);
}

.staff-navbar .nav-link.active {
    color: var(--text-brand) !important;
    background-color: var(--bg-accent);
    font-weight: var(--font-weight-bold);
}

/* Main content area */
.main-content {
    flex: 1 0 auto;
    padding: var(--space-8) 0;
}

/* Product-specific alert accent: Bootstrap still owns contextual colors and states. */
.alert-accent {
    border-left-width: 4px;
}

/* Legacy dropdown and language-selector variants were removed:
   the current navbar uses Bootstrap's .dropdown-menu / .dropdown-item, and
   PurgeCSS confirms no callers remain. */

/* Footer */
.staff-footer {
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    color: var(--text-tertiary);
    font-size: var(--font-size-xs);
    padding: var(--space-3) 0;
    flex-shrink: 0;
}
.staff-footer p { font-size: var(--font-size-xs); }
.staff-footer .keyboard-help-link { font-size: inherit; }
/* Shortcuts need a keyboard; hide the footer link on small touch screens.
   Both conditions, so a desktop browser that misreports its pointer keeps it. */
@media (pointer: coarse) and (max-width: 991.98px) {
    .keyboard-help-link { display: none; }
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .main-content {
        padding: var(--space-4) 0;
    }

    .staff-navbar .navbar-nav {
        padding: 0.75rem 0;
    }

    .staff-navbar .nav-link {
        padding: 0.625rem 1rem !important;
        margin: 0.125rem 0;
    }
}

/* The backdrop only exists below the expand breakpoint; on desktop the menu
   is always open and there is nothing to dim. */
.staff-nav-backdrop {
    display: none;
}

@media (max-width: 1199.98px) {
    .staff-nav-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        /* Below .staff-navbar (1030) so the bar and its open menu stay lit. */
        z-index: 1029;
        background: rgba(11, 13, 15, 0.5);
        opacity: 0;
        visibility: hidden;
        transition: opacity var(--transition-fast), visibility var(--transition-fast);
    }

    /* .collapsing covers the open/close animation, .show the settled state. */
    body:has(.staff-navbar .navbar-collapse.show) .staff-nav-backdrop,
    body:has(.staff-navbar .navbar-collapse.collapsing) .staff-nav-backdrop {
        opacity: 1;
        visibility: visible;
    }

    /* Scroll lock: body overflow propagates to the viewport, so the page
       underneath stays put while the menu is open. The menu itself keeps its
       own overflow-y and scrolls when it is taller than the screen. */
    body:has(.staff-navbar .navbar-collapse.show) {
        overflow: hidden;
    }

    .staff-navbar .navbar-collapse {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        z-index: 1040;
        width: 100%;
        height: auto !important;
        max-height: calc(100vh - 80px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        background: var(--bg-primary);
        border-top: 1px solid var(--border-color);
        padding-bottom: 0.75rem;
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    /* The top bar now carries the brand, the icon cluster and the hamburger on
       one line, and at 390px that does not fit by default: the bar wraps to two
       rows and the hamburger drops under the logo. Three things buy the room.

       The brand's right margin exists to separate it from the nav links, which
       below this breakpoint are inside the collapse — it buys nothing here. */
    .staff-navbar-brand {
        margin-right: var(--space-2) !important;
        /* Truncate the word-mark rather than wrap the bar on narrower phones. */
        min-width: 0;
        overflow: hidden;
    }

    .staff-navbar-brand > span:not(.brand-badge) {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Never wrap: with the brand able to shrink, the row absorbs the pressure. */
    .staff-navbar > .container {
        flex-wrap: nowrap;
    }

    /* The stacked-menu padding above is for the collapse; this cluster sits in
       the bar itself, where it would just make the bar taller. */
    .staff-navbar .staff-nav-icons {
        padding: 0 !important;
    }

    /* Icon-only links: the generous side padding is for labelled ones, and a
       square box that stays thumb-sized is worth more here than the padding. */
    .staff-navbar .staff-nav-icons .nav-link {
        padding: 0.5rem !important;
        margin: 0 !important;
        min-width: 40px;
        min-height: 40px;
        justify-content: center;
    }

    /* Stacked menu: every row spans the full width. The account list carries
       .align-items-center for the desktop bar, which in a column centres its
       row. */
    .staff-navbar .navbar-collapse .navbar-nav {
        align-items: stretch !important;
    }

    /* The nav-link is a flex row, so the dropdown caret sat right after the
       label (Planning ▾, Manage ▾); push it to the row's end instead. */
    .staff-navbar .navbar-collapse .nav-link.dropdown-toggle {
        justify-content: space-between;
    }

    .staff-navbar .navbar-collapse .nav-link.dropdown-toggle > .staff-nav-username {
        margin-right: auto;
    }

    /* Keep the unread pill beside "Manage", not mid-row. */
    .staff-navbar .navbar-collapse .nav-link.dropdown-toggle > #nav-unread-badge {
        margin-left: 0.5rem;
        margin-right: auto;
    }

    .staff-navbar .navbar-nav .dropdown-menu {
        position: static;
        float: none;
        transform: none !important;
        margin-left: 1rem;
        margin-right: 1rem;
        border-radius: var(--radius-md);
    }
}

/* Enhanced loading states */
.page-loading {
    opacity: 0.7;
    position: relative;
}

/* Global loading overlay */
.global-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: color-mix(in srgb, var(--bg-primary) 90%, transparent);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-fast);
}

.global-loading-overlay.show {
    opacity: 1;
    visibility: visible;
}

.global-loading-overlay .loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
}

.global-loading-overlay .loading-spinner .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--bg-track);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-text {
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
}

/* HTMX request indicators */
.htmx-indicator {
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
    opacity: 1;
}

/* ==========================================================================
   Impersonation Banner
   Sticky warning bar shown while an admin impersonates another user
   (templates/partials/impersonation_banner.html). The distinct orange gradient
   is kept as literals (bespoke banner treatment, not palette drift; mirrors the
   admin-list gradient in admin-impersonation.css). Overrides Bootstrap's
   .alert-warning by load order.
   ========================================================================== */

.impersonation-banner {
    background: linear-gradient(135deg, #ff6b35 0%, #f7931e 100%);
    border-bottom: 3px solid #e85d04 !important;
    color: white;
    box-shadow: 0 2px 8px rgba(232, 93, 4, 0.3);
    position: sticky;
    top: 76px;
    z-index: 1040;
    animation: slideDown 0.3s ease-out;
    font-family: var(--font-sans);
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.impersonation-banner__icon {
    font-size: 1.2rem;
    color: rgba(255, 255, 255, 0.9);
}

.impersonation-banner strong {
    font-weight: 600;
}

.impersonation-banner__meta {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.85rem;
}

.impersonation-banner__action {
    background: rgba(255, 255, 255, 0.9);
    color: #e85d04;
    border: 1px solid rgba(255, 255, 255, 0.3);
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.impersonation-banner__action:hover {
    background: white;
    color: #e85d04;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.impersonation-banner .btn-close {
    filter: brightness(0) invert(1);
    opacity: 0.7;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.impersonation-banner .btn-close:hover {
    opacity: 1;
    transform: scale(1.1);
}

@media (max-width: 768px) {
    .impersonation-banner .container {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }

    .impersonation-banner__actions {
        flex-direction: column;
        gap: 0.5rem !important;
        width: 100%;
    }

    .impersonation-banner__action {
        width: auto;
        min-width: 160px;
    }
}

/* ==========================================================================
   Brand mark: the logo tile and the context badge beside the wordmark
   ========================================================================== */

/* Logo and Branding */
.mundared-logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--color-brand-light);
  border: 1px solid var(--color-brand-ring);
  padding: 4px;
  transition: all var(--transition-fast);
  object-fit: contain;
}

.mundared-logo:hover {
  background: var(--color-brand-ring);
  transform: scale(1.05);
}

/* Small uppercase pill for context tags next to the wordmark (OPS, DEV,
   STAGING, tenant code). */
.brand-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    background: var(--color-status-neutral-bg);
    color: var(--color-status-neutral-text);
    font-size: 10px;
    font-weight: var(--font-weight-bold);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    line-height: 1.2;
}

/* The loading overlay's spinner. */
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
