/* =======================================
   ROAS HOURLY CHART STYLES - CẬP NHẬT
   Thêm PnL và chế độ hiển thị hourly diff
   ======================================= */

/* Reset và base styles */
* {
    box-sizing: border-box;
}

/* Header Section - Tối ưu */
.roas-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px 25px;
    border-radius: 8px;
    margin-bottom: 25px;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    border: 1px solid #e2e8f0;
}

.roas-header h1 {
    margin: 0 0 10px 0;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-weight: 600;
    color: white;
}

.roas-header p {
    margin: 0 0 15px 0;
    font-size: 14px;
    opacity: 0.9;
}

.header-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

.back-link,
.json-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: white;
    text-decoration: none;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 15px;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.back-link:hover,
.json-link:hover {
    background: rgba(255, 255, 255, 0.3);
    text-decoration: none;
}

/* Stats Summary - Compact với PnL mới */
.stats-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    background: white;
    padding: 15px;
    border-radius: 6px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    border: 1px solid #e2e8f0;
    transition: all 0.2s ease;
}

.stat-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

/* Màu sắc đặc biệt cho từng loại stat */
.stat-card.revenue {
    border-left: 4px solid #10b981;
}

.stat-card.ads {
    border-left: 4px solid #f59e0b;
}

.stat-card.roas {
    border-left: 4px solid #3b82f6;
}

.stat-card.pnl {
    border-left: 4px solid #8b5cf6;
}

.stat-label {
    font-size: 12px;
    color: #64748b;
    margin-bottom: 5px;
    font-weight: 500;
}

.stat-value {
    font-size: 16px;
    font-weight: 700;
    color: #1e293b;
}

.stat-value.positive {
    color: #059669;
}

.stat-value.negative {
    color: #dc2626;
}

/* Chart Controls - Sửa lỗi layout + thêm display mode */
.chart-controls {
    background: white;
    padding: 18px;
    border-radius: 8px;
    margin-bottom: 15px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    border: 1px solid #e2e8f0;
}

/* Main Chart Tabs - 4 tabs mới */
.chart-tabs {
    display: flex;
    justify-content: center;
    gap: 4px;
    margin-bottom: 15px;
    padding: 4px;
    background: #f8fafc;
    border-radius: 6px;
    flex-wrap: wrap;
}

.chart-tab {
    padding: 8px 16px;
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: #64748b;
    transition: all 0.2s ease;
    white-space: nowrap;
    min-width: 90px;
    flex: 1;
}

.chart-tab.active {
    background: #667eea;
    color: white;
    box-shadow: 0 1px 3px rgba(102, 126, 234, 0.3);
}

.chart-tab:hover:not(.active) {
    color: #667eea;
    background: rgba(102, 126, 234, 0.1);
}

/* Display Mode Toggle - MỚI */
.display-mode-toggle {
    display: flex;
    justify-content: center;
    gap: 3px;
    margin: 12px 0;
    padding: 3px;
    background: #f1f5f9;
    border-radius: 6px;
    max-width: 280px;
    margin-left: auto;
    margin-right: auto;
}

.mode-btn {
    padding: 6px 12px;
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: #64748b;
    transition: all 0.2s ease;
    white-space: nowrap;
    flex: 1;
}

.mode-btn.active {
    background: #0ea5e9;
    color: white;
    box-shadow: 0 1px 2px rgba(14, 165, 233, 0.3);
}

.mode-btn:hover:not(.active) {
    color: #0ea5e9;
    background: rgba(14, 165, 233, 0.1);
}

/* Control Actions - Sửa overflow */
.control-actions {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin: 12px 0;
    flex-wrap: wrap;
}

.control-btn {
    padding: 6px 12px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    color: #475569;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.control-btn:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
    color: #334155;
}

.control-btn:active {
    transform: translateY(1px);
}

/* Legend Controls - Sửa responsive */
.legend-controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 8px;
    margin-top: 12px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: #f8fafc;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    font-size: 13px;
}

.legend-item:hover {
    background: #f1f5f9;
    border-color: #e2e8f0;
}

.legend-item.disabled {
    opacity: 0.5;
    background: #f3f4f6;
}

.legend-color {
    width: 14px;
    height: 14px;
    border-radius: 2px;
    flex-shrink: 0;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.legend-label {
    font-size: 13px;
    font-weight: 500;
    color: #374151;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Chart Container - SỬA CHÍNH TẠI ĐÂY */
.chart-container {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    border: 1px solid #e2e8f0;
    position: relative;
    overflow: hidden;
}

.chart-wrapper {
    position: relative;
    width: 100%;
    height: 450px;
    margin-top: 15px;
    overflow: hidden;
}

/* Canvas sizing - SỬA CHÍNH */
.chart-wrapper canvas {
    max-width: 100% !important;
    max-height: 100% !important;
    width: 100% !important;
    height: 100% !important;
}

/* Loading State */
.chart-container.loading {
    opacity: 0.6;
    pointer-events: none;
}

.chart-container.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 24px;
    height: 24px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    transform: translate(-50%, -50%);
    z-index: 10;
}

@keyframes spin {
    0% {
        transform: translate(-50%, -50%) rotate(0deg);
    }

    100% {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

/* Info Panel - MỚI cho hiển thị thông tin mode */
.info-panel {
    background: #f0f9ff;
    border: 1px solid #0ea5e9;
    border-radius: 6px;
    padding: 10px 15px;
    margin: 10px 0;
    font-size: 13px;
    color: #0c4a6e;
    display: flex;
    align-items: center;
    gap: 8px;
}

.info-panel.hidden {
    display: none;
}

.info-panel .info-icon {
    font-size: 16px;
    color: #0ea5e9;
}

/* Footer - Compact */
.footer {
    background: #f8fafc;
    padding: 15px;
    border-radius: 6px;
    margin-top: 20px;
    text-align: center;
    color: #64748b;
    font-size: 13px;
    border: 1px solid #e2e8f0;
    line-height: 1.5;
}

.footer code {
    background: #e2e8f0;
    padding: 1px 4px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 11px;
}

.footer small {
    color: #94a3b8;
    display: block;
    margin-top: 5px;
}

/* Keyboard shortcuts indicator */
.shortcuts-hint {
    background: #fffbeb;
    border: 1px solid #f59e0b;
    border-radius: 4px;
    padding: 8px 12px;
    margin: 10px 0;
    font-size: 12px;
    color: #92400e;
    text-align: center;
}

/* =======================================
   RESPONSIVE DESIGN - SỬA ĐẦY ĐỦ
   ======================================= */

@media (max-width: 768px) {
    .container {
        padding: 15px;
        margin-top: 80px;
    }

    body {
        padding-top: 0;
        /* Reset nếu có */
    }

    .roas-header {
        padding: 15px;
        margin-bottom: 20px;
    }

    .roas-header h1 {
        font-size: 20px;
        flex-direction: column;
        gap: 8px;
    }

    .roas-header p {
        font-size: 13px;
    }

    .stats-summary {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .stat-card {
        padding: 12px;
    }

    .stat-value {
        font-size: 14px;
    }

    .chart-controls {
        padding: 15px;
    }

    .chart-tabs {
        gap: 3px;
        padding: 3px;
    }

    .chart-tab {
        padding: 6px 10px;
        font-size: 12px;
        min-width: 70px;
    }

    .display-mode-toggle {
        max-width: 100%;
    }

    .mode-btn {
        padding: 5px 8px;
        font-size: 11px;
    }

    .control-actions {
        gap: 6px;
    }

    .control-btn {
        padding: 5px 10px;
        font-size: 11px;
    }

    .legend-controls {
        grid-template-columns: 1fr;
        gap: 6px;
    }

    .legend-item {
        padding: 5px 8px;
    }

    .chart-container {
        padding: 15px;
    }

    .chart-wrapper {
        height: 350px;
    }

    .chart-controls:first-child,

    .roas-header:first-child {
        margin-top: 0;
    }

    .mobile-menu-btn {
        z-index: 1010 !important;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 10px;
    }

    .roas-header {
        padding: 12px;
    }

    .roas-header h1 {
        font-size: 18px;
    }

    .stats-summary {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .stat-card {
        padding: 10px;
    }

    .stat-label {
        font-size: 11px;
    }

    .stat-value {
        font-size: 13px;
    }

    .chart-controls {
        padding: 12px;
    }

    .chart-tab {
        padding: 5px 8px;
        font-size: 11px;
        min-width: 60px;
    }

    .mode-btn {
        padding: 4px 6px;
        font-size: 10px;
    }

    .control-btn {
        padding: 4px 8px;
        font-size: 10px;
    }

    .chart-container {
        padding: 12px;
    }

    .chart-wrapper {
        height: 300px;
    }

    .legend-label {
        font-size: 12px;
    }

    .legend-color {
        width: 12px;
        height: 12px;
    }

    .footer {
        padding: 12px;
        font-size: 12px;
    }

    .info-panel {
        padding: 8px 12px;
        font-size: 12px;
    }

    .shortcuts-hint {
        font-size: 11px;
        padding: 6px 10px;
    }
}

/* =======================================
   CHART SPECIFIC FIXES + PnL COLORS
   ======================================= */

/* Ensure Chart.js responsive */
.chart-wrapper .chartjs-render-monitor {
    animation: chartjs-render-animation 0.001s;
}

/* Fix chart overflow issues */
.chart-wrapper>div {
    position: relative !important;
    height: 100% !important;
    width: 100% !important;
}

/* Hide scrollbars if any */
.chart-wrapper::-webkit-scrollbar {
    display: none;
}

.chart-wrapper {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* PnL specific styling */
.pnl-positive {
    color: #059669 !important;
}

.pnl-negative {
    color: #dc2626 !important;
}

.roas-percentage::after {
    content: '%';
    font-size: 0.9em;
    opacity: 0.7;
}

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

.text-center {
    text-align: center;
}

.hidden {
    display: none !important;
}

.fade-in {
    opacity: 0;
    animation: fadeIn 0.3s ease-in-out forwards;
}

@keyframes fadeIn {
    to {
        opacity: 1;
    }
}

.pulse {
    animation: pulse 2s infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.7;
    }
}

/* =======================================
   PRINT STYLES
   ======================================= */

@media print {

    .control-actions,
    .header-actions,
    .display-mode-toggle,
    .shortcuts-hint {
        display: none;
    }

    .roas-header {
        background: #f8fafc !important;
        color: #1e293b !important;
        box-shadow: none;
    }

    .chart-wrapper {
        height: 400px;
        break-inside: avoid;
    }

    .stats-summary {
        break-inside: avoid;
    }
}