/* =========================================================
   style_titlebar.css — updated for Option B (modal-first dashboard)
   Goals:
   - Responsive titlebar (no overflow on small screens)
   - Cleaner hover behavior (dropdown unaffected)
   - Better focus-visible for keyboard navigation
   - Stable z-index layering with modals
   ========================================================= */

.titlebar {
    display: flex;
    align-items: center;
    background-color: var(--header_bg, #1a1a2e);
    padding: var(--medium-padding) var(--large-padding);
    font-size: var(--fs-md);
    font-weight: var(--fw-medium);
    color: #fff;
    text-align: left;

    /* Cleanest behavior for “disappear/reappear” */
    position: fixed;
    top: 0;
    left: 0;
    right: 0;

    z-index: 900;
    gap: 14px; /* prevents elements touching */

    /* Hide/show animation */
    transform: translateY(0);
    transition: transform 220ms ease;
    will-change: transform;
}

/* Hidden state toggled by JS on scroll down */
.titlebar.titlebar--hidden{
    transform: translateY(-110%);
    pointer-events: none; /* prevents hover/click while hidden */
}

/* Links baseline */
.titlebar a {
    color: var(--body);
    text-decoration: none;
}

/* Brand */
.titlebar-logo {
    width: auto;
    flex-grow: 0;
    padding-left: var(--small-padding);
    min-width: 0;
    display: flex;
    align-items: center;
}

.titlebar-logo img{
    height: 34px;
    width: auto;
    display: block;
}

/* Brand link (logo + title clickable) */
.brand-link{
    display: inline-flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--body);
    min-width: 0;
}

.brand-title{
    font-weight: 700;
    letter-spacing: 0.02em;
    white-space: nowrap; /* prevents awkward line breaks */
}

/* Center area: menu */
.titlebar-centre {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0;
    min-width: 0;
}

.titlebar-centre p {
    margin: 0;
    padding: 0;
}

/* Right side */
.titlebar-user {
    flex-grow: 0;
    display: flex;
    align-items: center;
    gap: 18px;
    min-width: 0;
}

.titlebar-user button {
    box-shadow: none;
}

/* Optional language block (hidden by default in your header.php) */
.titlebar-lang {
    flex-grow: 0;
    margin-left: 10px;
    margin-right: 3vw;
}

.titlebar-lang a {
    color: var(--body);
    text-transform: uppercase;
    text-decoration: none;
    margin-left: .5em;
    margin-right: .5em;
}

/* Avoid affecting images inside the right area */
.titlebar-user > img,
.titlebar-user > a > img {
    margin-bottom: 0;
    margin-right: 10px;
}

/* Only uppercase the classic header buttons, not dropdown/menu buttons */
.titlebar-user > button {
    background-color: transparent;
    color: var(--body);
    border: none;
    padding: var(--small-padding) var(--medium-padding);
    text-transform: uppercase;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease;
    box-shadow: none;
    font-size: var(--fs-sm);
    font-weight: var(--fw-regular);
}

/* CTA button like "Acceder" */
.titlebar-user .btn-access {
    background: var(--cyan, #4ECDC4);
    color: #fff;
    border-radius: 999px;
    padding: 10px 20px;
    text-transform: none;
    font-weight: 600;
    border: none;
    transition: background-color 0.2s ease;
}
.titlebar-user .btn-access:hover {
    background: var(--cyan_hover, #3dbdb5);
    color: #fff;
}

/* Global hover (IMPORTANT: don't apply to dropdown items) */
.titlebar button:hover,
.titlebar a:hover {
    color: var(--navy_over);
}

/* Hard override: dropdown items keep their own color rules */
.user-dropdown .user-dropdown-item:hover{
    color: #111 !important;
}
.user-dropdown .user-dropdown-item--danger:hover{
    color: #b3261e !important;
}

/* Keyboard focus: visible but not noisy */
.titlebar a:focus-visible,
.titlebar button:focus-visible {
    outline: 2px solid rgba(235, 170, 63, 0.85);
    outline-offset: 3px;
    border-radius: 10px;
}

/* Legacy login button (if still used elsewhere) */
.login-button {
    padding: var(--small-padding) var(--medium-padding);
    background-color: var(--navy);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: var(--fs-md);
    font-weight: var(--fw-medium);
}
.login-button:hover {
    background-color: var(--navy_over);
}

/* ===============================
   Logged-in right-side links
   =============================== */

.titlebar-right-link{
    color: var(--body);
    text-decoration: none;
    font-size: var(--fs-sm);
    font-weight: var(--fw-regular);
    white-space: nowrap;
}

/* ===============================
   Avatar dropdown menu
   =============================== */

.user-menu{
    position: relative;
    display: inline-flex;
    align-items: center;
}

/* Avatar button (override titlebar button defaults) */
.user-avatar-btn{
    position: relative;
    border: none;
    background: transparent;
    padding: 0;
    cursor: pointer;
    text-transform: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    line-height: 1;
}

/* Round avatar */
.user-avatar{
    width: 34px;
    height: 34px;
    min-width: 34px;
    min-height: 34px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    object-fit: cover;
    overflow: hidden;
    border: 2px solid rgba(255,255,255,0.25);
    flex-shrink: 0;         /* never let flex collapse this */
    box-sizing: content-box; /* border is OUTSIDE the 34×34 area */
}

/* Defensive: override any global img reset (max-width:100%, height:auto, etc.) */
.user-avatar img{
    width: 100%  !important;
    height: 100% !important;
    max-width: none  !important; /* kills "img { max-width:100% }" */
    max-height: none !important;
    object-fit: cover;
    display: block;
    border: none;
    border-radius: 0; /* container handles clipping */
    margin: 0;
    padding: 0;
    flex-shrink: 0;
}

/* Initials fallback inside .user-avatar */
.user-avatar-initials{
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 0.8rem;
    letter-spacing: 0.3px;
    border-radius: 999px;
    user-select: none;
}

/* Notification badge */
.notif-badge{
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 18px;
    height: 18px;
    padding: 0 6px;
    border-radius: 999px;
    background: #E53935;
    color: #fff;
    font-size: 11px;
    line-height: 18px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0,0,0,0.25);
}

.notif-badge--inline{
    position: static;
    margin-left: 10px;
}

/* Dropdown */
.user-dropdown{
    position: absolute;
    right: 0;
    top: calc(100% + 10px);
    min-width: 220px;
    background: #fff;
    color: #111;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.25);
    padding: 8px;
    display: none;
    z-index: 1100; /* NEW: above titlebar, below modal overlay (your modals are 1200) */
}

/* Show when JS toggles .is-open */
.user-dropdown.is-open{
    display: block;
}

/* Dropdown items */
.user-dropdown-item{
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 10px 12px;
    border-radius: 10px;
    text-decoration: none;
    color: #111 !important;
    background: transparent;
    border: none;
    font-size: var(--fs-sm);
    font-weight: 500;
    cursor: pointer;
    text-transform: none;
}

/* Button item inherits the same look */
.user-dropdown-item-btn{
    text-align: left;
}

/* Hover inside dropdown: keep neutral */
.user-dropdown-item:hover{
    background: rgba(0,0,0,0.06);
    color: #111 !important;
}

/* Dropdown focus (keyboard) */
.user-dropdown-item:focus-visible{
    outline: 2px solid rgba(21, 42, 105, 0.55);
    outline-offset: 2px;
}

/* Divider inside dropdown (before danger actions like logout) */
.user-dropdown-divider{
    height: 1px;
    margin: 6px 8px;
    background: rgba(0,0,0,0.10);
}

/* Danger item (logout) */
.user-dropdown-item--danger{
    color: #b3261e !important;          /* readable red */
    border: 1px solid rgba(179,38,30,0.22);
    background: rgba(179,38,30,0.05);
}

/* Hover for danger item */
.user-dropdown-item--danger:hover{
    background: rgba(179,38,30,0.10);
    color: #b3261e !important;
}

/* Focus for danger item (keyboard) */
.user-dropdown-item--danger:focus-visible{
    outline: 2px solid rgba(179,38,30,0.55);
    outline-offset: 2px;
}

/* ===============================
   Responsive tweaks
   =============================== */
@media screen and (max-width: 900px) {
    .titlebar {
        flex-wrap: wrap;
        justify-content: space-between;
    }
    .titlebar-centre {
        order: 3;
        width: 100%;
        justify-content: center;
    }
    .titlebar-user {
        order: 2;
    }
    .titlebar-logo {
        order: 1;
    }
}

@media screen and (max-width: 520px) {
    .brand-title {
        display: none; /* keep just the icon when very tight */
    }
    .titlebar-user {
        gap: 10px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .titlebar{
        transition: none !important;
    }
}
