/* =============================================================
   Dashboard CO2 - Cia Verde
   Design System: Dark Theme (moderado), Eco-friendly
   ============================================================= */

:root {
    /* Backgrounds */
    --bg-primary: #171b24;
    --bg-secondary: #1e2430;
    --bg-tertiary: #252c3a;
    --bg-hover: #2b3344;

    /* Borders */
    --border: #2d3545;
    --border-light: #353e50;

    /* Text */
    --text-primary: #e4e9f2;
    --text-secondary: #8892a4;
    --text-muted: #5f6b80;

    /* Accent Colors */
    --green: #22c55e;
    --green-dim: rgba(34, 197, 94, 0.12);
    --red: #ef4444;
    --red-dim: rgba(239, 68, 68, 0.12);
    --orange: #f97316;
    --orange-dim: rgba(249, 115, 22, 0.12);
    --yellow: #eab308;
    --yellow-dim: rgba(234, 179, 8, 0.12);
    --blue: #3b82f6;
    --blue-dim: rgba(59, 130, 246, 0.12);
    --purple: #a855f7;
    --purple-dim: rgba(168, 85, 247, 0.12);
    --teal: #14b8a6;

    /* Chart palette */
    --chart-1: #22c55e;
    --chart-2: #ef4444;
    --chart-3: #3b82f6;
    --chart-4: #f97316;
    --chart-5: #a855f7;
    --chart-6: #eab308;

    /* Sizing */
    --radius: 10px;
    --radius-sm: 6px;
    --header-height: 72px;

    /* Transitions */
    --transition: 180ms ease;
}

/* RESET & BASE */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* SCROLLBAR */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* =============================================================
   HEADER
   ============================================================= */
.header {
    position: sticky;
    top: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 28px;
    height: var(--header-height);
    background: rgba(23, 27, 36, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-shrink: 0;
}

.logo-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    background: var(--green-dim);
    color: var(--green);
}

.header-title {
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.3px;
}

.header-subtitle {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 400;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    overflow-x: auto;
}

/* DATE FILTER */
.date-filter {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: nowrap;
}

.month-pills {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.month-pill {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 12px;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.month-pill:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--border-light);
}

.month-pill.active {
    background: var(--green-dim);
    color: var(--green);
    border-color: var(--green);
}

.date-range-inputs {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.date-input {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 12px;
    outline: none;
    transition: var(--transition);
}

.date-input:focus {
    border-color: var(--green);
}

.date-separator {
    font-size: 12px;
    color: var(--text-muted);
}

.btn-filter {
    padding: 6px 16px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--green);
    color: #fff;
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-filter:hover {
    background: #1aad50;
    transform: translateY(-1px);
}

/* =============================================================
   MAIN CONTENT
   ============================================================= */
.main-content {
    max-width: 1440px;
    margin: 0 auto;
    padding: 24px 28px 48px;
}

/* =============================================================
   KPI CARDS
   ============================================================= */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 14px;
    margin-bottom: 20px;
}

.kpi-card {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 18px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: var(--transition);
}

.kpi-card:hover {
    background: var(--bg-tertiary);
    border-color: var(--border-light);
    transform: translateY(-2px);
}

.kpi-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    flex-shrink: 0;
}

.icon-green { background: var(--green-dim); color: var(--green); }
.icon-red { background: var(--red-dim); color: var(--red); }
.icon-orange { background: var(--orange-dim); color: var(--orange); }
.icon-yellow { background: var(--yellow-dim); color: var(--yellow); }
.icon-blue { background: var(--blue-dim); color: var(--blue); }
.icon-purple { background: var(--purple-dim); color: var(--purple); }

.kpi-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.kpi-label {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 4px;
}

.kpi-value {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.5px;
    line-height: 1.1;
}

.kpi-unit {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* =============================================================
   CHART CARDS
   ============================================================= */
.charts-row {
    display: flex;
    gap: 14px;
    margin-bottom: 14px;
}

.chart-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: var(--transition);
}

.chart-card:hover {
    border-color: var(--border-light);
}

.chart-wide { flex: 2; }
.chart-narrow { flex: 1; min-width: 280px; }
.chart-half { flex: 1; }
.chart-full { flex: 1; width: 100%; }

.chart-header {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 8px;
    padding: 16px 20px 0;
}

.chart-title {
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -0.2px;
}

.chart-subtitle {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 400;
}

.chart-body {
    padding: 12px 16px 16px;
    position: relative;
    height: 280px;
}

.chart-body-small {
    height: 220px;
}

/* DONUT CHART */
.chart-body-donut {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.donut-center {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none;
}

.donut-pct {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
}

.donut-label {
    font-size: 11px;
    color: var(--text-muted);
}

/* =============================================================
   HEATMAP
   ============================================================= */
.heatmap-container {
    height: 480px;
    border-radius: 0 0 var(--radius) var(--radius);
}

/* Leaflet dark tiles adjustments */
.leaflet-container {
    background: var(--bg-primary) !important;
}

.leaflet-control-attribution {
    background: rgba(30, 36, 48, 0.8) !important;
    color: var(--text-muted) !important;
    font-size: 10px !important;
}

.leaflet-control-attribution a {
    color: var(--text-secondary) !important;
}

.leaflet-control-zoom a {
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border) !important;
}

.leaflet-control-zoom a:hover {
    background: var(--bg-tertiary) !important;
}

/* =============================================================
   TABLE
   ============================================================= */
.table-search {
    margin-left: auto;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 12px;
    outline: none;
    width: 200px;
    transition: var(--transition);
}

.table-search:focus {
    border-color: var(--green);
    width: 260px;
}

.table-search::placeholder {
    color: var(--text-muted);
}

.table-wrapper {
    max-height: 480px;
    overflow: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12.5px;
}

.data-table thead {
    position: sticky;
    top: 0;
    z-index: 2;
}

.data-table th {
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table td {
    padding: 9px 14px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    transition: var(--transition);
}

.data-table tbody tr:hover td {
    background: var(--bg-hover);
}

.data-table .cell-placa {
    font-weight: 600;
    color: var(--text-primary);
}

.data-table .cell-danger {
    color: var(--red);
    font-weight: 600;
}

.data-table .cell-warning {
    color: var(--orange);
    font-weight: 600;
}

.data-table .cell-ok {
    color: var(--green);
    font-weight: 600;
}

/* =============================================================
   LOADING
   ============================================================= */
.loading-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(23, 27, 36, 0.7);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 14px;
    font-size: 14px;
    color: var(--text-secondary);
}

.loading-overlay.show {
    display: flex;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--green);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* =============================================================
   RESPONSIVE
   ============================================================= */
@media (max-width: 1280px) {
    .kpi-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 900px) {
    .header {
        flex-direction: column;
        height: auto;
        padding: 14px 16px;
        gap: 10px;
    }

    .header-right {
        width: 100%;
    }

    .date-filter {
        flex-wrap: wrap;
        width: 100%;
    }

    .month-pills {
        overflow-x: auto;
        width: 100%;
        padding-bottom: 4px;
    }

    .main-content {
        padding: 16px 12px 32px;
    }

    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .charts-row {
        flex-direction: column;
    }

    .chart-narrow {
        min-width: unset;
    }

    .heatmap-container {
        height: 350px;
    }
}

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

    .kpi-value {
        font-size: 20px;
    }
}

/* LEGENDA DO MAPA DE CALOR */
.chart-header-map {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 16px;
    padding-bottom: 14px;
}

.map-legend {
    display: flex;
    gap: 14px;
    align-items: center;
    font-size: 11px;
    color: var(--text-secondary);
    margin-left: auto;
    flex-shrink: 0;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
}

.legend-color {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    box-shadow: 0 0 5px currentColor;
}

.legend-color.color-blue { background: #3b82f6; color: #3b82f6; }
.legend-color.color-green { background: #10b981; color: #10b981; }
.legend-color.color-yellow { background: #eab308; color: #eab308; }
.legend-color.color-orange { background: #f97316; color: #f97316; }
.legend-color.color-red { background: #ef4444; color: #ef4444; }

@media (max-width: 768px) {
    .chart-header-map {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .map-legend {
        margin-left: 0;
        flex-wrap: wrap;
        gap: 8px;
    }
}
