.profit-page {
    --profit-panel-bg: rgba(var(--ag-fg-rgb), 0.025);
    --profit-panel-border: var(--ag-border);
    --profit-muted: var(--mud-palette-text-secondary);
}

.profit-workspace {
    width: 100%;
    max-width: none;
    padding: 10px 14px 14px;
}

.profit-page .mud-paper {
    border-color: var(--profit-panel-border) !important;
}

.profit-page .mud-alert {
    margin-bottom: 8px !important;
    padding-top: 8px;
    padding-bottom: 8px;
}

.profit-page .mud-table-toolbar {
    min-height: 48px;
    padding: 6px 10px;
    gap: 8px;
}

.profit-page .mud-table-toolbar .mud-input-control {
    margin-top: 0;
    margin-bottom: 0;
}

.profit-header-actions,
.profit-range-actions {
    min-width: 0;
}

.profit-page .profit-action-button.mud-button-root,
.profit-page .profit-run-button.mud-button-root {
    min-height: 36px;
    height: 36px;
    min-width: 118px;
    padding: 0 14px;
    border-radius: 8px;
    white-space: nowrap;
}

.profit-page .profit-range-button.mud-button-root,
.profit-page .profit-section-button.mud-button-root {
    min-height: 30px;
    height: 30px;
    min-width: 86px;
    padding: 0 10px;
    border-radius: 8px;
    white-space: nowrap;
}

.profit-page .profit-run-button.mud-button-root {
    width: 100%;
}

.profit-page .mud-button-root .mud-button-icon-start {
    margin-inline-start: 0;
    margin-inline-end: 6px;
}

.profit-analysis-dialog {
    max-height: min(86vh, 920px);
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 12px;
}

.profit-analysis-dialog .mud-grid {
    min-width: 0;
}

.profit-analysis-dialog .mud-table-container {
    max-width: 100%;
}

.profit-exec {
    border: 1px solid var(--profit-panel-border);
    background: linear-gradient(135deg, rgba(14, 165, 233, 0.10), rgba(16, 185, 129, 0.06));
    border-radius: 8px;
    padding: 10px 12px;
}

.profit-exec-title {
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: 0;
}

.profit-exec-copy {
    color: var(--profit-muted);
    line-height: 1.45;
    max-width: 960px;
}

.profit-kpi {
    min-height: 72px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.profit-kpi .mud-typography-h6 {
    font-size: 1.02rem;
    line-height: 1.25;
}

.profit-section {
    min-height: 100%;
    background: var(--profit-panel-bg);
}

.profit-section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.profit-section-subtitle {
    color: var(--profit-muted);
    line-height: 1.35;
}

.profit-priority {
    border-left: 4px solid var(--mud-palette-warning);
    background: rgba(245, 158, 11, 0.08);
}

.profit-priority.profit-ok {
    border-left-color: var(--mud-palette-success);
    background: rgba(16, 185, 129, 0.08);
}

.profit-risk-breakdown {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.profit-risk-cell {
    border: 1px solid var(--profit-panel-border);
    border-radius: 8px;
    padding: 10px;
    background: var(--ag-surface-sunken);
}

.profit-risk-value {
    font-weight: 800;
    font-size: 1.15rem;
}

.profit-risk-label {
    color: var(--profit-muted);
    font-size: 0.76rem;
}

.profit-action-cell {
    min-width: 42px;
}

.profit-pl {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.profit-pl-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--profit-panel-border);
    padding: 8px 0;
}

.profit-pl-line:last-child {
    border-bottom: 0;
}

.profit-pl-line .mud-typography-subtitle1 {
    font-weight: 800;
    white-space: nowrap;
}

.profit-cfo-card,
.profit-decision-card {
    min-height: 100%;
}

.profit-cfo-signals,
.profit-decision-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.profit-cfo-signal,
.profit-decision-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border: 1px solid var(--profit-panel-border);
    border-radius: 8px;
    padding: 8px 10px;
    background: var(--ag-surface-sunken);
}

.profit-cfo-signal .mud-typography-subtitle1 {
    font-weight: 800;
    white-space: nowrap;
}

.profit-decision-row .mud-chip {
    min-width: 86px;
    justify-content: center;
}

.profit-clickable-cell {
    cursor: pointer;
}

.profit-clickable-cell:hover {
    background: rgba(var(--ag-primary-rgb), 0.10);
}

.profit-formula-box {
    min-height: 100%;
    background: var(--ag-surface-sunken);
}

.profit-utility-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
}

.profit-utility-bar .mud-input-control,
.profit-utility-bar .mud-button-root {
    margin-top: 0;
    margin-bottom: 0;
}

.profit-lines-filterbar {
    background: var(--ag-surface-sunken);
}

.profit-lines-filterbar .mud-input-control {
    margin-top: 0;
    margin-bottom: 0;
}

.profit-filter-summary {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.profit-filter-insight {
    min-height: 86px;
    background: var(--ag-surface-sunken);
}

.profit-customer-loss-table .mud-table-toolbar {
    min-height: 44px;
}

@media (max-width: 960px) {
    .profit-analysis-dialog {
        max-height: 84vh;
    }

    .profit-filter-summary {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.profit-page .mud-table {
    font-size: 0.84rem;
}

.profit-page .mud-table-cell {
    padding: 4px 8px;
}

@media (max-width: 960px) {
    .profit-risk-breakdown {
        grid-template-columns: 1fr;
    }

    .profit-kpi {
        min-height: 76px;
    }

    .profit-workspace {
        padding: 8px;
    }

    .profit-page .profit-action-button.mud-button-root,
    .profit-page .profit-run-button.mud-button-root {
        min-width: 104px;
    }

    .profit-cfo-signal,
    .profit-decision-row {
        align-items: flex-start;
        flex-direction: column;
    }
}

/* Interactive KPI cards & Grouped Panels styles */
.profit-kpi-clickable {
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.profit-kpi-clickable:hover {
    background: rgba(var(--ag-fg-rgb), 0.05) !important;
    border-color: var(--mud-palette-primary) !important;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.profit-kpi-clickable.active {
    background: rgba(var(--ag-primary-rgb), 0.12) !important;
    border-color: var(--mud-palette-primary) !important;
    box-shadow: 0 0 8px rgba(var(--ag-primary-rgb), 0.25);
}

.profit-kpi-clickable.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background-color: var(--mud-palette-primary);
}

.profit-grouped-panels {
    background: transparent !important;
}

.profit-grouped-panels .mud-expand-panel {
    background: var(--profit-panel-bg) !important;
    border: 1px solid var(--profit-panel-border) !important;
    border-radius: 8px !important;
    margin-bottom: 10px !important;
    overflow: hidden;
}

.profit-grouped-panels .mud-expand-panel-header {
    padding: 12px 16px !important;
    background: var(--ag-surface-sunken) !important;
}

.profit-grouped-panels .mud-expand-panel-header:hover {
    background: rgba(var(--ag-fg-rgb), 0.06) !important;
}

/* Responsive alignment for quick date buttons and action buttons next to labeled inputs */
@media (min-width: 960px) {
    .profit-range-actions-wrapper,
    .profit-btn-align-input {
        margin-top: 14px;
    }
}

/* MudChart SVG text layout & readability — theme-aware via --ag-fg-rgb */
.mud-charts-xaxis-text {
    fill: rgba(var(--ag-fg-rgb), 0.75) !important;
    font-size: 0.72rem !important;
}
.mud-charts-yaxis-text {
    fill: rgba(var(--ag-fg-rgb), 0.75) !important;
    font-size: 0.72rem !important;
}
.mud-chart-legend-text {
    fill: rgba(var(--ag-fg-rgb), 0.9) !important;
    font-size: 0.8rem !important;
}
.mud-chart-line {
    overflow: visible !important;
}
.mud-chart-bar {
    overflow: visible !important;
}

/* Donut chart container: responsive, stays square, max 300px */
.profit-donut-wrap {
    width: min(300px, 100%);
    height: min(300px, 100%);
    min-height: 220px;
}

/* =====================================================================
   Mobile fix: toolbar inside MudTable bị squeeze trên màn hình nhỏ
   Nút XUẤT EXCEL / CHART / chip bị hiển thị dọc do flex-wrap: nowrap
   ===================================================================== */
@media (max-width: 640px) {
    .profit-page .mud-table-toolbar {
        flex-wrap: wrap !important;
        height: auto !important;
        min-height: 44px;
        padding: 8px 8px 6px;
        row-gap: 6px;
        overflow: visible !important;
    }

    /* Spacer trên mobile không cần thiết - sẽ đẩy các nút ra khỏi màn hình */
    .profit-page .mud-table-toolbar .mud-spacer {
        display: none !important;
    }

    /* Chips wrap sang dòng mới thay vì bị squeeze */
    .profit-page .mud-table-toolbar .mud-chip-set {
        order: 5;
        width: 100%;
        flex-wrap: wrap !important;
        gap: 4px;
    }

    /* Buttons giữ nguyên kích thước, không bị thu hẹp */
    .profit-page .mud-table-toolbar > .mud-button-root {
        flex-shrink: 0;
        min-width: auto;
        white-space: nowrap;
    }

    /* TextField / Select xuống dòng riêng, full width */
    .profit-page .mud-table-toolbar > .mud-input-control,
    .profit-page .mud-table-toolbar > .mud-select {
        order: 6;
        width: 100% !important;
        max-width: 100% !important;
        margin-left: 0 !important;
    }

    /* KPI value text: ngăn wrap từng ký tự với overflow-wrap: anywhere từ global CSS */
    .profit-kpi .mud-typography-h6 {
        font-size: clamp(0.7rem, 3.5vw, 1.02rem) !important;
        overflow-wrap: normal !important;
        word-break: keep-all !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}


