/* ============================================================
   CRM Control Panel — Arabic RTL design system
   ============================================================ */
@font-face {
    font-family: 'Cairo';
    src: url('../fonts/Cairo-Variable.ttf') format('truetype');
    font-weight: 100 900;
    font-display: swap;
}

:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #eef2ff;
    --primary-soft: #e0e7ff;
    --success: #059669;
    --success-light: #ecfdf5;
    --warning: #d97706;
    --warning-light: #fffbeb;
    --danger: #dc2626;
    --danger-light: #fef2f2;
    --info: #0284c7;
    --info-light: #f0f9ff;
    --purple: #7c3aed;
    --purple-light: #f5f3ff;
    --ink: #0f172a;
    --body: #475569;
    --muted: #94a3b8;
    --border: #e2e8f0;
    --bg: #f4f6fb;
    --card: #ffffff;
    --sidebar-bg: #141922;
    --sidebar-text: #94a3b8;
    --sidebar-active: #4f46e5;
    --radius: 14px;
    --radius-sm: 9px;
    --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .05);
    --shadow-lg: 0 10px 40px rgba(15, 23, 42, .14);
    --font: 'Cairo', 'Segoe UI', Tahoma, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--body);
    line-height: 1.65;
    direction: rtl;
}

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

h1, h2, h3, h4, h5 { color: var(--ink); font-weight: 700; line-height: 1.4; }

img { max-width: 100%; }

::selection { background: var(--primary-soft); }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ============================================================ Layout */
.app { display: flex; min-height: 100vh; }

.sidebar {
    width: 256px; flex-shrink: 0;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    position: fixed; inset-block: 0; inset-inline-start: 0;
    display: flex; flex-direction: column;
    z-index: 60;
    transition: width .22s ease, transform .22s ease;
}

.main {
    flex: 1; min-width: 0;
    margin-inline-start: 256px;
    display: flex; flex-direction: column;
    transition: margin-inline-start .22s ease;
}

.sidebar-logo {
    display: flex; align-items: center; gap: 10px;
    padding: 18px 18px 14px;
    color: #fff !important;
}
.sidebar-logo .logo-ic {
    width: 38px; height: 38px; border-radius: 11px;
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    display: grid; place-items: center; font-size: 19px; flex-shrink: 0; overflow: hidden;
}
.sidebar-logo .logo-ic img { width: 100%; height: 100%; object-fit: contain; }
.sidebar-logo .logo-txt { font-weight: 700; font-size: 14.5px; white-space: nowrap; overflow: hidden; }
.sidebar-logo .logo-txt small { display: block; font-size: 10.5px; color: #64748b; font-weight: 600; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 6px 12px 20px; }

.nav-group { margin: 16px 6px 4px; }
.nav-group-title {
    font-size: 10.5px; font-weight: 700; color: #526078;
    padding: 0 10px; margin-bottom: 6px;
    letter-spacing: .4px; text-transform: uppercase;
    white-space: nowrap; overflow: hidden;
}
.nav-item {
    display: flex; align-items: center; gap: 11px;
    padding: 9px 12px; margin: 2px 0;
    border-radius: 10px;
    color: var(--sidebar-text);
    font-size: 13.5px; font-weight: 600;
    transition: background .15s, color .15s;
    white-space: nowrap;
    position: relative;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #e2e8f0; }
.nav-item.active {
    background: linear-gradient(135deg, var(--primary), #6d28d9);
    color: #fff;
    box-shadow: 0 4px 14px rgba(79, 70, 229, .35);
}
.nav-item .ni-ic { font-size: 16px; width: 22px; text-align: center; flex-shrink: 0; }
.nav-item .ni-badge {
    margin-inline-start: auto;
    background: var(--danger); color: #fff;
    font-size: 10.5px; font-weight: 700;
    border-radius: 20px; padding: 1px 7px;
}
.nav-item .chev { margin-inline-start: auto; font-size: 11px; opacity: .7; }

.sidebar-foot { padding: 12px 14px; border-top: 1px solid rgba(255,255,255,.07); }
.sidebar-foot small { color: #526078; }

/* Collapsed sidebar */
.sidebar.collapsed { width: 76px; }
.sidebar.collapsed .logo-txt, .sidebar.collapsed .nav-item > span:not(.ni-ic),
.sidebar.collapsed .nav-group-title, .sidebar.collapsed .sidebar-foot { display: none; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 10px; }
.sidebar.collapsed .nav-item .ni-badge { position: absolute; top: 4px; inset-inline-start: 38px; font-size: 9px; padding: 0 5px; }
.sidebar.collapsed .sidebar-logo { justify-content: center; padding-inline: 0; }
.main.wide { margin-inline-start: 76px; }

/* ============================================================ Topbar */
.topbar {
    background: rgba(255,255,255,.9);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
    padding: 0 26px;
    height: 64px;
    display: flex; align-items: center; gap: 14px;
    position: sticky; top: 0; z-index: 50;
}
.topbar .tb-title { font-size: 15.5px; font-weight: 700; color: var(--ink); }
.topbar .tb-sub { font-size: 12px; color: var(--muted); }

.icon-btn {
    width: 38px; height: 38px; border-radius: 10px;
    border: 1px solid var(--border); background: #fff; color: var(--body);
    display: grid; place-items: center; cursor: pointer;
    font-size: 16px; position: relative;
    transition: all .15s;
}

.svg-icon { width: 1.15em; height: 1.15em; display: inline-block; flex: 0 0 auto; vertical-align: -0.18em; }
.ni-ic .svg-icon, .stat-ic .svg-icon, .es-ic .svg-icon, .notif-ic .svg-icon { width: 1.25em; height: 1.25em; vertical-align: -0.22em; }
.act-btn .svg-icon { width: 1.05em; height: 1.05em; }
.icon-btn:hover { background: var(--primary-light); color: var(--primary); border-color: var(--primary-soft); }
.icon-btn .dot {
    position: absolute; top: 6px; inset-inline-start: 7px;
    width: 9px; height: 9px; border-radius: 50%;
    background: var(--danger); border: 2px solid #fff;
}

/* ============================================================ Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    border: 1px solid transparent; border-radius: 10px;
    padding: 8px 16px; font-size: 13px; font-weight: 700;
    font-family: var(--font); cursor: pointer;
    transition: all .15s; white-space: nowrap;
    line-height: 1.5;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #047857; color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; color: #fff; }
.btn-ghost { background: transparent; color: var(--body); border-color: var(--border); }
.btn-ghost:hover { background: #f1f5f9; }
.btn-soft { background: var(--primary-light); color: var(--primary); }
.btn-soft:hover { background: var(--primary-soft); }
.btn-sm { padding: 5px 11px; font-size: 12px; border-radius: 8px; }
.btn-lg { padding: 11px 22px; font-size: 14.5px; }
.btn-block { width: 100%; }
.btn-whatsapp { background: #22c55e; color: #fff; }
.btn-whatsapp:hover { background: #16a34a; color: #fff; }

/* ============================================================ Cards */
.card {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-hd {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 15px 20px; border-bottom: 1px solid var(--border);
}
.card-hd h3 { font-size: 14px; }
.card-bd { padding: 20px; }
.card-ft { padding: 14px 20px; border-top: 1px solid var(--border); }

/* Stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 22px; }
.stat-col { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stat-card {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px 18px; display: flex; gap: 14px; align-items: center;
    box-shadow: var(--shadow); transition: transform .15s;
}
.stat-card:hover { transform: translateY(-2px); }
.stat-ic {
    width: 48px; height: 48px; border-radius: 13px; flex-shrink: 0;
    display: grid; place-items: center; font-size: 21px;
}
.stat-ic.si-primary { background: var(--primary-light); color: var(--primary); }
.stat-ic.si-success { background: var(--success-light); color: var(--success); }
.stat-ic.si-warning { background: var(--warning-light); color: var(--warning); }
.stat-ic.si-danger  { background: var(--danger-light);  color: var(--danger); }
.stat-ic.si-info    { background: var(--info-light);    color: var(--info); }
.stat-ic.si-purple  { background: var(--purple-light);  color: var(--purple); }
.stat-val { font-size: 20px; font-weight: 800; color: var(--ink); line-height: 1.3; }
.stat-lbl { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat-foot { font-size: 11px; color: var(--muted); margin-top: 2px; }
.stat-foot b { color: var(--success); }
.stat-foot b.danger { color: var(--danger); }

/* ============================================================ Badges */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 11px; font-weight: 700;
    padding: 3px 10px; border-radius: 20px;
    white-space: nowrap;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { background: var(--success-light); color: var(--success); }
.badge-danger  { background: var(--danger-light);  color: var(--danger); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-info    { background: var(--info-light);    color: var(--info); }
.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-secondary { background: #f1f5f9; color: #64748b; }
.badge-purple  { background: var(--purple-light);  color: var(--purple); }

.avatar {
    width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    color: #fff; display: grid; place-items: center;
    font-weight: 700; font-size: 14px;
}
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }

/* ============================================================ Tables */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table thead th {
    text-align: start; font-size: 11.5px; font-weight: 700; color: var(--muted);
    padding: 11px 16px; border-bottom: 1.5px solid var(--border);
    background: #fafbfe; white-space: nowrap;
}
.table tbody td {
    padding: 12px 16px; border-bottom: 1px solid var(--border);
    vertical-align: middle; color: var(--body);
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: #f8fafc; }
.table .cell-main { font-weight: 700; color: var(--ink); }
.table .cell-sub { font-size: 11.5px; color: var(--muted); }

/* Row actions */
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.act-btn {
    width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border);
    background: #fff; color: var(--body); cursor: pointer;
    display: grid; place-items: center; font-size: 14px; transition: all .14s;
}
.act-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.act-btn.danger:hover { border-color: var(--danger); color: var(--danger); background: var(--danger-light); }
.act-btn.success:hover { border-color: var(--success); color: var(--success); background: var(--success-light); }
.act-btn.warning:hover { border-color: var(--warning); color: var(--warning); background: var(--warning-light); }

/* ============================================================ Forms */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px 20px; }
.form-grid .full { grid-column: 1 / -1; }
.form-group label { display: block; font-size: 12.5px; font-weight: 700; color: var(--ink); margin-bottom: 6px; }
.form-group label .req { color: var(--danger); }
.label-hint { font-size: 11px; color: var(--muted); font-weight: 500; }

.input, .select, textarea.input {
    width: 100%; border: 1.5px solid var(--border); border-radius: 10px;
    padding: 9px 13px; font-size: 13.5px; font-family: var(--font);
    background: #fff; color: var(--ink); transition: border .15s, box-shadow .15s;
    outline: none; direction: inherit;
}
.input:focus, .select:focus, textarea.input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3.5px var(--primary-soft);
}
.input.is-invalid, .select.is-invalid, textarea.input.is-invalid {
    border-color: var(--danger);
    box-shadow: 0 0 0 3.5px var(--danger-light);
}
.input:disabled { background: #f8fafc; color: var(--muted); }
textarea.input { min-height: 92px; resize: vertical; }
select.select { appearance: auto; }
.field-error { font-size: 11.5px; color: var(--danger); font-weight: 600; margin-top: 4px; }
.form-hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.checkbox-line { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--body); cursor: pointer; }
.checkbox-line input { accent-color: var(--primary); width: 16px; height: 16px; }

/* ============================================================ Page head & filters */
.page-head {
    display: flex; align-items: center; justify-content: space-between; gap: 14px;
    margin-bottom: 20px; flex-wrap: wrap;
}
.page-head h1 { font-size: 20px; }
.page-head .ph-sub { color: var(--muted); font-size: 12.5px; }

.filter-bar {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 14px 18px; margin-bottom: 18px; box-shadow: var(--shadow);
    display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end;
}
.filter-bar .form-group { min-width: 150px; flex: 1; }
.filter-bar .form-group:has(input[type=text]) { flex: 2; min-width: 220px; }
.filter-bar .actions-row { display: flex; gap: 8px; align-items: center; }

/* ============================================================ Dropdowns */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
    position: absolute; top: calc(100% + 6px); inset-inline-end: 0;
    background: #fff; border: 1px solid var(--border); border-radius: 12px;
    box-shadow: var(--shadow-lg); min-width: 210px; padding: 6px;
    z-index: 90; opacity: 0; visibility: hidden;
    transform: translateY(-4px); transition: all .16s;
}
.dropdown.open .dropdown-menu { opacity: 1; visibility: visible; transform: translateY(0); }
.dropdown-item {
    display: flex; align-items: center; gap: 9px;
    padding: 8px 12px; border-radius: 8px;
    font-size: 13px; font-weight: 600; color: var(--body);
    width: 100%; background: none; border: 0; cursor: pointer; text-align: start;
    font-family: var(--font);
}
.dropdown-item:hover { background: var(--primary-light); color: var(--primary); }
.dropdown-item.danger:hover { background: var(--danger-light); color: var(--danger); }
.dropdown-sep { height: 1px; background: var(--border); margin: 5px 8px; }
.dropdown-hd { padding: 7px 12px 4px; font-size: 11px; font-weight: 800; color: var(--muted); }

/* ============================================================ Modal & drawer */
.overlay {
    position: fixed; inset: 0; background: rgba(15, 23, 42, .55);
    z-index: 100; opacity: 0; visibility: hidden;
    transition: all .18s; backdrop-filter: blur(2px);
}
.overlay.show { opacity: 1; visibility: visible; }

.modal {
    position: fixed; z-index: 110; top: 50%; inset-inline-start: 50%;
    transform: translate(-50%, -46%) scale(.97);
    background: #fff; border-radius: 16px; width: 92%; max-width: 520px;
    box-shadow: var(--shadow-lg); opacity: 0; visibility: hidden;
    transition: all .18s; max-height: 88vh; display: flex; flex-direction: column;
}
.modal.show { opacity: 1; visibility: visible; transform: translate(-50%, -50%) scale(1); }
.modal-hd { padding: 17px 22px 0; font-size: 16px; font-weight: 800; color: var(--ink); display: flex; justify-content: space-between; align-items: center; }
.modal-bd { padding: 16px 22px; overflow-y: auto; font-size: 13.5px; }
.modal-ft { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }
.modal-close { background: none; border: 0; font-size: 19px; color: var(--muted); cursor: pointer; line-height: 1; }

.drawer {
    position: fixed; z-index: 110; top: 0; bottom: 0; inset-inline-start: 0;
    width: 400px; max-width: 92vw; background: #fff;
    box-shadow: var(--shadow-lg); transform: translateX(100%);
    transition: transform .22s ease; display: flex; flex-direction: column;
    direction: rtl;
}
.drawer.open { transform: translateX(0); }
.drawer-hd { padding: 17px 22px; border-bottom: 1px solid var(--border); font-weight: 800; color: var(--ink); display: flex; justify-content: space-between; }
.drawer-bd { padding: 18px 22px; overflow-y: auto; flex: 1; }
.drawer-ft { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; gap: 10px; }

/* ============================================================ Tabs */
.tabs { display: flex; border-bottom: 1.5px solid var(--border); overflow-x: auto; gap: 4px; margin-bottom: 20px; }
.tab {
    padding: 10px 16px; font-size: 13px; font-weight: 700; color: var(--muted);
    border: 0; background: none; cursor: pointer; font-family: var(--font);
    border-bottom: 2.5px solid transparent; margin-bottom: -1.5px;
    white-space: nowrap; display: inline-flex; align-items: center; gap: 7px;
}
.tab:hover { color: var(--primary); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab .cnt { background: var(--primary-soft); color: var(--primary); font-size: 11px; font-weight: 800; border-radius: 20px; padding: 0 7px; }

/* ============================================================ Alerts / toasts */
.alert {
    display: flex; gap: 10px; align-items: flex-start;
    padding: 12px 16px; border-radius: 11px; font-size: 13px; font-weight: 600;
    margin-bottom: 14px; border: 1px solid transparent;
}
.alert-success { background: var(--success-light); color: #065f46; border-color: #a7f3d0; }
.alert-danger  { background: var(--danger-light);  color: #991b1b; border-color: #fecaca; }
.alert-warning { background: var(--warning-light); color: #92400e; border-color: #fde68a; }
.alert-info    { background: var(--info-light);    color: #075985; border-color: #bae6fd; }
.alert ul { margin-inline-start: 18px; }

.toast-wrap {
    position: fixed; bottom: 22px; inset-inline-end: 22px; z-index: 200;
    display: flex; flex-direction: column; gap: 10px;
}
.toast {
    background: #fff; border-radius: 12px; border: 1px solid var(--border);
    box-shadow: var(--shadow-lg); padding: 13px 16px; min-width: 280px; max-width: 380px;
    display: flex; gap: 10px; align-items: flex-start;
    animation: toastIn .25s ease; font-size: 13px; font-weight: 600; color: var(--ink);
    border-inline-start: 4px solid var(--primary);
}
.toast.out { animation: toastOut .25s ease forwards; }
.toast-success { border-inline-start-color: var(--success); }
.toast-danger { border-inline-start-color: var(--danger); }
.toast-warning { border-inline-start-color: var(--warning); }
.toast-info { border-inline-start-color: var(--info); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(10px); } }

/* ============================================================ Empty & skeleton */
.empty-state { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty-state .es-ic {
    width: 74px; height: 74px; margin: 0 auto 14px; border-radius: 50%;
    background: #f1f5f9; display: grid; place-items: center; font-size: 30px;
}
.empty-state h4 { color: var(--ink); margin-bottom: 5px; font-size: 15px; }
.empty-state p { font-size: 12.5px; max-width: 360px; margin: 0 auto 16px; }

.skeleton { background: linear-gradient(90deg, #eef1f6 25%, #e2e8f0 50%, #eef1f6 75%); background-size: 200% 100%; animation: skel 1.4s infinite; border-radius: 8px; }
@keyframes skel { to { background-position: -200% 0; } }

/* ============================================================ Pagination */
.pagination { display: flex; gap: 6px; justify-content: flex-start; align-items: center; flex-wrap: wrap; }
.page-link {
    min-width: 34px; height: 34px; padding: 0 10px;
    border: 1px solid var(--border); border-radius: 9px;
    background: #fff; color: var(--body); font-size: 12.5px; font-weight: 700;
    display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.page-link:hover { border-color: var(--primary); color: var(--primary); }
.page-link.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.page-link.disabled { opacity: .45; pointer-events: none; }
.page-info { font-size: 12px; color: var(--muted); }

/* ============================================================ Misc components */
.progress { height: 8px; background: #eef2f7; border-radius: 8px; overflow: hidden; min-width: 90px; }
.progress > div { height: 100%; border-radius: 8px; background: var(--primary); width: 50%; transition: width .4s; }
.progress.success > div { background: var(--success); }
.progress.danger > div { background: var(--danger); }
.progress.warning > div { background: var(--warning); }

.stats-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.mini-stat { background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; padding: 8px 14px; }
.mini-stat b { display: block; color: var(--ink); font-size: 14px; }
.mini-stat span { font-size: 11px; color: var(--muted); }

.timeline { position: relative; padding-inline-start: 24px; }
.timeline::before { content: ''; position: absolute; inset-inline-start: 8px; top: 4px; bottom: 4px; width: 2px; background: var(--border); }
.tl-item { position: relative; padding-bottom: 18px; }
.tl-item::before {
    content: ''; position: absolute; inset-inline-start: -21px; top: 5px;
    width: 10px; height: 10px; border-radius: 50%; background: var(--primary);
    border: 2px solid #fff; box-shadow: 0 0 0 2px var(--primary-soft);
}
.tl-item.tl-success::before { background: var(--success); box-shadow: 0 0 0 2px var(--success-light); }
.tl-item.tl-danger::before { background: var(--danger); box-shadow: 0 0 0 2px var(--danger-light); }
.tl-item.tl-warning::before { background: var(--warning); box-shadow: 0 0 0 2px var(--warning-light); }
.tl-item.tl-info::before { background: var(--info); box-shadow: 0 0 0 2px var(--info-light); }
.tl-title { font-weight: 700; color: var(--ink); font-size: 13px; display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.tl-meta { font-size: 11.5px; color: var(--muted); }
.tl-body { font-size: 12.5px; color: var(--body); margin-top: 2px; }

.kv-list { display: grid; gap: 10px; }
.kv { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; padding-bottom: 8px; border-bottom: 1px dashed var(--border); }
.kv:last-child { border-bottom: 0; padding-bottom: 0; }
.kv .k { color: var(--muted); font-weight: 600; }
.kv .v { color: var(--ink); font-weight: 700; text-align: end; }

.notif-item { display: flex; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--border); align-items: flex-start; }
.notif-item:last-child { border-bottom: 0; }
.notif-item.unread { background: var(--primary-light); }
.notif-ic { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0; font-size: 15px; }
.notif-title { font-weight: 700; font-size: 13px; color: var(--ink); }
.notif-msg { font-size: 12px; color: var(--body); }
.notif-time { font-size: 11px; color: var(--muted); display: block; margin-top: 2px; }

.chip { display: inline-block; background: #f1f5f9; color: #475569; font-size: 11.5px; font-weight: 700; border-radius: 8px; padding: 2px 9px; }

.pay-method-ic { width: 30px; height: 30px; border-radius: 8px; display: inline-grid; place-items: center; color: #fff; font-size: 11px; font-weight: 800; }

/* ============================================================ Auth pages */
.auth-wrap {
    min-height: 100vh; display: grid; place-items: center; padding: 28px;
    background: #101827; position: relative; overflow: hidden;
}
.auth-wrap::before, .auth-wrap::after {
    content: ''; position: absolute; border-radius: 50%; filter: blur(4px); opacity: .95;
}
.auth-wrap::before { width: 760px; height: 760px; background: radial-gradient(circle, rgba(79,70,229,.5), transparent 68%); top: -380px; inset-inline-end: -320px; }
.auth-wrap::after { width: 640px; height: 640px; background: radial-gradient(circle, rgba(14,165,233,.24), transparent 70%); bottom: -360px; inset-inline-start: -260px; }
.auth-shell { width: min(100%, 440px); position: relative; z-index: 1; }
.auth-brand { display: flex; align-items: center; justify-content: center; gap: 11px; color: #fff; margin-bottom: 26px; text-align: start; }
.auth-brand-mark { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 13px; color: #fff; background: linear-gradient(135deg, #818cf8, #4f46e5); box-shadow: 0 10px 24px rgba(79,70,229,.4); font-size: 20px; }
.auth-brand b { display: block; font-size: 14px; }
.auth-brand span { display: block; color: #94a3b8; font-size: 10.5px; margin-top: 2px; }
.auth-card {
    background: rgba(255,255,255,.98); width: 100%; padding: 42px 40px; border-radius: 24px;
    box-shadow: 0 26px 60px rgba(0,0,0,.25); border: 1px solid rgba(255,255,255,.22);
}
.pwa-install-btn[hidden] { display: none !important; }
.pwa-install-auth:not([hidden]) {
    display: inline-flex;
    width: 100%;
    margin-top: 14px;
    padding: 9px 16px;
}
.auth-company { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.auth-logo { width: 50px; height: 50px; border-radius: 15px; background: #eef2ff; display: grid; place-items: center; font-size: 22px; color: var(--primary); overflow: hidden; flex: 0 0 auto; }
.auth-logo img { width: 100%; height: 100%; object-fit: contain; }
.auth-company-name { display: block; color: var(--ink); font-size: 15px; font-weight: 800; line-height: 1.4; }
.auth-kicker { color: var(--primary); font-size: 12px; font-weight: 800; }
.auth-title { font-size: 23px; font-weight: 800; color: var(--ink); margin: 6px 0 8px; }
.auth-sub { font-size: 12.5px; color: var(--muted); margin-bottom: 28px; line-height: 1.8; }
.auth-field { position: relative; }
.auth-field label { font-size: 12.5px; font-weight: 800; margin-bottom: 7px; display: block; }
.auth-field .input { padding-inline-start: 42px; min-height: 48px; border-color: #dbe2ef; background: #fbfcfe; }
.auth-field .input:focus { background: #fff; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
.auth-input-icon { position: absolute; inset-inline-start: 14px; bottom: 14px; color: #94a3b8; font-size: 17px; pointer-events: none; }
.auth-options { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 11.5px; }
.auth-options a { color: var(--primary); font-weight: 800; }
.auth-submit { min-height: 50px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; box-shadow: 0 10px 20px rgba(79,70,229,.25); }
.auth-foot { text-align: center; font-size: 12px; color: var(--muted); margin-top: 18px; }
.auth-foot a { font-weight: 700; }
.auth-demo { border: 1px solid #e2e8f0; border-radius: 12px; background: #f8fafc; padding: 11px 13px; color: #64748b; font-size: 11px; display: grid; gap: 3px; }
.auth-demo b { color: var(--ink); }
.auth-copyright { color: #64748b; font-size: 10.5px; text-align: center; margin: 18px 0 0; }

/* ============================================================ Invoice (print view) */
.invoice-sheet {
    background: #fff; max-width: 800px; margin: 0 auto;
    border-radius: var(--radius); border: 1px solid var(--border);
    padding: 34px 40px; box-shadow: var(--shadow);
}
.inv-top { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 28px; flex-wrap: wrap; }
.inv-company { display: flex; gap: 14px; align-items: center; }
.inv-logo { width: 62px; height: 62px; border-radius: 14px; object-fit: cover; background: var(--primary-light); display: grid; place-items: center; font-size: 26px; overflow: hidden; }
.inv-logo img { width: 100%; height: 100%; object-fit: contain; }
.inv-company h2 { font-size: 19px; }
.inv-company .inv-meta { font-size: 12px; color: var(--muted); line-height: 1.7; }
.inv-number { text-align: end; }
.inv-number .big { font-size: 21px; font-weight: 800; color: var(--primary); }
.inv-number .st { font-size: 12px; color: var(--muted); }
.inv-sections { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 26px; }
.inv-section { border: 1px solid var(--border); border-radius: 12px; padding: 14px 18px; background: #fafbfe; }
.inv-section h4 { font-size: 12px; color: var(--muted); font-weight: 800; margin-bottom: 8px; }
.inv-section .ism { font-size: 12.5px; line-height: 1.9; }
.inv-section .ism b { color: var(--ink); }
.inv-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 20px; }
.inv-table th { background: var(--primary); color: #fff; padding: 10px 14px; font-size: 12px; text-align: start; }
.inv-table td { border: 1px solid var(--border); padding: 10px 14px; }
.inv-totals { width: 300px; margin-inline-start: auto; font-size: 13.5px; }
.inv-totals .row { display: flex; justify-content: space-between; padding: 6px 0; }
.inv-totals .row.total { border-top: 2px solid var(--border); font-weight: 800; color: var(--primary); font-size: 16px; padding-top: 10px; }
.inv-totals .row.balance { font-weight: 800; color: var(--danger); }
.inv-footer { border-top: 1px dashed var(--border); margin-top: 26px; padding-top: 16px; font-size: 12px; color: var(--muted); }
.inv-actions { display: flex; gap: 8px; justify-content: center; margin: 18px 0; flex-wrap: wrap; }
@media print {
    body { background: #fff; }
    .topbar, .sidebar, .inv-actions, .no-print { display: none !important; }
    .main, .main.wide { margin-inline-start: 0 !important; }
    .invoice-sheet { box-shadow: none; border: 0; max-width: 100%; }
    @page { margin: 14mm; }
}

/* ============================================================ Charts */
.chart-box { position: relative; height: 280px; }
.chart-box.sm { height: 230px; }

/* ============================================================ Utilities */
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row.center { align-items: center; justify-content: center; }
.row.between { justify-content: space-between; }
.align-center { display: inline-flex; align-items: center; gap: 8px; }
.mt-0 { margin-top: 0 } .mt-1 { margin-top: 6px } .mt-2 { margin-top: 12px } .mt-3 { margin-top: 18px } .mt-4 { margin-top: 26px }
.mb-0 { margin-bottom: 0 } .mb-1 { margin-bottom: 6px } .mb-2 { margin-bottom: 12px } .mb-3 { margin-bottom: 18px } .mb-4 { margin-bottom: 26px }
.ms-auto { margin-inline-start: auto; }
.text-primary { color: var(--primary) !important; } .text-success { color: var(--success) !important; }
.text-danger { color: var(--danger) !important; } .text-warning { color: var(--warning) !important; }
.text-muted { color: var(--muted) !important; } .text-ink { color: var(--ink) !important; }
.text-sm { font-size: 12px; } .text-xs { font-size: 11px; } .text-lg { font-size: 16px; }
.fw-700 { font-weight: 700; } .fw-800 { font-weight: 800; }
.d-none { display: none !important; }
.flex-1 { flex: 1; min-width: 0; }

/* ============================================================ Responsive */
@media (max-width: 1200px) {
    .stat-grid, .stat-col { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 992px) {
    .sidebar { transform: translateX(100%); width: 260px; }
    .sidebar.collapsed { transform: translateX(100%); width: 260px; }
    .sidebar.open { transform: translateX(0); }
    .main, .main.wide { margin-inline-start: 0; }
    .topbar { padding: 0 16px; }
    .form-grid { grid-template-columns: 1fr; }
    /* The service editor and the role cards keep a useful two-column layout on tablets. */
    .services-form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
    .services-grid, .settings-grid, .roles-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
    .auth-wrap { padding: 18px; }
    .auth-shell { grid-template-columns: 1fr; max-width: 500px; min-height: 0; }
    .auth-aside { display: none; }
    .auth-card { max-width: 100%; padding: 42px 36px; }
}
@media (max-width: 640px) {
    html { font-size: 13px; }
    .topbar { height: 58px; gap: 8px; padding-inline: 12px; }
    .topbar .tb-title { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .topbar .tb-sub { display: none; }
    .topbar .btn-primary { padding: 7px 10px; font-size: 11.5px; }
    .topbar .dropdown-menu { position: fixed; inset-inline: 12px; top: 64px; min-width: 0 !important; }
    .page-pad { padding: 16px 12px !important; }
    footer { padding: 12px !important; }
    .stat-grid, .stat-col { grid-template-columns: 1fr; }
    .services-grid, .settings-grid, .roles-grid, .services-form-grid { grid-template-columns: 1fr !important; }
    .page-head { align-items: stretch; margin-bottom: 16px; gap: 10px; }
    .page-head h1 { font-size: 17px; }
    .page-head .ph-sub { font-size: 11.5px; }
    .auth-wrap { padding: 12px; align-items: start; }
    .auth-shell { border-radius: 20px; }
    .auth-card { padding: 32px 24px; }
    .auth-title { font-size: 22px; }
    .page-head > .btn { width: 100%; }
    .filter-bar { padding: 12px; gap: 10px; }
    .filter-bar .form-group, .filter-bar .form-group:has(input[type=text]) { min-width: 100%; flex-basis: 100%; }
    .filter-bar .actions-row { width: 100%; }
    .filter-bar .actions-row .btn { flex: 1; }
    .card-hd, .card-bd, .card-ft { padding-inline: 14px; }
    .card-hd { align-items: flex-start; flex-wrap: wrap; }
    .table-wrap { margin-inline: -1px; }
    table.table { min-width: 720px; font-size: 12px; }
    .table thead th, .table tbody td { padding: 10px 12px; }
    .row > .btn { flex: 1; }
    .btn-lg { padding: 10px 14px; font-size: 13px; }
    .checkbox-line { align-items: flex-start; }
    .card-bd { padding: 14px; }
    .inv-sections { grid-template-columns: 1fr; }
    .inv-totals { width: 100%; }
    .modal { width: 96%; }
    .toast-wrap { inset-inline: 12px; bottom: 12px; }
    .toast { min-width: 0; max-width: 100%; }

    /* Customer and user lists become readable cards instead of requiring horizontal scrolling. */
    .table-wrap:has(.customer-table), .table-wrap:has(.users-table) { overflow: visible; }
    table.customer-table, table.users-table { min-width: 0; width: 100%; }
    .customer-table thead, .users-table thead { display: none; }
    .customer-table tbody, .users-table tbody { display: grid; gap: 10px; padding: 10px; }
    .customer-table tbody tr, .users-table tbody tr {
        display: grid; grid-template-columns: minmax(82px, .8fr) minmax(0, 1.2fr);
        gap: 0; border: 1px solid var(--border); border-radius: 11px; overflow: hidden;
        background: #fff;
    }
    .customer-table tbody td, .users-table tbody td {
        display: grid; grid-column: 1 / -1;
        grid-template-columns: minmax(82px, .8fr) minmax(0, 1.2fr);
        align-items: center; padding: 0; border: 0;
        border-bottom: 1px solid var(--border);
    }
    .customer-table tbody td::before, .users-table tbody td::before {
        padding: 9px 10px; background: #fafbfe; color: var(--muted); font-size: 11px;
        font-weight: 700; border-bottom: 1px solid var(--border); content: '';
    }
    .customer-table tbody td > *, .users-table tbody td > * { min-width: 0; padding: 9px 10px; }
    .customer-table tbody td:nth-child(1)::before { content: 'العميل'; }
    .customer-table tbody td:nth-child(2)::before { content: 'الهاتف'; }
    .customer-table tbody td:nth-child(3)::before { content: 'الفروع'; }
    .customer-table tbody td:nth-child(4)::before { content: 'الخدمات'; }
    .customer-table tbody td:nth-child(5)::before { content: 'المدفوع'; }
    .customer-table tbody td:nth-child(6)::before { content: 'المتبقي'; }
    .customer-table tbody td:nth-child(7)::before { content: 'أقرب انتهاء'; }
    .customer-table tbody td:nth-child(8)::before { content: 'الحالة'; }
    .customer-table tbody td:nth-child(9)::before { content: 'الإجراءات'; }
    .users-table tbody td:nth-child(1)::before { content: 'المستخدم'; }
    .users-table tbody td:nth-child(2)::before { content: 'البريد'; }
    .users-table tbody td:nth-child(3)::before { content: 'الدور'; }
    .users-table tbody td:nth-child(4)::before { content: 'آخر دخول'; }
    .users-table tbody td:nth-child(5)::before { content: 'تاريخ الإضافة'; }
    .users-table tbody td:nth-child(6)::before { content: 'الحالة'; }
    .users-table tbody td:nth-child(7)::before { content: 'الإجراءات'; }
    .customer-table tbody td:last-child, .users-table tbody td:last-child,
    .customer-table tbody td:last-child::before, .users-table tbody td:last-child::before { border-bottom: 0; }
    .customer-table .row-actions, .users-table .row-actions { flex-wrap: wrap !important; }
    .settings-submit .btn { width: 100%; }
}
@media (min-width: 993px) {
    .overlay-mobile { display: none !important; }
}
