/* === BTG Pactual Office webfont === */
@font-face { font-family: 'BTG Pactual Office'; src: url('../fonts/BTGPactualOffice-Light.ttf') format('truetype'); font-weight: 300; font-style: normal; font-display: swap; }
@font-face { font-family: 'BTG Pactual Office'; src: url('../fonts/BTGPactualOffice-Regular.ttf') format('truetype'); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: 'BTG Pactual Office'; src: url('../fonts/BTGPactualOffice-SemiBold.ttf') format('truetype'); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: 'BTG Pactual Office'; src: url('../fonts/BTGPactualOffice-Bold.ttf') format('truetype'); font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: 'BTG Pactual Office'; src: url('../fonts/BTGPactualOffice-ExtraBold.ttf') format('truetype'); font-weight: 800; font-style: normal; font-display: swap; }
@font-face { font-family: 'BTG Pactual Office'; src: url('../fonts/BTGPactualOffice-Black.ttf') format('truetype'); font-weight: 900; font-style: normal; font-display: swap; }

/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #EFF2F8;
    --surface: #ffffff;
    --surface-alt: #f7f9fc;
    --border: #d9e0ea;
    --text: #191919;
    --text-muted: #6b7b96;
    --accent: #195AB4;
    --accent-hover: #4d9eff;
    --navy: #001F62;

    --vibra: #16a34a;
    --ipiranga: #d4a017;
    --raizen: #7b2d8e;
    --regionals: #195AB4;
    --market: #6b7b96;
    --incumbents: #e74c3c;
    --market-total: #6b7b96;

    --font: 'BTG Pactual Office', Arial, Helvetica, sans-serif;
    --mono: 'BTG Pactual Office', Arial, Helvetica, sans-serif;
    --radius: 6px;
    --shadow: 0 1px 4px rgba(0, 31, 98, 0.08);
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.45;
    min-height: 100vh;
    font-size: 14px;
}

#app {
    max-width: 1440px;
    margin: 0 auto;
    padding: 0 0 40px;
}

/* === Header === */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: var(--navy);
    color: #fff;
}
.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}
.btn-back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(255,255,255,0.12);
    color: #fff;
    text-decoration: none;
    transition: background 0.2s;
}
.btn-back:hover {
    background: rgba(255,255,255,0.25);
}
.header-logo {
    height: 48px;
}
.header h1 {
    font-size: 22px;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.5px;
}
.subtitle {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.6);
}
.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}
.data-range {
    color: rgba(255, 255, 255, 0.7);
    font-size: 13px;
}
.loading {
    color: var(--accent-hover);
    font-size: 13px;
    animation: pulse 1.2s infinite;
}
.loading.hidden { display: none; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

/* === Tabs === */
.tabs {
    display: flex;
    gap: 0;
    padding: 0 24px;
    background: var(--navy);
    border-bottom: 2px solid rgba(255,255,255,0.10);
}
.tab {
    padding: 14px 28px;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.5);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: color 0.2s, border-color 0.2s;
    letter-spacing: 0.3px;
    text-transform: uppercase;
    white-space: nowrap;
}
.tab:hover { color: rgba(255, 255, 255, 0.85); }
.tab.active {
    color: #fff;
    border-bottom-color: var(--accent-hover);
}

/* === Filters === */
.filters {
    display: flex;
    align-items: flex-end;
    gap: 20px;
    padding: 16px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.filter-group label {
    display: block;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--navy);
    margin-bottom: 4px;
}
.filter-group select {
    padding: 6px 14px;
    background: #fff;
    border: 1px solid #c8d0de;
    border-radius: 20px;
    color: #1a2e5a;
    font-size: 13px;
    font-family: var(--font);
    min-width: 130px;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7b96' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.filter-group select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(25, 90, 180, 0.15);
}
.checkbox-group {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
}
.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 13px;
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    color: var(--text);
    cursor: pointer;
    margin-bottom: 0;
}
.checkbox-group input[type="checkbox"] {
    accent-color: var(--accent);
    width: 15px;
    height: 15px;
    cursor: pointer;
}
.filter-actions {
    display: flex;
    gap: 8px;
    margin-left: auto;
}

/* === Buttons === */
.btn {
    padding: 6px 16px;
    border: none;
    border-radius: 20px;
    background: var(--navy);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: background 0.2s;
}
.btn:hover { background: var(--accent); }
.btn:disabled { background: #c8d0de; color: var(--text-muted); cursor: not-allowed; }
.btn-sm { padding: 4px 12px; font-size: 12px; }

/* === Dashboard === */
.dashboard {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 20px 24px;
}

/* === Chart Section === */
.chart-section {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow);
}
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--accent);
}
.section-header h2 {
    font-size: 14px;
    font-weight: 700;
    color: var(--navy);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.chart-container {
    position: relative;
    height: 380px;
}

/* === Table Section === */
.table-section {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow);
}
.table-section h2 {
    font-size: 14px;
    font-weight: 700;
    color: var(--navy);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--accent);
}
.table-wrapper {
    overflow-x: auto;
    max-height: 400px;
    overflow-y: auto;
}
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13px;
}
thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--navy);
    color: #fff;
    padding: 8px 12px;
    text-align: center;
    font-weight: 700;
    font-size: 12px;
    border-bottom: 2px solid var(--accent);
    white-space: nowrap;
}
thead th:first-child {
    text-align: center;
    position: sticky;
    left: 0;
    z-index: 3;
    background: var(--navy);
}
tbody td {
    padding: 6px 12px;
    text-align: center;
    border-bottom: 1px solid #f0f0f0;
    font-family: var(--mono);
    font-size: 12px;
    white-space: nowrap;
    transition: background 0.15s;
}
tbody td:first-child {
    text-align: center;
    font-family: var(--font);
    font-weight: 700;
    color: var(--navy);
    position: sticky;
    left: 0;
    background: #fff;
    z-index: 1;
}
tbody tr:nth-child(even) { background: #f9f9f9; }
tbody tr:nth-child(even) td:first-child { background: #f9f9f9; }
tbody tr:nth-child(odd) { background: #fff; }
tbody tr:nth-child(odd) td:first-child { background: #fff; }
tbody tr:hover { background: #e6eef8; }
tbody tr:hover td:first-child { background: #e6eef8; }

/* Color-coded columns */
td.vibra { color: var(--vibra); font-weight: 600; }
td.ipiranga { color: var(--ipiranga); font-weight: 600; }
td.raizen { color: var(--raizen); font-weight: 600; }
td.regionals { color: var(--regionals); font-weight: 600; }
td.market { color: var(--text-muted); }
td.incumbents { color: var(--incumbents); font-weight: 600; }
td.market-total { color: var(--market-total); }

/* === Footer === */
.footer {
    margin: 32px 24px 0;
    padding: 16px 0 18px;
    border-top: 2px solid var(--accent);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: var(--text-muted);
    font-size: 12px;
}
.footer-logo {
    height: 26px;
    opacity: 0.85;
    margin-bottom: 2px;
}
.footer-signatures {
    font-size: 12.5px;
    font-weight: 700;
    color: var(--navy);
    letter-spacing: 0.2px;
}
.footer-emails {
    font-size: 11.5px;
    color: var(--text-muted);
}
.footer-emails a {
    color: var(--accent);
    text-decoration: none;
}
.footer-emails a:hover {
    text-decoration: underline;
}

/* === Scrollbar === */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #c8d0de; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* === Table wrapper: smooth scroll on iOS === */
.table-wrapper {
    -webkit-overflow-scrolling: touch;
}

/* === Mobile (max 768px) === */
@media (max-width: 768px) {
    body { font-size: 13px; }

    #app { padding: 0 0 24px; }

    /* Header */
    .header {
        flex-wrap: wrap;
        gap: 8px;
        padding: 12px 16px;
    }
    .header h1 { font-size: 15px; }
    .header .subtitle { display: none; }
    .header-right { gap: 8px; }
    .header-logo { height: 32px; }
    .data-range, .loading { font-size: 11px; }

    /* Tabs: horizontal scroll, 44px touch target */
    .tabs {
        padding: 0 8px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .tabs::-webkit-scrollbar { display: none; }
    .tab {
        padding: 0 16px;
        height: 44px;
        font-size: 11px;
        flex-shrink: 0;
        display: flex;
        align-items: center;
    }

    /* Filters: stack vertically, full-width */
    .filters {
        flex-direction: column;
        align-items: stretch;
        padding: 12px 16px;
        gap: 10px;
    }
    .filter-group { width: 100%; }
    .filter-group select {
        width: 100%;
        min-width: unset;
        min-height: 44px;
        font-size: 14px;
        padding: 10px 36px 10px 14px;
    }
    .checkbox-group { gap: 12px; }
    .checkbox-group label { font-size: 14px; gap: 8px; }
    .checkbox-group input[type="checkbox"] { width: 18px; height: 18px; }
    .filter-actions { margin-left: 0; width: 100%; display: flex; gap: 8px; }
    .filter-actions .btn { flex: 1; }

    /* Buttons: 44px touch target */
    .btn { min-height: 44px; font-size: 14px; }
    .btn-back { width: 40px; height: 40px; }

    /* Dashboard */
    .dashboard { padding: 12px 16px; gap: 12px; }

    /* Chart sections */
    .chart-section, .table-section { padding: 12px 10px; }
    .chart-container { height: 240px; }
    .section-header { flex-wrap: wrap; gap: 8px; }
    .section-header h2 { font-size: 12px; }

    /* Tables: horizontal scroll with sticky first column */
    .table-wrapper { max-height: none; overflow-x: auto; overflow-y: visible; -webkit-overflow-scrolling: touch; }
    table { font-size: 11px; min-width: 480px; }
    thead th { padding: 6px 8px; font-size: 10px; }
    tbody td { padding: 5px 8px; font-size: 11px; }
    tbody td:first-child { min-width: 70px; white-space: nowrap; font-size: 11px; }

    /* Frozen first column (date / label) */
    table.frozen-date-table thead th:first-child,
    table.frozen-date-table tbody td:first-child {
        position: sticky;
        left: 0;
        z-index: 2;
        background: var(--surface);
        box-shadow: 2px 0 4px rgba(0,31,98,0.07);
    }
    table.frozen-date-table thead th:first-child { background: var(--navy); z-index: 3; }
    table.frozen-date-table tbody tr:nth-child(even) td:first-child { background: var(--surface-alt); }
    table.frozen-date-table tbody tr:hover td:first-child { background: #e8eef9; }

    /* Footer */
    .footer { margin: 20px 16px 0; }
}

/* Company colour classes for table cells */
td.vibra         { color: var(--vibra);      font-weight: 600; }
td.ipiranga      { color: var(--ipiranga);   font-weight: 600; }
td.raizen        { color: var(--raizen);     font-weight: 600; }
td.regionals     { color: var(--regionals);  font-weight: 600; }
td.market        { color: var(--text-muted); }
td.incumbents    { color: var(--incumbents); font-weight: 600; }
td.market-total  { color: var(--market-total); }
