/* دلفي شات - الأنماط (RTL) */
:root {
  --brand: #0f5a4a;
  --brand-2: #137560;
  --brand-ink: #ffffff;
  --accent: #e8a33d;
  --bg: #eef1f0;
  --panel: #ffffff;
  --panel-2: #f6f8f7;
  --text: #16211d;
  --muted: #687873;
  --line: #e2e8e5;
  --chat-bg: #ebe5da;
  --bubble-in: #ffffff;
  --bubble-out: #d6f0e2;
  --tick: #8a9a95;
  --tick-read: #1f8ae0;
  --danger: #c53030;
  --shadow: 0 1px 2px rgba(0,0,0,.08), 0 2px 8px rgba(0,0,0,.04);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Tahoma, "Noto Sans Arabic", "Geeza Pro", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand: #127a63;
    --brand-2: #1a8f74;
    --bg: #0c1311;
    --panel: #141d1a;
    --panel-2: #1a2522;
    --text: #e4ebe8;
    --muted: #8fa29b;
    --line: #23302c;
    --chat-bg: #0a100e;
    --bubble-in: #1c2724;
    --bubble-out: #104637;
    --tick: #7d918a;
    --tick-read: #4fb6f0;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.5 var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.ltr { direction: ltr; unicode-bidi: isolate; }
.noscript { padding: 24px; text-align: center; }

/* ---------- البداية ---------- */
#app { height: 100%; height: 100dvh; }
.splash { height: 100%; display: grid; place-content: center; text-align: center; color: var(--muted); }
.splash img { border-radius: 22px; margin: 0 auto; }

/* ---------- أزرار وحقول ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px; padding: 11px 18px; min-height: 44px;
  background: var(--brand); color: var(--brand-ink); font-weight: 600;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid currentColor; }
.btn.block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 42px; height: 42px; flex: none;
  border: 0; border-radius: 50%; background: transparent; color: inherit;
}
.icon-btn:hover { background: rgba(127,127,127,.12); }
.icon-btn svg, .btn svg { width: 22px; height: 22px; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.input {
  width: 100%; padding: 11px 13px; border-radius: 11px;
  border: 1px solid var(--line); background: var(--panel); outline: none; min-height: 44px;
}
.input:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-2) 22%, transparent); }
.input.code { font-size: 26px; letter-spacing: 10px; text-align: center; font-weight: 700; }
.hint { font-size: 13px; color: var(--muted); }
.error-text { color: var(--danger); font-size: 14px; min-height: 20px; margin: 4px 0 10px; }

/* ---------- شاشة الدخول ---------- */
.login {
  min-height: 100%; display: grid; place-items: center; padding: 24px 16px;
  background: linear-gradient(170deg, var(--brand) 0 38%, var(--bg) 38%);
}
.login-card {
  width: 100%; max-width: 400px; background: var(--panel); border-radius: 20px;
  padding: 28px 22px; box-shadow: 0 10px 40px rgba(0,0,0,.12);
}
.login-card .logo { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.login-card .logo img { width: 52px; height: 52px; border-radius: 14px; }
.login-card h1 { font-size: 22px; margin: 0; }
.login-card p.sub { margin: 2px 0 0; color: var(--muted); font-size: 14px; }

/* ---------- التخطيط الرئيسي ---------- */
.layout { height: 100%; display: grid; grid-template-columns: 1fr; background: var(--bg); }
.pane { height: 100%; min-height: 0; display: flex; flex-direction: column; background: var(--panel); }
.layout .chat-pane { display: none; }
.layout.chat-open .list-pane { display: none; }
.layout.chat-open .chat-pane { display: flex; }
@media (min-width: 860px) {
  .layout { grid-template-columns: minmax(320px, 380px) 1fr; }
  .layout .list-pane, .layout.chat-open .list-pane { display: flex; border-inline-end: 1px solid var(--line); }
  .layout .chat-pane { display: flex; }
  .chat-pane .back-btn { display: none; }
}
.topbar {
  display: flex; align-items: center; gap: 6px; min-height: 58px; flex: none;
  padding: 6px 8px; padding-top: calc(6px + env(safe-area-inset-top));
  background: var(--brand); color: var(--brand-ink);
}
.topbar .title { flex: 1; min-width: 0; font-size: 19px; font-weight: 700; padding-inline-start: 8px; }
.topbar .title small { display: block; font-size: 12px; font-weight: 400; opacity: .85; }
.topbar .peer { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; background: none; border: 0; padding: 0; text-align: start; color: inherit; }
.topbar .peer .meta { min-width: 0; }
.topbar .peer b { display: block; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .peer small { display: block; font-size: 12px; opacity: .85; }

.searchbar { padding: 8px 12px; border-bottom: 1px solid var(--line); flex: none; }
.searchbar input { width: 100%; border: 0; background: var(--panel-2); border-radius: 10px; padding: 9px 12px; outline: none; }

.banner { margin: 10px 12px 0; padding: 10px 12px; border-radius: 12px; font-size: 13.5px; display: flex; gap: 10px; align-items: center; background: color-mix(in srgb, var(--accent) 18%, var(--panel)); }
.banner .btn { min-height: 34px; padding: 6px 12px; font-size: 13px; }
.banner p { margin: 0; flex: 1; }
.banner.danger { background: color-mix(in srgb, var(--danger) 14%, var(--panel)); }

/* ---------- قائمة المحادثات ---------- */
.conv-list { flex: 1; overflow-y: auto; min-height: 0; }
.conv {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 14px;
  border: 0; background: none; text-align: start; position: relative;
}
.conv::after { content: ""; position: absolute; inset-inline: 74px 0; bottom: 0; border-bottom: 1px solid var(--line); }
.conv:hover { background: var(--panel-2); }
.conv.active { background: color-mix(in srgb, var(--brand) 10%, var(--panel)); }
.conv .body { flex: 1; min-width: 0; }
.conv .row { display: flex; align-items: baseline; gap: 8px; }
.conv .name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .time { font-size: 12px; color: var(--muted); flex: none; }
.conv .time.unread { color: var(--brand-2); font-weight: 600; }
.conv .preview { flex: 1; min-width: 0; color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 4px; }
.conv .preview .txt { overflow: hidden; text-overflow: ellipsis; }
.badge { min-width: 21px; height: 21px; padding: 0 6px; border-radius: 11px; background: var(--accent); color: #2b1a00; font-size: 12px; font-weight: 700; display: inline-grid; place-items: center; flex: none; }
.empty { padding: 40px 24px; text-align: center; color: var(--muted); }
.empty svg { width: 64px; height: 64px; opacity: .35; }

.avatar {
  width: 48px; height: 48px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-weight: 700; font-size: 18px; color: #fff; background: var(--av, #5b7a72);
}
.avatar.sm { width: 38px; height: 38px; font-size: 15px; }
.avatar.shop { border-radius: 14px; }

.fab {
  position: absolute; inset-inline-end: 18px; bottom: calc(18px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 18px; border: 0; background: var(--brand); color: #fff;
  box-shadow: 0 6px 18px rgba(0,0,0,.22); display: grid; place-items: center;
}
.fab svg { width: 26px; height: 26px; }
.list-pane { position: relative; }

/* ---------- شاشة المحادثة ---------- */
.chat-empty { flex: 1; display: grid; place-content: center; text-align: center; color: var(--muted); background: var(--chat-bg); }
.chat-empty img { width: 88px; height: 88px; border-radius: 22px; margin: 0 auto 10px; opacity: .9; }
.messages {
  flex: 1; overflow-y: auto; min-height: 0; padding: 10px 4% 14px;
  background-color: var(--chat-bg);
  background-image: radial-gradient(color-mix(in srgb, var(--text) 6%, transparent) 1px, transparent 1.4px);
  background-size: 22px 22px;
  display: flex; flex-direction: column; gap: 2px;
}
.load-more { align-self: center; margin: 6px 0 10px; font-size: 13px; padding: 6px 14px; border-radius: 20px; border: 0; background: var(--panel); box-shadow: var(--shadow); color: var(--muted); }
.day { align-self: center; margin: 10px 0 8px; font-size: 12.5px; padding: 4px 12px; border-radius: 9px; background: var(--panel); color: var(--muted); box-shadow: var(--shadow); }
.msg {
  max-width: min(78%, 560px); padding: 6px 9px 4px; border-radius: 12px; box-shadow: var(--shadow);
  background: var(--bubble-in); align-self: flex-start; position: relative; margin-top: 2px;
  overflow-wrap: anywhere;
}
.msg.out { background: var(--bubble-out); align-self: flex-end; }
.msg.first.in { border-start-start-radius: 4px; margin-top: 8px; }
.msg.first.out { border-start-end-radius: 4px; margin-top: 8px; }
.msg .text { white-space: pre-wrap; }
.msg .text a { color: var(--tick-read); }
.msg .foot { display: flex; align-items: center; justify-content: flex-end; gap: 4px; font-size: 11.5px; color: var(--muted); margin-top: 1px; float: inline-end; margin-inline-start: 10px; position: relative; top: 5px; }
.msg::after { content: ""; display: block; clear: both; }
.tick { display: inline-flex; color: var(--tick); }
.tick svg { width: 17px; height: 17px; }
.tick.read { color: var(--tick-read); }
.tick.fail { color: var(--danger); }
.msg.failed { cursor: pointer; }
.msg .fail-note { font-size: 12px; color: var(--danger); }

.file-card {
  display: flex; align-items: center; gap: 10px; padding: 8px; margin: 2px 0 4px; border-radius: 10px;
  background: color-mix(in srgb, var(--text) 6%, transparent); border: 0; width: 100%; min-width: 220px; text-align: start;
}
.file-card .ficon { width: 40px; height: 46px; flex: none; border-radius: 6px; background: #d93025; color: #fff; display: grid; place-items: center; font-size: 11px; font-weight: 800; }
.file-card .fmeta { min-width: 0; flex: 1; }
.file-card .fname { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-card .fsize { font-size: 12px; color: var(--muted); }
.progress { height: 4px; border-radius: 2px; background: color-mix(in srgb, var(--text) 12%, transparent); overflow: hidden; margin-top: 4px; }
.progress i { display: block; height: 100%; background: var(--brand-2); width: 0; transition: width .2s; }

.composer {
  display: flex; align-items: flex-end; gap: 6px; padding: 8px; flex: none;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  background: var(--panel-2); border-top: 1px solid var(--line);
}
.composer textarea {
  flex: 1; resize: none; border: 0; outline: none; background: var(--panel); border-radius: 22px;
  padding: 10px 15px; max-height: 140px; min-height: 44px; line-height: 1.45;
}
.composer .send { background: var(--brand); color: #fff; width: 46px; height: 46px; }
.composer .send:hover { background: var(--brand-2); }
.composer .send svg { transform: scaleX(-1); }
.blocked-bar { padding: 14px; text-align: center; background: var(--panel-2); border-top: 1px solid var(--line); color: var(--muted); padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
.blocked-bar button { background: none; border: 0; color: var(--brand-2); font-weight: 600; }

/* ---------- القوائم المنبثقة والنوافذ ---------- */
.menu {
  position: fixed; z-index: 30; min-width: 210px; background: var(--panel); color: var(--text);
  border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.2); padding: 6px; 
}
.menu button { display: flex; width: 100%; gap: 10px; align-items: center; padding: 11px 12px; border: 0; background: none; border-radius: 8px; text-align: start; }
.menu button:hover { background: var(--panel-2); }
.menu button.danger { color: var(--danger); }
.backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.4); display: grid; align-items: end; justify-items: center; animation: fade .15s; }
.backdrop.clear { background: transparent; }
@media (min-width: 600px) { .backdrop { align-items: center; } }
.sheet {
  width: 100%; max-width: 520px; max-height: 92dvh; display: flex; flex-direction: column;
  background: var(--panel); border-radius: 20px 20px 0 0; box-shadow: 0 -8px 30px rgba(0,0,0,.2);
  padding-bottom: env(safe-area-inset-bottom); animation: up .2s ease-out;
}
@media (min-width: 600px) { .sheet { border-radius: 20px; } }
.sheet header { display: flex; align-items: center; gap: 6px; padding: 10px 10px 6px 16px; border-bottom: 1px solid var(--line); }
.sheet header h2 { flex: 1; margin: 0; font-size: 17px; }
.sheet .content { padding: 16px; overflow-y: auto; }
.sheet .actions { display: flex; gap: 10px; margin-top: 6px; }
.sheet .actions .btn { flex: 1; }
.list-rows { margin: 4px -16px 0; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-top: 1px solid var(--line); }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .grow b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.list-row .grow small { color: var(--muted); }
.list-row .btn { min-height: 36px; padding: 6px 12px; font-size: 13.5px; }
.pill { display: inline-block; font-size: 12px; border-radius: 20px; padding: 1px 9px; background: var(--panel-2); color: var(--muted); }
.pill.ok { background: color-mix(in srgb, #1f9d66 18%, var(--panel)); color: #13744b; }
.pill.bad { background: color-mix(in srgb, var(--danger) 15%, var(--panel)); color: var(--danger); }
.section-title { font-size: 13px; color: var(--muted); margin: 18px 0 8px; font-weight: 600; }
.code-show { text-align: center; padding: 6px 0 4px; }
.code-show .code { font-size: 44px; font-weight: 800; letter-spacing: 12px; direction: ltr; color: var(--brand-2); margin: 6px 0; }
.stat { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.switch-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.switch-row .grow { flex: 1; }

#toast {
  position: fixed; z-index: 50; inset-inline: 16px; bottom: calc(86px + env(safe-area-inset-bottom));
  margin: 0 auto; max-width: 420px; padding: 11px 16px; border-radius: 12px;
  background: #1c2522; color: #fff; text-align: center; font-size: 14px;
  opacity: 0; transform: translateY(10px); pointer-events: none; transition: .2s;
}
#toast.show { opacity: 1; transform: none; }
.offline-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); display: inline-block; margin-inline-start: 6px; }

@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(30px); opacity: .6; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
