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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header */
.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px 0;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.header h1 {
    font-size: 2rem;
    font-weight: 700;
}

.header-info {
    margin-top: 5px;
    font-size: 0.9rem;
    opacity: 0.9;
}

/* Filters Section */
.filters {
    background: white;
    padding: 30px 0;
    margin: 20px 0;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.filters h2 {
    margin-bottom: 20px;
    color: #333;
}

.filter-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    align-items: end;
}

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

.filter-group label {
    font-weight: 600;
    margin-bottom: 5px;
    color: #555;
    font-size: 0.9rem;
}

.filter-group select,
.filter-group input {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.95rem;
    background: white;
}

.filter-group select:focus,
.filter-group input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Buttons */
.btn-primary,
.btn-secondary {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5568d3;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(102, 126, 234, 0.3);
}

.btn-secondary {
    background: #e0e0e0;
    color: #333;
}

.btn-secondary:hover {
    background: #d0d0d0;
}

/* Dashboard Section */
.dashboard {
    background: white;
    padding: 30px 0;
    margin: 20px 0;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.dashboard h2 {
    margin-bottom: 20px;
    color: #333;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

.metric-card {
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    transition: transform 0.3s ease;
}

.metric-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.metric-label {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 10px;
    font-weight: 600;
}

.metric-value {
    font-size: 2rem;
    font-weight: 700;
    color: #333;
}

/* Chart */
.chart-container {
    margin-top: 40px;
    padding: 20px;
    background: #f9f9f9;
    border-radius: 8px;
}

.chart-container h3 {
    margin-bottom: 20px;
    color: #333;
}

#performance-chart {
    max-height: 400px;
}

/* Table Section */
.table-section {
    background: white;
    padding: 30px 0;
    margin: 20px 0;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.table-section h2 {
    margin-bottom: 20px;
    color: #333;
}

.table-container {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.data-table thead {
    background: #667eea;
    color: white;
}

.data-table th,
.data-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #ddd;
}

.data-table th {
    font-weight: 600;
    position: sticky;
    top: 0;
}

.data-table tbody tr:hover {
    background: #f5f5f5;
}

.data-table tbody tr:nth-child(even) {
    background: #fafafa;
}

/* Footer */
.footer {
    background: #333;
    color: white;
    text-align: center;
    padding: 20px 0;
    margin-top: 40px;
}

/* Error Page */
.error-container {
    max-width: 600px;
    margin: 100px auto;
    padding: 40px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    text-align: center;
}

.error-message {
    color: #e74c3c;
    font-size: 1.2rem;
    margin: 20px 0;
}

.error-stack {
    text-align: left;
    margin: 20px 0;
    padding: 20px;
    background: #f5f5f5;
    border-radius: 4px;
    overflow-x: auto;
}

.error-stack pre {
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
}

/* Responsive */
@media (max-width: 768px) {
    .filter-form {
        grid-template-columns: 1fr;
    }

    .metrics-grid {
        grid-template-columns: 1fr;
    }

    .header h1 {
        font-size: 1.5rem;
    }

    .metric-value {
        font-size: 1.5rem;
    }
}

/* ============================================
   UNIFIED METRICS GRID - v0.11.0
   20 KPI cards grouped by category
   ============================================ */

.metrics-grid {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    margin: 2rem 0;
}

.metrics-section {
    background: #f8f9fa;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.metrics-section-title {
    margin: 0 0 1rem 0;
    color: #2c3e50;
    font-size: 1.25rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.kpi-cards {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 1rem;
}

.kpi-card {
    background: white;
    padding: 1.25rem;
    border-radius: 6px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    position: relative;
    transition: all 0.3s ease;
    cursor: default;
}

.kpi-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transform: translateY(-2px);
}

.kpi-card.highlight {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.kpi-icon {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
}

.kpi-label {
    font-size: 0.875rem;
    color: #6c757d;
    font-weight: 500;
    line-height: 1.2;
}

.kpi-card.highlight .kpi-label {
    color: rgba(255,255,255,0.9);
}

.kpi-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: #2c3e50;
    line-height: 1;
    margin-top: 0.25rem;
}

.kpi-card.highlight .kpi-value {
    color: white;
}

.kpi-tooltip {
    display: none;
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: white;
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    font-size: 0.75rem;
    white-space: nowrap;
    z-index: 1000;
    margin-bottom: 0.5rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.kpi-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: #333;
}

.kpi-card:hover .kpi-tooltip {
    display: block;
}

/* ============================================
   UNIFIED TABLE - v0.11.0
   20 columns for all campaigns
   ============================================ */

.table-container {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    overflow-x: auto;
    margin: 2rem 0;
}

.metrics-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    /* min-width removido - colunas se ajustam ao numero de colunas dinamicamente */
}

.metrics-table thead {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    position: sticky;
    top: 0;
    z-index: 10;
}

.metrics-table th {
    padding: 1rem 0.75rem;
    text-align: left;
    font-weight: 600;
    white-space: nowrap;
    border-bottom: 2px solid rgba(255,255,255,0.2);
    cursor: pointer;
    user-select: none;
}

.metrics-table th:hover {
    background: rgba(255,255,255,0.1);
}

.metrics-table th.sortable {
    cursor: pointer;
}

.sort-icon {
    margin-left: 0.25rem;
    opacity: 0.5;
    font-size: 0.75rem;
}

.metrics-table th:hover .sort-icon {
    opacity: 1;
}

.metrics-table tbody tr {
    border-bottom: 1px solid #e9ecef;
    transition: background-color 0.2s ease;
}

.metrics-table tbody tr:hover {
    background-color: #f8f9fa;
}

.metrics-table td {
    padding: 0.875rem 0.75rem;
    white-space: nowrap;
}

.metrics-table td.campaign-name {
    font-weight: 600;
    color: #2c3e50;
    max-width: 250px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    position: sticky;
    left: 0;
    background: white;
    z-index: 5;
}

.metrics-table tbody tr:hover td.campaign-name {
    background-color: #f8f9fa;
}

.metrics-table td.text-right {
    text-align: right;
}

.metrics-table td.highlight-good {
    color: #28a745;
    font-weight: 600;
}

.metrics-table td.cell-currency,
.metrics-table td.cell-currency-small {
    color: #007bff;
}

.metrics-table td.cell-roas {
    color: #6f42c1;
    font-weight: 600;
}

.metrics-table td.cell-percentage {
    color: #fd7e14;
}

/* Empty and Loading States */
.empty-state,
.loading-state {
    text-align: center;
    padding: 4rem 2rem;
    color: #6c757d;
}

.empty-state-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: #495057;
}

.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

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

/* ============================================
   RESPONSIVE - Mobile Optimizations
   ============================================ */

@media (max-width: 1200px) {
    .kpi-cards {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .kpi-cards {
        grid-template-columns: repeat(2, 1fr);
    }

    .metrics-section {
        padding: 1rem;
    }

    .metrics-section-title {
        font-size: 1.1rem;
    }

    .kpi-card {
        padding: 1rem;
    }

    .kpi-value {
        font-size: 1.5rem;
    }

    .table-container {
        border-radius: 0;
        margin-left: -20px;
        margin-right: -20px;
    }

    .metrics-table {
        font-size: 0.75rem;
    }

    .metrics-table th,
    .metrics-table td {
        padding: 0.5rem 0.5rem;
    }
}

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

    .kpi-value {
        font-size: 1.25rem;
    }
}

/* ========================================
   LOADING STATES & ANIMATIONS - v2.1.0
   ======================================== */

/* Full-screen Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    z-index: 9998;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(3px);
    transition: opacity 300ms ease-out;
    will-change: opacity;
}

.loading-overlay.fade-out {
    opacity: 0;
    pointer-events: none;
}

.loading-spinner-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.loading-text {
    color: #5F6368;
    font-size: 14px;
    font-weight: 500;
    animation: pulse 1.5s ease-in-out infinite;
}

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

/* Skeleton Loaders */
.skeleton {
    background: linear-gradient(
        90deg,
        #f0f0f0 25%,
        #e0e0e0 50%,
        #f0f0f0 75%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: 4px;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-table-row {
    height: 48px;
    width: 100%;
    margin-bottom: 8px;
}

/* Fade-in Animations */
.fade-in-stagger {
    opacity: 0;
    animation: fadeIn 400ms ease-out forwards;
}

/* Staggered delays for 20 metric cards (50ms interval) */
.fade-in-stagger:nth-child(1) { animation-delay: 0ms; }
.fade-in-stagger:nth-child(2) { animation-delay: 50ms; }
.fade-in-stagger:nth-child(3) { animation-delay: 100ms; }
.fade-in-stagger:nth-child(4) { animation-delay: 150ms; }
.fade-in-stagger:nth-child(5) { animation-delay: 200ms; }
.fade-in-stagger:nth-child(6) { animation-delay: 250ms; }
.fade-in-stagger:nth-child(7) { animation-delay: 300ms; }
.fade-in-stagger:nth-child(8) { animation-delay: 350ms; }
.fade-in-stagger:nth-child(9) { animation-delay: 400ms; }
.fade-in-stagger:nth-child(10) { animation-delay: 450ms; }
.fade-in-stagger:nth-child(11) { animation-delay: 500ms; }
.fade-in-stagger:nth-child(12) { animation-delay: 550ms; }
.fade-in-stagger:nth-child(13) { animation-delay: 600ms; }
.fade-in-stagger:nth-child(14) { animation-delay: 650ms; }
.fade-in-stagger:nth-child(15) { animation-delay: 700ms; }
.fade-in-stagger:nth-child(16) { animation-delay: 750ms; }
.fade-in-stagger:nth-child(17) { animation-delay: 800ms; }
.fade-in-stagger:nth-child(18) { animation-delay: 850ms; }
.fade-in-stagger:nth-child(19) { animation-delay: 900ms; }
.fade-in-stagger:nth-child(20) { animation-delay: 950ms; }

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

/* Disabled State for Filters */
.filter-disabled {
    pointer-events: none;
    opacity: 0.6;
    cursor: not-allowed;
}

/* Loading Button State */
.btn-loading {
    position: relative;
    color: transparent !important;
}

.btn-loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-left: -8px;
    margin-top: -8px;
    border: 2px solid white;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* Accessibility: Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    .fade-in-stagger,
    .loading-overlay,
    .skeleton {
        animation: none !important;
        transition: none !important;
    }

    .fade-in-stagger {
        opacity: 1;
        transform: none;
    }
}

/* ========================================
   TOAST NOTIFICATIONS - v0.29.0
   ======================================== */

/* Toast Container - Fixed position bottom-right */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 400px;
    pointer-events: none;
}

/* Individual Toast */
.toast {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    background: white;
    border-left: 4px solid;
    pointer-events: auto;
    animation: toastSlideIn 300ms ease-out;
    transform-origin: right center;
    position: relative;
    overflow: hidden;
}

.toast.hiding {
    animation: toastSlideOut 300ms ease-out forwards;
}

/* Toast Types */
.toast.toast-error {
    border-left-color: #D93025;
    background: #FEF2F2;
}

.toast.toast-warning {
    border-left-color: #F9AB00;
    background: #FFFBEB;
}

.toast.toast-info {
    border-left-color: #1A73E8;
    background: #EFF6FF;
}

.toast.toast-success {
    border-left-color: #1E8E3E;
    background: #F0FDF4;
}

/* Toast Icon */
.toast-icon {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
}

.toast-error .toast-icon { color: #D93025; }
.toast-warning .toast-icon { color: #F9AB00; }
.toast-info .toast-icon { color: #1A73E8; }
.toast-success .toast-icon { color: #1E8E3E; }

/* Toast Content */
.toast-content {
    flex: 1;
    min-width: 0;
}

.toast-title {
    font-weight: 600;
    font-size: 14px;
    color: #1C1E21;
    margin-bottom: 4px;
}

.toast-message {
    font-size: 13px;
    color: #5F6368;
    line-height: 1.4;
}

/* Toast Actions */
.toast-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.toast-action-btn {
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 500;
    border-radius: 4px;
    cursor: pointer;
    transition: all 200ms ease;
    border: none;
}

.toast-action-btn.primary {
    background: #1A73E8;
    color: white;
}

.toast-action-btn.primary:hover {
    background: #185ABC;
}

.toast-action-btn.secondary {
    background: #E0E0E0;
    color: #1C1E21;
}

.toast-action-btn.secondary:hover {
    background: #D0D0D0;
}

/* Toast Close Button */
.toast-close {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    border: none;
    background: none;
    cursor: pointer;
    color: #9AA0A6;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 200ms ease;
}

.toast-close:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #5F6368;
}

/* Toast Animations */
@keyframes toastSlideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes toastSlideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* Progress bar for auto-dismiss */
.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: currentColor;
    opacity: 0.3;
    animation: toastProgressShrink linear forwards;
}

@keyframes toastProgressShrink {
    from { width: 100%; }
    to { width: 0%; }
}

/* Toast reduced motion */
@media (prefers-reduced-motion: reduce) {
    .toast,
    .toast.hiding,
    .toast-progress {
        animation: none !important;
    }

    .toast {
        opacity: 1;
        transform: none;
    }

    .toast.hiding {
        opacity: 0;
    }
}

/* Toast responsive */
@media (max-width: 480px) {
    .toast-container {
        left: 16px;
        right: 16px;
        bottom: 16px;
        max-width: none;
    }
}
