/* =============================================
   NUVSHOP - CSS PRINCIPAL
   ============================================= */

:root {
    --primary:      #4f46e5;
    --primary-dark: #4338ca;
    --primary-rgb:  79, 70, 229;
    --sidebar-w:    260px;
    --sidebar-collapsed-w: 68px;
    --topbar-h:     62px;
    --transition:   .22s ease;
    --radius:       .75rem;
    --radius-sm:    .5rem;
    --shadow:       0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
    --shadow-md:    0 4px 24px rgba(0,0,0,.12);
}

* { box-sizing: border-box; }

/* html + body: impede scroll horizontal em qualquer navegador mobile */
html { overflow-x: hidden; }

body {
    font-family: 'Inter', sans-serif;
    font-size:   .875rem;
    line-height: 1.6;
    overflow-x:  hidden;
}

/* =============================================
   AUTH (login / cadastro)
   ============================================= */

.login-body {
    background: linear-gradient(135deg, #4f46e5 0%, #0f172a 100%);
    min-height: 100vh;
    position:   relative;
}

.login-overlay {
    position:   fixed;
    inset:      0;
    background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.04'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    pointer-events: none;
}

.login-card {
    background:    #fff;
    border-radius: 1rem;
    padding:       2.5rem 2rem;
    width:         100%;
    max-width:     420px;
    position:      relative;
    z-index:       10;
    box-shadow:    0 20px 60px rgba(0,0,0,.3);
    margin:        0 auto;
}

.login-logo i { font-size: 3.5rem; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(24px); }
    to   { opacity: 1; transform: translateY(0);    }
}
.animate-fade-in { animation: fadeIn .45s ease forwards; }

/* =============================================
   LAYOUT DO PAINEL
   ============================================= */

.painel-wrapper {
    display:    flex;
    min-height: 100vh;
}

/* =============================================
   SIDEBAR
   ============================================= */

.sidebar {
    width:      var(--sidebar-w);
    height:     100vh;
    position:   fixed;
    left:       0;
    top:        0;
    z-index:    100;
    transition: width var(--transition), transform var(--transition);
    overflow:   hidden;
    display:    flex;
    flex-direction: column;
}

.sidebar-brand {
    padding:     1.125rem 1.25rem;
    font-weight: 700;
    font-size:   1.1rem;
    display:     flex;
    align-items: center;
    gap:         .625rem;
    white-space: nowrap;
    letter-spacing: -.01em;
}

.sidebar-brand i { font-size: 1.4rem; }

/* User info */
.sidebar-user {
    display:     flex;
    align-items: center;
    gap:         .75rem;
    padding:     .875rem 1.25rem;
    margin:      0 .75rem .25rem;
    border-radius: var(--radius-sm);
    white-space: nowrap;
    overflow:    hidden;
}

.sidebar-user-avatar {
    font-size:   1.6rem;
    opacity:     .7;
    flex-shrink: 0;
}

.sidebar-user-info {
    display:        flex;
    flex-direction: column;
    gap:            .2rem;
    overflow:       hidden;
    min-width:      0;
}

.sidebar-user-name {
    font-size:   .8rem;
    font-weight: 600;
    white-space: nowrap;
    overflow:    hidden;
    text-overflow: ellipsis;
    opacity:     .9;
}

.badge-nivel {
    font-size:    .65rem;
    align-self:   flex-start;
    font-weight:  600;
    padding:      .15em .5em;
    border-radius: 999px;
}

/* Menu list */
.sidebar-menu {
    flex:       1;
    padding:    .5rem 0 1rem;
    overflow-y: auto;
    overflow-x: hidden;
    list-style: none;
    margin:     0;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.sidebar-menu::-webkit-scrollbar { display: none; }

/* Section labels */
.sidebar-section-label {
    padding:     1rem 1.25rem .25rem;
    white-space: nowrap;
}

.sidebar-section-label span {
    font-size:      .65rem;
    font-weight:    700;
    letter-spacing: .08em;
    text-transform: uppercase;
    opacity:        .4;
}

/* Divider */
.sidebar-divider {
    height:  1px;
    margin:  .5rem .75rem;
}

/* Menu links */
.sidebar-menu li a {
    display:        flex;
    align-items:    center;
    gap:            .75rem;
    padding:        .6rem 1rem .6rem 1.25rem;
    margin:         .1rem .625rem;
    font-size:      .835rem;
    font-weight:    500;
    text-decoration: none;
    white-space:    nowrap;
    border-radius:  var(--radius-sm);
    transition:     background var(--transition), color var(--transition), transform var(--transition);
}

.sidebar-menu li a i {
    font-size:  1.05rem;
    min-width:  20px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-menu li a.active,
.sidebar-menu li a:hover {
    transform: translateX(2px);
}

.sidebar-link-sair { opacity: .7; }
.sidebar-link-sair:hover { opacity: 1; }

/* =============================================
   OVERLAY — SIDEBAR MOBILE
   ============================================= */

.sidebar-overlay {
    display:          none;
    position:         fixed;
    inset:            0;
    background:       rgba(0, 0, 0, .45);
    z-index:          1040;
    backdrop-filter:  blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.sidebar-overlay.active { display: block; }

/* Collapsed sidebar */
.sidebar-collapsed .sidebar { width: var(--sidebar-collapsed-w); }
.sidebar-collapsed .sidebar .sidebar-brand span,
.sidebar-collapsed .sidebar .sidebar-user-info,
.sidebar-collapsed .sidebar .sidebar-section-label span,
.sidebar-collapsed .sidebar .sidebar-menu li a span { display: none; }
.sidebar-collapsed .sidebar .sidebar-brand { justify-content: center; padding: 1.125rem .5rem; }
.sidebar-collapsed .sidebar .sidebar-user  { justify-content: center; padding: .875rem .5rem; margin: 0 .25rem .25rem; }
.sidebar-collapsed .sidebar .sidebar-menu li a { justify-content: center; padding: .7rem; margin: .1rem .375rem; }
.sidebar-collapsed .sidebar .sidebar-section-label { padding: .875rem .5rem .25rem; }
.sidebar-collapsed .sidebar .sidebar-divider { margin: .5rem .375rem; }

/* =============================================
   TOPBAR
   ============================================= */

.topbar {
    position:    fixed;
    top:         0;
    left:        var(--sidebar-w);
    right:       0;
    height:      var(--topbar-h);
    z-index:     99;
    display:     flex;
    align-items: center;
    padding:     0 1.5rem;
    gap:         .875rem;
    transition:  left var(--transition);
}

.sidebar-collapsed .topbar { left: var(--sidebar-collapsed-w); }

.topbar-toggle {
    background: none;
    border:     none;
    font-size:  1.25rem;
    cursor:     pointer;
    padding:    .35rem .5rem;
    border-radius: var(--radius-sm);
    transition: background var(--transition);
}

.topbar-spacer { flex: 1; }

/* =============================================
   CONTEÚDO PRINCIPAL
   ============================================= */

.painel-content {
    margin-left: var(--sidebar-w);
    margin-top:  var(--topbar-h);
    padding:     1.75rem 2rem;
    min-height:  calc(100vh - var(--topbar-h));
    transition:  margin-left var(--transition);
}

.sidebar-collapsed .painel-content { margin-left: var(--sidebar-collapsed-w); }

/* =============================================
   CARDS DE ESTATÍSTICA
   ============================================= */

.card-stat {
    border:        none;
    border-radius: var(--radius);
    box-shadow:    var(--shadow);
    padding:       1.375rem 1.5rem;
    transition:    transform var(--transition), box-shadow var(--transition);
    position:      relative;
    overflow:      hidden;
}

.card-stat::before {
    content:       '';
    position:      absolute;
    top:           0;
    left:          0;
    right:         0;
    height:        3px;
    background:    linear-gradient(90deg, rgba(var(--primary-rgb),.6), rgba(var(--primary-rgb),.2));
    opacity:       0;
    transition:    opacity var(--transition);
}

.card-stat:hover {
    transform:  translateY(-3px);
    box-shadow: var(--shadow-md);
}

.card-stat:hover::before { opacity: 1; }

.card-stat .stat-icon {
    width:         52px;
    height:        52px;
    border-radius: .625rem;
    display:       flex;
    align-items:   center;
    justify-content: center;
    font-size:     1.4rem;
    flex-shrink:   0;
}

.card-stat .stat-value {
    font-size:   1.75rem;
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: -.02em;
}

/* =============================================
   CABEÇALHOS DE PÁGINA
   ============================================= */

.page-header {
    display:     flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap:   wrap;
    gap:         .75rem;
    margin-bottom: 1.5rem;
}

.page-header-title h4 {
    font-weight:    700;
    margin-bottom:  .125rem;
    letter-spacing: -.02em;
}

/* =============================================
   TABELAS / CARDS DE LISTAGEM
   ============================================= */

.card {
    border-radius: var(--radius) !important;
    box-shadow: var(--shadow);
}

.table th {
    font-size:      .75rem;
    font-weight:    600;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.table td { vertical-align: middle; }

/* =============================================
   FORMULÁRIOS
   ============================================= */

.form-control,
.form-select {
    border-radius: var(--radius-sm);
    font-size:     .875rem;
    transition:    border-color var(--transition), box-shadow var(--transition);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--primary);
    box-shadow:   0 0 0 .2rem rgba(var(--primary-rgb), .15);
}

.form-label {
    font-size:   .8rem;
    font-weight: 600;
    margin-bottom: .35rem;
}

/* =============================================
   BOTÕES
   ============================================= */

.btn {
    border-radius: var(--radius-sm);
    font-weight:   500;
    font-size:     .855rem;
}

.btn-primary {
    background:   var(--primary);
    border-color: var(--primary);
}
.btn-primary:hover {
    background:   var(--primary-dark);
    border-color: var(--primary-dark);
}

/* =============================================
   MODAIS
   ============================================= */

.modal-content {
    border-radius: var(--radius) !important;
    border: none !important;
    box-shadow: 0 20px 60px rgba(0,0,0,.2);
}

.modal-header {
    border-bottom-width: 1px;
    padding: 1.125rem 1.5rem;
}

.modal-footer {
    border-top-width: 1px;
    padding: .875rem 1.5rem;
}

/* =============================================
   RESPONSIVIDADE
   ============================================= */

/* ---- Tablet / Mobile (≤ 768px) ---- */
@media (max-width: 768px) {

    /* Sidebar: oculta por padrão, desliza com sidebar-open */
    .sidebar {
        transform:  translateX(-100%);
        z-index:    1050;
        box-shadow: none;
    }
    .sidebar.sidebar-open {
        transform:  translateX(0);
        box-shadow: 8px 0 32px rgba(0,0,0,.35);
    }

    /* Garante topbar e conteúdo sempre em largura total */
    .topbar,
    .sidebar-collapsed .topbar           { left: 0 !important; }
    .painel-content,
    .sidebar-collapsed .painel-content   { margin-left: 0 !important; padding: 1rem 1rem; overflow-x: hidden; max-width: 100vw; }

    /* Login card: padding menor em telas menores */
    .login-card { padding: 1.75rem 1.25rem; }

    /* Modais: remove margem lateral excessiva */
    .modal-dialog { margin: .5rem auto; }

    /* Modal body scrollável para formulários longos */
    .modal-body {
        max-height:  calc(100dvh - 200px);
        overflow-y:  auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Contenção de overflow: rows e filhos não escapam do painel */
    .painel-content .row { max-width: 100%; }
    .painel-content > * { max-width: 100%; }

    /* DataTables: scrollável horizontalmente */
    .dataTables_wrapper { overflow-x: auto; }

    /* DataTables: controls em linha */
    .dataTables_length,
    .dataTables_filter { margin-bottom: .5rem; }

    /* Botões de ação da página: empilham no mobile */
    .d-flex.gap-2.flex-wrap .btn { flex: 1 1 auto; }

    /* Painel empresa: oculta a topbar (tema/perfil migram para o drawer) e
       elimina a margem superior do conteúdo. Escopado para não afetar
       super-admin / cliente, que continuam usando a topbar + hambúrguer. */
    .has-bottom-nav .topbar { display: none !important; }
    .has-bottom-nav .painel-content {
        margin-top:  0 !important;
        padding-top: calc(1rem + env(safe-area-inset-top, 0px));
    }

    /* Touch targets mínimos */
    .btn { min-height: 38px; }
    .btn-sm { min-height: 32px; }

    /* Espaço extra no final do conteúdo para não sobrepor o bottom nav */
    .painel-content {
        padding-bottom: calc(62px + 1rem + env(safe-area-inset-bottom, 0px)) !important;
    }

    /* Toast notifications: sobe acima do bottom nav */
    .toast-container.position-fixed.bottom-0,
    [style*="z-index:9999"].position-fixed.bottom-0 { bottom: 70px !important; }
}

/* ---- Celular pequeno (≤ 576px) ---- */
@media (max-width: 576px) {

    /* Conteúdo: padding ainda menor */
    .painel-content { padding: .75rem !important; }

    /* Login card: ocupa quase tela inteira */
    .login-card { padding: 1.5rem 1rem; max-width: 100%; }

    /* Cabeçalho de página: empilha título e botão */
    .d-flex.align-items-center.justify-content-between.mb-4 {
        flex-direction: column;
        align-items:    flex-start !important;
    }
    .d-flex.align-items-center.justify-content-between.mb-4 > .btn,
    .d-flex.align-items-center.justify-content-between.mb-4 > a.btn { width: 100%; }

    /* ══════════════════════════════════════════
       STAT / KPI CARDS — 2 por linha, compactos
       ══════════════════════════════════════════ */

    /* Padding interno enxuto e altura mínima consistente */
    .card-body { padding: .7rem .65rem !important; }
    .ped-stat, .frete-stat { padding: .7rem .8rem !important; }

    /* Valores numéricos (todas as variações usadas no sistema) */
    .stat-num,
    .ped-stat  .stat-num,
    .frete-stat .stat-num { font-size: 1.05rem !important; }

    .card-body .fs-4.fw-bold, .card-body .fs-4 { font-size: 1rem  !important; }
    .card-body .fs-5.fw-bold, .card-body .fs-5 { font-size: .9rem !important; }

    /* Valores com inline style font-size:1.4rem (dashboard gradiente) */
    .card-body .fw-bold[style*="font-size:1.4rem"],
    .card-body .fw-bold[style*="font-size: 1.4rem"] { font-size: 1.05rem !important; }

    /* Rótulos (labels) dos cards — menores e com line-height curto */
    .card.text-center .text-muted.small,
    .ped-stat .stat-lbl,
    .frete-stat .stat-lbl,
    .card-body .small.opacity-80 { font-size: .64rem !important; line-height: 1.2; }

    /* Relatórios: valor/label dos KPIs coloridos */
    .kpi-value { font-size: 1.05rem !important; }
    .kpi-label { font-size: .6rem !important; }
    .kpi-sub   { font-size: .62rem !important; }
    .rel-kpi-card { padding: .75rem .85rem !important; }

    /* ── CARDS COM ÍCONE LATERAL (despesas, dashboard secundário) ── */
    .card-body .d-flex.align-items-center.gap-3 { gap: .45rem !important; }

    /* Ícones inline-style de 40–44px → 32px para caber no col-6 */
    .card-body .d-flex.align-items-center.gap-3 > div:first-child[style*="width:40px"],
    .card-body .d-flex.align-items-center.gap-3 > div:first-child[style*="width:44px"],
    .card-body .d-flex.align-items-center.gap-3 > div:first-child[style*="width: 40px"],
    .card-body .d-flex.align-items-center.gap-3 > div:first-child[style*="width: 44px"] {
        width:      32px !important;
        height:     32px !important;
        min-width:  32px !important;
        font-size:  .9rem !important;
        border-radius: 8px !important;
        flex-shrink: 0;
    }
    .card-body .d-flex.align-items-center.gap-3 .fw-bold.fs-6 { font-size: .8rem !important; }
    .card-body .d-flex.align-items-center.gap-3 .text-muted.small { font-size: .62rem !important; line-height: 1.2; }

    /* ── TABS / ABAS ── */
    /* Scroll horizontal forçado em todas as tabs */
    .nav-tabs {
        flex-wrap:   nowrap !important;
        overflow-x:  auto !important;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }
    .nav-tabs::-webkit-scrollbar { display: none; }
    .nav-link { white-space: nowrap; padding: .5rem .75rem; }

    /* ── FILTROS (pedidos) ── */
    #tipo-tabs .btn { font-size: .75rem; padding: .28rem .55rem; }
    #filtro-status  { max-width: 140px; }

    /* ── TABELAS ── */
    .table td, .table th { font-size: .78rem; padding: .4rem .35rem; }
    .dtr-details { font-size: .8rem; }
    .dtr-details td { padding: .25rem .5rem; }

    /* ── MODAL ── */
    .modal-dialog { margin: .25rem; max-width: calc(100vw - .5rem); }
    .modal-body   { max-height: calc(100dvh - 160px); }

    /* ── BADGES ── */
    .badge { font-size: .72rem; padding: .3em .55em; }

    /* Sidebar brand: menor */
    .sidebar-brand { font-size: .95rem; }
}

/* ---- Celular muito pequeno (≤ 400px) ---- */
@media (max-width: 400px) {
    /* padding mínimo: row g-3 usa margem negativa de 8px — padding nunca pode ser < 8px */
    .painel-content { padding: .75rem !important; }
    .card-body { padding: .6rem !important; }
    .table td, .table th { font-size: .73rem; padding: .3rem .25rem; }
}

/* =============================================
   BOTTOM NAVIGATION — MOBILE
   ============================================= */

.bottom-nav {
    display:     flex; /* visível no mobile por padrão; desktop oculta via min-width abaixo */
    position:    fixed;
    bottom:      0;
    left:        0;
    right:       0;
    z-index:     1030;
    align-items: stretch;
    border-top:  1px solid transparent;
    /* Suporte a safe-area do iPhone X+ */
    padding-bottom: env(safe-area-inset-bottom, 0px);
    height: calc(62px + env(safe-area-inset-bottom, 0px));
}

/* Oculta em desktop — declarado aqui para não conflitar com media queries acima */
@media (min-width: 769px) {
    .bottom-nav { display: none; }
}

.bottom-nav-item {
    flex:            1;
    display:         flex;
    flex-direction:  column;
    align-items:     center;
    justify-content: center;
    gap:             3px;
    text-decoration: none;
    border:          none;
    background:      none;
    padding:         0 4px;
    cursor:          pointer;
    position:        relative;
    transition:      color var(--transition), transform var(--transition);
    -webkit-tap-highlight-color: transparent;
}

/* Indicador de item ativo — linha no topo */
.bottom-nav-item.ativo::before {
    content:       '';
    position:      absolute;
    top:           0;
    left:          50%;
    transform:     translateX(-50%);
    width:         28px;
    height:        3px;
    border-radius: 0 0 4px 4px;
    background:    var(--primary);
}

/* Feedback tátil */
.bottom-nav-item:active { transform: scale(.9); }

.bottom-nav-icon {
    font-size:   1.45rem;
    line-height: 1;
    position:    relative;
    display:     flex;
    align-items: center;
    justify-content: center;
}

.bottom-nav-label {
    font-size:   .62rem;
    font-weight: 600;
    letter-spacing: .01em;
    line-height: 1;
    white-space: nowrap;
}

/* Badge de notificação (ex: pedidos pendentes) */
.bottom-nav-badge {
    position:      absolute;
    top:           -5px;
    right:         -9px;
    background:    #ef4444;
    color:         #fff;
    font-size:     .55rem;
    font-weight:   700;
    min-width:     16px;
    height:        16px;
    border-radius: 999px;
    display:       flex;
    align-items:   center;
    justify-content: center;
    padding:       0 3px;
    border:        2px solid transparent; /* preenchido pelo tema */
}

/* =============================================
   DRAWER — BLOCO "CONTA" (apenas mobile)
   ============================================= */

/* Itens Perfil/Tema migrados da topbar — só no mobile */
.sidebar-mobile-conta { display: none; }
@media (max-width: 768px) {
    .has-bottom-nav .sidebar-mobile-conta { display: block; }
}

/* Botão de tema dentro do drawer, com aparência de link de menu */
.sidebar-menu li .sidebar-tema-btn {
    display:        flex;
    align-items:    center;
    gap:            .75rem;
    width:          calc(100% - 1.25rem);
    padding:        .6rem 1rem .6rem 1.25rem;
    margin:         .1rem .625rem;
    font-size:      .835rem;
    font-weight:    500;
    color:          inherit;
    background:     none;
    border:         none;
    border-radius:  var(--radius-sm);
    text-align:     left;
    cursor:         pointer;
    transition:     background var(--transition);
}
.sidebar-menu li .sidebar-tema-btn i {
    font-size:  1.05rem;
    min-width:  20px;
    text-align: center;
    flex-shrink: 0;
}
.sidebar-menu li .sidebar-tema-btn:hover { background: rgba(79, 70, 229, .18); }

/* =============================================
   UTILITÁRIOS
   ============================================= */

.cursor-pointer { cursor: pointer; }
.rounded-xl     { border-radius: var(--radius) !important; }
.fw-600         { font-weight: 600; }
