/* ============================================================
   ContractingPro ERP — Royal Purple Theme 🟣
   Primary: #3b0764 | Accent: #7c3aed | Light: #faf5ff
   Font: Cairo (Arabic RTL)
   ============================================================ */

/* ── CSS Variables ─────────────────────────────────────────── */
:root {
    --sidebar-bg:       #3b0764;
    --sidebar-hover:    rgba(167,139,250,.12);
    --sidebar-active:   rgba(167,139,250,.22);
    --sidebar-text:     rgba(255,255,255,.6);
    --sidebar-active-text: #c4b5fd;
    --sidebar-active-border: #a78bfa;
    --sidebar-section:  rgba(167,139,250,.35);
    --sidebar-width:    260px;

    --brand-primary:    #3b0764;
    --brand-accent:     #7c3aed;
    --brand-light:      #6d28d9;

    --page-bg:          #faf5ff;
    --card-bg:          #ffffff;
    --card-border:      #ede9fe;
    --card-shadow:      0 2px 12px rgba(109,40,217,.07);
    --card-radius:      12px;

    --topbar-bg:        #ffffff;
    --topbar-border:    #ede9fe;

    --table-head-bg:    #3b0764;
    --table-head-color: #ffffff;
    --table-row-hover:  #faf5ff;
    --table-border:     #f3e8ff;

    --btn-primary-bg:   #7c3aed;
    --btn-primary-hover:#6d28d9;

    --badge-active-bg:  #f0fdf4;
    --badge-active-color:#15803d;
    --badge-warn-bg:    #fefce8;
    --badge-warn-color: #a16207;
    --badge-danger-bg:  #fce7f3;
    --badge-danger-color:#9d174d;

    --text-primary:     #1e0a3c;
    --text-secondary:   #6b21a8;
    --text-muted:       #9ca3af;

    --success:  #15803d;
    --warning:  #d97706;
    --danger:   #be185d;
    --info:     #0369a1;
}

/* ── Global ────────────────────────────────────────────────── */
* { font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif; box-sizing: border-box; }

html, body { direction: rtl; }

body {
    background: var(--page-bg);
    color: var(--text-primary);
    margin: 0;
    transition: background .25s ease, color .25s ease;
}

/* ── App Layout ────────────────────────────────────────────── */
#app-wrapper {
    display: flex;
    flex-direction: row;        /* sidebar يمين، content يسار */
    min-height: 100vh;
    direction: rtl;
}

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--sidebar-bg);
    position: sticky;
    top: 0;
    align-self: flex-start;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    max-height: 100vh;
    order: 1;                   /* القائمة أولاً = أقصى اليمين */
    flex-shrink: 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(167,139,250,.2) transparent;
    border-left: 1px solid rgba(167,139,250,.15);
}

/* Sidebar Brand */
.sidebar .brand-section {
    padding: 20px 16px 16px;
    border-bottom: 1px solid rgba(167,139,250,.15);
    margin-bottom: 8px;
}
.sidebar .brand-title {
    font-size: 16px;
    font-weight: 800;
    color: #fff;
    line-height: 1.2;
}
.sidebar .brand-subtitle {
    font-size: 10px;
    color: rgba(255,255,255,.35);
    font-weight: 400;
    margin-top: 2px;
    display: block;
}
.sidebar .company-name {
    font-size: 11px;
    color: #c4b5fd;
    font-weight: 600;
    margin-top: 6px;
    padding: 4px 8px;
    background: rgba(167,139,250,.15);
    border-radius: 6px;
    display: inline-block;
}

/* Sidebar Section Headers */
.sidebar .nav-section-header {
    font-size: 9px;
    font-weight: 700;
    color: var(--sidebar-section);
    letter-spacing: .1em;
    text-transform: uppercase;
    padding: 10px 16px 4px;
}

/* Sidebar Links */
.sidebar-link {
    color: var(--sidebar-text) !important;
    border-radius: 8px;
    margin: 1px 8px;
    padding: 9px 12px;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all .15s ease;
    border-right: 2px solid transparent;
    text-decoration: none;
}
.sidebar-link:hover {
    background: var(--sidebar-hover);
    color: rgba(255,255,255,.85) !important;
}
.sidebar-link.active {
    background: var(--sidebar-active);
    color: var(--sidebar-active-text) !important;
    border-right: 2px solid var(--sidebar-active-border);
    font-weight: 600;
}
.sidebar-link i {
    font-size: 14px;
    width: 18px;
    text-align: center;
    opacity: .8;
}
.sidebar-link.active i { opacity: 1; }

/* ── Topbar ────────────────────────────────────────────────── */
.topbar {
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--topbar-border);
    min-height: 56px;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 8px rgba(109,40,217,.06);
}
.topbar .company-badge {
    background: #ede9fe;
    color: #5b21b6;
    padding: 4px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}
.topbar .switch-btn {
    color: #7c3aed;
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    padding: 5px 12px;
    border: 1px solid #ddd6fe;
    border-radius: 8px;
    background: #f5f3ff;
    transition: .15s;
}
.topbar .switch-btn:hover { background: #ede9fe; }

/* ── Main Content ──────────────────────────────────────────── */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    order: 2;                   /* المحتوى على اليسار */
}
.content-area {
    padding: 24px;
    flex: 1;
}

/* ── Cards ─────────────────────────────────────────────────── */
.card {
    background: var(--card-bg);
    border: 1px solid var(--card-border) !important;
    border-radius: var(--card-radius) !important;
    box-shadow: var(--card-shadow) !important;
}
.card-header, .card-head {
    background: var(--brand-primary) !important;
    color: #fff !important;
    border-radius: var(--card-radius) var(--card-radius) 0 0 !important;
    border: none !important;
    padding: 12px 18px;
    font-weight: 700;
    font-size: 14px;
}

/* ── Stats Cards ───────────────────────────────────────────── */
.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--card-radius);
    padding: 16px 18px;
    box-shadow: var(--card-shadow);
    transition: transform .2s, box-shadow .2s;
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(109,40,217,.12);
}
.stat-card .stat-value {
    font-size: 26px;
    font-weight: 800;
    color: var(--brand-primary);
    line-height: 1;
}
.stat-card .stat-label {
    font-size: 12px;
    color: var(--brand-accent);
    font-weight: 600;
    margin-top: 4px;
}
.stat-card .stat-icon {
    font-size: 28px;
    opacity: .2;
}

/* ── Tables ────────────────────────────────────────────────── */
.table thead th,
thead[style*="background"] {
    background: var(--table-head-bg) !important;
    color: var(--table-head-color) !important;
    font-weight: 600;
    font-size: 13px;
    border: none !important;
    padding: 12px 14px;
    white-space: nowrap;
}
.table tbody tr:hover { background: var(--table-row-hover); }
.table td, .table th { border-color: var(--table-border) !important; vertical-align: middle; }

/* ── Buttons ───────────────────────────────────────────────── */
.btn-primary {
    background: var(--btn-primary-bg) !important;
    border-color: var(--btn-primary-bg) !important;
    color: #fff !important;
    font-weight: 600;
    border-radius: 8px;
}
.btn-primary:hover, .btn-primary:focus {
    background: var(--btn-primary-hover) !important;
    border-color: var(--btn-primary-hover) !important;
}
.btn-outline-primary {
    color: var(--btn-primary-bg) !important;
    border-color: var(--btn-primary-bg) !important;
    font-weight: 600;
    border-radius: 8px;
}
.btn-outline-primary:hover {
    background: var(--btn-primary-bg) !important;
    color: #fff !important;
}

/* ── Form Controls ─────────────────────────────────────────── */
.form-control:focus, .form-select:focus {
    border-color: #a78bfa !important;
    box-shadow: 0 0 0 3px rgba(167,139,250,.15) !important;
}
.form-label { font-weight: 600; font-size: 13px; color: var(--text-primary); }

/* ── Badges ────────────────────────────────────────────────── */
.badge.bg-success, .badge-success { background: var(--badge-active-bg) !important; color: var(--badge-active-color) !important; }
.badge.bg-warning, .badge-warning { background: var(--badge-warn-bg) !important; color: var(--badge-warn-color) !important; }
.badge.bg-danger,  .badge-danger  { background: var(--badge-danger-bg) !important; color: var(--badge-danger-color) !important; }
.badge.bg-primary  { background: var(--brand-accent) !important; color: #fff !important; }
.badge.bg-info     { background: #ede9fe !important; color: #5b21b6 !important; }

/* ── Alerts / TempData ─────────────────────────────────────── */
.alert-success { background: #f0fdf4; border-color: #bbf7d0; color: #15803d; }
.alert-danger  { background: #fce7f3; border-color: #fbcfe8; color: #9d174d; }
.alert-warning { background: #fefce8; border-color: #fde68a; color: #92400e; }
.alert-info    { background: #f5f3ff; border-color: #ddd6fe; color: #5b21b6; }

/* ── Links ─────────────────────────────────────────────────── */
a { color: var(--brand-accent); }
a:hover { color: var(--brand-light); }

/* ── Page Titles ───────────────────────────────────────────── */
h4, h5 { color: var(--brand-primary); font-weight: 700; }
.page-title {
    font-size: 20px;
    font-weight: 800;
    color: var(--brand-primary);
    display: flex;
    align-items: center;
    gap: 10px;
}
.page-title i { color: var(--brand-accent); }

/* ── Filter Cards ──────────────────────────────────────────── */
.filter-card {
    background: #fff;
    border: 1px solid var(--card-border);
    border-radius: var(--card-radius);
    padding: 16px 18px;
}

/* ── Modals ────────────────────────────────────────────────── */
.modal-header {
    background: var(--brand-primary) !important;
    color: #fff !important;
    border-radius: 12px 12px 0 0;
}
.modal-header .btn-close { filter: invert(1); }
.modal-content { border-radius: 12px; border: none; box-shadow: 0 20px 60px rgba(59,7,100,.2); }

/* ── Report Header ─────────────────────────────────────────── */
.report-header { border-bottom: 3px solid var(--brand-primary); padding-bottom: 14px; margin-bottom: 18px; }

/* ── Nav Pills ─────────────────────────────────────────────── */
.nav-pills .nav-link.active { background: var(--brand-accent); }
.nav-pills .nav-link { color: var(--brand-accent); }

/* ── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ddd6fe; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #a78bfa; }

/* ── Hover Shadow ──────────────────────────────────────────── */
.hover-shadow { transition: box-shadow .2s, transform .2s; }
.hover-shadow:hover { box-shadow: 0 6px 20px rgba(109,40,217,.12) !important; transform: translateY(-2px); }

/* ── Print ─────────────────────────────────────────────────── */
@media print {
    .sidebar, .topbar, .no-print, .btn, button:not(.print-keep) { display: none !important; }
    .main-content, body { margin: 0 !important; padding: 8px !important; }
    .card { box-shadow: none !important; border: 1px solid #ddd !important; }
    thead { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        width: 60px;
        position: fixed;
        right: 0;
        top: 0;
        height: 100vh;
        z-index: 1000;
    }
    .sidebar .brand-title, .sidebar .nav-section-header,
    .sidebar-link span, .sidebar .company-name { display: none; }
    .sidebar-link { justify-content: center; padding: 12px; }
    .sidebar-link i { width: auto; font-size: 18px; }
    .main-content { margin-right: 60px; }
}

/* ── Smooth Theme Transition ── */
.sidebar, .card, .topbar, .stat-card, .modal-content,
.table thead th, .badge, .btn-primary, .btn-outline-primary,
.sidebar-link, .nav-section-header {
    transition: background .25s ease, color .2s ease,
                border-color .2s ease, box-shadow .2s ease !important;
}

/* ── Topbar Icons & User Menu ────────────────────────────────── */
.topbar-icon-btn {
    width: 36px; height: 36px;
    border-radius: 8px;
    border: 1px solid var(--topbar-border, #ede9fe);
    background: var(--card-bg, #fff);
    color: var(--brand-accent, #7c3aed);
    font-size: 15px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    position: relative; transition: .2s;
}
.topbar-icon-btn:hover { background: var(--badge-bg); transform: scale(1.05); }
.notif-dot {
    position: absolute; top: 6px; left: 6px;
    width: 7px; height: 7px;
    background: #ef4444; border-radius: 50%;
    border: 2px solid #fff;
}

/* User Avatar */
.user-avatar {
    width: 32px; height: 32px;
    background: var(--brand-accent, #7c3aed);
    color: #fff;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 700;
    cursor: pointer; transition: .2s;
    flex-shrink: 0;
}
.user-menu {
    display: flex; align-items: center; gap: 6px;
    cursor: pointer; padding: 4px 8px;
    border-radius: 8px; transition: .15s;
    position: relative;
}
.user-menu:hover { background: var(--badge-bg); }

/* User Dropdown */
.user-dropdown {
    position: fixed;
    top: 58px;
    left: 16px;
    width: 220px;
    background: #fff;
    border: 1px solid var(--card-border, #ede9fe);
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0,0,0,.14);
    z-index: 9990;
    display: none;
    flex-direction: column;
    direction: rtl;
    overflow: hidden;
    animation: panelIn .18s ease;
}
.user-dropdown.open { display: flex; }
.user-dropdown-header {
    display: flex; align-items: center; gap: 10px;
    padding: 14px 14px 10px;
    background: #fafafa;
}
.user-avatar-lg {
    width: 40px; height: 40px;
    background: var(--brand-accent, #7c3aed);
    color: #fff; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px; font-weight: 700; flex-shrink: 0;
}
.user-dropdown-item {
    display: flex; align-items: center;
    padding: 9px 14px;
    font-size: 13px; color: #374151;
    text-decoration: none; transition: .12s;
    cursor: pointer;
}
.user-dropdown-item:hover { background: var(--badge-bg); color: var(--brand-accent); }
.dropdown-divider { height: 1px; background: #f1f5f9; margin: 2px 0; }
