:root {
    --primary-orange: #FF9F43;
    --primary-orange-light: #FFF0E1;
    --text-dark: #2D3436;
    --text-grey: #636e72;
    --bg-color: #F7F8FA;
    /* Light Grey */
    --card-bg: #FFFFFF;
    --success-green: #2ecc71;
    --danger-red: #e74c3c;
    --font-family: 'Inter', sans-serif;
    --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.05);
    --border-color: #f1f2f6;
    --menu-bg: #FFFFFF;
}

body.dark-mode {
    --bg-color: #1a1a1a;
    --card-bg: #2d2d2d;
    --text-dark: #f5f6fa;
    --text-grey: #b2bec3;
    --primary-orange-light: rgba(255, 159, 67, 0.15);
    --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.3);
    --border-color: #404040;
    --menu-bg: #2d2d2d;
}

/* Dark Mode Specific Tweaks */
body.dark-mode .menu-btn {
    color: var(--text-dark);
}

body.dark-mode .menu-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

body.dark-mode .stat-card.compact {
    background-color: #353b48;
    border-color: #404040;
}

body.dark-mode .history-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

body.dark-mode .chart-section,
body.dark-mode .stat-card,
body.dark-mode .stat-group {
    border-color: var(--border-color);
}

body.dark-mode .history-header {
    border-bottom-color: var(--border-color);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-dark);
    -webkit-font-smoothing: antialiased;
}

.dashboard-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-height: 100vh;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.menu-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-dark);
    padding: 4px;
    border-radius: 50%;
    transition: background-color 0.2s;
}

.menu-btn:hover {
    background-color: #F1F2F6;
}

.header h1 {
    font-size: 24px;
    /* Slightly smaller for mobile fit */
    font-weight: 800;
    color: var(--text-dark);
    letter-spacing: -0.5px;
}

.header-right {
    display: flex;
    align-items: center;
}

.time-info {
    text-align: right;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.clock {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-dark);
    font-family: monospace;
    /* Fixed width for tick stability */
}

.last-sync {
    font-size: 11px;
    color: var(--text-grey);
    margin-top: 2px;
}

/* Toggle Switch */
.toggle-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.toggle-label {
    font-size: 12px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    text-transform: uppercase;
    width: 80px;
    /* Fixed width to prevent jumping */
}

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.3);
    transition: .4s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: rgba(255, 255, 255, 0.6);
}

input:checked+.slider:before {
    transform: translateX(20px);
}

/* Hero Top Row */
.hero-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.stat-card.hero h3 {
    margin-bottom: 0;
}

/* History Menu (Off-canvas) */
.history-menu {
    position: fixed;
    top: 0;
    left: -300px;
    width: 280px;
    height: 100vh;
    background: var(--card-bg);
    box-shadow: 2px 0 20px rgba(0, 0, 0, 0.1);
    z-index: 2000;
    transition: left 0.3s ease;
    display: flex;
    flex-direction: column;
}

.history-menu.active {
    left: 0;
}

.menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    z-index: 1500;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.menu-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.history-header {
    padding: 20px;
    border-bottom: 1px solid #F0F0F0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-header h3 {
    font-size: 18px;
    font-weight: 700;
}

.history-header button {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-grey);
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.history-item {
    padding: 12px 16px;
    border-radius: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-item:hover {
    background-color: #F7F8FA;
}

.history-item.active {
    background-color: var(--primary-orange-light);
    color: var(--primary-orange);
    font-weight: 600;
}

.history-item .month-label {
    font-size: 14px;
}

.history-item .month-total {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-dark);
}

/* Menu Navigation */
.menu-nav {
    padding: 10px;
    border-bottom: 1px solid var(--border-color);
}

.menu-nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 12px;
    text-decoration: none;
    color: var(--text-dark);
    font-weight: 600;
    font-size: 14px;
    transition: all 0.2s;
}

.menu-nav-link:hover {
    background-color: var(--primary-orange-light);
    color: var(--primary-orange);
}

.menu-nav-link svg {
    flex-shrink: 0;
}

/* Layout */
.main-content {
    display: grid;
    grid-template-columns: 1fr 340px;
    /* Slightly wider side */
    gap: 24px;
}

@media (max-width: 900px) {
    .main-content {
        /* Switch to flex column-reverse to put Stats (bottom in HTML) on Top visually */
        display: flex;
        flex-direction: column-reverse;
        gap: 20px;
    }

    .stat-group-row {
        flex-direction: column;
    }

    .stats-panel {
        width: 100%;
    }
}

@media (max-width: 600px) {
    .dashboard-container {
        padding: 12px;
    }

    .header h1 {
        font-size: 24px;
    }

    .chart-section {
        padding: 16px;
        min-height: 300px;
    }

    .stat-card.hero {
        padding: 20px;
    }

    .stat-card.hero .value {
        font-size: 32px;
    }
}

/* Month Navigator */
.month-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 10px 0 16px;
    grid-column: 1 / -1;
}

.month-nav-btn {
    background: var(--card-bg);
    border: 1px solid #e0e0e0;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-dark);
    transition: all 0.15s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.month-nav-btn:hover {
    background: var(--text-dark);
    color: #fff;
    border-color: var(--text-dark);
}

.month-nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.month-nav-btn:disabled:hover {
    background: var(--card-bg);
    color: var(--text-dark);
    border-color: #e0e0e0;
}

.month-nav-label {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-dark);
    min-width: 140px;
    text-align: center;
}

.month-nav-live {
    font-size: 12px;
    font-weight: 600;
    color: #27ae60;
    text-decoration: none;
    margin-left: 8px;
    animation: pulse-live 2s infinite;
}

.month-nav-live:hover {
    text-decoration: underline;
}

@keyframes pulse-live {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

body.dark-mode .month-nav-btn {
    border-color: #444;
}

body.dark-mode .month-nav-btn:hover {
    background: #fff;
    color: #1a1a2e;
    border-color: #fff;
}

/* Chart */
.chart-section {
    background: var(--card-bg);
    border-radius: 20px;
    padding: 24px;
    box-shadow: var(--shadow-soft);
    min-height: 450px;
    position: relative;
    width: 100%;
    border: 1px solid #F0F0F0;
}

/* Channel Selector */
.channel-selector {
    display: flex;
    gap: 6px;
    margin-bottom: 16px;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: none;
}

.channel-selector::-webkit-scrollbar {
    display: none;
}

.channel-pill {
    padding: 5px 14px;
    border-radius: 20px;
    border: 1px solid #e0e0e0;
    background: transparent;
    color: var(--text-grey);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s ease;
}

.channel-pill:hover {
    border-color: #bbb;
    color: var(--text-dark);
}

.channel-pill.active {
    background: var(--text-dark);
    color: #fff;
    border-color: var(--text-dark);
}

body.dark-mode .channel-pill {
    border-color: #444;
}

body.dark-mode .channel-pill:hover {
    border-color: #666;
}

body.dark-mode .channel-pill.active {
    background: #fff;
    color: #1a1a2e;
    border-color: #fff;
}

/* Forecast Bar */
.forecast-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 0 6px;
}

.forecast-toggle {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 12px;
    border-radius: 14px;
    border: 1.5px solid var(--border-color, #eee);
    background: transparent;
    color: var(--text-grey);
    font-family: 'Outfit', sans-serif;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.forecast-toggle:hover {
    border-color: var(--text-grey);
}

.forecast-toggle.active {
    border-color: #FF9F43;
    color: #FF9F43;
    background: rgba(255, 159, 67, 0.08);
}

body.dark-mode .forecast-toggle {
    border-color: #2a2a4a;
    color: #8899aa;
}

body.dark-mode .forecast-toggle.active {
    border-color: #FF9F43;
    color: #FF9F43;
    background: rgba(255, 159, 67, 0.12);
}

.forecast-info {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-grey);
}

.forecast-info .fc-value {
    color: #FF9F43;
    font-weight: 700;
}

.forecast-info .fc-method {
    font-size: 0.65rem;
    font-weight: 400;
    opacity: 0.7;
}

/* Forecast Summary Panel */
.forecast-summary .fc-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid var(--border-color, #eee);
}

.forecast-summary .fc-row:last-child {
    border-bottom: none;
}

.forecast-summary .fc-channel {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-dark, #2D3436);
}

body.dark-mode .forecast-summary .fc-channel {
    color: #e0e0e0;
}

.forecast-summary .fc-numbers {
    text-align: right;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.forecast-summary .fc-est {
    font-size: 0.8rem;
    font-weight: 700;
    color: #FF9F43;
}

.forecast-summary .fc-remaining {
    font-size: 0.65rem;
    font-weight: 500;
    color: var(--text-grey);
}

.forecast-summary .fc-total-row {
    font-weight: 700;
    padding-top: 8px;
    border-top: 2px solid var(--border-color, #eee);
}

.forecast-summary .fc-total-row .fc-channel {
    font-weight: 700;
}

body.dark-mode .forecast-summary .fc-row {
    border-bottom-color: #2a2a4a;
}

body.dark-mode .forecast-summary .fc-total-row {
    border-top-color: #2a2a4a;
}

.forecast-summary .fc-accuracy {
    font-size: 0.6rem;
    font-weight: 600;
    margin-left: 4px;
}

.forecast-summary .fc-method-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding-top: 8px;
    margin-top: 4px;
    border-top: 1px solid var(--border-color, #eee);
}

.forecast-summary .fc-method-label {
    font-size: 0.6rem;
    color: var(--text-grey);
    font-style: italic;
}

body.dark-mode .forecast-summary .fc-method-info {
    border-top-color: #2a2a4a;
}

.fc-volatile {
    color: #e67e22;
    font-size: 0.85em;
    font-weight: 500;
}

.fc-trend {
    font-size: 0.85em;
    font-weight: 600;
    margin-left: 6px;
    padding: 1px 6px;
    border-radius: 4px;
    background: rgba(46, 204, 113, 0.12);
    color: #27ae60;
}

.fc-trend.fc-trend-down {
    background: rgba(231, 76, 60, 0.12);
    color: #e74c3c;
}

.fc-volatile-label {
    color: #95a5a6;
    font-style: italic;
    font-size: 0.9em;
}

/* Mid-month deviation alerts (forecast info bar) */
.fc-alert {
    font-size: 0.7rem;
    font-weight: 600;
    margin-left: 6px;
    padding: 2px 8px;
    border-radius: 4px;
}

.fc-alert-below {
    background: rgba(231, 76, 60, 0.12);
    color: #e74c3c;
}

.fc-alert-above {
    background: rgba(46, 204, 113, 0.12);
    color: #27ae60;
}

.fc-alert-ontrack {
    background: rgba(52, 152, 219, 0.10);
    color: #7f8c8d;
}

/* Per-channel trend status indicators (forecast summary) */
.fc-status {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    font-size: 0.6rem;
    font-weight: 700;
    border-radius: 50%;
    margin-right: 5px;
    vertical-align: middle;
    line-height: 1;
}

.fc-status-below {
    background: rgba(231, 76, 60, 0.15);
    color: #e74c3c;
}

.fc-status-above {
    background: rgba(46, 204, 113, 0.15);
    color: #27ae60;
}

.fc-status-ontrack {
    background: rgba(149, 165, 166, 0.15);
    color: #95a5a6;
    font-size: 0.4rem;
}

/* Wave Pipeline Section */
.fc-pipeline {
    border-top: 1px solid var(--border-color);
    margin-top: 8px;
    padding-top: 8px;
}

.fc-pipeline-header {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-grey);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.fc-pipeline-summary {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    margin-bottom: 6px;
}

.fc-pipeline-stat {
    font-weight: 500;
}

.fc-pipeline-expected {
    color: #27ae60;
    font-weight: 600;
}

.fc-pipeline-arrow {
    color: var(--text-grey);
    font-size: 0.75rem;
}

.fc-pipeline-rate {
    color: var(--text-grey);
    font-size: 0.75rem;
}

.fc-pipeline-buckets {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.fc-pipeline-bucket {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-grey);
    padding: 2px 0;
}

.fc-pipeline-bucket-label {
    width: 42px;
    font-weight: 500;
    color: var(--text-dark);
}

.fc-pipeline-bucket-count {
    width: 24px;
    text-align: right;
    font-size: 0.7rem;
}

.fc-pipeline-bucket-due {
    width: 65px;
    text-align: right;
}

.fc-pipeline-bucket-arrow {
    font-size: 0.65rem;
}

.fc-pipeline-bucket-exp {
    width: 55px;
    text-align: right;
    color: #27ae60;
    font-weight: 500;
}

.fc-pipeline-bucket-prob {
    font-size: 0.65rem;
    color: var(--text-grey);
    opacity: 0.7;
}

.chart-container {
    position: relative;
    width: 100%;
    height: 400px;
}

/* Stats Panel */
.stats-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.stat-card[data-channel] {
    cursor: pointer;
    transition: opacity 0.15s ease;
}

.stat-card[data-channel]:hover {
    opacity: 0.8;
}

.stat-group {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 16px;
    box-shadow: var(--shadow-soft);
    border: 1px solid #F0F0F0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.stat-group h4 {
    font-size: 12px;
    text-transform: uppercase;
    color: var(--text-grey);
    font-weight: 700;
    margin-bottom: 4px;
    letter-spacing: 0.5px;
}

/* Collapsible Sections */
details.collapsible {
    background: var(--card-bg);
    border-radius: 16px;
    box-shadow: var(--shadow-soft);
    border: 1px solid #F0F0F0;
    overflow: hidden;
}

body.dark-mode details.collapsible {
    border-color: var(--border-color);
}

details.collapsible summary.stat-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    cursor: pointer;
    list-style: none;
    user-select: none;
}

details.collapsible summary.stat-group-header::-webkit-details-marker {
    display: none;
}

details.collapsible summary.stat-group-header h4 {
    font-size: 12px;
    text-transform: uppercase;
    color: var(--text-grey);
    font-weight: 700;
    letter-spacing: 0.5px;
    margin: 0;
}

details.collapsible .chevron {
    color: var(--text-grey);
    transition: transform 0.2s ease;
}

details.collapsible[open] .chevron {
    transform: rotate(180deg);
}

details.collapsible .stat-group-content {
    padding: 0 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.stat-group-row {
    display: flex;
    gap: 16px;
}

.stat-group-row .stat-card {
    flex: 1;
}

/* Base Card */
.stat-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 20px;
    box-shadow: var(--shadow-soft);
    border: 1px solid #F0F0F0;
    position: relative;
}

/* Hero Card (Grand Total) */
.stat-card.hero {
    background: linear-gradient(135deg, #FF9F43 0%, #FF851B 100%);
    color: white;
    border: none;
    padding: 24px;
}

.stat-card.hero h3 {
    color: rgba(255, 255, 255, 0.9);
    font-size: 13px;
    text-transform: uppercase;
    margin-bottom: 8px;
}

.stat-card.hero .value {
    color: white;
    font-size: 36px;
}

.stat-card.hero .currency {
    color: rgba(255, 255, 255, 0.8);
    font-size: 16px;
}

.stat-card.hero .stat-sub {
    margin-top: 12px;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    gap: 10px;
}

.stat-card.hero .growth-badge {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    backdrop-filter: blur(4px);
}

.stat-card.hero .growth-badge.negative {
    background: rgba(255, 255, 255, 0.2);
    color: #ffcccc;
    /* Light red for contrast on orange */
}

.comparison-amount {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.7);
    cursor: help;
    position: relative;
}

.comparison-amount::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-dark);
    color: white;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 12px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 100;
}

body.dark-mode .comparison-amount::after {
    background: #f5f5f5;
    color: #1a1a1a;
}

.comparison-amount:hover::after {
    opacity: 1;
}

/* Compact Cards */
.stat-card.compact {
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: none;
    border: 1px solid #f1f2f6;
    background: #FAFAFB;
    border-radius: 12px;
}

.stat-card.compact .label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-grey);
}

.stat-card.compact .value-sm {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-dark);
}

/* Sub-channel indicators */
.sub-shopee {
    border-left: 4px solid #EE4D2D !important;
}

.sub-tiktok {
    border-left: 4px solid #000000 !important;
}

.sub-lazada {
    border-left: 4px solid #0f146d !important;
}

/* Group Summary */
.stat-card.summary {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 10px 16px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px dashed #e1e2e6;
    border-radius: 0;
    margin-top: 4px;
}

.stat-card.summary .value-md {
    font-size: 18px;
    font-weight: 800;
    color: var(--text-dark);
}

/* Loader */
.loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.loader.active {
    opacity: 1;
    pointer-events: all;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--primary-orange-light);
    border-top: 4px solid var(--primary-orange);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Daily Sales Table */
.daily-table-section {
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.daily-table-wrapper {
    overflow-x: auto;
}

.daily-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.daily-table th {
    text-align: right;
    padding: 8px 12px;
    font-weight: 600;
    color: var(--text-grey);
    border-bottom: 2px solid #e0e0e0;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.daily-table th:first-child {
    text-align: left;
    width: 70px;
}

.daily-table td:first-child {
    white-space: nowrap;
}

.daily-table td {
    text-align: right;
    padding: 6px 12px;
    border-bottom: 1px solid #f1f2f6;
    font-variant-numeric: tabular-nums;
}

.daily-table td:first-child {
    text-align: left;
    font-weight: 600;
    color: var(--text-grey);
}

.daily-table tr:hover {
    background-color: var(--primary-orange-light);
}

.daily-table tr.today-row {
    background-color: var(--primary-orange-light);
    font-weight: 600;
}

.daily-table tr.zero-row td {
    color: #ccc;
}

body.dark-mode .daily-table th {
    border-bottom-color: var(--border-color);
}

body.dark-mode .daily-table td {
    border-bottom-color: var(--border-color);
}

body.dark-mode .daily-table tr.zero-row td {
    color: #555;
}