/* ============================================================
   HR Alerts — نظام رسائل التنبيه الموحّد
   حوارات مركزية للرسائل الحرجة (خطأ/تحذير/تأكيد) وتوستات علوية
   غير معيقة لرسائل النجاح والمعلومات. RTL بالكامل، يدعم الوضع
   الداكن (body.dark) ويحترم تفضيل تقليل الحركة.
   ============================================================ */

:root {
    --hra-bg: #ffffff;
    --hra-text: #1f2a3d;
    --hra-muted: #64748b;
    --hra-border: rgba(100, 116, 139, .16);
    --hra-success: #10b981;
    --hra-error: #ef4444;
    --hra-warning: #f59e0b;
    --hra-info: #3b82f6;
    --hra-question: #6366f1;
    --hra-overlay: rgba(15, 23, 42, .48);
    --hra-radius: 18px;
    --hra-shadow: 0 24px 64px -12px rgba(15, 23, 42, .28), 0 8px 24px -8px rgba(15, 23, 42, .14);
    --hra-toast-shadow: 0 12px 32px -8px rgba(15, 23, 42, .22);
    --hra-font: inherit;
}

body.dark {
    --hra-bg: #1e2a3a;
    --hra-text: #e2e8f0;
    --hra-muted: #94a3b8;
    --hra-border: rgba(148, 163, 184, .14);
    --hra-overlay: rgba(2, 6, 16, .62);
    --hra-shadow: 0 24px 64px -12px rgba(0, 0, 0, .55), 0 8px 24px -8px rgba(0, 0, 0, .35);
    --hra-toast-shadow: 0 12px 32px -8px rgba(0, 0, 0, .5);
}

/* ------------------------------------------------------------
   الطبقة الحاجبة والحوار
   ------------------------------------------------------------ */
.hra-overlay {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: var(--hra-overlay);
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
    opacity: 0;
    transition: opacity .22s ease;
    direction: rtl;
    font-family: var(--hra-font);
}

.hra-overlay.hra-show { opacity: 1; }
.hra-overlay.hra-hide { opacity: 0; }

.hra-dialog {
    position: relative;
    width: 100%;
    max-width: 430px;
    background: var(--hra-bg);
    color: var(--hra-text);
    border-radius: var(--hra-radius);
    box-shadow: var(--hra-shadow);
    padding: 34px 30px 26px;
    text-align: center;
    overflow: hidden;
    transform: translateY(14px) scale(.94);
    opacity: 0;
    transition: transform .34s cubic-bezier(.18, 1.3, .34, 1), opacity .22s ease;
}

.hra-overlay.hra-show .hra-dialog { transform: translateY(0) scale(1); opacity: 1; }
.hra-overlay.hra-hide .hra-dialog { transform: translateY(8px) scale(.96); opacity: 0; }

.hra-dialog.hra-wide { max-width: 640px; }

/* شريط لون علوي رفيع بلون الحالة */
.hra-dialog::before {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    height: 4px;
    background: var(--hra-accent, var(--hra-info));
    opacity: .9;
}

.hra-dialog.hra-success  { --hra-accent: var(--hra-success); }
.hra-dialog.hra-error    { --hra-accent: var(--hra-error); }
.hra-dialog.hra-warning  { --hra-accent: var(--hra-warning); }
.hra-dialog.hra-info     { --hra-accent: var(--hra-info); }
.hra-dialog.hra-question { --hra-accent: var(--hra-question); }

/* اهتزاز خفيف يلفت النظر لرسائل الخطأ */
.hra-overlay.hra-show .hra-dialog.hra-error { animation: hra-shake .5s cubic-bezier(.36, .07, .19, .97) .25s; }

@keyframes hra-shake {
    10%, 90% { transform: translateX(-1px); }
    20%, 80% { transform: translateX(2px); }
    30%, 50%, 70% { transform: translateX(-3px); }
    40%, 60% { transform: translateX(3px); }
}

/* ------------------------------------------------------------
   الأيقونة: دائرة بخلفية شفيفة بلون الحالة + رسم متحرك
   ------------------------------------------------------------ */
.hra-icon-wrap {
    position: relative;
    width: 84px;
    height: 84px;
    margin: 0 auto 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: color-mix(in srgb, var(--hra-accent, var(--hra-info)) 12%, transparent);
}

/* حلقة نبض تتمدد خلف الأيقونة */
.hra-icon-wrap::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid var(--hra-accent, var(--hra-info));
    opacity: 0;
    animation: hra-ring 1.4s ease-out .35s;
}

@keyframes hra-ring {
    0%   { transform: scale(.7); opacity: .55; }
    100% { transform: scale(1.45); opacity: 0; }
}

.hra-icon {
    width: 46px;
    height: 46px;
    stroke: var(--hra-accent, var(--hra-info));
    stroke-width: 2.4;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}

/* رسم المسار تدريجياً (علامة الصح، إكس الخطأ...) */
.hra-icon .hra-draw {
    stroke-dasharray: 90;
    stroke-dashoffset: 90;
    animation: hra-draw .55s ease-out .28s forwards;
}

.hra-icon .hra-draw-late {
    stroke-dasharray: 90;
    stroke-dashoffset: 90;
    animation: hra-draw .45s ease-out .5s forwards;
}

@keyframes hra-draw { to { stroke-dashoffset: 0; } }

/* نبض علامة التحذير */
.hra-dialog.hra-warning .hra-icon { animation: hra-pulse 1.6s ease-in-out .5s infinite; }

@keyframes hra-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.08); }
}

/* ------------------------------------------------------------
   النصوص والأزرار
   ------------------------------------------------------------ */
.hra-title {
    font-size: 19px;
    font-weight: 700;
    margin-bottom: 8px;
    line-height: 1.5;
}

.hra-text {
    font-size: 14.5px;
    color: var(--hra-muted);
    line-height: 1.9;
    margin-bottom: 22px;
    white-space: pre-line;
    word-break: break-word;
}

.hra-title:empty, .hra-text:empty { display: none; }

.hra-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.hra-btn {
    min-width: 108px;
    padding: 9px 22px;
    border-radius: 12px;
    border: 1px solid transparent;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: transform .15s ease, box-shadow .15s ease, background .15s ease, filter .15s ease;
    outline: none;
}

.hra-btn:hover { transform: translateY(-1px); filter: brightness(1.06); }
.hra-btn:active { transform: translateY(0); }

.hra-btn-primary {
    color: #fff;
    background: var(--hra-accent, var(--hra-info));
    box-shadow: 0 6px 16px -6px color-mix(in srgb, var(--hra-accent, var(--hra-info)) 65%, transparent);
}

.hra-btn-primary:focus-visible {
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--hra-accent, var(--hra-info)) 30%, transparent);
}

.hra-btn-danger {
    color: #fff;
    background: var(--hra-error);
    box-shadow: 0 6px 16px -6px color-mix(in srgb, var(--hra-error) 65%, transparent);
}

.hra-btn-ghost {
    color: var(--hra-muted);
    background: transparent;
    border-color: var(--hra-border);
}

.hra-btn-ghost:hover { background: color-mix(in srgb, var(--hra-muted) 8%, transparent); }

/* ------------------------------------------------------------
   شريط التقدم للعدّ التنازلي قبل الإغلاق التلقائي
   ------------------------------------------------------------ */
.hra-progress {
    position: absolute;
    bottom: 0;
    right: 0;
    left: 0;
    height: 3px;
    background: color-mix(in srgb, var(--hra-accent, var(--hra-info)) 14%, transparent);
}

.hra-progress > span {
    display: block;
    height: 100%;
    width: 100%;
    background: var(--hra-accent, var(--hra-info));
    transform-origin: right;
    animation: hra-countdown linear forwards;
}

@keyframes hra-countdown {
    from { transform: scaleX(1); }
    to   { transform: scaleX(0); }
}

/* ------------------------------------------------------------
   التوستات (إشعارات علوية غير معيقة)
   ------------------------------------------------------------ */
.hra-toast-region {
    position: fixed;
    /* تحت الهيدر الثابت للنظام كي لا يتغطى التوست به */
    top: 86px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100001;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: min(430px, calc(100vw - 32px));
    direction: rtl;
    pointer-events: none;
    font-family: var(--hra-font);
}

.hra-toast {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    width: 100%;
    padding: 13px 16px 15px;
    background: var(--hra-bg);
    color: var(--hra-text);
    border: 1px solid var(--hra-border);
    border-radius: 14px;
    box-shadow: var(--hra-toast-shadow);
    overflow: hidden;
    pointer-events: auto;
    transform: translateY(-16px) scale(.97);
    opacity: 0;
    transition: transform .3s cubic-bezier(.18, 1.3, .34, 1), opacity .22s ease;
}

.hra-toast.hra-show { transform: translateY(0) scale(1); opacity: 1; }
.hra-toast.hra-hide { transform: translateY(-10px) scale(.97); opacity: 0; }

.hra-toast.hra-success  { --hra-accent: var(--hra-success); }
.hra-toast.hra-error    { --hra-accent: var(--hra-error); }
.hra-toast.hra-warning  { --hra-accent: var(--hra-warning); }
.hra-toast.hra-info     { --hra-accent: var(--hra-info); }

/* شريط لون جانبي (يمين — RTL) */
.hra-toast::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    width: 4px;
    background: var(--hra-accent);
}

.hra-toast .hra-toast-icon {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    margin-top: 1px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: color-mix(in srgb, var(--hra-accent) 13%, transparent);
}

.hra-toast .hra-toast-icon svg {
    width: 19px;
    height: 19px;
    stroke: var(--hra-accent);
    stroke-width: 2.6;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}

.hra-toast-body { flex: 1 1 auto; min-width: 0; }

.hra-toast-title {
    font-size: 14px;
    font-weight: 700;
    line-height: 1.6;
}

.hra-toast-text {
    font-size: 13px;
    color: var(--hra-muted);
    line-height: 1.7;
    word-break: break-word;
}

.hra-toast-title:empty, .hra-toast-text:empty { display: none; }

.hra-toast-close {
    flex: 0 0 auto;
    width: 26px;
    height: 26px;
    margin-right: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--hra-muted);
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    transition: background .15s ease, color .15s ease;
}

.hra-toast-close:hover {
    background: color-mix(in srgb, var(--hra-muted) 12%, transparent);
    color: var(--hra-text);
}

.hra-toast .hra-progress { height: 2.5px; }

/* إيقاف العدّ عند مرور المؤشر — إمهال القارئ */
.hra-toast:hover .hra-progress > span,
.hra-dialog:hover .hra-progress > span { animation-play-state: paused; }

/* ------------------------------------------------------------
   شاشات صغيرة
   ------------------------------------------------------------ */
@media (max-width: 480px) {
    .hra-dialog { padding: 28px 20px 22px; }
    .hra-icon-wrap { width: 72px; height: 72px; }
    .hra-icon { width: 40px; height: 40px; }
    .hra-actions { flex-direction: column-reverse; }
    .hra-btn { width: 100%; }
}

/* ------------------------------------------------------------
   احترام تفضيل تقليل الحركة
   ------------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
    .hra-overlay, .hra-dialog, .hra-toast, .hra-btn { transition: none; }
    .hra-icon .hra-draw, .hra-icon .hra-draw-late { animation-duration: .01s; animation-delay: 0s; }
    .hra-icon-wrap::after,
    .hra-dialog.hra-warning .hra-icon,
    .hra-overlay.hra-show .hra-dialog.hra-error { animation: none; }
}
