/* =============================================================================
   shell/topbar.css
   Topbar navigation, layout toggle switch, and switchable-layout support.
   ============================================================================= */

/* ── App shell: layout transition ─────────────────────────────────────────── */

.app-shell {
    transition: opacity 0.2s ease;
}

.app-shell.layout-transitioning {
    opacity: 0;
    pointer-events: none;
}

/* ── App shell: topbar layout mode ────────────────────────────────────────── */

.app-shell.topbar-layout {
    flex-direction: column;
}

.app-shell.topbar-layout .app-sidebar {
    display: none;
}

.app-shell.topbar-layout .app-topbar {
    display: flex;
}

.app-shell.topbar-layout .content-mobile-header {
    display: none;
}

.app-shell.topbar-layout .app-content {
    height: 0;
    min-height: 0;
}

/* ── Topbar base ───────────────────────────────────────────────────────────── */

.app-topbar {
    display: none;
    align-items: center;
    gap: var(--space-2);
    padding: 0 var(--space-4);
    background-color: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    height: 56px;
    position: relative;
    z-index: var(--z-fixed);
}

/* ── Topbar brand ──────────────────────────────────────────────────────────── */

.topbar-brand-wrap {
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.topbar-brand {
    display: flex;
    align-items: center;
    text-decoration: none;
    flex-shrink: 0;
}

.topbar-brand:hover {
    text-decoration: none;
}

.topbar-logo {
    height: 28px;
    width: auto;
    object-fit: contain;
}

/* ── Topbar nav ────────────────────────────────────────────────────────────── */

/*
 * overflow: visible is intentional — allows absolutely-positioned dropdowns
 * to render outside the nav bounds without being clipped.
 * (overflow-x: auto would force overflow-y: auto, hiding the dropdowns.)
 */
.topbar-nav {
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 1;
    min-width: 0;
    overflow: visible;
    padding: 0 var(--space-3);
}

/* ── Topbar item ───────────────────────────────────────────────────────────── */

.topbar-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: 6px var(--space-3);
    border-radius: var(--radius-md);
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-medium);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    text-decoration: none;
    white-space: nowrap;
    transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
    line-height: var(--line-height-normal);
    position: relative;
}

.topbar-item:hover {
    background-color: var(--primary-light);
    color: var(--primary);
    text-decoration: none;
}

.topbar-item.active {
    background: linear-gradient(160deg, var(--info-light) 0%, var(--primary-light) 100%);
    color: var(--primary);
    font-weight: var(--font-weight-semibold);
    box-shadow: inset 0 -2px 0 var(--primary);
}

.topbar-item.active i {
    color: var(--primary);
}

.topbar-item.active:hover {
    background: linear-gradient(160deg, var(--info-light) 0%, var(--primary-light) 100%);
    color: var(--primary-dark);
    box-shadow: inset 0 -2px 0 var(--primary);
    text-decoration: none;
}

.topbar-item.active:hover i {
    color: var(--primary-dark);
}

.topbar-item i {
    font-size: 13px;
    flex-shrink: 0;
    width: 14px;
    text-align: center;
    color: var(--text-light);
    transition: color 0.15s ease;
}

.topbar-item:hover i {
    color: var(--primary);
}

.topbar-external-icon {
    font-size: var(--font-size-xs);
    color: var(--text-subtle);
    flex-shrink: 0;
}

/* ── Topbar groups (dropdowns) ─────────────────────────────────────────────── */

.topbar-group {
    position: relative;
    display: flex;
    flex-direction: column;
}

.topbar-chevron {
    font-size: 10px;
    color: var(--text-subtle);
    transition: transform 0.25s ease;
    flex-shrink: 0;
}

.topbar-group.active > .topbar-item .topbar-chevron {
    transform: rotate(180deg);
}

/* ── Topbar dropdown content ───────────────────────────────────────────────── */

.topbar-dropdown-content {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 210px;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: var(--z-dropdown);
    display: flex;
    flex-direction: column;
    gap: 1px;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    padding: 0;
    transition:
        max-height 0.3s ease,
        opacity 0.25s ease,
        padding 0.25s ease;
}

.topbar-dropdown-content.show {
    max-height: 400px;
    opacity: 1;
    padding: var(--space-2);
}

/* ── Topbar sub-items ──────────────────────────────────────────────────────── */

.topbar-sub-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: 7px var(--space-3);
    border-radius: var(--radius-md);
    background: none;
    border: none;
    color: var(--text-medium);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-normal);
    font-family: inherit;
    text-decoration: none;
    transition: background-color 0.15s ease, color 0.15s ease;
    white-space: nowrap;
    width: 100%;
    text-align: left;
    cursor: pointer;
}

.topbar-sub-item:hover {
    background-color: var(--primary-light);
    color: var(--primary);
    text-decoration: none;
}

.topbar-sub-item i {
    width: 14px;
    font-size: var(--font-size-xs);
    flex-shrink: 0;
    text-align: center;
    color: var(--text-subtle);
    transition: color 0.15s ease;
}

.topbar-sub-item:hover i {
    color: var(--primary);
}

/* ── Topbar end (actions + toggle section) ─────────────────────────────────── */

.topbar-end {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-shrink: 0;
    min-width: 0;
    margin-left: auto;
}

.topbar-footer-btn {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: 6px var(--space-3);
    border-radius: var(--radius-md);
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-medium);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    text-decoration: none;
    white-space: nowrap;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.topbar-footer-btn:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-dark);
    text-decoration: none;
}

.topbar-back-btn {
    color: var(--primary);
}

.topbar-back-btn:hover {
    background-color: var(--primary-light);
    color: var(--primary-dark);
}

.request-btn-crm.topbar-footer-btn {
    border: none;
}

.request-btn-crm.topbar-footer-btn i {
    color: rgba(255, 255, 255, 0.85) !important;
}

/* Sidebar toggle section */
.sidebar-layout-section {
    padding: var(--space-3) var(--space-2);
    border-bottom: 1px solid var(--border-color);
    margin-bottom: var(--space-1);
}

.sidebar-layout-section .layout-toggle-wrap {
    justify-content: space-between;
    width: 100%;
}

.sidebar-layout-section .layout-toggle-label {
    color: var(--text-medium);
    font-size: var(--font-size-sm);
}

.app-sidebar.collapsed .sidebar-layout-section {
    display: none;
}

/* Topbar toggle section */
.topbar-layout-section {
    padding: 0 var(--space-3);
    border-left: 1px solid var(--border-color);
    height: 32px;
}

.topbar-layout-section .layout-toggle-wrap {
    gap: var(--space-2);
    height: 100%;
}

@media (max-width: 1180px) {
    .app-topbar {
        flex-wrap: wrap;
        align-items: stretch;
        gap: var(--space-3);
        height: auto;
        padding: var(--space-3) var(--space-4);
    }

    .topbar-brand-wrap {
        min-height: 36px;
    }

    .topbar-nav {
        order: 3;
        flex-basis: 100%;
        overflow-x: auto;
        padding: 0;
        scrollbar-width: none;
    }

    .topbar-nav::-webkit-scrollbar {
        display: none;
    }

    .topbar-end {
        flex: 1;
        justify-content: flex-end;
        flex-wrap: wrap;
    }

    .topbar-layout-section {
        border-left: none;
        padding: 0;
        height: auto;
    }
}

/* ── Mobile ────────────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
    .app-topbar {
        padding: var(--space-3);
    }

    .topbar-logo {
        height: 24px;
    }

    .topbar-footer-btn span,
    .topbar-back-btn span {
        display: none;
    }

    .topbar-footer-btn,
    .topbar-back-btn {
        padding: 6px;
    }

    .topbar-layout-section .layout-toggle-label {
        display: none;
    }

    .topbar-end {
        justify-content: flex-start;
    }

    .app-shell.topbar-layout {
        height: calc(100vh - 24px);
        margin: 12px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .topbar-dropdown-content,
    .topbar-chevron,
    .layout-toggle-input,
    .layout-toggle-input::after,
    .app-shell {
        transition: none;
    }
}
