/* Modern System Dashboard - Glassmorphism SaaS Gold Theme */
:root {
    --glass-bg: rgba(255, 255, 255, 0.75);
    --glass-border: rgba(255, 255, 255, 0.4);
    --glass-shadow: 0 8px 32px 0 rgba(197, 160, 89, 0.15);

    --primary-gold: #c5a059;
    --primary-gold-dark: #a6844a;
    --primary-gold-light: #f1d39b;

    --deep-black: #0f0f0f;
    --sidebar-bg: #ffffff;

    --gradient-gold: var(--gradient-gold);
    --gradient-premium: var(--gradient-premium);
    --gradient-gold-premium: var(--gradient-gold-premium);
    --gradient-glass: linear-gradient(135deg, rgba(255, 255, 255, 0.4) 0%, rgba(255, 255, 255, 0.1) 100%);

    --shadow-soft: 0 8px 32px 0 rgba(197, 160, 89, 0.15);
    --shadow-hover: 0 12px 48px 0 rgba(197, 160, 89, 0.25);

    --sidebar-width: 260px;
    --transition-base: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    --success-soft: rgba(31, 171, 137, 0.1);
    --warning-soft: rgba(255, 152, 0, 0.1);
    --info-soft: rgba(47, 128, 237, 0.1);
    --danger-soft: rgba(255, 154, 158, 0.1);
    --gold-soft: rgba(197, 160, 89, 0.1);

    /* Additional Glass Tokens */
    --glass-bg-op: rgba(255, 255, 255, 0.6);
    --glass-border-op: rgba(197, 160, 89, 0.25);
}

html, 
body {
    height: 100%;
}

body {
    background-color: var(--bg-system);
    font-family: var(--font-family-system), system-ui, -apple-system, sans-serif;
    color: var(--text-dark);
    margin: 0;
    display: flex;
    flex-direction: column;
}

/* Glassmorphism Classes */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    box-shadow: var(--glass-shadow);
    transition: var(--transition-base);
}

.glass-panel:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-hover);
}

.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 1px solid var(--glass-border);
    border-radius: 15px;
    box-shadow: var(--shadow-soft), inset 0 0 0 1px rgba(255,255,255,0.05);
}

/* Glass Form Elements */
.glass-input, .form-control.glass-panel {
    background: rgba(255, 255, 255, 0.8) !important;
    border: 1px solid var(--glass-border-op) !important;
    color: #333 !important;
    transition: var(--transition-base);
    border-radius: 10px;
}

.glass-input:focus, .form-control.glass-panel:focus {
    background: #fff !important;
    border-color: var(--primary-gold) !important;
    box-shadow: 0 0 0 0.25rem var(--gold-soft) !important;
    outline: none;
}

.glass-check {
    width: 1.25em;
    height: 1.25em;
    background-color: var(--glass-bg-op);
    border: 1px solid var(--glass-border-op);
    cursor: pointer;
}

.glass-check:checked {
    background-color: var(--primary-gold);
    border-color: var(--primary-gold);
}

/* Modern Card */
.modern-card {
    border: none;
    border-radius: 20px;
    background: white;
    box-shadow: var(--glass-shadow);
    transition: var(--transition-base);
    overflow: hidden;
}

.modern-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-hover);
}

.stat-card {
    position: relative;
    overflow: hidden;
}

.stat-card::after {
    content: '';
    position: absolute;
    top: -50px;
    right: -50px;
    width: 150px;
    height: 150px;
    background: radial-gradient(circle, var(--gold-soft) 0%, transparent 70%);
    border-radius: 50%;
    z-index: 0;
    pointer-events: none;
}

.modern-card .card-header {
    background: transparent;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    padding: 1.25rem 1.5rem;
}

/* Sidebar Styling */
#sidebar-wrapper {
    background: var(--sidebar-bg) !important;
    backdrop-filter: none;
    border-right: 1px solid var(--gold-soft);
    box-shadow: 2px 0 15px rgba(0, 0, 0, 0.03);
    z-index: 1000;
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    flex: 0 0 var(--sidebar-width);
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), min-width 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: visible; /* Bớt gắt gao để dễ override */
    position: relative;
    height: auto !important;
    min-height: 100vh;
}

#sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
    backdrop-filter: blur(2px);
}

/* Backdrop only shown on mobile when sidebar is open */
/* See media query below for mobile-specific rule */

.sidebar-close-btn {
    display: none;
    position: absolute;
    top: 1rem;
    right: 1rem;
    font-size: 1.5rem;
    color: var(--primary-gold);
    cursor: pointer;
    z-index: 1001;
}

.sidebar-heading {
    padding: 2.5rem 1rem;
    background: #ffffff;
}

.sidebar-heading a {
    color: var(--primary-gold-dark) !important;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-size: 1.1rem !important;
    text-decoration: none;
}

.sidebar-heading i {
    font-size: 1.8rem;
}

.list-group-item {
    background: transparent;
    border: none;
    padding: 0.9rem 1.5rem;
    margin: 0;
    border-radius: 0;
    transition: all 0.2s ease;
    border-left: 4px solid transparent;
}

.list-group-item a, .sidebar-link {
    color: var(--text-dark);
    opacity: 0.7;
    font-weight: 500;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    width: 100%;
    text-decoration: none;
    transition: var(--transition-base);
}

.list-group-item i, .sidebar-link i {
    color: var(--primary-gold);
    opacity: 0.6;
    font-size: 1.2rem;
    margin-right: 15px;
    transition: all 0.2s ease;
}

.list-group-item:hover {
    background: var(--gold-soft);
    border-left-color: var(--primary-gold);
}

.list-group-item:hover a {
    color: var(--primary-gold-dark);
    opacity: 1;
}

.list-group-item:hover i {
    color: var(--primary-gold-dark);
}

.list-group-item.active {
    background: var(--gold-soft) !important;
    border-left: 4px solid var(--primary-gold) !important;
    box-shadow: none;
}

.list-group-item.active a {
    color: var(--primary-gold-dark) !important;
    font-weight: 700;
}

.list-group-item.active i, .sidebar-link.active i {
    color: var(--primary-gold-dark) !important;
    opacity: 1;
}

/* Navbar Extension */
.navbar {
    border-bottom: 1px solid rgba(197, 160, 89, 0.1) !important;
    padding: 0.75rem 2rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.02);
    position: sticky;
    top: 0;
    z-index: 1020 !important;
}

.navbar .dropdown-menu {
    z-index: 1030 !important;
}

/* Stat Icon Upgrade */
.stat-icon-wrapper {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
    margin-bottom: 1rem;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
}

.bg-gold-light {
    background: #fffcf5;
    color: var(--primary-gold);
}

.bg-gradient-gold {
    background: var(--gradient-gold);
}

.bg-gradient-dark {
    background: var(--gradient-dark-gold);
}

.bg-gradient-gold-premium {
    background: #c5a059 !important;
    background: var(--gradient-gold-premium) !important;
}

.hero-welcome-card {
    color: #ffffff !important;
    position: relative;
    z-index: 1;
}

.hero-welcome-card h1,
.hero-welcome-card p,
.hero-welcome-card .lead {
    color: inherit !important;
}

.bg-gradient-premium {
    background: var(--gradient-premium);
}

.bg-gradient-success {
    background: linear-gradient(135deg, #42d392 0%, #209978 100%);
}

.bg-gradient-info {
    background: linear-gradient(135deg, #56ccf2 0%, #2f80ed 100%);
}

.bg-gradient-danger {
    background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 100%, #fecfef 100%);
}

/* Dashboard Report Cards */
.report-card {
    position: relative;
    border-radius: 24px;
    padding: 2rem;
    background: white;
    border: 1px solid rgba(197, 160, 89, 0.1);
    transition: var(--transition-base);
    height: 100%;
}

.report-card:hover {
    border-color: var(--primary-gold);
    box-shadow: var(--shadow-hover);
}

.report-card .icon-panel {
    font-size: 3rem;
    background: var(--gradient-gold);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 1.5rem;
}

/* DataTables Aesthetic */
.dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background: var(--gradient-gold) !important;
    border: none !important;
    color: white !important;
    border-radius: 8px !important;
}

table.dataTable thead th {
    background: var(--gold-soft);
    color: var(--primary-gold-dark);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--primary-gold-light);
}

.table-dark-transparent {
    background: transparent !important;
}

.table-dark-transparent thead th {
    background: rgba(255, 255, 255, 0.8) !important;
    color: var(--primary-gold-dark) !important;
    border-bottom: 2px solid var(--glass-border-op);
    text-transform: uppercase;
    font-size: 0.85rem;
    letter-spacing: 1px;
    padding: 15px;
}

.table-dark-transparent tbody td {
    border-color: rgba(0, 0, 0, 0.05) !important;
    color: #333 !important;
    padding: 15px;
    vertical-align: middle;
}

.system-pulse {
    background: var(--success-soft);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    color: #1fab89;
}

.status-badge-premium {
    background: rgba(31, 171, 137, 0.2);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(31, 171, 137, 0.6);
    color: #42d392 !important;
    padding: 8px 16px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(31, 171, 137, 0.2);
}

.pulse-dot-green {
    width: 8px;
    height: 8px;
    background-color: #42d392;
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(66, 211, 146, 0.7);
    animation: pulse-green 2s infinite;
}

.btn-glass {
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white !important;
    transition: all 0.3s ease;
}

.btn-gradient-gold {
    background: var(--gradient-gold) !important;
    color: #ffffff !important;
    font-weight: 700 !important;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(0, 0, 0, 0.1) !important;
    transition: var(--transition-base);
    box-shadow: 0 4px 12px rgba(197, 160, 89, 0.3) !important;
}

.btn-gold {
    background: var(--primary-gold);
    color: #fff !important;
    border: none;
    font-weight: bold;
    transition: var(--transition-base);
    border-radius: 8px;
    padding: 8px 20px;
}

.btn-gold:hover {
    background: var(--primary-gold-dark);
    color: #fff !important;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px var(--gold-soft);
}

.btn-gradient-gold-premium {
    background: #c5a059 !important; /* Fallback color */
    background: var(--gradient-gold-premium) !important;
    border: 1px solid rgba(197, 160, 89, 0.4) !important;
    color: white !important;
    box-shadow: 0 4px 15px rgba(197,160,89,0.3) !important;
    transition: var(--transition-base);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-gradient-gold-premium:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(197,160,89,0.5) !important;
    filter: brightness(1.1);
    color: white !important;
}

.btn-gradient-gold-premium i {
    color: white !important;
}

.btn-outline-gold {
    background: transparent;
    border: 1px solid var(--primary-gold);
    color: var(--primary-gold);
    font-weight: bold;
    transition: var(--transition-base);
}

.btn-outline-gold:hover {
    background: var(--primary-gold);
    color: #fff !important;
}

.btn-outline-glass {
    background: rgba(255, 255, 255, 0.6);
    border: 1px solid var(--glass-border-op);
    color: #333 !important;
    transition: var(--transition-base);
}

.btn-outline-glass:hover {
    background: rgba(255, 255, 255, 0.9);
    border-color: var(--primary-gold);
    color: var(--primary-gold-dark) !important;
}

.btn-gradient-gold:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(211, 84, 0, 0.4) !important;
    filter: brightness(0.9);
}

.btn-white {
    background: #ffffff !important;
    color: #8a6d3b !important;
    border: 1px solid rgba(184, 134, 11, 0.3) !important;
    transition: var(--transition-base);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05) !important;
}

.btn-white:hover {
    background: #fdfaf5 !important;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(197, 160, 89, 0.15) !important;
}

.btn-glass:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

@keyframes pulse-green {
    0% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(66, 211, 146, 0.7);
    }

    70% {
        transform: scale(1);
        box-shadow: 0 0 0 6px rgba(66, 211, 146, 0);
    }

    100% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(66, 211, 146, 0);
    }
}

.bg-success-soft {
    background-color: var(--success-soft) !important;
}

.bg-warning-soft {
    background-color: var(--warning-soft) !important;
}

.bg-info-soft {
    background-color: var(--info-soft) !important;
}

.bg-danger-soft {
    background-color: var(--danger-soft) !important;
}

.bg-gold-soft {
    background-color: var(--gold-soft) !important;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(15px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-fade-in {
    animation: fadeIn 0.5s ease-out forwards;
}

@keyframes pulse {
    0% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(31, 171, 137, 0.7);
    }

    70% {
        transform: scale(1);
        box-shadow: 0 0 0 10px rgba(31, 171, 137, 0);
    }

    100% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(31, 171, 137, 0);
    }
}

/* Utilities */
.text-gold {
    color: var(--primary-gold) !important;
}

.tracking-wider {
    letter-spacing: 0.1em;
}

.border-gold-soft {
    border-color: rgba(197, 160, 89, 0.2) !important;
}

.btn-glass-dark {
    background: rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white !important;
    transition: all 0.3s ease;
}

.btn-glass-dark:hover {
    background: rgba(0, 0, 0, 0.2);
    transform: translateY(-2px);
}

.text-white-shadow {
    color: #ffffff !important;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.text-gold-light {
    color: var(--primary-gold-light) !important;
}

.bg-glass {
    background: rgba(255, 255, 255, 0.4);
    backdrop-filter: blur(5px);
}

.rounded-2xl {
    border-radius: 1.5rem !important;
}

/* Layout */
#wrapper {
    flex: 1 0 auto;
    display: flex;
    width: 100%;
    overflow-x: hidden;
    position: relative;
}

#sidebar-wrapper {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    flex: 0 0 var(--sidebar-width);
    z-index: 1000;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#page-content-wrapper {
    flex: 1;
    width: 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
    transition: var(--transition-base);
}

/* Desktop: toggled = sidebar collapsed */
@media (min-width: 992px) {
    #wrapper.toggled #sidebar-wrapper {
        width: 0 !important;
        min-width: 0 !important;
        flex: 0 0 0 !important;
        border-right: none !important;
        overflow: hidden !important;
        opacity: 0 !important;
        visibility: hidden !important;
        pointer-events: none !important;
    }

    #wrapper.toggled #sidebar-wrapper * {
        opacity: 0 !important;
        visibility: hidden !important;
    }

    #wrapper.toggled #page-content-wrapper {
        width: 100% !important;
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }
}

@media (max-width: 991.98px) {
    #sidebar-wrapper {
        transform: translateX(calc(-1 * var(--sidebar-width)));
        position: fixed;
        /* Re-add for mobile overlay */
        height: 100vh;
        /* Re-add for mobile overlay */
        top: 0;
        left: 0;
    }

    #page-content-wrapper {
        margin-left: 0 !important;
        width: 100% !important;
    }

    #wrapper.toggled #sidebar-wrapper {
        transform: translateX(0);
        box-shadow: 10px 0 30px rgba(0, 0, 0, 0.1);
    }

    #wrapper.toggled #sidebar-backdrop {
        display: block;
    }

    .sidebar-close-btn {
        display: block;
    }
}

.footer {
    flex-shrink: 0;
    min-height: 60px;
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.95) !important;
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border-top: 1px solid rgba(197, 160, 89, 0.15) !important;
    position: relative;
    z-index: 10;
    margin-top: auto;
    width: auto;
}

.footer .container-fluid {
    width: 100%;
    padding-left: 2.5rem;
    padding-right: 1.5rem;
}


.border-radius-10 {
    border-radius: 10px !important;
}

.fw-800 {
    font-weight: 800;
}

.fw-700 {
    font-weight: 700;
}

.fw-600 {
    font-weight: 600;
}

.fw-500 {
    font-weight: 500;
}

/* Modern Table */
.modern-table {
    border-collapse: separate;
    border-spacing: 0 8px;
}

.modern-table thead th {
    background: var(--gold-soft);
    color: var(--primary-gold-dark);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
    padding: 1rem 1.5rem;
    border: none;
}

.modern-table tbody tr {
    background: white;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.02);
    transition: var(--transition-base);
}

.modern-table tbody tr:hover {
    transform: scale(1.005);
    box-shadow: 0 5px 15px rgba(197, 160, 89, 0.1);
}

.modern-table td {
    padding: 1.25rem 1.5rem;
    border: none;
    color: #4a4a4a;
}

.modern-table td:first-child {
    border-radius: 12px 0 0 12px;
}

.modern-table td:last-child {
    border-radius: 0 12px 12px 0;
}

/* Quick Action Buttons */
.quick-action-btn {
    background: white;
    border: 1px solid rgba(197, 160, 89, 0.1);
    border-radius: 15px;
    transition: var(--transition-base);
}

.quick-action-btn:hover {
    background: var(--gold-soft);
    border-color: var(--primary-gold);
    transform: translateY(-3px);
}

.bg-glass {
    background: rgba(255, 255, 255, 0.1) !important;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.opacity-05 {
    opacity: 0.05 !important;
}

.opacity-10 {
    opacity: 0.1 !important;
}

.opacity-15 {
    opacity: 0.15 !important;
}

.opacity-20 {
    opacity: 0.2 !important;
}

/* --- Print Optimization --- */
@media print {

    /* Hide non-printable elements */
    #sidebar-wrapper,
    #sidebar-backdrop,
    .navbar,
    .footer,
    .nav-pills,
    .btn,
    #sidebar-toggle,
    .zalo-chat-widget,
    #custom-date-range,
    #taxTabs,
    .alert-info,
    #btnSubmitSaaSTax,
    .btn-outline-secondary,
    .card-header .btn {
        display: none !important;
    }

    /* Reset layout for print */
    #wrapper {
        display: block !important;
    }

    #page-content-wrapper {
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
    }

    main {
        padding: 0 !important;
    }

    .container-fluid {
        padding: 0 !important;
    }

    .card {
        border: 1px solid #ddd !important;
        box-shadow: none !important;
        margin-bottom: 20px !important;
        break-inside: avoid;
    }

    .card-body {
        padding: 15px !important;
    }

    body {
        background: white !important;
        font-size: 11pt !important;
    }

    h1,
    .h3 {
        font-size: 18pt !important;
        margin-bottom: 5mm !important;
    }

    table {
        width: 100% !important;
        border-collapse: collapse !important;
    }

    table th,
    table td {
        border: 1px solid #eee !important;
        padding: 8px !important;
    }

    /* Print-only elements visibility */
    .print-only {
        display: block !important;
    }

    .no-print {
        display: none !important;
    }

    /* Force landscape if needed via orientation: profile */
    @page {
        margin: 1.5cm;
    }
}

/* Hide print-only elements on screen */
.print-only {
    display: none;
}

/* --- AI Assistant Chatbot --- */
.ai-chat-wrapper {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 2000;
}

.ai-chat-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--gradient-gold-premium);
    box-shadow: 0 10px 25px rgba(197, 160, 89, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    transition: var(--transition-base);
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.ai-chat-btn:hover {
    transform: scale(1.1) rotate(5deg);
    box-shadow: 0 15px 35px rgba(197, 160, 89, 0.5);
}

.ai-chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 500px;
    max-height: calc(100vh - 150px);
    min-height: 250px;
    display: flex;
    flex-direction: column;
    z-index: 2001;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(15px);
    border: 1px solid var(--glass-border-op);
    border-radius: 20px;
    box-shadow: var(--shadow-hover);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateY(20px);
}

.ai-chat-window.show {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
}

.ai-chat-header {
    background: var(--gradient-gold-premium);
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: white;
    flex: 0 0 auto; /* Không co giãn phần header */
}

.ai-chat-body {
    flex: 1 1 auto; /* Chiếm toàn bộ không gian còn lại và cho phép co giãn */
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-height: 0; /* Quan trọng để flex child có thể nhỏ hơn nội dung */
}

.ai-chat-footer {
    padding: 12px;
    background: #fff;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    flex: 0 0 auto;
}

.ai-chat-footer .input-group .form-control {
    border-radius: 12px 0 0 12px !important;
    font-size: 0.85rem;
    padding: 10px 15px;
    border: 1px solid #eee !important;
}

.ai-chat-footer .btn-primary {
    border-radius: 0 12px 12px 0 !important;
    padding: 0 15px !important;
    font-size: 0.9rem !important;
    height: auto !important;
    min-height: 42px !important;
    box-shadow: none !important;
    margin: 0 !important;
}

.ai-chat-footer .btn-primary:hover {
    transform: none !important;
}

.chat-bubble {
    padding: 10px 15px;
    border-radius: 15px;
    max-width: 85%;
    font-size: 0.9rem;
    line-height: 1.4;
    position: relative;
    word-wrap: break-word;
}

.chat-bubble-ai {
    background: #f0f2f5;
    color: #333;
    align-self: flex-start;
    border-bottom-left-radius: 2px;
}

.chat-bubble-user {
    background: var(--primary-gold);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}

.typing-indicator {
    padding: 10px 15px;
    background: #f0f2f5;
    border-radius: 15px;
    align-self: flex-start;
    display: none;
    margin-bottom: 10px;
}

.typing-indicator span {
    height: 8px;
    width: 8px;
    float: left;
    margin: 0 1px;
    background-color: #9e9e9e;
    display: block;
    border-radius: 50%;
    opacity: 0.4;
    animation: typing 1s infinite;
}

@keyframes typing {
    0% { transform: translateY(0px); }
    28% { transform: translateY(-5px); }
    44% { transform: translateY(0px); }
}

@media (max-width: 991.98px) {
    .ai-chat-window {
        width: calc(100vw - 30px);
        height: calc(100vh - 120px);
        max-height: calc(100vh - 100px);
        bottom: 70px;
        right: 0;
    }
    .ai-chat-btn {
        width: 50px;
        height: 50px;
        font-size: 1.2rem;
    }

    /* ==========================================================================
       SYSTEM-WIDE MOBILE UX OPTIMIZATION (REFINED FLATTENING)
       ========================================================================== */
    
    html body { overflow-x: hidden !important; }

    /* Parent Wrapper: Use width: 100% instead of 100vw to avoid flex squashing */
    html body div.main-content, 
    html body div.content-wrapper, 
    html body div#page-content-wrapper { 
        padding-left: 3px !important; 
        padding-right: 3px !important; 
        margin-left: 0 !important; 
        margin-right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
    }
    
    /* Targeted Flattening: Only kill side padding on mobile, leave vertical padding alone */
    html body .main-content .container-fluid,
    html body .main-content .content-wrapper,
    html body .main-content section.content,
    html body .content-wrapper .container-fluid,
    html body .content-wrapper section.content,
    html body .container-fluid .container-fluid,
    html body .px-2, html body .px-3, html body .px-4,
    html body .p-3, html body .p-4 { 
        padding-left: 0 !important; 
        padding-right: 0 !important; 
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    /* Smart Grid Stretch */
    html body .row { 
        margin-left: -3px !important; 
        margin-right: -3px !important; 
        display: flex !important; 
        flex-wrap: wrap !important; 
        width: calc(100% + 6px) !important;
    }
    
    /* Grid Columns -> Force 2 Columns ONLY on small phones/portrait */
    @media (max-width: 575.98px) {
        html body .row > .col-6, 
        html body .row > [class*="col-6"],
        html body .row > .col-md-2,
        html body .row > .col-md-3,
        html body [id*="stats"] [class*="col-"],
        html body [class*="grid"] [class*="col-"] { 
            flex: 0 0 50% !important; 
            max-width: 50% !important; 
            width: 50% !important; 
            padding-left: 3px !important; 
            padding-right: 3px !important;
        }
    }
    
    /* Large Columns -> Full width on mobile */
    html body .row > .col-12,
    html body .row > .col-md-12,
    html body .row > .col-lg-8,
    html body .row > .col-lg-12,
    html body [class*="table-responsive"] { 
        flex: 0 0 100% !important; 
        max-width: 100% !important; 
        width: 100% !important; 
        padding-left: 3px !important; 
        padding-right: 3px !important;
    }

    /* Compact UI elements */
    html body .card { 
        border-radius: 12px !important; 
        margin-bottom: 0.65rem !important; 
        border: none !important;
        box-shadow: 0 4px 12px rgba(0,0,0,0.06) !important; 
    }
    
    html body .card-body { 
        padding: 0.65rem !important; 
    }

    /* Quick Action Buttons -> Grid on mobile portrait only */
    @media (max-width: 767.98px) {
        html body .rounded-pill.glass-panel.d-inline-flex {
            display: grid !important;
            grid-template-columns: 1fr 1fr !important;
            gap: 8px !important;
            padding: 8px !important;
            border-radius: 15px !important;
            width: calc(100% - 6px) !important;
            margin-left: 3px !important;
            margin-right: 3px !important;
        }
        
        html body .rounded-pill.glass-panel .btn {
            width: 100% !important;
            border-radius: 10px !important;
            padding: 8px 5px !important;
            font-size: 0.85rem !important;
            white-space: nowrap !important;
            overflow: hidden !important;
            text-overflow: ellipsis !important;
        }
    }

    /* UI Consistency */
    html body .breadcrumb { display: none !important; }
    html body h1, html body .h1 { font-size: 1.15rem !important; font-weight: 800 !important; }
    html body .d-flex.mb-4, html body .container-fluid.mb-4 { padding-left: 3px !important; padding-right: 3px !important; }
}