/* نظام إحصائيات datatime — تصميم فاتح */
:root {
    --bg: #f4f6fa;
    --card: #ffffff;
    --border: #e5e9f0;
    --border-strong: #d3dae6;
    --text: #16202f;
    --muted: #6b7688;
    --faint: #93a0b3;
    --primary: #2563eb;
    --primary-soft: #eff4ff;
    --teal: #0d9488;
    --amber: #d97706;
    --rose: #e11d48;
    --violet: #7c3aed;
    --slate: #64748b;
    --green: #059669;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(16, 32, 47, .04), 0 6px 20px rgba(16, 32, 47, .05);
    --shadow-sm: 0 1px 2px rgba(16, 32, 47, .06);
}

* { box-sizing: border-box; }

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", "Helvetica Neue", Arial, system-ui, sans-serif;
    font-size: 14.5px;
    line-height: 1.65;
    direction: rtl;
}

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

.num, .ltr { direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; }
.mono {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: .88em;
    direction: ltr;
    unicode-bidi: isolate;
}

/* ---------- الشريط العلوي ---------- */
.topbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar-in {
    max-width: 1480px;
    margin: 0 auto;
    padding: 0 22px;
    height: 60px;
    display: flex;
    align-items: center;
    gap: 18px;
}
.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 16px;
    color: var(--text);
}
.brand:hover { text-decoration: none; }
.brand-mark {
    width: 30px; height: 30px;
    border-radius: 8px;
    background: linear-gradient(135deg, #2563eb, #4f8bff);
    color: #fff;
    display: grid; place-items: center;
    font-size: 15px;
    box-shadow: 0 2px 6px rgba(37, 99, 235, .3);
}
.topbar .sep { flex: 1; }
.topbar-meta { color: var(--muted); font-size: 12.5px; }
.topbar-meta b { color: var(--text); font-weight: 600; }

.container { max-width: 1480px; margin: 0 auto; padding: 22px; }

/* ---------- أزرار وعناصر ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 13px;
    border: 1px solid var(--border-strong);
    background: #fff;
    border-radius: 9px;
    color: var(--text);
    font-size: 13.5px;
    font-family: inherit;
    cursor: pointer;
    transition: .15s;
}
.btn:hover { background: #f8fafc; border-color: #b9c4d6; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: #1d54cf; border-color: #1d54cf; }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }

.range {
    display: inline-flex;
    background: #eef1f6;
    border-radius: 10px;
    padding: 3px;
    gap: 2px;
}
.range a {
    padding: 5px 12px;
    border-radius: 7px;
    font-size: 13px;
    color: var(--muted);
}
.range a:hover { color: var(--text); text-decoration: none; }
.range a.on { background: #fff; color: var(--text); font-weight: 600; box-shadow: var(--shadow-sm); }

.field {
    padding: 8px 12px;
    border: 1px solid var(--border-strong);
    border-radius: 9px;
    font-family: inherit;
    font-size: 14px;
    background: #fff;
    color: var(--text);
    width: 100%;
}
.field:focus { outline: 2px solid #bfd4ff; border-color: var(--primary); }

/* ---------- بطاقات المؤشرات ---------- */
.kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.kpi {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 15px 16px;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}
.kpi-label { color: var(--muted); font-size: 12.5px; display: flex; align-items: center; gap: 6px; }
.kpi-value { font-size: 26px; font-weight: 700; letter-spacing: -.5px; margin-top: 3px; }
.kpi-sub { color: var(--faint); font-size: 12px; margin-top: 2px; }
.kpi::before {
    content: ""; position: absolute; inset-inline-start: 0; top: 0; bottom: 0; width: 3px;
    background: var(--primary);
}
.kpi.teal::before { background: var(--teal); }
.kpi.amber::before { background: var(--amber); }
.kpi.rose::before { background: var(--rose); }
.kpi.violet::before { background: var(--violet); }
.kpi.slate::before { background: var(--slate); }
.kpi.green::before { background: var(--green); }

/* ---------- البطاقات ---------- */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    margin-bottom: 18px;
    overflow: hidden;
}
.card-head {
    padding: 13px 17px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.card-head h2 { margin: 0; font-size: 15px; font-weight: 700; }
.card-head .sep { flex: 1; }
.card-head .hint { color: var(--faint); font-size: 12.5px; font-weight: 400; }
.card-body { padding: 17px; }
.card-body.tight { padding: 0; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
@media (max-width: 1000px) {
    .grid2, .grid3 { grid-template-columns: 1fr; }
}

/* ---------- الجداول ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.tbl th {
    text-align: right;
    padding: 10px 14px;
    background: #fafbfd;
    border-bottom: 1px solid var(--border);
    color: var(--muted);
    font-weight: 600;
    font-size: 12.5px;
    white-space: nowrap;
    position: sticky;
    top: 0;
}
table.tbl th.sortable { cursor: pointer; user-select: none; }
table.tbl th.sortable:hover { color: var(--text); }
table.tbl th .arrow { opacity: .45; font-size: 10px; }
table.tbl td {
    padding: 9px 14px;
    border-bottom: 1px solid #f1f4f8;
    vertical-align: middle;
}
table.tbl tbody tr:hover { background: #fafcff; }
table.tbl tbody tr:last-child td { border-bottom: 0; }
td.n, th.n { text-align: left; direction: ltr; font-variant-numeric: tabular-nums; }
.dim { color: var(--muted); }
.faint { color: var(--faint); }
.nowrap { white-space: nowrap; }
.trunc { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: bottom; }

/* ---------- شرائح ---------- */
.pill {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    line-height: 1.7;
    white-space: nowrap;
}
.pill.direct   { background: #f1f5f9; color: #475569; }
.pill.search   { background: #eff4ff; color: #1d4ed8; }
.pill.social   { background: #f5f0ff; color: #6d28d9; }
.pill.referral { background: #ecfdf5; color: #047857; }
.pill.ai       { background: #fff7ed; color: #c2410c; }
.pill.internal { background: #f8fafc; color: #64748b; }
.pill.bot      { background: #fef2f2; color: #be123c; }
.pill.human    { background: #ecfdf5; color: #047857; }
.pill.plain    { background: #f1f5f9; color: #475569; }

/* ---------- أشرطة النِسَب ---------- */
.bar {
    height: 6px;
    background: #eef1f6;
    border-radius: 4px;
    overflow: hidden;
    min-width: 70px;
}
.bar > i { display: block; height: 100%; background: var(--primary); border-radius: 4px; }
.bar.teal > i { background: var(--teal); }
.bar.amber > i { background: var(--amber); }
.bar.rose > i { background: var(--rose); }
.bar.violet > i { background: var(--violet); }
.bar.slate > i { background: var(--slate); }

.stack { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: #eef1f6; }
.stack > i { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px; font-size: 12.5px; }
.legend span { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.legend i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }

/* ---------- المخططات ---------- */
.chart { width: 100%; display: block; }
.chart .grid-line { stroke: #eef1f6; stroke-width: 1; }
.chart .axis-txt { fill: var(--faint); font-size: 10.5px; }
.chart .dot { fill: #fff; stroke: var(--primary); stroke-width: 2; }
.spark { vertical-align: middle; }

.tooltip {
    position: fixed;
    background: #16202f;
    color: #fff;
    padding: 7px 11px;
    border-radius: 8px;
    font-size: 12.5px;
    pointer-events: none;
    opacity: 0;
    transition: opacity .12s;
    z-index: 100;
    white-space: nowrap;
    box-shadow: 0 4px 14px rgba(0,0,0,.2);
}
.tooltip.show { opacity: 1; }

/* ---------- تسجيل الدخول ---------- */
.login-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
    background: radial-gradient(1200px 600px at 50% -10%, #e8effc 0%, var(--bg) 60%);
}
.login {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 34px 30px;
    width: 100%;
    max-width: 380px;
    text-align: center;
}
.login h1 { font-size: 19px; margin: 14px 0 4px; }
.login p { color: var(--muted); font-size: 13.5px; margin: 0 0 22px; }
.login .brand-mark { width: 46px; height: 46px; font-size: 22px; margin: 0 auto; border-radius: 13px; }
.code-input {
    font-size: 26px;
    text-align: center;
    letter-spacing: 12px;
    padding: 13px;
    direction: ltr;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}
.error {
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
    border-radius: 9px;
    padding: 9px 12px;
    font-size: 13px;
    margin-bottom: 16px;
}

/* ---------- متفرقات ---------- */
.crumb { color: var(--muted); font-size: 13px; margin-bottom: 12px; }
.crumb a { color: var(--muted); }
.page-title { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 0 0 16px; }
.page-title h1 { margin: 0; font-size: 22px; letter-spacing: -.3px; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .grow { flex: 1; min-width: 180px; }
.empty { text-align: center; color: var(--faint); padding: 34px 16px; font-size: 13.5px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); padding: 0 17px; overflow-x: auto; }
.tabs a {
    padding: 11px 13px;
    font-size: 13.5px;
    color: var(--muted);
    border-bottom: 2px solid transparent;
    white-space: nowrap;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.on { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.dot-live {
    width: 7px; height: 7px; border-radius: 50%; background: var(--green);
    display: inline-block; box-shadow: 0 0 0 3px rgba(5,150,105,.16);
    animation: pulse 2s infinite;
}
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .35 } }

.flow { display: flex; flex-direction: column; gap: 0; }
.flow-step {
    display: flex; gap: 12px; align-items: flex-start;
    padding: 9px 0; border-bottom: 1px dashed #eef1f6; font-size: 13.5px;
}
.flow-step:last-child { border-bottom: 0; }
.flow-time { color: var(--faint); font-size: 12px; min-width: 62px; direction: ltr; }

@media (max-width: 640px) {
    .container { padding: 14px; }
    .kpi-value { font-size: 22px; }
    .topbar-in { padding: 0 14px; gap: 10px; }
    .topbar-meta { display: none; }
}
