/* ===========================
   EMAC Treasury System — Production CSS
   Arabic RTL — Modern Clean Design
   =========================== */

:root {
    --primary: #1a56db;
    --primary-dark: #1340a8;
    --primary-light: #e8eefb;
    --secondary: #0d9488;
    --accent: #f59e0b;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #f59e0b;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.1), 0 4px 10px rgba(0,0,0,0.05);
    --sidebar-width: 260px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
    direction: rtl;
    text-align: right;
    background: var(--gray-50);
    color: var(--gray-800);
    line-height: 1.6;
    min-height: 100vh;
}

/* Hide all pages by default — SPA router shows one at a time */
.page { display: none; }
.page.active { display: block; }

/* Full-screen pages (login, company-select) */
.page-fullscreen { min-height: 100vh; }
.page-fullscreen.active { display: flex; }

/* ===== LOGIN PAGE ===== */
.login-page {
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1a56db 0%, #0d9488 100%);
    padding: 20px;
    width: 100%;
}

.login-card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 40px;
    width: 100%;
    max-width: 420px;
    text-align: center;
}

.login-logo {
    width: 80px;
    height: 80px;
    background: var(--primary);
    border-radius: 50%;
    margin: 0 auto 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    color: white;
}

.login-card h1 {
    font-size: 24px;
    color: var(--gray-900);
    margin-bottom: 8px;
}

.login-card .subtitle {
    color: var(--gray-500);
    margin-bottom: 30px;
    font-size: 14px;
}

/* ===== FORMS ===== */
.form-group {
    margin-bottom: 20px;
    text-align: right;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-700);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px 16px;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-family: inherit;
    direction: rtl;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: white;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.15);
}

.form-group input::placeholder { color: var(--gray-400); }

.form-group .input-icon-wrap { position: relative; }
.form-group .input-icon-wrap input { padding-right: 44px; }
.form-group .input-icon-wrap .icon {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-400);
    font-size: 18px;
}

.form-error {
    color: var(--danger);
    font-size: 13px;
    margin-top: 4px;
}

/* ===== ALERT ===== */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.alert-danger { background: #fee2e2; color: #991b1b; }
.alert-success { background: #d1fae5; color: #065f46; }
.alert-warning { background: #fef3c7; color: #92400e; }

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary { background: var(--primary); color: white; width: 100%; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); box-shadow: var(--shadow-md); }

.btn-secondary { background: var(--gray-100); color: var(--gray-700); border: 1.5px solid var(--gray-200); }
.btn-secondary:hover:not(:disabled) { background: var(--gray-200); }

.btn-success { background: var(--success); color: white; }
.btn-success:hover:not(:disabled) { background: #15803d; }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }

.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-icon { padding: 6px 10px; }

/* ===== COMPANY SELECT PAGE ===== */
.company-page {
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--gray-50);
    padding: 20px;
    width: 100%;
}

.company-card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 40px;
    width: 100%;
    max-width: 600px;
    text-align: center;
}

.company-card h1 { font-size: 22px; margin-bottom: 8px; color: var(--gray-900); }
.company-card .subtitle { color: var(--gray-500); margin-bottom: 30px; font-size: 14px; }

.company-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    text-align: right;
}

.company-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    color: inherit;
    background: white;
}
.company-item:hover { border-color: var(--primary); background: var(--primary-light); }
.company-item.active { border-color: var(--primary); background: var(--primary-light); }

.company-icon {
    width: 50px; height: 50px;
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    font-size: 22px; flex-shrink: 0;
}
.company-icon.c1 { background: #dbeafe; color: #1d4ed8; }
.company-icon.c2 { background: #d1fae5; color: #059669; }
.company-icon.c3 { background: #fef3c7; color: #d97706; }

.company-info h3 { font-size: 16px; margin-bottom: 2px; }
.company-info p { font-size: 13px; color: var(--gray-500); }

/* ===== APP LAYOUT ===== */
.app-layout { display: flex; min-height: 100vh; }

/* ===== SIDEBAR ===== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--gray-900);
    color: white;
    position: fixed;
    top: 0; right: 0; bottom: 0;
    overflow-y: auto;
    z-index: 100;
    display: flex;
    flex-direction: column;
}

.sidebar-header { padding: 20px; border-bottom: 1px solid rgba(255,255,255,0.1); }
.sidebar-header .logo { display: flex; align-items: center; gap: 12px; }
.sidebar-header .logo-icon {
    width: 40px; height: 40px;
    background: var(--primary);
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    font-size: 18px;
}
.sidebar-header .logo-text { font-size: 16px; font-weight: 700; }
.sidebar-header .logo-sub { font-size: 11px; color: var(--gray-400); }

/* Company switcher in sidebar */
.company-switcher {
    margin: 16px 20px;
    padding: 10px 14px;
    background: rgba(255,255,255,0.08);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
}
.company-switcher:hover { background: rgba(255,255,255,0.14); }
.company-switcher .cs-icon {
    width: 32px; height: 32px;
    background: var(--primary); border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; flex-shrink: 0;
}
.company-switcher .cs-name { font-size: 13px; font-weight: 600; }
.company-switcher .cs-label { font-size: 10px; color: var(--gray-400); }
.company-switcher .cs-arrow { margin-right: auto; color: var(--gray-400); }

/* Company dropdown */
.company-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    left: 0;
    margin: 4px 0 0;
    background: var(--gray-800);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    z-index: 110;
}
.company-dropdown.open { display: block; }
.company-dropdown-item {
    padding: 10px 14px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s;
    color: var(--gray-300);
}
.company-dropdown-item:hover { background: rgba(255,255,255,0.1); color: white; }
.company-dropdown-item.active { background: rgba(26, 86, 219, 0.2); color: white; }

/* Nav menu */
.sidebar-nav { padding: 10px 0; flex: 1; }
.nav-section {
    padding: 8px 20px 4px;
    font-size: 11px;
    text-transform: uppercase;
    color: var(--gray-500);
    letter-spacing: 0.5px;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: var(--gray-300);
    text-decoration: none;
    font-size: 14px;
    transition: all 0.15s;
    border-right: 3px solid transparent;
    cursor: pointer;
}
.nav-item:hover { background: rgba(255,255,255,0.06); color: white; }
.nav-item.active { background: rgba(26, 86, 219, 0.15); color: white; border-right-color: var(--primary); }
.nav-item .nav-icon { font-size: 18px; width: 22px; text-align: center; }
.nav-item.disabled { opacity: 0.35; pointer-events: none; }
.nav-item.hidden { display: none; }

/* Collapsible sidebar submenu */
.nav-parent {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: var(--gray-300);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s;
    border-right: 3px solid transparent;
}
.nav-parent:hover { background: rgba(255,255,255,0.06); color: white; }
.nav-parent.expanded { color: white; }
.nav-parent .nav-icon { font-size: 18px; width: 22px; text-align: center; }
.nav-arrow {
    margin-right: auto;
    font-size: 12px;
    transition: transform 0.2s;
}
.nav-parent.expanded .nav-arrow { transform: rotate(90deg); }

.nav-submenu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease;
}
.nav-submenu.open { max-height: 400px; }
.nav-submenu .nav-item {
    padding-right: 52px;
    font-size: 13px;
}

/* Sidebar footer */
.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    gap: 12px;
}
.sidebar-footer .user-avatar {
    width: 36px; height: 36px;
    background: var(--secondary);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; font-weight: 700; flex-shrink: 0;
}
.sidebar-footer .user-name { font-size: 13px; font-weight: 600; }
.sidebar-footer .user-role { font-size: 11px; color: var(--gray-400); }
.sidebar-footer .logout-btn {
    margin-right: auto;
    color: var(--gray-400);
    cursor: pointer;
    font-size: 18px;
    transition: color 0.2s;
    background: none;
    border: none;
}
.sidebar-footer .logout-btn:hover { color: var(--danger); }

/* ===== MAIN CONTENT ===== */
.main-content { margin-right: var(--sidebar-width); flex: 1; padding: 0; }

.topbar {
    background: white;
    border-bottom: 1px solid var(--gray-200);
    padding: 16px 30px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar h2 { font-size: 20px; color: var(--gray-900); }
.topbar .breadcrumb { font-size: 13px; color: var(--gray-400); }

.page-content { padding: 30px; }

/* ===== CARDS & STATS ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}
.stat-card {
    background: white;
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 16px;
}
.stat-icon {
    width: 48px; height: 48px;
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    font-size: 22px;
}
.stat-icon.blue { background: #dbeafe; color: #1d4ed8; }
.stat-icon.green { background: #d1fae5; color: #059669; }
.stat-icon.amber { background: #fef3c7; color: #d97706; }
.stat-icon.red { background: #fee2e2; color: #dc2626; }

.stat-info h3 { font-size: 24px; font-weight: 700; line-height: 1; }
.stat-info p { font-size: 13px; color: var(--gray-500); margin-top: 4px; }

/* ===== TABLE ===== */
.card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.card-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}
.card-header h3 { font-size: 16px; }

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }
table th {
    background: var(--gray-50);
    padding: 12px 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-600);
    text-align: right;
    border-bottom: 1px solid var(--gray-200);
    white-space: nowrap;
}
table td { padding: 14px 16px; font-size: 14px; border-bottom: 1px solid var(--gray-100); }
table tr:hover { background: var(--gray-50); }

/* ===== BADGES ===== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-green { background: #d1fae5; color: #059669; }
.badge-amber { background: #fef3c7; color: #92400e; }
.badge-red { background: #fee2e2; color: #dc2626; }
.badge-gray { background: var(--gray-100); color: var(--gray-600); }

/* ===== MODAL ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
}
.modal-overlay.open { display: flex; }

.modal {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
}
.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.modal-header h3 { font-size: 18px; }
.modal-close {
    background: none;
    border: none;
    font-size: 22px;
    color: var(--gray-400);
    cursor: pointer;
}
.modal-close:hover { color: var(--gray-600); }
.modal-body { padding: 24px; }
.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--gray-100);
    display: flex;
    gap: 12px;
    justify-content: flex-start;
}

/* ===== CHECKBOX GROUP ===== */
.checkbox-group { display: flex; flex-wrap: wrap; gap: 10px; }
.checkbox-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}
.checkbox-item:hover { border-color: var(--primary); }
.checkbox-item.checked { border-color: var(--primary); background: var(--primary-light); }
.checkbox-item input { accent-color: var(--primary); }

/* ===== TOAST NOTIFICATIONS ===== */
.toast-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}
.toast {
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.3s ease-out;
    pointer-events: auto;
}
.toast-success { background: #065f46; color: white; }
.toast-danger { background: #991b1b; color: white; }
.toast-warning { background: #92400e; color: white; }

@keyframes toastIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== LOADING SPINNER ===== */
.spinner {
    display: inline-block;
    width: 20px; height: 20px;
    border: 3px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.7s linear infinite;
}
.spinner-dark {
    border-color: var(--gray-200);
    border-top-color: var(--primary);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--gray-400);
}
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 15px; }

/* ===== BADGE EXTRAS ===== */
.badge-yellow { background: #fef3c7; color: #92400e; }

/* ===== NUMERIC CELLS ===== */
.num { font-variant-numeric: tabular-nums; text-align: left; direction: ltr; }

/* ===== SMALL BUTTON ===== */
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ===== TEXT HELPERS ===== */
.text-muted { color: var(--gray-400); }

/* ===== EXCHANGE RATE GRID ===== */
.exchange-rate-grid th,
.exchange-rate-grid td { text-align: center; }
.exchange-rate-grid .er-cell { position: relative; }
.exchange-rate-grid .er-edit-btn {
    opacity: 0;
    position: absolute;
    left: 4px;
    top: 50%;
    transform: translateY(-50%);
    padding: 2px 6px;
    font-size: 11px;
    background: none;
    border: none;
    cursor: pointer;
    transition: opacity 0.15s;
}
.exchange-rate-grid .er-cell:hover .er-edit-btn { opacity: 1; }
.er-current-month { background: rgba(26, 86, 219, 0.06); }

/* ===== IMPORT WIZARD ===== */
.wizard-step-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
}
.wizard-step-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}
.step-num {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    background: var(--gray-100);
    color: var(--gray-400);
    transition: all 0.2s;
}
.wizard-step-item.active .step-num { background: var(--primary); color: white; }
.wizard-step-item.completed .step-num { background: #059669; color: white; }
.step-label { font-size: 12px; color: var(--gray-500); }
.wizard-step-item.active .step-label { color: var(--primary); font-weight: 600; }
.step-connector {
    width: 40px;
    height: 2px;
    background: var(--gray-200);
    margin: 0 8px;
    margin-bottom: 18px;
}

/* Upload area */
.upload-area {
    border: 2px dashed var(--gray-200);
    border-radius: var(--radius);
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}
.upload-area:hover,
.upload-area.dragover {
    border-color: var(--primary);
    background: rgba(26, 86, 219, 0.04);
}
.upload-icon { font-size: 48px; margin-bottom: 12px; }

/* Entity type radio cards */
.entity-type-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}
.radio-card {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}
.radio-card:hover { border-color: var(--primary); }
.radio-card:has(input:checked) { border-color: var(--primary); background: var(--primary-light); }
.radio-card input { accent-color: var(--primary); }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .sidebar { width: 100%; position: relative; }
    .main-content { margin-right: 0; }
    .stats-grid { grid-template-columns: 1fr; }
    .topbar { padding: 12px 16px; }
    .page-content { padding: 16px; }
    .modal { max-width: 95%; }
}
