:root {
  --green: #16a34a;
  --green-d: #15803d;
  --green-l: #dcfce7;
  --green-soft: #f0fdf4;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e6eaf0;
  --bg: #f5f7fa;
  --card: #ffffff;
  --wa-bg: #e5ddd5;
  --wa-bubble: #d9fdd3;
  --amber: #f59e0b;
  --red: #dc2626;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 8px 24px rgba(16,24,40,.06);
  --shadow-lg: 0 4px 12px rgba(16,24,40,.06), 0 16px 40px rgba(16,24,40,.10);
  --radius: 18px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: 'IBM Plex Sans Arabic', 'Tajawal', -apple-system, 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
button { font-family: inherit; cursor: pointer; }
::selection { background: var(--green-l); }

/* ===== الدخول ===== */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background:
    radial-gradient(900px 460px at 85% -10%, #e7f6ee 0%, transparent 60%),
    radial-gradient(700px 380px at 8% 110%, #e9f8f0 0%, transparent 55%),
    var(--bg);
}
.login-card {
  position: relative;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 24px; padding: 42px 34px 34px; width: 100%; max-width: 410px;
  text-align: center; box-shadow: var(--shadow-lg);
}
.brand-logo { width: 66px; height: 66px; margin-bottom: 14px; filter: drop-shadow(0 6px 14px rgba(22,163,74,.25)); }
.wordmark { font-size: 25px; font-weight: 800; letter-spacing: -.2px; margin-bottom: 4px; }
.login-card .muted { margin-bottom: 24px; font-size: 14px; }

/* زر اللغة */
.lang-btn {
  background: #fff; border: 1.5px solid var(--line); color: var(--ink);
  border-radius: 10px; padding: 7px 13px; font-size: 13px; font-weight: 800;
  font-family: 'Inter', sans-serif; min-width: 42px; cursor: pointer; flex: none;
  transition: border-color .15s, color .15s;
}
.lang-btn:hover { border-color: var(--green); color: var(--green-d); }
.card-lang { position: absolute; top: 16px; inset-inline-start: 16px; }

.field { text-align: start; margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 700; margin-bottom: 6px; }
input, textarea {
  width: 100%; background: #fff; border: 1.5px solid var(--line);
  border-radius: 12px; color: var(--ink); padding: 12px 14px;
  font-size: 15px; font-family: inherit; transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus {
  outline: none; border-color: var(--green);
  box-shadow: 0 0 0 4px rgba(22,163,74,.12);
}
textarea { resize: vertical; line-height: 1.7; }

.btn-primary {
  width: 100%;
  background: linear-gradient(180deg, #19b355, var(--green));
  color: #fff; border: none;
  border-radius: 12px; padding: 13px; font-size: 15px; font-weight: 700;
  box-shadow: 0 2px 6px rgba(22,163,74,.28);
  transition: filter .15s, transform .05s, box-shadow .15s;
}
.btn-primary:hover { filter: brightness(.96); box-shadow: 0 3px 10px rgba(22,163,74,.35); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: .6; cursor: default; }
.btn-ghost {
  background: #fff; color: var(--muted); border: 1.5px solid var(--line);
  border-radius: 10px; padding: 8px 16px; font-size: 14px; font-weight: 700;
  transition: background .15s, color .15s;
}
.btn-ghost:hover { background: #f8fafc; color: var(--ink); }
.error { color: var(--red); font-size: 14px; margin-top: 12px; min-height: 18px; }

/* ===== الشريط العلوي ===== */
.topbar {
  background: rgba(255,255,255,.9); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
}
.topbar-in {
  max-width: 960px; margin: 0 auto; padding: 12px 20px;
  display: flex; align-items: center; justify-content: space-between;
}
.store { display: flex; align-items: center; gap: 12px; }
.topbar-logo { width: 42px; height: 42px; flex: none; }
.store-name { font-weight: 800; font-size: 16px; line-height: 1.3; }
.store-sub { font-size: 12px; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex: none; }

/* ===== المحتوى ===== */
.container { max-width: 960px; margin: 0 auto; padding: 24px 20px 130px; }
.intro { margin: 26px 0 18px; }
.intro h2 { font-size: 20px; font-weight: 800; }
.intro .muted { font-size: 14px; }

/* ===== شريط الإحصائيات ===== */
.stats-row {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 22px;
}
@media (max-width: 640px) { .stats-row { grid-template-columns: 1fr 1fr 1fr; gap: 8px; } }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); text-align: center;
}
.stat .num { font-size: 26px; font-weight: 800; color: var(--green-d); line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat .lbl { font-size: 12.5px; color: var(--muted); font-weight: 700; }
@media (max-width: 640px) { .stat { padding: 12px 8px; } .stat .num { font-size: 20px; } .stat .lbl { font-size: 11px; } }

/* ===== بطاقات الرسائل ===== */
.msg-card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow);
  transition: box-shadow .2s;
}
.msg-card:hover { box-shadow: var(--shadow-lg); }
.msg-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.msg-emoji {
  display: grid; place-items: center; width: 40px; height: 40px;
  border-radius: 12px; background: var(--green-l); color: var(--green-d); flex: none;
}
.msg-emoji svg, .wa-ico svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.msg-head-txt { flex: 1; }
.msg-title { font-weight: 800; font-size: 15px; }
.msg-when { font-size: 12px; }

.msg-body { display: grid; grid-template-columns: 1fr 300px; gap: 20px; }
@media (max-width: 720px) { .msg-body { grid-template-columns: 1fr; } }

.vars { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  background: #eef2f7; color: #334155; border: 1px solid var(--line);
  border-radius: 999px; padding: 3px 11px; font-size: 12px; font-weight: 600;
  cursor: pointer; transition: background .12s, color .12s, border-color .12s;
}
.chip:hover { background: var(--green); color: #fff; border-color: var(--green); }
.chip code { font-family: inherit; }

/* ===== معاينة واتساب (واقعية) ===== */
.preview { display: flex; }
.wa-phone {
  width: 100%; border-radius: 16px; overflow: hidden;
  border: 1px solid #d8d2c8; box-shadow: var(--shadow);
  display: flex; flex-direction: column; min-height: 210px; background: #efeae2;
}
.wa-chat-head {
  display: flex; align-items: center; gap: 9px;
  background: #008069; color: #fff; padding: 9px 12px; flex: none;
}
.wa-chat-head .pt-av {
  width: 31px; height: 31px; border-radius: 50%; background: #25d366;
  color: #fff; display: grid; place-items: center; font-size: 14px; font-weight: 700; flex: none;
}
.wa-hd-txt { flex: 1; min-width: 0; line-height: 1.25; }
.wa-hd-txt .pt-name { display: block; font-size: 13.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wa-hd-txt .pt-on { font-size: 10.5px; opacity: .85; }
.wa-hd-ic { display: flex; gap: 15px; opacity: .95; flex: none; }
.wa-hd-ic svg { width: 17px; height: 17px; fill: #fff; }
.wa-chat {
  flex: 1; padding: 12px 10px 13px;
  background-color: #efeae2;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120'%3E%3Cg fill='none' stroke='%23000' stroke-opacity='0.045' stroke-width='1.4' stroke-linecap='round'%3E%3Cpath d='M20 22c3-4 8-4 10 0'/%3E%3Ccircle cx='86' cy='30' r='5'/%3E%3Cpath d='M28 78l4 4 6-7'/%3E%3Cpath d='M90 88c0-5 8-5 8 0s-8 5-8 0z'/%3E%3Cpath d='M55 52l5-8 5 8z'/%3E%3Ccircle cx='24' cy='104' r='3'/%3E%3Cpath d='M104 58h10'/%3E%3C/g%3E%3C/svg%3E");
  display: flex; flex-direction: column; gap: 8px; justify-content: flex-end;
}
.wa-day {
  align-self: center; background: #ffffff; color: #54656f;
  font-size: 10.5px; font-weight: 600; padding: 3px 11px; border-radius: 8px;
  box-shadow: 0 1px 1px rgba(0,0,0,.06);
}
/* فقاعة صادرة: بالعربي (RTL) رسائلك تكون على اليسار مع ذيل — مثل واتساب تماماً */
.bubble {
  position: relative; align-self: flex-end; max-width: 92%;
  background: var(--wa-bubble); border-radius: 9px; border-start-end-radius: 0;
  padding: 6px 9px 7px; font-size: 13.2px; line-height: 1.65; color: #111b21;
  box-shadow: 0 1px 1px rgba(0,0,0,.1);
}
.bubble::after {
  content: ""; position: absolute; top: 0; inset-inline-end: -7px;
  border: 7px solid transparent;
  border-top-color: var(--wa-bubble); border-inline-start-color: var(--wa-bubble);
  border-inline-start-width: 4px; border-top-width: 6px;
}
.bubble-text { white-space: pre-wrap; word-break: break-word; }
.bubble-text:empty::after { content: "المعاينة تظهر هنا…"; color: #667781; }
.bubble-meta {
  display: flex; justify-content: flex-end; align-items: center; gap: 3px;
  direction: ltr; font-size: 10px; color: #667781; margin: 3px -2px -2px 0; line-height: 1;
}
.bubble-meta svg { width: 14px; height: 10px; fill: #53bdeb; }

/* ===== شريط الحفظ ===== */
.savebar {
  position: fixed; bottom: 0; right: 0; left: 0; z-index: 20;
  background: rgba(255,255,255,.92); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line); padding: 12px 20px;
  display: flex; align-items: center; justify-content: center; gap: 16px;
}
.savebar .btn-primary { width: auto; padding: 12px 34px; }
.save-msg { font-size: 14px; font-weight: 700; color: var(--green-d); }

/* ===== رابط تبديل دخول/تسجيل ===== */
.switch { margin-top: 18px; font-size: 14px; }
.switch a { color: var(--green); font-weight: 700; cursor: pointer; text-decoration: none; }
.switch a:hover { text-decoration: underline; }

/* ===== زر التشغيل/الإطفاء ===== */
.toggle { position: relative; display: inline-flex; cursor: pointer; flex: none; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.tgl-track {
  width: 46px; height: 26px; background: #cbd5e1; border-radius: 999px;
  transition: background .18s; display: inline-block; position: relative;
}
.tgl-dot {
  position: absolute; top: 3px; right: 3px; width: 20px; height: 20px;
  background: #fff; border-radius: 50%; transition: transform .18s;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.toggle input:checked + .tgl-track { background: var(--green); }
.toggle input:checked + .tgl-track .tgl-dot { transform: translateX(-20px); }
[dir="ltr"] .tgl-dot { right: auto; left: 3px; }
[dir="ltr"] .toggle input:checked + .tgl-track .tgl-dot { transform: translateX(20px); }

/* حالة الرسالة المطفأة */
.msg-card.off .msg-body { opacity: .45; filter: grayscale(.4); pointer-events: none; }
.msg-card.off .msg-emoji { filter: grayscale(1); opacity: .6; }
.msg-card.off::after {
  content: "متوقّفة"; font-size: 11px; font-weight: 700; color: #94a3b8;
}

/* ===== بطاقات الربط ===== */
.wa-card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.wa-head { display: flex; align-items: center; justify-content: space-between; }
.wa-title { display: flex; align-items: center; gap: 12px; }
.wa-ico {
  display: grid; place-items: center; width: 42px; height: 42px;
  border-radius: 12px; background: var(--green-l); color: var(--green-d); flex: none;
}
.wa-t { font-weight: 800; font-size: 15px; }
.wa-status { font-size: 13px; }
.wa-dot { width: 12px; height: 12px; border-radius: 50%; background: #cbd5e1; flex: none; transition: background .2s; }
.wa-dot.pulse { animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(245,158,11,.4); } 50% { box-shadow: 0 0 0 7px rgba(245,158,11,0); } }
.wa-body { margin-top: 14px; }
.wa-desc { font-size: 14px; margin-bottom: 14px; }
.wa-link-btn { width: auto; padding: 11px 22px; }
.wa-ok { color: var(--green-d); font-weight: 700; margin-bottom: 12px; }
.wa-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-ghost.danger { color: var(--red); border-color: #fecaca; }
.btn-ghost.danger:hover { background: #fef2f2; }

.wa-qr { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.wa-qr img {
  width: 190px; height: 190px; border-radius: 14px; border: 1px solid var(--line);
  padding: 8px; background: #fff; box-shadow: var(--shadow);
}
.wa-steps { font-size: 14px; }
.wa-steps ol { margin: 8px 20px 0; line-height: 2; }
.wa-steps b { color: var(--green-d); }
.wa-expire { font-size: 12.5px; margin: 14px 0 8px; }
.wa-steps .btn-ghost { width: auto; padding: 8px 16px; font-size: 13px; }
.to-form { max-width: 420px; }
.to-form .field { margin-bottom: 12px; }
.to-form .wa-link-btn { margin-top: 6px; }

/* ===== نافذة الحساب (تغيير كلمة المرور) ===== */
dialog.acct {
  border: none; border-radius: 20px; padding: 0; max-width: 380px; width: calc(100% - 40px);
  box-shadow: var(--shadow-lg);
}
dialog.acct::backdrop { background: rgba(15,23,42,.45); backdrop-filter: blur(2px); }
.acct-in { padding: 26px 24px; font-family: 'Tajawal', sans-serif; }
.acct-in h3 { font-size: 17px; font-weight: 800; margin-bottom: 4px; }
.acct-in .muted { font-size: 13px; margin-bottom: 16px; }
.acct-actions { display: flex; gap: 10px; margin-top: 6px; }
.acct-actions .btn-ghost { flex: 1; }
.acct-actions .btn-primary { flex: 2; }

/* ===== تذييل ===== */
.app-foot { text-align: center; color: #94a3b8; font-size: 12.5px; padding: 10px 0 20px; }
