@font-face {
  font-family: 'Plex Arabic';
  font-weight: 400;
  font-display: swap;
  src: url(/fonts/plex-arabic-400.woff2) format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FEFC;
}
@font-face {
  font-family: 'Plex Arabic';
  font-weight: 500;
  font-display: swap;
  src: url(/fonts/plex-arabic-500.woff2) format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FEFC;
}
@font-face {
  font-family: 'Plex Arabic';
  font-weight: 600;
  font-display: swap;
  src: url(/fonts/plex-arabic-600.woff2) format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FEFC;
}
@font-face {
  font-family: 'Plex Arabic';
  font-weight: 400;
  font-display: swap;
  src: url(/fonts/plex-latin-400.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212;
}
@font-face {
  font-family: 'Plex Arabic';
  font-weight: 500;
  font-display: swap;
  src: url(/fonts/plex-latin-500.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212;
}
@font-face {
  font-family: 'Plex Arabic';
  font-weight: 600;
  font-display: swap;
  src: url(/fonts/plex-latin-600.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212;
}

:root {
  --bg: #e8ecea;
  --panel: #ffffff;
  --panel-2: #f5f6f6;
  --chat-bg: #efeae2;
  --text: #111b21;
  --muted: #667781;
  --line: #e4e8e6;
  --accent: #128c5e;
  --accent-2: #1fa874;
  --accent-ink: #ffffff;
  --accent-soft: #e2f5ec;
  --bubble-in: #ffffff;
  --bubble-out: #d9fdd3;
  --hover: #f3f5f4;
  --active: #e8eceb;
  --danger: #d33f49;
  --warn: #c97a12;
  --read: #2fa3e6;
  --shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
  --overlay: rgba(11, 20, 26, 0.45);
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a1014;
    --panel: #111b21;
    --panel-2: #1d282f;
    --chat-bg: #0b141a;
    --text: #e9edef;
    --muted: #8d9ca6;
    --line: #233138;
    --accent: #21b37a;
    --accent-2: #27c486;
    --accent-ink: #062016;
    --accent-soft: #12352a;
    --bubble-in: #1f2c33;
    --bubble-out: #035c47;
    --hover: #1b262c;
    --active: #25333b;
    --danger: #ef6b73;
    --warn: #e7a33e;
    --read: #53bdeb;
    --shadow: 0 1px 0.5px rgba(0, 0, 0, 0.35);
    --overlay: rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: 'Plex Arabic', 'Segoe UI', Tahoma, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button, a, input, textarea, select, .chat-item { touch-action: manipulation; }
a { color: var(--accent); }
[hidden] { display: none !important; }
svg { flex-shrink: 0; }

.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
.flip { transform: scaleX(-1); }

/* ---------- عناصر عامة ---------- */

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  position: relative;
}
.icon-btn:hover { background: var(--active); color: var(--text); }
.icon-btn:focus-visible, .btn:focus-visible, .chip:focus-visible, .chat-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.icon-btn .dot {
  position: absolute;
  top: 7px;
  inset-inline-end: 7px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--warn);
  border: 2px solid var(--panel-2);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 16px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-weight: 500;
  font-size: 14px;
  white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn:disabled { opacity: 0.55; cursor: default; }

.input {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  outline: none;
}
.input:focus { border-color: var(--accent); }

.badge {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--accent-2);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 96px;
  padding: 0 7px;
  height: 19px;
  border-radius: 10px;
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--tag);
  background: color-mix(in srgb, var(--tag) 14%, transparent);
  flex-shrink: 0;
}

/* ---------- التخطيط ---------- */

.app {
  display: grid;
  grid-template-columns: minmax(320px, 420px) 1fr;
  grid-template-rows: minmax(0, 1fr);
  height: var(--app-h, 100vh);
  max-width: 1600px;
  margin: 0 auto;
  background: var(--panel);
  box-shadow: 0 0 0 1px var(--line);
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border-inline-end: 1px solid var(--line);
  background: var(--panel);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 60px;
  padding: 0 12px 0 8px;
  background: var(--panel-2);
  flex-shrink: 0;
}
.topbar .title {
  flex: 1;
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.menu-wrap { position: relative; }
.menu {
  position: absolute;
  top: 44px;
  inset-inline-end: 0;
  z-index: 20;
  min-width: 210px;
  padding: 6px 0;
  border-radius: 10px;
  background: var(--panel);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18), 0 0 0 1px var(--line);
}
.menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 16px;
  border: 0;
  background: none;
  text-align: start;
}
.menu button:hover { background: var(--hover); }
.menu button .grow { flex: 1; }
.menu button small { color: var(--muted); font-size: 12.5px; }

.option-list { display: grid; gap: 6px; }
.option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  font-size: 15px;
  text-align: start;
}
.option:hover { background: var(--hover); }
.option.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.steps-list { display: grid; gap: 10px; margin: 0; padding-inline-start: 22px; font-size: 15px; line-height: 1.7; }
.steps-list svg { vertical-align: -3px; color: var(--read); }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 12px 6px;
  flex-shrink: 0;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 11px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  color: var(--muted);
}
.chip:hover { background: var(--hover); }
.chip.on { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.chip .swatch { width: 9px; height: 9px; border-radius: 50%; background: var(--tag); }
.chip .swatch.off { background: transparent; box-shadow: inset 0 0 0 2px var(--tag); }
.chip .badge { height: 18px; min-width: 18px; font-size: 11px; }

.search {
  position: relative;
  padding: 6px 12px 8px;
  flex-shrink: 0;
}
.search svg { position: absolute; inset-inline-start: 24px; top: 16px; color: var(--muted); pointer-events: none; }
.search input {
  width: 100%;
  height: 36px;
  padding: 0 44px 0 12px;
  padding-inline-start: 44px;
  padding-inline-end: 12px;
  border: 0;
  border-radius: 8px;
  background: var(--panel-2);
  outline: none;
}

.alert {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 2px 12px 8px;
  padding: 10px 12px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--warn) 13%, transparent);
  font-size: 13.5px;
}
.alert .grow { flex: 1; }
.alert .btn { min-height: 30px; padding: 0 12px; font-size: 13px; }
.alert.info { background: var(--accent-soft); }

.chat-list {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 0 12px;
  border: 0;
  background: none;
  text-align: start;
}
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--active); }
.chat-item .body {
  flex: 1;
  min-width: 0;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}
.chat-item .row { display: flex; align-items: center; gap: 6px; min-width: 0; }
.chat-item .name {
  flex: 1;
  min-width: 0;
  font-size: 15.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item .time { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.chat-item.unread .time { color: var(--accent-2); font-weight: 600; }
.chat-item .preview {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 3px;
  color: var(--muted);
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
}
.chat-item .preview span { overflow: hidden; text-overflow: ellipsis; }
.chat-item.unread .preview { color: var(--text); }

.avatar {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  flex-shrink: 0;
  color: #fff;
  font-weight: 600;
  font-size: 18px;
  background: var(--av, #8696a0);
  position: relative;
}
.avatar.sm { width: 40px; height: 40px; font-size: 16px; }
.avatar .ring {
  position: absolute;
  bottom: -1px;
  inset-inline-end: -1px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--tag);
  border: 2.5px solid var(--panel);
}

.empty-list {
  padding: 48px 24px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

/* ---------- المحادثة ---------- */

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--chat-bg);
  position: relative;
}

.welcome {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 32px;
  text-align: center;
  color: var(--muted);
  background: var(--panel-2);
  border-bottom: 6px solid var(--accent);
}
.welcome h1 { margin: 18px 0 8px; font-size: 26px; font-weight: 500; color: var(--text); }
.welcome p { margin: 0 auto; max-width: 440px; font-size: 14px; }
.welcome .stats { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 22px; }
.welcome .stat {
  display: flex;
  border: 0;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  font-size: 13.5px;
  box-shadow: 0 0 0 1px var(--line);
}
.welcome .stat .state { color: var(--muted); font-size: 12.5px; }

.chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 60px;
  padding: 0 12px;
  background: var(--panel-2);
  flex-shrink: 0;
  z-index: 2;
}
.chat-head .who { flex: 1; min-width: 0; }
.chat-head .who .name { font-weight: 500; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .who .sub { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.chat-head .back { display: none; }

.messages {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 6% 8px;
  display: flex;
  flex-direction: column;
}
.messages .older { align-self: center; margin: 4px 0 10px; }

.day {
  align-self: center;
  margin: 10px 0 8px;
  padding: 4px 12px;
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  font-size: 12.5px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 4px;
  z-index: 1;
}

.msg {
  display: flex;
  margin-top: 2px;
}
.msg.first { margin-top: 8px; }
.msg.out { justify-content: flex-end; }

.bubble {
  position: relative;
  max-width: min(78%, 560px);
  padding: 6px 9px 7px;
  border-radius: 9px;
  background: var(--bubble-in);
  box-shadow: var(--shadow);
  overflow-wrap: anywhere;
  font-size: 14.5px;
  line-height: 1.55;
}
.msg.out .bubble { background: var(--bubble-out); }
.msg.in.first .bubble { border-start-start-radius: 0; }
.msg.out.first .bubble { border-start-end-radius: 0; }
.bubble .sender { font-size: 13px; font-weight: 600; margin-bottom: 1px; }
.bubble .text { white-space: pre-wrap; }
.bubble .deleted { color: var(--muted); font-style: italic; }
.bubble .quote {
  margin: 2px 0 5px;
  padding: 5px 9px;
  border-inline-start: 4px solid var(--accent-2);
  border-radius: 6px;
  background: color-mix(in srgb, var(--text) 6%, transparent);
  color: var(--muted);
  font-size: 13px;
  white-space: pre-wrap;
  max-height: 64px;
  overflow: hidden;
}
.bubble .meta {
  float: inline-end;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-inline-start: 10px;
  margin-top: 6px;
  margin-bottom: -4px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  position: relative;
  top: 3px;
}
.bubble .meta .tick { color: var(--muted); }
.bubble .meta .tick.read { color: var(--read); }
.bubble .meta .tick.failed { color: var(--danger); }
.bubble::after { content: ''; display: block; clear: both; }

.bubble .media {
  display: block;
  margin: -2px -5px 4px;
  border-radius: 7px;
  overflow: hidden;
  background: color-mix(in srgb, var(--text) 8%, transparent);
}
.bubble .media img, .bubble .media video {
  display: block;
  width: 100%;
  max-width: 330px;
  max-height: 360px;
  min-height: 120px;
  object-fit: cover;
}
.bubble .media.placeholder {
  display: grid;
  place-items: center;
  width: 260px;
  max-width: 100%;
  height: 180px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 12px;
}
/* الملصق بدون فقاعة، والوقت فوقه في شريحة صغيرة مثل واتساب */
.msg .bubble.sticker { background: transparent; box-shadow: none; padding: 0; }
.bubble.sticker img { display: block; width: 150px; height: 150px; object-fit: contain; }
.bubble.sticker .meta {
  float: none;
  position: absolute;
  bottom: 4px;
  inset-inline-end: 4px;
  top: auto;
  margin: 0;
  padding: 1px 6px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 85%, transparent);
}
.bubble audio { display: block; width: 260px; max-width: 100%; height: 40px; margin: 2px 0; }

.file-card {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
  margin: 0 -3px 4px;
  padding: 10px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--text) 6%, transparent);
  color: inherit;
  text-decoration: none;
}
.file-card .ficon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 44px;
  border-radius: 6px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
}
.file-card .fname { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.file-card .fsize { font-size: 12px; color: var(--muted); }
.file-card .grow { flex: 1; min-width: 0; }

.loc { display: flex; align-items: center; gap: 8px; text-decoration: none; color: inherit; }
.loc .pin { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); }

.composer-wrap { background: var(--panel-2); flex-shrink: 0; }
.composer {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 8px 12px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}
.composer textarea {
  flex: 1;
  min-height: 42px;
  max-height: 160px;
  padding: 9px 14px;
  border: 0;
  border-radius: 21px;
  background: var(--panel);
  resize: none;
  outline: none;
  line-height: 1.5;
}
.composer .send { background: var(--accent); color: var(--accent-ink); width: 42px; height: 42px; }
.composer .send:hover { background: var(--accent-2); color: var(--accent-ink); }
.composer .send:disabled { opacity: 0.5; }
.icon-btn.on { color: var(--accent); }

.picker {
  display: flex;
  flex-direction: column;
  height: 300px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}
.picker-tabs {
  display: flex;
  gap: 2px;
  padding: 4px 8px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
  flex-shrink: 0;
}
.picker-tabs::-webkit-scrollbar { display: none; }
.picker-tabs button {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 40px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  filter: grayscale(0.7);
  opacity: 0.75;
}
.picker-tabs button.on { background: var(--accent-soft); color: var(--accent); filter: none; opacity: 1; }
.picker-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 0 10px 10px; }
.picker-title {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 8px 2px 6px;
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
}
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); }
.emoji-grid button {
  height: 42px;
  border: 0;
  border-radius: 8px;
  background: none;
  font-family: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif;
  font-size: 26px;
  line-height: 1;
}
.emoji-grid button:hover { background: var(--hover); }
.sticker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; }
.sticker-grid button {
  aspect-ratio: 1;
  padding: 6px;
  border: 0;
  border-radius: 10px;
  background: none;
}
.sticker-grid button:hover { background: var(--hover); }
.sticker-grid img { width: 100%; height: 100%; object-fit: contain; }
.sticker-grid .sticker-make {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: 2px dashed var(--line);
  color: var(--muted);
  font-size: 12px;
}
.picker-empty { padding: 16px 8px; color: var(--muted); font-size: 13.5px; text-align: center; }

.composer-note {
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
}
.composer-note .btn { margin-inline-start: 8px; min-height: 30px; font-size: 13px; }

.attach {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 12px 0;
  padding: 8px;
  border-radius: 10px;
  background: var(--panel);
}
.attach img { width: 52px; height: 52px; object-fit: cover; border-radius: 6px; }
.attach .ficon { width: 44px; height: 52px; }
.attach .info { flex: 1; min-width: 0; font-size: 13.5px; }
.attach .info .n { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.attach .info .s { color: var(--muted); font-size: 12px; }
.attach .ficon { display: grid; place-items: center; border-radius: 6px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 600; }

.drop-hint {
  position: absolute;
  inset: 60px 0 0;
  z-index: 5;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--panel) 85%, transparent);
  border: 3px dashed var(--accent);
  font-size: 18px;
  font-weight: 500;
  color: var(--accent);
}

/* ---------- النوافذ ---------- */

.modal-back {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--overlay);
}
.modal {
  width: 100%;
  max-width: 460px;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.3);
}
.modal.wide { max-width: 860px; }
.modal-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px 10px 10px;
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 1;
}
.modal-head h2 { flex: 1; margin: 0; font-size: 18px; font-weight: 600; }
.modal-body { padding: 4px 20px 20px; }
.modal-body p { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; margin-bottom: 5px; font-size: 13px; color: var(--muted); }
.form-error { color: var(--danger); font-size: 13.5px; }
.form-error:empty { display: none; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }

.numbers {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
@media (max-width: 700px) {
  .numbers { grid-template-columns: 1fr; }
}
.num-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  border-top: 4px solid var(--tag);
  background: var(--panel);
}
.num-card .head { display: flex; align-items: center; gap: 8px; }
.num-card .label-input {
  flex: 1;
  min-width: 0;
  height: 34px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  font-size: 16px;
  font-weight: 600;
}
.num-card .label-input:hover, .num-card .label-input:focus { border-color: var(--line); outline: none; background: var(--panel-2); }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatches button {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--panel);
  box-shadow: 0 0 0 1px var(--line);
  background: var(--c);
  padding: 0;
}
.swatches button.on { box-shadow: 0 0 0 2px var(--c); }
.state-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12.5px;
  font-weight: 500;
  background: var(--panel-2);
  color: var(--muted);
}
.state-pill::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.state-pill.open { color: var(--accent); background: var(--accent-soft); }
.state-pill.closed, .state-pill.connecting { color: var(--warn); background: color-mix(in srgb, var(--warn) 13%, transparent); }
.state-pill.qr, .state-pill.code { color: var(--read); background: color-mix(in srgb, var(--read) 13%, transparent); }
.num-card .phone { font-size: 15px; }
.num-card .phone small { display: block; color: var(--muted); font-size: 12.5px; }
.num-card .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.num-card .reason { font-size: 13px; color: var(--warn); }
.num-card.add-card {
  align-items: center;
  justify-content: center;
  min-height: 150px;
  border: 2px dashed var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  font-weight: 500;
}
.num-card.add-card:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.num-card.add-card:disabled { opacity: 0.5; cursor: default; }
.link-btn {
  align-self: flex-start;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 13px;
  text-decoration: underline;
}
.link-btn:hover { color: var(--danger); }
.qr-box { display: grid; justify-items: center; gap: 10px; text-align: center; }
.qr-box img { width: 230px; height: 230px; border-radius: 8px; background: #fff; padding: 6px; }
.qr-box .steps { font-size: 13px; color: var(--muted); }
.pair-code {
  direction: ltr;
  font-size: 30px;
  font-weight: 600;
  letter-spacing: 4px;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--panel-2);
  font-family: ui-monospace, 'SFMono-Regular', Menlo, monospace;
}
.code-form { display: flex; gap: 8px; }
.code-form .input { direction: ltr; text-align: left; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  max-width: calc(100% - 32px);
  padding: 10px 18px;
  border-radius: 10px;
  background: #1f2c33;
  color: #fff;
  font-size: 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- الجوال ---------- */

@media (max-width: 900px) {
  /* ثابت زي تطبيق واتساب: ما تتحرك الصفحة ولا تكبر لما تكتب */
  html, body { overflow: hidden; }
  .app { position: fixed; top: 0; left: 0; right: 0; transform: translateY(var(--vv-top, 0px)); }
  .composer textarea, .search input, .input { font-size: 16px; }
  .picker { height: 42vh; }
  .chat-item, .chip, .icon-btn, .btn, .topbar, .chat-head, .menu {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }
  .app { grid-template-columns: 1fr; box-shadow: none; }
  .main { display: none; }
  body.in-chat .sidebar { display: none; }
  body.in-chat .main { display: flex; }
  .chat-head .back { display: inline-grid; }
  .messages { padding: 10px 10px 6px; }
  .bubble { max-width: 86%; }
  .modal-back { padding: 0; align-items: end; }
  .modal { max-width: none; max-height: 92dvh; border-radius: 16px 16px 0 0; }
  .modal.wide { max-width: none; }
  .modal-body { padding-bottom: max(20px, env(safe-area-inset-bottom)); }
}

@media (min-width: 1440px) {
  .app { margin: 19px auto; height: calc(var(--app-h, 100vh) - 38px); }
}

/* ---------- صفحة الدخول ---------- */

.login-page {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 16px;
  background:
    linear-gradient(var(--accent) 0 220px, transparent 220px) no-repeat,
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 380px;
  padding: 32px 28px 28px;
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.15);
  text-align: center;
}
.login-card h1 { margin: 14px 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 22px; color: var(--muted); font-size: 14px; }
.login-card form { display: grid; gap: 12px; text-align: start; }
.login-card .btn { width: 100%; min-height: 44px; margin-top: 4px; }
.login-card .error { min-height: 20px; color: var(--danger); font-size: 13.5px; text-align: center; }
.login-note {
  padding: 12px 14px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--warn) 12%, transparent);
  font-size: 14px;
  line-height: 1.7;
  text-align: start;
}
.login-note code { font-size: 13px; }
.logo {
  display: inline-grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 18px;
  background: var(--accent);
  color: #fff;
}
