/* الرسائل v3: صندوق وارد برقم الجوال، نافذة بحث من الأسفل، ومحادثة خاصة */
#messages-v3-root{--ms-bg:#10232c;--ms-surface:#152d37;--ms-surface-2:#1a3641;--ms-line:rgba(154,210,191,.18);--ms-gold:#e6cf94;--ms-gold-soft:#f6e9c0;--ms-mint:#7ee6bb;--ms-text:#f4f1e8;--ms-muted:#9fb5ad;--ms-cta:linear-gradient(135deg,#c2b0f7,#9a85e6);font-family:"IBM Plex Sans Arabic","Tajawal",system-ui,sans-serif;color:var(--ms-text)}
#messages-v3-root *{box-sizing:border-box;letter-spacing:0}
#messages-v3-root h2,#messages-v3-root h3,#messages-v3-root p{margin:0}
#messages-v3-root button{font:inherit;color:inherit;cursor:pointer}
#messages-v3-root svg{width:20px;height:20px;fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}
.ms-page{display:grid;gap:12px;max-width:620px;margin:0 auto;padding:4px 2px 110px}

/* الرأس + الإشعارات */
.ms-head{display:flex;align-items:center;justify-content:space-between;gap:12px}
.ms-head h2{font-size:28px;font-weight:800;color:var(--ms-gold-soft);line-height:1.1}
.ms-pill{display:inline-flex;align-items:center;height:30px;padding:0 13px;border-radius:999px;background:rgba(126,230,187,.14);border:1px solid rgba(126,230,187,.4);color:var(--ms-mint);font-size:12.5px;font-weight:800}
.ms-pill.is-quiet{background:transparent;border-color:var(--ms-line);color:var(--ms-muted);font-weight:600}

/* رقم الجوال */
.ms-phone{display:grid;grid-template-columns:auto 1fr auto;align-items:center;gap:12px;padding:12px 14px;border:1px solid var(--ms-line);border-radius:18px;background:var(--ms-surface)}
.ms-phone-icon{display:grid;place-items:center;width:42px;height:42px;border-radius:13px;background:rgba(230,207,148,.1);border:1px solid rgba(230,207,148,.35);color:var(--ms-gold)}
.ms-phone-text{display:grid;gap:2px;min-width:0}
.ms-phone-text small{font-size:11.5px;color:var(--ms-muted)}
.ms-phone-text b{font-size:19px;font-weight:800;letter-spacing:.06em;font-variant-numeric:tabular-nums;text-align:right}
.ms-icon-btn{display:grid;place-items:center;width:40px;height:40px;border:1px solid var(--ms-line);border-radius:12px;background:rgba(255,255,255,.04)}
.ms-icon-btn:hover{border-color:rgba(230,207,148,.45)}

/* البحث */
.ms-search{display:flex;align-items:center;gap:10px;width:100%;min-height:50px;padding:0 16px;border:1px solid var(--ms-line);border-radius:16px;background:var(--ms-surface-2);color:var(--ms-muted);text-align:start;font-size:14.5px}
.ms-search svg{color:var(--ms-gold);flex:none}
.ms-search:hover{border-color:rgba(230,207,148,.45)}

/* قائمة المحادثات */
.ms-section-title{display:flex;align-items:baseline;justify-content:space-between;margin-top:4px}
.ms-section-title h3{font-size:17px;font-weight:800;color:var(--ms-gold-soft)}
.ms-section-title span{font-size:12px;color:var(--ms-muted)}
.ms-list{display:grid;gap:8px}
.ms-row{display:grid;grid-template-columns:48px minmax(0,1fr);gap:12px;align-items:center;width:100%;padding:11px 12px;border:1px solid var(--ms-line);border-radius:16px;background:var(--ms-surface);text-align:start}
.ms-row:hover{border-color:rgba(230,207,148,.4)}
.ms-row.is-unread{border-color:rgba(126,230,187,.45);background:linear-gradient(135deg,#183a43,#142f38)}
.ms-avatar{display:grid;place-items:center;width:48px;height:48px;border-radius:50%;background:radial-gradient(circle at 30% 25%,#2a5260,#12303a 75%);border:1.5px solid rgba(230,207,148,.55);color:var(--ms-gold-soft);font-size:19px;font-weight:800;flex:none}
.ms-row-body{display:grid;gap:5px;min-width:0}
.ms-row-top{display:flex;align-items:baseline;justify-content:space-between;gap:8px}
.ms-row-top b{font-size:15.5px;font-weight:800;color:var(--ms-gold-soft);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.ms-row-top time{font-size:11px;color:var(--ms-muted);white-space:nowrap}
.ms-row-bottom{display:flex;align-items:center;justify-content:space-between;gap:8px}
.ms-preview{font-size:13px;color:var(--ms-muted);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}
.ms-preview em{font-style:normal;color:#b9a8ee}
.ms-row.is-unread .ms-preview{color:var(--ms-text);font-weight:700}
.ms-count{display:grid;place-items:center;min-width:22px;height:22px;padding:0 6px;border-radius:999px;background:var(--ms-mint);color:#0b2a22;font-style:normal;font-size:12px;font-weight:800;flex:none}
.ms-empty{display:grid;gap:6px;justify-items:center;padding:26px 16px;border:1px dashed rgba(230,207,148,.35);border-radius:18px;text-align:center}
.ms-empty b{font-size:16px;color:var(--ms-gold-soft)}
.ms-empty span{font-size:13px;color:var(--ms-muted);line-height:1.7}

/* نافذة البحث من الأسفل */
.ms-sheet-backdrop{position:fixed;inset:0;z-index:9998;background:rgba(3,10,13,.62);backdrop-filter:blur(2px)}
.ms-sheet{position:fixed;z-index:9999;inset-inline:0;bottom:0;max-width:620px;margin:0 auto;display:grid;gap:12px;padding:10px 18px calc(22px + env(safe-area-inset-bottom,0px));border:1px solid rgba(230,207,148,.3);border-bottom:0;border-radius:26px 26px 0 0;background:linear-gradient(180deg,#1a3641,#10262e);box-shadow:0 -18px 50px rgba(0,0,0,.5);transform:translateY(105%);transition:transform .32s cubic-bezier(.2,.9,.3,1)}
.ms-sheet.is-in{transform:translateY(0)}
.ms-sheet-handle{justify-self:center;width:44px;height:5px;border-radius:999px;background:rgba(255,255,255,.22)}
.ms-sheet-head{display:flex;align-items:center;justify-content:space-between}
.ms-sheet-head h3{font-size:19px;font-weight:800;color:var(--ms-gold-soft)}
.ms-label{font-size:12.5px;color:var(--ms-muted)}
.ms-input-row{display:grid;grid-template-columns:1fr auto;gap:10px}
.ms-input-row input{min-height:52px;padding:0 16px;border:1px solid var(--ms-line);border-radius:14px;background:#0c1c22;color:var(--ms-text);font:inherit;font-size:20px;font-weight:700;letter-spacing:.12em;text-align:left;font-variant-numeric:tabular-nums}
.ms-input-row input::placeholder{color:#5d7570;letter-spacing:.1em;font-weight:500}
.ms-input-row input:focus,.ms-composer textarea:focus{outline:2px solid var(--ms-gold);outline-offset:1px;border-color:transparent}
.ms-go{min-height:52px;padding:0 20px;border:1px solid rgba(230,207,148,.45);border-radius:14px;background:rgba(230,207,148,.1);color:var(--ms-gold-soft);font-weight:800}
.ms-go.is-primary{border:0;background:var(--ms-cta);color:#20163f;min-height:44px;padding:0 14px}
.ms-go:disabled{opacity:.55}
.ms-error{padding:10px 12px;border-radius:12px;background:rgba(240,120,120,.12);border:1px solid rgba(240,120,120,.35);color:#f3b3b3;font-size:13px}
.ms-found{display:grid;grid-template-columns:auto 1fr auto;gap:12px;align-items:center;padding:12px;border:1px solid rgba(126,230,187,.4);border-radius:16px;background:rgba(126,230,187,.07)}
.ms-found span:nth-child(2){display:grid;gap:2px;min-width:0}
.ms-found b{font-size:15.5px;color:var(--ms-gold-soft)}
.ms-found small{font-size:12.5px;color:var(--ms-muted);text-align:right;letter-spacing:.06em}

/* المحادثة */
.ms-thread{padding-bottom:0;gap:0;min-height:calc(100dvh - 110px);grid-template-rows:auto 1fr auto}
.ms-thread-head{display:grid;grid-template-columns:auto auto 1fr auto auto;gap:12px;align-items:center;padding:8px 0 12px;border-bottom:1px solid var(--ms-line)}
.ms-thread-head .ms-icon-btn svg{transform:none}
.ms-thread-name{display:grid;gap:2px;min-width:0}
.ms-thread-name b{font-size:16.5px;font-weight:800;color:var(--ms-gold-soft)}
.ms-thread-name small{font-size:12px;color:var(--ms-muted);text-align:right;letter-spacing:.06em}
.ms-messages{display:flex;flex-direction:column;gap:6px;padding:14px 2px;overflow-y:auto;max-height:calc(100dvh - 300px);min-height:200px}
.ms-day{align-self:center;margin:8px 0 4px}
.ms-day span{padding:3px 12px;border-radius:999px;background:rgba(255,255,255,.06);font-size:11.5px;color:var(--ms-muted)}
.ms-bubble{max-width:82%;padding:9px 13px 6px;border-radius:18px;display:grid;gap:3px}
.ms-bubble p{font-size:14.5px;line-height:1.7;white-space:pre-wrap;overflow-wrap:anywhere}
.ms-bubble.is-mine{align-self:flex-start;background:linear-gradient(135deg,#2f5b52,#24473f);border-bottom-right-radius:6px;border:1px solid rgba(126,230,187,.3)}
.ms-bubble.is-theirs{align-self:flex-end;background:var(--ms-surface-2);border-bottom-left-radius:6px;border:1px solid var(--ms-line)}
.ms-meta{display:flex;align-items:center;gap:5px;font-size:10.5px;color:var(--ms-muted)}
.ms-meta i{font-style:normal;color:var(--ms-mint);letter-spacing:-.1em}
.ms-composer{position:sticky;bottom:76px;display:grid;grid-template-columns:1fr auto;gap:10px;align-items:end;padding:10px 0 0;background:linear-gradient(180deg,transparent,var(--ms-bg) 30%)}
.ms-composer textarea{min-height:48px;max-height:120px;resize:none;padding:12px 14px;border:1px solid var(--ms-line);border-radius:16px;background:#0c1c22;color:var(--ms-text);font:inherit;font-size:14.5px;line-height:1.5}
.ms-send{display:grid;place-items:center;width:50px;height:48px;border:0;border-radius:15px;background:var(--ms-cta);color:#20163f}
.ms-send:disabled{opacity:.5}
.ms-send svg{transform:scaleX(-1)}

/* إشعار على أيقونة الرسائل في الرئيسية */
[onclick*="openPage('messages')"]{position:relative}
.ms-tile-badge{position:absolute;top:6px;inset-inline-start:6px;display:grid;place-items:center;min-width:22px;height:22px;padding:0 6px;border-radius:999px;background:#7ee6bb;color:#0b2a22;font-size:12px;font-weight:800;box-shadow:0 0 0 3px rgba(16,35,44,.9);z-index:3}
#ms-toast{position:fixed;z-index:80;inset-inline:0;bottom:96px;margin:0 auto;width:max-content;max-width:86vw;padding:10px 16px;border-radius:12px;background:#101b1b;border:1px solid #648f84;color:#f5f1e9;font-size:13.5px;opacity:0;pointer-events:none;transition:opacity .18s}
#ms-toast.is-on{opacity:1}
#messages-v3-root button:focus-visible{outline:2px solid var(--ms-gold);outline-offset:2px}
@media(max-width:380px){.ms-head h2{font-size:25px}.ms-phone-text b{font-size:17px}}
@media(prefers-reduced-motion:reduce){.ms-sheet{transition:none}}
#messages > :not(#messages-v3-root){display:none!important}
#messages-v3-root .ms-composer textarea{min-height:48px!important;height:48px;max-height:120px;resize:none!important;overflow-y:auto}

/* صندوق رقم المستلم + لوحة الاتصال */
.ms-search{display:grid;grid-template-columns:auto 1fr auto;align-items:center;gap:12px;min-height:66px;padding:12px 14px;border:1px solid rgba(230,207,148,.35);background:var(--ms-surface)}
.ms-search .ms-phone-icon{width:42px;height:42px}
.ms-search-hint{font-size:18px;font-weight:700;letter-spacing:.08em;color:#5d7570;text-align:right;font-variant-numeric:tabular-nums}
.ms-search-go{padding:8px 14px;border-radius:12px;background:var(--ms-cta);color:#20163f;font-size:13px;font-weight:800}
.ms-hint{text-align:center;font-size:12.5px;color:var(--ms-muted)}
.ms-dial-display{display:flex;justify-content:center;align-items:center;gap:6px;padding:6px 0 2px}
.ms-dial-gap{width:10px}
.ms-slot{display:grid;place-items:center;width:27px;height:44px;border-radius:9px;border:1px solid var(--ms-line);background:#0c1c22;font-size:21px;font-weight:800;color:var(--ms-gold-soft);font-variant-numeric:tabular-nums}
.ms-slot.is-fixed{color:var(--ms-muted);background:rgba(255,255,255,.04)}
.ms-slot.is-filled:not(.is-fixed){border-color:rgba(230,207,148,.5)}
.ms-slot.is-next{border-color:var(--ms-gold);box-shadow:0 0 0 2px rgba(230,207,148,.25)}
.ms-keypad{display:grid;grid-template-columns:repeat(3,1fr);gap:10px;max-width:340px;width:100%;margin:2px auto 0}
.ms-key{display:grid;place-items:center;height:56px;border:1px solid var(--ms-line);border-radius:16px;background:var(--ms-surface-2);color:var(--ms-text);font-size:24px;font-weight:700;font-variant-numeric:tabular-nums;touch-action:manipulation}
.ms-key:hover{border-color:rgba(230,207,148,.45)}
.ms-key:active{transform:scale(.96);background:#25454f}
.ms-key.is-aux{background:transparent;color:var(--ms-muted)}
.ms-key.is-go{display:none}
.ms-send-go{width:100%;max-width:340px;min-height:52px;margin:4px auto 0;border:0;border-radius:15px;background:var(--ms-cta);color:#20163f;font-size:16px;font-weight:800}
.ms-send-go:disabled{opacity:.4}
.ms-sheet{justify-items:center}
.ms-sheet>*{width:100%}
.ms-sheet>#ms-dial-body{display:grid;gap:10px;justify-items:center}
.ms-sheet .ms-found,.ms-sheet .ms-error{max-width:340px}
@media(max-width:380px){.ms-slot{width:24px;height:40px;font-size:19px}.ms-key{height:50px}.ms-search-go{display:none}.ms-search{grid-template-columns:auto 1fr}}
.ms-sheet>.ms-sheet-handle{width:44px}
.ms-keypad,.ms-dial-display{direction:ltr}
body:has(.ms-sheet) .floating-home,body:has(.ms-sheet) #floatingHome{display:none!important}

.ms-safe-btn{min-height:34px;padding:0 12px;border:1px solid var(--ms-line);border-radius:10px;background:rgba(255,255,255,.05);color:inherit;font:inherit;font-size:12.5px;font-weight:700;cursor:pointer}
.ms-safe-btn[data-ms-block]{color:#ffb4bd}

.ms-avatar img{width:100%;height:100%;object-fit:cover;border-radius:inherit}
