/* styles.css */
:root {
    --bg-dark: #0D1126;
    /* Azul profundo baseado no logo */
    --bg-sidebar: #151B3D;
    /* Azul secundário da marca */
    --accent: #F58220;
    /* Laranja vibrante do "seu" no logo */
    --blue-logo: #2E3192;
    /* Azul do "vendedor" no logo */
    --gold: #FFB347;
    /* Laranja mais claro para contrastes */
    --text-main: #F8FAFC;
    /* Branco limpo */
    --text-dim: #94A3B8;
    /* Cinza azulado para textos secundários */
    --card-bg: rgba(255, 255, 255, 0.03);
    --border: rgba(255, 255, 255, 0.08);
    --hover-bg: rgba(245, 130, 32, 0.1);
    /* Hover baseado no laranja */
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    overflow: hidden;
    height: 100vh;
}

.app-container {
    display: flex;
    height: 100vh;
}

/* Sidebar Styling */
.sidebar {
    width: 240px;
    /* Reduzido de 280px */
    background-color: var(--bg-sidebar);
    padding: 1rem;
    /* Reduzido de 2rem 1.5rem */
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    /* Reduzido de 1.5rem */
    border-right: 1px solid var(--border);
    overflow-y: auto;
}

.sidebar-header h2 {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    /* Reduzido de 0.5rem */
}

.filter-group label {
    font-size: 0.75rem;
    /* Reduzido */
    color: var(--text-dim);
    font-weight: 500;
}

.filter-group select {
    background: var(--bg-dark);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 0.6rem;
    border-radius: 6px;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.3s;
}

.filter-group select:focus {
    border-color: var(--accent);
}

/* Estilo para Custom Multi-Seleção (Lista Suspensa) */
.custom-select {
    position: relative;
    user-select: none;
}

.select-header {
    background: var(--bg-dark);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 0.7rem 1rem;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.3s;
}

.select-header:hover {
    border-color: var(--accent);
}

.select-header .status-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
}

.select-header .arrow {
    font-size: 0.6rem;
    transition: transform 0.3s;
    color: var(--text-dim);
}

.custom-select.active .arrow {
    transform: rotate(180deg);
}

.select-options {
    position: absolute;
    top: calc(100% + 5px);
    left: 0;
    width: 100%;
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: 6px;
    z-index: 2000;
    max-height: 250px;
    overflow-y: auto;
    display: none;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

.custom-select.active .select-options {
    display: block;
    animation: fadeIn 0.2s ease-out;
}

.option-item {
    padding: 10px 15px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.85rem;
    color: var(--text-main);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.option-item:hover {
    background: var(--hover-bg);
    padding-left: 20px;
}

.option-item.selected {
    background: rgba(245, 130, 32, 0.15);
    color: var(--accent);
    font-weight: 600;
}

.option-item.selected::after {
    content: '✓';
    font-size: 0.7rem;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.btn-secondary {
    margin-top: 1rem;
    background: transparent;
    border: 1px solid var(--accent);
    color: var(--accent);
    padding: 0.8rem;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s;
}

.btn-secondary:hover {
    background: var(--hover-bg);
}

/* Main Content Styling */
.main-content {
    flex: 1;
    padding: 1.5rem 2rem;
    /* Aumentado */
    display: flex;
    flex-direction: column;
    gap: 1.8rem;
    /* Aumentado de 1rem */
    overflow-y: auto;
}

.top-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    /* Centralizado verticalmente para um ar mais premium */
    border-bottom: 1px solid var(--border);
    /* Borda mais sutil */
    padding-bottom: 0.8rem;
    /* Reduzido de 1.5rem */
    position: relative;
}

.top-header::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 80px;
    /* Reduzido de 100px */
    height: 2px;
    background: var(--accent);
    /* Detalhe lateral na borda */
}

.header-info h1 {
    font-size: 1.5rem;
    /* Reduzido de 2rem */
    font-weight: 800;
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 2px;
    /* Reduzido de 3px */
    background: linear-gradient(to right, #fff 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    position: relative;
    display: inline-block;
}

.last-update {
    font-size: 0.9rem;
    color: var(--text-dim);
}

/* Metrics Grid */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
}

.metric-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    padding: 1.2rem 1.5rem;
    /* Aumentado de 0.8rem 1rem */
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    /* Aumentado */
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(10px);
}

.metric-card:hover {
    transform: translateY(-5px);
    border-color: var(--accent);
    box-shadow: 0 10px 30px -15px var(--accent);
}

.metric-card.active {
    background: var(--accent);
    color: var(--bg-dark);
}

.metric-card.active .metric-label,
.metric-card.active .metric-value {
    color: var(--bg-dark);
}

.metric-label {
    font-size: 0.65rem;
    /* Reduzido de 0.75rem */
    font-weight: 700;
    color: var(--text-dim);
    letter-spacing: 1px;
}

.metric-value {
    font-size: 1.2rem;
    /* Reduzido de 1.5rem */
    font-weight: 700;
    color: #fff;
}

/* Table Styling */
.table-container {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    margin-bottom: 2rem;
}

.table-header-custom {
    padding: 1rem 1.5rem;
    /* Aumentado */
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid var(--border);
}

.table-title {
    font-size: 0.95rem;
    /* Aumentado */
    font-weight: 600;
    color: var(--text-main);
}

.table-scroll {
    overflow-x: auto;
    max-height: calc(100vh - 350px);
    /* Ajustado para compensar o aumento de altura das áreas superiores */
    overflow-y: auto;
}

table {
    width: 100%;
    min-width: 1200px;
    /* Aumentado para dar mais ar às colunas de dados */
    border-collapse: collapse;
    font-size: 0.88rem;
    /* Aumentado */
}

thead th,
tbody td {
    white-space: nowrap;
    /* Impede quebras de texto em colunas pequenas */
}

/* Tornar a primeira coluna (Vendedor) fixa horizontalmente */
thead th:first-child,
tbody td:first-child {
    position: sticky;
    left: 0;
    z-index: 20;
}

thead th:first-child {
    z-index: 30;
    background: var(--bg-sidebar);
}

thead tr:nth-child(2) th:first-child {
    z-index: 31;
    background: var(--bg-sidebar);
}

tbody td:first-child {
    background-color: #0D1126 !important;
    /* Fundo totalmente opaco */
    border-right: 2px solid var(--border);
}

/* Ajustes para manter o hover na coluna fixa */
tbody tr:hover td:first-child {
    background: rgba(245, 130, 32, 0.15);
    /* Destaque laranja sutil no hover */
}

/* Ajuste para o Total Geral na coluna fixa */
tbody tr:last-child td:first-child {
    background: var(--bg-sidebar);
    color: var(--gold);
    z-index: 21;
}

thead th {
    text-align: left;
    padding: 0 1.2rem;
    background-color: #151B3D !important;
    /* Cor sólida OPACO */
    color: var(--accent);
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--border);
    height: 48px;
}

thead tr:nth-child(2) th {
    top: 48px;
    background-color: #151B3D !important;
    /* Cor sólida OPACO */
    font-size: 0.65rem;
    color: var(--text-dim);
    border-bottom: 2px solid var(--border);
    height: 40px;
}

/* Ajuste específico para a coluna fixa com rowSpan */
.fixed-column-header {
    position: sticky !important;
    left: 0 !important;
    top: 0 !important;
    z-index: 150 !important;
    background-color: #151B3D !important;
    border-right: 2px solid var(--border);
    box-shadow: 6px 0 15px rgba(0, 0, 0, 0.5);
    height: 88px !important;
}

/* Estilos para Agrupamento de Meses */
.month-group-border {
    border-left: 2px solid rgba(245, 130, 32, 0.3) !important;
}

thead th.month-header {
    background-color: #24213d !important;
    /* Cor composta sólida OPACO */
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 2px;
    font-size: 0.85rem;
    font-weight: 700;
    padding: 0 0.8rem !important;
    border-bottom: 1px solid var(--border);
}

tbody tr:hover td.month-group-border {
    border-left: 2px solid rgba(245, 130, 32, 0.4) !important;
    /* Destaque no hover */
}

tbody td {
    padding: 0.9rem 1.2rem;
    /* Aumentado de 0.6rem */
    border-bottom: 1px solid var(--border);
    color: var(--text-main);
}

tbody tr:hover {
    background: rgba(245, 130, 32, 0.08);
    /* Hover laranja coerente */
}

tbody tr:last-child {
    background: rgba(255, 255, 255, 0.05);
    font-weight: 700;
}

tbody tr:last-child td {
    color: var(--gold);
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-sidebar);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-dim);
}

/* Botão Mobile */
.mobile-only-btn {
    display: none;
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--gold);
    color: var(--bg-dark);
    border: none;
    padding: 1rem 1.5rem;
    border-radius: 50px;
    font-weight: 700;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
    z-index: 1001;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 999;
}

/* Responsividade */
@media (max-width: 992px) {
    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        bottom: 0;
        z-index: 1000;
        transition: left 0.3s ease;
    }

    .sidebar.active {
        left: 0;
    }

    .mobile-only-btn {
        display: block;
    }

    .overlay.active {
        display: block;
    }

    .main-content {
        padding: 1rem;
        overflow-x: hidden;
    }

    .header-info h1 {
        font-size: 1.5rem;
    }

    .metrics-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.8rem;
    }

    .metric-card {
        padding: 1rem;
    }

    .metric-value {
        font-size: 1.1rem;
    }
}

@media (max-width: 480px) {
    .metrics-grid {
        grid-template-columns: 1fr;
    }

    .top-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .last-update {
        font-size: 0.7rem;
    }
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-dark);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 1;
    transition: opacity 0.5s ease-out, visibility 0.5s;
    backdrop-filter: blur(5px);
}

.loading-overlay.hidden {
    opacity: 0;
    visibility: hidden;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 5px solid var(--border);
    border-top: 5px solid var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1.5rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-overlay p {
    color: var(--accent);
    font-weight: 600;
    font-size: 1.1rem;
    letter-spacing: 2px;
    text-transform: uppercase;
}

/* Login Page Styles */
.login-body {
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--bg-dark);
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 20px;
}

.login-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2.5rem;
    backdrop-filter: blur(10px);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.5);
    transition: transform 0.1s;
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-header h2 {
    font-weight: 800;
    font-size: 1.5rem;
    color: #fff;
    margin-bottom: 0.2rem;
}

.login-header p {
    color: var(--accent);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.input-group {
    margin-bottom: 1.5rem;
}

.input-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.input-group input {
    width: 100%;
    padding: 12px 15px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: #fff;
    font-size: 0.95rem;
    outline: none;
    transition: all 0.3s;
}

.input-group input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(245, 130, 32, 0.2);
}

.btn-login {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    color: var(--bg-dark);
    border: none;
    border-radius: 6px;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 1rem;
}

.btn-login:hover {
    background: #ff983f;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(245, 130, 32, 0.3);
}

.login-error {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    padding: 10px;
    border-radius: 6px;
    font-size: 0.85rem;
    text-align: center;
    margin-bottom: 1rem;
}

.hidden {
    display: none !important;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

.shake {
    animation: shake 0.4s;
}

.btn-logout {
    margin-top: auto; /* Empurra pro fim do sidebar */
    margin-bottom: 1rem;
    background: transparent;
    border: 1px solid rgba(239, 68, 68, 0.5);
    color: #ef4444;
    padding: 0.8rem;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s;
    text-align: center;
}

.btn-logout:hover {
    background: rgba(239, 68, 68, 0.1);
}