:root {
    /* New Palette */
    --bg-color: #F6F4EC;
    /* Street Stone */
    --surface-color: #FFFFFF;
    /* White cards */
    --text-color: #000000;
    /* Early Riser */
    --accent-color: #FFAC2E;
    /* Hepcat Gold */
    --secondary-bg: #EEE1B8;
    /* Muted Malt */
    --border-color: #E0E0E0;
    /* Light gray for borders */
    --hoptimism: #F9EC00;
    /* Hoptimism Yellow */

    /* Legacy mappings for compatibility */
    --trend-up: #4CAF50;
    /* Green for positive trends */
    --trend-down: #ef5350;
    /* Red for negative */
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

header {
    padding: 16px 24px;
    background-color: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
}

h1 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    display: flex;
    align-items: center;
}

h1 span {
    color: var(--accent-color);
    margin-right: 8px;
}

.controls {
    display: flex;
    gap: 12px;
    align-items: center;
}

select,
button {
    background-color: var(--bg-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    outline: none;
    transition: all 0.2s ease;
}

select:hover,
button:hover {
    border-color: #787b86;
}

button.active {
    background-color: var(--accent-color);
    border-color: var(--accent-color);
    color: black;
    font-weight: 600;
}

.main-container {
    flex: 1;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow: hidden;
}

#chart-container {
    flex: 1;
    background-color: var(--surface-color);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    position: relative;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

#chart-container a {
    display: none !important;
}

.chart-overlay {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 5;
    pointer-events: none;
}

.outlet-label {
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 4px;
}

.granularity-label {
    font-size: 12px;
    color: #787b86;
    text-transform: uppercase;
}

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-top: 20px;
}

.stat-card {
    background-color: var(--surface-color);
    padding: 16px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.stat-value {
    font-size: 24px;
    font-weight: bold;
    color: #26a69a;
    margin-bottom: 4px;
}

.stat-desc {
    font-size: 12px;
    color: #787b86;
    text-align: right;
}

/* Rate of Sale Table Styles */
#ros-table-container {
    display: none;
    width: 100%;
    height: 500px;
    overflow: auto;
    background-color: var(--surface-color);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    margin-bottom: 24px;
}

.ros-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    color: var(--text-color);
}

.ros-table th,
.ros-table td {
    padding: 12px 16px;
    text-align: right;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.ros-table th {
    text-align: center;
    background-color: var(--secondary-bg);
    /* Muted Malt */
    color: black;
    position: sticky;
    top: 0;
    z-index: 2;
    font-weight: 600;
}

.ros-table th:first-child {
    position: sticky;
    left: 0;
    z-index: 3;
    text-align: left;
    border-right: 1px solid var(--border-color);
}

.ros-table td:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    background-color: var(--surface-color);
    text-align: left;
    font-weight: 500;
    border-right: 1px solid var(--border-color);
}

.ros-table tr:hover td {
    background-color: rgba(255, 172, 46, 0.1);
}

.floating-tooltip {
    width: 180px;
    min-height: 100px;
    /* max-height removed to allow content to fit */
    position: absolute;
    display: none;
    padding: 12px;
    box-sizing: border-box;
    font-size: 13px;
    color: var(--text-color);
    background-color: var(--surface-color);
    text-align: left;
    z-index: 1000;
    top: 12px;
    left: 12px;
    pointer-events: none;
    border: 1px solid var(--accent-color);
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    font-feature-settings: "tnum";
    -webkit-font-feature-settings: "tnum";
}

.tooltip-date {
    font-weight: bold;
    margin-bottom: 8px;
    color: var(--text-color);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 4px;
}

.tooltip-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}

.tooltip-label {
    color: #787b86;
}

.tooltip-value {
    font-weight: 600;
}

/* Executive Dashboard Styles */
#executive-dashboard {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 24px;
}

.exec-card {
    background-color: var(--surface-color);
    border-radius: 12px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    border: 1px solid var(--border-color);
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.exec-card.primary {
    background-color: var(--surface-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--accent-color);
    /* Add accent strip */
}

.exec-card.success {
    background-color: var(--surface-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--hoptimism);
    /* Add accent strip */
}

.stat-card.profit {
    background-color: var(--accent-color);
    color: black;
    border: none;
}

.stat-card.profit .stat-value,
.stat-card.profit .stat-desc {
    color: black;
}



.exec-label {
    font-size: 14px;
    opacity: 0.9;
    margin-bottom: 8px;
    font-weight: 500;
}

.exec-value {
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 4px;
}

.exec-secondary {
    font-size: 13px;
    opacity: 0.8;
    margin-top: 4px;
}

.exec-trend {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 20px;
    font-weight: 600;
}

.trend-up {
    color: #26a69a;
}

.trend-down {
    color: #ef5350;
}

.exec-diff {
    font-size: 13px;
    color: #787b86;
    margin-top: 4px;
}

.exec-context {
    font-size: 11px;
    background: rgba(0, 0, 0, 0.2);
    padding: 4px 8px;
    border-radius: 4px;
    margin-top: 8px;
    display: inline-block;
}

/* Forecast & Inventory Styles */
button.forecast-btn {
    border-color: #9c27b0;
    color: #e1bee7;
}

button.forecast-btn.active {
    background-color: #9c27b0;
    color: white;
}

#inventory-table-container {
    display: none;
    width: 100%;
    height: 500px;
    overflow: auto;
    background-color: var(--surface-color);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    margin-bottom: 24px;
}

.inv-safe {
    color: #66bb6a;
}

.inv-risk {
    color: #ffa726;
}

.inv-critical {
    color: #ef5350;
    font-weight: bold;
}

.exec-card.forecast {
    background: linear-gradient(135deg, #7B1FA2 0%, #9C27B0 100%);
    color: white;
    border: none;
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
    body {
        height: 100%;
        overflow-y: auto;
        /* Specific scroll behavior for mobile */
    }

    header {
        flex-direction: column;
        align-items: stretch;
        gap: 16px;
        padding: 16px;
    }

    .controls {
        flex-direction: column;
        /* Stack controls vertically */
        align-items: stretch;
        gap: 12px;
    }

    #outlet-selector {
        width: 100%;
        padding: 12px;
    }

    #granularity-toggle {
        display: flex;
        flex-wrap: wrap;
        /* Allow wrapping */
        gap: 8px;
    }

    #granularity-toggle button {
        flex: 1 1 30%;
        /* Grow to fill, split into roughly 3 per row */
        padding: 10px;
        font-size: 13px;
    }

    #value-toggle {
        margin-left: 0 !important;
        display: flex;
        gap: 8px;
    }

    #value-toggle button {
        flex: 1;
        padding: 10px;
    }

    #btn-refresh {
        padding: 12px;
        background-color: var(--surface-color);
    }

    .main-container {
        padding: 12px;
        overflow: visible;
        /* Let body handle scroll */
        height: auto;
    }

    #executive-dashboard {
        grid-template-columns: 1fr;
        /* Stack cards */
        gap: 12px;
    }

    .stats {
        grid-template-columns: 1fr 1fr;
        /* 2 columns for smaller stats */
        gap: 12px;
    }

    #chart-container {
        min-height: 350px;
        /* Ensure chart is tall enough */
    }

    .exec-value {
        font-size: 28px;
    }
}
