/* Topbar — uma linha: Título | projetos recentes | ações */
body.app-layout {
    --app-chrome-top: var(--topbar-height);
}

.app-topbar {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    width: auto;
    height: var(--topbar-height);
    min-height: var(--topbar-height);
    max-height: var(--topbar-height);
    box-sizing: border-box;
    z-index: 900;
    margin: 0;
    padding: 0;
    text-align: left;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    font-family: var(--font-saas, var(--font-family));
    transition: left 0.25s ease;
}

:root[data-theme="dark"] .app-topbar {
    background: rgba(31, 41, 55, 0.92);
}

.app-topbar__inner {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    height: 100%;
    padding: 0 1.25rem;
    min-width: 0;
}

.app-topbar__title,
header.app-topbar .app-topbar__title,
header.app-topbar h1 {
    margin: 0;
    font-size: 1rem !important;
    font-weight: 600;
    color: var(--text-color-dark);
    letter-spacing: normal;
    line-height: 1.25;
    white-space: nowrap;
    flex-shrink: 0;
}

.app-topbar__sep {
    width: 1px;
    height: 22px;
    background: var(--border-color);
    flex-shrink: 0;
}

.app-topbar__recent {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    overflow: hidden;
    padding: 0.15rem 0;
}

.app-topbar__proj {
    flex: 1;
    min-width: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    max-width: none;
    padding: 0.3rem 0.65rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 500;
    text-decoration: none;
    color: var(--text-color-body);
    background: var(--saas-bg-subtle, #f1f5f9);
    border: 1px solid transparent;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.app-topbar__proj:hover {
    background: #eff6ff;
    border-color: #bfdbfe;
    color: var(--primary-color);
}

.app-topbar__proj--empty {
    color: var(--text-color-light);
    font-style: italic;
    background: transparent;
    border: 1px dashed var(--border-color);
}

.app-topbar__proj--empty:hover {
    color: var(--primary-color);
    border-color: #bfdbfe;
}

.app-topbar__toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
    cursor: pointer;
    user-select: none;
}

.app-topbar__toggle--dropdown {
    position: relative;
    margin: 0;
    flex-shrink: 0;
    width: 2.5rem;
    height: 1.35rem;
}

.app-topbar__dropdown-pref {
    padding: 0.7rem 0.85rem;
    background: var(--saas-bg-subtle, #f8fafc);
    border-bottom: 1px solid var(--border-color);
}

.app-topbar__dropdown-pref-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.65rem;
}

.app-topbar__dropdown-pref-info {
    display: flex;
    flex-direction: column;
    gap: 0.12rem;
    min-width: 0;
    flex: 1;
}

.app-topbar__dropdown-pref-info strong {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-color-dark);
    line-height: 1.25;
}

.app-topbar__dropdown-pref-info span {
    font-size: 0.68rem;
    color: var(--text-color-muted, #64748b);
    line-height: 1.3;
}

.app-topbar__toggle-label {
    letter-spacing: 0.01em;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-color-muted, #64748b);
    white-space: nowrap;
}

.app-topbar__toggle input {
    position: absolute;
    inset: 0;
    opacity: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    cursor: pointer;
    z-index: 2;
}

.app-topbar__toggle-switch {
    position: relative;
    display: block;
    width: 2.5rem;
    height: 1.35rem;
    background: #94a3b8;
    border-radius: 999px;
    transition: background 0.2s ease;
    flex-shrink: 0;
    box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.08);
}

.app-topbar__toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 1.1rem;
    height: 1.1rem;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.25);
    transition: transform 0.2s ease;
}

.app-topbar__toggle input:checked + .app-topbar__toggle-switch {
    background: var(--primary-color, #1a237e);
}

.app-topbar__toggle input:checked + .app-topbar__toggle-switch::after {
    transform: translateX(1.15rem);
}

.app-topbar__toggle input:focus-visible + .app-topbar__toggle-switch {
    outline: 2px solid var(--primary-color, #1a237e);
    outline-offset: 2px;
}

.app-topbar__toggle:hover .app-topbar__toggle-label {
    color: var(--primary-color, #1a237e);
}

.app-topbar__actions {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
    margin-left: 0.25rem;
}

.app-topbar__icon-btn {
    position: relative;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--surface-color);
    color: var(--text-color-body);
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s ease;
    padding: 0;
}

.app-topbar__icon-btn:hover {
    background: #eff6ff;
    border-color: #bfdbfe;
    color: var(--primary-color);
}

.app-topbar__badge {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 7px;
    height: 7px;
    background: var(--danger-color);
    border-radius: 50%;
    border: 1.5px solid var(--surface-color);
}

.app-topbar__user {
    position: relative;
}

.app-topbar__user-btn {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    height: 36px;
    padding: 0 0.5rem 0 0.35rem;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background: var(--surface-color);
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-color-dark);
}

.app-topbar__user-btn:hover,
.app-topbar__user-btn[aria-expanded="true"] {
    border-color: #bfdbfe;
    background: #eff6ff;
}

.app-topbar__avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, #3b82f6, #6366f1);
    flex-shrink: 0;
}

.app-topbar__avatar--img {
    object-fit: cover;
}

.app-topbar__avatar--hidden {
    display: none;
}

.app-topbar__user-name {
    max-width: 88px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-topbar__user-chevron {
    font-size: 0.6rem;
    opacity: 0.5;
    transition: transform 0.2s ease;
}

.app-topbar__user-btn[aria-expanded="true"] .app-topbar__user-chevron {
    transform: rotate(180deg);
}

.app-topbar__dropdown {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    width: min(292px, calc(100vw - 1.5rem));
    max-height: min(70vh, 520px);
    overflow-x: hidden;
    overflow-y: auto;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 0.65rem 0 0;
    z-index: 1100;
}

.app-topbar__dropdown-head {
    padding: 0.35rem 0.85rem 0.55rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.app-topbar__dropdown-head strong {
    font-size: 0.88rem;
    color: var(--text-color-dark);
}

.app-topbar__dropdown-head span {
    font-size: 0.72rem;
    color: var(--text-color-light);
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-topbar__dropdown-stats {
    display: flex;
    gap: 0.35rem;
    padding: 0.55rem 0.85rem;
}

.app-topbar__dropdown-stats a {
    flex: 1;
    font-size: 0.68rem;
    padding: 0.35rem;
    border-radius: 6px;
    background: var(--saas-bg-subtle);
    text-decoration: none;
    color: var(--text-color-body);
    text-align: center;
}

.app-topbar__dropdown-stats a:hover {
    background: #eff6ff;
    color: var(--primary-color);
}

.app-topbar__dropdown-label {
    margin: 0.35rem 0 0.2rem;
    padding: 0 0.85rem;
    font-size: 0.62rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-color-light);
}

.app-topbar__dropdown-link {
    display: block;
    padding: 0.35rem 0.85rem;
    font-size: 0.8rem;
    color: var(--text-color-body);
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-topbar__dropdown-link:hover {
    background: var(--saas-bg-subtle);
    color: var(--primary-color);
}

.app-topbar__dropdown-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 0.35rem;
    padding: 0.55rem 0.85rem 0.25rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--primary-color);
    text-decoration: none;
}

@media (max-width: 992px) {
    .app-topbar {
        left: var(--sidebar-width-collapsed);
    }

    .app-topbar__user-name {
        display: none;
    }

    .app-topbar__user-btn {
        padding: 0 0.35rem;
    }

    .app-topbar__title {
        font-size: 0.9rem;
        max-width: 72px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .app-topbar__proj {
        font-size: 0.72rem;
    }
}

@media (max-width: 640px) {
    .app-topbar__sep,
    .app-topbar__recent {
        display: none;
    }

    .app-topbar__toggle-label {
        display: none;
    }

    .app-topbar__dropdown-pref-info span {
        display: none;
    }

    .app-topbar__inner {
        justify-content: space-between;
    }

    .app-topbar__title {
        max-width: none;
        flex: 1;
    }
}

:root[data-theme="dark"] .app-topbar__proj {
    background: var(--saas-bg-subtle);
}

:root[data-theme="dark"] .app-topbar__proj:hover {
    background: rgba(59, 130, 246, 0.15);
}

:root[data-theme="dark"] .app-topbar__toggle-switch {
    background: #64748b;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

:root[data-theme="dark"] .app-topbar__dropdown-pref {
    background: rgba(15, 23, 42, 0.45);
}

:root[data-theme="dark"] .app-topbar__toggle input:checked + .app-topbar__toggle-switch {
    background: #818cf8;
}

.topbar-pref-modal-root {
    position: fixed;
    inset: 0;
    z-index: 100001;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.topbar-pref-modal-root:not([hidden]) {
    display: flex;
}

.topbar-pref-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(2px);
}

.topbar-pref-modal {
    position: relative;
    width: min(480px, 100%);
    background: var(--surface-color, #fff);
    border-radius: 1rem;
    box-shadow: 0 24px 48px rgba(26, 35, 126, 0.22);
    overflow: hidden;
    color: var(--text-color-body);
}

.topbar-pref-modal-title {
    margin: 0;
    padding: 1.15rem 1.25rem 0.75rem;
    font-size: 1.05rem;
    color: var(--text-color-dark);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.topbar-pref-modal-body {
    padding: 0 1.25rem 1rem;
    font-size: 0.92rem;
    line-height: 1.55;
}

.topbar-pref-modal-body ul {
    margin: 0.75rem 0;
    padding-left: 1.2rem;
}

.topbar-pref-modal-body li {
    margin-bottom: 0.35rem;
}

.topbar-pref-modal-hint {
    margin: 0.75rem 0 0;
    font-size: 0.82rem;
    color: var(--text-color-muted, #64748b);
}

.topbar-pref-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.85rem 1.25rem 1.15rem;
    border-top: 1px solid var(--border-color);
}

.topbar-pref-btn {
    border: none;
    border-radius: 0.5rem;
    padding: 0.55rem 1rem;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
}

.topbar-pref-btn--ghost {
    background: transparent;
    color: var(--text-color-muted, #64748b);
}

.topbar-pref-btn--ghost:hover {
    background: rgba(26, 35, 126, 0.06);
}

.topbar-pref-btn--primary {
    background: var(--primary-color, #1a237e);
    color: #fff;
}

.topbar-pref-btn--primary:hover {
    filter: brightness(1.08);
}
