/* ===== نظام الإدارة — التنسيق ===== */
:root {
    --blue:        #0C63CC;   /* اللون الأساسي */
    --blue-dark:   #06498F;   /* كحلي */
    --blue-bright: #268BF3;   /* أزرق فاتح */
    --tint:        #EDF6FD;   /* خلفية فاتحة */
    --tint-2:      #F3FAFF;
    --white:       #FFFFFF;
    --ink:         #0B2545;   /* النص الأساسي */
    --muted:       #5B7089;   /* نص ثانوي */
    --line:        #DBE7F3;   /* حدود */
    --green:       #16A34A;   /* دخل / تحقق */
    --green-bg:    #E7F6EC;
    --red:         #DC2626;   /* مصروف / حذف */
    --red-bg:      #FDECEC;
    --amber:       #B45309;
    --shadow:      0 2px 8px rgba(6, 73, 143, .08);
    --shadow-lg:   0 10px 40px rgba(6, 73, 143, .18);
    --radius:      14px;
    --font:        "IBM Plex Sans Arabic", "Segoe UI", Tahoma, "Noto Sans Arabic", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font);
    color: var(--ink);
    background: var(--tint-2);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font-family: inherit; font-size: 1rem; }
button { cursor: pointer; }
a { color: inherit; }

/* ---------- تسجيل الدخول ---------- */
.login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: linear-gradient(160deg, var(--tint) 0%, var(--white) 60%);
    padding: 20px;
}
.login-card {
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    padding: 36px 32px;
    width: 100%;
    max-width: 380px;
    text-align: center;
}
.login-logo-wrap {
    width: 100px; height: 100px; margin: 0 auto 8px;
    display: grid; place-items: center;
    background: var(--white); border: 1px solid var(--line);
    border-radius: 22px; box-shadow: var(--shadow); overflow: hidden;
}
.login-logo { width: 100%; height: 100%; object-fit: contain; }
.login-card h1 { margin: 14px 0 2px; font-size: 1.5rem; font-weight: 700; color: var(--blue-dark); letter-spacing: -.01em; }
.login-sub { margin: 0 0 22px; color: var(--muted); }
.login-card label { display: block; text-align: start; margin-bottom: 6px; font-weight: 500; }
.login-card input {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--line);
    border-radius: 10px;
    margin-bottom: 18px;
    background: var(--tint-2);
}
.login-card input:focus { outline: none; border-color: var(--blue-bright); background: var(--white); }
.login-card button {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 10px;
    background: var(--blue);
    color: var(--white);
    font-weight: 700;
    font-size: 1.05rem;
    transition: background .15s;
}
.login-card button:hover { background: var(--blue-dark); }
.login-error {
    background: var(--red-bg);
    color: var(--red);
    border-radius: 10px;
    padding: 10px;
    margin-bottom: 16px;
    font-weight: 500;
}

/* ---------- الشريط العلوي ---------- */
.topbar {
    display: flex;
    align-items: center;
    gap: 18px;
    background: var(--white);
    border-bottom: 1px solid var(--line);
    padding: 10px 20px;
    position: sticky;
    top: 0;
    z-index: 20;
    box-shadow: var(--shadow);
    flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo-badge {
    width: 46px; height: 46px; display: grid; place-items: center;
    background: var(--white); border: 1px solid var(--line);
    border-radius: 12px; box-shadow: var(--shadow); flex: none;
}
.brand-logo { width: 34px; height: 34px; object-fit: contain; }
.brand-name { font-weight: 700; font-size: 1.2rem; color: var(--blue-dark); letter-spacing: -.01em; }
.tabs { display: flex; gap: 6px; margin-inline-start: auto; flex-wrap: wrap; }
.tab {
    border: none;
    background: transparent;
    color: var(--muted);
    font-weight: 700;
    font-size: 1rem;
    padding: 9px 16px;
    border-radius: 10px;
    transition: all .15s;
}
.tab:hover { background: var(--tint); color: var(--blue); }
.tab.is-active { background: var(--blue); color: var(--white); }
.whoami {
    font-weight: 700; font-size: .82rem; color: var(--blue-dark);
    background: var(--tint); border: 1px solid var(--line);
    padding: 6px 12px; border-radius: 999px; direction: ltr; white-space: nowrap;
}
.logout {
    text-decoration: none;
    color: var(--muted);
    font-weight: 500;
    padding: 8px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    transition: all .15s;
}
.logout:hover { border-color: var(--red); color: var(--red); background: var(--red-bg); }

/* ---------- المحتوى ---------- */
.content { max-width: 1100px; width: 100%; margin: 0 auto; padding: 22px 20px 60px; min-width: 0; }
.view { display: none; min-width: 0; }
.view.is-active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}
.section-head h2 { margin: 0; font-size: 1.4rem; color: var(--blue-dark); }
.section-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- الأزرار ---------- */
.btn {
    border: 1px solid var(--line);
    background: var(--white);
    color: var(--ink);
    padding: 9px 16px;
    border-radius: 10px;
    font-weight: 700;
    transition: all .15s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.btn:hover { border-color: var(--blue-bright); color: var(--blue); }
.btn-primary { background: var(--blue); border-color: var(--blue); color: var(--white); }
.btn-primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); color: var(--white); }
.btn-green { background: var(--green); border-color: var(--green); color: var(--white); }
.btn-green:hover { filter: brightness(.94); color: var(--white); }
.btn-danger { background: var(--white); border-color: var(--line); color: var(--red); }
.btn-danger:hover { background: var(--red-bg); border-color: var(--red); }
.btn-sm { padding: 6px 12px; font-size: .9rem; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--tint); color: var(--blue); }

/* ---------- بطاقات الملخص ---------- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}
.stat {
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
}
.stat .label { color: var(--muted); font-weight: 500; font-size: .95rem; }
.stat .value { font-size: 1.7rem; font-weight: 800; margin-top: 4px; }
.stat .cur { font-size: .95rem; font-weight: 500; color: var(--muted); margin-inline-start: 4px; }
.stat.income .value { color: var(--green); }
.stat.expense .value { color: var(--red); }
.stat.net .value { color: var(--blue); }

/* ---------- شريط الفلاتر ---------- */
.filters {
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 18px;
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    box-shadow: var(--shadow);
}
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
    border: 1px solid var(--line);
    background: var(--tint-2);
    color: var(--muted);
    padding: 7px 14px;
    border-radius: 999px;
    font-weight: 700;
    font-size: .9rem;
    transition: all .15s;
}
.chip:hover { border-color: var(--blue-bright); color: var(--blue); }
.chip.is-active { background: var(--blue); border-color: var(--blue); color: var(--white); }
.filters .field { display: flex; align-items: center; gap: 6px; }
.filters label { color: var(--muted); font-size: .9rem; font-weight: 500; }
.filters input, .filters select {
    border: 1.5px solid var(--line);
    border-radius: 9px;
    padding: 8px 10px;
    background: var(--tint-2);
}
.filters input:focus, .filters select:focus { outline: none; border-color: var(--blue-bright); background: var(--white); }
.filters .spacer { margin-inline-start: auto; }

/* ---------- الجداول / القوائم ---------- */
.table-wrap { overflow-x: auto; max-width: 100%; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; min-width: 640px; }
thead th {
    text-align: start;
    background: var(--tint);
    color: var(--blue-dark);
    font-weight: 700;
    padding: 12px 14px;
    font-size: .92rem;
    white-space: nowrap;
}
tbody td { padding: 12px 14px; border-top: 1px solid var(--line); vertical-align: middle; }
tbody tr:hover { background: var(--tint-2); }
.num { font-variant-numeric: tabular-nums; font-weight: 700; }
.income-amt { color: var(--green); }
.expense-amt { color: var(--red); }
.row-actions { display: flex; gap: 4px; white-space: nowrap; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .82rem; font-weight: 700; }
.badge-role { background: var(--tint); color: var(--blue-dark); }
.badge-yes { background: var(--green-bg); color: var(--green); }
.badge-no { background: var(--tint); color: var(--muted); }
.badge-expense { background: var(--red-bg); color: var(--red); }
.badge-salary { background: #FFF3E0; color: var(--amber); }

.pill-time { background: var(--tint); color: var(--blue-dark); padding: 3px 9px; border-radius: 8px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* حالة الموعد */
.status-sel {
    border: 1px solid var(--line); border-radius: 8px;
    padding: 5px 8px; font-weight: 700; font-size: .85rem; font-family: inherit;
    background: var(--tint); color: var(--muted); cursor: pointer;
}
.status-sel.st-done { background: var(--green-bg); color: var(--green); border-color: var(--green-bg); }
.status-sel.st-canceled { background: var(--red-bg); color: var(--red); border-color: var(--red-bg); }
.status-sel.st-pending { background: var(--tint); color: var(--muted); }
tr.bk-canceled > td:not(:last-child) { opacity: .5; }
tr.bk-canceled .pill-time { text-decoration: line-through; }
.wa-link {
    display: inline-flex; align-items: center; gap: 5px;
    color: var(--green); font-weight: 700; text-decoration: none;
    background: var(--green-bg); padding: 5px 11px; border-radius: 8px;
    direction: ltr;
}
.wa-link:hover { filter: brightness(.95); }
.muted { color: var(--muted); }

/* حالة فارغة */
.empty {
    text-align: center;
    padding: 50px 20px;
    color: var(--muted);
    background: var(--white);
    border: 1px dashed var(--line);
    border-radius: var(--radius);
}
.empty .big { font-size: 2.4rem; margin-bottom: 6px; }

/* عناوين تجميع المواعيد حسب اليوم */
.day-group { margin-bottom: 22px; }
.day-head {
    display: flex; align-items: baseline; gap: 8px;
    margin: 0 0 8px; padding-bottom: 6px;
    border-bottom: 2px solid var(--tint);
    color: var(--blue-dark); font-weight: 800; font-size: 1.05rem;
}
.day-head .count { color: var(--muted); font-size: .85rem; font-weight: 500; }

/* ---------- النوافذ المنبثقة ---------- */
.modal-root {
    position: fixed; inset: 0; z-index: 50;
    background: rgba(11, 37, 69, .45);
    display: grid; place-items: center; padding: 20px;
    animation: fade .15s ease;
}
.modal {
    background: var(--white);
    border-radius: 18px;
    box-shadow: var(--shadow-lg);
    width: 100%; max-width: 480px;
    max-height: 90vh; overflow-y: auto;
}
.modal-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 22px; border-bottom: 1px solid var(--line);
    position: sticky; top: 0; background: var(--white);
}
.modal-head h3 { margin: 0; color: var(--blue-dark); font-size: 1.2rem; }
.modal-close { border: none; background: transparent; font-size: 1.5rem; color: var(--muted); line-height: 1; padding: 0 4px; }
.modal-close:hover { color: var(--red); }
.modal-body { padding: 20px 22px; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-start; }

.form-row { margin-bottom: 15px; }
.form-row.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row label { display: block; margin-bottom: 6px; font-weight: 700; font-size: .93rem; }
.form-row input, .form-row select, .form-row textarea {
    width: 100%; padding: 11px 13px;
    border: 1.5px solid var(--line); border-radius: 10px;
    background: var(--tint-2);
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus {
    outline: none; border-color: var(--blue-bright); background: var(--white);
}
.form-row textarea { resize: vertical; min-height: 70px; }
.check-row { display: flex; align-items: center; gap: 8px; }
.check-row input { width: auto; }
.hint { color: var(--muted); font-size: .85rem; margin-top: 5px; }

/* التنبيه العائم */
.toast {
    position: fixed; inset-block-end: 24px; inset-inline-start: 50%;
    transform: translateX(50%);
    background: var(--blue-dark); color: var(--white);
    padding: 12px 22px; border-radius: 12px;
    box-shadow: var(--shadow-lg); font-weight: 700; z-index: 80;
    animation: fade .2s ease;
}
.toast.err { background: var(--red); }
.toast.ok { background: var(--green); }

/* تذييل الصفحة */
.app-body { display: flex; flex-direction: column; min-height: 100vh; }
.content { flex: 1 0 auto; }
.site-foot {
    flex: none; text-align: center; color: var(--muted); font-size: .85rem;
    padding: 16px; border-top: 1px solid var(--line); background: var(--white);
    display: flex; gap: 8px; justify-content: center; align-items: center;
}
.site-foot .dot { opacity: .5; }

/* أيقونة الحالة الفارغة */
.empty svg { width: 44px; height: 44px; color: var(--blue-bright); opacity: .65; margin-bottom: 10px; }

/* نموذج فرعي: عميل جديد داخل نموذج الدخل */
.subform { border: 1px dashed var(--line); border-radius: 10px; padding: 12px 12px 2px; background: var(--tint-2); }

/* أيقونة واتساب داخل الرابط */
.wa-link svg { width: 15px; height: 15px; }

/* إخفاء شريط التمرير في التبويبات عند الحاجة */
.tabs::-webkit-scrollbar { height: 0; }
.tabs { scrollbar-width: none; }

/* ------- الأجهزة اللوحية والجوالات ------- */
@media (max-width: 768px) {
    .topbar { gap: 8px 12px; padding: 10px 14px; }
    .tabs {
        order: 3; flex-basis: 100%; margin-inline-start: 0;
        flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px;
    }
    .tab { white-space: nowrap; flex: none; }
    .logout { margin-inline-start: auto; }
    .brand-name { font-size: 1.08rem; }
    .content { padding: 16px 12px 40px; }

    .section-head { align-items: stretch; }
    .section-actions { width: 100%; }
    .section-actions .btn { flex: 1 1 auto; justify-content: center; }
    .section-actions .field { flex: 1 1 100%; }
    .section-actions .field input { width: 100%; }

    .form-row.two { grid-template-columns: 1fr; }

    .filters { padding: 12px; }
    .filters .spacer { margin-inline-start: 0; width: 100%; height: 0; }
    .filters .field { flex: 1 1 auto; }
    .filters .field input, .filters .field select { width: 100%; }

    .modal { max-width: 100%; }
    .modal-foot { flex-wrap: wrap; }
    .modal-foot .btn { flex: 1 1 auto; justify-content: center; }
}

/* ------- الجوالات الصغيرة ------- */
@media (max-width: 480px) {
    .brand-logo { width: 30px; height: 30px; }
    .logo-badge { width: 42px; height: 42px; }
    .section-head h2 { font-size: 1.2rem; }
    .chips { width: 100%; }
    .chip { flex: 1 1 auto; text-align: center; }
    .stat .value { font-size: 1.45rem; }
    .row-actions { flex-wrap: wrap; }
}
