/* ═══════════ وصلة — التنسيق العام ═══════════ */
:root {
  --green: #2e7d32;
  --green-dark: #1b5e20;
  --green-light: #e8f5e9;
  --red: #d32f2f;
  --bg: #f6f8f6;
  --card: #ffffff;
  --text: #1c2b1c;
  --muted: #6b7c6b;
  --bubble-me: #d5f0d6;
  --bubble-them: #ffffff;
  --radius: 18px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --pill: #eef2ee;          /* سطح حبة الكتابة، أفتح قليلاً من الشريط الأبيض */
  --pill-border: #dbe4db;   /* حدّ خفيف للحبة والبطاقات المنبثقة */
  --muted-ic: #5f6f5f;      /* لون الأيقونات الصغيرة داخل الحبة */
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: "Segoe UI", Tahoma, "Noto Naskh Arabic", sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
}

.hidden { display: none !important; }

/* ─────────── الشاشات ─────────── */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  max-width: 720px;
  margin: 0 auto;
}

/* ─────────── الشريط العلوي ─────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--green);
  color: #fff;
  box-shadow: var(--shadow);
  z-index: 5;
}
.topbar h1 { font-size: 1.25rem; flex: 1; }
.topbar-actions { display: flex; gap: 8px; }

/* ─────────── الأزرار ─────────── */
button {
  font-family: inherit;
  font-size: 1rem;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary {
  background: var(--green);
  color: #fff;
  padding: 14px 20px;
  font-size: 1.1rem;
  font-weight: 600;
  width: 100%;
}
.btn-primary:active { background: var(--green-dark); }

.btn-danger {
  background: var(--red);
  color: #fff;
  padding: 14px 20px;
  font-size: 1.1rem;
  font-weight: 600;
  width: 100%;
}

.btn-big { font-size: 1.3rem; padding: 18px 24px; }
.btn-small { width: auto; padding: 10px 18px; font-size: 1rem; }

.btn-link {
  background: none;
  color: var(--green);
  text-decoration: underline;
  padding: 12px;
  width: 100%;
}

.btn-icon {
  background: rgba(255, 255, 255, 0.15);
  font-size: 1.5rem;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.composer .btn-icon, .recording-bar .btn-icon { background: var(--green-light); }

.btn-emergency {
  background: var(--red);
  font-size: 1.5rem;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(211, 47, 47, 0.5); }
  50% { box-shadow: 0 0 0 8px rgba(211, 47, 47, 0); }
}


.fab {
  position: absolute;
  bottom: calc(24px + env(safe-area-inset-bottom));
  inset-inline-end: 24px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  font-size: 1.8rem;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

/* ─────────── تسجيل الدخول ─────────── */
#screen-auth {
  justify-content: center;
  align-items: center;
  padding: 24px;
}
.auth-box {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border-radius: 24px;
  padding: 32px 24px;
  box-shadow: var(--shadow);
  text-align: center;
}
.auth-logo { width: 84px; height: 84px; border-radius: 22px; }
.auth-box h1 { color: var(--green); margin: 8px 0 2px; }
.auth-subtitle { color: var(--muted); margin-bottom: 20px; }

input, select, textarea {
  font-family: inherit;
  font-size: 1.05rem;
  width: 100%;
  padding: 14px;
  margin-bottom: 12px;
  border: 2px solid #dde5dd;
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--green); }

.error-box {
  background: #fdecea;
  color: var(--red);
  padding: 12px;
  border-radius: var(--radius);
  margin-bottom: 12px;
  font-size: 0.95rem;
}

/* ─────────── القوائم ─────────── */
.list { flex: 1; overflow-y: auto; padding: 12px; }
.pad { flex: 1; overflow-y: auto; padding: 16px; }
.hint { color: var(--muted); font-size: 0.9rem; margin-bottom: 12px; }

.list-item {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  cursor: pointer;
  border: 3px solid transparent;
}
.list-item:active { background: var(--green-light); }
.list-item.selected { border-color: var(--green); background: var(--green-light); }

.avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 700;
  flex-shrink: 0;
}
.avatar.group { background: #7b1fa2; }

.item-body { flex: 1; min-width: 0; }
.item-title { font-weight: 700; font-size: 1.05rem; }
.item-sub {
  color: var(--muted);
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item-time { color: var(--muted); font-size: 0.8rem; flex-shrink: 0; }

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 48px 24px;
  font-size: 1.05rem;
  line-height: 2;
}
.empty-state .big { font-size: 3rem; }

/* ─────────── الرسائل ─────────── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg {
  position: relative;
  max-width: 80%;
  padding: 10px 14px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  word-wrap: break-word;
}

/* علامات الإرسال/التسليم/القراءة */
.ticks { font-size: 0.75rem; margin-inline-start: 4px; color: var(--muted); letter-spacing: -2px; }
.ticks.read { color: #2196f3; }
.read-time { font-size: 0.7rem; color: #2196f3; }

/* زر حذف الرسالة (يظهر فقط عندما يسمح الإعداد) */
.msg-del {
  position: absolute;
  top: -8px;
  inset-inline-end: -6px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 0.75rem;
  opacity: 0.55;
  padding: 0;
}
.msg-del:active { opacity: 1; }

/* الصور: زر تحميل عائم + مؤشر نقر */
.img-wrap { position: relative; display: inline-block; }
.img-wrap img.photo { cursor: pointer; }
.img-dl {
  position: absolute;
  bottom: 8px;
  inset-inline-end: 8px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 1rem;
  padding: 0;
}
.img-dl:active { background: rgba(0, 0, 0, 0.8); }

/* عارض الصور بالحجم الكامل */
.lightbox-box {
  background: var(--card);
  border-radius: 20px;
  padding: 14px;
  max-width: min(94vw, 900px);
  text-align: center;
}
#lightbox-img {
  max-width: 100%;
  max-height: 72vh;
  object-fit: contain;
  border-radius: 12px;
}
.btn-link-download {
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  width: 100%;
}

/* بطاقة ملف مرفق */
.file-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--green-light);
  border-radius: 12px;
  padding: 10px 12px;
  text-decoration: none;
  color: var(--text);
  max-width: 260px;
}
.file-card .file-icon { font-size: 1.7rem; flex-shrink: 0; }
.file-card .file-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}
.file-card .file-meta b {
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-card .file-meta span { font-size: 0.75rem; color: var(--muted); }
.file-card .file-dl { font-size: 1.1rem; flex-shrink: 0; }

/* شريط تقدم الرفع */
.upload-bar { background: var(--green-light); border-top: 2px solid var(--green); }
.upload-name {
  max-width: 30%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.85rem;
}
.progress-track {
  flex: 1;
  height: 10px;
  background: #d5e2d5;
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--green);
  border-radius: 999px;
  transition: width 0.15s;
}
#upload-pct { font-size: 0.8rem; font-weight: 700; color: var(--green-dark); }

/* معاينة قبل الإرسال */
.preview-img {
  max-width: 100%;
  max-height: 45vh;
  border-radius: 12px;
  object-fit: contain;
}
.preview-doc { margin: 0 auto; }

/* رسالة محذوفة (ظاهرياً) */
.msg.deleted { opacity: 0.75; }
.msg .deleted-text { font-style: italic; color: var(--muted); font-size: 0.9rem; }
.msg.me {
  align-self: flex-start;      /* جهة البداية: يمين في RTL ويسار في LTR */
  background: var(--bubble-me);
  border-end-start-radius: 6px;
}
.msg.them {
  align-self: flex-end;
  background: var(--bubble-them);
  border-end-end-radius: 6px;
}
/* نص الرسالة: احفظ الأسطر المتعددة (\n) واللف مع كسر الكلمات الطويلة */
.msg .msg-text { white-space: pre-wrap; overflow-wrap: break-word; }
.msg .sender { font-size: 0.8rem; font-weight: 700; color: var(--green); margin-bottom: 2px; }
.msg .time { font-size: 0.7rem; color: var(--muted); margin-top: 4px; text-align: end; }
.msg .translated {
  border-top: 1px dashed #b0c0b0;
  margin-top: 6px;
  padding-top: 6px;
  font-size: 0.95rem;
  color: #33691e;
}
.msg .translated::before { content: "🌐 "; }

.msg.emergency {
  background: #ffebee;
  border: 3px solid var(--red);
  font-weight: 700;
}

.msg audio { max-width: 220px; width: 220px; display: block; }
.msg img.photo {
  max-width: 220px;
  border-radius: 12px;
  display: block;
}

.msg .map-frame {
  border: 0;
  border-radius: 12px;
  width: 240px;
  height: 180px;
  max-width: 100%;
  display: block;
}
.msg .map-link {
  display: block;
  margin-top: 6px;
  color: var(--green);
  font-weight: 600;
  font-size: 0.9rem;
}

.day-divider {
  align-self: center;
  background: #e0e8e0;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 4px 14px;
  border-radius: 999px;
  margin: 8px 0;
}

/* ─────────── شريط الكتابة (نمط واتساب) ─────────── */
.composer {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 7px;
  padding: 8px 8px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  background: var(--card);
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.06);
}

/* الحبة العريضة: تحوي الإيموجي + الحقل + المرفق داخل حدّ واحد */
.composer-pill {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  background: var(--pill);
  border: 1.5px solid var(--pill-border);
  border-radius: 24px;
  padding: 3px 6px;
  transition: border-color .15s;
}
.composer-pill:focus-within { border-color: var(--green); }

/* أيقونتان صغيرتان مدمجتان داخل الحبة */
.pill-icon {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: transparent;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted-ic);
}
.pill-icon:active { background: rgba(0, 0, 0, 0.06); }

.composer textarea {
  flex: 1;
  min-width: 0;
  margin: 0;
  border: none;
  background: transparent;
  /* يتمدد تلقائياً عبر JS بين سطر واحد و~6 أسطر ثم يظهر شريط تمرير داخلي */
  min-height: 36px;
  max-height: 132px;
  height: 36px;
  padding: 7px 4px;
  line-height: 1.4;
  resize: none;
  overflow-y: hidden;
  white-space: pre-wrap;
  word-break: break-word;
}
.composer textarea:focus { border: none; }

/* الدائرة الوحيدة خارج الحبة: تسجيل عند الفراغ / إرسال عند وجود نص */
.btn-round {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
.btn-round:active { background: var(--green-dark); }
.btn-round .ic-send { display: none; }
.btn-round.is-send .ic-send { display: block; }
.btn-round.is-send .ic-mic { display: none; }
:root[dir="rtl"] .btn-round .ic-send { transform: scaleX(-1); }

/* قائمة المرفقات ومنتقي الإيموجي: بطاقات منبثقة فوق الشريط */
.pop-menu, .emoji-pop {
  position: absolute;
  bottom: calc(100% + 6px);
  background: var(--card);
  border: 1px solid var(--pill-border);
  border-radius: 16px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  z-index: 20;
}
.pop-menu {
  inset-inline-start: 8px;
  min-width: 190px;
  padding: 6px;
}
.pop-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: transparent;
  font-size: 1rem;
  color: var(--text);
  text-align: start;
}
.pop-item:active { background: var(--green-light); }
.pop-ic { font-size: 1.3rem; width: 26px; text-align: center; }

.emoji-pop {
  inset-inline: 8px;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  max-height: 200px;
  overflow-y: auto;
}
.emoji-pop button {
  background: transparent;
  font-size: 1.5rem;
  padding: 6px 0;
  border-radius: 10px;
  line-height: 1;
}
.emoji-pop button:active { background: var(--green-light); }

.recording-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: #fff3f3;
  border-top: 2px solid var(--red);
}
.rec-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--red);
  animation: blink 1s infinite;
}
@keyframes blink { 50% { opacity: 0.2; } }
#rec-time { flex: 1; font-weight: 700; color: var(--red); font-size: 1.1rem; }

/* ─────────── الإعدادات ─────────── */
.settings label {
  display: block;
  font-weight: 600;
  margin-bottom: 16px;
}
.settings label input, .settings label select { margin-top: 6px; }
.settings label.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  padding: 14px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.settings label.row input[type="checkbox"] {
  width: 28px;
  height: 28px;
  margin: 0;
  accent-color: var(--green);
}
.settings .btn-primary { margin: 18px 0 10px; }

/* ─────────── النوافذ المنبثقة ─────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal-box {
  background: var(--card);
  border-radius: 24px;
  padding: 24px;
  width: 100%;
  max-width: 420px;
  text-align: center;
}
.modal-box h2 { margin-bottom: 14px; }
.modal-box p { margin-bottom: 14px; line-height: 1.7; }
.modal-actions { display: flex; gap: 12px; margin-top: 16px; }
.emergency-box { border: 4px solid var(--red); }

#selfie-video {
  width: 100%;
  border-radius: 16px;
  background: #000;
  transform: scaleX(-1);
}

/* ─────────── طلبات التواصل والبحث ─────────── */
.search-row { display: flex; gap: 8px; margin-bottom: 12px; }
.search-row input, .search-row select { flex: 1; margin-bottom: 0; }
.search-row .btn-small { width: auto; flex-shrink: 0; }

.list-flat { margin-bottom: 8px; }

.request-card { border: 2px solid var(--green); cursor: default; }
.request-card:active { background: var(--card); }
.req-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}
.req-actions .btn-small { width: auto; font-size: 0.85rem; padding: 8px 12px; }

.empty-state.small { padding: 20px 12px; font-size: 0.95rem; }

.badge-locked { background: #ede7f6; color: #4527a0; }
.badge-verified { background: #e3f2fd; color: #1565c0; }

/* صف دخول مشبوه (دولة جديدة/مختلفة) */
.login-warn {
  background: #fdecea;
  border-radius: 8px;
  border-inline-start: 4px solid var(--red);
  padding-inline-start: 8px;
}

/* ─────────── لوحة الإدارة ─────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card h2 { font-size: 1.05rem; margin-bottom: 12px; }

.admin-item { align-items: flex-start; cursor: default; }
.admin-item:active { background: var(--card); }

.admin-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}
.admin-actions .btn-small { width: auto; font-size: 0.85rem; padding: 8px 12px; }

.btn-warn {
  background: #f9a825;
  color: #fff;
  font-weight: 600;
}

.badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  background: #e0e8e0;
  color: var(--muted);
  border-radius: 999px;
  padding: 2px 8px;
  margin-inline-start: 6px;
  vertical-align: middle;
}
.badge-admin { background: var(--green-light); color: var(--green-dark); }
.badge-mod { background: #fff3e0; color: #e65100; }
.badge-frozen { background: #e3f2fd; color: #1565c0; }

.sec-title { margin: 20px 4px 10px; font-size: 1.1rem; }

.radio-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 4px;
  cursor: pointer;
  font-size: 0.95rem;
}
.radio-row input[type="radio"] {
  width: 22px;
  height: 22px;
  margin: 0;
  flex-shrink: 0;
  accent-color: var(--green);
}

.viewer-box { max-width: 560px; text-align: start; }
.viewer-messages {
  height: 55vh;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 12px;
  padding: 12px;
  margin: 12px 0;
}
.viewer-msg { max-width: 100%; }
.deleted-marker {
  background: #fdecea;
  border: 1px dashed var(--red);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.8rem;
  color: var(--red);
  margin-bottom: 6px;
}

.audit-row {
  font-size: 0.85rem;
  padding: 8px 4px;
  border-bottom: 1px solid #edf2ed;
  line-height: 1.7;
}
.audit-row:last-child { border-bottom: none; }
.audit-time {
  display: inline-block;
  color: var(--muted);
  font-size: 0.75rem;
  margin-inline-end: 8px;
}

/* ─────────── التنبيهات ─────────── */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: #323b32;
  color: #fff;
  padding: 12px 22px;
  border-radius: 999px;
  z-index: 99;
  font-size: 0.95rem;
  box-shadow: var(--shadow);
  max-width: 90%;
  text-align: center;
}
