/*
 * نظام إدارة المخدومين والخدام
 * © 2026 إسلام عبدالله (Eslam Abdullah) — https://eslamabdullah.com
 * جميع الحقوق محفوظة. يُمنع نسخ أو إعادة بيع أو توزيع هذا الكود دون إذن كتابي من المطور.
 */
:root {
    --primary: #1f5f8b;
    --primary-dark: #174a6c;
    --bg: #f3f5f8;
    --surface: #ffffff;
    --text: #1d2733;
    --muted: #6b7785;
    --border: #e1e6ec;
    --success: #1f8a4c;
    --success-bg: #e6f5ec;
    --danger: #c0392b;
    --danger-bg: #fbeaea;
    --info-bg: #eaf2fa;
    --radius: 10px;
    --sidebar-w: 240px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    font-family: 'Cairo', 'Tajawal', Tahoma, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    direction: rtl;
    text-align: right;
    font-size: 15px;
    line-height: 1.7;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0; line-height: 1.4; }

/* ---------- التخطيط ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    background: #16324a;
    color: #fff;
    position: fixed;
    top: 0; bottom: 0; right: 0;
    display: flex;
    flex-direction: column;
    z-index: 30;
    transition: transform .2s ease;
}

.sidebar-brand {
    padding: 20px;
    font-size: 18px;
    font-weight: 700;
    border-bottom: 1px solid rgba(255,255,255,.1);
}

.sidebar-nav { display: flex; flex-direction: column; padding: 12px 10px; gap: 4px; flex: 1; }

.sidebar-nav a {
    color: #d6e2ee;
    padding: 10px 14px;
    border-radius: 8px;
    font-weight: 600;
}
.sidebar-nav a:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.sidebar-nav a.active { background: var(--primary); color: #fff; }
.sidebar-nav a.logout { margin-top: auto; color: #f4b6ae; }

.sidebar-backdrop { display: none; }

.main {
    flex: 1;
    margin-right: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 14px 24px;
    display: flex;
    align-items: center;
    gap: 14px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.page-title { font-size: 20px; font-weight: 700; flex: 1; }

.topbar-user { display: flex; align-items: center; gap: 10px; font-size: 14px; flex-wrap: wrap; }
.user-name { font-weight: 600; }
.role-badge { background: var(--info-bg); color: var(--primary); padding: 2px 10px; border-radius: 20px; font-size: 12px; font-weight: 700; }
.link-muted { color: var(--muted); font-size: 13px; }

.menu-btn {
    display: none;
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px;
    cursor: pointer;
    flex-direction: column;
    gap: 4px;
}
.menu-btn span { display: block; width: 20px; height: 2px; background: var(--text); }

.content { padding: 24px; flex: 1; }

.footer { padding: 16px 24px; color: var(--muted); font-size: 13px; text-align: center; }
.footer a { font-weight: 700; }
.center-page { flex-direction: column; }
.login-footer { margin: 18px 0 0; padding: 0; }

/* ---------- البطاقات ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}
.card-title { font-size: 17px; margin-bottom: 14px; }

.form-card { max-width: 520px; }
.form-card.wide { max-width: 900px; }

.welcome { margin: 0 0 18px; font-size: 16px; }

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 16px;
}
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    border-top: 4px solid var(--primary);
}
.stat-success { border-top-color: var(--success); }
.stat-danger { border-top-color: var(--danger); }
.stat-value { font-size: 30px; font-weight: 700; }
.stat-label { color: var(--muted); font-weight: 600; }

/* ---------- النماذج ---------- */
.field { margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 600; font-size: 14px; }
.req { color: var(--danger); }

input[type=text], input[type=password], input[type=tel], input[type=date],
input[type=search], input[type=file], select, textarea {
    font-family: inherit;
    font-size: 15px;
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(31,95,139,.25); border-color: var(--primary); }
textarea { resize: vertical; }
.readonly { background: #f5f7f9; color: var(--muted); }
.ltr-input { direction: ltr; text-align: right; }
.ltr-num { direction: ltr; unicode-bidi: plaintext; }
.hint { color: var(--muted); font-size: 12.5px; }

.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 18px; }

.form-actions { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; }

.inline-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { margin-bottom: 0; }
.grow { flex: 1; min-width: 200px; }

.current-photo { display: flex; align-items: center; gap: 10px; }

.file-picker {
    display: flex; align-items: center; gap: 10px; cursor: pointer;
    border: 1px dashed var(--border); border-radius: 8px; padding: 8px 10px; background: #fff;
    position: relative;
}
.file-picker input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.file-picker:focus-within { outline: 2px solid rgba(31,95,139,.25); }
.file-name { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- الأزرار ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    padding: 9px 18px;
    border-radius: 8px;
    border: 1px solid var(--primary);
    background: var(--primary);
    color: #fff;
    cursor: pointer;
    white-space: nowrap;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn-light { background: #fff; color: var(--primary); border-color: var(--border); }
.btn-light:hover { background: #f1f5f9; }
.btn-danger { background: #fff; color: var(--danger); border-color: #f0c7c2; }
.btn-danger:hover { background: var(--danger-bg); }
.btn-sm { padding: 4px 12px; font-size: 13px; }
.btn-block { width: 100%; }

/* ---------- التنبيهات ---------- */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-weight: 600; }
.alert-success { background: var(--success-bg); color: var(--success); }
.alert-error { background: var(--danger-bg); color: var(--danger); }
.alert-info { background: var(--info-bg); color: var(--primary); }

/* ---------- الجداول ---------- */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.search-form { display: flex; gap: 8px; flex: 1; max-width: 560px; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; min-width: 560px; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: right; vertical-align: middle; }
.table th { background: #f7f9fb; font-size: 14px; color: var(--muted); font-weight: 700; }
.table tr:hover td { background: #fafbfc; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.actions form { margin: 0; }
.strong-link { font-weight: 700; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 13px; font-weight: 700; }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-muted { background: #eef1f4; color: var(--muted); }

.empty { color: var(--muted); text-align: center; padding: 20px 0; margin: 0; }
.muted { color: var(--muted); margin: 0 0 10px; }

.pagination { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 16px; }

/* ---------- الصور ---------- */
.avatar { border-radius: 50%; object-fit: cover; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.avatar-empty { background: var(--info-bg); color: var(--primary); font-weight: 700; }
.avatar-sm { width: 38px; height: 38px; font-size: 16px; }
.avatar-md { width: 56px; height: 56px; font-size: 22px; }
.avatar-lg { width: 140px; height: 140px; font-size: 52px; }

/* ---------- ملف المخدوم ---------- */
.profile { display: flex; gap: 28px; align-items: flex-start; }
.profile-info { flex: 1; }
.profile-info h2 { font-size: 22px; margin-bottom: 12px; }
.info-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 24px; margin: 0 0 16px; }
.info-list div { display: flex; gap: 8px; border-bottom: 1px dashed var(--border); padding-bottom: 6px; }
.info-list dt { color: var(--muted); font-weight: 600; min-width: 110px; }
.info-list dd { margin: 0; font-weight: 600; }

.note-form { margin-bottom: 18px; }
.notes { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.note { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; background: #fbfcfd; }
.note-text { margin: 0 0 6px; }
.note-meta { display: flex; gap: 16px; color: var(--muted); font-size: 13px; }

/* ---------- الحضور ---------- */
.meeting-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.meeting-head h2 { font-size: 20px; }

.attendance-list { list-style: none; padding: 0; margin: 0; }
.attendance-row {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    padding: 10px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.att-member { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.att-options { display: flex; gap: 8px; }
.att-option { cursor: pointer; }
.att-option input { position: absolute; opacity: 0; pointer-events: none; }
.att-option span {
    display: inline-block; padding: 6px 18px; border: 1px solid var(--border);
    border-radius: 8px; font-weight: 600; background: #fff; user-select: none;
}
.att-option.present input:checked + span { background: var(--success); border-color: var(--success); color: #fff; }
.att-option.absent input:checked + span { background: var(--danger); border-color: var(--danger); color: #fff; }
.att-option input:focus-visible + span { outline: 2px solid var(--primary); }

/* ---------- تسجيل الدخول والرسائل ---------- */
.center-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 400px; padding: 32px; }
.login-title { font-size: 24px; text-align: center; color: var(--primary); }
.login-sub { text-align: center; color: var(--muted); margin: 4px 0 22px; }
.message-card { max-width: 440px; text-align: center; }
.message-card h2 { margin-bottom: 8px; }

/* ---------- التجاوب ---------- */
@media (max-width: 900px) {
    .grid-3 { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(100%); }
    body.sidebar-open .sidebar { transform: translateX(0); }
    body.sidebar-open .sidebar-backdrop {
        display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20;
    }
    .main { margin-right: 0; }
    .menu-btn { display: inline-flex; }
    .topbar { padding: 12px 16px; flex-wrap: wrap; }
    .page-title { font-size: 18px; }
    .topbar-user { width: 100%; font-size: 13px; }
    .content { padding: 16px; }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .profile { flex-direction: column; align-items: center; text-align: center; }
    .profile-info { width: 100%; text-align: right; }
    .profile-info h2 { text-align: center; }
    .info-list { grid-template-columns: 1fr; }
    .search-form { max-width: none; width: 100%; }
    .toolbar > .btn { width: 100%; }
    .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat { padding: 14px; }
    .stat-value { font-size: 24px; }
}
