/* جِسر — تصميم عصري: خلفية متدرّجة ناعمة، رأس زجاجي، فقاعات مستديرة، حركة خفيفة */
:root {
  --bg: #eef3f3;
  --bg-glow-1: rgba(45, 212, 191, .35);
  --bg-glow-2: rgba(99, 102, 241, .18);
  --card: #ffffff;
  --card-glass: rgba(255,255,255,.72);
  --text: #0f1f24;
  --muted: #65767c;
  --line: rgba(15, 31, 36, .08);
  --accent: #0d9488;
  --accent-2: #14b8a6;
  --accent-ink: #ffffff;
  --accent-soft: #d9f3ef;
  --mine: linear-gradient(135deg, #dff7f2, #e8f1ff);
  --danger: #dc2626;
  --ok: #22c55e;
  --shadow: 0 1px 2px rgba(15,31,36,.05), 0 8px 24px -12px rgba(15,31,36,.18);
  --radius: 18px;
  --radius-sm: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a1113;
    --bg-glow-1: rgba(20, 184, 166, .22);
    --bg-glow-2: rgba(99, 102, 241, .16);
    --card: #121c1f;
    --card-glass: rgba(18,28,31,.72);
    --text: #e7eeee;
    --muted: #8da0a4;
    --line: rgba(231,238,238,.08);
    --accent: #2dd4bf;
    --accent-2: #5eead4;
    --accent-ink: #04201d;
    --accent-soft: #113a37;
    --mine: linear-gradient(135deg, #10302e, #16243a);
    --danger: #f87171;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 12px 30px -14px rgba(0,0,0,.6);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(900px 500px at 85% -10%, var(--bg-glow-1), transparent 60%),
    radial-gradient(700px 500px at -10% 110%, var(--bg-glow-2), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  font-family: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.err { color: var(--danger); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
::selection { background: var(--accent-soft); }

/* ---------- الدخول ---------- */
#login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 400px; background: var(--card-glass); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--line); border-radius: 28px; box-shadow: var(--shadow);
  padding: 40px 30px 32px; text-align: center; animation: rise .5s cubic-bezier(.2,.8,.2,1);
}
@keyframes rise { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
.login-card .logo { width: 84px; height: 84px; border-radius: 22px; box-shadow: 0 10px 30px -10px rgba(13,148,136,.6); }
.login-card h1 { margin: 14px 0 4px; font-size: 34px; letter-spacing: -.5px; }
.lead { color: var(--muted); margin: 0 0 26px; font-size: 15px; }
.gsi { display: flex; justify-content: center; min-height: 44px; }
.legal { margin: 22px 0 0; line-height: 1.7; }
.menu-item.small { font-size: 12px; }
a.menu-item { text-decoration: none; color: inherit; }
.dev-form { margin-top: 20px; text-align: start; padding-top: 16px; border-top: 1px dashed var(--line); }
.dev-form label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; min-width: 0; }
input[type=email], textarea, select {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 14px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.btn { border: 0; border-radius: var(--radius-sm); padding: 10px 18px; background: var(--accent-soft); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--accent-ink); font-weight: 600; }

/* ---------- الهيكل ---------- */
#app { height: 100dvh; display: flex; flex-direction: column; max-width: 880px; margin: 0 auto; }
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 14px; background: var(--card-glass); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { width: 38px; height: 38px; border-radius: 11px; }
.brand .title { font-weight: 700; font-size: 18px; line-height: 1.2; letter-spacing: -.2px; }
.devices { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 48vw; }
.devices .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); margin-inline-end: 5px; vertical-align: middle; box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 20%, transparent); }
.devices.off .dot { background: #9ca3af; box-shadow: none; }
.actions { display: flex; align-items: center; gap: 6px; position: relative; }
.chip {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 5px 12px; font-size: 12px;
  max-width: 160px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: background .15s;
}
.chip:hover { background: var(--accent-soft); }
.icon-btn {
  border: 0; background: transparent; width: 42px; height: 42px; border-radius: 50%; font-size: 20px;
  display: inline-grid; place-items: center; transition: background .15s, transform .1s;
}
.icon-btn:hover { background: var(--accent-soft); }
.icon-btn:active { transform: scale(.94); }
.menu {
  position: absolute; top: 48px; inset-inline-end: 0; width: 300px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 8px; z-index: 20; animation: rise .18s ease-out;
}
.menu-head { display: flex; align-items: center; gap: 10px; padding: 8px 10px 12px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.avatar { width: 38px; height: 38px; border-radius: 50%; }
.me-name { font-weight: 600; }
.menu-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; font-size: 14px; }
.menu-row select { padding: 6px 10px; font-size: 13px; }
.menu-item { display: block; width: 100%; text-align: start; border: 0; background: transparent; padding: 10px; border-radius: var(--radius-sm); font-size: 14px; }
.menu-item:hover { background: var(--accent-soft); }
.menu-item.danger { color: var(--danger); }

/* ---------- شريط المحادثات ---------- */
.convs {
  display: flex; gap: 6px; align-items: center; padding: 8px 12px; overflow-x: auto; scrollbar-width: none;
  background: var(--card-glass); border-bottom: 1px solid var(--line); backdrop-filter: blur(12px);
}
.convs::-webkit-scrollbar { display: none; }
.conv {
  flex: none; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--card);
  border-radius: 999px; padding: 5px 12px; font-size: 13px; max-width: 200px; white-space: nowrap; transition: background .15s, border-color .15s;
}
.conv .cname { overflow: hidden; text-overflow: ellipsis; }
.conv:hover { background: var(--accent-soft); }
.conv.active { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.conv.pending { border-style: dashed; color: var(--muted); }
.conv.gone { opacity: .6; text-decoration: line-through; }
.conv .badge { background: var(--danger); color: #fff; border-radius: 999px; font-size: 11px; min-width: 18px; height: 18px; display: inline-grid; place-items: center; padding: 0 5px; font-weight: 700; }
.conv .tag { font-size: 11px; background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 1px 7px; }
.conv.active .tag { background: rgba(255,255,255,.25); color: inherit; }
.conv.add { width: 34px; height: 34px; padding: 0; justify-content: center; font-size: 20px; border-style: dashed; }

/* ---------- لافتة حالة المحادثة ---------- */
.notice {
  margin: 10px 14px 0; padding: 12px 14px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line);
  box-shadow: var(--shadow); font-size: 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; animation: rise .25s ease-out;
}
.notice .grow { flex: 1; min-width: 200px; }
.notice .btn { padding: 7px 14px; font-size: 13px; }
.notice .btn.ghost { background: transparent; border: 1px solid var(--line); }
.notice .btn.danger { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }

/* ---------- القائمة ---------- */
.list { flex: 1; overflow-y: auto; padding: 16px 14px 10px; display: flex; flex-direction: column; gap: 10px; scroll-behavior: smooth; overscroll-behavior: contain; }
.empty { margin: auto; text-align: center; color: var(--muted); max-width: 380px; animation: rise .5s ease-out; }
.empty-icon { font-size: 60px; filter: drop-shadow(0 10px 20px rgba(13,148,136,.25)); }
.day { align-self: center; font-size: 12px; color: var(--muted); background: var(--card-glass); border: 1px solid var(--line); border-radius: 999px; padding: 2px 12px; margin: 6px 0; backdrop-filter: blur(8px); }
.item {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px 14px 8px;
  max-width: min(92%, 680px); align-self: flex-start; animation: pop .22s cubic-bezier(.2,.8,.2,1);
  border-start-start-radius: 6px;
}
.item.mine { align-self: flex-end; background: var(--mine); border-start-start-radius: var(--radius); border-start-end-radius: 6px; }
.item .from { font-size: 12px; font-weight: 600; color: var(--accent); margin-bottom: 2px; }
.composer.disabled { opacity: .55; pointer-events: none; }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }
.item .text { white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; font-size: 15px; }
.item .text.clamp { max-height: 10.5em; overflow: hidden; -webkit-mask-image: linear-gradient(#000 70%, transparent); mask-image: linear-gradient(#000 70%, transparent); }
.more { border: 0; background: transparent; color: var(--accent); padding: 2px 0; font-size: 13px; font-weight: 600; }
.file { display: flex; align-items: center; gap: 12px; }
.file .ficon { font-size: 26px; width: 48px; height: 48px; display: grid; place-items: center; background: var(--accent-soft); border-radius: 14px; flex: none; }
.file .fname { font-weight: 600; word-break: break-all; }
.file .fmeta { font-size: 12px; color: var(--muted); }
.thumb { display: block; max-width: 100%; max-height: 320px; border-radius: 12px; margin-bottom: 8px; cursor: zoom-in; }
.meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.meta .tools { display: flex; gap: 2px; }
.tool { border: 0; background: transparent; padding: 3px 8px; border-radius: 8px; font-size: 13px; color: var(--muted); text-decoration: none; transition: background .12s, color .12s; }
.tool:hover { background: rgba(127,127,127,.12); color: var(--text); }
.tool.del:hover, .tool.confirm { color: var(--danger); }
.tool.confirm { background: color-mix(in srgb, var(--danger) 12%, transparent); font-weight: 600; }

/* ---------- السحب ---------- */
.drop {
  position: fixed; inset: 10px; z-index: 50; background: color-mix(in srgb, var(--accent) 14%, transparent); backdrop-filter: blur(3px);
  display: grid; place-items: center; font-size: 26px; font-weight: 700; color: var(--accent);
  border: 3px dashed var(--accent); border-radius: 24px; pointer-events: none;
}

/* ---------- المُنشئ ---------- */
.composer {
  background: var(--card-glass); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line); padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  position: sticky; bottom: 0;
}
.uploads { display: flex; flex-direction: column; gap: 6px; }
.uploads:not(:empty) { margin-bottom: 8px; }
.up { font-size: 13px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 6px 12px; }
.up .bar { height: 4px; background: var(--line); border-radius: 2px; margin-top: 5px; overflow: hidden; }
.up .bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .15s; }
.compose-row { display: flex; align-items: flex-end; gap: 8px; }
.attach { cursor: pointer; }
#text { flex: 1; resize: none; max-height: 40vh; min-height: 44px; line-height: 1.5; border-radius: 22px; padding: 10px 16px; }
.send { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--accent-ink); font-size: 18px; box-shadow: 0 6px 16px -6px rgba(13,148,136,.7); }
.send:hover { filter: brightness(1.06); background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.send:disabled { opacity: .5; cursor: default; }

/* ---------- حوار المسموح لهم ---------- */
.dlg { border: 1px solid var(--line); border-radius: 22px; padding: 20px 22px; width: min(92vw, 460px); background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.dlg::backdrop { background: rgba(0,0,0,.35); backdrop-filter: blur(2px); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; margin: 0 0 6px; }
.dlg-head h2 { font-size: 18px; margin: 0; }
.dlg .row { margin: 12px 0; }
.allowed-list { list-style: none; margin: 0; padding: 0; max-height: 46vh; overflow-y: auto; }
.allowed-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 4px; border-top: 1px solid var(--line); font-size: 14px; }
.allowed-list .who { min-width: 0; overflow: hidden; text-overflow: ellipsis; direction: ltr; text-align: start; }
.allowed-list .kind { font-size: 11px; color: var(--muted); background: var(--accent-soft); border-radius: 999px; padding: 1px 8px; flex: none; }

/* ---------- تنبيه ---------- */
.toast {
  position: fixed; bottom: 96px; inset-inline: 0; margin: auto; width: max-content; max-width: 90vw;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; z-index: 100; font-size: 14px;
  box-shadow: var(--shadow); animation: rise .2s ease-out;
}

@media (max-width: 520px) {
  .chip { display: none; }
  .item { max-width: 96%; }
  .devices { max-width: 56vw; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
