/* =====================================================================
   نظام إدارة العملاء - مؤسسة طوق نجاة للتنمية
   الألوان مشتقة من هوية اللوجو: أزرق أساسي + أخضر وبرتقالي لمسات
   ===================================================================== */
@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700;800&display=swap');

:root {
    --blue:        #1256a0;
    --blue-light:  #1b74c9;
    --blue-dark:   #0d3f78;
    --green:       #2e9e4a;
    --orange:      #ef8a1e;

    --ink:    #1e2a38;
    --muted:  #6b7787;
    --bg:     #eef2f7;
    --card:   #ffffff;
    --border: #dde4ec;
    --line:   #eef2f7;

    --shadow: 0 1px 3px rgba(16,42,76,.06), 0 6px 18px rgba(16,42,76,.05);
    --radius: 12px;
    --sidebar-w: 256px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 15px;
    line-height: 1.7;
}

a { color: var(--blue); text-decoration: none; }
a:hover { color: var(--blue-dark); }

/* --------------------------- صفحة الدخول --------------------------- */
.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    background: #ffffff;
}
.auth-card {
    background: var(--card);
    width: 100%;
    max-width: 400px;
    border-radius: 16px;
    padding: 36px 32px;
    border: 1px solid var(--border);
    box-shadow: 0 10px 40px rgba(16,42,76,.12);
    text-align: center;
}
.auth-logo { max-width: 160px; height: auto; margin-bottom: 8px; }
.auth-card h1 { font-size: 22px; margin: 8px 0 20px; color: var(--blue-dark); }
.auth-hint { color: var(--muted); font-size: 14px; margin: -8px 0 20px; }

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

.sidebar {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: var(--sidebar-w);
    background: linear-gradient(180deg, var(--blue-dark), var(--blue));
    color: #fff;
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform .25s ease;
}
.sidebar-brand {
    padding: 22px 20px;
    text-align: center;
    border-bottom: 1px solid rgba(255,255,255,.12);
}
.sidebar-brand img { max-width: 120px; height: auto; background: #fff; border-radius: 10px; padding: 8px; }
.sidebar-brand .org { display: block; margin-top: 10px; font-size: 14px; font-weight: 600; opacity: .95; }

.nav { padding: 14px 12px; flex: 1; overflow-y: auto; }
.nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #dbe7f5;
    padding: 11px 14px;
    border-radius: 10px;
    font-weight: 500;
    margin-bottom: 4px;
    transition: background .15s, color .15s;
}
.nav a .ico { width: 20px; text-align: center; font-size: 17px; }
.nav a:hover { background: rgba(255,255,255,.10); color: #fff; }
.nav a.active { background: #fff; color: var(--blue-dark); font-weight: 700; }

.sidebar-foot { padding: 14px; border-top: 1px solid rgba(255,255,255,.12); font-size: 13px; }
.sidebar-foot .who { opacity: .9; margin-bottom: 8px; }

.main { margin-right: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 14px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky; top: 0; z-index: 50;
}
.topbar h1 { font-size: 19px; margin: 0; }
.menu-btn { display: none; background: none; border: 0; font-size: 24px; color: var(--ink); cursor: pointer; }

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

/* --------------------------- المكوّنات --------------------------- */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}
.card-head {
    padding: 16px 20px;
    border-bottom: 1px solid var(--line);
    display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px;
}
.card-head h2 { font-size: 17px; margin: 0; }
.card-body { padding: 20px; }

/* بطاقات الإحصائيات */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}
.stat::after { content: ''; position: absolute; inset-inline-start: 0; top: 0; bottom: 0; width: 5px; }
.stat.b::after { background: var(--blue); }
.stat.g::after { background: var(--green); }
.stat.o::after { background: var(--orange); }
.stat .label { color: var(--muted); font-size: 14px; }
.stat .value { font-size: 26px; font-weight: 800; color: var(--ink); margin-top: 4px; }
.stat .value small { font-size: 14px; font-weight: 600; color: var(--muted); }

/* الجداول */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14.5px; }
table.data th, table.data td { padding: 12px 14px; text-align: right; border-bottom: 1px solid var(--line); }
table.data th { background: #f7f9fc; color: var(--muted); font-weight: 700; white-space: nowrap; }
table.data tr:hover td { background: #fafcff; }
table.data td.actions { white-space: nowrap; }

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

/* الأزرار */
.btn {
    display: inline-flex; align-items: center; gap: 7px;
    border: 1px solid transparent;
    border-radius: 9px;
    padding: 9px 16px;
    font-family: inherit; font-size: 14.5px; font-weight: 600;
    cursor: pointer; text-decoration: none;
    transition: filter .15s, background .15s;
}
.btn:hover { filter: brightness(.95); }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { color: #fff; }
.btn-green { background: var(--green); color: #fff; }
.btn-green:hover { color: #fff; }
.btn-outline { background: #fff; color: var(--blue); border-color: var(--border); }
.btn-danger { background: #fff; color: #c0392b; border-color: #f0c6c1; }
.btn-danger:hover { background: #c0392b; color: #fff; }
.btn-sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; justify-content: center; }

/* النماذج */
.field { margin-bottom: 16px; text-align: right; }
.field label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 14px; }
.field input, .field select, .field textarea {
    width: 100%;
    font-family: inherit; font-size: 15px;
    padding: 10px 13px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: #fff; color: var(--ink);
    transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none;
    border-color: var(--blue-light);
    box-shadow: 0 0 0 3px rgba(27,116,201,.15);
}
.field textarea { resize: vertical; min-height: 90px; }
.field .hint { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.form-actions { display: flex; gap: 10px; margin-top: 8px; }

/* التنبيهات */
.alert { border-radius: 10px; padding: 13px 16px; margin-bottom: 18px; font-size: 14.5px; text-align: right; }
.alert-success { background: #e7f6ec; color: #1e6b34; border: 1px solid #bfe5cb; }
.alert-error   { background: #fdeceb; color: #a02b1e; border: 1px solid #f3c9c4; }
.alert-info    { background: #e9f2fb; color: #1256a0; border: 1px solid #c5ddf4; }

/* الشارات (Badges) */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12.5px; font-weight: 600; }
.badge-blue  { background: #e5eefa; color: var(--blue); }
.badge-green { background: #e6f5ea; color: var(--green); }
.badge-orange{ background: #fdf0e0; color: #b96a0e; }
.badge-gray  { background: #eef1f5; color: var(--muted); }

/* شريط أدوات البحث */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; }
.toolbar .search { flex: 1; min-width: 220px; }
.toolbar .search input { margin: 0; }

/* صفحة تفاصيل العميل */
.profile-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; align-items: start; }
.info-list { list-style: none; padding: 0; margin: 0; }
.info-list li { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--line); gap: 12px; }
.info-list li:last-child { border-bottom: 0; }
.info-list .k { color: var(--muted); }
.info-list .v { font-weight: 600; text-align: left; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 12px 0; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border-bottom: 0; }
.timeline .meta { color: var(--muted); font-size: 13px; margin-top: 3px; }

/* ===================================================================
   الإيصال (يظهر على الشاشة وعند الطباعة)
   =================================================================== */
.receipt-page { background: var(--bg); padding: 24px; }
.receipt {
    background: #fff;
    max-width: 800px;
    margin: 0 auto;
    padding: 40px 44px;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
    position: relative;
}
.receipt-header { display: flex; align-items: center; gap: 20px; border-bottom: 3px solid var(--blue); padding-bottom: 18px; }
.receipt-header img { max-width: 130px; height: auto; }
.receipt-header .org-info h2 { margin: 0 0 4px; color: var(--blue-dark); font-size: 22px; }
.receipt-header .org-info .sub { color: var(--muted); font-size: 13px; }

.receipt-title { text-align: center; margin: 22px 0 8px; }
.receipt-title h3 { display: inline-block; font-size: 20px; color: var(--green); border: 2px solid var(--green); border-radius: 30px; padding: 6px 26px; margin: 0; }

.receipt-no { text-align: center; color: var(--muted); margin-bottom: 22px; font-size: 14px; }
.receipt-no strong { color: var(--ink); }

.receipt-rows { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
.receipt-rows td { padding: 11px 6px; border-bottom: 1px dashed var(--border); font-size: 15px; }
.receipt-rows td.lbl { color: var(--muted); width: 160px; }
.receipt-rows td.val { font-weight: 700; }

.receipt-amount {
    background: #f4f8fc;
    border: 1px solid #d6e4f3;
    border-radius: 10px;
    padding: 16px 20px;
    margin-bottom: 8px;
    display: flex; justify-content: space-between; align-items: center;
}
.receipt-amount .big { font-size: 26px; font-weight: 800; color: var(--blue-dark); }
.receipt-tafqeet { background: #fbfdff; border: 1px dashed #c9dcf0; border-radius: 10px; padding: 12px 18px; margin-bottom: 26px; font-weight: 600; }
.receipt-tafqeet .k { color: var(--muted); font-weight: 500; margin-inline-end: 6px; }

.receipt-signs { display: flex; justify-content: space-between; margin-top: 40px; }
.receipt-signs .sign { text-align: center; width: 45%; color: var(--muted); }
.receipt-signs .sign .line { border-top: 1px solid var(--ink); margin-top: 44px; padding-top: 6px; }

.receipt-footer { text-align: center; color: var(--muted); font-size: 12.5px; margin-top: 30px; border-top: 1px solid var(--line); padding-top: 14px; }

.print-actions { max-width: 800px; margin: 0 auto 16px; display: flex; gap: 10px; justify-content: flex-end; }

/* --------------------------- الاستجابة للموبايل --------------------------- */
.overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 90; }

@media (max-width: 880px) {
    .sidebar { transform: translateX(100%); }
    .sidebar.open { transform: translateX(0); }
    .main { margin-right: 0; }
    .menu-btn { display: block; }
    .overlay.show { display: block; }
    .profile-grid { grid-template-columns: 1fr; }
    .grid-2 { grid-template-columns: 1fr; }
}

/* --------------------------- الطباعة --------------------------- */
@media print {
    body { background: #fff; }
    .sidebar, .topbar, .print-actions, .no-print { display: none !important; }
    .main { margin: 0; }
    .content, .receipt-page { padding: 0; }
    .receipt { box-shadow: none; border: 0; max-width: 100%; padding: 10px 0; }
    @page { size: A4; margin: 16mm; }
}
