/*
 * Moretto ERP · DS-01
 * Cabecera administrativa canónica.
 * Desktop: contexto + acciones + sistema en una sola banda.
 * Tablet/móvil: contexto/sistema arriba y acciones de página en una segunda banda.
 */

.fi-main:has(.moretto-ds01-topbar-navigation) {
    padding-top: 0 !important;
}

.fi-page-header-main-ctn:has(.moretto-ds01-topbar-navigation) {
    row-gap: 0.75rem !important;
    padding-top: 0 !important;
}

.fi-header:has(.moretto-ds01-topbar-navigation) {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto !important;
    align-items: center !important;
    gap: 0.75rem !important;
    min-width: 0;
    min-height: 4rem;
    margin: 0 !important;
    padding: 0.625rem 0.75rem !important;
    border: 1px solid color-mix(in srgb, var(--ui-border, #d8dce3) 76%, transparent);
    border-radius: 0 0 0.9rem 0.9rem;
    background: color-mix(in srgb, var(--ui-surface, #ffffff) 88%, transparent);
    box-shadow: 0 0.6rem 1.8rem color-mix(in srgb, #0f172a 8%, transparent);
    backdrop-filter: blur(18px) saturate(145%);
}

.fi-header:has(.moretto-ds01-topbar-navigation) > :first-child {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto;
    align-items: center;
    justify-content: start;
    row-gap: 0.0625rem;
    min-width: 0;
    overflow: hidden;
    text-align: start;
}

.moretto-ds01-topbar-navigation {
    display: none !important;
}

.fi-header:has(.moretto-ds01-topbar-navigation) .fi-breadcrumbs {
    grid-column: 1;
    grid-row: 1;
    align-self: end;
    justify-self: start;
    min-width: 0;
    margin: 0;
    overflow: hidden;
}

.fi-header:has(.moretto-ds01-topbar-navigation) .fi-breadcrumbs-list {
    justify-content: flex-start;
    flex-wrap: nowrap;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
}

.fi-header:has(.moretto-ds01-topbar-navigation) .fi-breadcrumbs-item,
.fi-header:has(.moretto-ds01-topbar-navigation) .fi-breadcrumbs-item-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fi-header:has(.moretto-ds01-topbar-navigation) .fi-breadcrumbs-item-label {
    color: var(--ui-text-muted, #657087);
    font-size: 0.625rem !important;
    font-weight: 500;
    line-height: 1.1;
    opacity: 0.6;
}

.fi-header:has(.moretto-ds01-topbar-navigation) .fi-breadcrumbs-item-separator {
    width: 0.625rem;
    height: 0.625rem;
    color: var(--ui-text-muted, #657087);
    opacity: 0.6;
}

.fi-header:has(.moretto-ds01-topbar-navigation) .fi-header-heading {
    grid-column: 1;
    grid-row: 2;
    display: block;
    align-self: start;
    justify-self: start;
    width: 100%;
    min-width: 0;
    margin: 0;
    overflow: hidden;
    color: var(--ui-text, #172033);
    font-family: var(--moretto-display, inherit);
    font-size: clamp(1.5rem, 1.7vw, 1.75rem) !important;
    font-weight: 700 !important;
    letter-spacing: -0.018em;
    line-height: 1.05;
    text-align: start;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fi-header:has(.moretto-ds01-topbar-navigation) .fi-header-heading::before,
.fi-header:has(.moretto-ds01-topbar-navigation) .fi-header-heading::after,
.fi-header:has(.moretto-ds01-topbar-navigation) .fi-header-subheading {
    display: none !important;
    content: none;
}

.fi-header:has(.moretto-ds01-topbar-navigation) .fi-header-actions-ctn {
    display: flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    min-width: 0;
    width: auto !important;
    margin: 0 !important;
    gap: 0.75rem !important;
}

.fi-header:has(.moretto-ds01-topbar-navigation) .fi-header-actions-ctn > .fi-ac {
    display: flex;
    flex: 0 1 auto;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: flex-end;
    min-width: 0;
    gap: 0.45rem !important;
}

.fi-header:has(.moretto-ds01-topbar-navigation) .fi-header-actions-ctn > .fi-ac .fi-btn,
.fi-header:has(.moretto-ds01-topbar-navigation) .fi-header-actions-ctn > .fi-ac .fi-dropdown-trigger > .fi-btn {
    min-height: 2.25rem !important;
    padding-block: 0.42rem !important;
    padding-inline: 0.68rem !important;
    border-radius: 0.58rem !important;
    box-shadow: none !important;
    transform: none !important;
    white-space: nowrap;
}

.fi-header:has(.moretto-ds01-topbar-navigation) .fi-header-actions-ctn > .fi-ac .fi-btn-label {
    font-size: 0.76rem !important;
    font-weight: 600 !important;
}

.moretto-ds01-topbar-system {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 0.45rem;
    padding-inline-start: 0.75rem;
    border-inline-start: 1px solid color-mix(in srgb, var(--ui-border, #d8dce3) 72%, transparent);
}

.moretto-ds01-topbar-system .fi-icon-btn,
.moretto-ds01-topbar-system .fi-user-menu-trigger {
    min-width: 2.25rem;
    min-height: 2.25rem;
}

html.dark .fi-header:has(.moretto-ds01-topbar-navigation) {
    border-color: color-mix(in srgb, var(--ui-border, #3f4654) 76%, transparent);
    background: color-mix(in srgb, var(--ui-surface, #171a20) 88%, transparent);
    box-shadow: 0 0.6rem 1.8rem color-mix(in srgb, #000000 26%, transparent);
}

html.dark .fi-header:has(.moretto-ds01-topbar-navigation) .fi-header-heading {
    color: var(--ui-text, #f4f5f7);
}

@supports not (backdrop-filter: blur(1px)) {
    .fi-header:has(.moretto-ds01-topbar-navigation) {
        background: var(--ui-surface, #ffffff);
    }

    html.dark .fi-header:has(.moretto-ds01-topbar-navigation) {
        background: var(--ui-surface, #171a20);
    }
}

/* Tablet: preserve title/system priority and move page actions below. */
@media (max-width: 63.999rem) {
    html body:not([data-moretto-pos]) .fi-main .fi-page .fi-header.fi-header:has(.moretto-ds01-topbar-navigation) {
        grid-template-columns: minmax(0, 1fr) auto !important;
        grid-template-rows: auto auto !important;
        align-items: center !important;
        gap: 0.5rem 0.65rem !important;
        min-height: 0 !important;
        padding: 0.55rem 0.62rem !important;
    }

    html body:not([data-moretto-pos]) .fi-main .fi-page .fi-header.fi-header:has(.moretto-ds01-topbar-navigation) > :first-child {
        grid-column: 1;
        grid-row: 1;
        min-width: 0;
    }

    html body:not([data-moretto-pos]) .fi-main .fi-page .fi-header.fi-header:has(.moretto-ds01-topbar-navigation) .fi-header-actions-ctn {
        display: contents !important;
    }

    html body:not([data-moretto-pos]) .fi-main .fi-page .fi-header.fi-header:has(.moretto-ds01-topbar-navigation) .fi-header-actions-ctn > .fi-ac {
        grid-column: 1 / -1;
        grid-row: 2;
        display: flex !important;
        width: 100%;
        min-width: 0;
        justify-content: flex-start !important;
        gap: 0.4rem !important;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 0.05rem 0 0.08rem;
        overscroll-behavior-inline: contain;
        scrollbar-width: none;
    }

    html body:not([data-moretto-pos]) .fi-main .fi-page .fi-header.fi-header:has(.moretto-ds01-topbar-navigation) .fi-header-actions-ctn > .fi-ac::-webkit-scrollbar {
        display: none;
    }

    html body:not([data-moretto-pos]) .fi-main .fi-page .fi-header.fi-header:has(.moretto-ds01-topbar-navigation) .moretto-ds01-topbar-system {
        grid-column: 2;
        grid-row: 1;
        align-self: center;
        justify-self: end;
        gap: 0.3rem;
        padding-inline-start: 0.5rem;
    }

    html body:not([data-moretto-pos]) .fi-main .fi-page .fi-header.fi-header:has(.moretto-ds01-topbar-navigation) .fi-header-heading {
        font-size: clamp(1.15rem, 4.6vw, 1.35rem) !important;
        line-height: 1.08 !important;
    }
}

/* Mobile: app-like header. System controls never compete with page actions. */
@media (max-width: 40rem) {
    html body:not([data-moretto-pos]) .fi-main .fi-page .fi-header.fi-header:has(.moretto-ds01-topbar-navigation) {
        gap: 0.42rem 0.5rem !important;
        margin-bottom: 0.6rem !important;
        padding: 0.5rem 0.52rem !important;
        border-radius: 0 0 0.75rem 0.75rem;
    }

    html body:not([data-moretto-pos]) .fi-main .fi-page .fi-header.fi-header:has(.moretto-ds01-topbar-navigation) .fi-breadcrumbs {
        max-width: min(58vw, 14rem);
    }

    html body:not([data-moretto-pos]) .fi-main .fi-page .fi-header.fi-header:has(.moretto-ds01-topbar-navigation) .fi-breadcrumbs-item-label {
        font-size: 0.56rem !important;
    }

    html body:not([data-moretto-pos]) .fi-main .fi-page .fi-header.fi-header:has(.moretto-ds01-topbar-navigation) .fi-header-heading {
        max-width: calc(100vw - 7.5rem);
        font-size: 1.08rem !important;
        letter-spacing: -0.012em;
    }

    html body:not([data-moretto-pos]) .fi-main .fi-page .fi-header.fi-header:has(.moretto-ds01-topbar-navigation) .moretto-ds01-topbar-system {
        gap: 0.18rem;
        padding-inline-start: 0.35rem;
        border-inline-start: 0;
    }

    html body:not([data-moretto-pos]) .fi-main .fi-page .fi-header.fi-header:has(.moretto-ds01-topbar-navigation) .moretto-ds01-topbar-system .fi-icon-btn,
    html body:not([data-moretto-pos]) .fi-main .fi-page .fi-header.fi-header:has(.moretto-ds01-topbar-navigation) .moretto-ds01-topbar-system .fi-user-menu-trigger {
        min-width: 2.15rem;
        min-height: 2.15rem;
    }

    html body:not([data-moretto-pos]) .fi-main .fi-page .fi-header.fi-header:has(.moretto-ds01-topbar-navigation) .fi-header-actions-ctn > .fi-ac .fi-btn,
    html body:not([data-moretto-pos]) .fi-main .fi-page .fi-header.fi-header:has(.moretto-ds01-topbar-navigation) .fi-header-actions-ctn > .fi-ac .fi-dropdown-trigger > .fi-btn {
        min-height: 2.15rem !important;
        padding: 0.35rem 0.55rem !important;
        border-radius: 0.55rem !important;
    }

    html body:not([data-moretto-pos]) .fi-main .fi-page .fi-header.fi-header:has(.moretto-ds01-topbar-navigation) .fi-header-actions-ctn > .fi-ac .fi-btn-label {
        font-size: 0.68rem !important;
    }
}

@media (min-width: 64rem) and (max-width: 72rem) {
    .fi-header:has(.moretto-ds01-topbar-navigation) {
        gap: 0.55rem !important;
        padding-inline: 0.55rem !important;
    }

    .fi-header:has(.moretto-ds01-topbar-navigation) .fi-breadcrumbs {
        max-width: 8.5rem;
    }

    .fi-header:has(.moretto-ds01-topbar-navigation) .fi-header-actions-ctn {
        gap: 0.5rem !important;
    }

    .fi-header:has(.moretto-ds01-topbar-navigation) .fi-header-actions-ctn > .fi-ac .fi-btn,
    .fi-header:has(.moretto-ds01-topbar-navigation) .fi-header-actions-ctn > .fi-ac .fi-dropdown-trigger > .fi-btn {
        padding-inline: 0.55rem !important;
    }

    .moretto-ds01-topbar-system {
        gap: 0.3rem;
        padding-inline-start: 0.5rem;
    }
}
