/* ==========================================================================
   PeopleOS — Design System (Package 23)
   RTL-first. لا build step. متغيرات CSS + Dark Mode عبر [data-theme="dark"].
   ========================================================================== */

:root {
    /* ---- Brand scale (Navy) ---- */
    --navy-900: #0f1a30;
    --navy-800: #16233f;
    --navy-700: #1a2b4a; /* الأساسي الأصلي — محفوظ كما هو */
    --navy-600: #24365c;
    --navy-500: #2c4270;
    --navy-400: #4a5f8c;
    --navy-100: #e7eaf2;
    --navy-50:  #f2f4f9;

    /* ---- Accent scale (Orange) ---- */
    --accent-700: #c25f1f;
    --accent-600: #d76c26;
    --accent-500: #e8792e; /* الأصلي */
    --accent-100: #fce8d8;
    --accent-50:  #fdf3ea;

    /* ---- Semantic ---- */
    --color-success: #1e7d38;
    --color-success-bg: #e6f4ea;
    --color-warning: #b25e02;
    --color-warning-bg: #fdf0e0;
    --color-danger: #c62828;
    --color-danger-bg: #fbe9e8;
    --color-info: #1565c0;
    --color-info-bg: #e6f0fb;

    /* ---- Surface / neutrals (رمادي دافئ) ---- */
    --gray-25:  #fafaf9;
    --gray-50:  #f5f5f3;
    --gray-100: #eeeeeb;
    --gray-200: #e3e3df;
    --gray-300: #cfcfc9;
    --gray-500: #85857c;
    --gray-700: #4a4a44;
    --gray-900: #201f1a;

    /* ---- Role mapping (light) ---- */
    --color-primary: var(--navy-700);
    --color-primary-hover: var(--navy-600);
    --color-accent: var(--accent-500);
    --color-accent-hover: var(--accent-600);
    --color-bg: #ffffff;
    --color-surface: var(--gray-50);
    --color-surface-raised: #ffffff;
    --color-border: var(--gray-200);
    --color-text: var(--gray-900);
    --color-text-muted: var(--gray-500);
    --color-shadow: rgba(15, 26, 48, 0.08);

    /* ---- Spacing ---- */
    --space-1: 4px; --space-2: 8px; --space-3: 12px;
    --space-4: 16px; --space-5: 24px; --space-6: 32px; --space-8: 48px;

    /* ---- Radius / shadow ---- */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --shadow-sm: 0 1px 2px rgba(15, 26, 48, 0.06);
    --shadow-md: 0 4px 16px rgba(15, 26, 48, 0.10);

    --font-sans: 'IBM Plex Sans Arabic', -apple-system, 'Segoe UI', sans-serif;
}

[data-theme="dark"] {
    --color-primary: var(--navy-500);
    --color-primary-hover: var(--navy-400);
    --color-accent: var(--accent-500);
    --color-accent-hover: #f0904f;
    --color-bg: #12161f;
    --color-surface: #0b0e15;
    --color-surface-raised: #1a1f2b;
    --color-border: #2b3242;
    --color-text: #e9eaee;
    --color-text-muted: #9198a8;
    --color-shadow: rgba(0, 0, 0, 0.35);

    --color-success-bg: rgba(30, 125, 56, 0.16);
    --color-warning-bg: rgba(178, 94, 2, 0.18);
    --color-danger-bg: rgba(198, 40, 40, 0.18);
    --color-info-bg: rgba(21, 101, 192, 0.18);
}

* { box-sizing: border-box; }

html { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }

body {
    font-family: var(--font-sans);
    background: var(--color-surface);
    color: var(--color-text);
    margin: 0;
    font-size: 16px;
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
    transition: background-color .15s ease, color .15s ease;
}

a { color: inherit; }

/* ---------------------------------------------------------------------- */
/* Top bar */
/* ---------------------------------------------------------------------- */
.top-bar {
    background: var(--color-primary);
    color: #fff;
    padding: 0 var(--space-5);
    height: 60px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 200;
}
.top-bar a { color: rgba(255,255,255,.88); text-decoration: none; }
.top-bar a:hover { color: #fff; }

.top-bar-brand {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-weight: 700;
    font-size: 1.05rem;
    color: #fff !important;
}
.top-bar-brand svg { flex-shrink: 0; }

.top-bar-nav {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    margin-inline-start: var(--space-6);
}
.top-bar-nav::-webkit-scrollbar { display: none; }
.top-bar-nav a {
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    font-size: 0.92rem;
    font-weight: 500;
    white-space: nowrap;
    transition: background-color .15s ease;
}
.top-bar-nav a:hover { background: rgba(255,255,255,.10); }
.top-bar-nav a.is-active { background: rgba(255,255,255,.16); color: #fff; }

.top-bar-actions { display: flex; align-items: center; gap: var(--space-3); }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    position: relative;
    transition: background-color .15s ease;
}
.icon-btn:hover { background: rgba(255,255,255,.12); }

.notif-dot {
    position: absolute;
    top: 2px;
    inset-inline-end: 2px;
    background: var(--color-accent);
    color: #fff;
    border-radius: 999px;
    min-width: 16px;
    height: 16px;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
    border: 2px solid var(--color-primary);
}

.search-box { position: relative; }
.search-box input {
    padding: var(--space-2) var(--space-3) var(--space-2) var(--space-2);
    padding-inline-start: 34px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    width: 200px;
    height: 38px;
    background: rgba(255,255,255,.14);
    color: #fff;
    font-family: inherit;
    font-size: 0.9rem;
}
.search-box input::placeholder { color: rgba(255,255,255,.65); }
.search-box input:focus { outline: none; background: #fff; color: var(--color-text); }
.search-box input:focus::placeholder { color: var(--color-text-muted); }
.search-box .search-icon {
    position: absolute;
    inset-inline-start: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: rgba(255,255,255,.75);
    pointer-events: none;
}
.search-box input:focus + .search-icon { color: var(--color-text-muted); }

.top-bar-logo { height: 34px; width: auto; display: block; object-fit: contain; }

#searchResults,
.search-results-panel {
    position: absolute;
    top: 46px;
    inset-inline-start: 0;
    width: 280px;
    max-height: 320px;
    overflow-y: auto;
    border-radius: var(--radius-sm);
    background: var(--color-surface-raised);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-md);
    /* أعلى من top-bar (200) وقائمة الموبايل المنسدلة، حتى لا يظهر خلفها أو تحتها */
    z-index: 500;
}
#searchResults a,
.search-results-panel a { color: var(--color-text) !important; }
#searchResults a:hover,
.search-results-panel a:hover { background: var(--color-surface); }

.mobile-nav-toggle { display: none; }

/* ---------------------------------------------------------------------- */
/* Layout */
/* ---------------------------------------------------------------------- */
.container { max-width: 1180px; margin: 0 auto; padding: var(--space-5); }

.card {
    background: var(--color-surface-raised);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    margin-bottom: var(--space-4);
    box-shadow: var(--shadow-sm);
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-5);
    flex-wrap: wrap;
}
.page-header h1 { margin: 0; font-size: 1.4rem; font-weight: 700; }
.page-header p { margin: var(--space-1) 0 0; color: var(--color-text-muted); font-size: 0.92rem; }

/* ---------------------------------------------------------------------- */
/* Buttons */
/* ---------------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-sm);
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    min-height: 44px;
    text-decoration: none;
    font-family: inherit;
    font-size: 0.95rem;
    transition: background-color .15s ease, border-color .15s ease, opacity .15s ease;
}
.btn:active { opacity: .85; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-accent  { background: var(--color-accent); color: #fff; }
.btn-accent:hover { background: var(--color-accent-hover); }
.btn-danger  { background: var(--color-danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }
.btn-outline { background: transparent; color: var(--color-primary); border-color: var(--color-border); }
.btn-outline:hover { background: var(--color-surface); }
.btn-ghost { background: transparent; color: var(--color-text); border-color: transparent; }
.btn-ghost:hover { background: var(--color-surface); }
.btn-sm { min-height: 34px; padding: var(--space-1) var(--space-3); font-size: 0.85rem; }

/* ---------------------------------------------------------------------- */
/* Forms */
/* ---------------------------------------------------------------------- */
.form-group { margin-bottom: var(--space-4); }
.form-group label { display: block; margin-bottom: var(--space-1); font-weight: 600; font-size: 0.92rem; }
.form-group .hint { font-size: 0.8rem; color: var(--color-text-muted); margin-top: var(--space-1); }
.req { color: var(--color-danger); font-weight: 700; }

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    min-height: 44px;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 1rem;
    background: var(--color-surface-raised);
    color: var(--color-text);
    transition: border-color .15s ease, box-shadow .15s ease;
}
.form-group textarea { min-height: 96px; resize: vertical; }
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--navy-100);
}
[data-theme="dark"] .form-group input:focus,
[data-theme="dark"] .form-group select:focus,
[data-theme="dark"] .form-group textarea:focus {
    box-shadow: 0 0 0 3px rgba(74, 95, 140, .35);
}

/* ---------------------------------------------------------------------- */
/* Alerts / badges */
/* ---------------------------------------------------------------------- */
.alert {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-4);
    font-size: 0.92rem;
    border: 1px solid transparent;
}
.alert-success { background: var(--color-success-bg); color: var(--color-success); border-color: color-mix(in srgb, var(--color-success) 25%, transparent); }
.alert-error   { background: var(--color-danger-bg);  color: var(--color-danger);  border-color: color-mix(in srgb, var(--color-danger) 25%, transparent); }

.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px var(--space-2);
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
}
.badge-active     { background: var(--color-success-bg); color: var(--color-success); }
.badge-terminated { background: var(--gray-100); color: var(--color-text-muted); }
.badge-warning    { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-info       { background: var(--color-info-bg); color: var(--color-info); }
.badge-danger     { background: var(--color-danger-bg); color: var(--color-danger); }
[data-theme="dark"] .badge-terminated { background: rgba(255,255,255,.06); }

/* ---------------------------------------------------------------------- */
/* Tables */
/* ---------------------------------------------------------------------- */
table { width: 100%; border-collapse: collapse; }
th, td { padding: var(--space-3); text-align: start; border-bottom: 1px solid var(--color-border); }
th { color: var(--color-text-muted); font-weight: 600; font-size: 0.82rem; text-transform: uppercase; letter-spacing: .02em; }
tbody tr { transition: background-color .12s ease; }
tbody tr:hover { background: var(--color-surface); }

/* ---------------------------------------------------------------------- */
/* Dashboard */
/* ---------------------------------------------------------------------- */
.dash-hero {
    background: linear-gradient(135deg, var(--navy-700) 0%, var(--navy-500) 100%);
    color: #fff;
    border-radius: var(--radius-lg);
    padding: var(--space-6) var(--space-5);
    margin-bottom: var(--space-5);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
    box-shadow: var(--shadow-md);
}
.dash-hero-greeting { font-size: 1.5rem; font-weight: 700; margin: 0 0 var(--space-1); }
.dash-hero-date { color: rgba(255,255,255,.75); font-size: 0.9rem; margin: 0; }
.dash-hero-icon {
    width: 56px; height: 56px;
    border-radius: var(--radius-md);
    background: rgba(255,255,255,.12);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}

.quick-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: var(--space-4);
}
.quick-card {
    background: var(--color-surface-raised);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    text-decoration: none;
    color: var(--color-text);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.quick-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--color-primary);
}
.quick-card-icon {
    width: 40px; height: 40px;
    border-radius: var(--radius-sm);
    background: var(--navy-50);
    color: var(--color-primary);
    display: flex; align-items: center; justify-content: center;
}
[data-theme="dark"] .quick-card-icon { background: rgba(74, 95, 140, .18); }
.quick-card-title { font-weight: 600; font-size: 0.95rem; }
.quick-card-desc { color: var(--color-text-muted); font-size: 0.82rem; margin: 0; }

.section-title {
    font-size: 1rem;
    font-weight: 700;
    margin: var(--space-6) 0 var(--space-3);
}
.section-title:first-child { margin-top: 0; }

.filter-bar {
    display: flex;
    gap: var(--space-3);
    flex-wrap: wrap;
    align-items: end;
}
.filter-bar .form-group { margin: 0; min-width: 160px; flex: 1; }
.filter-bar .form-group.grow-0 { flex: 0 0 auto; min-width: 0; }

.pagination { display: flex; gap: var(--space-1); margin-top: var(--space-4); flex-wrap: wrap; align-items: center; }
.pagination a,
.pagination span.pagination-ellipsis {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 var(--space-2);
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    color: var(--color-text);
    text-decoration: none;
    font-size: 0.88rem;
}
.pagination a:hover { background: var(--color-surface); }
.pagination a.is-active { background: var(--color-primary); border-color: var(--color-primary); color: #fff; font-weight: 700; }
.pagination span.pagination-ellipsis { border-color: transparent; color: var(--color-text-muted); cursor: default; }
.pagination a.pagination-nav { color: var(--color-text-muted); }
.pagination a.pagination-nav.is-disabled { opacity: .4; pointer-events: none; }

.table-empty {
    text-align: center;
    color: var(--color-text-muted);
    padding: var(--space-8) var(--space-4) !important;
}

.row-actions { display: flex; gap: var(--space-3); align-items: center; }
.row-actions a { display: inline-flex; align-items: center; gap: 4px; text-decoration: none; color: var(--color-primary); font-size: 0.88rem; font-weight: 600; }
.row-actions a:hover { text-decoration: underline; }

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 26, 48, 0.55);
    align-items: center;
    justify-content: center;
    z-index: 300;
    padding: var(--space-4);
}
.modal-overlay.is-open { display: flex; }
.modal-box { max-width: 420px; width: 100%; margin: 0; }
.modal-box h3 { margin-top: 0; }
.modal-actions { display: flex; gap: var(--space-2); margin-top: var(--space-4); }

.auth-page {
    min-height: calc(100vh - 60px);
    display: grid;
    grid-template-columns: 1.1fr 1fr;
    /* كسر خارج .container (max-width + padding) للحصول على تخطيط بعرض كامل */
    width: 100vw;
    margin-inline: calc(50% - 50vw);
    margin-top: calc(-1 * var(--space-5));
    margin-bottom: calc(-1 * var(--space-5));
}
.auth-brand-panel {
    background: linear-gradient(160deg, var(--navy-900) 0%, var(--navy-700) 55%, var(--navy-500) 100%);
    color: #fff;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: var(--space-8);
    position: relative;
    overflow: hidden;
}
.auth-brand-panel::before {
    content: '';
    position: absolute;
    width: 480px; height: 480px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(232,121,46,.18) 0%, transparent 70%);
    top: -160px;
    inset-inline-end: -160px;
}
.auth-brand-logo {
    width: 220px;
    height: auto;
    margin-bottom: var(--space-6);
    /* توهّج خفيف يذوّب حواف اللوغو بخلفية Navy بدل ما يبان كمستطيل منفصل */
    filter: drop-shadow(0 0 30px rgba(255,255,255,.18));
    position: relative;
    z-index: 1;
}
.auth-brand-title { font-size: 1.9rem; font-weight: 700; margin: 0 0 var(--space-3); max-width: 380px; line-height: 1.4; position: relative; z-index: 1; }
.auth-brand-sub { color: rgba(255,255,255,.7); font-size: 0.98rem; max-width: 360px; line-height: 1.7; position: relative; z-index: 1; }

.auth-form-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-6);
}
.auth-card {
    width: 100%;
    max-width: 400px;
    padding: var(--space-6) var(--space-6);
    background: var(--color-surface-raised);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.auth-card h1 { font-size: 1.4rem; margin: 0 0 var(--space-1); }
.auth-card .auth-lead { color: var(--color-text-muted); font-size: 0.92rem; margin: 0 0 var(--space-6); }
.auth-card .form-group { margin-bottom: var(--space-5); }
.auth-card .btn { width: 100%; margin-top: var(--space-2); }
.auth-card .auth-footer-link { margin-top: var(--space-5); text-align: center; font-size: 0.9rem; }
.auth-card .auth-footer-link a { color: var(--color-primary); font-weight: 600; text-decoration: none; }
.auth-card .auth-footer-link a:hover { text-decoration: underline; }

.password-field { position: relative; }
.password-field input { padding-inline-end: 42px; }
.password-toggle {
    position: absolute;
    inset-inline-end: 4px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    width: 34px; height: 34px;
    display: flex; align-items: center; justify-content: center;
    border-radius: var(--radius-sm);
}
.password-toggle:hover { background: var(--color-surface); }

@media (max-width: 860px) {
    .auth-page { grid-template-columns: 1fr; }
    .auth-brand-panel { display: none; }
}

.site-footer {
    text-align: center;
    padding: var(--space-5) var(--space-4);
    font-size: 0.78rem;
    color: var(--color-text-muted);
}
.site-footer a {
    color: var(--color-text-muted);
    font-weight: 600;
    text-decoration: none;
    transition: color .2s ease;
}
.site-footer a:hover { color: #c9a227; } /* ذهبي أنيق عند المرور بالماوس */

.form-section {
    margin-bottom: var(--space-6);
    padding-inline-start: var(--space-4);
    border-inline-start: 3px solid var(--section-accent, var(--color-border));
}
.form-section:last-of-type { margin-bottom: var(--space-5); }
.form-section-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
}
.form-section-header-inner {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px; height: 30px;
    border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--section-accent, var(--gray-500)) 16%, transparent);
    color: var(--section-accent, var(--gray-500));
    flex-shrink: 0;
}
.form-section-header h3 { margin: 0; font-size: 1rem; font-weight: 700; }
.form-section-header p { margin: 2px 0 0; font-size: 0.8rem; color: var(--color-text-muted); font-weight: 400; }

.form-section--basic    { --section-accent: var(--navy-700); }
.form-section--job      { --section-accent: var(--accent-500); }
.form-section--personal { --section-accent: var(--color-info); }
.form-section--status   { --section-accent: var(--color-success); }
.form-section--danger   { --section-accent: var(--color-danger); }

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0 var(--space-4);
}
.form-grid .form-group { margin-bottom: var(--space-4); }
.form-grid .form-group.span-2 { grid-column: span 2; }
@media (max-width: 640px) {
    .form-grid .form-group.span-2 { grid-column: span 1; }
}

.danger-zone {
    margin-top: var(--space-6);
    padding: var(--space-4);
    background: var(--color-danger-bg);
    border-radius: var(--radius-md);
    border: 1px solid color-mix(in srgb, var(--color-danger) 25%, transparent);
}
.danger-zone p { margin: 0 0 var(--space-3); font-size: 0.86rem; color: var(--color-danger); }

/* ---------------------------------------------------------------------- */
/* Utility */
/* ---------------------------------------------------------------------- */
.text-muted { color: var(--color-text-muted); }
.mt-0 { margin-top: 0; }

/* ---------------------------------------------------------------------- */
/* Responsive */
/* ---------------------------------------------------------------------- */
@media (max-width: 900px) {
    .top-bar-nav {
        display: none;
        position: absolute;
        top: 60px;
        inset-inline: 0;
        background: var(--color-primary);
        flex-direction: column;
        align-items: stretch;
        padding: var(--space-2);
        box-shadow: var(--shadow-md);
        margin-inline-start: 0;
        max-height: calc(100vh - 60px);
        overflow-y: auto;
    }
    .top-bar-nav.is-open { display: flex; }
    .top-bar-nav a { padding: var(--space-3); }
    .search-box input { width: 140px; }
    .mobile-nav-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 38px;
        height: 38px;
        border-radius: var(--radius-sm);
        background: transparent;
        border: none;
        color: #fff;
        cursor: pointer;
        order: -1;
    }
    .mobile-nav-toggle:hover { background: rgba(255,255,255,.12); }
}

@media (max-width: 768px) {
    .container { padding: var(--space-3); }
    .search-box input { width: 110px; }
    table, thead, tbody, th, td, tr { display: block; }
    thead { display: none; }
    tr { margin-bottom: var(--space-4); border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: var(--space-3); background: var(--color-surface-raised); }
    td { border: none; padding: var(--space-1) 0; }
    td::before { content: attr(data-label); font-weight: 600; display: block; color: var(--color-text-muted); font-size: 0.78rem; }
}
