/**
 * Engineering Accounts SaaS - Master CSS
 * Supports: Dark/Light Mode, RTL layout, Tables, Stats, Sidebar
 */

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

:root {
    --font-family-base: 'Tajawal', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --app-sidebar-width: 260px;
    --app-header-height: 64px;
    --app-primary: #1b64da;
    --app-primary-hover: #1551b0;
    --app-success: #10b981;
    --app-warning: #f59e0b;
    --app-danger: #ef4444;
    --app-info: #06b6d4;
    
    /* Light Mode Tokens */
    --bg-body: #f4f6fb;
    --bg-surface: #ffffff;
    --bg-card: #ffffff;
    --bg-sidebar: #0f172a;
    --sidebar-text: #94a3b8;
    --sidebar-text-hover: #ffffff;
    --sidebar-active-bg: rgba(27, 100, 218, 0.15);
    --sidebar-active-text: #60a5fa;
    --border-color: #e2e8f0;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --table-hover-bg: #f8fafc;
    --table-header-bg: #f8fafc;
}

[data-bs-theme="dark"] {
    /* Dark Mode Tokens */
    --bg-body: #0b0f19;
    --bg-surface: #131b2e;
    --bg-card: #131b2e;
    --bg-sidebar: #0b1120;
    --sidebar-text: #94a3b8;
    --sidebar-text-hover: #f1f5f9;
    --sidebar-active-bg: rgba(37, 99, 235, 0.25);
    --sidebar-active-text: #93c5fd;
    --border-color: #1e293b;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --table-hover-bg: #1e293b;
    --table-header-bg: #1a233a;
}

body {
    font-family: var(--font-family-base);
    background-color: var(--bg-body);
    color: var(--text-main);
    min-height: 100vh;
    margin: 0;
    transition: background-color 0.25s ease, color 0.25s ease;
}

/* App Layout */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.app-sidebar {
    width: var(--app-sidebar-width);
    background-color: var(--bg-sidebar);
    color: var(--sidebar-text);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    z-index: 1040;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.05);
}

.sidebar-header {
    height: var(--app-header-height);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: #ffffff;
    font-weight: 700;
    font-size: 1.15rem;
}

.sidebar-menu {
    list-style: none;
    padding: 1rem 0.75rem;
    margin: 0;
    flex-grow: 1;
    overflow-y: auto;
}

.sidebar-item {
    margin-bottom: 0.25rem;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.7rem 1rem;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: 0.6rem;
    font-weight: 500;
    font-size: 0.925rem;
    transition: all 0.2s ease;
}

.sidebar-link i {
    width: 20px;
    text-align: center;
    font-size: 1.1rem;
}

.sidebar-link:hover {
    color: var(--sidebar-text-hover);
    background-color: rgba(255, 255, 255, 0.05);
}

.sidebar-link.active {
    color: var(--sidebar-active-text);
    background-color: var(--sidebar-active-bg);
    font-weight: 600;
}

.sidebar-heading {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 1rem 1rem 0.4rem;
    color: #64748b;
    font-weight: 700;
}

/* Main Container */
.app-main {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Header / Navbar */
.app-header {
    height: var(--app-header-height);
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 1020;
    transition: background-color 0.25s ease, border-color 0.25s ease;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Content Area */
.app-content {
    padding: 1.75rem;
    flex-grow: 1;
}

/* Cards & Surfaces */
.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 0.85rem;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.02);
    transition: all 0.2s ease;
}

.card-header {
    background-color: transparent;
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.25rem;
    font-weight: 600;
}

/* Modern Tables */
.table-responsive {
    position: relative;
    border-radius: 0.6rem;
}

.table {
    color: var(--text-main);
    border-color: var(--border-color);
    margin-bottom: 0;
    vertical-align: middle;
}

.table > thead {
    background-color: var(--table-header-bg);
    font-size: 0.825rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-muted);
}

.table > thead th {
    padding: 0.85rem 1rem;
    font-weight: 700;
    border-bottom: 2px solid var(--border-color);
    white-space: nowrap;
}

.table > tbody td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

.table-hover > tbody > tr:hover {
    background-color: var(--table-hover-bg);
}

/* Loading Overlay for AJAX Tables */
.table-loading-overlay {
    position: absolute;
    inset: 0;
    background-color: rgba(255, 255, 255, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10;
    backdrop-filter: blur(1px);
    border-radius: 0.6rem;
}

[data-bs-theme="dark"] .table-loading-overlay {
    background-color: rgba(19, 27, 46, 0.75);
}

.table-loading-overlay.active {
    display: flex;
}

/* Theme Toggle Button */
.theme-toggle-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-main);
    cursor: pointer;
    transition: all 0.2s ease;
}

.theme-toggle-btn:hover {
    background-color: var(--table-hover-bg);
    color: var(--app-primary);
}

/* Custom Badges */
.badge-subtle-success {
    background-color: rgba(16, 185, 129, 0.12) !important;
    color: #059669 !important;
    border: 1px solid rgba(16, 185, 129, 0.25);
}

.badge-subtle-warning {
    background-color: rgba(245, 158, 11, 0.12) !important;
    color: #d97706 !important;
    border: 1px solid rgba(245, 158, 11, 0.25);
}

.badge-subtle-danger {
    background-color: rgba(239, 68, 68, 0.12) !important;
    color: #dc2626 !important;
    border: 1px solid rgba(239, 68, 68, 0.25);
}

.badge-subtle-primary {
    background-color: rgba(27, 100, 218, 0.12) !important;
    color: #1b64da !important;
    border: 1px solid rgba(27, 100, 218, 0.25);
}

.badge-subtle-info {
    background-color: rgba(6, 182, 212, 0.12) !important;
    color: #0891b2 !important;
    border: 1px solid rgba(6, 182, 212, 0.25);
}

.badge-subtle-secondary {
    background-color: rgba(100, 116, 139, 0.12) !important;
    color: #475569 !important;
    border: 1px solid rgba(100, 116, 139, 0.25);
}

/* Dark Mode Badges Adjustments */
[data-bs-theme="dark"] .badge-subtle-success {
    background-color: rgba(16, 185, 129, 0.18) !important;
    color: #34d399 !important;
    border-color: rgba(16, 185, 129, 0.3);
}

[data-bs-theme="dark"] .badge-subtle-warning {
    background-color: rgba(245, 158, 11, 0.18) !important;
    color: #fbbf24 !important;
    border-color: rgba(245, 158, 11, 0.3);
}

[data-bs-theme="dark"] .badge-subtle-danger {
    background-color: rgba(239, 68, 68, 0.18) !important;
    color: #f87171 !important;
    border-color: rgba(239, 68, 68, 0.3);
}

[data-bs-theme="dark"] .badge-subtle-primary {
    background-color: rgba(37, 99, 235, 0.2) !important;
    color: #60a5fa !important;
    border-color: rgba(37, 99, 235, 0.35);
}

[data-bs-theme="dark"] .badge-subtle-info {
    background-color: rgba(6, 182, 212, 0.18) !important;
    color: #22d3ee !important;
    border-color: rgba(6, 182, 212, 0.3);
}

[data-bs-theme="dark"] .badge-subtle-secondary {
    background-color: rgba(148, 163, 184, 0.15) !important;
    color: #cbd5e1 !important;
    border-color: rgba(148, 163, 184, 0.25);
}

/* Fix Bootstrap .bg-light inside Dark Mode (Issue 2) */
[data-bs-theme="dark"] .badge.bg-light,
[data-bs-theme="dark"] .bg-light {
    background-color: #1e293b !important;
    color: #94a3b8 !important;
    border-color: #334155 !important;
}

[data-bs-theme="dark"] .badge.bg-light.text-muted,
[data-bs-theme="dark"] .bg-light.text-muted {
    color: #94a3b8 !important;
}

/* Pagination Styling */
.pagination {
    margin: 0;
    gap: 0.35rem;
    display: flex;
    align-items: center;
}

.page-item .page-link {
    border-radius: 0.5rem !important;
    border: 1px solid var(--border-color);
    color: var(--text-main);
    background-color: var(--bg-surface);
    padding: 0.4rem 0.85rem;
    font-size: 0.875rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    height: 38px;
    transition: all 0.15s ease-in-out;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.page-item:not(.active):not(.disabled) .page-link:hover {
    background-color: var(--table-hover-bg);
    color: var(--app-primary);
    border-color: var(--app-primary);
    transform: translateY(-1px);
}

.page-item.active .page-link {
    background-color: var(--app-primary) !important;
    border-color: var(--app-primary) !important;
    color: #ffffff !important;
    font-weight: 600;
    box-shadow: 0 3px 8px rgba(27, 100, 218, 0.35);
}

.page-item.disabled .page-link {
    color: var(--text-muted);
    background-color: transparent !important;
    border-color: var(--border-color);
    opacity: 0.5;
    cursor: not-allowed;
}

[data-bs-theme="dark"] .page-item .page-link {
    background-color: #151f33;
    border-color: #24324f;
    color: #cbd5e1;
}

[data-bs-theme="dark"] .page-item:not(.active):not(.disabled) .page-link:hover {
    background-color: #1e2d4d;
    color: #93c5fd;
    border-color: #3b5282;
}

[data-bs-theme="dark"] .page-item.active .page-link {
    background-color: #2563eb !important;
    border-color: #2563eb !important;
    color: #ffffff !important;
    box-shadow: 0 3px 10px rgba(37, 99, 235, 0.4);
}

[data-bs-theme="dark"] .page-item.disabled .page-link {
    background-color: rgba(255, 255, 255, 0.02) !important;
    border-color: #1e293b;
    color: #475569;
}

/* Print Styles for Statements & Reports */
@media print {
    .app-sidebar,
    .app-header,
    .btn,
    .modal,
    .breadcrumb,
    .table-loading-overlay,
    nav[aria-label="breadcrumb"] {
        display: none !important;
    }

    .app-main {
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
    }

    .app-content {
        padding: 0 !important;
    }

    body {
        background-color: #ffffff !important;
        color: #000000 !important;
        font-size: 11pt !important;
    }

    .card {
        border: 1px solid #dee2e6 !important;
        box-shadow: none !important;
        break-inside: avoid;
        margin-bottom: 1rem !important;
    }

    .table-responsive {
        overflow: visible !important;
        display: block !important;
        width: 100% !important;
    }

    .table {
        border: 1px solid #dee2e6 !important;
        font-size: 8.5pt !important;
        width: 100% !important;
    }

    .table th,
    .table td {
        border: 1px solid #dee2e6 !important;
        padding: 4px 6px !important;
        color: #000000 !important;
    }

    .table thead th {
        background-color: #f8f9fa !important;
        color: #000000 !important;
    }

    .badge {
        border: 1px solid #ccc !important;
        color: #000 !important;
        background: transparent !important;
    }
}

