:root {
    --red: #d32f2f;
    --red-bg: #ffebee;
    --orange: #f57c00;
    --orange-bg: #fff3e0;
    --blue: #00897b;
    /* Using a Teal/Greenish Blue as requested for 'Xanh' < 200 */
    --blue-bg: #e0f2f1;
    --dark: #111827;
    --gray: #6b7280;
    --light-gray: #f3f4f6;
    --bg-color: #ffffff;
    --text-primary: #1f2937;
    --font-main: 'Encode Sans', sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font-main);
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.5;
    overflow-x: hidden;
    /* Prevent horizontal scroll */
}

.wrap {
    max-width: 1200px;
    margin: 0 auto;
    padding: 30px 20px;
}

/* Header */
.header {
    margin-bottom: 40px;
    border-bottom: 1px solid #eee;
    padding-bottom: 20px;
    text-align: center;
}

.main-title {
    font-size: 36px;
    font-weight: 700;
    line-height: 1.2;
    margin: 0 0 15px 0;
    color: var(--dark);
    letter-spacing: -0.02em;
}

.sapo {
    font-size: 18px;
    line-height: 1.6;
    color: #4b5563;
    max-width: 800px;
    margin: 0 auto;
}

.highlight-red {
    color: var(--red);
    font-weight: 700;
}

/* Layout */
.main-grid {
    display: grid;
    grid-template-columns: 1.6fr 1fr;
    gap: 60px;
    align-items: start;
}

/* Bar Chart Section */
.chart-section {
    width: 100%;
}

.bar-header {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    text-transform: uppercase;
    color: var(--gray);
    font-weight: 600;
    margin-bottom: 15px;
    border-bottom: 2px solid #eee;
    padding-bottom: 8px;
}

.bars-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.bar-row {
    display: flex;
    align-items: center;
    position: relative;
    padding: 4px 0;
}

.bar-label-group {
    width: 180px;
    flex-shrink: 0;
    padding-right: 15px;
    display: flex;
    align-items: center;
}

.bar-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bar-warn-icon {
    color: var(--red);
    margin-left: 6px;
    font-size: 14px;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.6;
        transform: scale(0.9);
    }

    100% {
        opacity: 1;
        transform: scale(1);
    }
}

.bar-track {
    flex-grow: 1;
    height: 32px;
    background: #f0f0f0;
    /* Track background optional */
    background: transparent;
    position: relative;
    border-radius: 0 16px 16px 0;
    margin-right: 10px;
}

.bar-fill {
    height: 100%;
    border-radius: 0 16px 16px 0;
    /* Bo góc động - Rounded corners */
    transition: width 1.2s cubic-bezier(0.22, 1, 0.36, 1);
    position: relative;
    cursor: pointer;
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.05);
}

.bar-fill:hover {
    filter: brightness(0.95) saturate(1.1);
}

.bar-bg-red {
    background: linear-gradient(90deg, #e53935 0%, #b71c1c 100%);
}

.bar-bg-orange {
    background: linear-gradient(90deg, #fb8c00 0%, #ef6c00 100%);
}

.bar-bg-blue {
    background: linear-gradient(90deg, #26a69a 0%, #00897b 100%);
}

.bar-value {
    width: 70px;
    text-align: right;
    font-weight: 700;
    color: var(--dark);
    font-size: 15px;
    flex-shrink: 0;
}

/* Tooltip */
.custom-tooltip {
    position: absolute;
    top: -35px;
    left: 50%;
    transform: translateX(-50%);
    background: #222;
    color: #fff;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s, top 0.2s;
    z-index: 10;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
}

.custom-tooltip::after {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 50%;
    transform: translateX(-50%);
    border-width: 5px 5px 0;
    border-style: solid;
    border-color: #222 transparent transparent transparent;
}

.bar-fill:hover .custom-tooltip {
    opacity: 1;
    top: -40px;
}

/* Detail indicator (Profit -> Loss) */
.profit-flip-badge {
    display: inline-block;
    font-size: 10px;
    background: #fee2e2;
    color: #b91c1c;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 5px;
    vertical-align: middle;
    text-transform: uppercase;
    font-weight: 700;
}

/* Sidebar */
.sidebar {
    position: sticky;
    top: 20px;
}

/* Key Insight Box */
.key-insight {
    background: linear-gradient(135deg, #fff 0%, #fafafa 100%);
    border: 1px solid #e5e7eb;
    border-left: 5px solid var(--red);
    padding: 24px;
    border-radius: 8px;
    margin-bottom: 30px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.03);
}

.insight-label {
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--red);
    margin-bottom: 8px;
}

.key-insight h3 {
    margin: 0 0 10px 0;
    font-size: 18px;
    color: var(--dark);
}

.key-insight p {
    font-size: 14px;
    color: var(--gray);
    margin-bottom: 12px;
}

.loss-list {
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: 14px;
}

.loss-list li {
    padding: 6px 0;
    border-bottom: 1px dashed #eee;
    display: flex;
    justify-content: space-between;
}

.loss-list li:last-child {
    border-bottom: none;
}

/* Donut Chart */
.chart-widget {
    background: #fff;
    border: 1px solid #eee;
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.03);
}

.chart-widget h3 {
    margin-top: 0;
    font-size: 16px;
    margin-bottom: 20px;
    color: var(--dark);
}

.donut-wrapper {
    position: relative;
    max-width: 240px;
    margin: 0 auto 20px auto;
}

.donut {
    width: 100%;
    height: auto;
    overflow: visible;
}

.donut-segment {
    transition: opacity 0.3s, transform 0.3s;
    transform-origin: 0 0;
    cursor: pointer;
}

.donut-segment:hover {
    opacity: 1 !important;
    transform: scale(1.05);
    filter: drop-shadow(0 0 5px rgba(0, 0, 0, 0.2));
}

.donut:hover .donut-segment {
    opacity: 0.3;
    /* Fade others */
}

.donut:hover .donut-segment:hover {
    opacity: 1;
}

.donut-center-num {
    font-size: 42px;
    font-weight: 700;
    fill: var(--dark);
    transition: all 0.2s;
}

.donut-center-label {
    font-size: 14px;
    fill: var(--gray);
    font-weight: 500;
}

/* Legend */
.legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    text-align: left;
}

.legend-item {
    display: flex;
    align-items: center;
    font-size: 12px;
    color: var(--gray);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 15px;
    transition: background 0.2s;
    user-select: none;
}

.legend-item:hover {
    background: #f3f4f6;
    color: var(--dark);
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 6px;
}

.legend-item.dimmed {
    opacity: 0.3;
}

/* Stat Card */
.stat-card {
    margin-top: 20px;
    background: var(--red-bg);
    padding: 15px;
    border-radius: 8px;
    text-align: center;
    border: 1px solid rgba(211, 47, 47, 0.1);
}

.stat-value {
    font-size: 32px;
    font-weight: 800;
    line-height: 1;
    margin-bottom: 5px;
}

.text-red {
    color: var(--red);
}

.stat-desc {
    font-size: 13px;
    color: #7f1d1d;
}

/* Narrative */
.narrative-block {
    margin-top: 40px;
    font-size: 16px;
    color: #374151;
    line-height: 1.7;
    background: #f9fafb;
    padding: 24px;
    border-radius: 8px;
}

.narrative-block h3 {
    margin-top: 0;
    color: var(--dark);
}

/* Responsive */
@media (max-width: 768px) {
    .main-grid {
        grid-template-columns: 1fr;
        gap: 40px;
    }

    .header {
        margin-bottom: 20px;
    }

    .main-title {
        font-size: 28px;
    }

    .sidebar {
        position: static;
        order: -1;
        /* Donut on top on mobile? Or bottom? Usually Top or middle. Let's keep it below for better flow if bars are main */
        order: 1;
        /* Keep below for detailed view */
    }

    .bar-label-group {
        width: 140px;
    }

    .bar-name {
        font-size: 13px;
    }

    .bar-warn-icon {
        display: none;
    }

    /* Save space */
}