/* ============================================================
   مكتب الدعم — ثيم فاتح، اتجاه من اليمين لليسار
   الفكرة البصرية: لون الحالة يسكن "عموداً" على حافة كل بلاغ،
   فيُقرأ وضع القائمة كاملةً بنظرة واحدة. ما عداه هادئ ومنضبط.
   ============================================================ */

:root {
    --mist: #f1f5f8;
    --surface: #ffffff;
    --ink: #10263b;
    --muted: #5d7284;
    --line: #dde5ec;
    --line-strong: #c9d5df;

    --primary: #0d5c8c;
    --primary-dark: #0a4a72;
    --primary-soft: #e3f0f8;

    --danger: #b4232a;
    --danger-soft: #fde5e6;
    --ok: #17784a;
    --warn-soft: #fdf3d9;

    --r-card: 12px;
    --r-ctl: 9px;
    color-scheme: light;
}

/* ألوان الحالات والأهمية: --c نص، --cs خلفية خفيفة، --bar عمود الحافة */
.st-open        { --c: #2457c5; --cs: #e7eefc; --bar: #3b71e0; }
.st-in_progress { --c: #96570a; --cs: #fdf0d5; --bar: #e39a18; }
.st-waiting     { --c: #6a3fb0; --cs: #efe8fb; --bar: #8b5fd1; }
.st-resolved    { --c: #17784a; --cs: #e0f3e8; --bar: #2fa66c; }
.st-closed      { --c: #5d7284; --cs: #e9eef2; --bar: #b5c2cd; }
.pr-low         { --c: #5d7284; --cs: #e9eef2; }
.pr-normal      { --c: #2d5f86; --cs: #e3eef7; }
.pr-high        { --c: #a34a06; --cs: #ffe9d2; }
.pr-urgent      { --c: #b4232a; --cs: #fde5e6; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--mist);
    color: var(--ink);
    font-family: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; line-height: 1.35; }
h1 { font-size: 1.55rem; font-weight: 700; }
h2 { font-size: 1.2rem; font-weight: 700; }
h3 { font-size: 1.02rem; font-weight: 600; }
p  { margin: 0 0 10px; }
a  { color: var(--primary); }
small { font-size: .82rem; color: var(--muted); }
code {
    background: #e9f0f5; padding: 1px 6px; border-radius: 6px;
    font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .88em; word-break: break-all;
}
.ic { flex: none; }
.muted { color: var(--muted); }
.sub { color: var(--muted); margin: 4px 0 0; }
.hint { color: var(--muted); font-size: .85rem; margin: 6px 0 0; }
.opt { font-weight: 400; color: var(--muted); font-size: .85rem; }
.ltr-cell { display: block; text-align: right; unicode-bidi: plaintext; }
.warn-inline { color: #96570a; font-size: .82rem; }

:focus-visible { outline: 3px solid rgba(13, 92, 140, .35); outline-offset: 2px; }

/* ---------- الهيكل ---------- */
.wrap { max-width: 1080px; margin-inline: auto; padding-inline: 16px; }
.main { padding-block: 22px 90px; }

.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; }
.topbar-in { display: flex; align-items: center; justify-content: space-between; min-height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: var(--primary); color: #fff; display: grid; place-items: center; }
.brand-text b { display: block; font-size: .98rem; line-height: 1.2; }
.brand-text small { display: block; line-height: 1.2; }
.topbar-user { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .9rem; }
.icon-btn { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; color: var(--muted); }
.icon-btn:hover { background: var(--mist); color: var(--ink); }

.nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
    display: flex; align-items: center; gap: 6px; padding: 10px 14px; white-space: nowrap;
    color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; font-weight: 500;
}
.nav a:hover { color: var(--ink); }
.nav a.active { color: var(--primary); border-color: var(--primary); font-weight: 600; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.back { display: inline-flex; align-items: center; gap: 2px; color: var(--muted); text-decoration: none; font-size: .88rem; margin-bottom: 4px; }
.back .ic { transform: scaleX(-1); }
.back:hover { color: var(--primary); }
.section-title { margin: 22px 0 10px; }

/* ---------- تنبيهات ---------- */
.flash { padding: 12px 14px; border-radius: var(--r-ctl); margin-bottom: 14px; border: 1px solid; border-inline-start-width: 4px; background: #fff; }
.flash-success { background: #eaf7f0; border-color: #b8e2cc; color: #0f5a37; }
.flash-error   { background: var(--danger-soft); border-color: #f2bcbe; color: #8c1b21; }
.flash-warn    { background: var(--warn-soft); border-color: #efd694; color: #6e4306; }
.flash code { background: #fff; }
.flash small { display: block; margin-top: 6px; color: inherit; opacity: .85; }

/* ---------- بطاقات ونماذج ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); padding: 18px; }
.card + .card, .card + .grid-2, .grid-2 + .card, .flash + .card { margin-top: 14px; }
.card.flush { padding: 0; overflow: hidden; }
.card-title { margin-bottom: 12px; }
.card-title.spaced { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.card-head .card-title { margin: 0; }
.sub-title { margin: 16px 0 8px; font-size: .95rem; color: var(--muted); font-weight: 600; }
.empty { text-align: center; padding: 42px 18px; }
.empty h2 { margin-bottom: 6px; }
.empty .btn { margin-top: 12px; }

.stack { display: flex; flex-direction: column; gap: 14px; }
.form-card { display: flex; flex-direction: column; gap: 14px; }
.form-card.flat { padding: 4px 0 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.align-start { align-items: start; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.field label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
input, select, textarea {
    width: 100%; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: var(--r-ctl);
    background: #fff; color: var(--ink); font: inherit; font-size: 16px;
}
textarea { resize: vertical; min-height: 96px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(13, 92, 140, .16); }
input:disabled { background: var(--mist); color: var(--muted); }
input[type=checkbox], input[type=radio] { width: auto; }
input[type=file] { padding: 8px; font-size: .9rem; }
.ltr-input { text-align: left; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: .92rem; cursor: pointer; }
.check input { margin-top: 5px; }

/* ---------- أزرار ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 42px;
    padding: 9px 16px; border-radius: var(--r-ctl); border: 1px solid transparent; cursor: pointer;
    font: inherit; font-size: .95rem; font-weight: 600; line-height: 1.2; text-decoration: none; transition: background .15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: #fff; color: var(--ink); border-color: var(--line-strong); }
.btn-ghost:hover { background: #f4f8fb; }
.btn-danger-ghost { background: #fff; color: var(--danger); border-color: #efc4c6; }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.btn-sm { min-height: 34px; padding: 5px 11px; font-size: .84rem; }
.btn-block { width: 100%; }
.btn-sso { background: #fff; border-color: var(--line-strong); color: var(--ink); width: 100%; }
.btn[disabled] { opacity: .6; cursor: progress; }

/* ---------- شارات ---------- */
.badge {
    display: inline-flex; align-items: center; padding: 1px 10px; border-radius: 99px; white-space: nowrap;
    font-size: .78rem; font-weight: 600; background: var(--cs); color: var(--c);
}
.chip { display: inline-block; padding: 0 9px; border-radius: 6px; background: #e9f0f5; color: var(--muted); font-size: .78rem; font-weight: 500; }
.chip-support { background: var(--primary-soft); color: var(--primary); }
.chip-internal { background: #fbe9b6; color: #6e4306; }

/* ---------- الإحصاءات والتبويبات والفلاتر ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 20px; }
.stat {
    position: relative; overflow: hidden; display: block; text-decoration: none; color: var(--ink);
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); padding: 12px 16px;
}
.stat::before { content: ""; position: absolute; inset-block: 0; inset-inline-start: 0; width: 4px; background: var(--bar); }
.stat b { display: block; font-size: 1.75rem; line-height: 1.25; color: var(--c); font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .85rem; }
.stat:hover { border-color: var(--line-strong); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tab { padding: 10px 14px; margin-bottom: -1px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500; }
.tab.active { color: var(--primary); border-color: var(--primary); font-weight: 600; }
.count { background: #e4ecf2; color: var(--muted); border-radius: 99px; padding: 0 8px; font-size: .78rem; margin-inline-start: 4px; }
.tab.active .count { background: var(--primary-soft); color: var(--primary); }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.filters .search { position: relative; flex: 1 1 240px; }
.filters .search .ic { position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.filters .search input { padding-inline-start: 38px; }
.filters select { width: auto; flex: 0 1 170px; }

/* ---------- قائمة البلاغات: عمود الحالة على الحافة ---------- */
.tlist { display: flex; flex-direction: column; gap: 8px; }
.trow {
    position: relative; overflow: hidden; display: flex; align-items: center; justify-content: space-between; gap: 14px;
    padding: 13px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card);
    text-decoration: none; color: var(--ink);
}
.trow::before { content: ""; position: absolute; inset-block: 0; inset-inline-start: 0; width: 5px; background: var(--bar); }
.trow:hover { border-color: var(--line-strong); background: #fbfdfe; }
.trow-main { min-width: 0; }
.trow-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tid { color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; margin-inline-end: 8px; }
.trow-meta { display: flex; flex-wrap: wrap; gap: 4px 16px; color: var(--muted); font-size: .82rem; margin-top: 2px; }
.trow-meta span { display: inline-flex; align-items: center; gap: 4px; }
.trow-meta .m-company { color: var(--ink); font-weight: 500; }
.trow-badges { display: flex; gap: 6px; flex: none; flex-wrap: wrap; justify-content: flex-end; }
.pager { display: flex; justify-content: center; align-items: center; gap: 14px; margin: 20px 0; color: var(--muted); font-size: .9rem; }

.fab {
    position: fixed; inset-inline-start: 18px; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); z-index: 25;
    width: 56px; height: 56px; border-radius: 18px; background: var(--primary); color: #fff;
    display: grid; place-items: center; box-shadow: 0 6px 18px rgba(13, 92, 140, .35);
}

/* ---------- صفحة البلاغ ---------- */
.ticket-head {
    background: var(--surface); border: 1px solid var(--line); border-inline-start: 6px solid var(--bar);
    border-radius: var(--r-card); padding: 14px 18px 16px; margin-bottom: 16px;
}
.title-row h1 { font-size: 1.35rem; overflow-wrap: anywhere; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.ticket-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; align-items: start; }
.ticket-side { display: flex; flex-direction: column; gap: 14px; }
.ticket-side .card + .card { margin-top: 0; }
.ticket-side p { margin-bottom: 8px; }
.ticket-side form + p, .ticket-side p + form { margin-top: 8px; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 0; }
.kv dt { color: var(--muted); font-size: .85rem; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.kv dd small { display: block; }

.thread { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; }
.thread .card { margin-top: 0; }
.msg-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.msg-head small { display: block; }
.msg-head .chip { margin-inline-start: 4px; }
.avatar { width: 36px; height: 36px; flex: none; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 700; }
.msg-body { line-height: 1.9; overflow-wrap: anywhere; }
.msg.from-support { border-inline-start: 4px solid var(--primary); }
.msg.internal { background: #fff9e8; border-color: #f0dca4; border-inline-start: 4px solid #e6b422; }
.msg.system { text-align: center; color: var(--muted); font-size: .84rem; padding: 2px 0; }
.msg.system small { margin-inline-start: 6px; }

.files { margin-top: 12px; }
.gallery { display: flex; flex-wrap: wrap; gap: 8px; }
.gallery img { width: 128px; height: 128px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); display: block; background: var(--mist); }
.audio-item { margin-top: 10px; }
.audio-name { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: .84rem; }
audio { width: 100%; max-width: 440px; display: block; margin-top: 4px; }
.file-link { display: inline-flex; align-items: center; gap: 6px; margin-top: 8px; margin-inline-end: 12px; }

/* ---------- حقل المرفقات ---------- */
.att-buttons { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 8px; }
.att-btn {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 68px; padding: 8px;
    border: 1.5px dashed var(--line-strong); border-radius: 10px; background: #f8fbfd; color: var(--ink);
    font: inherit; font-size: .84rem; font-weight: 500; cursor: pointer;
}
.att-btn .ic { color: var(--primary); }
.att-btn:hover { border-color: var(--primary); background: var(--primary-soft); }
.rec { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 10px; padding: 10px 12px; background: var(--danger-soft); border: 1px solid #f2bcbe; border-radius: 10px; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: #d92d20; animation: pulse 1.2s ease-in-out infinite; }
.rec-time { font-variant-numeric: tabular-nums; font-weight: 700; direction: ltr; }
.rec-label { color: var(--muted); font-size: .88rem; flex: 1; }
@keyframes pulse { 50% { opacity: .25; } }

.att-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; margin-top: 10px; }
.att-list:empty { display: none; }
.att-item { position: relative; border: 1px solid var(--line); border-radius: 10px; background: #fff; overflow: hidden; }
.att-item img { width: 100%; height: 96px; object-fit: cover; display: block; }
.att-item.wide { grid-column: 1 / -1; padding: 10px 40px 10px 10px; }
.att-item.wide audio { max-width: none; }
.att-item .att-name { display: block; padding: 4px 8px; font-size: .74rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-item.wide .att-name { padding: 0 0 4px; font-size: .82rem; }
.att-remove {
    position: absolute; top: 4px; inset-inline-end: 4px; width: 26px; height: 26px; border: 0; border-radius: 50%;
    background: rgba(16, 38, 59, .78); color: #fff; display: grid; place-items: center; cursor: pointer; padding: 0;
}

/* ---------- جداول ---------- */
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; min-width: 720px; }
.tbl th { text-align: start; padding: 10px 14px; font-size: .8rem; font-weight: 600; color: var(--muted); background: #f6f9fb; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 11px 14px; border-top: 1px solid var(--line); vertical-align: top; }
.tbl thead tr td, .tbl thead + tbody tr:first-child td { border-top: 0; }
.tbl td small { display: block; }
.muted-row td { opacity: .6; }
.muted-row td.actions { opacity: 1; }
.actions { white-space: nowrap; }
.inline { display: inline-flex; gap: 6px; flex-wrap: nowrap; }
.creds .tbl { min-width: 0; }

/* ---------- الشركات ---------- */
.company-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; margin-top: 16px; }
.company-card { margin: 0 !important; display: flex; flex-direction: column; gap: 14px; }
.company-card.inactive { opacity: .7; }
.company-top { display: flex; align-items: center; gap: 12px; }
.company-top .badge { margin-inline-start: auto; }
.company-icon { width: 42px; height: 42px; border-radius: 12px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; flex: none; }
.company-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.company-stats a { text-decoration: none; color: var(--ink); background: var(--mist); border-radius: 10px; padding: 8px 10px; }
.company-stats a:hover { background: var(--primary-soft); }
.company-stats b { display: block; font-size: 1.3rem; line-height: 1.3; font-variant-numeric: tabular-nums; }
.company-stats span { font-size: .76rem; color: var(--muted); }
.company-actions { display: flex; flex-wrap: wrap; gap: 6px; }

.fold summary { display: flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 600; list-style: none; }
.fold summary::-webkit-details-marker { display: none; }
.fold summary .ic { color: var(--primary); }
.fold[open] summary { margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }

.copy-box { display: flex; align-items: center; gap: 8px; margin: 8px 0; padding: 6px 6px 6px 10px; background: #f4f8fb; border: 1px solid var(--line); border-radius: var(--r-ctl); }
.copy-box code { flex: 1; background: none; padding: 0; text-align: left; }
.flash .copy-box { background: #fff; }
.status-list { list-style: none; margin: 14px 0; padding: 0; display: grid; gap: 6px; font-size: .92rem; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #c3cfd9; margin-inline-end: 8px; }
.dot.on { background: var(--ok); }

/* ---------- صفحات الدخول ---------- */
body.bare { background: var(--mist); }
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-split {
    display: grid; grid-template-columns: 1.1fr 1fr; width: 100%; max-width: 900px;
    background: var(--surface); border: 1px solid var(--line); border-radius: 18px; overflow: hidden;
}
.auth-intro { background: var(--primary-soft); padding: 44px 36px; display: flex; flex-direction: column; justify-content: center; gap: 14px; }
.auth-intro h1 { font-size: 1.7rem; }
.auth-intro p { color: #34556f; max-width: 34ch; margin: 0; }
.auth-logo { width: 52px; height: 52px; border-radius: 15px; background: var(--primary); color: #fff; display: grid; place-items: center; margin-bottom: 8px; }
.auth-card { padding: 36px 32px; display: flex; flex-direction: column; gap: 12px; }
.auth-card h2 { font-size: 1.25rem; }
.auth-card .sub { margin: 0 0 4px; }
.auth-card-solo { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; }
.auth-card-solo.wide { max-width: 540px; }
.auth-foot { text-align: center; margin: 4px 0 0; font-size: .9rem; }
.sso-btns { display: flex; flex-direction: column; gap: 8px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .82rem; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ---------- الجوال ---------- */
@media (max-width: 860px) {
    .ticket-layout { grid-template-columns: minmax(0, 1fr); }
    .auth-split { grid-template-columns: 1fr; }
    .auth-intro { padding: 28px 24px; }
    .auth-intro p { max-width: none; }
}
@media (max-width: 720px) {
    body { font-size: 15px; }
    h1 { font-size: 1.35rem; }
    .grid-2 { grid-template-columns: 1fr; }
    .stats { grid-template-columns: repeat(2, 1fr); }
    .uname { display: none; }
    .trow { flex-direction: column; align-items: stretch; gap: 8px; }
    .trow-title { white-space: normal; }
    .trow-badges { justify-content: flex-start; }
    .card { padding: 16px; }
    .main { padding-top: 16px; }
    .page-head .btn { width: 100%; }
    .auth-card { padding: 26px 20px; }
}
@media (min-width: 721px) {
    .fab { display: none; }
}
@media (prefers-reduced-motion: reduce) {
    .rec-dot { animation: none; }
    .btn { transition: none; }
}

@media print {
    body * { visibility: hidden; }
    .creds, .creds * { visibility: visible; }
    .creds { position: absolute; inset: 0; border: 0; }
    .creds [data-print] { display: none; }
}

/* تلميحات الحقول وحالة الإرسال */
.field-hint { margin: 8px 0 0; font-size: .84rem; color: var(--muted); }
form.is-busy { opacity: .75; pointer-events: none; }
button[aria-busy="true"] { cursor: progress; }

/* ---------- المساعدة عن بعد (مشاركة شاشة) ---------- */
.remote-card .hint { margin-bottom: 10px; }
.remote-video { width: 100%; border-radius: var(--r-ctl); background: #0b1b28; display: block; aspect-ratio: 16/9; object-fit: contain; }
.remote-consent { background: var(--primary-soft); border: 1px solid var(--line); border-radius: var(--r-ctl); padding: 12px; }
.remote-consent p { margin-bottom: 10px; }
.remote-live { background: var(--warn-soft); border-radius: var(--r-ctl); padding: 12px; font-size: .92rem; }
.remote-live .btn { margin-top: 10px; }
.rustdesk-fold { margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 10px; }
.rustdesk-fold summary { cursor: pointer; font-size: .88rem; color: var(--primary); font-weight: 600; }
.rustdesk-fold[open] summary { margin-bottom: 8px; }
