/* ============================================================
   Enigma Connect — الهوية البصرية الداكنة الجيوفيزيائية
   تدعم الاتجاهين RTL/LTR عبر الخصائص المنطقية (inline-start/end)
   ============================================================ */

:root {
  --bg0: #05080D;
  --bg1: #0A1018;
  --bg2: #0F1826;
  --bg3: #141F30;
  --line: #1D2A3C;
  --txt: #E8F1FA;
  --mut: #8CA3BD;
  --cyan: #22D3EE;
  --green: #4ADE80;
  --grad: linear-gradient(135deg, #22D3EE, #4ADE80);
  --danger: #F87171;
  --warn: #FBBF24;
  --r: 14px;
  --shadow: 0 10px 40px rgba(0, 0, 0, .45);
}

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

html, body {
  height: 100%;
  background: var(--bg0);
  color: var(--txt);
  font-family: 'Cairo', 'Segoe UI', Tahoma, Arial, sans-serif;
  font-size: 15.5px;
  overflow: hidden;
}

button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }
.hidden { display: none !important; }
.muted { color: var(--mut); }
.small { font-size: .82rem; }
.center { text-align: center; }
.w100 { width: 100%; }
.grow { flex: 1; }

/* ============ الخلفية الزلزالية ============ */
.bg-fx { position: fixed; inset: 0; z-index: 0; pointer-events: none; }
.bg-wave { position: absolute; inset-inline: 0; width: 100%; height: 300px; opacity: .8; }
.bg-wave.w1 { top: 12%; animation: drift 26s ease-in-out infinite alternate; }
.bg-wave.w2 { bottom: 10%; animation: drift 34s ease-in-out infinite alternate-reverse; }
@keyframes drift { from { transform: translateX(0); } to { transform: translateX(-40px); } }
.glow { position: absolute; border-radius: 50%; filter: blur(90px); }
.glow.g1 { width: 420px; height: 420px; background: rgba(34, 211, 238, .10); top: -120px; inset-inline-start: -80px; }
.glow.g2 { width: 380px; height: 380px; background: rgba(74, 222, 128, .08); bottom: -120px; inset-inline-end: -60px; }

/* ============ نظام الشاشات ============ */
.screen {
  position: fixed; inset: 0; z-index: 1;
  display: none;
  align-items: center; justify-content: center;
  padding: 18px;
}
.screen.active { display: flex; }

/* ============ شاشة الافتتاح ============ */
.splash-inner { text-align: center; max-width: 460px; }
.logo-svg { width: min(340px, 80vw); }
.logo-svg .draw {
  stroke-dasharray: 420; stroke-dashoffset: 420;
  animation: draw 1.6s ease forwards;
}
@keyframes draw { to { stroke-dashoffset: 0; } }
.lock-g { animation: lockIn .8s .9s ease both; transform-origin: 282px 99px; }
@keyframes lockIn { from { opacity: 0; transform: scale(.7); } to { opacity: 1; transform: scale(1); } }
.pulse { animation: pulse 1.8s 1.6s ease-in-out infinite; transform-origin: center; }
@keyframes pulse { 0%, 100% { opacity: .4; r: 3; } 50% { opacity: 1; r: 5; } }

.splash-title { font-size: 2rem; font-weight: 800; margin-top: 6px; letter-spacing: .5px; }
.splash-title span { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.splash-tag { color: var(--mut); margin-top: 6px; font-size: .95rem; }
.splash-bar {
  margin: 26px auto 0; width: 220px; height: 4px;
  background: var(--bg3); border-radius: 4px; overflow: hidden;
}
.splash-bar i {
  display: block; height: 100%; width: 40%;
  background: var(--grad); border-radius: 4px;
  animation: slide 1.1s ease-in-out infinite;
}
@keyframes slide { 0% { transform: translateX(-160%); } 100% { transform: translateX(360%); } }

/* ============ بطاقة الدخول ============ */
.auth-card {
  position: relative; z-index: 1;
  width: min(420px, 94vw);
  max-height: 92vh; overflow-y: auto;
  background: linear-gradient(160deg, rgba(15, 24, 38, .92), rgba(10, 16, 24, .94));
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px 26px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  animation: rise .5s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.logo-sm { width: 150px; display: block; margin: 0 auto 10px; }

.auth-banner {
  background: rgba(251, 191, 36, .1);
  border: 1px solid rgba(251, 191, 36, .35);
  color: var(--warn);
  border-radius: 10px; padding: 10px 12px;
  font-size: .82rem; margin-bottom: 14px;
}

.lang-row { display: flex; gap: 6px; justify-content: center; margin: 10px 0 16px; }
.lang-row button {
  background: var(--bg2); color: var(--mut);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 14px; font-size: .8rem; font-weight: 600;
  transition: all .2s;
}
.lang-row button.active { background: var(--grad); color: #06251F; border-color: transparent; }
.lang-row.compact { margin: 0; }
.lang-row.compact button { padding: 3px 10px; font-size: .72rem; }

.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg1); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 18px; }
.auth-tabs button {
  background: transparent; border: 0; color: var(--mut);
  padding: 9px; border-radius: 9px; font-weight: 700; transition: all .2s;
}
.auth-tabs button.active { background: var(--grad); color: #06251F; }

form label { display: block; margin-bottom: 13px; }
form label span { display: block; font-size: .8rem; color: var(--mut); margin-bottom: 5px; font-weight: 600; }

input, textarea {
  width: 100%;
  background: var(--bg1);
  border: 1px solid var(--line);
  color: var(--txt);
  border-radius: 11px;
  padding: 11px 13px;
  font-size: .95rem;
  outline: none;
  transition: border .2s, box-shadow .2s;
}
input:focus, textarea:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, .15);
}
input[type="search"] { margin-bottom: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--bg2); color: var(--txt);
  border-radius: 11px; padding: 11px 18px;
  font-weight: 700; font-size: .92rem;
  transition: transform .15s, box-shadow .2s, background .2s;
}
.btn:hover { transform: translateY(-1px); }
.btn.primary { background: var(--grad); border: 0; color: #06251F; }
.btn.primary:hover { box-shadow: 0 6px 22px rgba(34, 211, 238, .3); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--bg2); }
.btn.danger-ghost { background: transparent; color: var(--danger); border-color: rgba(248, 113, 113, .35); }
.btn.tiny { padding: 6px 12px; font-size: .78rem; border-radius: 8px; }
.btn.tiny.grad { background: var(--grad); border: 0; color: #06251F; }
.btn.tiny.ok { background: rgba(74, 222, 128, .15); color: var(--green); border-color: rgba(74, 222, 128, .4); }
.btn.tiny.danger { background: rgba(248, 113, 113, .12); color: var(--danger); border-color: rgba(248, 113, 113, .35); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

.auth-msg { min-height: 22px; font-size: .84rem; margin-top: 8px; color: var(--danger); }
.auth-msg.ok { color: var(--green); }

.unlock-icon { font-size: 2.6rem; text-align: center; margin-bottom: 8px; }
.un-user { text-align: center; color: var(--cyan); font-weight: 700; margin: 10px 0 14px; }
.row-between { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-top: 14px; flex-wrap: wrap; }
.row-between.justify-center { justify-content: center; }

/* ============ هيكل التطبيق ============ */
#screen-app { padding: 0; flex-direction: column; align-items: stretch; justify-content: flex-start; }

.app-header {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: rgba(10, 16, 24, .85);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.brand-txt { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-txt strong { font-size: .98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-txt small { color: var(--mut); font-size: .7rem; letter-spacing: 1.5px; }

.hd-actions { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  background: var(--bg2); border: 1px solid var(--line);
  color: var(--txt); width: 38px; height: 38px;
  border-radius: 10px; font-size: 1.05rem;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .2s;
}
.icon-btn:hover { background: var(--bg3); }

.avatar { width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0; }
.avatar.sm { width: 32px; height: 32px; }

.layout { flex: 1; display: grid; grid-template-columns: 330px 1fr; min-height: 0; }

/* ============ الشريط الجانبي ============ */
.sidebar {
  background: rgba(10, 16, 24, .7);
  border-inline-end: 1px solid var(--line);
  display: flex; flex-direction: column;
  min-height: 0;
}
.sb-tabs { display: flex; border-bottom: 1px solid var(--line); }
.sb-tabs button {
  flex: 1; background: transparent; border: 0;
  color: var(--mut); padding: 13px 6px;
  font-weight: 700; font-size: .85rem;
  border-bottom: 2px solid transparent;
  transition: all .2s;
}
.sb-tabs button.active { color: var(--cyan); border-bottom-color: var(--cyan); background: rgba(34, 211, 238, .05); }

.pn { flex: 1; overflow-y: auto; padding: 12px; min-height: 0; }
.pn h4 { color: var(--mut); font-size: .78rem; letter-spacing: .5px; margin: 16px 4px 10px; text-transform: uppercase; }
.pn h4:first-child { margin-top: 2px; }

.list { display: flex; flex-direction: column; gap: 6px; }

.empty { color: var(--mut); text-align: center; padding: 26px 12px; font-size: .88rem; }
.empty.pad { padding: 50px 30px; }

.conv-item, .member-item {
  display: flex; align-items: center; gap: 11px;
  width: 100%; text-align: start;
  background: transparent; border: 1px solid transparent;
  border-radius: 12px; padding: 10px;
  color: var(--txt); transition: background .15s;
}
.conv-item:hover, .member-item:hover { background: var(--bg2); }
.conv-item.active { background: rgba(34, 211, 238, .09); border-color: rgba(34, 211, 238, .25); }

.conv-mid { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.conv-name { font-weight: 700; font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-name small { color: var(--mut); font-weight: 400; }
.conv-preview {
  color: var(--mut); font-size: .8rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-side { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.conv-time { color: var(--mut); font-size: .68rem; }
.badge {
  background: var(--grad); color: #06251F;
  font-size: .68rem; font-weight: 800;
  border-radius: 999px; padding: 1px 7px;
}
.member-arrow { color: var(--mut); font-size: 1.2rem; }

/* لوحة الأدمن */
.new-code {
  background: rgba(74, 222, 128, .08);
  border: 1px dashed rgba(74, 222, 128, .45);
  border-radius: 12px; padding: 12px;
  margin: 10px 0; text-align: center;
  display: flex; flex-direction: column; gap: 8px;
}
.new-code code { font-size: 1.15rem; color: var(--green); font-weight: 700; letter-spacing: 1px; }
.new-code small { color: var(--mut); font-size: .72rem; }

.code-item {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg2); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 10px;
}
.code-item code { flex: 1; font-size: .8rem; color: var(--txt); }
.chip { font-size: .68rem; border-radius: 999px; padding: 2px 9px; font-weight: 700; }
.chip.used { background: rgba(140, 163, 189, .15); color: var(--mut); }
.chip.ok { background: rgba(74, 222, 128, .15); color: var(--green); }
.chip.expired { background: rgba(251, 191, 36, .12); color: var(--warn); }
.mini-copy {
  background: var(--bg3); border: 1px solid var(--line); color: var(--txt);
  border-radius: 7px; width: 28px; height: 28px; font-size: .85rem;
}

.pending-item {
  display: flex; align-items: center; gap: 9px;
  background: var(--bg2); border: 1px solid var(--line);
  border-radius: 12px; padding: 9px 10px; flex-wrap: wrap;
}
.pending-item .btn { flex-shrink: 0; }

/* ============ منطقة المحادثة ============ */
.chat-pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; position: relative; }

.chat-empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; padding: 30px; gap: 8px;
  max-width: 480px; margin: 0 auto;
}
.chat-empty .big-wave { width: 240px; opacity: .9; }
.chat-empty h3 { font-size: 1.25rem; }
.chat-empty p { color: var(--mut); font-size: .92rem; line-height: 1.8; }

#chat-main { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.chat-header {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 16px;
  background: rgba(10, 16, 24, .85);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.ch-meta { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; flex: 1; }
.ch-meta strong { font-size: .98rem; }
.ch-status { color: var(--mut); font-size: .74rem; }
.ch-status.online { color: var(--green); }
.ch-status.typing { color: var(--cyan); }

.fp-chip {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg2); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 12px;
}
.fp-chip code { font-size: .7rem; color: var(--mut); letter-spacing: .5px; }

#btn-back { display: none; }

.msgs {
  flex: 1; overflow-y: auto; padding: 18px 18px 8px;
  display: flex; flex-direction: column; gap: 4px;
  min-height: 0;
}

.day-sep { text-align: center; margin: 12px 0 8px; }
.day-sep span {
  background: var(--bg2); color: var(--mut);
  font-size: .72rem; border-radius: 999px; padding: 3px 14px;
  border: 1px solid var(--line);
}

.bubble-row { display: flex; }
.bubble-row.me { justify-content: flex-end; }
.bubble-row.them { justify-content: flex-start; }

.bubble {
  max-width: 78%;
  border-radius: 16px;
  padding: 9px 13px 6px;
  margin-bottom: 6px;
  animation: bubbleIn .22s ease;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
@keyframes bubbleIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.bubble-row.me .bubble {
  background: var(--grad);
  color: #05231C;
  border-end-inline-end-radius: 5px;
}
.bubble-row.them .bubble {
  background: var(--bg3);
  border: 1px solid var(--line);
  border-end-inline-start-radius: 5px;
}
.bubble-text { font-size: .95rem; line-height: 1.65; white-space: pre-wrap; }
.bubble-meta {
  display: flex; align-items: center; justify-content: flex-end; gap: 5px;
  font-size: .66rem; opacity: .75; margin-top: 3px;
}
.rcpt { font-size: .72rem; }
.rcpt.seen { color: #0B4F3B; font-weight: 800; }
.bubble-row.them .rcpt { color: var(--cyan); }
.locked { font-size: 1rem; }

/* ============ شريط الكتابة ============ */
.composer {
  display: flex; align-items: flex-end; gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: rgba(10, 16, 24, .9);
  border-top: 1px solid var(--line);
}
.composer textarea {
  resize: none; max-height: 120px; min-height: 44px;
  border-radius: 14px;
}
.send-btn {
  width: 46px; height: 46px; border-radius: 50%;
  background: var(--grad); color: #06251F;
  border: 0; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: transform .15s, box-shadow .2s;
}
.send-btn:hover { transform: scale(1.06); box-shadow: 0 6px 20px rgba(34, 211, 238, .35); }
.send-btn:active { transform: scale(.95); }

/* ============ المودالات ============ */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(3, 6, 10, .65);
  backdrop-filter: blur(6px);
  display: none; align-items: center; justify-content: center;
  padding: 16px;
}
.modal.open { display: flex; }
.modal-panel {
  width: min(430px, 94vw);
  max-height: 88vh; overflow-y: auto;
  background: linear-gradient(160deg, var(--bg2), var(--bg1));
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 22px;
  box-shadow: var(--shadow);
  animation: rise .3s ease;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.modal-head h3 { font-size: 1.1rem; }
.modal-panel h4 {
  color: var(--mut); font-size: .78rem; letter-spacing: .5px;
  margin: 18px 0 9px; text-transform: uppercase;
}
.stack label, label.stack { display: block; margin-bottom: 10px; }
.stack span { display: block; font-size: .8rem; color: var(--mut); margin-bottom: 5px; }

.fp-big {
  display: block; text-align: center;
  background: var(--bg1); border: 1px dashed var(--line);
  border-radius: 10px; padding: 10px;
  color: var(--cyan); font-size: .95rem; letter-spacing: 2px;
}

.av-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.av-opt {
  background: transparent; border: 2px solid transparent;
  border-radius: 50%; padding: 2px; line-height: 0;
  transition: border .15s, transform .15s;
}
.av-opt:hover { transform: scale(1.08); }
.av-opt.sel { border-color: var(--cyan); }

/* ============ التوست ============ */
.toasts {
  position: fixed; bottom: 18px; inset-inline-start: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex; flex-direction: column; gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  background: var(--bg3); color: var(--txt);
  border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 18px;
  font-size: .86rem; font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0; transform: translateY(8px);
  transition: all .3s ease;
  max-width: 88vw;
}
.toast.show { opacity: 1; transform: none; }
.toast.ok { border-color: rgba(74, 222, 128, .5); }
.toast.err { border-color: rgba(248, 113, 113, .5); }

/* ============ أشرطة التمرير ============ */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 9px; }
::-webkit-scrollbar-thumb:hover { background: var(--line); }

/* ============ الجوال ============ */
@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; }

  .sidebar { width: 100%; }
  .chat-pane {
    position: fixed; inset: 0; z-index: 20;
    background: var(--bg0);
    transform: translateX(-102%);
    transition: transform .28s ease;
  }
  html[dir="rtl"] .chat-pane { transform: translateX(102%); }
  #screen-app.chat-open .chat-pane { transform: translateX(0) !important; }

  #btn-back { display: inline-flex; }
  .fp-chip { display: none; }
  .bubble { max-width: 86%; }
  .brand-txt small { display: none; }
  .lang-row.compact button { padding: 3px 8px; }
}

@media (max-width: 480px) {
  .av-grid { grid-template-columns: repeat(4, 1fr); }
  .app-header { padding: 8px 10px; }
  .lang-row.compact button[data-lang-btn="ar"] { display: none; }
}

/* تقليل الحركة لمن يفضلها */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
