/*
 * لوحة الموظفين — مجموعة المزاد الدولي / MACCHINAA
 * نفس هوية الحاسبة: أسود #1c191a + أحمر #bf2229 + أبيض، RTL، جوّال أولاً.
 */
:root {
  --navy: #1c191a;
  --navy-2: #38302f;
  --gold: #bf2229;       /* الأحمر الأساسي */
  --gold-soft: #f3c3c5;
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #1b1718;
  --muted: #6b7785;
  --line: #e2e7ee;
  --good: #0f7a4d;
  --warn-bg: #fff7d6;
  --warn-line: #e9c84a;
  --late-bg: #fdecec;
  --late-line: #bf2229;
  --shadow: 0 6px 24px rgba(28, 25, 26, 0.10);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--ink);
  font-family: "Segoe UI", "Helvetica Neue", Tahoma, Arial, "Noto Sans Arabic", sans-serif;
  -webkit-text-size-adjust: 100%;
}

/* ===== الهيدر ===== */
.site-header { background: #fff; padding: 12px 16px 0; border-bottom: 3px solid var(--gold); box-shadow: var(--shadow); position: sticky; top: 0; z-index: 50; }
.header-inner { max-width: 1180px; margin: 0 auto; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; flex: 1 1 auto; }
.brand img { width: 56px; height: 56px; flex: none; object-fit: contain; }
.brand-text .ar { font-size: 1.3rem; font-weight: 800; color: var(--ink); }
.brand-text .en { font-size: .8rem; color: var(--gold); font-weight: 700; letter-spacing: .5px; text-transform: uppercase; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.staff-id { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; line-height: 1.1; }
.staff-name { font-weight: 800; font-size: .9rem; color: var(--navy-2); }

.tabs { max-width: 1180px; margin: 10px auto 0; display: flex; gap: 4px; flex-wrap: wrap; }
.tab { background: transparent; border: 0; border-bottom: 3px solid transparent; color: var(--muted); padding: 10px 14px; font-weight: 800; font-size: .9rem; cursor: pointer; font-family: inherit; }
.tab.active { color: var(--gold); border-bottom-color: var(--gold); }

/* ===== أزرار عامة ===== */
.btn-gold { background: var(--gold); color: #fff; border: 0; padding: 12px 20px; border-radius: 10px; font-weight: 800; cursor: pointer; font-size: .95rem; font-family: inherit; }
.btn-gold:disabled { opacity: .45; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--navy-2); border: 1px solid var(--line); padding: 9px 16px; border-radius: 10px; font-weight: 700; cursor: pointer; font-family: inherit; }
.btn-ghost:hover { border-color: var(--gold); color: var(--gold); }
.btn-sm { padding: 7px 12px; font-size: .82rem; border-radius: 8px; }
.btn-danger { background: var(--gold); color: #fff; border: 0; }

.badge { display: inline-block; font-size: .68rem; font-weight: 800; padding: 3px 9px; border-radius: 999px; background: #eef2f7; color: var(--navy-2); border: 1px solid var(--line); }

/* ===== شاشة الدخول ===== */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { background: var(--card); width: min(380px, 100%); border-radius: 16px; box-shadow: var(--shadow); border: 1px solid var(--line); padding: 26px 22px; text-align: center; }
.login-logo { width: 72px; height: 72px; object-fit: contain; }
.login-card h2 { margin: 10px 0 4px; font-size: 1.25rem; color: var(--navy-2); }
.login-sub { margin: 0 0 16px; color: var(--muted); font-size: .85rem; }
.login-card .field { text-align: start; margin-bottom: 12px; }
.login-card .btn-gold { width: 100%; margin-top: 6px; }

/* ===== الحقول ===== */
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: .78rem; color: var(--muted); font-weight: 700; }
.field input, .field select, .stack-form input, .stack-form select {
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; font-size: .95rem;
  background: var(--card); color: var(--ink); min-height: 44px; width: 100%; font-family: inherit;
}
.field input:focus, .field select:focus, .stack-form input:focus, .stack-form select:focus { outline: 2px solid var(--gold); border-color: var(--gold); }

.form-msg { font-size: .85rem; font-weight: 700; min-height: 1.1em; margin-top: 8px; }
.form-msg.ok { color: var(--good); }
.form-msg.err { color: var(--gold); }

/* ===== المنطقة الرئيسية ===== */
.app-main { max-width: 1180px; margin: 0 auto; padding: 0 16px 40px; }
.controls { margin: 18px 0 8px; display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.field.search { flex: 1 1 280px; }
.result-count { color: var(--muted); font-size: .85rem; padding: 4px 0; }

/* ===== شبكة الطلبات ===== */
.orders-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; margin-top: 8px; }
.order-card { background: var(--card); border: 1px solid var(--line); border-inline-start: 5px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 14px 16px; cursor: pointer; transition: box-shadow .15s, transform .1s; }
.order-card:hover { box-shadow: 0 10px 28px rgba(28,25,26,.16); transform: translateY(-2px); }
.order-card .oc-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.order-card .oc-ref { font-weight: 900; color: var(--navy-2); font-size: 1rem; }
.order-card .oc-vehicle { color: var(--ink); font-size: .9rem; margin-top: 2px; }
.order-card .oc-row { display: flex; gap: 6px; margin-top: 8px; font-size: .82rem; color: var(--ink); }
.order-card .oc-row .lbl { color: var(--muted); font-weight: 700; min-width: 62px; }
.order-card .oc-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }
.order-card .oc-total { font-weight: 900; color: var(--good); font-variant-numeric: tabular-nums; }

/* شارة الحالة */
.status-chip { display: inline-block; font-size: .72rem; font-weight: 800; padding: 4px 10px; border-radius: 999px; background: #eef2f7; color: var(--navy-2); border: 1px solid var(--line); white-space: nowrap; }
.status-chip.s-awaiting { background: #eef2f7; }
.status-chip.s-processing { background: #e7f0ff; border-color: #bcd4ff; color: #1d4ed8; }
.status-chip.s-on_the_way { background: #fff3e0; border-color: #ffd699; }
.status-chip.s-at_yard { background: #ede7f6; border-color: #cdbef0; }
.status-chip.s-shipped { background: #e3f5ec; border-color: #a8e0c4; color: var(--good); }
.status-chip.s-delivered { background: var(--good); color: #fff; border-color: var(--good); }
.status-chip.s-cancelled { background: #f3f3f3; color: var(--muted); text-decoration: line-through; }

/* تلوين التقادم */
.aging-warn { background: var(--warn-bg); border-inline-start-color: var(--warn-line); }
.aging-late { background: var(--late-bg); border-inline-start-color: var(--late-line); animation: pulseLate 1.2s ease-in-out infinite; }
@keyframes pulseLate {
  0%, 100% { box-shadow: 0 0 0 0 rgba(191, 34, 41, .45); border-inline-start-color: var(--late-line); }
  50%      { box-shadow: 0 0 0 6px rgba(191, 34, 41, .05); border-inline-start-color: #ff5a60; }
}
.aging-tag { font-size: .66rem; font-weight: 900; padding: 2px 7px; border-radius: 6px; }
.aging-tag.warn { background: var(--warn-line); color: #5b4a00; }
.aging-tag.late { background: var(--gold); color: #fff; }

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

/* ===== لوحات المدير ===== */
.panel-cols { display: grid; grid-template-columns: 320px 1fr; gap: 16px; margin-top: 18px; }
.panel-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 16px 18px; margin-top: 18px; }
.panel-card.grow { margin-top: 0; }
.panel-cols .panel-card { margin-top: 0; }
.panel-card h3 { margin: 0 0 12px; color: var(--navy-2); font-size: 1.05rem; }
.stack-form { display: grid; gap: 10px; }

.data-table { border-collapse: collapse; width: 100%; min-width: 420px; font-size: .85rem; }
.data-table th { background: var(--navy); color: #fff; text-align: start; padding: 8px 10px; white-space: nowrap; font-size: .76rem; position: sticky; top: 0; }
.data-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data-table tr:nth-child(even) td { background: #fafbfd; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* التحليلات */
.stats-body { margin-top: 18px; display: grid; gap: 16px; }
.stat-cards { display: flex; gap: 12px; flex-wrap: wrap; }
.stat-card { flex: 1 1 130px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 14px; text-align: center; }
.stat-card.alert { border-color: var(--gold); background: #fff8f8; }
.stat-n { display: block; font-size: 1.8rem; font-weight: 900; color: var(--navy-2); font-variant-numeric: tabular-nums; }
.stat-card.alert .stat-n { color: var(--gold); }
.stat-l { display: block; font-size: .76rem; color: var(--muted); margin-top: 4px; }
.stat-bars { display: grid; gap: 8px; }
.stat-bar-row { display: flex; align-items: center; gap: 10px; font-size: .82rem; }
.stat-bar-row .sb-lbl { flex: 0 0 130px; font-weight: 700; color: var(--navy-2); }
.stat-bar-row .sb-track { flex: 1 1 auto; background: #eef2f7; border-radius: 999px; height: 16px; overflow: hidden; }
.stat-bar-row .sb-fill { height: 100%; background: var(--gold); border-radius: 999px; }
.stat-bar-row .sb-n { flex: 0 0 36px; text-align: end; font-weight: 800; font-variant-numeric: tabular-nums; }

/* ===== Modal التفاصيل ===== */
.overlay { position: fixed; inset: 0; z-index: 1000; background: rgba(20,20,25,.55); display: flex; align-items: flex-start; justify-content: center; padding: 16px; overflow-y: auto; }
.overlay[hidden] { display: none; }
.detail-box { background: #fff; width: min(720px, 100%); border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.3); overflow: hidden; margin: auto; }
.detail-head { display: flex; align-items: center; justify-content: space-between; background: linear-gradient(135deg, var(--navy-2), var(--navy)); color: #fff; padding: 14px 18px; }
.detail-head h3 { margin: 0; font-size: 1.1rem; }
.detail-x { background: transparent; border: 0; color: #fff; font-size: 1.6rem; line-height: 1; cursor: pointer; }
.detail-body { padding: 16px 18px; max-height: 80vh; overflow-y: auto; }

.det-sec { margin-bottom: 18px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.det-sec:last-child { border-bottom: 0; }
.det-sec h4 { margin: 0 0 10px; color: var(--gold); font-size: .95rem; }
.det-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; font-size: .88rem; }
.det-grid .k { color: var(--muted); font-weight: 700; }
.det-grid .v { color: var(--ink); font-weight: 600; }

/* خط زمني الحالات */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline li { position: relative; padding: 0 22px 14px 0; border-inline-start: 2px solid var(--line); margin-inline-start: 6px; }
.timeline li:last-child { padding-bottom: 0; }
.timeline li::before { content: ""; position: absolute; inset-inline-start: -7px; top: 2px; width: 12px; height: 12px; border-radius: 50%; background: var(--gold); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); }
.tl-status { font-weight: 800; color: var(--navy-2); font-size: .9rem; }
.tl-meta { color: var(--muted); font-size: .78rem; margin-top: 2px; }
.tl-note { font-size: .82rem; margin-top: 3px; }

/* أزرار تغيير الحالة */
.status-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.status-actions button { font-family: inherit; }
.note-input { width: 100%; margin-bottom: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; font-size: .9rem; font-family: inherit; }
.rbac-note { font-size: .78rem; color: var(--muted); margin-top: 8px; }
.alert-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.alert-actions button { background: #fff3e0; border: 1px solid #ffb74d; color: #8a5200; border-radius: 8px; padding: 8px 12px; font-weight: 800; cursor: pointer; font-size: .82rem; font-family: inherit; }
.alert-actions button:hover { background: #ffe0b2; }

/* ===== الدردشة ===== */
.chat-box { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.chat-msgs { max-height: 260px; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; background: #fafbfd; }
.chat-empty { color: var(--muted); font-size: .85rem; text-align: center; padding: 18px; }
.chat-msg { max-width: 78%; padding: 8px 12px; border-radius: 12px; font-size: .88rem; line-height: 1.5; }
.chat-msg .cm-who { display: block; font-size: .68rem; font-weight: 800; margin-bottom: 2px; opacity: .8; }
.chat-msg.staff { align-self: flex-start; background: var(--gold-soft); border: 1px solid #e7a9ab; }
.chat-msg.customer { align-self: flex-end; background: #e7f0ff; border: 1px solid #bcd4ff; }
.chat-time { font-size: .64rem; color: var(--muted); margin-top: 3px; }
.chat-send { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); background: #fff; }
.chat-send input { flex: 1 1 auto; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: .9rem; font-family: inherit; }
.chat-send button { flex: none; }

/* ===== Toast ===== */
.toast { position: fixed; bottom: 20px; inset-inline: 0; margin: 0 auto; width: max-content; max-width: 90%; background: var(--navy); color: #fff; padding: 12px 20px; border-radius: 12px; font-weight: 700; font-size: .9rem; box-shadow: var(--shadow); z-index: 1100; text-align: center; }
.toast[hidden] { display: none; }
.toast.err { background: var(--gold); }
.toast.ok { background: var(--good); }

/* ===== استجابة الجوّال ===== */
@media (max-width: 760px) {
  .panel-cols { grid-template-columns: 1fr; }
  .det-grid { grid-template-columns: 1fr; }
  .brand img { width: 46px; height: 46px; }
  .brand-text .ar { font-size: 1.1rem; }
  .stat-bar-row .sb-lbl { flex: 0 0 96px; }
}
