/* نظام رسائل التواصل — عربي RTL فاتح */

:root {
    --bg:        #f5f7fa;
    --card:      #ffffff;
    --line:      #e4e9f0;
    --line-soft: #eef2f7;
    --ink:       #12263f;
    --muted:     #64748b;
    --faint:     #94a3b8;
    --primary:   #2563eb;
    --primary-d: #1d4ed8;
    --primary-l: #eff4ff;
    --green:     #059669;
    --green-l:   #ecfdf5;
    --amber:     #b45309;
    --amber-l:   #fffbeb;
    --red:       #dc2626;
    --red-l:     #fef2f2;
    --radius:    12px;
    --shadow:    0 1px 2px rgba(18, 38, 63, .04), 0 4px 14px rgba(18, 38, 63, .05);
}

* { box-sizing: border-box; }

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: system-ui, -apple-system, "Segoe UI", Tahoma, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.6;
}

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

.ltr { direction: ltr; unicode-bidi: isolate; }
.num { font-variant-numeric: tabular-nums; }

/* ── الترويسة ───────────────────────────────────────────────── */
.topbar {
    background: var(--card);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar-in {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    align-items: center;
    gap: 26px;
    min-height: 60px;
    flex-wrap: wrap;
}
.brand {
    font-weight: 700;
    font-size: 16px;
    color: var(--ink);
    display: flex;
    align-items: center;
    gap: 9px;
}
.brand:hover { text-decoration: none; }
.brand-dot {
    width: 9px; height: 9px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 0 3px var(--green-l);
}
.nav { display: flex; gap: 4px; margin-inline-start: auto; flex-wrap: wrap; }
.nav a {
    padding: 7px 14px;
    border-radius: 8px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 500;
}
.nav a:hover { background: var(--bg); color: var(--ink); text-decoration: none; }
.nav a.on { background: var(--primary-l); color: var(--primary-d); }
.nav .badge {
    display: inline-block;
    min-width: 18px;
    padding: 0 5px;
    margin-inline-start: 5px;
    border-radius: 9px;
    background: var(--red);
    color: #fff;
    font-size: 11px;
    line-height: 18px;
    text-align: center;
}

/* ── التخطيط ────────────────────────────────────────────────── */
.wrap { max-width: 1280px; margin: 0 auto; padding: 24px 20px 60px; }

h1 { font-size: 21px; margin: 0 0 4px; font-weight: 700; }
.sub { color: var(--muted); font-size: 13.5px; margin: 0 0 22px; }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card + .card { margin-top: 18px; }
.card-pad { padding: 18px 20px; }
.card-head {
    padding: 14px 20px;
    border-bottom: 1px solid var(--line-soft);
    font-weight: 600;
    font-size: 14.5px;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ── بطاقات الأرقام ─────────────────────────────────────────── */
.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}
.tile {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow);
}
.tile-label { color: var(--muted); font-size: 12.5px; margin-bottom: 6px; }
.tile-value { font-size: 26px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.tile-value.accent { color: var(--primary); }
.tile-value.warn   { color: var(--amber); }

/* ── الفلاتر ────────────────────────────────────────────────── */
.filters {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: flex-end;
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 500; }
.field.grow { flex: 1 1 240px; }

input[type=text], input[type=search], input[type=email], input[type=password], select, textarea {
    font: inherit;
    font-size: 14px;
    color: var(--ink);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 9px;
    padding: 8px 11px;
    width: 100%;
    transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-l);
}
textarea { resize: vertical; min-height: 80px; }

.btn {
    font: inherit;
    font-size: 14px;
    font-weight: 500;
    padding: 8px 16px;
    border-radius: 9px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    cursor: pointer;
    white-space: nowrap;
    transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); border-color: var(--primary-d); }
.btn-danger { color: var(--red); border-color: #f3c9c9; }
.btn-danger:hover { background: var(--red-l); }
.btn-sm { padding: 5px 11px; font-size: 13px; }
a.btn { display: inline-block; }

/* ── الجداول ────────────────────────────────────────────────── */
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
    text-align: start;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    padding: 11px 16px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
    background: #fbfcfe;
}
tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--line-soft);
    vertical-align: top;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fbfcfe; }
tbody tr.unread { background: #fcfdff; }
tbody tr.unread td:first-child { box-shadow: inset 3px 0 0 var(--primary); }
tbody tr.spam { opacity: .62; }

.cell-main { font-weight: 600; }
.cell-sub  { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.nowrap { white-space: nowrap; }

/* ── وسوم ───────────────────────────────────────────────────── */
.tag {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 500;
    background: var(--bg);
    color: var(--muted);
    border: 1px solid var(--line);
    white-space: nowrap;
}
.tag-green { background: var(--green-l); color: var(--green); border-color: #b7e8d5; }
.tag-amber { background: var(--amber-l); color: var(--amber); border-color: #f5dda8; }
.tag-red   { background: var(--red-l);   color: var(--red);   border-color: #f5cccc; }
.tag-blue  { background: var(--primary-l); color: var(--primary-d); border-color: #cfe0ff; }

.star { color: #d4a017; }
.star-off { color: #d5dbe3; }

/* ── حالة فارغة ─────────────────────────────────────────────── */
.empty { padding: 56px 20px; text-align: center; color: var(--muted); }
.empty-title { font-size: 16px; font-weight: 600; color: var(--ink); margin-bottom: 6px; }

/* ── ترقيم الصفحات ──────────────────────────────────────────── */
.pager {
    display: flex;
    gap: 6px;
    align-items: center;
    justify-content: center;
    padding: 16px;
    flex-wrap: wrap;
    border-top: 1px solid var(--line-soft);
}
.pager a, .pager span {
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 13.5px;
    border: 1px solid var(--line);
    color: var(--muted);
    background: #fff;
}
.pager a:hover { background: var(--bg); text-decoration: none; }
.pager .on { background: var(--primary); border-color: var(--primary); color: #fff; }
.pager .gap { border: none; background: none; }

/* ── تفاصيل الرسالة ─────────────────────────────────────────── */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 2px;
    background: var(--line-soft);
    border-radius: 10px;
    overflow: hidden;
}
.detail-cell { background: #fff; padding: 13px 16px; }
.detail-label { font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.detail-value { font-weight: 500; word-break: break-word; }

.message-body {
    white-space: pre-wrap;
    word-break: break-word;
    background: #fbfcfe;
    border: 1px solid var(--line-soft);
    border-radius: 10px;
    padding: 16px 18px;
    line-height: 1.8;
}

.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── التنبيهات ──────────────────────────────────────────────── */
.alert {
    padding: 11px 15px;
    border-radius: 10px;
    margin-bottom: 16px;
    font-size: 14px;
    border: 1px solid;
}
.alert-ok   { background: var(--green-l); color: var(--green); border-color: #b7e8d5; }
.alert-warn { background: var(--amber-l); color: var(--amber); border-color: #f5dda8; }
.alert-err  { background: var(--red-l);   color: var(--red);   border-color: #f5cccc; }

/* ── صفحة الدخول ────────────────────────────────────────────── */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.login-box {
    width: 100%;
    max-width: 380px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 32px 28px;
    box-shadow: 0 4px 24px rgba(18, 38, 63, .07);
}
.login-title { font-size: 19px; font-weight: 700; margin: 0 0 4px; text-align: center; }
.login-sub { color: var(--muted); font-size: 13.5px; text-align: center; margin: 0 0 24px; }
.code-input {
    text-align: center;
    font-size: 26px;
    letter-spacing: 10px;
    padding: 12px;
    direction: ltr;
    font-variant-numeric: tabular-nums;
}
.login-box .btn { width: 100%; margin-top: 14px; padding: 11px; }
.login-foot {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--line-soft);
    text-align: center;
    font-size: 13px;
    color: var(--muted);
}

@media (max-width: 640px) {
    .wrap { padding: 18px 14px 50px; }
    .topbar-in { padding: 0 14px; gap: 14px; }
    .nav { width: 100%; margin-inline-start: 0; order: 3; padding-bottom: 8px; }
    thead th, tbody td { padding: 10px 12px; }
}
