/* Premium Color Palette & Theme defined by reference image */
:root {
    --primary-color: #006D5B; /* Deep brand green */
    --primary-hover: #005a4a;
    --background-color: #f7f9f9;
    --panel-bg: #ffffff;
    --text-main: #333333;
    --text-muted: #666666;
    --border-color: #e0e0e0;
    --border-radius: 8px;
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.05);
    
    /* Indicator colors */
    --color-target: #E31A1C; /* Red for target */
    --color-mtd: #006D5B; /* Green for MTD */
    --color-l3m: #999999; /* Grey for L3M */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--background-color);
    color: var(--text-main);
    padding: 20px;
}

.dashboard-container {
    max-width: 1440px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* === Filters & Header === */
.filter-bar {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 0.8fr 1.2fr;
    gap: 15px;
    background: var(--panel-bg);
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    border: 2px solid var(--primary-color);
    position: sticky;
    top: 5px;
    z-index: 1001;
}

/* === Dashboard Tabs === */
.dashboard-tabs {
    display: flex;
    gap: 2px;
    background: #e0e6e6;
    padding: 2px;
    border-radius: 8px;
    position: sticky;
    top: 135px; /* Adjust based on filter-bar height */
    z-index: 1000;
    margin-bottom: 10px;
}

.tab-btn {
    flex: 1;
    padding: 10px 20px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tab-btn:hover {
    background: rgba(0, 109, 91, 0.05);
    color: var(--primary-color);
}

.tab-btn.active {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 2px 6px rgba(0, 109, 91, 0.2);
}

/* === Dashboard Carousel === */
.dashboard-carousel {
    width: 100%;
    overflow: hidden;
    position: relative;
    padding-bottom: 20px;
}

.carousel-slider {
    display: flex;
    width: 300%;
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.carousel-item {
    width: 33.33333%;
    flex: 0 0 33.33333%;
    padding: 0 5px;
}

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

.filter-group label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
}

.premium-select {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: #FAFAFA;
    font-size: 13px;
    color: var(--text-main);
    transition: border-color 0.2s;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 1em;
}

.premium-select:hover, .premium-select:focus {
    border-color: var(--primary-color);
    outline: none;
}

.header-action {
    display: flex;
    align-items: stretch;
}

.primary-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 24px;
    font-weight: 600;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 16px;
    width: 100%;
    margin-top: 0;
    transition: background-color 0.2s, transform 0.1s;
}

.primary-btn:hover {
    background-color: var(--primary-hover);
}

.primary-btn:active {
    transform: scale(0.98);
}

/* === Main Grid === */
.grid-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

/* Panels */
.panel {
    background: var(--panel-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    padding: 20px;
    border: 2px solid var(--primary-color); /* Matches PowerBI framing look */
    position: relative;
    display: flex;
    flex-direction: column;
}

.panel-title {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 5px;
    text-align: center;
    color: var(--text-main);
}

/* Sell In Panel Setup */
.sell-in-panel {
    grid-column: 1 / 2;
    min-height: 600px; /* Match height of right side */
}

.legend-custom {
    display: flex;
    justify-content: flex-start;
    gap: 15px;
    font-size: 12px;
    margin-bottom: 10px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}
.dot.red { background-color: var(--color-target); }
.dot.green { background-color: var(--color-mtd); }
.dot.grey { background-color: var(--color-l3m); }


/* Right Side Grid */
.right-grid {
    grid-column: 2 / 3;
    display: grid;
    grid-template-columns: 1fr 3fr;
    grid-template-rows: auto 1fr;
    gap: 15px;
}

.gauge-panel {
    grid-column: 1 / 2;
}

.donut-panel {
    grid-column: 2 / 3;
}

.bar-panel {
    grid-column: 1 / 3; /* Spans across whole right bottom */
}


/* Chart Containers */
.chart-container-large {
    width: 100%;
    height: 500px;
    flex-grow: 1;
}

.chart-container-small {
    width: 100%;
    height: 220px;
}

.chart-container-medium {
    width: 100%;
    height: 250px;
}

/* Responsive adjustments */
@media (max-width: 1200px) {
    .filter-bar {
         grid-template-columns: repeat(3, 1fr);
    }
    .grid-layout {
        grid-template-columns: 1fr;
    }
    .right-grid {
        grid-column: 1 / 2;
    }
}

/* === Custom Tree Select === */
.custom-tree-select {
    position: relative;
    width: 100%;
}
.tree-select-header {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: #FAFAFA;
    font-size: 13px;
    color: var(--text-main);
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    background-color: white;
}
.tree-select-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    min-width: max-content;
    max-height: 350px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
}
.tree-search {
    padding: 8px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.tree-search input {
    width: 100%;
    padding: 6px;
    border: 1px solid #ccc;
    border-radius: 3px;
    outline: none;
}
.tree-search input:focus {
    border-color: var(--primary-color);
}
.tree-content {
    overflow-y: auto;
    padding: 5px;
    flex-grow: 1;
    min-height: 0; 
    max-height: 300px;
}
.tree-node {
    margin-left: 15px;
}
.tree-item {
    display: flex;
    align-items: center;
    padding: 4px 0;
    cursor: pointer;
}
.tree-item input[type="checkbox"] {
    margin-right: 8px;
    accent-color: var(--primary-color);
}
.tree-item .toggle-icon {
    width: 16px;
    text-align: center;
    margin-right: 5px;
    color: var(--text-muted);
    font-size: 10px;
}
.tree-label {
    font-size: 12px;
}

/* === Flat Filter UI === */
.label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.clear-filter {
    cursor: pointer;
    color: var(--primary-color);
    opacity: 0.6;
    transition: opacity 0.2s;
    display: flex;
    align-items: center;
}
.clear-filter:hover {
    opacity: 1;
}

/* === Achievement State === */
.panel {
    transition: border-color 0.4s ease;
}

.achievement-failed {
    border-color: #E31A1C !important;
}

/* === Distributor Details Section === */
.dist-section {
    padding: 16px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    overflow: hidden;
}

.dist-section-header {
    background: #1a3a34;
    padding: 12px 16px;
    margin-bottom: 12px;
    border-radius: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.dist-label {
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    margin: 0;
}

.dist-controls {
    display: flex;
    gap: 8px;
}

.dist-ctrl-btn {
    background: #1a3a34;
    border: 1px solid #2e5a50;
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.2s, transform 0.1s;
}

.dist-ctrl-btn:hover {
    background: #e6fdf8;
    color: #006D5B;
}

.dist-ctrl-btn:active {
    transform: scale(0.95);
}

.dist-table-wrapper {
    overflow-x: auto;
    overflow-y: auto;
    max-height: 520px;
    width: 100%;
}

.dist-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11.5px;
    min-width: 1500px;
}

.dist-table thead tr {
    background: #1a3a34;
    color: #fff;
}

.dist-table thead th {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #1a3a34;
    padding: 9px 10px;
    text-align: right;
    white-space: nowrap;
    border-right: 1px solid #2e5a50;
    font-weight: 600;
}

.dist-table thead th.col-desc {
    text-align: left;
}

.dist-table tbody tr {
    border-bottom: 1px solid #e8f0ee;
    transition: background 0.15s;
}

.dist-table tbody tr:hover {
    background: #f0faf8;
}

/* Level coloring */
.dist-table tr.lvl-0 { background: #dff2ee; font-weight: 700; }
.dist-table tr.lvl-0:hover { background: #c8e8e2; }
.dist-table tr.lvl-1 { background: #f0faf8; font-weight: 600; }
.dist-table tr.lvl-2 { background: #fff; font-weight: 500; }
.dist-table tr.lvl-3 { background: #fafefe; font-weight: 400; }
.dist-table tr.lvl-4 { background: #ffffff; font-weight: 400; color: #555; }

.dist-table tr.lvl-0 td.sticky-col { padding-left: 8px; }
.dist-table tr.lvl-1 td.sticky-col { padding-left: 22px; }
.dist-table tr.lvl-2 td.sticky-col { padding-left: 36px; }
.dist-table tr.lvl-3 td.sticky-col { padding-left: 50px; }
.dist-table tr.lvl-4 td.sticky-col { padding-left: 64px; } 

.dist-table tfoot td, .dist-table tfoot th { 
    background: #1a3a34; 
    color: #fff; 
    font-weight: 700; 
    position: sticky; 
    bottom: 0; 
    z-index: 10;
}

.dist-table td, .dist-table th {
    padding: 7px 10px;
    text-align: right;
    white-space: nowrap;
    border-right: 1px solid #e8f0ee;
}

/* Sticky first column */
.dist-table .sticky-col {
    position: sticky;
    left: 0;
    z-index: 5;
    text-align: left;
    min-width: 220px;
    max-width: 280px;
    background: inherit;
    border-right: 2px solid #b0d4cc;
}

.dist-table thead .sticky-col { z-index: 15; background: #1a3a34; }
.dist-table tfoot .sticky-col { z-index: 15; background: #1a3a34; }

/* Indent levels */
.dist-desc { display: flex; align-items: center; gap: 5px; cursor: pointer; }
.dist-desc .toggle-btn {
    width: 16px; height: 16px; display: inline-flex; align-items: center;
    justify-content: center; font-size: 9px; color: #006D5B;
    background: #d4ede8; border-radius: 3px; flex-shrink: 0;
    transition: transform 0.2s;
}
.dist-desc .toggle-btn.expanded { transform: rotate(90deg); }
.dist-desc .no-toggle { width: 16px; flex-shrink: 0; }
.dist-desc .desc-text { white-space: normal; word-wrap: break-word; line-height: 1.3; }

.dist-table tr.lvl-0 td.sticky-col { padding-left: 8px; }
.dist-table tr.lvl-1 td.sticky-col { padding-left: 22px; }
.dist-table tr.lvl-2 td.sticky-col { padding-left: 36px; }
.dist-table tr.lvl-3 td.sticky-col { padding-left: 50px; }

/* Percentage cells */
.pct-cell { padding: 2px 6px; border-radius: 3px; display: inline-block; min-width: 55px; text-align: center; font-weight: 600; }
.pct-green { background: #d4edda; color: #155724; }
.pct-red   { background: #f8d7da; color: #721c24; }

.dist-loading { text-align: center; padding: 30px; color: #999; font-style: italic; }

