/* مقر الشركة — نظام بصري واحد، داكن، يعمل RTL وLTR بخصائص منطقية */
:root {
  --bg: #0f1115; --panel: #171a21; --panel-2: #1e222b; --line: #2a2f3a;
  --text: #e8eaf0; --muted: #8b93a5; --accent: #4f8cff; --accent-2: #2f6ae0;
  --ok: #34c98e; --warn: #e0a83c; --err: #e05c5c; --radius: 12px;
}
* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: "Segoe UI", Tahoma, system-ui, sans-serif;
  font-size: 15px; line-height: 1.6; text-align: start;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.err { color: var(--err); }
.center { text-align: center; }

/* زر اللغة */
.lang-btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  color: var(--text); height: 38px; min-width: 44px; cursor: pointer; font-size: 13px;
}
.lang-btn:hover { border-color: var(--accent); }

/* الدخول */
.login { display: grid; place-items: center; height: 100%; }
.login-card {
  position: relative;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 40px 32px; width: min(360px, 90vw); display: grid; gap: 16px; text-align: center;
}
.login-card .lang-btn { position: absolute; inset-block-start: 12px; inset-inline-end: 12px; height: 30px; min-width: 38px; }
.login-card h1 { font-size: 22px; }
.login-card input {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 14px; color: var(--text); font-size: 15px; text-align: center;
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-card button[type="submit"] {
  background: var(--accent); border: 0; border-radius: 8px; padding: 10px;
  color: #fff; font-size: 15px; cursor: pointer;
}
.login-card button[type="submit"]:hover { background: var(--accent-2); }

/* الهيكل */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.topbar-title { min-width: 0; }
.topbar h1 { font-size: 18px; }
.topbar-actions { display: flex; gap: 8px; flex-shrink: 0; }
.badge {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 20px;
  font-size: 12px; padding: 2px 10px; color: var(--muted); vertical-align: middle;
}
#refreshBtn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  color: var(--text); width: 38px; height: 38px; font-size: 17px; cursor: pointer;
}
.layout { flex: 1; display: flex; min-height: 0; }

/* قائمة الموظفين */
.sidebar {
  width: 300px; flex-shrink: 0; border-inline-end: 1px solid var(--line);
  overflow-y: auto; background: var(--panel); padding: 10px;
}
.dept-label { font-size: 12px; color: var(--muted); margin: 14px 8px 6px; }
.staff-card {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: start;
  background: transparent; border: 1px solid transparent; border-radius: 10px;
  padding: 10px 12px; cursor: pointer; color: var(--text); font-size: 15px;
  font-family: inherit;
}
.staff-card:hover { background: var(--panel-2); }
.staff-card.active { background: var(--panel-2); border-color: var(--accent); }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #7c5cff); color: #fff;
  font-weight: 600; flex-shrink: 0;
}
.staff-meta { min-width: 0; }
.staff-meta .title { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 8px; height: 8px; border-radius: 50%; margin-inline-start: auto; flex-shrink: 0; }
.dot.active { background: var(--ok); }
.dot.paused { background: var(--warn); }

/* المحادثة */
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.empty { flex: 1; display: grid; place-items: center; color: var(--muted); padding: 20px; text-align: center; }
#chatView { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-head {
  display: flex; align-items: center; gap: 14px; padding: 12px 20px;
  border-bottom: 1px solid var(--line); background: var(--panel);
}
.chat-who { min-width: 0; }
.chat-head h2 { font-size: 17px; }
.stats { margin-inline-start: auto; display: flex; gap: 14px; font-size: 12px; color: var(--muted); flex-shrink: 0; }
.stats b { color: var(--text); }

.messages { flex: 1; overflow-y: auto; padding: 20px; display: grid; gap: 12px; align-content: start; }
.msg {
  max-width: 78%; border-radius: var(--radius); padding: 10px 14px;
  overflow-wrap: anywhere; text-align: start;
}
/* متن الرسالة بعد التصيير — أحجام متسقة وتباعد منتظم */
.msg .body p { margin: 0 0 6px; }
.msg .body p:last-child { margin-bottom: 0; }
.msg .body h4 { font-size: 14px; margin: 10px 0 4px; color: var(--accent); }
.msg.owner .body h4 { color: #cfe0ff; }
.msg .body h4:first-child { margin-top: 0; }
.msg .body ul { margin: 4px 0 6px; padding-inline-start: 20px; }
.msg .body li { margin-bottom: 3px; }
.msg .body code {
  background: rgba(0,0,0,.3); border-radius: 4px; padding: 1px 5px;
  font-size: 13px; font-family: Consolas, monospace; direction: ltr;
  unicode-bidi: isolate; display: inline-block;
}
.msg .body br { line-height: .5; }
.msg .body strong { font-weight: 600; }
/* الوقت معزول اتجاهياً كي لا ينقلب في RTL، ويبقى في جهة بداية القراءة */
.msg .time { font-size: 11px; color: var(--muted); margin-top: 4px; }
.msg .time bdi { unicode-bidi: isolate; }
.msg audio { width: 100%; max-width: 260px; margin-bottom: 6px; display: block; }

/* بالعربي كل شيء يبدأ من اليمين، وبالإنجليزي من اليسار — لا شيء يتيه في الجهة المقابلة.
   التمييز بين رسائلك ورسائل الموظف باللون وشريط جانبي، لا بالمحاذاة. */
.msg { justify-self: start; }
.msg.staff {
  background: var(--panel-2); border: 1px solid var(--line);
  border-start-start-radius: 4px;
}
.msg.owner {
  background: var(--accent-2); border-inline-start: 3px solid #9db8ff;
  border-start-start-radius: 4px;
}
.msg.staff .from { font-size: 12px; color: var(--accent); margin-bottom: 2px; }
.msg audio { min-width: 240px; }

/* المرفقات داخل الرسائل */
.msg .files { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.thumb {
  max-width: 200px; max-height: 200px; border-radius: 8px; display: block;
  border: 1px solid var(--line);
}
.file-chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px;
  background: rgba(255,255,255,.06); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 10px; color: var(--text); text-decoration: none;
}
.file-chip:hover { border-color: var(--accent); }

/* شريط المرفقات قبل الإرسال */
.attach-bar {
  display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 20px;
  background: var(--panel); border-top: 1px solid var(--line);
}
.pending-chip {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 4px 10px; font-size: 13px; display: inline-flex; align-items: center; gap: 8px;
}
.pending-chip b { cursor: pointer; color: var(--err); font-size: 15px; line-height: 1; }

/* تلميح الحالة */
.mic-hint {
  padding: 6px 20px; font-size: 13px; color: var(--muted);
  background: var(--panel); border-top: 1px solid var(--line);
}
.mic-hint.err { color: var(--err); }
.mic-hint.ok { color: var(--ok); }

#attachBtn {
  background: var(--panel-2); border: 1px solid var(--line); min-width: 44px;
  padding: 0 8px; font-size: 16px; color: var(--text);
}

/* الكتابة */
.composer {
  display: flex; gap: 10px; align-items: flex-end; padding: 12px 20px;
  border-top: 1px solid var(--line); background: var(--panel);
}
.composer textarea {
  flex: 1; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 14px; color: var(--text); font-size: 15px; font-family: inherit;
  resize: none; max-height: 140px; text-align: start;
}
.composer textarea:focus { outline: none; border-color: var(--accent); }
.composer button {
  background: var(--accent); border: 0; border-radius: 10px; padding: 10px 18px;
  color: #fff; font-size: 15px; cursor: pointer; height: 42px; font-family: inherit;
}
.composer button:hover { background: var(--accent-2); }
.composer button:disabled { opacity: .5; cursor: default; }
#micBtn {
  background: var(--panel-2); border: 1px solid var(--line); min-width: 46px;
  padding: 0 8px; font-size: 16px; color: var(--text); font-variant-numeric: tabular-nums;
}
#micBtn.rec { background: var(--err); border-color: var(--err); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .6; } }

@media (max-width: 720px) {
  .sidebar { width: 76px; padding: 6px; }
  .staff-meta, .dept-label { display: none; }
  .staff-card { justify-content: center; padding: 8px; }
  .dot { display: none; }
  .msg { max-width: 90%; }
  .stats { display: none; }
  .topbar { padding: 10px 14px; }
  .composer, .messages { padding-inline: 14px; }
}
