@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

/* Dynamic Theme Variables (Vibrant HSL palettes) */
:root {
    --font-primary: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    
    /* Light Mode - AdminLTE Vibrant Colors */
    --rz-primary: #17a2b8;
    --app-bg: #f4f6f9;
    --app-card-bg: #ffffff;
    --app-text: #2c3e50;
    --app-text-muted: #6c757d;
    --app-border: #dee2e6;
    
    --sidebar-bg: #2d3748;
    --sidebar-text: #e2e8f0;
    --sidebar-active-bg: #17a2b8;
    --sidebar-active-text: #ffffff;
    
    --accent-orange: #fd7e14;
    --accent-green: #28a745;
    --accent-red: #dc3545;
    --accent-purple: #6f42c1;
    
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

html.dark-mode, body.dark-mode {
    /* Dark Mode - Slate & Vibrant Neon Highlights */
    --rz-primary: #00e5ff;
    --app-bg: #0f172a;
    --app-card-bg: #1e293b;
    --app-text: #f8fafc;
    --app-text-muted: #94a3b8;
    --app-border: #334155;
    
    --sidebar-bg: #0b0f19;
    --sidebar-text: #94a3b8;
    --sidebar-active-bg: #00e5ff;
    --sidebar-active-text: #0b0f19;
    
    --accent-orange: #ffab00;
    --accent-green: #00e676;
    --accent-red: #ff1744;
    --accent-purple: #d500f9;

    /* Radzen specific custom property overrides for dark theme */
    --rz-text-color: #f8fafc;
    --rz-text-title-color: #f8fafc;
    --rz-grid-cell-color: #f8fafc;
    --rz-grid-header-color: #f8fafc;
    --rz-grid-header-background-color: #1e293b;
    --rz-grid-cell-background-color: #0f172a;
    --rz-grid-hover-background-color: #334155;
    --rz-input-background-color: #0f172a;
    --rz-input-color: #f8fafc;
    --rz-input-placeholder-color: #94a3b8;
    --rz-input-focus-background-color: #0f172a;
    --rz-chart-axis-color: #94a3b8;
    --rz-chart-title-color: #f8fafc;
    --rz-chart-label-color: #94a3b8;
    --rz-card-background-color: #1e293b;
    --rz-dialog-background-color: #1e293b;
    --rz-dialog-title-color: #f8fafc;
    --rz-menu-background-color: #1e293b;
    --rz-menu-item-color: #f8fafc;
    --rz-dropdown-background-color: #0f172a;
    --rz-dropdown-color: #f8fafc;
    --rz-dropdown-items-background-color: #1e293b;
    --rz-dropdown-items-color: #f8fafc;
    --rz-panel-background-color: #1e293b;
    --rz-panel-title-color: #f8fafc;
}

/* Ensure text contrast for bootstrap classes in dark mode */
body.dark-mode h1, body.dark-mode h2, body.dark-mode h3, body.dark-mode h4, body.dark-mode h5, body.dark-mode h6,
body.dark-mode .h1, body.dark-mode .h2, body.dark-mode .h3, body.dark-mode .h4, body.dark-mode .h5, body.dark-mode .h6 {
    color: var(--app-text) !important;
}
body.dark-mode label, body.dark-mode .form-label, body.dark-mode legend {
    color: var(--app-text) !important;
}
body.dark-mode .card-title, body.dark-mode .card-header, body.dark-mode .card-body {
    color: var(--app-text) !important;
}
body.dark-mode .table, body.dark-mode table {
    color: var(--app-text) !important;
}
body.dark-mode .text-dark {
    color: var(--app-text) !important;
}
body.dark-mode .text-muted {
    color: var(--app-text-muted) !important;
}
body.dark-mode .border-bottom {
    border-color: var(--app-border) !important;
}
body.dark-mode .bg-light {
    background-color: var(--app-bg) !important;
    color: var(--app-text) !important;
}
body.dark-mode .alert-dark {
    background-color: var(--app-bg) !important;
    border-color: var(--app-border) !important;
    color: var(--app-text) !important;
}
body.dark-mode .bg-white {
    background-color: var(--app-card-bg) !important;
}
body.dark-mode .alert h1, body.dark-mode .alert h2, body.dark-mode .alert h3, 
body.dark-mode .alert h4, body.dark-mode .alert h5, body.dark-mode .alert h6,
body.dark-mode .alert .h1, body.dark-mode .alert .h2, body.dark-mode .alert .h3, 
body.dark-mode .alert .h4, body.dark-mode .alert .h5, body.dark-mode .alert .h6 {
    color: inherit !important;
}

/* Base resets */
html, body {
    height: 100%;
    margin: 0;
    font-family: var(--font-primary);
    background-color: var(--app-bg) !important;
    color: var(--app-text) !important;
    transition: var(--transition-smooth);
}

a {
    color: var(--rz-primary);
    text-decoration: none;
    transition: var(--transition-smooth);
}
a:hover {
    filter: brightness(1.2);
}

/* Page Layout */
.page-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar Styling */
.mema-sidebar {
    width: 270px;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    height: 100%;
    z-index: 1000;
    box-shadow: 4px 0 10px rgba(0, 0, 0, 0.1);
    transition: var(--transition-smooth);
}

.mema-sidebar-brand {
    padding: 1.5rem 1rem;
    font-size: 1.3rem;
    font-weight: 700;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    gap: 0.8rem;
    color: #ffffff;
}

.mema-sidebar-menu {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0.5rem;
}

.mema-menu-item {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.75rem 1rem;
    color: var(--sidebar-text);
    border-radius: 6px;
    margin-bottom: 0.25rem;
    font-weight: 500;
    transition: var(--transition-smooth);
}

.mema-menu-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: #ffffff;
}

.mema-menu-item.active {
    background-color: var(--sidebar-active-bg);
    color: var(--sidebar-active-text) !important;
    box-shadow: 0 4px 12px rgba(23, 162, 184, 0.3);
}

.mema-menu-header {
    padding: 0.75rem 1rem 0.25rem 1rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--app-text-muted);
    font-weight: 700;
}

/* Main Content Area */
.mema-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.mema-navbar {
    height: 60px;
    background-color: var(--app-card-bg);
    border-bottom: 1px solid var(--app-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
    transition: var(--transition-smooth);
}

.mema-content-wrapper {
    flex: 1;
    overflow-y: auto;
    padding: 2rem 1.5rem;
    background-color: var(--app-bg);
}

/* Card Styling */
.mema-card {
    background-color: var(--app-card-bg);
    border: 1px solid var(--app-border);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05), 0 2px 4px -1px rgba(0,0,0,0.03);
    margin-bottom: 1.5rem;
    transition: var(--transition-smooth);
}

/* Metric Widgets */
.metric-card {
    position: relative;
    overflow: hidden;
}
.metric-card-icon {
    position: absolute;
    right: 1.5rem;
    bottom: 1rem;
    font-size: 3rem;
    opacity: 0.15;
    color: var(--rz-primary);
}

/* Theme Switcher Toggle */
.theme-toggle-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.25rem;
    color: var(--app-text);
    padding: 0.5rem;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-smooth);
}
.theme-toggle-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.dark-mode .theme-toggle-btn:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

/* Floating AI Chatbot Drawer styles */
.mema-chatbot-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 2000;
}

.mema-chatbot-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: var(--rz-primary);
    color: #ffffff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(23, 162, 184, 0.4);
    transition: var(--transition-smooth);
}

.mema-chatbot-toggle:hover {
    transform: scale(1.08) rotate(5deg);
}

.mema-chatbot-drawer {
    position: fixed;
    bottom: 95px;
    right: 24px;
    width: 380px;
    height: 500px;
    background-color: var(--app-card-bg);
    border: 1px solid var(--app-border);
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform 0.30s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease;
    transform-origin: bottom right;
}

.mema-chatbot-header {
    background-color: var(--rz-primary);
    color: #ffffff;
    padding: 1rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.mema-chatbot-body {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.mema-chat-bubble {
    max-width: 80%;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    font-size: 0.9rem;
    line-height: 1.4;
}

.mema-chat-bubble.bot {
    background-color: var(--app-bg);
    color: var(--app-text);
    align-self: flex-start;
    border-bottom-left-radius: 2px;
}

.mema-chat-bubble.user {
    background-color: var(--rz-primary);
    color: #ffffff;
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}

.mema-chatbot-footer {
    padding: 0.75rem;
    border-top: 1px solid var(--app-border);
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* Micro-animations */
@keyframes pulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.1); opacity: 0.7; }
    100% { transform: scale(1); opacity: 1; }
}

.listening-pulse {
    animation: pulse 1.5s infinite ease-in-out;
    background-color: var(--accent-red) !important;
}

/* Print Layout Definitions (Customized for Invoice/Voucher Prints) */
@media print {
    @page {
        size: portrait;
        margin: 10mm;
    }
    body, .mema-content-wrapper, .mema-main, .page-container {
        background: #ffffff !important;
        color: #000000 !important;
        overflow: visible !important;
        height: auto !important;
    }
    
    .mema-sidebar, .mema-navbar, .mema-chatbot-container, .no-print {
        display: none !important;
    }
    
    .mema-content-wrapper {
        padding: 0 !important;
        margin: 0 !important;
    }
    
    .print-header {
        display: block !important;
        border-bottom: 2px solid #333333;
        margin-bottom: 2rem;
        padding-bottom: 1rem;
    }
    
    .mema-card {
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    /* Paper size printing utilities */
    .mema-print-a4 {
        width: 210mm !important;
        margin: auto !important;
        padding: 10mm !important;
        box-sizing: border-box !important;
    }
    .mema-print-letter {
        width: 8.5in !important;
        margin: auto !important;
        padding: 0.5in !important;
        box-sizing: border-box !important;
    }
    .mema-print-thermal {
        width: 80mm !important;
        margin: 0 !important;
        padding: 2mm !important;
        box-sizing: border-box !important;
        font-size: 10px !important;
    }
    .mema-print-thermal table {
        font-size: 9px !important;
        margin-bottom: 15px !important;
    }
    .mema-print-thermal th, .mema-print-thermal td {
        padding: 4px 2px !important;
    }
    .mema-print-thermal h2, .mema-print-thermal h3 {
        font-size: 14px !important;
    }
    .mema-print-thermal h4 {
        font-size: 11px !important;
    }
    .mema-print-thermal img {
        height: 30px !important;
    }
}
.print-header {
    display: none;
}

/* User Profile Navbar Dropdown Card */
.user-profile-container {
    position: relative;
    display: inline-block;
}
.user-profile-btn {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    outline: none;
    transition: var(--transition-smooth);
}
.user-profile-btn:hover {
    opacity: 0.85;
    transform: scale(1.05);
}
.user-avatar-img {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--rz-primary);
}
.user-avatar-placeholder {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background-color: var(--app-border);
    color: var(--app-text);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--rz-primary);
}
.mema-profile-popup {
    position: absolute;
    right: 0;
    top: 48px;
    width: 280px;
    z-index: 1050;
    border-radius: 12px;
    border: 1px solid var(--app-border);
    background-color: var(--app-card-bg);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    animation: fadeInDown 0.2s ease-out;
}
html[dir="rtl"] .mema-profile-popup,
.rtl-layout .mema-profile-popup {
    right: auto;
    left: 0;
}
@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Voucher Print Layout */
@media print {
    .print-voucher-card {
        display: flex !important;
        flex-direction: column !important;
        min-height: 140mm !important;
        box-sizing: border-box !important;
        background-color: #ffffff !important;
        color: #000000 !important;
        page-break-inside: avoid !important;
    }
    .print-voucher-card .signature-row {
        margin-top: auto !important;
        padding-top: 2rem !important;
    }
    /* Force table borders in print layouts */
    .print-voucher-card table,
    .print-voucher-card th,
    .print-voucher-card td,
    .print-voucher-custom table,
    .print-voucher-custom th,
    .print-voucher-custom td {
        border: 1px solid #000000 !important;
        border-collapse: collapse !important;
        color: #000000 !important;
    }
    .print-voucher-card th,
    .print-voucher-custom th {
        background-color: #f3f4f6 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}

/* Invoice & Receipt Print Layout */
@media print {
    .print-invoice-card, .print-receipt-card {
        display: flex !important;
        flex-direction: column !important;
        box-sizing: border-box !important;
        background-color: #ffffff !important;
        color: #000000 !important;
        page-break-inside: avoid !important;
    }
}

/* Mobile Sidebar Styles */
@media (max-width: 768px) {
    .mema-menu-header {
        display: none !important;
    }
    .mema-sidebar-brand {
        padding: 0.75rem 1rem !important;
        font-size: 1.1rem !important;
    }
    .mema-sidebar-menu {
        padding: 0.5rem 0.25rem !important;
    }
    .mema-menu-item {
        padding: 0.5rem 0.75rem !important;
        gap: 0.6rem !important;
        font-size: 0.85rem !important;
    }
}

/* Radzen Chart & Tooltip overrides to guarantee visibility */
.rz-chart-tooltip, .rz-tooltip {
    z-index: 9999 !important;
    pointer-events: none !important;
}
.rz-chart-tooltip-content, .rz-tooltip-content {
    background-color: #1e293b !important;
    color: #ffffff !important;
    border: 1px solid #334155 !important;
    border-radius: 6px !important;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.05) !important;
    padding: 8px 12px !important;
}

/* Custom Theme Variant Overrides */

/* Light - Emerald Mint */
body.theme-light-emerald {
    --rz-primary: #10b981;
    --app-bg: #f0fdf4;
    --app-card-bg: #ffffff;
    --app-text: #065f46;
    --app-text-muted: #047857;
    --app-border: #d1fae5;
    --sidebar-bg: #064e3b;
    --sidebar-text: #a7f3d0;
    --sidebar-active-bg: #10b981;
    --sidebar-active-text: #ffffff;
    --accent-orange: #f59e0b;
    --accent-green: #10b981;
    --accent-red: #ef4444;
    --accent-purple: #8b5cf6;
}

/* Light - Sunset Coral */
body.theme-light-sunset {
    --rz-primary: #ff7a59;
    --app-bg: #fff7f5;
    --app-card-bg: #ffffff;
    --app-text: #3c2a21;
    --app-text-muted: #7a6b63;
    --app-border: #ffe5df;
    --sidebar-bg: #2b1e19;
    --sidebar-text: #ffdcd5;
    --sidebar-active-bg: #ff7a59;
    --sidebar-active-text: #ffffff;
    --accent-orange: #ff9800;
    --accent-green: #4caf50;
    --accent-red: #f44336;
    --accent-purple: #9c27b0;
}

/* Light - Lavender Amethyst */
body.theme-light-lavender {
    --rz-primary: #8b5cf6;
    --app-bg: #faf5ff;
    --app-card-bg: #ffffff;
    --app-text: #4c1d95;
    --app-text-muted: #7c3aed;
    --app-border: #f3e8ff;
    --sidebar-bg: #311b92;
    --sidebar-text: #ede9fe;
    --sidebar-active-bg: #8b5cf6;
    --sidebar-active-text: #ffffff;
    --accent-orange: #ff9800;
    --accent-green: #4caf50;
    --accent-red: #f44336;
    --accent-purple: #8b5cf6;
}

/* Light - Royal Orchid */
body.theme-light-orchid {
    --rz-primary: #a21caf;
    --app-bg: #fdf4ff;
    --app-card-bg: #ffffff;
    --app-text: #701a75;
    --app-text-muted: #a21caf;
    --app-border: #fae8ff;
    --sidebar-bg: #4a044e;
    --sidebar-text: #fdf4ff;
    --sidebar-active-bg: #d946ef;
    --sidebar-active-text: #ffffff;
    --accent-orange: #ff9800;
    --accent-green: #4caf50;
    --accent-red: #f44336;
    --accent-purple: #a21caf;
}

/* Dark - Neon Midnight */
body.theme-dark-midnight {
    --rz-primary: #38bdf8;
    --app-bg: #020617;
    --app-card-bg: #0f172a;
    --app-text: #f1f5f9;
    --app-text-muted: #64748b;
    --app-border: #1e293b;
    --sidebar-bg: #030712;
    --sidebar-text: #64748b;
    --sidebar-active-bg: #38bdf8;
    --sidebar-active-text: #030712;
    --accent-orange: #f97316;
    --accent-green: #10b981;
    --accent-red: #ef4444;
    --accent-purple: #a855f7;
}

/* Dark - Abyssal Forest */
body.theme-dark-forest {
    --rz-primary: #10b981;
    --app-bg: #022c22;
    --app-card-bg: #064e3b;
    --app-text: #ecfdf5;
    --app-text-muted: #34d399;
    --app-border: #047857;
    --sidebar-bg: #022c22;
    --sidebar-text: #34d399;
    --sidebar-active-bg: #10b981;
    --sidebar-active-text: #022c22;
    --accent-orange: #f59e0b;
    --accent-green: #10b981;
    --accent-red: #f43f5e;
    --accent-purple: #a78bfa;
}

/* Dark - Cyberpunk Amber */
body.theme-dark-cyberpunk {
    --rz-primary: #f59e0b;
    --app-bg: #18181b;
    --app-card-bg: #27272a;
    --app-text: #fafafa;
    --app-text-muted: #a1a1aa;
    --app-border: #3f3f46;
    --sidebar-bg: #09090b;
    --sidebar-text: #a1a1aa;
    --sidebar-active-bg: #f59e0b;
    --sidebar-active-text: #09090b;
    --accent-orange: #f59e0b;
    --accent-green: #22c55e;
    --accent-red: #ef4444;
    --accent-purple: #d946ef;
}

/* Dark - Orchid Shadow */
body.theme-dark-orchid {
    --rz-primary: #d946ef;
    --app-bg: #140518;
    --app-card-bg: #210a27;
    --app-text: #fdf4ff;
    --app-text-muted: #c084fc;
    --app-border: #3b1248;
    --sidebar-bg: #140518;
    --sidebar-text: #c084fc;
    --sidebar-active-bg: #d946ef;
    --sidebar-active-text: #ffffff;
    --accent-orange: #f97316;
    --accent-green: #10b981;
    --accent-red: #ef4444;
    --accent-purple: #d946ef;
}

/* Dropdown specific width styling for themes */
.theme-dropdown {
    width: 170px !important;
}

@media (max-width: 768px) {
    .theme-dropdown {
        width: 65px !important;
    }
}

/* Radzen Dialog Modal Overrides to guarantee visibility above sticky elements */
.rz-dialog-wrapper {
    z-index: 10050 !important;
}
.rz-dialog-mask {
    z-index: 10040 !important;
}
.rz-dialog {
    z-index: 10055 !important;
}

/* Limit sticky table/grid header z-index to prevent overlaying global modal dialogs */
.sticky-top, 
.rz-grid-table thead, 
.rz-grid-table thead th {
    z-index: 5 !important;
}

/* Ensure Radzen dropdown/calendar popups are visible above elevated dialog modal wrapper */
.rz-popup,
.rz-dropdown-panel,
.rz-datepicker-panel,
.rz-autocomplete-panel,
.rz-multiselect-panel,
.rz-menu-panel {
    z-index: 10100 !important;
}

/* RTL Layout Custom Overrides */
[dir="rtl"] {
    text-align: right;
}

[dir="rtl"] .mema-sidebar {
    box-shadow: -4px 0 10px rgba(0, 0, 0, 0.1);
}

[dir="rtl"] .me-1, [dir="rtl"] .me-2, [dir="rtl"] .me-3, [dir="rtl"] .me-4 {
    margin-left: unset !important;
}
[dir="rtl"] .me-1 { margin-left: 0.25rem !important; margin-right: 0 !important; }
[dir="rtl"] .me-2 { margin-left: 0.5rem !important; margin-right: 0 !important; }
[dir="rtl"] .me-3 { margin-left: 1rem !important; margin-right: 0 !important; }
[dir="rtl"] .me-4 { margin-left: 1.5rem !important; margin-right: 0 !important; }

[dir="rtl"] .ms-1, [dir="rtl"] .ms-2, [dir="rtl"] .ms-3, [dir="rtl"] .ms-4 {
    margin-right: unset !important;
}
[dir="rtl"] .ms-1 { margin-right: 0.25rem !important; margin-left: 0 !important; }
[dir="rtl"] .ms-2 { margin-right: 0.5rem !important; margin-left: 0 !important; }
[dir="rtl"] .ms-3 { margin-right: 1rem !important; margin-left: 0 !important; }
[dir="rtl"] .ms-4 { margin-right: 1.5rem !important; margin-left: 0 !important; }

/* Invert icons where necessary in RTL */
[dir="rtl"] i.fa-angle-right {
    transform: rotate(180deg);
}
[dir="rtl"] i.fa-chevron-right {
    transform: rotate(180deg);
}
[dir="rtl"] i.fa-arrow-right {
    transform: rotate(180deg);
}
[dir="rtl"] i.fa-arrow-left {
    transform: rotate(180deg);
}