/* Correcoes de escopo para os painis internos.
   Mantem as classes antigas funcionando sem deixar CSS extraido de uma area
   alterar o layout de outra area. */

body[data-authenticated-role],
body.is-admin-page {
    margin: 0;
    padding: 0;
    min-height: 100vh;
    background: #f8fafc;
    color: #0f172a;
    font-family: 'Outfit', sans-serif;
    display: block;
    overflow-x: hidden;
    max-width: 100vw;
}

body[data-authenticated-role] *,
body[data-authenticated-role] *::before,
body[data-authenticated-role] *::after,
body.is-admin-page *,
body.is-admin-page *::before,
body.is-admin-page *::after {
    box-sizing: border-box;
}

body[data-authenticated-role] .admin-sidebar,
body.is-admin-page .admin-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    z-index: 1000;
    background: #0f172a;
    color: #fff;
    display: flex;
    flex-direction: column;
    padding: 32px 24px;
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    box-sizing: border-box;
}

body[data-authenticated-role] .admin-main,
body.is-admin-page .admin-main {
    min-height: 100vh;
    min-width: 0;
    max-width: 100vw;
    overflow-x: hidden;
    background: #f8fafc;
}

body[data-authenticated-role="comerciante"] .admin-main,
body[data-authenticated-role="consumidor"] .admin-main {
    margin-left: 280px;
    width: calc(100vw - 280px);
    max-width: calc(100vw - 280px);
    display: flex;
    flex-direction: column;
}

body[data-authenticated-role="motoboy"] .admin-layout,
body.is-admin-page .admin-layout {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    min-height: 100vh;
    background: #f8fafc;
}

body[data-authenticated-role="motoboy"] .admin-main,
body.is-admin-page .admin-main {
    grid-column: 2;
    margin-left: 0;
    width: 100%;
    max-width: calc(100vw - 280px);
}

body[data-authenticated-role] .admin-topbar,
body.is-admin-page .admin-topbar {
    min-height: 80px;
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid var(--line, #e2e8f0);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 40px;
    position: sticky;
    top: 0;
    z-index: 900;
    box-sizing: border-box;
    max-width: 100%;
    overflow: hidden;
}

body[data-authenticated-role] .content-shell,
body[data-authenticated-role] .admin-content-shell {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    overflow-x: hidden;
}

body[data-authenticated-role="consumidor"] .content-shell {
    padding: 32px 40px 96px;
}

body[data-authenticated-role="comerciante"] .admin-main > .pmb-csp-0226 {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    overflow-x: hidden;
}

body[data-authenticated-role="motoboy"] .admin-content-shell {
    padding: 40px;
    max-width: min(1400px, 100%);
    margin: 0 auto;
}

body[data-authenticated-role] .page-shell,
body.is-admin-page .page-shell,
body.is-admin-page .responsive-container {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

body[data-authenticated-role] .surface-card,
body[data-authenticated-role] .hero-panel,
body[data-authenticated-role] .auth-card,
body[data-authenticated-role] .stat-card-premium,
body[data-authenticated-role] .metric-card-premium,
body[data-authenticated-role] .card-premium-logistics,
body.is-admin-page .surface-card,
body.is-admin-page .hero-panel-mini,
body.is-admin-page .metric-card,
body.is-admin-page .admin-command-card {
    max-width: 100%;
    min-width: 0;
    overflow-wrap: anywhere;
}

body[data-authenticated-role] .hub-grid-main,
body[data-authenticated-role] .summary-grid,
body[data-authenticated-role] .metric-grid,
body[data-authenticated-role] .report-metric-grid,
body[data-authenticated-role] .content-grid,
body[data-authenticated-role] .grid-2,
body[data-authenticated-role] .row-2,
body[data-authenticated-role] .motoboy-stats-row,
body[data-authenticated-role] .motoboy-action-strip,
body[data-authenticated-role] .vehicle-readiness-grid,
body[data-authenticated-role] .wallet-main-grid,
body.is-admin-page .summary-grid,
body.is-admin-page .metric-grid,
body.is-admin-page .admin-command-grid {
    max-width: 100%;
    min-width: 0;
}

body[data-authenticated-role] .hub-grid-main {
    grid-template-columns: minmax(0, 1fr) minmax(280px, 340px);
}

body[data-authenticated-role] .motoboy-stats-row,
body[data-authenticated-role] .motoboy-action-strip,
body[data-authenticated-role] .vehicle-readiness-grid,
body.is-admin-page .metric-grid,
body.is-admin-page .admin-command-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
}

body[data-authenticated-role] img,
body[data-authenticated-role] video,
body[data-authenticated-role] canvas,
body[data-authenticated-role] iframe,
body.is-admin-page img,
body.is-admin-page video,
body.is-admin-page canvas,
body.is-admin-page iframe {
    max-width: 100%;
}

body[data-authenticated-role] table,
body.is-admin-page table {
    width: 100%;
    max-width: 100%;
    table-layout: fixed;
}

body[data-authenticated-role] th,
body[data-authenticated-role] td,
body.is-admin-page th,
body.is-admin-page td {
    overflow-wrap: anywhere;
    word-break: break-word;
}

body[data-authenticated-role] .compact-table-group,
body[data-authenticated-role] .table-responsive,
body[data-authenticated-role] .data-table-wrapper,
body.is-admin-page .compact-table-group,
body.is-admin-page .table-responsive,
body.is-admin-page .data-table-wrapper {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

body[data-authenticated-role] .admin-topbar > *,
body[data-authenticated-role] .consumer-topbar-right,
body[data-authenticated-role] .topbar-left,
body.is-admin-page .admin-topbar > * {
    min-width: 0;
}

body[data-authenticated-role] .admin-topbar h1,
body[data-authenticated-role] .admin-topbar h2,
body[data-authenticated-role] .admin-topbar h3,
body.is-admin-page .admin-topbar h1,
body.is-admin-page .admin-topbar h2,
body.is-admin-page .admin-topbar h3 {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

body[data-authenticated-role] .mobile-bottom-nav,
body.is-admin-page .mobile-bottom-nav {
    max-width: 100vw;
    overflow: hidden;
}

/* Abas internas: todos os paineis devem rolar apenas na vertical. */
body[data-authenticated-role] .page-shell > *,
body[data-authenticated-role] .content-shell > *,
body[data-authenticated-role] .admin-content-shell > *,
body[data-authenticated-role] .card-stack > *,
body.is-admin-page .responsive-container > * {
    max-width: 100%;
    min-width: 0;
}

body[data-authenticated-role] .d-flex,
body[data-authenticated-role] [class*="pmb-csp-0060"],
body[data-authenticated-role] [class*="pmb-csp-0421"],
body[data-authenticated-role] [class*="pmb-csp-0479"],
body.is-admin-page .d-flex {
    min-width: 0;
    flex-wrap: wrap;
}

body[data-authenticated-role] .btn,
body[data-authenticated-role] .btn-primary,
body[data-authenticated-role] .btn-secondary,
body[data-authenticated-role] .btn-ghost,
body[data-authenticated-role] .btn-premium,
body[data-authenticated-role] .btn-outline-premium,
body.is-admin-page .btn,
body.is-admin-page .btn-primary,
body.is-admin-page .btn-secondary,
body.is-admin-page .btn-ghost {
    max-width: 100%;
    min-width: 0;
    white-space: normal;
    text-align: center;
}

/* Catalogo do comerciante: renderiza apenas o modo escolhido. */
body[data-authenticated-role="comerciante"] .catalog-page {
    overflow-x: hidden;
}

body[data-authenticated-role="comerciante"] .catalog-page .mgmt-toolbar-card,
body[data-authenticated-role="comerciante"] .catalog-page .data-table-wrapper,
body[data-authenticated-role="comerciante"] .catalog-page .product-detail-grid,
body[data-authenticated-role="comerciante"] .catalog-page .product-compact-list,
body[data-authenticated-role="comerciante"] .catalog-page .product-mobile-list {
    max-width: 100%;
    min-width: 0;
}

body[data-authenticated-role="comerciante"] .catalog-page .mgmt-toolbar-card form {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

body[data-authenticated-role="comerciante"] .catalog-page .mgmt-toolbar-card form > * {
    min-width: 0;
}

body[data-authenticated-role="comerciante"] .catalog-page .mgmt-toolbar-card input,
body[data-authenticated-role="comerciante"] .catalog-page .mgmt-toolbar-card select {
    max-width: 100%;
}

body[data-authenticated-role="comerciante"] .catalog-page .data-table-wrapper,
body[data-authenticated-role="comerciante"] .catalog-page .product-detail-grid,
body[data-authenticated-role="comerciante"] .catalog-page .product-compact-list,
body[data-authenticated-role="comerciante"] .catalog-page .product-mobile-list {
    display: none;
}

body[data-authenticated-role="comerciante"] .catalog-page.catalog-view-list .data-table-wrapper {
    display: block;
}

body[data-authenticated-role="comerciante"] .catalog-page.catalog-view-detail .product-detail-grid {
    display: grid;
}

body[data-authenticated-role="comerciante"] .catalog-page.catalog-view-compact .product-compact-list {
    display: grid;
}

body[data-authenticated-role="comerciante"] .catalog-page .product-cell {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr);
    align-items: center;
    min-width: 0;
}

body[data-authenticated-role="comerciante"] .catalog-page .product-cell > div,
body[data-authenticated-role="comerciante"] .catalog-page .product-detail-card > div,
body[data-authenticated-role="comerciante"] .catalog-page .product-compact-row > div,
body[data-authenticated-role="comerciante"] .catalog-page .product-mobile-card > div {
    min-width: 0;
}

body[data-authenticated-role="comerciante"] .catalog-page .compact-table {
    table-layout: auto;
}

body[data-authenticated-role="comerciante"] .catalog-page .compact-table th,
body[data-authenticated-role="comerciante"] .catalog-page .compact-table td {
    vertical-align: middle;
}

body[data-authenticated-role="comerciante"] .catalog-page .product-detail-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
    gap: 18px;
}

body[data-authenticated-role="comerciante"] .catalog-page .product-compact-row {
    grid-template-columns: 32px minmax(0, 1fr) minmax(90px, 130px) minmax(76px, 110px);
    max-width: 100%;
}

body[data-authenticated-role="comerciante"] .catalog-page .catalog-view-switch {
    max-width: 100%;
    flex-wrap: wrap;
}

body[data-authenticated-role="comerciante"] .bulk-action-bar {
    max-width: min(760px, calc(100vw - 32px));
    left: 50%;
    right: auto;
    flex-wrap: wrap;
    justify-content: center;
}

body[data-authenticated-role="comerciante"] .product-drawer .drawer-content {
    width: min(520px, 100vw);
    max-width: 100vw;
}

body[data-authenticated-role] .sidebar-nav,
body.is-admin-page .sidebar-nav {
    min-width: 0;
}

body[data-authenticated-role] .sidebar-link,
body.is-admin-page .sidebar-link {
    width: 100%;
    box-sizing: border-box;
    text-align: left;
}

@media (max-width: 1024px) {
    body[data-authenticated-role] .admin-sidebar,
    body.is-admin-page .admin-sidebar {
        display: none;
    }

    body[data-authenticated-role="motoboy"] .admin-layout,
    body.is-admin-page .admin-layout {
        grid-template-columns: 1fr;
    }

    body[data-authenticated-role] .admin-main,
    body.is-admin-page .admin-main {
        margin-left: 0;
        grid-column: 1;
        width: 100vw;
        max-width: 100vw;
        padding-bottom: 90px;
    }

    body[data-authenticated-role] .admin-topbar,
    body.is-admin-page .admin-topbar {
        padding: 0 20px;
    }

    body[data-authenticated-role="consumidor"] .content-shell,
    body[data-authenticated-role="motoboy"] .admin-content-shell {
        padding: 24px 20px 100px;
    }

    body[data-authenticated-role] .hub-grid-main,
    body[data-authenticated-role] .summary-grid,
    body[data-authenticated-role] .grid-2,
    body[data-authenticated-role] .row-2,
    body[data-authenticated-role] .wallet-main-grid,
    body.is-admin-page .summary-grid {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    body[data-authenticated-role="comerciante"] .catalog-page.catalog-view-list .data-table-wrapper {
        display: none;
    }

    body[data-authenticated-role="comerciante"] .catalog-page .product-mobile-list {
        display: grid;
    }

    body[data-authenticated-role="comerciante"] .catalog-page.catalog-view-detail .product-detail-grid,
    body[data-authenticated-role="comerciante"] .catalog-page.catalog-view-compact .product-compact-list {
        display: none;
    }

    body[data-authenticated-role="comerciante"] .catalog-page .mgmt-toolbar-card form {
        flex-direction: column;
        align-items: stretch;
    }

    body[data-authenticated-role="comerciante"] .catalog-page .mgmt-toolbar-card form > div,
    body[data-authenticated-role="comerciante"] .catalog-page .mgmt-toolbar-card select,
    body[data-authenticated-role="comerciante"] .catalog-page .mgmt-toolbar-card button,
    body[data-authenticated-role="comerciante"] .catalog-page .catalog-view-switch {
        width: 100%;
    }

    body[data-authenticated-role="comerciante"] .catalog-page .catalog-view-switch {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    body[data-authenticated-role="comerciante"] .bulk-action-bar {
        bottom: 88px;
        width: calc(100vw - 28px);
        border-radius: 18px;
    }
}

@media (max-width: 640px) {
    body[data-authenticated-role] .admin-topbar,
    body.is-admin-page .admin-topbar {
        min-height: 72px;
        padding: 0 14px;
        gap: 10px;
    }

    body[data-authenticated-role="consumidor"] .content-shell,
    body[data-authenticated-role="motoboy"] .admin-content-shell {
        padding: 18px 14px 96px;
    }

    body[data-authenticated-role] .surface-card,
    body.is-admin-page .surface-card {
        padding: 20px;
        border-radius: 18px;
    }
}
