/* ============================================================
   واجهة بوابة واتساب - تنسيق عربي RTL
   WhatsApp Walled Garden - Arabic RTL Dark Theme
   wifi2fm.com API Integration
   ============================================================ */

:root {
    --bg-deep:        #0a0f0d;
    --bg-primary:     #0d1412;
    --bg-surface:     #111b17;
    --bg-elevated:    #162520;
    --bg-hover:       #1a2e27;
    --accent:         #25d366;
    --accent-dim:     #1da851;
    --accent-glow:    rgba(37, 211, 102, 0.15);
    --accent-glow-strong: rgba(37, 211, 102, 0.3);
    --text-primary:   #e8ede9;
    --text-secondary: #8fa898;
    --text-muted:     #5a7565;
    --text-on-accent: #0a0f0d;
    --bubble-out:     #1a3a2a;
    --bubble-out-border: #25503a;
    --bubble-in:      #1a2220;
    --bubble-in-border: #2a3432;
    --border:         #1e3028;
    --danger:         #e74c3c;
    --warning:        #f39c12;
    --shadow:         0 4px 24px rgba(0,0,0,0.4);
    --radius:         12px;
    --radius-sm:      8px;
    --font-display:   'Noto Kufi Arabic', 'IBM Plex Sans Arabic', system-ui, sans-serif;
    --font-main:      'IBM Plex Sans Arabic', 'Noto Kufi Arabic', system-ui, sans-serif;
    --font-mono:      'JetBrains Mono', 'Fira Code', monospace;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { direction: rtl; }

html, body {
    height: 100%;
    font-family: var(--font-main);
    font-size: 15px;
    color: var(--text-primary);
    background: var(--bg-deep);
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

.hidden { display: none !important; }

.screen {
    width: 100%; height: 100%;
    position: absolute; top: 0; left: 0;
}


/* ── شاشة تسجيل الدخول ────────────────────────────────── */

.login-container {
    width: 100%; height: 100%;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    padding: 24px; position: relative;
}

.login-glow {
    position: absolute; top: 30%; left: 50%;
    transform: translate(-50%, -50%);
    width: 500px; height: 500px;
    background: radial-gradient(circle, var(--accent-glow) 0%, transparent 70%);
    pointer-events: none;
    animation: glowPulse 4s ease-in-out infinite;
}

@keyframes glowPulse {
    0%, 100% { opacity: 0.4; transform: translate(-50%, -50%) scale(1); }
    50%      { opacity: 0.7; transform: translate(-50%, -50%) scale(1.1); }
}

.login-card {
    width: 100%; max-width: 420px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 48px 36px 40px;
    position: relative; z-index: 1;
    box-shadow: var(--shadow);
}

.login-icon {
    width: 68px; height: 68px;
    margin: 0 auto 24px;
    background: var(--accent-glow);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: var(--accent);
    animation: iconFloat 3s ease-in-out infinite;
}
.login-icon svg { width: 38px; height: 38px; }

@keyframes iconFloat {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-6px); }
}

.login-title {
    text-align: center;
    font-family: var(--font-display);
    font-size: 2rem; font-weight: 800;
    margin-bottom: 10px;
}

.login-subtitle {
    text-align: center;
    font-size: 0.95rem; color: var(--text-secondary);
    margin-bottom: 34px; line-height: 1.7;
}

.login-form { display: flex; flex-direction: column; gap: 20px; }

.input-group label {
    display: block; font-size: 0.82rem; font-weight: 600;
    color: var(--text-secondary); margin-bottom: 10px;
    font-family: var(--font-display);
}

.phone-input-wrapper {
    display: flex; align-items: center;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color 0.2s, box-shadow 0.2s;
    direction: ltr;
}

.phone-input-wrapper:focus-within {
    border-color: var(--accent-dim);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.phone-prefix {
    padding: 0 4px 0 14px;
    font-size: 1.05rem; font-weight: 600;
    color: var(--accent); font-family: var(--font-mono);
}

.phone-input-wrapper input {
    flex: 1; background: transparent; border: none; outline: none;
    padding: 14px 14px 14px 4px;
    font-size: 1.1rem; font-family: var(--font-mono); font-weight: 500;
    color: var(--text-primary); letter-spacing: 0.05em;
    direction: ltr; text-align: left;
}
.phone-input-wrapper input::placeholder { color: var(--text-muted); font-weight: 400; }

.input-hint {
    display: block; font-size: 0.78rem; color: var(--text-muted);
    margin-top: 8px; text-align: right;
}


/* ── خطوات التحقق ─────────────────────────────────────── */

.verify-status {
    display: flex; flex-direction: column; gap: 8px;
    padding: 16px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.verify-step {
    display: flex; align-items: center; gap: 10px;
    font-size: 0.88rem; color: var(--text-muted);
    transition: color 0.3s;
}

.verify-step .step-icon {
    font-size: 1rem; width: 24px; text-align: center;
    flex-shrink: 0;
}

.verify-step.loading .step-text { color: var(--warning); }
.verify-step.loading .step-icon { animation: pulse 1s ease-in-out infinite; }

.verify-step.success .step-text { color: var(--accent); }
.verify-step.error .step-text { color: var(--danger); }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.4; }
}


/* ── الزر الرئيسي ─────────────────────────────────────── */

.btn-primary {
    width: 100%; padding: 15px;
    background: var(--accent); color: var(--text-on-accent);
    border: none; border-radius: var(--radius-sm);
    font-family: var(--font-display);
    font-size: 1.05rem; font-weight: 700;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
}
.btn-primary:hover { background: var(--accent-dim); box-shadow: 0 4px 20px var(--accent-glow-strong); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-loader {
    display: inline-flex; gap: 4px;
    align-items: center; justify-content: center;
}
.btn-loader .dot {
    width: 6px; height: 6px;
    background: var(--text-on-accent); border-radius: 50%;
    animation: dotBounce 0.6s ease-in-out infinite;
}
.btn-loader .dot:nth-child(2) { animation-delay: 0.1s; }
.btn-loader .dot:nth-child(3) { animation-delay: 0.2s; }

@keyframes dotBounce {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-6px); }
}

.error-msg {
    margin-top: 14px; padding: 10px 14px;
    background: rgba(231, 76, 60, 0.1);
    border: 1px solid rgba(231, 76, 60, 0.3);
    border-radius: var(--radius-sm);
    color: var(--danger); font-size: 0.88rem; text-align: center;
}

.login-footer {
    position: relative; z-index: 1;
    margin-top: 24px; font-size: 0.78rem;
    color: var(--text-muted); text-align: center;
}


/* ── شاشة المحادثة ─────────────────────────────────────── */

.chat-layout {
    display: flex; flex-direction: column;
    height: 100%; width: 100%; max-width: 720px;
    margin: 0 auto; background: var(--bg-primary);
}

.chat-header {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0; z-index: 10;
}

.header-btn {
    width: 36px; height: 36px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s; flex-shrink: 0;
}
.header-btn svg { transform: scaleX(-1); }
.header-btn:hover { background: var(--bg-hover); color: var(--danger); border-color: var(--danger); }

.header-avatar {
    width: 42px; height: 42px; border-radius: 50%;
    background: var(--accent-glow); color: var(--accent);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}

.header-info { flex: 1; min-width: 0; }
.header-name { font-family: var(--font-display); font-size: 1.05rem; font-weight: 700; line-height: 1.3; }
.header-status { font-size: 0.78rem; color: var(--accent); font-weight: 500; }
.header-status.offline { color: var(--text-muted); }
.header-phone { font-family: var(--font-mono); font-size: 0.8rem; color: var(--text-muted); flex-shrink: 0; direction: ltr; }


/* ── الرسائل ───────────────────────────────────────────── */

.chat-messages {
    flex: 1; overflow-y: auto; overflow-x: hidden;
    padding: 16px; scroll-behavior: smooth;
    background-image:
        radial-gradient(circle at 80% 50%, rgba(37,211,102,0.03) 0%, transparent 50%),
        radial-gradient(circle at 20% 20%, rgba(37,211,102,0.02) 0%, transparent 40%);
}

.chat-messages::-webkit-scrollbar { width: 5px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

.messages-inner {
    display: flex; flex-direction: column; gap: 6px;
    min-height: 100%; justify-content: flex-end;
}

.system-msg { text-align: center; padding: 8px 0; }
.system-msg span {
    display: inline-block; padding: 7px 18px;
    background: var(--bg-elevated); border-radius: 20px;
    font-size: 0.78rem; color: var(--text-muted);
}

.msg {
    display: flex; flex-direction: column;
    max-width: 78%;
    animation: msgIn 0.3s ease-out;
}

@keyframes msgIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

.msg.outgoing { align-self: flex-start; }
.msg.incoming { align-self: flex-end; }

.msg-bubble {
    padding: 10px 14px; border-radius: 16px;
    line-height: 1.7; word-wrap: break-word;
    overflow-wrap: break-word; font-size: 0.95rem;
}

.msg.outgoing .msg-bubble {
    background: var(--bubble-out);
    border: 1px solid var(--bubble-out-border);
    border-bottom-left-radius: 4px;
}

.msg.incoming .msg-bubble {
    background: var(--bubble-in);
    border: 1px solid var(--bubble-in-border);
    border-bottom-right-radius: 4px;
}

.msg-meta { display: flex; align-items: center; gap: 6px; margin-top: 4px; padding: 0 4px; }
.msg.outgoing .msg-meta { justify-content: flex-start; }
.msg.incoming .msg-meta { justify-content: flex-end; }

.msg-time { font-size: 0.68rem; color: var(--text-muted); font-family: var(--font-mono); direction: ltr; }
.msg-status { font-size: 0.7rem; }
.msg-status.delivered { color: var(--text-muted); }
.msg-status.read      { color: var(--accent); }
.msg-status.failed    { color: var(--danger); }


/* ── منطقة الإدخال ─────────────────────────────────────── */

.chat-input-area {
    padding: 12px 16px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.message-form { display: flex; align-items: flex-end; gap: 10px; }

.input-wrapper {
    flex: 1; background: var(--bg-elevated);
    border: 1px solid var(--border); border-radius: 24px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--accent-dim);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.input-wrapper textarea {
    display: block; width: 100%;
    padding: 12px 18px; background: transparent;
    border: none; outline: none;
    font-family: var(--font-main); font-size: 0.95rem;
    color: var(--text-primary); line-height: 1.6;
    resize: none; max-height: 120px; overflow-y: auto;
    direction: rtl; text-align: right;
}
.input-wrapper textarea::placeholder { color: var(--text-muted); }

.send-btn {
    width: 44px; height: 44px;
    background: var(--accent); color: var(--text-on-accent);
    border: none; border-radius: 50%;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.15s, opacity 0.2s;
}
.send-btn .send-icon { transform: scaleX(-1); }
.send-btn:hover:not(:disabled) { background: var(--accent-dim); transform: scale(1.06); }
.send-btn:active:not(:disabled) { transform: scale(0.95); }
.send-btn:disabled { opacity: 0.3; cursor: not-allowed; transform: none; }

/* ── زر إرفاق + معاينة الصورة ──────────────────────────── */

.attach-btn {
    width: 44px; height: 44px;
    background: transparent; color: var(--text-secondary);
    border: 1px solid var(--border); border-radius: 50%;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}
.attach-btn:hover { background: var(--bg-hover); color: var(--accent); border-color: var(--accent); }

.image-preview {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 16px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    position: relative;
}

.image-preview img {
    width: 60px; height: 60px;
    object-fit: cover; border-radius: 6px;
    border: 1px solid var(--border);
}

.image-preview .preview-label {
    font-size: 0.82rem; color: var(--text-secondary);
}

.cancel-image-btn {
    position: absolute; top: 4px; left: 4px;
    width: 22px; height: 22px;
    background: var(--danger); color: #fff;
    border: none; border-radius: 50%;
    font-size: 12px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: transform 0.15s;
}
.cancel-image-btn:hover { transform: scale(1.1); }

/* صورة في فقاعة الرسالة */
.msg-image {
    max-width: 100%; border-radius: 8px;
    margin-bottom: 6px;
}


/* ── التجاوب ───────────────────────────────────────────── */

@media (max-width: 480px) {
    .login-card { padding: 36px 24px 32px; border-radius: 16px; }
    .login-title { font-size: 1.6rem; }
    .chat-header { padding: 10px 12px; }
    .header-phone { display: none; }
    .msg { max-width: 88%; }
    .input-wrapper textarea { font-size: 1rem; }
}

@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .chat-input-area { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
}
