/* ===========================================
   DASHBOARD STELLA - CSS RESPONSIVO
   =========================================== */

/* Reset e Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 100%);
    min-height: 100vh;
    padding: clamp(10px, 2vw, 20px);
    color: #ffff;
    transition: background 0.3s ease, color 0.3s ease;
    overflow-x: hidden;
}

/* Container Principal */
.dashboard {
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
    overflow-x: hidden;
}

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

.header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: clamp(12px, 2vw, 20px);
    padding: clamp(15px, 3vw, 25px);
    margin-bottom: clamp(15px, 2vw, 25px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
    display: flex; 
    flex-wrap: wrap; 
    align-items: center;
    gap: 15px;
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

.header-content {
    flex: 1;
    min-width: 250px;
}

.header h1 {
    color: #1e40af;
    font-size: clamp(1.8em, 4vw, 2.8em);
    margin-bottom: 8px;
    font-weight: 800;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
    transition: color 0.3s ease;
    word-break: break-word;
}

.header .subtitle {
    color: #1e40af;
    font-size: clamp(1em, 2.5vw, 1.3em);
    font-weight: 600;
    transition: color 0.3s ease;
}

#toggle-dark-mode {
    padding: clamp(8px, 1.5vw, 12px) clamp(15px, 3vw, 20px);
    font-size: clamp(0.8em, 1.5vw, 0.9em);
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

#toggle-dark-mode:hover {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(37, 99, 235, 0.4);
}

/* Status Bar */
.status-bar {
    display: flex;
    gap: clamp(10px, 1.5vw, 15px);
    flex-wrap: wrap;
    width: 100%;
    margin-top: 15px;
    justify-content: flex-start;
}

.status-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: clamp(8px, 1.2vw, 10px) clamp(14px, 1.8vw, 18px);
    border-radius: 22px;
    font-weight: 700;
    font-size: clamp(0.85em, 1.5vw, 0.95em);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border: 2px solid transparent;
    white-space: nowrap;
    min-width: fit-content;
}

.status-online {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    border-color: #34d399;
    animation: pulse-green 2s infinite;
}

.status-warning {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: white;
    border-color: #fbbf24;
    animation: pulse-orange 2s infinite;
}

.status-info {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    border-color: #60a5fa;
}

/* ===========================================
   GRID SYSTEM
   =========================================== */

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: clamp(15px, 2vw, 25px);
    margin-bottom: clamp(15px, 2vw, 25px);
}

/* Grid específico para diferentes seções */
.grid-2 {
    grid-template-columns: repeat(auto-fit, minmax(450px, 1fr));
}

.grid-3 {
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

/* ===========================================
   CARDS
   =========================================== */

.card {
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(15px);
    border-radius: clamp(12px, 2vw, 20px);
    padding: clamp(15px, 2.5vw, 30px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
    border: 2px solid rgba(255, 255, 255, 0.3);
    display: flex;
    flex-direction: column;
    min-height: fit-content;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}

.card-title {
    font-size: clamp(1.2em, 2.5vw, 1.5em);
    font-weight: 800;
    color: #1e40af;
    margin-bottom: clamp(15px, 2vw, 25px);
    display: flex;
    align-items: center;
    gap: 10px;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
    transition: color 0.3s ease;
    flex-wrap: wrap;
}

/* ===========================================
   METRICS
   =========================================== */

.metric {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: clamp(10px, 2vw, 15px) 0;
    border-bottom: 2px solid #e5e7eb;
    font-size: clamp(0.9em, 1.8vw, 1.1em);
    transition: border-color 0.3s ease;
    gap: 15px;
}

.metric:last-child {
    border-bottom: none;
}

.metric-label {
    color: #374151;
    font-weight: 700; 
    font-size: 1em;
    transition: color 0.3s ease;
    flex: 1;
}

.metric-value {
    font-weight: 800;
    font-size: clamp(1.1em, 2vw, 1.3em);
    text-align: right;
}

.metric-value.updated {
    animation: value-updated 1.5s ease-out;
}

/* Metric Color Classes */
.metric-success {
    color: #059669;
    text-shadow: 1px 1px 2px rgba(5, 150, 105, 0.3);
}

.metric-warning {
    color: #d97706;
    text-shadow: 1px 1px 2px rgba(217, 119, 6, 0.3);
}

.metric-danger {
    color: #dc2626;
    text-shadow: 1px 1px 2px rgba(220, 38, 38, 0.3);
}

.metric-primary {
    color: #2563eb;
    text-shadow: 1px 1px 2px rgba(37, 99, 235, 0.3);
}

/* ===========================================
   BIG NUMBERS
   =========================================== */

.big-number {
    text-align: center;
    padding: clamp(15px, 3vw, 25px) 0;
}

.big-number-value {
    font-size: clamp(2.5em, 6vw, 4em);
    font-weight: 900;
    color: #1e40af;
    line-height: 1;
    text-shadow: 3px 3px 6px rgba(30, 64, 175, 0.3);
    transition: color 0.3s ease;
    word-break: break-all;
}

.big-number-label {
    color: #6b7280;
    font-size: clamp(1em, 2vw, 1.3em);
    margin-top: 15px;
    font-weight: 700; 
    transition: color 0.3s ease;
}

/* ===========================================
   PROGRESS BARS
   =========================================== */

.progress-bar {
    width: 100%;
    height: 12px;
    background: #e5e7eb;
    border-radius: 6px;
    overflow: hidden;
    margin-top: 12px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: background 0.3s ease;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #10b981, #059669);
    transition: width 0.3s ease;
    box-shadow: 0 2px 4px rgba(16, 185, 129, 0.4);
}

/* ===========================================
   CHARTS AND MAPS
   =========================================== */

.chart-placeholder, .map-container {
    height: clamp(200px, 40vw, 400px);
    max-height: 400px;
    background: linear-gradient(45deg, #f8fafc, #f1f5f9);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #64748b;
    font-style: italic;
    border: 3px dashed #cbd5e0;
    font-size: clamp(0.9em, 1.8vw, 1.1em);
    font-weight: 600;
    transition: background 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

.pie-chart-container {
    position: relative;
    height: clamp(250px, 35vw, 350px);
    max-height: 350px;
}

.map-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.8);
    z-index: 1000;
}

.spinner {
    border: 3px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    border-top: 3px solid #3B82F6;
    width: 30px;
    height: 30px;
    animation: spin 1s linear infinite;
    margin-bottom: 10px;
}

/* ===========================================
   CONVERSATIONS
   =========================================== */

.conversation-list {
    max-height: clamp(250px, 40vh, 350px);
    overflow-y: auto;
    scroll-behavior: smooth;
}

.conversation-item {
    padding: clamp(10px, 2vw, 15px);
    border-bottom: 2px solid #e5e7eb;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    font-size: clamp(0.9em, 1.6vw, 1.05em);
    transition: border-color 0.3s ease;
    gap: 10px;
}

.conversation-item:last-child {
    border-bottom: none;
}

.conversation-info {
    flex: 1;
    min-width: 150px;
}

.conversation-phone {
    font-weight: 700;
    color: #1f2937;
    font-size: 1.1em;
    transition: color 0.3s ease;
    word-break: break-all;
}

.conversation-time {
    font-size: 1em;
    color: #6b7280;
    font-weight: 500;
    transition: color 0.3s ease;
}

.conversation-status {
    padding: clamp(6px, 1vw, 8px) clamp(10px, 2vw, 15px);
    border-radius: 20px;
    font-size: clamp(0.8em, 1.4vw, 0.9em);
    font-weight: 700;
    white-space: nowrap;
}

.status-active {
    background: linear-gradient(135deg, #d1fae5, #a7f3d0);
    color: #065f46;
    border: 2px solid #34d399;
}

.status-waiting {
    background: linear-gradient(135deg, #c7defe, #8ab2fd);
    color: #2493fb;
    border: 2px solid #0e0e92;
}

.status-intervention {
    background: linear-gradient(135deg, #fee2e2, #fecaca);
    color: #b91c1c;
    border: 2px solid #f87171;
}

/* ===========================================
   BENCHMARKS AND TRENDS
   =========================================== */

.benchmark {
    margin-top: clamp(15px, 3vw, 28px);
    padding: clamp(10px, 2vw, 15px);
    background: rgba(59, 130, 246, 0.1);
    border-radius: 12px;
    font-size: clamp(0.9em, 1.6vw, 1.05em);
    border: 2px solid rgba(59, 130, 246, 0.2);
    transition: background 0.3s ease, border-color 0.3s ease;
}

.benchmark-label {
    color: #374151;
    font-weight: 600;
    transition: color 0.3s ease;
}

.benchmark-value {
    font-weight: 700;
    margin-left: 8px;
    font-size: 1.1em;
}

.benchmark-neutral {
    color: #374151;
    transition: color 0.3s ease;
}

.trend {
    margin-top: 18px;
    font-size: clamp(0.8em, 1.5vw, 1em);
    font-weight: 700;
    padding: 8px 15px;
    border-radius: 20px;
    text-align: center;
    border: 2px solid transparent;
}

.trend-up {
    background: linear-gradient(135deg, #d1fae5, #a7f3d0);
    color: #065f46;
    border-color: #34d399;
}

.trend-down {
    background: linear-gradient(135deg, #fef2f2, #fecaca);
    color: #991b1b;
    border-color: #f87171;
}

.trend-neutral {
    background: linear-gradient(135deg, #dbeafe, #bfdbfe);
    color: #1e40af;
    border-color: #60a5fa;
}

.metric-with-benchmark {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
}

.benchmark-small {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.benchmark-label-small {
    color: #6b7280;
    font-weight: 600;
    transition: color 0.3s ease;
    font-size: clamp(0.8em, 1.4vw, 0.85em);
}

.trend-small { 
    font-size: 0.9em; 
    font-weight: 700; 
}

.trend-up-small { 
    color: #059669; 
}

.trend-down-small { 
    color: #dc2626; 
}

.trend-neutral-small { 
    color: #2563eb; 
}

/* ===========================================
   STATUS INDICATORS
   =========================================== */

.status-indicator {
    padding: clamp(4px, 1vw, 6px) clamp(8px, 1.5vw, 12px);
    border-radius: 15px;
    font-size: clamp(0.8em, 1.4vw, 0.9em);
    font-weight: bold;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.status-indicator.online {
    background-color: #d1fae5;
    color: #065f46;
    border: 1px solid #34d399;
}

.status-indicator.offline {
    background-color: #fef2f2;
    color: #991b1b;
    border: 1px solid #f87171;
}

.status-indicator.checking {
    background-color: #fef3c7;
    color: #92400e;
    border: 1px solid #fbbf24;
}

.status-indicator.partial {
    background-color: #ffedd5;
    color: #9a3412;
    border: 1px solid #fb923c;
}

/* ===========================================
   BUTTONS
   =========================================== */

.btn {
    padding: 15px 25px;
    border: none;
    border-radius: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
    text-align: center;
    font-size: 1.05em;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn-primary {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(37, 99, 235, 0.4);
}

.btn-danger {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
}

.btn-danger:hover {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(220, 38, 38, 0.4);
}

/* ===========================================
   ALERTS
   =========================================== */

.alert {
    background: linear-gradient(135deg, #fef2f2, #fee2e2);
    border: 2px solid #fca5a5;
    border-radius: 12px;
    padding: 18px;
    margin-bottom: 15px;
    color: #991b1b;
    font-weight: 600;
    font-size: 1.05em;
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.15);
    animation: slide-alert 0.5s ease-out;
    transition: background 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

.alert:last-child {
    margin-bottom: 0;
}

/* ===========================================
   UTILITY CLASSES
   =========================================== */

.icon {
    width: 24px; 
    height: 24px; 
    display: inline-flex; 
    align-items: center;
    justify-content: center;
}

.critical-number {
    font-size: 4.5em !important;
    font-weight: 900 !important;
    text-shadow: 4px 4px 8px rgba(0, 0, 0, 0.3) !important;
    animation: pulse-critical 3s infinite;
}

.last-update {
    text-align: center;
    color: #a0aec0;
    font-size: clamp(0.8em, 1.4vw, 0.9em);
    margin-top: 20px;
    transition: color 0.3s ease;
}

.pulse { 
    animation: pulse 2s infinite; 
}

.custom-marker-leads {
    background: none !important;
    border: none !important;
}

/* ===========================================
   ANIMATIONS
   =========================================== */

@keyframes pulse-green {
    0%, 100% { box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4); transform: scale(1); }
    50% { box-shadow: 0 8px 20px rgba(16, 185, 129, 0.6); transform: scale(1.02); }
}

@keyframes pulse-orange {
    0%, 100% { box-shadow: 0 4px 12px rgba(245, 158, 11, 0.4); transform: scale(1); }
    50% { box-shadow: 0 8px 20px rgba(245, 158, 11, 0.6); transform: scale(1.02); }
}

@keyframes slide-alert {
    0% { transform: translateX(-100%); opacity: 0; }
    100% { transform: translateX(0); opacity: 1; }
}

@keyframes pulse-critical {
    0%, 100% { color: #dc2626; }
    50% { color: #ef4444; }
}

@keyframes value-updated { 
    0% { background-color: transparent; }
    25% { background-color: rgba(255, 223, 186, 0.5); } 
    100% { background-color: transparent; }
}

@keyframes pulse { 
    0%, 100% { opacity: 1; } 
    50% { opacity: 0.7; } 
}

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

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* ===========================================
   DARK MODE
   =========================================== */

body.dark-mode {
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    color: #f8fafc; 
}

body.dark-mode .header {
    background: rgba(15, 23, 42, 0.98); 
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}

body.dark-mode .header h1,
body.dark-mode .header .subtitle {
    color: #3b82f6; 
}

body.dark-mode .card {
    background: rgba(15, 23, 42, 0.95); 
    border-color: rgba(71, 85, 105, 0.5);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}

body.dark-mode .card:hover {
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

body.dark-mode .card-title {
    color: #7f9cf5; 
}

body.dark-mode .metric-label,
body.dark-mode .benchmark-label,
body.dark-mode .big-number-label,
body.dark-mode .conversation-time,
body.dark-mode .benchmark-label-small {
    color: #cbd5e1; 
}

body.dark-mode .chart-placeholder,
body.dark-mode .map-container {
    color: #cbd5e1; 
    border-color: #475569; 
    background: linear-gradient(45deg, #0f172a, #1e293b); 
}

body.dark-mode .big-number-value { 
    color: #3b82f6; 
}

body.dark-mode .metric-value.metric-success { 
    color: #68d391; 
} 

body.dark-mode .metric-value.metric-warning { 
    color: #faf089; 
} 

body.dark-mode .metric-value.metric-danger { 
    color: #fc8181; 
}  

body.dark-mode .metric-value.metric-primary { 
    color: #7f9cf5; 
}  

body.dark-mode .progress-bar { 
    background: #2d3748; 
}

body.dark-mode .progress-fill { 
    background: linear-gradient(90deg, #38a169, #2f855a); 
}

body.dark-mode .alert {
    background: linear-gradient(135deg, #4a1d1d, #5c2323); 
    color: #fecaca; 
    border-color: #f87171; 
}

body.dark-mode .conversation-phone { 
    color: #e2e8f0; 
}

body.dark-mode .conversation-item,
body.dark-mode .metric {
    border-color: #4a5568; 
}

body.dark-mode .benchmark {
    background: rgba(127, 156, 245, 0.1); 
    border-color: rgba(127, 156, 245, 0.2);
}

body.dark-mode .benchmark-neutral { 
    color: #a0aec0; 
}

body.dark-mode .last-update { 
    color: #718096; 
}

body.dark-mode .status-active {
    background: linear-gradient(135deg, #2c5242, #1e3b2f); 
    color: #a7f3d0; 
    border-color: #34d399;
}

body.dark-mode .status-waiting {
    background: linear-gradient(135deg, #0a256b, #09185c); 
    color: #8a93fd; 
    border-color: #2444fb;
}

body.dark-mode .status-intervention {
    background: linear-gradient(135deg, #7f1d1d, #991b1b); 
    color: #fecaca; 
    border-color: #f87171; 
}

/* Dark mode para status das integrações */
body.dark-mode .status-indicator.online {
    background-color: #065f46; 
    color: #d1fae5; 
    border-color: #34d399;
}

body.dark-mode .status-indicator.offline {
    background-color: #991b1b; 
    color: #fef2f2; 
    border-color: #f87171;
}

body.dark-mode .status-indicator.checking {
    background-color: #92400e; 
    color: #fef3c7; 
    border-color: #fbbf24;
}

body.dark-mode .status-indicator.partial {
    background-color: #7c2d12; 
    color: #ffedd5; 
    border-color: #fb923c;
}

body.dark-mode .map-loading {
    background: rgba(45, 55, 72, 0.8);
}

/* ===========================================
   RESPONSIVE BREAKPOINTS
   =========================================== */

/* Mobile-First: Telas pequenas (até 768px) */
@media (max-width: 768px) {
    body {
        padding: 8px;
        overflow-x: hidden;
    }
    
    .dashboard {
        width: 100%;
        max-width: 100vw;
        overflow-x: hidden;
    }
    
    .grid,
    .grid-2,
    .grid-3 {
        grid-template-columns: 1fr;
        gap: 12px;
        width: 100%;
        max-width: 100%;
    }
    
    .card {
        width: 100%;
        max-width: 100%;
        margin: 0;
        padding: 15px;
        overflow: hidden;
        word-wrap: break-word;
    }
    
    .status-bar {
        flex-direction: column;
        gap: 8px;
        align-items: stretch;
        width: 100%;
    }
    
    .status-item {
        justify-content: center;
        min-width: auto;
        flex: 1;
        padding: 12px 20px;
        font-size: 0.9em;
        gap: 8px;
        border-radius: 25px;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }
    
    .header {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
        max-width: 100%;
        padding: 15px;
    }
    
    #toggle-dark-mode {
        margin-top: 15px;
        align-self: center;
        width: 100%;
        max-width: 250px;
    }
    
    .metric {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        width: 100%;
    }
    
    .metric-label,
    .metric-value {
        max-width: 100%;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    .metric-with-benchmark {
        align-items: flex-start;
        width: 100%;
    }
    
    .conversation-item {
        flex-direction: column;
        align-items: flex-start;
        width: 100%;
        padding: 12px;
    }
    
    .conversation-status {
        align-self: flex-start;
    }
    
    .chart-placeholder, .map-container {
        height: clamp(200px, 50vw, 300px);
        width: 100%;
        max-width: 100%;
    }
    
    .pie-chart-container {
        height: clamp(200px, 40vw, 250px);
        width: 100%;
        max-width: 100%;
    }
    
    .big-number-value {
        font-size: clamp(2em, 8vw, 3.5em);
        word-break: normal;
    }
    
    .card-title {
        font-size: clamp(1.1em, 4vw, 1.3em);
        word-wrap: break-word;
    }
}

/* Tablets - MEIO TERMO: 2 cards por linha (769px até 1200px) */
@media (min-width: 769px) and (max-width: 1200px) {
    .grid,
    .grid-2,
    .grid-3 {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .status-bar {
        justify-content: flex-start;
    }
    
    .chart-placeholder, .map-container {
        height: clamp(250px, 40vw, 350px);
    }
}

/* Desktop: layout completo (1201px+) */
@media (min-width: 1201px) {
    .grid {
        grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    }
    
    .grid-2 {
        grid-template-columns: repeat(auto-fit, minmax(450px, 1fr));
    }
    
    .grid-3 {
        grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    }
    
    .status-bar {
        justify-content: flex-start;
    }
}