/* ============================================================
   RESET & BASE
   ============================================================ */

html,
body {
    padding-top: 35px;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

.router-link {
    color: #333;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

a {
    text-decoration: none;
    color: inherit;
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
::-webkit-scrollbar-track {
    background: #e9edf3;
}
::-webkit-scrollbar-thumb {
    background: #b6c4d8;
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: #94a8c2;
}

/* ============================================================
   TOPBAR FIXA (lado a lado com a sidebar no desktop)
   ============================================================ */
.topbar-fixed {
    position: fixed;
    top: 0;
    left: 180px;
    /* mesma largura da sidebar */
    right: 0;
    z-index: 1040;
    background: #ffffff;
    border-bottom: 1px solid #eef2f6;
    padding: 0.5rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: nowrap;
    min-height: 64px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.02);
    transition: left 0.3s ease, width 0.3s ease;
}

.sidebar-collapsed .topbar-fixed {
    left: 0;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
    flex-shrink: 1;
}

.topbar-left .page-title {
    font-weight: 700;
    font-size: 1rem;
    color: #0f172a;
    letter-spacing: -0.2px;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
    transition: max-width 0.2s ease;
    flex-shrink: 2;
}

.topbar-left .page-title small {
    font-weight: 400;
    font-size: 0.6rem;
    color: #94a3b8;
    margin-left: 0.3rem;
}

.toggle-sidebar-btn {
    border: none;
    background: transparent;
    color: #475569;
    font-size: 1rem;
    padding: 0.2rem 0.3rem;
    border-radius: 8px;
    transition: background 0.15s, color 0.15s;
    cursor: pointer;
    line-height: 1;
    flex-shrink: 0;
}
.toggle-sidebar-btn:hover {
    background: #f1f5f9;
    color: #0f172a;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
    flex-shrink: 1;
    justify-content: flex-end;
}

.topbar-icon {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: #fff;
    border: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #475569;
    font-size: 0.75rem;
    transition: all 0.15s;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
}
.topbar-icon:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
    color: #0f172a;
}
.topbar-icon .dot {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 6px;
    height: 6px;
    background: #ef4444;
    border-radius: 50%;
    border: 2px solid #fff;
}

.topbar-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #e9edf3;
    cursor: pointer;
    transition: border 0.15s;
    flex-shrink: 0;
}
.topbar-avatar:hover {
    border-color: #6366f1;
}

.hamburger-btn {
    border: none;
    background: transparent;
    color: #1e293b;
    font-size: 1.1rem;
    padding: 0.2rem 0.3rem;
    border-radius: 8px;
    transition: background 0.15s;
    flex-shrink: 0;
}
.hamburger-btn:hover {
    background: #f1f5f9;
}

/* ============================================================
   WRAPPER
   ============================================================ */
/* .wrapper {
    display: flex;
    width: 100%;
    min-height: calc(100vh - 64px);
    overflow-x: hidden;
} */

/* ============================================================
   SIDEBAR (offcanvas-lg) – fixa no topo (desktop)
   ============================================================ */
.sidebar-offcanvas {
    background: #ffffff;
    border-right: 1px solid #eef2f6;
    transition: width 0.3s ease, min-width 0.3s ease, padding 0.3s ease, transform 0.3s ease;
    overflow: hidden;
}

.sidebar-offcanvas {
    --bs-offcanvas-width: 120px;
    /* largura adequada para mobile */
}

/* ===========================================
   OFFCANVAS MOBILE
=========================================== */

@media (max-width: 991.98px) {
    .sidebar-offcanvas {
        --bs-offcanvas-width: 280px;
        max-width: 85vw;
    }

    .topbar-fixed {
        left: 0 !important;
        width: 100%;
        max-width: 100%;
        padding: .45rem .9rem;
        min-height: 60px;
    }

    .main-content {
        flex: 1 1 auto;
        margin-left: 0 !important;
        min-width: 0;
        width: auto;
        padding: 1rem;
        overflow-x: clip; /* ou hidden */
    }

    .container,
    .container-fluid {
        width: 100%;
        max-width: 100%;
        padding-left: .75rem;
        padding-right: .75rem;
    }

    .row {
        --bs-gutter-x: 1rem;
        margin-left: 0;
        margin-right: 0;
    }

    .sidebar-offcanvas .offcanvas-header {
        padding: 1rem;
        border-bottom: 1px solid #eef2f6;
    }

    .sidebar-offcanvas .offcanvas-body {
        padding: .75rem;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .sidebar-offcanvas .sidebar-footer {
        margin-top: auto;
        padding-top: 1rem;
        border-top: 1px solid #eef2f6;
    }

    /* evita regras do desktop quando colapsado */
    .sidebar-collapsed .sidebar-offcanvas {
        width: auto !important;
        min-width: auto !important;
        padding: inherit !important;
        border-right: none !important;
        overflow: visible !important;
    }

    .sidebar-collapsed .sidebar-offcanvas .sidebar-brand,
    .sidebar-collapsed .sidebar-offcanvas .sidebar-nav,
    .sidebar-collapsed .sidebar-offcanvas .sidebar-footer {
        display: flex !important;
    }
}

/* ===========================================
   DESKTOP
=========================================== */

@media (min-width: 992px) {
    .sidebar-offcanvas {
        position: fixed;
        top: 0;
        left: 0;
        width: 180px;
        min-width: 180px;
        height: 100vh;
        transform: none !important;
        visibility: visible !important;
        display: flex;
        flex-direction: column;
        background: #fff;
        border-right: 1px solid #eef2f6;
        overflow-y: auto;
        overflow-x: hidden;
        z-index: 1030;
    }

    .sidebar-collapsed .sidebar-offcanvas {
        width: 0 !important;
        min-width: 0 !important;
        padding: 0 !important;
        border-right: none;
        overflow: hidden;
    }

    .sidebar-collapsed .sidebar-offcanvas .sidebar-brand,
    .sidebar-collapsed .sidebar-offcanvas .sidebar-nav,
    .sidebar-collapsed .sidebar-offcanvas .sidebar-footer {
        display: none;
    }

    .main-content {
        margin-left: 180px;
        flex: 1 1 auto;          /* CORREÇÃO: usa flex em vez de largura fixa */
        width: auto;             /* CORREÇÃO: evita calc() que causava overflow */
        min-width: 0;
        max-width: 100%;
        padding: 1.25rem;
        overflow-x: hidden;      /* CORREÇÃO: previne vazamento horizontal */
        transition: margin-left .3s ease;
    }

    .sidebar-collapsed .main-content {
        margin-left: 0;
        /* width: 100% não é necessário pois flex:1 já ocupa todo o espaço */
    }

    .sidebar-offcanvas .offcanvas-header {
        display: none !important;
    }

    .sidebar-offcanvas .offcanvas-body {
        padding: 10px;
        flex: 1;
        display: flex;
        flex-direction: column;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .offcanvas-backdrop {
        display: none !important;
    }
}

/* ===========================================
   ELEMENTOS RESPONSIVOS (reforço contra overflow)
=========================================== */

.container,
.container-fluid,
.row {
    max-width: 100%;
    padding-left: calc(var(--bs-gutter-x) * 0.5);
    padding-right: calc(var(--bs-gutter-x) * 0.5);
}

.row {
    --bs-gutter-x: 1rem;
    margin-left: 0;
    margin-right: 0;
}

img,
table,
.card,
canvas,
svg,
iframe {
    max-width: 100%;
}

.table-responsive {
    overflow-x: auto;
}

.card {
    min-width: 0;
}

.d-flex {
    min-width: 0;
}

.flex-grow-1 {
    min-width: 0;
}

.col,
[class*="col-"] {
    min-width: 0;
    word-break: break-word; /* quebra palavras longas */
}

pre,
code {
    white-space: pre-wrap;
    word-break: break-word;
}

/* ============================================================
   SIDEBAR NAV (compacta)
   ============================================================ */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0 0.3rem 1.2rem 0.3rem;
    border-bottom: 1px solid #f0f4fa;
    margin-bottom: 1rem;
}
.sidebar-brand .brand-icon {
    width: 30px;
    height: 30px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 0.95rem;
    font-weight: 700;
    flex-shrink: 0;
}
.sidebar-brand span {
    font-weight: 700;
    font-size: 0.9rem;
    letter-spacing: -0.2px;
    color: #0f172a;
}
.sidebar-brand small {
    font-weight: 400;
    font-size: 0.55rem;
    color: #94a3b8;
    letter-spacing: 0.2px;
    text-transform: uppercase;
}

.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
}
.sidebar-nav .nav-label {
    font-size: 0.55rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #94a3b8;
    padding: 0.6rem 0.3rem 0.3rem 0.3rem;
    font-weight: 600;
}

.sidebar-nav .nav-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0.5rem;
    border-radius: 8px;
    color: #475569;
    font-weight: 500;
    font-size: 0.75rem;
    transition: all 0.15s ease;
    cursor: pointer;
    margin-bottom: 1px;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    flex-shrink: 0;
    word-break: break-word;
    overflow-wrap: break-word;
}
.sidebar-nav .nav-item i {
    width: 16px;
    font-size: 0.8rem;
    text-align: center;
    color: #94a3b8;
    transition: color 0.15s;
    flex-shrink: 0;
}
.sidebar-nav .nav-item:hover {
    background: #f1f5f9;
    color: #0f172a;
}
.sidebar-nav .nav-item:hover i {
    color: #6366f1;
}
.sidebar-nav .nav-item.active {
    background: #eef2ff;
    color: #4f46e5;
    font-weight: 600;
}
.sidebar-nav .nav-item.active i {
    color: #4f46e5;
}
.sidebar-nav .nav-item .badge {
    margin-left: auto;
    font-size: 0.55rem;
    padding: 0.15rem 0.4rem;
    border-radius: 30px;
    font-weight: 600;
    background: #eef2ff;
    color: #4f46e5;
    flex-shrink: 0;
}
.sidebar-nav .nav-item .chevron {
    margin-left: auto;
    font-size: 0.55rem;
    transition: transform 0.25s ease;
    color: #94a3b8;
    flex-shrink: 0;
}
.sidebar-nav .nav-item[aria-expanded="true"] .chevron {
    transform: rotate(180deg);
}

.nav-sub-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.5rem 0.35rem 2rem;
    border-radius: 6px;
    color: #475569;
    font-size: 0.7rem;
    font-weight: 400;
    transition: all 0.15s;
    cursor: pointer;
    margin-bottom: 1px;
    width: 100%;
    word-break: break-word;
    overflow-wrap: break-word;
}
.nav-sub-item i {
    width: 14px;
    font-size: 0.65rem;
    color: #94a3b8;
    flex-shrink: 0;
}
.nav-sub-item:hover {
    background: #f1f5f9;
    color: #0f172a;
}
.nav-sub-item.active-sub {
    background: #f1f5f9;
    color: #4f46e5;
    font-weight: 500;
}
.nav-sub-item.active-sub i {
    color: #4f46e5;
}

.collapse-sub {
    padding-left: 0.2rem;
    margin-bottom: 0.2rem;
}

.sidebar-footer {
    border-top: 1px solid #f0f4fa;
    padding-top: 0.8rem;
    margin-top: 0.5rem;
}
.sidebar-footer .user-card {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0.3rem;
    border-radius: 8px;
    transition: background 0.15s;
    cursor: pointer;
}
.sidebar-footer .user-card:hover {
    background: #f1f5f9;
}
.sidebar-footer .user-card img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #e9edf3;
    flex-shrink: 0;
}
.sidebar-footer .user-card .user-info {
    flex: 1;
    min-width: 0;
}
.sidebar-footer .user-card .user-info .name {
    font-weight: 600;
    font-size: 0.75rem;
    color: #0f172a;
}
.sidebar-footer .user-card .user-info .role {
    font-size: 0.6rem;
    color: #94a3b8;
}

/* ============================================================
   CARDS, TABELAS (mantido)
   ============================================================ */
.card-premium {
    background: #ffffff;
    border: none;
    border-radius: 14px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03), 0 4px 12px rgba(0, 0, 0, 0.04);
    transition: box-shadow 0.2s ease, transform 0.15s ease;
    height: 100%;
}
.card-premium:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
}
.card-premium .card-body {
    padding: 0.9rem 1rem;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.stat-card .stat-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}
.stat-card .stat-icon.purple {
    background: #eef2ff;
    color: #6366f1;
}
.stat-card .stat-icon.green {
    background: #ecfdf5;
    color: #10b981;
}
.stat-card .stat-icon.orange {
    background: #fffbeb;
    color: #f59e0b;
}
.stat-card .stat-icon.blue {
    background: #eff6ff;
    color: #3b82f6;
}
.stat-card .stat-content {
    flex: 1;
    min-width: 0;
}
.stat-card .stat-content .stat-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: #94a3b8;
    font-weight: 600;
}
.stat-card .stat-content .stat-value {
    font-weight: 700;
    font-size: 1.15rem;
    color: #0f172a;
    line-height: 1.2;
}
.stat-card .stat-content .stat-change {
    font-size: 0.6rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 0.1rem 0.4rem;
    border-radius: 30px;
    background: #ecfdf5;
    color: #10b981;
}
.stat-card .stat-content .stat-change.down {
    background: #fef2f2;
    color: #ef4444;
}

.table-premium {
    font-size: 0.75rem;
}
.table-premium thead th {
    background: #f8fafc;
    color: #475569;
    font-weight: 600;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    border-bottom: 1px solid #e9edf3;
    padding: 0.5rem 0.6rem;
}
.table-premium tbody td {
    padding: 0.5rem 0.6rem;
    vertical-align: middle;
    border-bottom: 1px solid #f1f5f9;
    color: #1e293b;
}
.table-premium tbody tr:hover {
    background: #fafcff;
}
.badge-status {
    font-size: 0.6rem;
    font-weight: 600;
    padding: 0.2rem 0.6rem;
    border-radius: 30px;
}
.badge-status.success {
    background: #ecfdf5;
    color: #10b981;
}
.badge-status.warning {
    background: #fffbeb;
    color: #f59e0b;
}
.badge-status.danger {
    background: #fef2f2;
    color: #ef4444;
}
.badge-status.info {
    background: #eff6ff;
    color: #3b82f6;
}
.avatar-group {
    display: flex;
    align-items: center;
}
.avatar-group .avatar-item {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid #fff;
    margin-right: -6px;
    object-fit: cover;
}
.avatar-group .avatar-more {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #e9edf3;
    border: 2px solid #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.5rem;
    font-weight: 700;
    color: #475569;
}
.activity-item {
    display: flex;
    gap: 0.7rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid #f1f5f9;
}
.activity-item:last-child {
    border-bottom: none;
}
.activity-item .activity-icon {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: #f1f5f9;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    color: #475569;
    flex-shrink: 0;
}
.activity-item .activity-icon.purple {
    background: #eef2ff;
    color: #6366f1;
}
.activity-item .activity-icon.green {
    background: #ecfdf5;
    color: #10b981;
}
.activity-item .activity-icon.orange {
    background: #fffbeb;
    color: #f59e0b;
}
.activity-item .activity-icon.blue {
    background: #eff6ff;
    color: #3b82f6;
}
.activity-item .activity-text {
    flex: 1;
    font-size: 0.75rem;
    color: #1e293b;
}
.activity-item .activity-text strong {
    font-weight: 600;
    color: #0f172a;
}
.activity-item .activity-text .time {
    display: block;
    font-size: 0.6rem;
    color: #94a3b8;
    margin-top: 1px;
}

.progress-sm {
    height: 4px;
    border-radius: 10px;
    background: #e9edf3;
    width: 100%;
}
.progress-sm .progress-bar {
    height: 4px;
    border-radius: 10px;
    background: linear-gradient(90deg, #6366f1, #8b5cf6);
}

.fs-extra-small {
    font-size: 0.6rem;
}
.inline-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-right: 4px;
}
.inline-dot.green {
    background: #10b981;
}
.inline-dot.yellow {
    background: #f59e0b;
}
.inline-dot.red {
    background: #ef4444;
}
.inline-dot.blue {
    background: #3b82f6;
}

/* ============================================================
   RESPONSIVE AJUSTES
   ============================================================ */

@media (max-width: 1200px) {
    .topbar-left .page-title {
        font-size: 0.85rem;
        max-width: 120px;
    }
    .topbar-left .page-title small {
        display: none;
    }
    .topbar-fixed {
        padding: 0.5rem 0.8rem;
    }
}

@media (max-width: 992px) {
    .topbar-fixed {
        left: 0 !important;
        padding: 0.4rem 0.8rem;
        min-height: 60px;
    }
    .topbar-left .page-title small {
        display: none;
    }
    .main-content {
        padding: 1rem 0.75rem;
    }
    body {
        padding-top: 60px;
    }
    .sidebar-collapsed .main-content {
        margin-left: 0 !important;
    }
}

@media (max-width: 768px) {
    .topbar-fixed {
        padding: 0.4rem 0.5rem;
        gap: 0.4rem;
    }
    .topbar-icon {
        width: 26px;
        height: 26px;
        font-size: 0.65rem;
    }
    .topbar-avatar {
        width: 26px;
        height: 26px;
    }
    .topbar-left .page-title {
        font-size: 0.75rem;
        max-width: 90px;
    }
    .stat-card .stat-content .stat-value {
        font-size: 1rem;
    }
    .main-content {
        padding: 0.75rem 0.5rem;
    }
}

@media (max-width: 480px) {
    .topbar-icon {
        width: 22px;
        height: 22px;
        font-size: 0.55rem;
    }
    .topbar-avatar {
        width: 22px;
        height: 22px;
    }
    .topbar-left .page-title {
        font-size: 0.65rem;
        max-width: 60px;
    }
}

/* CORREÇÃO PARA MOBILE – manter empilhamento sem forçar largura fixa */
@media (max-width: 991.98px) {
    .sidebar-offcanvas .offcanvas-body .sidebar-nav {
        flex-direction: column;
        /* removido width:100% e display:flex forçados, o Bootstrap já faz */
    }
    /* Não force display:flex nos itens, pois o offcanvas já gerencia */
}