:root {
    --pv-marrom: #D2623F;
    --pv-laranja: #D2623F;
    --pv-marrom-claro: #b8512f;
    --pv-laranja-claro: #e67a57;
    --pv-bege: #fdf3ef;

    --bg-primary: #fafafa;
    --bg-card: #ffffff;
    --text-primary: #2d2d2d;
    --text-secondary: #6b6b6b;
    --border: #e0e0e0;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #dc2626;

    --gradient-pv: linear-gradient(135deg, #c0542e 0%, #D2623F 60%, #e67a57 100%);
    --gradient-laranja: linear-gradient(135deg, var(--pv-laranja) 0%, var(--pv-laranja-claro) 100%);
}

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

body {
    font-family: 'Nunito', 'Montserrat', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--pv-laranja); }

/* ============================================ */
/* LOGIN */
/* ============================================ */

.login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gradient-pv);
    padding: 1rem;
}

.login-card {
    background: white;
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.25);
    padding: 2.5rem;
    width: 100%;
    max-width: 380px;
}

.login-logo {
    background: var(--pv-bege);
    color: var(--pv-laranja);
    width: 56px;
    height: 56px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: 1.5rem;
    margin: 0 auto 1rem;
}

.login-card h1 {
    text-align: center;
    color: var(--pv-marrom);
    font-size: 1.375rem;
    margin-bottom: 0.25rem;
}

.login-card .subtitle {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 1.75rem;
}

.login-error {
    background: rgba(220, 38, 38, 0.1);
    color: var(--danger);
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 1rem;
    display: none;
}

.login-error.show { display: block; }

/* ============================================ */
/* FORM ELEMENTS (genérico) */
/* ============================================ */

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 700;
    color: var(--pv-marrom);
    margin-bottom: 0.4rem;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 0.9375rem;
    font-family: inherit;
    background: var(--bg-primary);
    color: var(--text-primary);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--pv-laranja);
    background: white;
}

.form-row {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.form-row .form-group {
    flex: 1;
    min-width: 140px;
}

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

.btn {
    padding: 0.75rem 1.25rem;
    border: none;
    border-radius: 8px;
    font-weight: 700;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.btn-primary {
    background: var(--pv-laranja);
    color: white;
}

.btn-primary:hover { background: var(--pv-laranja-claro); }

.btn-secondary {
    background: white;
    color: var(--pv-marrom);
    border: 2px solid var(--border);
}

.btn-secondary:hover { border-color: var(--pv-laranja); }

.btn-danger {
    background: rgba(220, 38, 38, 0.1);
    color: var(--danger);
}

.btn-danger:hover { background: rgba(220, 38, 38, 0.2); }

.btn-sm {
    padding: 0.4rem 0.75rem;
    font-size: 0.75rem;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-block { width: 100%; }

.form-msg {
    font-size: 0.8125rem;
    font-weight: 600;
    margin-top: 0.5rem;
    display: none;
}

.form-msg.show { display: block; }
.form-msg.error { color: var(--danger); }
.form-msg.success { color: var(--success); }

/* ============================================ */
/* USER BAR (acima do header, não sticky) */
/* ============================================ */

.user-bar {
    background: var(--pv-bege);
    padding: 0.6rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
    font-size: 0.8125rem;
}

@media (max-width: 768px) {
    .user-bar {
        padding: 0.5rem 1rem;
        font-size: 0.75rem;
    }
}

.user-bar-name {
    color: var(--pv-marrom);
    font-weight: 700;
}

.user-bar-actions {
    display: flex;
    gap: 0.5rem;
}

.user-bar-actions button {
    background: none;
    border: none;
    color: var(--pv-marrom);
    font-weight: 700;
    cursor: pointer;
    font-size: 0.8125rem;
    text-decoration: underline;
    font-family: inherit;
    padding: 0.2rem;
}

@media (max-width: 768px) {
    .user-bar-actions button { font-size: 0.75rem; }
}

/* ============================================ */
/* HEADER */
/* ============================================ */

.header {
    background: var(--gradient-pv);
    box-shadow: 0 4px 20px rgba(61, 47, 35, 0.15);
    position: sticky;
    top: 0;
    z-index: 100;
}

@media (min-width: 769px) {
    .header { padding: 2rem 2rem 1.5rem; }
    .header-content { max-width: 1600px; margin: 0 auto; }
    .brand { display: flex; align-items: center; gap: 1.5rem; }
    .brand-logo {
        background: white; padding: 0.75rem 1.5rem; border-radius: 8px;
        font-weight: 900; font-size: 1.75rem; color: var(--pv-laranja); letter-spacing: -1px;
    }
    .brand-name h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: 0.25rem; color: white; }
    .brand-slogan { font-size: 0.875rem; font-weight: 400; opacity: 0.9; font-style: italic; color: white; }
}

@media (max-width: 768px) {
    .header { padding: 1rem; }
    .header-content { display: flex; align-items: center; justify-content: space-between; }
    .brand { display: flex; align-items: center; gap: 0.75rem; }
    .brand-logo {
        background: white; padding: 0.5rem 1rem; border-radius: 6px;
        font-weight: 900; font-size: 1.25rem; color: var(--pv-laranja); letter-spacing: -1px;
    }
    .brand-name h1 { font-size: 1rem; font-weight: 700; color: white; margin-bottom: 0.125rem; }
    .brand-slogan { font-size: 0.625rem; font-weight: 400; opacity: 0.85; font-style: italic; color: white; }
}

/* ============================================ */
/* NAVIGATION TABS */
/* ============================================ */

.nav-tabs {
    background: white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    position: sticky;
    top: 0;
    z-index: 99;
    overflow-x: auto;
}

@media (min-width: 769px) {
    .nav-tabs { top: 120px; }
    .nav-tabs-container { max-width: 1600px; margin: 0 auto; padding: 0 2rem; display: flex; gap: 2rem; }
    .nav-tab {
        padding: 1.25rem 0; background: transparent; border: none; color: var(--text-secondary);
        cursor: pointer; font-weight: 600; font-size: 1rem; border-bottom: 3px solid transparent;
        transition: all 0.2s; white-space: nowrap; font-family: inherit;
    }
    .nav-tab.active { color: var(--pv-laranja); border-bottom-color: var(--pv-laranja); }
    .nav-tab:hover:not(.active) { color: var(--pv-marrom); }
}

@media (max-width: 768px) {
    .nav-tabs { top: 60px; }
    .nav-tabs-container { display: flex; padding: 0; }
    .nav-tab {
        flex: 1; padding: 1rem 0.5rem; background: transparent; border: none; color: var(--text-secondary);
        cursor: pointer; font-weight: 600; font-size: 0.8125rem; border-bottom: 3px solid transparent;
        transition: all 0.2s; text-align: center; white-space: nowrap; font-family: inherit;
    }
    .nav-tab.active { color: var(--pv-laranja); border-bottom-color: var(--pv-laranja); background: rgba(210, 98, 63, 0.05); }
}

.nav-tab.hidden { display: none; }

/* ============================================ */
/* CONTAINER PRINCIPAL */
/* ============================================ */

.dashboard-container { padding-top: 2rem; padding-bottom: 4rem; }

@media (min-width: 769px) {
    .dashboard-container { max-width: 1600px; margin: 0 auto; padding: 2rem; }
}

@media (max-width: 768px) {
    .dashboard-container { padding: 1rem; }
}

.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeIn 0.3s ease; }

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

/* ============================================ */
/* CARDS DE MÉTRICAS */
/* ============================================ */

@media (min-width: 769px) {
    .metrics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1.5rem; margin-bottom: 2rem; }
    .metric-card {
        background: var(--bg-card); padding: 2rem; border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.08);
        border-left: 4px solid var(--pv-laranja); transition: all 0.3s; position: relative; overflow: hidden;
    }
    .metric-card:hover { transform: translateY(-5px); box-shadow: 0 8px 24px rgba(0,0,0,0.12); }
    .metric-value { font-size: 2.5rem; font-weight: 800; color: var(--pv-marrom); line-height: 1; margin-bottom: 0.75rem; }
}

@media (max-width: 768px) {
    .metrics-grid { display: flex; flex-direction: column; gap: 1rem; margin-bottom: 1.5rem; }
    .metric-card {
        background: var(--bg-card); padding: 1.25rem; border-radius: 10px; box-shadow: 0 2px 6px rgba(0,0,0,0.06);
        border-left: 3px solid var(--pv-laranja); display: flex; align-items: center; justify-content: space-between; min-height: 80px;
    }
    .metric-card-content { flex: 1; }
    .metric-value { font-size: 2rem; font-weight: 800; color: var(--pv-marrom); line-height: 1; margin-bottom: 0.25rem; }
}

.metric-card.primary { border-left-color: var(--pv-marrom); }

.metric-label {
    font-size: 0.8rem; font-weight: 600; color: var(--text-secondary);
    text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 0.75rem;
}

@media (max-width: 768px) {
    .metric-label { font-size: 0.7rem; margin-bottom: 0.25rem; }
}

.metric-change { display: flex; align-items: center; gap: 0.5rem; font-size: 0.75rem; font-weight: 600; margin-top: 0.5rem; flex-wrap: wrap; }
.metric-change.positive { color: var(--success); }
.metric-change.neutral { color: var(--text-secondary); }

/* ============================================ */
/* SELECT DE GERENTE / FILTROS */
/* ============================================ */

.filter-box {
    background: white; padding: 1.5rem; border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.08); margin-bottom: 1.5rem;
}

@media (max-width: 768px) {
    .filter-box { padding: 1rem; border-radius: 10px; }
}

.filter-label { font-size: 0.875rem; font-weight: 600; color: var(--pv-marrom); margin-bottom: 0.75rem; display: block; }

.pv-select {
    width: 100%; padding: 1rem; background: var(--bg-primary); border: 2px solid var(--border);
    border-radius: 8px; font-size: 1rem; font-weight: 600; color: var(--pv-marrom); cursor: pointer;
    transition: all 0.2s; font-family: inherit;
}

@media (max-width: 768px) {
    .pv-select { padding: 0.875rem; font-size: 0.9375rem; min-height: 48px; }
}

.pv-select:focus { outline: none; border-color: var(--pv-laranja); background: white; }

/* ============================================ */
/* SECTION / TABELAS */
/* ============================================ */

.section { background: var(--bg-card); padding: 2rem; border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.08); margin-bottom: 2rem; }

@media (max-width: 768px) {
    .section { padding: 1rem; border-radius: 10px; margin-bottom: 1.5rem; }
}

.section-title { font-size: 1.5rem; font-weight: 700; color: var(--pv-marrom); margin-bottom: 1.5rem; }

@media (max-width: 768px) {
    .section-title { font-size: 1.125rem; margin-bottom: 1rem; }
}

@media (min-width: 769px) {
    .table-container { overflow-x: auto; }
    table { width: 100%; border-collapse: separate; border-spacing: 0; }
    thead { background: var(--pv-laranja); }
    th { padding: 1rem 1.5rem; text-align: left; font-weight: 700; font-size: 0.75rem; color: white; text-transform: uppercase; letter-spacing: 0.5px; }
    th:first-child { border-radius: 8px 0 0 0; }
    th:last-child { border-radius: 0 8px 0 0; }
    td { padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border); font-weight: 500; }
    tbody tr { transition: background 0.2s; }
    tbody tr:hover { background: var(--bg-primary); }
}

@media (max-width: 768px) {
    .table-container.responsive-cards { display: none; }
    table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.8125rem; }
    thead { background: var(--pv-laranja); }
    th { padding: 0.6rem 0.75rem; text-align: left; font-weight: 700; font-size: 0.65rem; color: white; text-transform: uppercase; }
    td { padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); font-weight: 500; }
}

/* Tabela genérica que sempre rola na horizontal (usada em Metas/Gestores) */
/* Tabelas de Metas/Gestores: layout fixo + quebra de texto no desktop, pra nenhuma coluna
   (ex: um select de "papel" ou um e-mail bem comprido, sem espaços) espremer as outras ou
   obrigar rolagem horizontal escondida. */
.simple-table-container { overflow-x: auto; }
.simple-table-container table { table-layout: fixed; width: 100%; }
.simple-table-container td,
.simple-table-container th {
    word-break: break-word;
    overflow-wrap: break-word;
}

/* No mobile, 5-6 colunas de largura igual ficam ilegíveis (texto quebrando letra a letra).
   Em vez disso, cada linha vira um "cartão" e cada célula mostra "Rótulo: valor" empilhado
   — mesma ideia das mobile-cards do ranking, só que via CSS puro usando data-label (definido
   no JS ao montar cada <td>), sem duplicar HTML. */
@media (max-width: 768px) {
    .simple-table-container table,
    .simple-table-container thead,
    .simple-table-container tbody,
    .simple-table-container th,
    .simple-table-container td,
    .simple-table-container tr {
        display: block;
    }
    .simple-table-container thead tr { position: absolute; top: -9999px; left: -9999px; }
    .simple-table-container tbody tr {
        margin-bottom: 1rem;
        border: 1px solid var(--border);
        border-radius: 10px;
        padding: 0.5rem 0.75rem;
    }
    .simple-table-container td {
        border: none;
        border-bottom: 1px solid var(--border);
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 1rem;
        padding: 0.5rem 0;
        text-align: right;
    }
    .simple-table-container td:last-child { border-bottom: none; }
    .simple-table-container td::before {
        content: attr(data-label);
        text-align: left;
        font-weight: 700;
        color: var(--pv-marrom);
        font-size: 0.7rem;
        text-transform: uppercase;
        flex-shrink: 0;
    }
}

.mobile-cards { display: none; flex-direction: column; gap: 1rem; }

@media (max-width: 768px) {
    .mobile-cards.show-mobile { display: flex; }
}

.ranking-card { background: var(--bg-primary); border-radius: 10px; padding: 1rem; border-left: 4px solid var(--pv-laranja); }
.ranking-card.rank-1 { border-left-color: #ffd700; }
.ranking-card.rank-2 { border-left-color: #c0c0c0; }
.ranking-card.rank-3 { border-left-color: #cd7f32; }
.ranking-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; }
.ranking-name { font-size: 1rem; font-weight: 700; color: var(--pv-marrom); }
.ranking-badge { background: var(--pv-laranja); color: white; padding: 0.25rem 0.75rem; border-radius: 20px; font-size: 0.75rem; font-weight: 700; }
.ranking-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.ranking-stat { display: flex; flex-direction: column; }
.ranking-stat-label { font-size: 0.7rem; color: var(--text-secondary); text-transform: uppercase; font-weight: 600; margin-bottom: 0.25rem; }
.ranking-stat-value { font-size: 1.125rem; font-weight: 700; color: var(--pv-marrom); }

/* ============================================ */
/* CHARTS */
/* ============================================ */

@media (min-width: 769px) {
    .charts-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.5rem; margin-bottom: 2rem; }
    .chart-container { background: var(--bg-card); padding: 1.5rem; border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.08); height: 340px; display: flex; flex-direction: column; }
    .chart-container canvas { flex: 1; min-height: 0; }
}

@media (max-width: 768px) {
    .charts-grid { display: flex; flex-direction: column; gap: 1.5rem; margin-bottom: 1.5rem; }
    .chart-container { background: var(--bg-card); padding: 1rem; border-radius: 10px; box-shadow: 0 2px 6px rgba(0,0,0,0.06); height: 280px; display: flex; flex-direction: column; }
    .chart-container canvas { flex: 1; min-height: 0; }
}

/* ============================================ */
/* EXPORT BUTTON (FAB no mobile) */
/* ============================================ */

.export-btn-mobile { display: none; }

@media (max-width: 768px) {
    .export-btn-mobile {
        position: fixed; bottom: 1rem; right: 1rem; width: 56px; height: 56px;
        background: var(--pv-laranja); color: white; border: none; border-radius: 50%;
        font-size: 1.5rem; cursor: pointer; box-shadow: 0 4px 12px rgba(210, 98, 63, 0.4);
        z-index: 1000; display: flex; align-items: center; justify-content: center;
    }
}

.chart-title { font-size: 1.125rem; font-weight: 700; color: var(--pv-marrom); margin-bottom: 1.5rem; }

@media (max-width: 768px) {
    .chart-title { font-size: 0.9375rem; margin-bottom: 1rem; }
}

/* ============================================ */
/* PERIOD SELECTOR */
/* ============================================ */

.period-selector { display: flex; gap: 0.5rem; background: var(--bg-primary); padding: 0.25rem; border-radius: 8px; margin-bottom: 1rem; flex-wrap: wrap; }

.period-btn {
    flex: 1; min-width: 100px; padding: 0.75rem 1rem; background: transparent; border: none; color: var(--text-secondary);
    cursor: pointer; border-radius: 6px; font-weight: 600; font-size: 0.875rem; transition: all 0.2s; font-family: inherit;
}

@media (max-width: 768px) {
    .period-btn { padding: 0.625rem 0.75rem; font-size: 0.8125rem; }
}

.period-btn.active { background: var(--pv-laranja); color: white; }

.period-custom-row {
    display: none;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    align-items: flex-end;
    flex-wrap: wrap;
}

.period-custom-row.show { display: flex; }

/* ============================================ */
/* UTILITIES */
/* ============================================ */

.badge { display: inline-block; padding: 0.375rem 0.875rem; border-radius: 6px; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.badge-success { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.badge-warning { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.badge-danger { background: rgba(220, 38, 38, 0.15); color: var(--danger); }
.badge-primary { background: rgba(210, 98, 63, 0.15); color: var(--pv-laranja); }

.loading { text-align: center; padding: 3rem 1rem; }
.spinner { border: 3px solid var(--border); border-top: 3px solid var(--pv-laranja); border-radius: 50%; width: 40px; height: 40px; animation: spin 1s linear infinite; margin: 0 auto 1rem; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

.empty-msg { text-align: center; color: var(--text-secondary); padding: 2rem 1rem; }

.error-msg {
    background: rgba(220, 38, 38, 0.1); color: var(--danger); padding: 0.75rem 1rem;
    border-radius: 8px; font-size: 0.875rem; font-weight: 600; margin-bottom: 1rem;
}

/* ============================================ */
/* MODAL */
/* ============================================ */

.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 200;
    display: flex; align-items: center; justify-content: center; padding: 1rem;
}

.modal-card {
    background: white; border-radius: 12px; padding: 2rem; width: 100%; max-width: 400px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.3);
}

.modal-card h3 { color: var(--pv-marrom); margin-bottom: 1.25rem; font-size: 1.25rem; }

.modal-actions { display: flex; gap: 0.75rem; margin-top: 1.25rem; }
.modal-actions .btn { flex: 1; }

.subsection-title { font-size: 1.125rem; font-weight: 700; color: var(--pv-marrom); margin: 1.5rem 0 1rem; }
.subsection-title:first-child { margin-top: 0; }

/* ============================================ */
/* META X REALIZADO (barra de progresso) */
/* ============================================ */

.meta-progress-card {
    background: var(--bg-primary);
    border-radius: 10px;
    padding: 1rem 1.25rem;
    margin-bottom: 0.75rem;
    border-left: 4px solid var(--pv-laranja);
}

.meta-progress-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.6rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.meta-progress-title { font-weight: 700; color: var(--pv-marrom); font-size: 0.9375rem; }
.meta-progress-values { font-size: 0.8125rem; color: var(--text-secondary); }

.meta-progress-track {
    background: var(--border);
    border-radius: 999px;
    height: 10px;
    overflow: hidden;
}

.meta-progress-fill {
    height: 100%;
    border-radius: 999px;
    background: var(--pv-laranja);
    transition: width 0.3s;
}

.meta-progress-fill.complete { background: var(--success); }
.meta-progress-fill.low { background: var(--warning); }

.meta-progress-pct {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-secondary);
    margin-top: 0.35rem;
    text-align: right;
}

.meta-progress-unavailable {
    font-style: italic;
    color: var(--text-secondary);
    font-size: 0.8125rem;
}

/* ============================================ */
/* FUNIL DE CONVERSÃO — taxas por etapa */
/* ============================================ */

.funil-taxas {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.funil-taxa-badge {
    background: var(--bg-primary);
    border-radius: 8px;
    padding: 0.6rem 1rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-secondary);
    border-left: 3px solid var(--pv-laranja);
}

.funil-taxa-badge .valor {
    font-weight: 800;
    color: var(--pv-marrom);
}
