@import url('https://fonts.googleapis.com/css2?family=Amiri+Quran&display=swap');

/* =====================================================================
   الدردشة (/dardacha) — WhatsApp Web dark, Nouran palette
   ===================================================================== */
:root {
  --deep: #0b141a;
  --panel: #111b21;
  --head: #202c33;
  --out: #005c4b;
  --in: #202c33;
  --accent: #00a884;
  --accent-soft: #0a332c;
  --text: #e9edef;
  --text-2: #d1d7db;
  --muted: #8696a0;
  --icon: #aebac1;
  --border: #222d34;
  --hover: #202c33;
  --active: #2a3942;
  --input: #2a3942;
  --system: #182229;
  --danger: #f15c6d;
  --menu: #233138;
  --blue: #53bdeb;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body.dd {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--deep);
  color: var(--text);
  font-family: 'Segoe UI', 'Helvetica Neue', Tahoma, Cairo, Arial, sans-serif;
  font-size: 14.5px;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: rgba(134, 150, 160, 0.3); border-radius: 3px; }
::-webkit-scrollbar-track { background: transparent; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.dd-app { display: flex; height: 100%; }

/* ------------------------------------------------------------ shared bits */
.dd-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--active);
  color: var(--text);
  font-weight: 600; font-size: 17px;
  user-select: none;
}
.dd-avatar.is-group { font-size: 20px; }
.dd-icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: none; cursor: pointer;
  color: var(--icon);
  font-size: 20px;
  transition: background 0.15s ease;
}
.dd-icon-btn:hover, .dd-icon-btn.is-open { background: rgba(255, 255, 255, 0.08); }
.dd-icon-btn svg { width: 22px; height: 22px; fill: currentColor; }
.dd-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 22px;
  border-radius: 24px;
  border: none;
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.dd-btn-primary { background: var(--accent); color: var(--panel); }
.dd-btn-primary:hover { background: #06cf9c; }
.dd-btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }
.dd-btn-ghost { background: transparent; color: var(--accent); box-shadow: inset 0 0 0 1px #2f3b43; }
.dd-btn-ghost:hover { background: rgba(0, 168, 132, 0.08); }
.dd-btn-danger { background: transparent; color: var(--danger); box-shadow: inset 0 0 0 1px #4a2d33; }
.dd-search {
  display: flex; align-items: center; gap: 10px;
  height: 35px;
  padding: 0 12px;
  border-radius: 8px;
  background: var(--head);
  flex: 1;
}
.dd-search svg { width: 18px; height: 18px; fill: var(--muted); flex-shrink: 0; }
.dd-search input { flex: 1; min-width: 0; background: transparent; border: none; outline: none; font-size: 14px; }
.dd-search input::placeholder { color: var(--muted); }

/* ------------------------------------------------------------ sidebar */
.dd-side {
  width: 30%;
  min-width: 320px;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--border);
  position: relative;
}
.dd-side-head {
  height: 59px;
  flex-shrink: 0;
  display: flex; align-items: center; gap: 10px;
  padding: 0 16px;
  background: var(--head);
  position: relative;
}
.dd-me-avatar { background: linear-gradient(135deg, #00a884, #005c4b); color: #fff; }
.dd-me-text { flex: 1; min-width: 0; line-height: 1.25; }
.dd-me-name { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dd-me-status { font-size: 12px; color: var(--muted); }
.dd-me-status.is-online::before { content: '● '; color: var(--accent); }
.dd-me-status.is-offline { color: var(--danger); }

.dd-menu {
  position: absolute;
  top: 52px; left: 12px;
  z-index: 50;
  min-width: 230px;
  padding: 8px 0;
  border-radius: 6px;
  background: var(--menu);
  box-shadow: 0 6px 24px rgba(11, 20, 26, 0.6);
  display: none;
}
.dd-menu.open { display: block; }
.dd-menu button {
  display: block; width: 100%;
  padding: 11px 22px;
  background: none; border: none; cursor: pointer;
  color: var(--text-2);
  font-size: 14.5px;
  text-align: right;
}
.dd-menu button:hover { background: var(--deep); }
.dd-menu hr { border: none; border-top: 1px solid var(--border); margin: 6px 0; }

.dd-search-wrap {
  flex-shrink: 0;
  padding: 7px 12px 6px;
  border-bottom: 1px solid var(--border);
}
.dd-tabs {
  display: flex; gap: 8px;
  padding: 9px 2px 3px;
  overflow-x: auto;
  scrollbar-width: none;
}
.dd-tabs::-webkit-scrollbar { display: none; }
.dd-tab {
  flex-shrink: 0;
  padding: 6px 13px;
  border-radius: 16px;
  border: none;
  background: var(--head);
  color: var(--muted);
  font-size: 13.5px;
  cursor: pointer;
}
.dd-tab:hover { background: var(--active); color: var(--text); }
.dd-tab.active { background: var(--accent-soft); color: var(--accent); }
.dd-tab-count:empty { display: none; }
.dd-tab-count { margin-right: 3px; font-size: 12px; }

.dd-list { flex: 1; overflow-y: auto; padding-bottom: 12px; }
.dd-section {
  padding: 14px 18px 6px;
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 600;
}
.dd-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  height: 72px;
  padding: 0 13px 0 15px;
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: right;
}
.dd-row:hover { background: var(--hover); }
.dd-row.active { background: var(--active); }
.dd-row .dd-avatar { width: 49px; height: 49px; font-size: 19px; }
.dd-row-body {
  flex: 1; min-width: 0; height: 100%;
  display: flex; flex-direction: column; justify-content: center; gap: 3px;
  border-bottom: 1px solid var(--border);
}
.dd-row:last-child .dd-row-body { border-bottom-color: transparent; }
.dd-row-top, .dd-row-bottom { display: flex; align-items: center; gap: 8px; min-width: 0; }
.dd-row-title { flex: 1; min-width: 0; font-size: 16px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dd-row-time { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.dd-row-preview { flex: 1; min-width: 0; font-size: 13.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dd-row-preview .dd-typing { color: var(--accent); }
.dd-badge {
  min-width: 20px; height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--panel);
  font-size: 12px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.dd-row.unread .dd-row-time { color: var(--accent); }
.dd-row.unread .dd-row-title { font-weight: 600; }
.dd-online-dot {
  position: absolute;
  bottom: 12px; right: 13px;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--panel);
}
.dd-row-action { font-size: 12.5px; color: var(--accent); flex-shrink: 0; }
.dd-list-empty { padding: 36px 24px; text-align: center; color: var(--muted); font-size: 14px; line-height: 1.7; }

/* ------------------------------------------------------------ main / empty */
.dd-main { flex: 1; min-width: 0; position: relative; display: flex; background: var(--deep); }
.dd-empty, .dd-gate {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 28px;
  text-align: center;
  background: #222e35;
  border-bottom: 6px solid var(--accent);
  position: relative;
}
.dd-gate { position: fixed; inset: 0; z-index: 100; }
.dd-empty-logo {
  width: 108px; height: 108px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--panel);
  box-shadow: 0 0 0 10px rgba(0, 168, 132, 0.08), 0 0 0 22px rgba(0, 168, 132, 0.04);
  margin-bottom: 18px;
}
.dd-empty h1, .dd-gate h1 { margin: 0; font-size: 30px; font-weight: 300; color: var(--text-2); }
.dd-empty p, .dd-gate p { margin: 0; max-width: 470px; font-size: 14px; line-height: 1.7; color: var(--muted); }
.dd-empty-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 10px; }
.dd-empty-foot { position: absolute; bottom: 34px; font-size: 13px; color: #667781; }

/* ------------------------------------------------------------ chat */
.dd-chat { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.dd-chat-head {
  height: 59px;
  flex-shrink: 0;
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  background: var(--head);
}
.dd-back { display: none; }
.dd-chat-meta { flex: 1; min-width: 0; line-height: 1.3; cursor: pointer; }
.dd-chat-title { font-size: 16px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dd-chat-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dd-chat-sub.is-typing, .dd-chat-sub.is-online { color: var(--accent); }

.dd-find {
  display: none;
  align-items: center; gap: 10px;
  padding: 7px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.dd-find.open { display: flex; }
#ddFindCount { font-size: 12.5px; color: var(--muted); white-space: nowrap; }

.dd-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 18px 7% 10px;
  background-color: var(--deep);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='96' height='96' viewBox='0 0 96 96'%3E%3Cg fill='none' stroke='%2300a884' stroke-opacity='0.055' stroke-width='1'%3E%3Crect x='28' y='28' width='40' height='40'/%3E%3Crect x='28' y='28' width='40' height='40' transform='rotate(45 48 48)'/%3E%3Ccircle cx='48' cy='48' r='9'/%3E%3Cpath d='M0 0l14 14M96 0L82 14M0 96l14-14M96 96L82 82'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 96px 96px;
}
.dd-more {
  align-self: center;
  margin: 4px 0 10px;
  padding: 5px 14px;
  border-radius: 14px;
  border: none;
  background: var(--system);
  color: var(--muted);
  font-size: 12.5px;
  cursor: pointer;
}
.dd-day {
  align-self: center;
  margin: 10px 0 8px;
  padding: 5px 12px;
  border-radius: 7.5px;
  background: var(--system);
  color: var(--muted);
  font-size: 12.5px;
  box-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
}
.dd-unread-mark {
  align-self: stretch;
  text-align: center;
  margin: 8px -7%;
  padding: 5px 0;
  background: rgba(0, 0, 0, 0.18);
  color: var(--accent);
  font-size: 12.5px;
}

.dd-msg {
  position: relative;
  max-width: 65%;
  padding: 6px 9px 8px;
  border-radius: 7.5px;
  box-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
  font-size: 14.2px;
  line-height: 1.45;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.dd-msg.first { margin-top: 10px; }
/* RTL: incoming on the right (start), outgoing on the left (end) */
.dd-msg.in { align-self: flex-start; background: var(--in); }
.dd-msg.out { align-self: flex-end; background: var(--out); }
.dd-msg.in.first { border-top-right-radius: 0; }
.dd-msg.out.first { border-top-left-radius: 0; }
.dd-msg.first::before { content: ''; position: absolute; top: 0; width: 8px; height: 13px; }
.dd-msg.in.first::before { right: -8px; background: var(--in); clip-path: polygon(0 0, 100% 0, 0 100%); }
.dd-msg.out.first::before { left: -8px; background: var(--out); clip-path: polygon(0 0, 100% 0, 100% 100%); }
.dd-sender { display: block; margin-bottom: 2px; font-size: 12.8px; font-weight: 500; cursor: pointer; }
.dd-sender:hover { text-decoration: underline; }
.dd-text { white-space: pre-wrap; }
.dd-text a { color: var(--blue); }
.dd-meta {
  float: left;
  position: relative;
  top: 7px;
  margin: 0 10px 0 -2px;
  font-size: 11px;
  line-height: 15px;
  color: rgba(233, 237, 239, 0.6);
  white-space: nowrap;
  user-select: none;
}
.dd-ticks { margin-right: 3px; letter-spacing: -3px; font-size: 12px; color: #8696a0; }
.dd-msg.out .dd-ticks { color: #8fd3c3; }
.dd-ticks.read { color: var(--blue) !important; }
.dd-msg.pending { opacity: 0.75; }
.dd-msg.failed { box-shadow: inset 0 0 0 1px var(--danger); }
.dd-msg.failed .dd-meta { color: var(--danger); }
.dd-msg.verse { max-width: min(560px, 80%); }
.dd-system {
  align-self: center;
  max-width: 85%;
  margin: 8px 0;
  padding: 5px 12px;
  border-radius: 7.5px;
  background: var(--system);
  color: var(--muted);
  font-size: 12.5px;
  text-align: center;
}
.dd-msg.match, .dd-system.match { box-shadow: 0 0 0 2px var(--accent); }
.dd-messages.searching > .dd-msg:not(.match) { opacity: 0.3; }

/* ------------------------------------------------------------ composer */
.dd-composer {
  flex-shrink: 0;
  position: relative;
  display: flex; align-items: flex-end; gap: 8px;
  min-height: 62px;
  padding: 10px 12px;
  background: var(--head);
}
.dd-composer textarea {
  flex: 1; min-width: 0;
  max-height: 140px;
  padding: 10px 12px;
  border: none; border-radius: 8px;
  outline: none;
  resize: none;
  background: var(--input);
  font-size: 15px;
  line-height: 1.4;
}
.dd-composer textarea::placeholder { color: var(--muted); }
.dd-composer .dd-icon-btn { height: 42px; }
.dd-send {
  width: 42px; height: 42px; flex-shrink: 0;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--panel);
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.dd-send:hover { background: #06cf9c; }
.dd-send svg { width: 20px; height: 20px; fill: currentColor; transform: scaleX(-1); }

/* ------------------------------------------------------------ 📖 Quran */
#ddQuranBtn.is-open { background: rgba(0, 168, 132, 0.15); }
.wq-panel {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 12px;
  z-index: 60;
  width: min(380px, calc(100vw - 24px));
  padding: 14px;
  border-radius: 10px;
  background: var(--menu);
  box-shadow: 0 8px 28px rgba(11, 20, 26, 0.65);
  display: none;
  flex-direction: column;
  gap: 9px;
}
.wq-panel.open { display: flex; }
.wq-title { font-size: 14px; font-weight: 600; }
.wq-input {
  height: 38px;
  padding: 0 12px;
  border: none; border-radius: 8px;
  outline: none;
  background: var(--input);
  text-align: center;
  letter-spacing: 1px;
  font-size: 15px;
}
.wq-hint { font-size: 12.5px; color: var(--muted); min-height: 16px; }
.wq-hint.is-error { color: var(--danger); }
.wq-preview {
  max-height: 180px;
  overflow-y: auto;
  font-family: 'Amiri Quran', 'KFGQPC Uthmanic Script HAFS', 'Amiri', serif;
  font-size: 21px;
  line-height: 2.1;
  color: #f3e5ab;
  text-align: center;
}
.wq-preview:empty { display: none; }
.wq-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.wq-btn {
  padding: 7px 14px;
  border-radius: 18px;
  border: none;
  background: transparent;
  color: var(--accent);
  box-shadow: inset 0 0 0 1px #2f3b43;
  font-size: 13px; font-weight: 600;
  cursor: pointer;
}
.wq-btn-primary { background: var(--accent); color: var(--panel); box-shadow: none; }
.wq-btn[disabled] { opacity: 0.4; cursor: not-allowed; }
.wq-verse {
  margin: 4px 0 2px;
  padding: 10px 14px 8px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.18);
  border-right: 3px solid #d4af37;
}
.wq-verse-text {
  font-family: 'Amiri Quran', 'KFGQPC Uthmanic Script HAFS', 'Amiri', serif;
  font-size: 22px;
  line-height: 2.15;
  color: #f3e5ab;
  text-align: center;
  white-space: normal;
}
.wq-verse-ref, .wq-ref-link { color: var(--blue); text-decoration: none; font-size: 12.5px; font-weight: 600; }
.wq-verse-ref { display: block; margin-top: 4px; text-align: left; }
.wq-verse-ref:hover, .wq-ref-link:hover { text-decoration: underline; }

/* ------------------------------------------------------------ modals */
.dd-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(11, 20, 26, 0.78);
}
.dd-modal-card {
  width: 100%;
  max-width: 440px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  border-radius: 10px;
  background: var(--head);
  color: var(--text);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}
.dd-modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px;
  background: var(--panel);
  font-size: 16px; font-weight: 600;
}
.dd-modal-head span { flex: 1; }
.dd-modal-body { padding: 16px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.dd-modal-foot { display: flex; gap: 8px; justify-content: flex-start; padding: 12px 18px 16px; flex-wrap: wrap; }
.dd-field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.dd-field input[type="text"], .dd-field textarea {
  padding: 10px 12px;
  border: none; border-radius: 8px;
  outline: none;
  background: var(--input);
  color: var(--text);
  font-size: 14.5px;
}
.dd-field textarea { resize: vertical; min-height: 60px; }
.dd-check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-2); cursor: pointer; }
.dd-check input { accent-color: var(--accent); width: 17px; height: 17px; }
.dd-pick-list { max-height: 220px; overflow-y: auto; border-radius: 8px; background: var(--panel); padding: 4px 0; }
.dd-pick-list .dd-check { padding: 8px 12px; }
.dd-pick-list .dd-check:hover { background: var(--hover); }
.dd-member {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
}
.dd-member .dd-avatar { width: 36px; height: 36px; font-size: 14px; position: relative; }
.dd-member-name { flex: 1; min-width: 0; font-size: 14.5px; cursor: pointer; }
.dd-member-name small { display: block; color: var(--muted); font-size: 12px; }
.dd-member .is-online { position: absolute; bottom: -1px; right: -1px; width: 11px; height: 11px; border-radius: 50%; background: var(--accent); border: 2px solid var(--head); }
.dd-role { font-size: 11.5px; color: var(--accent); background: var(--accent-soft); padding: 2px 8px; border-radius: 10px; }
.dd-card-hero { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 6px 0 4px; text-align: center; }
.dd-card-hero .dd-avatar { width: 84px; height: 84px; font-size: 32px; }
.dd-card-hero h2 { margin: 4px 0 0; font-size: 20px; font-weight: 500; }
.dd-card-hero p { margin: 0; color: var(--muted); font-size: 13.5px; }

.dd-toast {
  position: fixed;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  max-width: calc(100vw - 32px);
  padding: 10px 18px;
  border-radius: 8px;
  background: var(--menu);
  color: var(--text);
  font-size: 14px;
  box-shadow: 0 6px 24px rgba(11, 20, 26, 0.6);
}

/* ------------------------------------------------------------ mobile */
@media (max-width: 768px) {
  .dd-side { width: 100%; max-width: none; min-width: 0; border-left: none; }
  .dd-main { display: none; }
  body.dd-chat-open .dd-side { display: none; }
  body.dd-chat-open .dd-main { display: flex; }
  .dd-back { display: inline-flex; margin-left: -8px; }
  .dd-chat-head { padding: 0 8px; gap: 8px; }
  .dd-messages { padding: 12px 10px 8px; }
  .dd-unread-mark { margin: 8px -10px; }
  .dd-msg { max-width: 85%; }
  .dd-composer { padding: 6px 8px; gap: 6px; }
  .dd-empty h1, .dd-gate h1 { font-size: 22px; }
}
