/* Shared navigation geometry; loaded after the existing shell layers. */

/* Visual Claude (16/09), inspirado na navegação do Magnific. */
@media (min-width: 769px) {
    .sidebar {
        top: 8px;
        height: calc(100vh - 16px);
        margin: 0 4px;
        border: 0;
        border-radius: 20px;
        box-shadow:
            0 0 0 1px color-mix(in srgb, var(--line) 34%, transparent),
            0 8px 24px color-mix(in srgb, #000 4%, transparent);
        overflow: hidden;
    }

    [data-theme="dark"] .sidebar {
        box-shadow:
            0 0 0 1px color-mix(in srgb, var(--line) 58%, transparent),
            0 12px 28px rgba(0, 0, 0, .18);
    }

    .app-shell {
        align-self: flex-start;
        height: calc(100vh - 16px);
        max-height: calc(100vh - 16px);
        min-height: 0;
        margin: 8px 4px 8px 4px;
        border-radius: 20px;
        background: var(--surface);
        box-shadow: 0 0 0 1px color-mix(in srgb, var(--line) 34%, transparent);
        overflow: hidden;
    }

    .app-main,
    .tab-panels {
        min-height: 0;
    }

    .app-main {
        overflow: auto;
    }

    .app-shell > .topbar {
        border-bottom: 0;
        box-shadow: none;
    }

    [data-theme="dark"] .app-shell {
        box-shadow: 0 0 0 1px color-mix(in srgb, var(--line) 48%, transparent);
    }

    /* Floating shell is inset 8px top+bottom (16px). Productivity sizes with
       100dvh − topbar and would otherwise clip the rail footer. */
    #panel-productivity {
        --pd-shell-offset: calc(var(--topbar-h, 60px) + 16px);
        height: calc(100dvh - var(--pd-shell-offset));
        max-height: calc(100dvh - var(--pd-shell-offset));
        min-height: 0;
    }

    #panel-productivity .pd-workspace,
    #panel-productivity .pd-rail,
    #panel-productivity .pd-main,
    #panel-productivity .pd-detail {
        height: calc(100dvh - var(--pd-shell-offset));
        max-height: calc(100dvh - var(--pd-shell-offset));
    }

    /* Match floating shell chrome — macos-hairline reads too dark here. */
    #panel-productivity .pd-rail {
        border-right-color: color-mix(in srgb, var(--line) 48%, transparent);
    }

    #panel-productivity .pd-header,
    #panel-productivity .pd-filterbar {
        border-bottom-color: color-mix(in srgb, var(--line) 48%, transparent);
    }

    #panel-productivity .pd-rail__footer {
        border-top-color: color-mix(in srgb, var(--line) 48%, transparent);
    }

    /* Same floating inset: Studio uses 100dvh − topbar and clips the dock. */
    #panel-studio {
        --st-shell-offset: calc(var(--topbar-h, 56px) + 16px);
        height: calc(100dvh - var(--st-shell-offset));
        max-height: calc(100dvh - var(--st-shell-offset));
        min-height: 0;
    }

    /* Chat: same clip as Studio. */
    #panel-chat {
        --ch-shell-offset: calc(var(--topbar-h, 46px) + 16px);
        height: calc(100dvh - var(--ch-shell-offset));
        max-height: calc(100dvh - var(--ch-shell-offset));
        min-height: 0;
    }
}

.sidebar__header,
html:not([data-sidebar-collapsed="true"]) .sidebar__header {
    height: 64px;
    min-height: 64px;
    border-bottom: 0;
}

.sidebar__brand .brand {
    gap: 10px;
    padding-left: 0;
}

.sidebar__brand .brand-mark {
    width: 30px;
    height: 30px;
    border-radius: 8px;
}

.sidebar__brand .brand-text strong {
    font-size: 20px;
    line-height: 24px;
}

.sidebar__footer,
html:not([data-sidebar-collapsed="true"]) .sidebar__footer {
    border-top: 0;
}

.sidebar__cta {
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr);
    align-items: center;
    gap: 6px;
    width: 100%;
    min-height: 40px;
    padding: 4px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    box-shadow: none;
    color: var(--text);
    cursor: pointer;
    font: inherit;
    text-align: left;
    transition: background 120ms ease, transform 120ms ease;
}

.sidebar__cta:hover {
    background: var(--hover);
}

.sidebar__cta:active {
    transform: scale(0.98);
}

.sidebar__cta:focus-visible {
    outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent);
    outline-offset: 2px;
}

.sidebar__cta-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
}

.sidebar__cta-label {
    overflow: hidden;
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: -0.015em;
    text-overflow: ellipsis;
    white-space: nowrap;
}

[data-theme="dark"] .sidebar__cta {
    background: var(--hover);
}

[data-theme="dark"] .sidebar__cta:hover {
    background: color-mix(in srgb, var(--hover) 84%, white);
}

.sidebar__brand .brand-mark,
.sidebar__brand .brand-mark svg,
.sidebar__brand .brand-mark__logo {
    color: #fff;
}

[data-theme="light"] .sidebar__brand .brand-mark {
    background: #111;
    border-color: var(--line);
    color: #fff;
}

[data-theme="dark"] .sidebar__brand .brand-mark {
    background: color-mix(in srgb, var(--accent) 18%, var(--surface));
    border-color: color-mix(in srgb, var(--accent) 34%, var(--line));
    color: #fff;
}

#tab-productivity:checked ~ .sidebar .sidebar__link[for="tab-productivity"],
#tab-reels:checked ~ .sidebar .sidebar__link[for="tab-reels"],
#tab-accounts:checked ~ .sidebar .sidebar__link[for="tab-accounts"],
#tab-publish:checked ~ .sidebar .sidebar__link[for="tab-publish"],
#tab-downloader:checked ~ .sidebar .sidebar__link[for="tab-downloader"],
#tab-studio:checked ~ .sidebar .sidebar__link[for="tab-studio"],
#tab-workflows:checked ~ .sidebar .sidebar__link[for="tab-workflows"],
#tab-chat:checked ~ .sidebar .sidebar__link[for="tab-chat"],
#tab-team:checked ~ .sidebar .sidebar__link[for="tab-team"],
#tab-bot:checked ~ .sidebar .sidebar__link[for="tab-bot"],
#tab-pixel:checked ~ .sidebar .sidebar__link[for="tab-pixel"] {
    background: var(--hover);
    color: var(--text);
    font-weight: 400;
}

#tab-productivity:checked ~ .sidebar .sidebar__link[for="tab-productivity"] .sidebar__link-icon,
#tab-reels:checked ~ .sidebar .sidebar__link[for="tab-reels"] .sidebar__link-icon,
#tab-accounts:checked ~ .sidebar .sidebar__link[for="tab-accounts"] .sidebar__link-icon,
#tab-publish:checked ~ .sidebar .sidebar__link[for="tab-publish"] .sidebar__link-icon,
#tab-downloader:checked ~ .sidebar .sidebar__link[for="tab-downloader"] .sidebar__link-icon,
#tab-studio:checked ~ .sidebar .sidebar__link[for="tab-studio"] .sidebar__link-icon,
#tab-workflows:checked ~ .sidebar .sidebar__link[for="tab-workflows"] .sidebar__link-icon,
#tab-chat:checked ~ .sidebar .sidebar__link[for="tab-chat"] .sidebar__link-icon,
#tab-team:checked ~ .sidebar .sidebar__link[for="tab-team"] .sidebar__link-icon,
#tab-bot:checked ~ .sidebar .sidebar__link[for="tab-bot"] .sidebar__link-icon,
#tab-pixel:checked ~ .sidebar .sidebar__link[for="tab-pixel"] .sidebar__link-icon {
    color: var(--text);
}

html:not([data-sidebar-collapsed="true"]) .sidebar {
    --sidebar-pad: 18px;
}

html:not([data-sidebar-collapsed="true"]) .sidebar__primary {
    padding: 0 18px 12px;
}

html:not([data-sidebar-collapsed="true"]) .sidebar__cta {
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr);
    align-items: center;
    gap: 6px;
    padding: 4px;
    min-height: 40px;
    box-sizing: border-box;
}

html:not([data-sidebar-collapsed="true"]) .sidebar__body {
    padding: 0 18px 16px;
}

html:not([data-sidebar-collapsed="true"]) .sidebar__nav {
    gap: 2px;
}

html:not([data-sidebar-collapsed="true"]) .sidebar__section {
    margin: 0;
    padding: 0;
    border: 0;
    gap: 0;
}

html:not([data-sidebar-collapsed="true"]) .sidebar__section + .sidebar__section::before {
    display: none;
}

/* Divisor entre cada grupo: Trabalho | IA | Operação | Social | Admin. */
html:not([data-sidebar-collapsed="true"]) .sidebar__section + .sidebar__section {
    margin-top: 8px;
    padding-top: 10px;
    border-top: 1px solid color-mix(in srgb, var(--line) 48%, transparent);
}

html:not([data-sidebar-collapsed="true"]) .sidebar__menu {
    gap: 2px;
    margin: 0;
    padding: 0;
}

html:not([data-sidebar-collapsed="true"]) .sidebar__link {
    display: flex;
    align-items: center;
    gap: 10px;
    height: auto;
    min-height: 32px;
    padding: 6px 10px;
    box-sizing: border-box;
    font-size: 12.5px;
    font-weight: 400;
    line-height: 18px;
    border-radius: 8px;
}

html:not([data-sidebar-collapsed="true"]) .sidebar__link-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 20px;
    width: 20px;
    height: 20px;
}

html:not([data-sidebar-collapsed="true"]) .sidebar__link-icon svg {
    display: block;
    width: 16px;
    height: 16px;
}

html:not([data-sidebar-collapsed="true"]) .sidebar__footer {
    padding: 12px 18px 16px;
}

html:not([data-sidebar-collapsed="true"]) .sidebar__profile {
    gap: 10px;
    padding: 4px 6px;
    border: 0;
    box-sizing: border-box;
}

html:not([data-sidebar-collapsed="true"]) .sidebar__avatar {
    flex: 0 0 26px;
    width: 26px;
    height: 26px;
}

/* Compact rail — Magnific: one center axis, equal hits, solid CTA. */
@media (min-width: 769px) {
    html[data-sidebar-collapsed="true"] .sidebar {
        --sidebar-collapsed-hit: 36px;
        width: 56px;
        overflow: hidden;
    }

    html[data-sidebar-collapsed="true"] .sidebar__inner {
        align-items: center;
        width: 100%;
    }

    html[data-sidebar-collapsed="true"] .sidebar__header {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
        gap: 0;
        width: 100%;
        height: auto;
        min-height: 0;
        padding: 12px 0 8px;
        border-bottom: 0;
    }

    html[data-sidebar-collapsed="true"] .sidebar__brand,
    html[data-sidebar-collapsed="true"] .sidebar__toolbar {
        display: flex;
        align-items: center;
        justify-content: center;
        flex: 0 0 auto;
        width: 100%;
        margin: 0;
        padding: 0;
    }

    /* The logo replaces the separate expand control in compact mode. */
    html[data-sidebar-collapsed="true"] .sidebar__toolbar {
        display: none;
    }

    html[data-sidebar-collapsed="true"] .sidebar__brand {
        cursor: pointer;
        border-radius: 10px;
    }

    html[data-sidebar-collapsed="true"] .sidebar__brand:focus-visible {
        outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent);
        outline-offset: 2px;
    }

    html[data-sidebar-collapsed="true"] .sidebar__brand .brand {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0;
        width: auto;
        padding: 0;
        margin: 0;
    }

    html[data-sidebar-collapsed="true"] .sidebar__brand .brand-mark {
        width: 36px;
        height: 36px;
        border-radius: 10px;
    }

    html[data-sidebar-collapsed="true"] .sidebar__brand .brand-mark svg,
    html[data-sidebar-collapsed="true"] .sidebar__brand .brand-mark__logo {
        width: 20px;
        height: 20px;
    }

    html[data-sidebar-collapsed="true"] .sidebar__collapse {
        display: flex;
        align-items: center;
        justify-content: center;
        width: var(--sidebar-collapsed-hit);
        height: var(--sidebar-collapsed-hit);
        min-height: var(--sidebar-collapsed-hit);
        margin: 0;
        padding: 0;
        border-radius: 9px;
    }

    html[data-sidebar-collapsed="true"] .sidebar__primary {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        padding: 6px 0 10px;
    }

    /* Magnific: the CTA *is* the colored square, not a mark in a track. */
    html[data-sidebar-collapsed="true"] .sidebar__cta {
        display: flex;
        align-items: center;
        justify-content: center;
        flex: 0 0 32px;
        grid-template-columns: none;
        gap: 0;
        width: 32px;
        height: 32px;
        min-height: 32px;
        padding: 0;
        margin: 0;
        border: 0;
        border-radius: 9px;
        background: var(--accent);
        box-shadow: none;
        color: #fff;
    }

    html[data-sidebar-collapsed="true"] .sidebar__cta:hover {
        background: color-mix(in srgb, var(--accent) 88%, #000);
    }

    html[data-sidebar-collapsed="true"] .sidebar__cta-mark {
        display: flex;
        align-items: center;
        justify-content: center;
        flex: 0 0 auto;
        width: 18px;
        height: 18px;
        margin: 0;
        border-radius: 0;
        background: transparent;
        color: inherit;
    }

    html[data-sidebar-collapsed="true"] .sidebar__cta-mark svg {
        display: block;
        width: 14px;
        height: 14px;
    }

    html[data-sidebar-collapsed="true"] .sidebar__cta-label {
        display: none;
    }

    html[data-sidebar-collapsed="true"] .sidebar__body {
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 100%;
        padding: 0 0 8px;
        overflow: auto;
    }

    html[data-sidebar-collapsed="true"] .sidebar__nav {
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 100%;
        gap: 2px;
    }

    html[data-sidebar-collapsed="true"] .sidebar__section,
    html[data-sidebar-collapsed="true"] .sidebar__section + .sidebar__section {
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 100%;
        margin: 0;
        padding: 0;
        gap: 2px;
        border: 0;
    }

    html[data-sidebar-collapsed="true"] .sidebar__section + .sidebar__section::before {
        display: none;
    }

    html[data-sidebar-collapsed="true"] .sidebar__section + .sidebar__section {
        width: var(--sidebar-collapsed-hit);
        margin-top: 6px;
        padding-top: 10px;
        border-top: 1px solid color-mix(in srgb, var(--line) 48%, transparent);
    }

    html[data-sidebar-collapsed="true"] .sidebar__menu {
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 100%;
        gap: 2px;
        padding: 0;
        margin: 0;
    }

    html[data-sidebar-collapsed="true"] .sidebar__item {
        display: flex;
        justify-content: center;
        width: 100%;
    }

    html[data-sidebar-collapsed="true"] .sidebar__link {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: var(--sidebar-collapsed-hit) !important;
        min-height: var(--sidebar-collapsed-hit) !important;
        height: var(--sidebar-collapsed-hit) !important;
        margin: 0 auto;
        padding: 0 !important;
        gap: 0;
        box-sizing: border-box;
        border-radius: 9px;
    }

    html[data-sidebar-collapsed="true"] .sidebar__link::before {
        display: none;
    }

    html[data-sidebar-collapsed="true"] .sidebar__link-icon {
        display: flex;
        align-items: center;
        justify-content: center;
        flex: 0 0 20px;
        width: 20px;
        height: 20px;
        margin: 0;
    }

    html[data-sidebar-collapsed="true"] .sidebar__link-icon svg {
        display: block;
        width: 16px;
        height: 16px;
    }

    html[data-sidebar-collapsed="true"] .sidebar__footer {
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 100%;
        margin-top: auto;
        padding: 8px 0 12px;
        border-top: 0;
        background: transparent;
    }

    html[data-sidebar-collapsed="true"] .sidebar__profile {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        width: var(--sidebar-collapsed-hit);
        min-height: 0;
        margin: 0 auto;
        padding: 0;
        border: 0;
        border-radius: 0;
        background: transparent;
        box-shadow: none;
    }

    html[data-sidebar-collapsed="true"] .sidebar__profile:hover {
        background: transparent;
    }

    html[data-sidebar-collapsed="true"] .sidebar__quick-actions {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 2px;
        width: var(--sidebar-collapsed-hit);
    }

    html[data-sidebar-collapsed="true"] .sidebar__avatar {
        flex: 0 0 var(--sidebar-collapsed-hit);
        width: var(--sidebar-collapsed-hit);
        height: var(--sidebar-collapsed-hit);
        border-radius: 999px;
    }

    html[data-sidebar-collapsed="true"] .sidebar__theme.theme-toggle,
    html[data-sidebar-collapsed="true"] .sidebar__logout-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: var(--sidebar-collapsed-hit) !important;
        height: var(--sidebar-collapsed-hit) !important;
        min-height: var(--sidebar-collapsed-hit) !important;
        margin: 0;
        padding: 0;
        border-radius: 9px;
    }
}

@media (max-width: 768px) {
    html:not([data-sidebar-collapsed="true"]) .sidebar__link {
        min-height: 44px;
    }
}
