/* ══════════════════════════════════════════════════════════════════════
   FT Platform — Global Styles
   Supports: Light + Dark mode via MudBlazor ThemeProvider
   ══════════════════════════════════════════════════════════════════════ */

/* ── DevExpress popup z-index fix ─────────────────────────────────
   DevExpress popups (export dropdown, toolbar menus) render ở body level.
   MudDialog fullscreen z-index ~1300 → đè popup DevExpress.
   Fix: boost DevExpress popup lên trên MudDialog. */
.dxbl-popup-root {
    z-index: 1500 !important;
}

/* ── NotificationBell popover — constrain mobile width ─────────────
   MudPopover render ở body level (portal), scoped CSS không reach được.
   !important vì MudBlazor có thể set inline width override. */
.ft-notif-popover {
    max-width: min(360px, calc(100vw - 16px)) !important;
}

/* Mobile (< 600px): force full-width sheet, bỏ anchor theo bell —
   sheet cố định 8px lề 2 bên, đảm bảo KHÔNG bao giờ tràn viewport.
   Trade-off: popup KHÔNG dính bell trên mobile, nhưng pattern này là chuẩn
   trên Gmail/Slack/iOS — user mobile mong full-width sheet, không phải tooltip. */
@media (max-width: 600px) {
    .ft-notif-popover {
        left: 8px !important;
        right: 8px !important;
        max-width: calc(100vw - 16px) !important;
        width: calc(100vw - 16px) !important;
        transform: none !important;
    }
}


/* ── Clickable / interactive cards (Task list, kanban, categories) ──
   Affordance "bấm được": nâng nhẹ + đổ bóng + viền primary khi hover.
   Dùng cho MudCard Outlined; inline border-left (category) vẫn giữ vì
   inline style thắng class. */
.ft-card-hover {
    transition: box-shadow .15s ease, transform .15s ease, border-color .15s ease;
}

.ft-card-hover:hover {
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
    transform: translateY(-2px);
    border-color: var(--mud-palette-primary);
}


/* ── Base ─────────────────────────────────────────────────────────── */

html, body {
    font-family: 'Roboto', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Smooth transition khi chuyển dark/light mode — chỉ active SAU khi theme đã apply xong.
   Class .ft-transitions-ready được thêm bởi MainLayout sau firstRender.
   Tránh FOUC: không transition trong lúc load ban đầu. */
html.ft-transitions-ready *, html.ft-transitions-ready *::before, html.ft-transitions-ready *::after {
    transition: background-color 0.2s ease, color 0.15s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

a, .btn-link {
    color: #1565C0;
}

.btn-primary {
    color: #fff;
    background-color: #1565C0;
    border-color: #0D47A1;
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
    box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #42A5F5;
}

.content {
    padding-top: 1.1rem;
}

h1:focus {
    outline: none;
}

.valid.modified:not([type=checkbox]) {
    outline: 1px solid #2E7D32;
}

.invalid {
    outline: 1px solid #C62828;
}

.validation-message {
    color: #C62828;
}

/* ── Error Boundaries ────────────────────────────────────────────── */

.blazor-error-boundary {
    background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNyA5OUwyNDAuMzgzIDk5QzIzNy45NjMgOTkgMjM2IDk3LjA2NTEgMjM2IDk0LjY3ODIgMjM2IDk0LjM3OTkgMjM2LjAzMSA5NC4wODg2IDIzNi4wODkgOTMuODA3MkwyMzYuMzM4IDkzLjAxNjIgMjM2Ljg1OCA5Mi4xMzE0IDI1OS40NzMgNTMuNjI5NCAyNTkuOTYxIDUyLjc5ODUgMjYwLjQwNyA1Mi4yNjU4QzI2MS4yIDUxLjQ4MzcgMjYyLjI5NiA1MSAyNjMuNTA2IDUxWk0yNjMuNTg2IDY2LjAxODNDMjYwLjczNyA2Ni4wMTgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
}

    .blazor-error-boundary::after {
        content: "An error has occurred."
    }

#blazor-error-ui {
    background: #fff3cd;
    bottom: 0;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.15);
    display: none;
    left: 0;
    padding: 0.8rem 1.5rem;
    position: fixed;
    width: 100%;
    z-index: 9999;
    color: #856404;
    font-size: 0.95rem;
}

#blazor-error-ui .reload {
    color: #1565C0;
    font-weight: 600;
    margin-left: 0.5rem;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 1rem;
    top: 0.6rem;
    color: #856404;
    text-decoration: none;
    font-size: 1.2rem;
}

.darker-border-checkbox.form-check-input {
    border-color: #929292;
}

.form-floating > .form-control-plaintext::placeholder, .form-floating > .form-control::placeholder {
    color: var(--bs-secondary-color);
    text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder, .form-floating > .form-control:focus::placeholder {
    text-align: start;
}

/* ── Drawer Enhancement ──────────────────────────────────────────── */

.ft-drawer {
    border-right: 1px solid var(--mud-palette-divider, #E0E0E0);
}

.ft-drawer .mud-drawer-header {
    min-height: 56px;
}

/* NavGroup icon muted — nổi bật hơn khi hover */
.mud-nav-group .mud-nav-link .mud-icon-root {
    opacity: 0.7;
    transition: opacity 0.15s ease;
}

.mud-nav-group .mud-nav-link:hover .mud-icon-root {
    opacity: 1;
}

/* Active nav item — accent bar bên trái */
.mud-navmenu .mud-nav-link.active {
    border-left: 3px solid var(--mud-palette-primary, #1565C0);
    background-color: var(--mud-palette-primary-hover, rgba(21,101,192,0.08));
    font-weight: 500;
}

/* Nav item hover — nhẹ nhàng */
.mud-navmenu .mud-nav-link:hover:not(.active) {
    background-color: var(--mud-palette-action-default-hover, rgba(0,0,0,0.04));
}

/* ── Cards & Paper Enhancement ───────────────────────────────────── */

/* Card hover effect cho dashboard cards */
.mud-card {
    transition: transform 0.15s ease, box-shadow 0.2s ease;
}

.mud-card:hover {
    transform: translateY(-1px);
}

/* ── Button Enhancement ──────────────────────────────────────────── */

.mud-button-root {
    transition: all 0.15s ease;
}

/* ── Chip & Badge ────────────────────────────────────────────────── */

.mud-chip {
    font-weight: 500;
    letter-spacing: 0.01em;
}

/* ── DataGrid compact styling ────────────────────────────────────── */

.mud-table-toolbar {
    padding-top: 4px !important;
    padding-bottom: 4px !important;
    min-height: 40px !important;
}

.mud-table-head .mud-table-cell {
    padding-top: 6px !important;
    padding-bottom: 6px !important;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
}

.mud-table-body .mud-table-cell {
    padding-top: 4px !important;
    padding-bottom: 4px !important;
}

.mud-table-pagination {
    padding-top: 2px !important;
    padding-bottom: 2px !important;
    min-height: 36px !important;
}

.mud-table-container {
    overflow-x: auto;
}

.mud-table-container > table {
    width: 100%;
}

/* Table row hover — smooth */
.mud-table-body .mud-table-row {
    transition: background-color 0.1s ease;
}

/* ── Dialog Enhancement ──────────────────────────────────────────── */

.mud-dialog {
    border-radius: 12px;
}

.mud-dialog .mud-dialog-title {
    font-weight: 600;
}

/* ── Snackbar Enhancement ────────────────────────────────────────── */

.mud-snackbar {
    border-radius: 8px;
}

/* ── Page Header Pattern ─────────────────────────────────────────── */

/* Consistent page header spacing */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

/* ── Responsive styling ──────────────────────────────────────────── */

@media (max-width: 599.98px) {
    .mud-main-content .mud-container {
        padding-left: 8px !important;
        padding-right: 8px !important;
    }

    .mud-typography-h5 {
        font-size: 1.15rem !important;
    }

    .mud-paper {
        padding: 8px !important;
    }

    .mud-table-pagination .mud-typography {
        font-size: 0.75rem;
    }

    .mud-dialog {
        margin: 8px !important;
        max-width: calc(100vw - 16px) !important;
    }

    /* Hide card hover effect on mobile (no hover) */
    .mud-card:hover {
        transform: none;
    }
}

@media (min-width: 600px) and (max-width: 959.98px) {
    .mud-dialog {
        max-width: min(600px, 90vw) !important;
    }
}

/* ── Scrollbar Styling ───────────────────────────────────────────── */

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.35);
}

/* Dark mode scrollbar */
.mud-theme-dark ::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
}

.mud-theme-dark ::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* ── Selection Color ─────────────────────────────────────────────── */

::selection {
    background: rgba(21, 101, 192, 0.2);
    color: inherit;
}

/* ── Mobile Bottom Navigation ───────────────────────────────────── */

.ft-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1300;
    background: var(--mud-palette-surface);
    border-top: 1px solid var(--mud-palette-lines-default);
    justify-content: space-around;
    align-items: center;
    padding: 4px 0;
    padding-bottom: env(safe-area-inset-bottom, 4px);
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
}

.ft-bottom-nav__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 6px 12px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--mud-palette-text-secondary);
    font-size: 0.65rem;
    font-weight: 500;
    min-width: 56px;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.15s ease, background-color 0.15s ease;
}

.ft-bottom-nav__item:active {
    background-color: var(--mud-palette-action-default-hover);
}

.ft-bottom-nav__item.active {
    color: var(--mud-palette-primary);
}

.ft-bottom-nav__item.active .mud-icon-root {
    color: var(--mud-palette-primary);
}

/* Padding bottom for main content on mobile to avoid bottom nav overlap */
@media (max-width: 959.98px) {
    .mud-main-content {
        padding-bottom: 64px !important;
    }
}

/* ── Touch-Friendly Enhancements ───────────────────────────────── */

@media (max-width: 959.98px) {
    /* Larger touch targets for buttons */
    .mud-icon-button {
        min-width: 44px;
        min-height: 44px;
    }

    /* Larger touch targets for text buttons on mobile */
    .mud-button-root.mud-button {
        min-height: 44px;
    }

    /* Larger touch targets for nav items */
    .mud-nav-link {
        min-height: 44px;
    }

    /* More padding for form fields on touch */
    .mud-input-control .mud-input {
        min-height: 44px;
    }

    /* Allow filter bar buttons to wrap on narrow screens */
    .d-flex.gap-2 {
        flex-wrap: wrap;
    }
}

/* ── Filter Bar Button Equal Width ───────────────────────────────── */

.d-flex.gap-2 > .mud-button-root {
    flex: 1 1 0;
    white-space: nowrap;
}

/* Single button should not stretch full width */
.d-flex.gap-2 > .mud-button-root:first-child:last-child {
    flex: 0 1 auto;
}

/* ── Utility Classes ─────────────────────────────────────────────── */

.text-gradient-primary {
    background: linear-gradient(135deg, #1565C0, #42A5F5);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ── Attendance Calendar ────────────────────────────────────────── */

.att-calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    border-bottom: 1px solid var(--mud-palette-lines-default);
}

.att-calendar-grid:last-of-type {
    border-bottom: none;
}

.att-calendar-header {
    background-color: var(--mud-palette-surface);
}

.att-calendar-header-cell {
    padding: 8px 4px;
    text-align: center;
    border-right: 1px solid var(--mud-palette-lines-default);
}

.att-calendar-header-cell:last-child {
    border-right: none;
}

.att-calendar-cell {
    min-height: 72px;
    border-right: 1px solid var(--mud-palette-lines-default);
    position: relative;
}

.att-calendar-cell:last-child {
    border-right: none;
}

.att-calendar-empty {
    background-color: var(--mud-palette-background);
    opacity: 0.5;
}

.att-calendar-day {
    padding: 4px 6px;
    cursor: default;
    display: flex;
    flex-direction: column;
    gap: 2px;
    transition: transform 0.1s ease, box-shadow 0.15s ease;
}

.att-calendar-day:hover {
    transform: scale(1.02);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    z-index: 1;
}

.att-weekend {
    background-color: var(--mud-palette-background);
    opacity: 0.85;
}

.att-today {
    outline: 2px solid var(--mud-palette-primary);
    outline-offset: -2px;
    z-index: 1;
}

.att-day-number {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--mud-palette-text-primary);
}

.att-today-number {
    background: var(--mud-palette-primary);
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
}

.att-day-times {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.att-time-in,
.att-time-out {
    font-size: 0.65rem;
    color: var(--mud-palette-text-secondary);
    line-height: 1.2;
}

.att-time-in::before {
    content: "↓ ";
    color: var(--mud-palette-success);
}

.att-time-out::before {
    content: "↑ ";
    color: var(--mud-palette-error);
}

.att-day-badge {
    position: absolute;
    top: 3px;
    right: 4px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    color: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    line-height: 1;
}

.att-calendar-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding: 10px 16px;
    background: var(--mud-palette-surface);
    border-top: 1px solid var(--mud-palette-lines-default);
}

.att-legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    color: var(--mud-palette-text-secondary);
}

.att-legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

/* Responsive: mobile hiển thị nhỏ gọn hơn */
@media (max-width: 600px) {
    .att-calendar-cell {
        min-height: 52px;
    }
    .att-day-times {
        display: none;
    }
    .att-day-number {
        font-size: 0.75rem;
    }
    .att-calendar-legend {
        gap: 8px;
    }
}

/* AI Diagnosis Response */
.ai-response-content {
    color: var(--mud-palette-text-primary);
    font-size: 0.875rem;
    line-height: 1.6;
}
.ai-response-content h4, .ai-response-content h5, .ai-response-content h6 {
    color: var(--mud-palette-primary);
}
.ai-response-content ul, .ai-response-content ol {
    color: var(--mud-palette-text-primary);
}
.ai-response-content strong {
    color: var(--mud-palette-text-primary);
    font-weight: 600;
}
.ai-response-content code {
    background: var(--mud-palette-background-gray);
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 0.85em;
}

/* ── ApexCharts Dark Mode Tooltip Fix ──────────────────────────── */
/* ApexCharts tooltip render ở body level (portal), KHÔNG nằm trong .mud-theme-dark.
   Dùng html[data-ft-dark] (set bởi App.razor) để target chính xác. */

html[data-ft-dark="true"] .apexcharts-tooltip {
    background: #1E1E2D !important;
    color: #E0E0E0 !important;
    border: 1px solid #3a3a4a !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5) !important;
}

html[data-ft-dark="true"] .apexcharts-tooltip-title {
    background: #27293d !important;
    color: #E0E0E0 !important;
    border-bottom: 1px solid #3a3a4a !important;
}

html[data-ft-dark="true"] .apexcharts-tooltip-text,
html[data-ft-dark="true"] .apexcharts-tooltip-text-y-label,
html[data-ft-dark="true"] .apexcharts-tooltip-text-y-value,
html[data-ft-dark="true"] .apexcharts-tooltip-text-goals-label,
html[data-ft-dark="true"] .apexcharts-tooltip-text-goals-value,
html[data-ft-dark="true"] .apexcharts-tooltip-text-z-label,
html[data-ft-dark="true"] .apexcharts-tooltip-text-z-value {
    color: #E0E0E0 !important;
}

html[data-ft-dark="true"] .apexcharts-tooltip-series-group {
    background: transparent !important;
}

/* ApexCharts xAxisTooltip */
html[data-ft-dark="true"] .apexcharts-xaxistooltip {
    background: #1E1E2D !important;
    color: #E0E0E0 !important;
    border: 1px solid #3a3a4a !important;
}

html[data-ft-dark="true"] .apexcharts-xaxistooltip-text {
    color: #E0E0E0 !important;
}

/* ApexCharts legend text */
html[data-ft-dark="true"] .apexcharts-legend-text {
    color: #E0E0E0 !important;
}

/* Giữ lại fallback cho trường hợp tooltip nằm trong MudBlazor scope */
.mud-theme-dark .apexcharts-tooltip {
    background: #1E1E2D !important;
    color: #E0E0E0 !important;
    border: 1px solid #3a3a4a !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5) !important;
}

.mud-theme-dark .apexcharts-tooltip-title {
    background: #27293d !important;
    color: #E0E0E0 !important;
    border-bottom: 1px solid #3a3a4a !important;
}

.mud-theme-dark .apexcharts-tooltip-text,
.mud-theme-dark .apexcharts-tooltip-text-y-label,
.mud-theme-dark .apexcharts-tooltip-text-y-value {
    color: #E0E0E0 !important;
}

.mud-theme-dark .apexcharts-tooltip-series-group {
    background: transparent !important;
}

.mud-theme-dark .apexcharts-xaxistooltip {
    background: #1E1E2D !important;
    color: #E0E0E0 !important;
    border: 1px solid #3a3a4a !important;
}

.mud-theme-dark .apexcharts-legend-text {
    color: #E0E0E0 !important;
}

/* ── Fullwidth dashboard override ──
   MainLayout wraps every page in <MudContainer MaxWidth.ExtraLarge pa-2 pa-sm-4>
   which caps content at 1920px — leaving ugly empty space on 2K/4K monitors for
   dashboard pages. When a page uses .dashboard-root, neutralize the container cap
   and padding so dashboard-root can fill the full main-content area (respecting
   drawer when open). Applied globally because scoped CSS cannot reach parent. */
body:has(.dashboard-root) .mud-main-content > .mud-container {
    max-width: none !important;
    padding: 0 !important;
}

/* SCADA page — full viewport (fit-to-contain canvas) */
body:has(.scada-page) .mud-main-content > .mud-container {
    max-width: none !important;
    padding: 0 !important;
}

/* Chart history pages — full width, charts can span to 2K/4K without empty gutters.
   Keeps existing px-4 padding from the wrapper div. */
body:has(.chart-history-page) .mud-main-content > .mud-container {
    max-width: none !important;
    padding: 0 !important;
}

/* Overview Dashboard (/dashboard) — full width with dynamic padding-inline.
   Uses .dashboard-page wrapper which manages its own breakpoint padding.
   Different from .dashboard-root (Machine/Energy fixed-viewport, no-scroll). */
body:has(.dashboard-page) .mud-main-content > .mud-container {
    max-width: none !important;
    padding: 0 !important;
}

/* Energy Cost Dashboard (/energy/cost-dashboard) — same overview pattern (§15). */
body:has(.cost-dashboard-page) .mud-main-content > .mud-container {
    max-width: none !important;
    padding: 0 !important;
}

/* Warehouse Dashboard (/warehouse/dashboard) — same overview pattern (§15). */
body:has(.warehouse-dashboard-page) .mud-main-content > .mud-container {
    max-width: none !important;
    padding: 0 !important;
}

/* System Management pages — full width with dynamic padding-inline.
   Applied to list/table/dashboard/form pages. Form sections inside should be wrapped
   in .sysmgmt-form to cap field width and prevent inputs from stretching too wide. */
body:has(.sysmgmt-page) .mud-main-content > .mud-container {
    max-width: none !important;
    padding: 0 !important;
}
.sysmgmt-page {
    padding-inline: 16px;
    padding-top: 16px;
    padding-bottom: 16px;
}
@media (min-width: 1280px) { .sysmgmt-page { padding-inline: 24px; } }
@media (min-width: 1920px) { .sysmgmt-page { padding-inline: 32px; } }
@media (min-width: 2560px) { .sysmgmt-page { padding-inline: 48px; } }

/* Form sections inside sysmgmt-page — cap width so inputs don't stretch ugly on FHD/2K/4K.
   Use this around groups of MudCard form fields. Data grids/tables stay outside this wrapper
   to keep using the full container width.
   margin-inline:auto centers the form horizontally on wide viewports (2K/4K). */
.sysmgmt-form {
    max-width: 1200px;
    margin-inline: auto;
}

/* Standard MudDataGrid action column — prevent wrap, fix minimum width.
   Trick: width:1% + white-space:nowrap → column shrinks to content width,
   other columns fill remainder. Apply CellClass + HeaderClass = "actions-cell". */
.mud-table-cell.actions-cell,
th.actions-cell {
    width: 1%;
    white-space: nowrap;
    text-align: right;
    padding-inline: 8px !important;
}
.actions-cell-inner {
    display: inline-flex;
    gap: 4px;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: nowrap;
}
/* Touch target ≥ 36px on HMI 7" (1024×600) and tablets — auto bump from Size.Small (32px).
   Desktop (>1280px) keeps Size.Small native size. */
@media (max-width: 1280px) {
    .actions-cell-inner .mud-icon-button,
    .actions-cell-inner .mud-button-root {
        min-width: 36px;
        min-height: 36px;
    }
}

/* Standard list-page toolbar (search + filters + actions).
   Replaces the old MudGrid xs=12 sm=4 pattern that stretched inputs to ~620px on FHD.
   Layout: flex row with fixed max-widths per slot; actions push right via margin-left:auto.
   On mobile (<600px), every slot stacks full-width. */

/* When a list page contains .page-toolbar, override MainLayout's MudContainer cap (ExtraLarge=1920px)
   so the page extends full-width on 2K/4K monitors. Inner content (PageHeader, page-toolbar, DataGrid)
   gets natural padding from the elements themselves; container padding is reset to 0. */
body:has(.page-toolbar) .mud-main-content > .mud-container {
    max-width: none !important;
    padding-inline: 16px !important;
}
@media (min-width: 1280px) { body:has(.page-toolbar) .mud-main-content > .mud-container { padding-inline: 24px !important; } }
@media (min-width: 1920px) { body:has(.page-toolbar) .mud-main-content > .mud-container { padding-inline: 32px !important; } }
@media (min-width: 2560px) { body:has(.page-toolbar) .mud-main-content > .mud-container { padding-inline: 48px !important; } }

.page-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
    padding: 12px;
}
.page-toolbar .tb-search    { flex: 1 1 240px; max-width: 320px; }
.page-toolbar .tb-filter    { flex: 0 1 200px; min-width: 160px; max-width: 200px; }
.page-toolbar .tb-range     { flex: 0 1 240px; max-width: 240px; }                  /* single date picker */
.page-toolbar .tb-daterange { flex: 0 1 320px; min-width: 280px; max-width: 320px; } /* date range (dd/MM/yyyy → dd/MM/yyyy) — cần rộng hơn để không cắt năm */
.page-toolbar .tb-actions   { display: flex; gap: 8px; margin-left: auto; align-items: stretch; }
.page-toolbar .tb-actions:has(.task-assignee-toggle) { flex-wrap: wrap; }     /* mobile: toggle + nút xuống dòng thay vì tràn */
.page-toolbar .tb-actions .task-assignee-toggle { align-self: center; }       /* canh giữa toggle Của tôi/Tất cả trong cụm action bên phải */
.page-toolbar .tb-actions .mud-button-root { align-self: stretch; min-width: 90px; }

/* PageHeader Actions slot — ensure all buttons (New / Export / Import / etc.) share equal height
   regardless of variant. MudButton Filled and Outlined render slightly different padding/border,
   so align-items:stretch + align-self:stretch on the button forces visual height parity.
   Also handles MudFileUpload-wrapped buttons (Import) so they line up with raw MudButtons. */
.page-header-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: stretch;
}
.page-header-actions > .mud-button-root,
.page-header-actions > .mud-file-upload,
.page-header-actions > .mud-menu {
    align-self: stretch;
}
.page-header-actions > .mud-button-root,
.page-header-actions .mud-file-upload .mud-button-root,
.page-header-actions .mud-menu .mud-button-root {
    min-width: 100px;
}
.page-header-actions .mud-file-upload,
.page-header-actions .mud-menu {
    display: flex;
}
.page-header-actions .mud-file-upload .mud-button-root,
.page-header-actions .mud-menu .mud-button-root {
    height: 100%;
}

@media (max-width: 599px) {
    .page-toolbar .tb-search,
    .page-toolbar .tb-filter,
    .page-toolbar .tb-range,
    .page-toolbar .tb-daterange,
    .page-toolbar .tb-actions {
        flex: 1 1 100%;
        max-width: none;
        min-width: 0;
        margin-left: 0;
    }
}

