/**
 * ============================================================================
 * نظام إدارة الجرد والمخازن – شركة غاز مصر (Egypt Gas)
 * ملف التنسيقات والتصميم الاحترافي الشامل (Enterprise Design System)
 * تطوير وبرمجة: Sherif Mohamed | Developer: Sherif Mohamed
 * ============================================================================
 */

:root {
    --primary: #0a3663;
    --primary-dark: #00223d;
    --primary-light: #154d85;
    --secondary: #0284c7;
    --secondary-light: #e0f2fe;
    --accent: #10b981;
    --accent-dark: #047857;
    --accent-light: #d1fae5;
    --warning: #f59e0b;
    --warning-dark: #b45309;
    --warning-light: #fef3c7;
    --danger: #ef4444;
    --danger-dark: #b91c1c;
    --danger-light: #fee2e2;
    --dark: #0f172a;
    --gray-900: #0f172a;
    --gray-800: #1e293b;
    --gray-700: #334155;
    --gray-600: #475569;
    --gray-500: #64748b;
    --gray-400: #94a3b8;
    --gray-300: #cbd5e1;
    --gray-200: #e2e8f0;
    --gray-100: #f1f5f9;
    --gray-50: #f8fafc;
    --white: #ffffff;
    --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.08);
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.08);
    --shadow-lg: 0 12px 24px -4px rgb(0 0 0 / 0.12), 0 4px 8px -2px rgb(0 0 0 / 0.06);
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 16px;
    --sidebar-width: 280px;
    --header-height: 70px;
    --font-family: 'Cairo', 'Tajawal', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body.app-body-container {
    font-family: var(--font-family);
    background-color: #f1f5f9;
    color: var(--gray-800);
    direction: rtl;
    text-align: right;
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ================= GLOBAL UTILITIES ================= */
.hidden {
    display: none !important;
}

#loginScreen.hidden,
.login-overlay.hidden {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
    z-index: -9999 !important;
}

#appShell.hidden,
.app-shell.hidden {
    display: none !important;
}

.alert-box.hidden {
    display: none !important;
}

.modal-overlay.hidden {
    display: none !important;
}

/* ================= 1. LOGIN SCREEN ================= */
.login-overlay {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: #021a30;
}

.login-bg-pattern {
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 50% 20%, #0a437a 0%, #011324 85%);
    opacity: 0.95;
}

.login-card {
    position: relative;
    z-index: 10;
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    max-width: 520px;
    width: 100%;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.25);
    animation: fadeInScale 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes fadeInScale {
    from { opacity: 0; transform: scale(0.94); }
    to { opacity: 1; transform: scale(1); }
}

.login-header {
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
    color: var(--white);
    padding: 30px 24px 22px;
    text-align: center;
    border-bottom: 4px solid var(--accent);
}

.login-logo-box {
    background: #ffffff;
    width: 86px;
    height: 86px;
    border-radius: 20px;
    margin: 0 auto 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
    padding: 6px;
    overflow: hidden;
}

.login-brand-logo {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 14px;
}

.login-header h2 {
    font-size: 1.55rem;
    font-weight: 800;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.tag-brand {
    font-size: 0.72rem;
    background: rgba(255, 255, 255, 0.22);
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 700;
    letter-spacing: 1px;
}

.login-header h3 {
    font-size: 1.05rem;
    color: #e0f2fe;
    font-weight: 600;
    margin-bottom: 4px;
}

.login-sub {
    font-size: 0.8rem;
    color: #94a3b8;
}

.login-body {
    padding: 28px 32px;
}

.login-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.login-title-row h4 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--gray-800);
}

.security-chip {
    font-size: 0.75rem;
    background: #ecfdf5;
    color: var(--accent-dark);
    padding: 3px 10px;
    border-radius: 20px;
    font-weight: 600;
    border: 1px solid #a7f3d0;
}

.input-icon-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon {
    position: absolute;
    right: 14px;
    font-size: 1.1rem;
    color: var(--gray-400);
    pointer-events: none;
}

.input-icon-wrap .form-control {
    padding-right: 44px;
    padding-left: 44px;
}

.btn-pwd-eye {
    position: absolute;
    left: 10px;
    background: none;
    border: none;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 4px;
    color: var(--gray-500);
}

.login-initial-tip {
    margin-top: 18px;
    padding: 10px 14px;
    background: #f8fafc;
    border: 1px dashed var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    color: var(--gray-600);
    line-height: 1.5;
}

.login-initial-tip code {
    background: #e2e8f0;
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--primary);
    font-weight: 700;
    font-family: monospace;
}

.login-footer {
    background: #f8fafc;
    padding: 16px 24px;
    border-top: 1px solid var(--gray-200);
    text-align: center;
}

.dev-badge-footer {
    font-size: 0.88rem;
    color: var(--gray-700);
    margin-bottom: 4px;
}

.dev-badge-footer strong {
    color: var(--primary);
}

.system-internal-note {
    font-size: 0.75rem;
    color: var(--gray-400);
}

/* ================= 2. ENTERPRISE APP SHELL ================= */
.app-shell {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.app-sidebar {
    width: var(--sidebar-width);
    background: #00223d;
    color: var(--white);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    box-shadow: 4px 0 15px rgba(0, 0, 0, 0.15);
    transition: transform 0.3s ease;
}

.sidebar-brand {
    padding: 18px 20px;
    background: #00192e;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-logo {
    width: 46px;
    height: 46px;
    background: var(--white);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3px;
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.sidebar-brand-logo {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 8px;
}

.sbt-title {
    font-size: 1.15rem;
    font-weight: 800;
    letter-spacing: -0.3px;
    color: var(--white);
}

.sbt-subtitle {
    font-size: 0.72rem;
    color: #38bdf8;
    font-weight: 700;
    letter-spacing: 1px;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 12px 10px;
}

.nav-section-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: #94a3b8;
    padding: 12px 14px 6px;
    font-weight: 800;
    letter-spacing: 0.5px;
}

.nav-item {
    width: 100%;
    background: transparent;
    border: none;
    color: #cbd5e1;
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 600;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    text-align: right;
    transition: all 0.2s ease;
    margin-bottom: 3px;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--white);
}

.nav-item.active {
    background: linear-gradient(90deg, #0284c7 0%, #0369a1 100%);
    color: var(--white);
    font-weight: 700;
    box-shadow: 0 4px 10px rgba(2, 132, 199, 0.3);
}

.nav-icon {
    font-size: 1.15rem;
}

.nav-badge-pill {
    margin-right: auto;
    background: var(--warning);
    color: var(--gray-900);
    font-size: 0.72rem;
    font-weight: 800;
    padding: 1px 7px;
    border-radius: 12px;
}

.sidebar-footer {
    padding: 14px 16px;
    background: #00192e;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sf-dev {
    font-size: 0.8rem;
    color: #cbd5e1;
}

.sf-name {
    color: #fef08a;
    display: block;
}

/* Main Content Area Wrapper */
.app-main-wrapper {
    flex: 1;
    margin-right: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-right 0.3s ease;
}

/* Top Header */
.top-header {
    height: var(--header-height);
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 500;
    box-shadow: var(--shadow-sm);
}

.th-left, .th-right {
    display: flex;
    align-items: center;
    gap: 14px;
}

.btn-sidebar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--gray-700);
}

.warehouse-selector-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--gray-100);
    padding: 4px 10px;
    border-radius: 20px;
    border: 1px solid var(--gray-200);
}

.quick-search-box {
    position: relative;
    width: 380px;
}

.qs-icon {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-400);
}

.quick-search-box input {
    width: 100%;
    padding: 8px 36px 8px 12px;
    border: 1px solid var(--gray-300);
    border-radius: 20px;
    font-family: inherit;
    font-size: 0.88rem;
    outline: none;
    background: var(--gray-50);
}

.quick-search-box input:focus {
    background: var(--white);
    border-color: var(--secondary);
    box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
}

.live-clock-badge {
    font-family: monospace;
    font-weight: 700;
    color: var(--primary);
    background: #e0f2fe;
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
}

/* User Session Pill */
.user-session-pill {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--gray-100);
    border: 1px solid var(--gray-200);
    padding: 4px 10px 4px 4px;
    border-radius: 30px;
}

.usp-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--secondary), var(--primary));
    color: var(--white);
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.82rem;
}

.usp-meta {
    display: flex;
    flex-direction: column;
}

.usp-name {
    font-size: 0.85rem;
    font-weight: 700;
    line-height: 1.1;
}

.usp-role {
    font-size: 0.68rem;
    color: var(--secondary);
    font-weight: 600;
}

.btn-header-logout {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #dc2626;
    padding: 4px 8px;
    border-radius: 16px;
    font-family: inherit;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s;
}

.btn-header-logout:hover {
    background: var(--danger);
    color: var(--white);
}

/* ================= 3. CONTENT AREA & TABS ================= */
.app-content-area {
    flex: 1;
    padding: 24px;
    max-width: 1440px;
    width: 100%;
    margin: 0 auto;
}

.content-tab {
    display: none;
    animation: tabFadeIn 0.25s ease-out;
}

.content-tab.active {
    display: block;
}

@keyframes tabFadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ================= 4. CARDS & PANELS ================= */
.card {
    background: var(--white);
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    margin-bottom: 24px;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #fafafa;
    gap: 12px;
}

.card-header h2, .card-header h3 {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--gray-800);
}

.card-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.card-body {
    padding: 20px;
}

.card-body.p-0 {
    padding: 0;
}

.split-view {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

/* ================= 5. KPI GRID ================= */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 16px 18px;
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 14px;
    transition: transform 0.2s, box-shadow 0.2s;
}

.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.kpi-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}

.kpi-blue .kpi-icon { background: #e0f2fe; color: #0284c7; }
.kpi-cyan .kpi-icon { background: #cffafe; color: #0891b2; }
.kpi-amber .kpi-icon { background: #fef3c7; color: #d97706; }
.kpi-rose .kpi-icon { background: #ffe4e6; color: #e11d48; }
.kpi-emerald .kpi-icon { background: #d1fae5; color: #059669; }
.kpi-purple .kpi-icon { background: #f3e8ff; color: #7e22ce; }
.kpi-indigo .kpi-icon { background: #e0e7ff; color: #4338ca; }
.kpi-dark .kpi-icon { background: #f1f5f9; color: #334155; }

.kpi-data {
    flex: 1;
}

.kpi-label {
    font-size: 0.82rem;
    color: var(--gray-500);
    font-weight: 600;
}

.kpi-value {
    font-size: 1.55rem;
    font-weight: 800;
    color: var(--gray-900);
    display: block;
    line-height: 1.2;
    margin: 2px 0;
}

.kpi-meta {
    font-size: 0.72rem;
    color: var(--gray-400);
}

/* Split Dash */
.dash-split-grid {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 20px;
}

.chart-legend-box {
    display: flex;
    justify-content: center;
    gap: 16px;
    font-size: 0.8rem;
}

.legend-badge {
    padding: 3px 8px;
    border-radius: 4px;
    color: var(--white);
    font-weight: 600;
}

.bg-emerald { background-color: var(--accent); }
.bg-purple { background-color: #8b5cf6; }
.bg-cyan { background-color: var(--secondary); }

/* Timeline List */
.timeline-list {
    max-height: 380px;
    overflow-y: auto;
}

.timeline-item {
    padding: 12px 18px;
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background 0.15s;
}

.timeline-item:hover {
    background-color: var(--gray-50);
}

.tli-left {
    display: flex;
    flex-direction: column;
}

.tli-doc {
    font-family: monospace;
    font-weight: 700;
    color: var(--primary);
    font-size: 0.85rem;
}

.tli-item {
    font-weight: 700;
    font-size: 0.92rem;
}

.tli-meta {
    font-size: 0.75rem;
    color: var(--gray-400);
}

/* ================= 6. DATA TABLES ================= */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.88rem;
    text-align: right;
}

.data-table th {
    background: #f1f5f9;
    color: #1e293b;
    font-weight: 700;
    padding: 12px 14px;
    border-bottom: 2px solid #cbd5e1;
    white-space: nowrap;
}

.data-table td {
    padding: 12px 14px;
    border-bottom: 1px solid #e2e8f0;
    vertical-align: middle;
    transition: background-color 0.15s ease;
}

.data-table tbody tr:hover {
    background-color: #f8fafc;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* Status Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.74rem;
    font-weight: 700;
    white-space: nowrap;
    border: 1px solid transparent;
}

.badge-success { background: #ecfdf5; color: #065f46; border-color: #a7f3d0; }
.badge-warning { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.badge-danger { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.badge-info { background: #f0f9ff; color: #075985; border-color: #bae6fd; }
.badge-secondary { background: #f1f5f9; color: #475569; border-color: #cbd5e1; }

/* Filter Panels */
.filter-panel {
    background: var(--gray-50);
    padding: 14px 20px;
    border-bottom: 1px solid var(--gray-200);
}

.row-filters {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.filter-col { display: flex; align-items: center; }
.flex-1 { flex: 1; min-width: 150px; }
.flex-2 { flex: 2; min-width: 260px; }
.flex-0 { flex: 0 0 auto; }

/* ================= 7. BUTTONS & FORMS ================= */
.btn {
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
    text-decoration: none;
}

.btn-sm { 
    padding: 5px 12px; 
    font-size: 0.8rem; 
    border-radius: 6px; 
    line-height: 1.4;
}
.btn-lg { padding: 12px 24px; font-size: 1rem; font-weight: 700; border-radius: 8px; }

.btn-primary { 
    background: var(--primary); 
    color: var(--white); 
    box-shadow: 0 2px 4px rgba(10, 54, 99, 0.2);
}
.btn-primary:hover { 
    background: var(--primary-light); 
    box-shadow: 0 4px 8px rgba(10, 54, 99, 0.3);
    transform: translateY(-1px);
}

.btn-secondary { background: var(--secondary); color: var(--white); }
.btn-secondary:hover { background: #0369a1; transform: translateY(-1px); }

.btn-success { 
    background: var(--accent); 
    color: var(--white); 
    box-shadow: 0 2px 4px rgba(16, 185, 129, 0.2);
}
.btn-success:hover { 
    background: var(--accent-dark); 
    transform: translateY(-1px);
}

.btn-warning { background: var(--warning); color: var(--gray-900); }
.btn-warning:hover { background: var(--warning-dark); color: var(--white); transform: translateY(-1px); }

.btn-danger { 
    background: var(--danger); 
    color: var(--white); 
    box-shadow: 0 2px 4px rgba(239, 68, 68, 0.2);
}
.btn-danger:hover { 
    background: var(--danger-dark); 
    transform: translateY(-1px);
}

.btn-outline { 
    background: #ffffff; 
    border: 1px solid var(--gray-300); 
    color: var(--gray-700); 
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
.btn-outline:hover { 
    background: var(--gray-50); 
    border-color: var(--gray-400); 
    transform: translateY(-1px);
}
.btn-outline.text-primary { 
    color: var(--primary) !important; 
    border-color: rgba(10, 54, 99, 0.25); 
}
.btn-outline.text-primary:hover { 
    background: rgba(10, 54, 99, 0.08); 
    border-color: var(--primary); 
}
.btn-outline.text-danger { 
    color: var(--danger) !important; 
    border-color: rgba(239, 68, 68, 0.25); 
}
.btn-outline.text-danger:hover { 
    background: rgba(239, 68, 68, 0.08); 
    border-color: var(--danger); 
}
.btn-outline.text-info { 
    color: var(--secondary) !important; 
    border-color: rgba(2, 132, 199, 0.25); 
}
.btn-outline.text-info:hover { 
    background: rgba(2, 132, 199, 0.08); 
    border-color: var(--secondary); 
}
.btn-outline.text-success { 
    color: var(--accent) !important; 
    border-color: rgba(16, 185, 129, 0.25); 
}
.btn-outline.text-success:hover { 
    background: rgba(16, 185, 129, 0.08); 
    border-color: var(--accent); 
}

.btn-ghost { background: transparent; border: none; color: var(--gray-600); }
.btn-ghost:hover { background: var(--gray-200); }

.btn-link { background: none; border: none; color: var(--secondary); font-family: inherit; font-weight: 600; cursor: pointer; }

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}

.form-row {
    display: flex;
    gap: 14px;
    margin-bottom: 12px;
}

.col-3 { flex: 1; }
.col-4 { flex: 1; }
.col-6 { flex: 1; }

.form-group label {
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--gray-700);
}

.required { color: var(--danger); }

.form-control, .form-select {
    width: 100%;
    padding: 8px 12px;
    font-family: inherit;
    font-size: 0.88rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    background: var(--white);
    color: var(--gray-800);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus, .form-select:focus {
    border-color: var(--secondary);
    box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
}

.form-control[readonly] { background: var(--gray-100); }

.form-divider {
    border: 0;
    border-top: 1px dashed var(--gray-300);
    margin: 18px 0;
}

.custom-checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.88rem;
    cursor: pointer;
}

/* ================= 8. MODAL DIALOGS ================= */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.65);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 20px;
}

.modal-overlay.hidden { display: none; }

.modal-dialog {
    background: var(--white);
    border-radius: var(--radius);
    max-width: 650px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: scaleIn 0.2s ease-out;
}

.modal-md { max-width: 550px; }
.modal-lg { max-width: 880px; }

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.96); }
    to { opacity: 1; transform: scale(1); }
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 1.15rem;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.6rem;
    color: var(--gray-400);
    cursor: pointer;
    line-height: 1;
}

.modal-close:hover { color: var(--gray-800); }

.modal-body { padding: 20px; }
.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--gray-200);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ================= 9. OFFICIAL FORMS PREVIEW & LIVE PRINT ================= */
.official-preview-frame {
    background: #ffffff;
    border: 1px solid var(--gray-300);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
    padding: 20px;
    border-radius: 4px;
    font-size: 9.5pt;
    min-height: 480px;
}

.reports-action-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}

.report-catalog-card {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 18px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.report-catalog-card h4 {
    font-size: 1.05rem;
    color: var(--primary);
    margin-bottom: 6px;
}

.report-catalog-card p {
    font-size: 0.82rem;
    color: var(--gray-500);
    margin-bottom: 14px;
}

.json-code-box {
    background: #0f172a;
    color: #38bdf8;
    padding: 12px;
    border-radius: 6px;
    font-family: monospace;
    font-size: 0.82rem;
    max-height: 350px;
    overflow-y: auto;
}

/* ================= 10. TOAST NOTIFICATIONS ================= */
.toast-stack {
    position: fixed;
    bottom: 24px;
    left: 24px;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast-msg {
    background: var(--gray-900);
    color: var(--white);
    padding: 12px 18px;
    border-radius: 8px;
    font-size: 0.9rem;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 280px;
    animation: slideInLeft 0.3s ease-out;
}

@keyframes slideInLeft {
    from { transform: translateX(-100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.toast-success { border-right: 5px solid var(--accent); }
.toast-error { border-right: 5px solid var(--danger); }
.toast-warning { border-right: 5px solid var(--warning); }

/* ================= 11. GLOBAL FOOTER ================= */
.app-global-footer {
    background: var(--white);
    border-top: 1px solid var(--gray-200);
    padding: 14px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    color: var(--gray-500);
    flex-wrap: wrap;
    gap: 10px;
}

.dev-highlight { color: var(--primary); font-weight: 700; }
.dot-online {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
    margin-left: 4px;
}

/* ================= 12. OFFICIAL A4 PRINT STYLES ================= */
.print-only { display: none; }

@media print {
    .no-print, .login-overlay, .modal-overlay, .toast-stack, .app-sidebar, .top-header, .app-global-footer {
        display: none !important;
    }

    body.app-body-container {
        background: #ffffff !important;
        color: #000000 !important;
        font-size: 10pt;
    }

    .app-main-wrapper {
        margin-right: 0 !important;
    }

    .print-only {
        display: block !important;
    }

    .print-page-wrapper {
        padding: 8mm 12mm;
    }

    .print-top-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-bottom: 2px solid #00223d;
        padding-bottom: 10px;
        margin-bottom: 12px;
    }

    .pth-company-ar {
        font-size: 15pt;
        font-weight: 900;
        color: #00223d;
    }

    .pth-sub {
        font-size: 9.5pt;
        color: #334155;
    }

    .pth-dept {
        font-size: 8.5pt;
        color: #64748b;
    }

    .print-internal-watermark {
        font-size: 7.5pt;
        color: #94a3b8;
        border: 1px dashed #cbd5e1;
        padding: 1px 6px;
        border-radius: 3px;
        margin-top: 4px;
    }

    .pth-company-en {
        font-family: Arial, sans-serif;
        font-weight: bold;
        font-size: 11pt;
        color: #00223d;
        text-align: left;
    }

    .pth-meta {
        text-align: left;
        font-size: 8.5pt;
        color: #334155;
    }

    .print-title-banner {
        text-align: center;
        margin-bottom: 15px;
    }

    .print-title-banner h2 {
        font-size: 14pt;
        color: #00223d;
        margin-bottom: 2px;
    }

    .print-doc-subinfo {
        font-size: 9pt;
        color: #475569;
    }

    table {
        width: 100% !important;
        border-collapse: collapse !important;
        margin-top: 10px;
        page-break-inside: auto;
    }

    tr { page-break-inside: avoid; page-break-after: auto; }
    thead { display: table-header-group; }

    th, td {
        border: 1px solid #64748b !important;
        padding: 5px 6px !important;
        font-size: 8.5pt !important;
    }

    th {
        background-color: #f1f5f9 !important;
        color: #000000 !important;
    }

    .print-signatures-grid {
        display: flex;
        justify-content: space-between;
        margin-top: 35px;
        page-break-inside: avoid;
    }

    .print-sig-col {
        width: 23%;
        text-align: center;
        border-top: 1px dotted #94a3b8;
        padding-top: 6px;
    }

    .psc-title { font-weight: bold; font-size: 9.5pt; display: block; margin-bottom: 12px; }
    .psc-name { font-size: 8.5pt; display: block; margin-bottom: 12px; }
    .psc-line { font-size: 8pt; color: #475569; display: block; }

    .print-bottom-footer {
        display: flex;
        justify-content: space-between;
        margin-top: 25px;
        padding-top: 6px;
        border-top: 1px solid #cbd5e1;
        font-size: 7.5pt;
        color: #64748b;
    }
}

/* ================= 13. RESPONSIVE DESIGN ================= */
@media (max-width: 1024px) {
    .app-sidebar {
        transform: translateX(100%);
    }

    .app-sidebar.open {
        transform: translateX(0);
    }

    .app-main-wrapper {
        margin-right: 0 !important;
    }

    .btn-sidebar-toggle {
        display: block;
    }

    .dash-split-grid, .split-view {
        grid-template-columns: 1fr;
    }

    .quick-search-box {
        width: 240px;
    }
}

@media (max-width: 640px) {
    .th-center { display: none; }
    .top-header { padding: 0 12px; }
    .app-content-area { padding: 12px; }
    .form-row { flex-direction: column; gap: 8px; }
}

/* 14. FOREMEN & CUSTODY STYLING */
.tab-subnav {
    display: flex;
    gap: 8px;
    border-bottom: 2px solid var(--border-color, #e2e8f0);
    padding-bottom: 8px;
    overflow-x: auto;
}

.tab-subnav .btn {
    white-space: nowrap;
    border-radius: 20px;
    padding: 6px 16px;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s ease;
}

.statement-header-controls {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 12px;
}

@media (max-width: 768px) {
    .statement-header-controls {
        flex-direction: column;
        align-items: stretch !important;
    }
    .page-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 12px;
    }
    .page-actions {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
    }
    .page-actions .btn {
        flex: 1 1 45%;
        text-align: center;
        font-size: 0.8rem;
    }
}
