/* ================================================================
   نظام إرادة للرواتب — ملف الأنماط
   ================================================================ */

:root {
    --primary:      #0d8a8a;
    --primary-dark: #0a6c6c;
    --primary-light:#e6f5f5;
    --sidebar-bg:   #0f172a;
    --sidebar-hover:#1e293b;
    --sidebar-text: #94a3b8;
    --sidebar-active:#ffffff;
    --body-bg:      #f1f5f9;
    --card-bg:      #ffffff;
    --border:       #e2e8f0;
    --text:         #1e293b;
    --text-muted:   #64748b;
    --success:      #10b981;
    --warning:      #f59e0b;
    --danger:       #ef4444;
    --info:         #06b6d4;
    --sidebar-width:260px;
    --topbar-height:64px;
}

/* ---- تعديلات أساسية ------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: 'Segoe UI', 'Tahoma', Arial, sans-serif;
    background: var(--body-bg);
    color: var(--text);
    direction: rtl;
    min-height: 100vh;
    margin: 0;
}

/* ---- Sidebar -------------------------------------------------- */
#sidebar {
    position: fixed;
    top: 0; right: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: transform .3s ease;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #334155 transparent;
}

#sidebar .sidebar-brand {
    padding: 20px 16px 16px;
    border-bottom: 1px solid #1e293b;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

#sidebar .brand-logo {
    background: #ffffff;
    border-radius: 12px;
    padding: 10px 14px;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
#sidebar .brand-logo img { max-width: 100%; height: 46px; object-fit: contain; }
#sidebar .brand-sub {
    font-size: 11px;
    color: var(--sidebar-text);
    letter-spacing: .5px;
}

#sidebar .sidebar-brand .brand-icon {
    width: 40px; height: 40px;
    background: var(--primary);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: white;
    flex-shrink: 0;
}

#sidebar .brand-text h1 {
    font-size: 15px;
    font-weight: 700;
    color: #f1f5f9;
    margin: 0;
    line-height: 1.2;
}

#sidebar .brand-text span {
    font-size: 11px;
    color: var(--sidebar-text);
}

#sidebar .nav-section {
    padding: 20px 12px 8px;
}

#sidebar .nav-section-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #475569;
    padding: 0 8px;
    margin-bottom: 6px;
}

#sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 2px;
    transition: all .2s;
}

#sidebar .nav-link:hover {
    background: var(--sidebar-hover);
    color: #e2e8f0;
}

#sidebar .nav-link.active {
    background: var(--primary);
    color: white;
}

#sidebar .nav-link i {
    font-size: 18px;
    width: 22px;
    text-align: center;
    flex-shrink: 0;
}

#sidebar .sidebar-footer {
    margin-top: auto;
    padding: 16px 12px;
    border-top: 1px solid #1e293b;
}

#sidebar .user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    background: var(--sidebar-hover);
}

#sidebar .user-avatar {
    width: 36px; height: 36px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: white;
    flex-shrink: 0;
}

#sidebar .user-name {
    font-size: 13px;
    font-weight: 600;
    color: #e2e8f0;
    margin: 0;
    line-height: 1.3;
}

#sidebar .user-role {
    font-size: 11px;
    color: var(--sidebar-text);
}

/* ---- Main Content -------------------------------------------- */
#main-content {
    margin-right: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ---- Topbar -------------------------------------------------- */
#topbar {
    height: var(--topbar-height);
    background: white;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
}

#topbar .page-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    margin: 0;
}

#topbar .topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

#topbar .topbar-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all .2s;
    text-decoration: none;
}

#topbar .topbar-btn.btn-logout {
    background: #fee2e2;
    color: var(--danger);
}

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

/* ---- Page Content ------------------------------------------- */
.page-content {
    flex: 1;
    padding: 28px;
}

/* ---- Cards -------------------------------------------------- */
.card {
    background: white;
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 1px 4px rgba(0,0,0,.05);
    overflow: hidden;
}

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

.card-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-body {
    padding: 20px;
}

/* ---- Stat Cards --------------------------------------------- */
.stat-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 1px 4px rgba(0,0,0,.05);
    transition: box-shadow .2s;
}

.stat-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.1); }

.stat-icon {
    width: 52px; height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
}

.stat-icon.blue   { background: var(--primary-light); color: var(--primary); }
.stat-icon.green  { background: #ecfdf5; color: var(--success); }
.stat-icon.yellow { background: #fffbeb; color: var(--warning); }
.stat-icon.red    { background: #fef2f2; color: var(--danger); }

.stat-info { flex: 1; }

.stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
    margin-bottom: 4px;
}

.stat-label {
    font-size: 13px;
    color: var(--text-muted);
}

/* ---- Tables ------------------------------------------------- */
.table-wrapper {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table thead th {
    background: #f8fafc;
    padding: 12px 16px;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
    text-align: right;
}

.data-table tbody td {
    padding: 13px 16px;
    border-bottom: 1px solid #f1f5f9;
    color: var(--text);
    vertical-align: middle;
}

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

/* ---- Badges ------------------------------------------------- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-success { background: #ecfdf5; color: #059669; }
.badge-warning { background: #fffbeb; color: #d97706; }
.badge-danger  { background: #fef2f2; color: #dc2626; }
.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-gray    { background: #f1f5f9; color: #64748b; }

/* ---- Buttons ------------------------------------------------ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: all .2s;
}

.btn-primary   { background: var(--primary);  color: white; }
.btn-primary:hover { background: var(--primary-dark); color: white; }
.btn-success   { background: var(--success);  color: white; }
.btn-success:hover { background: #059669; color: white; }
.btn-danger    { background: var(--danger);   color: white; }
.btn-danger:hover  { background: #dc2626; color: white; }
.btn-warning   { background: var(--warning);  color: white; }
.btn-outline   { background: white; color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { background: #f8fafc; }
.btn-sm        { padding: 5px 12px; font-size: 13px; }
.btn-icon      { padding: 7px; border-radius: 8px; }

/* ---- Forms -------------------------------------------------- */
.form-group { margin-bottom: 20px; }

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
}

.form-label .required { color: var(--danger); margin-right: 2px; }

.form-control, .form-select {
    display: block;
    width: 100%;
    padding: 9px 14px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    color: var(--text);
    background: white;
    transition: border-color .2s, box-shadow .2s;
    font-family: inherit;
    direction: rtl;
}

.form-control:focus, .form-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(13,138,138,.1);
}

.form-control::placeholder { color: #94a3b8; }

textarea.form-control { resize: vertical; min-height: 90px; }

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}

.form-section {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 24px;
}

.form-section-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ---- Tabs --------------------------------------------------- */
.tabs-nav {
    display: flex;
    border-bottom: 2px solid var(--border);
    margin-bottom: 24px;
    gap: 0;
}

.tab-btn {
    padding: 12px 20px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    margin-bottom: -2px;
    transition: all .2s;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
}

.tab-btn:hover { color: var(--primary); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ---- Alerts ------------------------------------------------- */
.alert {
    padding: 13px 16px;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 20px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.alert-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-danger  { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.alert-info    { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

/* ---- Modals ------------------------------------------------- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.show { display: flex; }

.modal-box {
    background: white;
    border-radius: 14px;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

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

.modal-title { font-size: 16px; font-weight: 700; margin: 0; }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-muted); }
.modal-body  { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }

/* ---- Search & Filter --------------------------------------- */
.search-bar {
    position: relative;
    width: 280px;
}

.search-bar input {
    width: 100%;
    padding: 8px 14px 8px 36px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
}

.search-bar i {
    position: absolute;
    left: 11px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

/* ---- Employee Card ----------------------------------------- */
.emp-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px; height: 38px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary);
    font-size: 15px;
    font-weight: 700;
    flex-shrink: 0;
}

/* ---- Payroll Table ----------------------------------------- */
.payroll-table th, .payroll-table td {
    font-size: 12px;
    padding: 8px 10px;
    white-space: nowrap;
}

.payroll-table .col-earning  { background: #f0fdf4 !important; }
.payroll-table .col-deduct   { background: #fef2f2 !important; }
.payroll-table .col-net      { background: #eff6ff !important; font-weight: 700; }
.payroll-table tfoot td      { font-weight: 700; background: #f8fafc; }

/* ---- Misc -------------------------------------------------- */
.divider {
    height: 1px;
    background: var(--border);
    margin: 20px 0;
}

.text-muted  { color: var(--text-muted); }
.text-sm     { font-size: 13px; }
.fw-bold     { font-weight: 700; }
.mt-auto     { margin-top: auto; }
.d-flex      { display: flex; }
.align-center{ align-items: center; }
.gap-8       { gap: 8px; }
.gap-12      { gap: 12px; }

/* ---- Empty State ------------------------------------------- */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state i   { font-size: 48px; margin-bottom: 16px; display: block; opacity: .4; }
.empty-state h3  { font-size: 16px; margin-bottom: 8px; color: var(--text); }
.empty-state p   { font-size: 14px; margin-bottom: 20px; }

/* ---- Responsive -------------------------------------------- */
#sidebar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: var(--text);
}

@media (max-width: 900px) {
    #sidebar {
        transform: translateX(100%);
    }
    #sidebar.open {
        transform: translateX(0);
    }
    #main-content {
        margin-right: 0;
    }
    #sidebar-toggle { display: flex; }
    .page-content { padding: 16px; }
}

/* ---- Loading Spinner --------------------------------------- */
.spinner {
    width: 20px; height: 20px;
    border: 2px solid rgba(255,255,255,.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin .6s linear infinite;
    display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Searchable Select ------------------------------------- */
.ss-wrap { position: relative; }
.ss-list {
    display: none;
    position: absolute;
    top: 100%; right: 0; left: 0;
    background: white;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    margin-top: 4px;
    max-height: 240px;
    overflow-y: auto;
    z-index: 50;
    box-shadow: 0 8px 24px rgba(0,0,0,.12);
}
.ss-item {
    padding: 9px 14px;
    font-size: 13px;
    cursor: pointer;
    border-bottom: 1px solid #f1f5f9;
}
.ss-item:hover { background: var(--primary-light); color: var(--primary); }
.ss-item:last-child { border-bottom: none; }
.ss-empty { padding: 14px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* Print */
@media print {
    #sidebar, #topbar { display: none !important; }
    #main-content { margin: 0 !important; }
    .no-print { display: none !important; }
}

/* ============ قائمة منسدلة قابلة للبحث (تُحسِّن <select>) ============ */
.nss { position: relative; }
.nss-control {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    width: 100%; text-align: right; cursor: pointer; background: #fff;
}
.nss-control .nss-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nss-control .nss-label.nss-ph { color: #94a3b8; }
.nss-control::after {
    content: ""; flex: 0 0 auto; width: 0; height: 0;
    border: 5px solid transparent; border-top-color: #94a3b8; margin-top: 4px;
}
.nss-pop {
    position: absolute; z-index: 60; top: calc(100% + 4px); inset-inline: 0;
    background: #fff; border: 1px solid var(--border, #e2e8f0); border-radius: 10px;
    box-shadow: 0 12px 32px rgba(0,0,0,.16); padding: 8px;
    display: flex; flex-direction: column; max-height: 300px;
}
.nss-pop[hidden] { display: none !important; }   /* الطيّ يتغلّب على display:flex */
.nss-search {
    width: 100%; padding: 8px 12px; border: 1px solid var(--border, #e2e8f0);
    border-radius: 8px; margin-bottom: 6px; font-family: inherit; font-size: 14px; direction: rtl;
}
.nss-search:focus { outline: none; border-color: var(--primary, #0d8a8a); box-shadow: 0 0 0 3px rgba(13,138,138,.12); }
.nss-list { overflow-y: auto; }
.nss-opt { padding: 8px 10px; border-radius: 7px; cursor: pointer; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nss-opt:hover, .nss-opt.active { background: var(--primary-light, #e6f5f5); color: var(--primary, #0d8a8a); }
.nss-opt.sel { font-weight: 700; }
.nss-empty { padding: 12px; color: #94a3b8; text-align: center; font-size: 13px; }
