/* ═══════════════════════════════════════════════════
   Vitallmente Dashboard — Tesla Design System
   ═══════════════════════════════════════════════════ */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ── Tokens (Modern UI) ── */
:root {
    --bg:         #ffffff;
    --surface:    #ffffff;
    --surface2:   #fafafa;
    --border:     rgba(0,0,0,0.06);
    --border-hover: rgba(0,0,0,0.12);
    --text:       #111111;
    --text2:      #666666;
    --accent:     #5e4352;
    --green:      #2e8b57;
    --red:        #dc143c;
    --orange:     #ff8c00;
    --blue:       #007aff;
    --yellow:     #f5a623;
    --sidebar-w:  256px;
    --radius:     12px;
    --shadow:     0 2px 8px rgba(0,0,0,0.02), 0 16px 32px rgba(0,0,0,0.02);
    --shadow-hover: 0 4px 12px rgba(0,0,0,0.04), 0 24px 48px rgba(0,0,0,0.03);
    --input-bg:   #ffffff;
}

[data-theme="dark"] {
    --bg:         #0a0a0a;
    --surface:    #0a0a0a;
    --surface2:   #111111;
    --border:     rgba(255,255,255,0.08);
    --border-hover: rgba(255,255,255,0.15);
    --text:       #ededed;
    --text2:      #888888;
    --accent:     #8a677a;
    --input-bg:   #000000;
    --shadow:     0 2px 8px rgba(0,0,0,0.4), 0 16px 32px rgba(0,0,0,0.3);
    --shadow-hover: 0 4px 12px rgba(0,0,0,0.6), 0 24px 48px rgba(0,0,0,0.5);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background .35s ease, color .35s ease;
    font-size: 14px;
}

/* ═══ LAYOUT ═══ */
.app { display: flex; min-height: 100vh; }

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    z-index: 20;
    transition: background .35s, border-color .35s;
}

.sidebar-brand {
    padding: 1.5rem 1.25rem;
    display: flex;
    align-items: center;
    gap: .6rem;
    border-bottom: 1px solid var(--border);
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -.025em;
    justify-content: center;
    background-color: var(--accent);
}

.sidebar-logo {
    max-width: 100%;
    max-height: 50px;
    object-fit: contain;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    overflow-y: auto;
}

.filter-group { display: flex; flex-direction: column; gap: .3rem; }

.filter-group label {
    font-size: .65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text2);
    display: flex;
    align-items: center;
    gap: .35rem;
}

.filter-group input, .filter-group select {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: .6rem .75rem;
    border-radius: 8px;
    font-size: .8rem;
    font-family: inherit;
    transition: border-color .2s, box-shadow .2s;
    appearance: none;
}

.quick-filters {
    display: flex;
    gap: .25rem;
    margin-bottom: .25rem;
}

.btn-qf {
    flex: 1;
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: .25rem;
    font-size: .65rem;
    border-radius: 4px;
    cursor: pointer;
    transition: background .2s, border-color .2s;
}

.btn-qf:hover {
    background: var(--border);
}

.btn-qf.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

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

.custom-multi-select {
    position: relative;
    user-select: none;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: .8rem;
    font-family: inherit;
    color: var(--text);
    transition: border-color .2s;
}

.custom-multi-select.open {
    border-color: var(--accent);
}

.select-header {
    padding: .55rem .75rem;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.select-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 4px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    z-index: 1000;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    max-height: 250px;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.custom-multi-select.open .select-dropdown {
    opacity: 1;
    pointer-events: all;
}

.select-actions {
    display: flex;
    gap: .5rem;
    padding: .5rem;
    border-bottom: 1px solid var(--border);
}

.select-actions button {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: .25rem;
    font-size: .7rem;
    border-radius: 4px;
    cursor: pointer;
    transition: background .2s;
}

.select-actions button:hover {
    background: var(--border);
}

.select-options {
    overflow-y: auto;
    padding: .25rem 0;
}

.select-option {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .4rem .75rem;
    cursor: pointer;
    transition: background .2s;
}

.select-option:hover {
    background: var(--surface);
}

.select-option input[type="checkbox"] {
    margin: 0;
    cursor: pointer;
    appearance: auto;
    width: auto;
    padding: 0;
    accent-color: var(--accent);
}

.sidebar-footer { padding: 1rem 1.25rem; border-top: 1px solid var(--border); }

.btn-refresh {
    width: 100%;
    background: var(--text);
    color: var(--bg);
    border: none;
    padding: .7rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: .8rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    transition: opacity .2s;
    font-family: inherit;
}

.btn-refresh:hover { opacity: .82; }

/* ── Main ── */
.main {
    margin-left: var(--sidebar-w);
    flex: 1;
    padding: 1.75rem 2rem 3rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    max-width: 100%;
    overflow-x: hidden;
}

/* ── Top bar ── */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 2rem;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: .5rem;
}

#mobile-menu-btn {
    display: none;
}

.mobile-nav-bar {
    display: contents;
}

.topbar-title-group {
    order: -1;
}

.mobile-top-logo {
    display: none;
}

.topbar h1 {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -.035em;
}

.topbar-sub { color: var(--text2); font-size: .78rem; margin-top: .15rem; }

.theme-btn, .menu-btn {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    cursor: pointer;
    font-size: 1.1rem;
    transition: transform .15s, background .15s;
}

.theme-btn:hover, .menu-btn:hover { transform: scale(1.1); background: var(--surface2); }

/* ═══ FINANCIAL KPIs ═══ */
.row-finance {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}

.fin-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 1rem;
    display: flex;
    flex-direction: column;
    gap: .2rem;
    box-shadow: var(--shadow);
    transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}

.fin-card:hover { 
    transform: translateY(-2px); 
    box-shadow: var(--shadow-hover);
    border-color: var(--border-hover);
}

.fin-label {
    font-size: .6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text2);
}

.fin-value {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -.025em;
    font-variant-numeric: tabular-nums;
}

.fin-income  .fin-value { color: var(--green); }
.fin-spend   .fin-value { color: var(--red); }
.fin-roi     .fin-value { color: var(--accent); }
.fin-leads   .fin-value { color: var(--text); }
.fin-agendado .fin-value { color: var(--blue); }
.fin-cpl     .fin-value { color: var(--text2); }

/* ═══ CARD ═══ */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    transition: background .35s, border-color .35s;
    position: relative;
}

.card-title {
    font-size: .8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    display: flex;
    align-items: center;
    gap: .4rem;
    margin-bottom: 1rem;
    color: var(--text2);
}

.card-title i { font-size: 1rem; }

.card-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 1rem; }
.card-head .card-title { margin-bottom: 0; }
.card-hint { font-size: .72rem; color: var(--text2); margin-top: .2rem; display: block; }

.chart-box { position: relative; width: 100%; }

/* ── Timeline Toggles ── */
.timeline-toggles {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    margin-bottom: 1rem;
}

.chip {
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text2);
    padding: .35rem .75rem;
    border-radius: 20px;
    font-size: .7rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .2s;
}

.chip:hover { border-color: var(--text2); color: var(--text); }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }

/* ── Segmented Control ── */
.segmented-control {
    display: flex;
    background: var(--surface2);
    padding: 3px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.segment {
    background: transparent;
    border: none;
    padding: .4rem .8rem;
    border-radius: 6px;
    font-size: .7rem;
    font-weight: 600;
    color: var(--text2);
    cursor: pointer;
    transition: all .2s;
}

.segment:hover { color: var(--text); }
.segment.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* ═══ PIPELINE ═══ */
.funnel-visual {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .5rem 0;
}

.funnel-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .5rem;
    flex: 1;
    position: relative;
}

.funnel-step:not(:last-child)::after {
    content: '';
    position: absolute;
    top: 22px;
    left: 56%;
    width: calc(100% - 12%);
    height: 2px;
    background: var(--border);
    z-index: 0;
}

.funnel-circle {
    width: 46px; height: 46px;
    border-radius: 50%;
    background: var(--bg);
    border: 2.5px solid var(--text2);
    display: grid; place-items: center;
    font-weight: 700;
    font-size: 1.05rem;
    z-index: 1;
    transition: transform .12s;
}

.funnel-step:hover .funnel-circle { transform: scale(1.1); }

.funnel-label {
    font-size: .65rem;
    font-weight: 700;
    color: var(--text2);
    text-transform: uppercase;
    text-align: center;
    letter-spacing: .03em;
}

/* Funnel colors: Leads=gray, Contato=YELLOW, Agendado=BLUE, Pago=green, Cancel=red */
.step-1 .funnel-circle { border-color: #8e8e93; color: #8e8e93; }
.step-2 .funnel-circle { border-color: var(--yellow); color: var(--yellow); }
.step-3 .funnel-circle { border-color: var(--blue);   color: var(--blue); }
.step-4 .funnel-circle { border-color: var(--green);  color: var(--green); }
.step-5 .funnel-circle { border-color: var(--red);    color: var(--red); }

/* ═══ CAMPAIGNS × LEADS CHART ROW ═══ */
.row-charts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}

/* ═══ TABLE ═══ */
.table-scroll { overflow-x: auto; }

.campaign-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: .8rem;
}

.campaign-table th,
.campaign-table td {
    padding: .7rem .85rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    white-space: nowrap;
}

.campaign-table th {
    font-size: .6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text2);
    background: rgba(255,255,255,0.8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 0;
}

.campaign-table th .resizer {
    resize: horizontal;
    overflow: hidden;
    padding: .7rem .85rem;
    min-width: 60px;
    width: 100%;
    display: flex;
    align-items: center;
    gap: 4px;
}

.campaign-table tfoot td {
    font-weight: 700;
    border-top: 2px solid var(--border);
    background: var(--surface);
    color: var(--text);
    position: sticky;
    bottom: 0;
    z-index: 10;
}

[data-theme="dark"] .campaign-table th {
    background: rgba(10,10,10,0.8);
}

.campaign-table th.sortable {
    cursor: pointer;
    user-select: none;
    transition: color .12s;
}

.campaign-table th.sortable:hover { color: var(--text); }

.campaign-table th.sortable i {
    margin-left: .2rem;
    font-size: .7rem;
    opacity: .3;
    vertical-align: middle;
    transition: opacity .12s;
}

.campaign-table th.sortable.active i { opacity: 1; color: var(--accent); }

.campaign-table tbody tr { transition: background .1s; }
.campaign-table tbody tr:hover { background: var(--surface2); }

.campaign-table td.money { font-weight: 600; font-variant-numeric: tabular-nums; }
.campaign-table td.roi-positive { color: var(--green); font-weight: 700; }
.campaign-table td.roi-negative { color: var(--red); font-weight: 700; }

/* ═══ BOTTOM ROW ═══ */
.row-bottom {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}

/* ── Insights ── */
#insights-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: .6rem;
}

#insights-list li {
    padding: .85rem 1rem;
    background: var(--surface2);
    border-radius: 8px;
    border-left: 3px solid var(--accent);
    font-size: .82rem;
    line-height: 1.55;
    color: var(--text2);
}

#insights-list li strong { color: var(--text); }

/* ═══ AI CONFIG (Sidebar) ═══ */
.sidebar-section {
    padding: .75rem 1.25rem;
    border-top: 1px solid var(--border);
}

.sidebar-section-title {
    font-size: .65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--accent);
    display: flex;
    align-items: center;
    gap: .35rem;
    margin-bottom: .6rem;
}

.api-key-row {
    display: flex;
    gap: .35rem;
}

.api-key-row input {
    flex: 1;
    background: var(--input-bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: .5rem .65rem;
    border-radius: 6px;
    font-size: .78rem;
    font-family: inherit;
    outline: none;
}

.api-key-row input:focus { border-color: var(--accent); }

.btn-icon {
    background: var(--input-bg);
    border: 1px solid var(--border);
    color: var(--text2);
    width: 32px; height: 32px;
    border-radius: 6px;
    display: grid; place-items: center;
    cursor: pointer;
    font-size: .9rem;
    transition: color .15s;
}

.btn-icon:hover { color: var(--text); }

.key-status {
    font-size: .68rem;
    margin-top: .25rem;
    display: block;
}

.key-status.saved { color: var(--green); }
.key-status.empty { color: var(--text2); }

/* ═══ AI ANALYZE BUTTON & CONFIRM ═══ */
.ai-controls {
    display: flex;
    align-items: center;
    gap: .75rem;
}

.token-estimate {
    font-size: .7rem;
    color: var(--text2);
    font-variant-numeric: tabular-nums;
}

.btn-ai {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: .45rem .9rem;
    border-radius: 6px;
    font-size: .75rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: .3rem;
    font-family: inherit;
    transition: opacity .15s;
}

.btn-ai:hover:not(:disabled) { opacity: .85; }
.btn-ai:disabled { opacity: .4; cursor: not-allowed; }

.btn-ai.loading {
    pointer-events: none;
    opacity: .6;
}

.ai-confirm-bar {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: .65rem 1rem;
    margin-bottom: .75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: .78rem;
    color: var(--text2);
    gap: .75rem;
}

.ai-confirm-bar span { flex: 1; }

.btn-ai-sm {
    border: none;
    padding: .35rem .7rem;
    border-radius: 5px;
    font-size: .72rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: opacity .15s;
}

.btn-ai-go {
    background: var(--green);
    color: #000;
    margin-right: .35rem;
}

.btn-ai-cancel {
    background: var(--surface);
    color: var(--text2);
    border: 1px solid var(--border);
}

.btn-ai-sm:hover { opacity: .82; }

/* ═══ RESPONSIVE ═══ */
@media (max-width: 1400px) {
    .row-finance { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 1024px) {
    .row-finance { grid-template-columns: repeat(2, 1fr); }
    .row-bottom, .row-charts { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .app { flex-direction: column; overflow-x: hidden; }
    
    #mobile-menu-btn { display: flex; }
    
    .sidebar {
        position: fixed;
        right: -320px;
        left: auto;
        width: 300px;
        height: 100vh;
        border-right: none;
        border-left: 1px solid var(--border);
        transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 9999;
        box-shadow: -4px 0 24px rgba(0,0,0,0.1);
        padding-bottom: 5rem;
    }
    
    .sidebar-brand { display: none; }
    
    .topbar {
        display: flex;
        flex-direction: column;
        align-items: stretch;
    }
    
    .mobile-nav-bar {
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 100%;
        background-color: var(--accent);
        padding: 0.75rem 1.25rem;
        border-radius: 12px;
        box-shadow: 0 4px 12px rgba(0,0,0,0.1);
        margin-bottom: 1.5rem;
    }
    
    .mobile-nav-logo-wrapper {
        display: flex;
        align-items: center;
        justify-content: flex-start;
    }

    .mobile-top-logo {
        display: block;
        max-height: 40px;
        margin: 0;
    }
    
    .topbar-title-group {
        text-align: center;
        margin-bottom: 1rem;
        order: 0;
    }
    
    .sidebar.open {
        right: 0;
    }

    /* Mobile overlay when menu is open */
    .sidebar-overlay {
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 9998;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s;
    }
    .sidebar-overlay.open {
        opacity: 1;
        pointer-events: all;
    }

    .main { margin-left: 0; padding: 1rem; width: 100%; }
    .row-finance { grid-template-columns: 1fr 1fr; }
}
