/* ==========================================
   CSS Reset & Base
   ========================================== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

/*
 * تعريف متغير ارتفاع الإعلان الثابت بحيث يمكن تعديل padding بطريقة
 * مرنة. يمكن تعديل هذه القيمة لاحقاً بدون تعديل الشيفرة الأخرى.
 */
:root {
    --fixed-video-height: 100px;
}

body {
    font-family: "Tajawal", sans-serif;
    background-color: var(--bg-color);
    background-image: var(--bg-gradient);
    background-attachment: fixed;
    color: var(--text-main);
    -webkit-tap-highlight-color: transparent;
    line-height: 1.7;
    /*
     * زيادة المسافة السفلية للجسم لاستيعاب عنصر الإعلان الثابت في الأسفل.
     * نجمع بين المسافة الأساسية (20px) وارتفاع الإعلان الثابت المحدد أعلاه.
     */
    padding-bottom: calc(20px + var(--fixed-video-height));
    overflow-x: hidden;
    transition:
        background-color 0.3s ease,
        background-image 0.3s ease,
        color 0.3s ease;
}

img,
svg,
video,
canvas,
audio,
iframe {
    display: block;
    max-width: 100%;
}

button,
input,
textarea,
select {
    font: inherit;
}

button {
    border: none;
    background: none;
}

a {
    color: inherit;
    text-decoration: none;
}

/* ==========================================
   Typography
   ========================================== */
.amiri-text {
    font-family: "Amiri", serif;
    line-height: 2;
}

.muted {
    color: var(--text-sub);
    font-size: 0.92rem;
    line-height: 1.65;
}

.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.text-strong {
    font-weight: 700;
}

/* ==========================================
   Focus & Accessibility
   ========================================== */
:focus {
    outline: none;
}

:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--primary) 60%, white);
    outline-offset: 3px;
    border-radius: var(--radius-sm);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[role="button"]:focus-visible {
    box-shadow:
        0 0 0 3px color-mix(in srgb, var(--card-bg) 70%, transparent),
        0 0 0 6px color-mix(in srgb, var(--primary) 28%, transparent);
}

::selection {
    background: var(--primary-light);
    color: var(--text-main);
}

[aria-hidden="true"] {
    pointer-events: none;
}

[hidden] {
    display: none !important;
}

.sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* ==========================================
   Buttons (Base)
   ========================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    background: var(--card-bg);
    color: var(--text-main);
    border: 1px solid var(--border);
    padding: 10px 20px;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition:
        transform 0.2s ease,
        background-color 0.2s ease,
        border-color 0.2s ease,
        color 0.2s ease,
        box-shadow 0.2s ease,
        opacity 0.2s ease,
        filter 0.2s ease;
    user-select: none;
    -webkit-user-select: none;
}

.btn:hover {
    box-shadow: var(--shadow-sm);
}

.btn:active {
    transform: scale(0.96);
}

.btn:disabled,
.btn[disabled],
.btn[aria-disabled="true"] {
    cursor: not-allowed;
    opacity: 0.6;
    transform: none;
    box-shadow: none;
    filter: saturate(0.8);
}

.btn--primary {
    background: var(--primary); /* سطر البديل الآمن للمتصفحات القديمة */
    background: linear-gradient(
        180deg,
        color-mix(in srgb, var(--primary) 92%, white),
        var(--primary)
    );
    color: #ffffff;
    border-color: var(--primary);
}


.btn--primary:hover {
    filter: brightness(1.03);
}

.btn--accent {
    background: var(--accent); /* سطر البديل الآمن */
    background: linear-gradient(
        180deg,
        color-mix(in srgb, var(--accent) 92%, white),
        var(--accent)
    );
    color: #ffffff;
    border-color: var(--accent);
}


.btn--accent:hover {
    filter: brightness(1.03);
}

[data-theme="royal"] .btn--primary,
[data-theme="royal"] .btn--accent {
    color: #0A2E24;
}

.btn--ghost {
    background: transparent;
    border-color: transparent;
    color: var(--primary);
}

.btn--ghost:hover {
    background: var(--primary-light);
}

.btn--ghost:active {
    background: var(--primary-light);
}

.btn--full {
    width: 100%;
}

.btn--start {
    justify-content: flex-start;
}

.btn--compact {
    min-height: auto;
    padding: 6px 12px;
    font-size: 0.9rem;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    transition:
        transform 0.2s ease,
        background-color 0.2s ease,
        border-color 0.2s ease,
        color 0.2s ease,
        box-shadow 0.2s ease,
        opacity 0.2s ease;
    background: var(--card-bg);
    border: 1px solid var(--border);
    color: var(--primary);
    flex-shrink: 0;
}

.icon-btn:hover {
    box-shadow: var(--shadow-sm);
}

.icon-btn:active {
    transform: scale(0.95);
}

.icon-btn:disabled,
.icon-btn[disabled],
.icon-btn[aria-disabled="true"] {
    cursor: not-allowed;
    opacity: 0.6;
    transform: none;
    box-shadow: none;
}

.icon-btn--transparent {
    background: transparent;
    border: none;
    box-shadow: none;
    color: var(--primary);
}

.icon-btn--danger {
    color: #ef4444;
}

/* ==========================================
   Inputs
   ========================================== */
.input {
    width: 100%;
    min-height: 44px;
    padding: 12px 15px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--card-bg); 
    background: color-mix(in srgb, var(--card-bg) 96%, white);
    color: var(--text-main);
    font-family: inherit;
    font-size: 1rem;
    transition:
        border-color 0.3s ease,
        box-shadow 0.3s ease,
        background-color 0.3s ease,
        color 0.3s ease;
}

.input::placeholder {
    color: var(--text-sub);
    opacity: 0.9;
}

.input:focus,
.input:focus-visible {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 12%, transparent);
    background: var(--card-bg);
}

.input:disabled,
.input[disabled],
.input[aria-disabled="true"] {
    cursor: not-allowed;
    opacity: 0.65;
}

.input-group {
    display: flex;
    align-items: center;
    gap: 8px;
}
/* ==========================================
   Toast
   ========================================== */
.app-toast {
    position: fixed;
    left: 50%;
    bottom: 18px;
    transform: translateX(-50%) translateY(120%);
    width: min(92vw, 420px);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-radius: 18px;
    border: 1px solid color-mix(in srgb, var(--border) 85%, transparent);
    background: color-mix(in srgb, var(--card-bg) 96%, white);
    color: var(--text-main);
    box-shadow:
        0 18px 40px rgba(0, 0, 0, 0.12),
        0 6px 18px rgba(0, 0, 0, 0.07);
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition:
        transform 0.26s ease,
        opacity 0.26s ease;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.app-toast--visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.app-toast__icon {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.05rem;
}

.app-toast__body {
    flex: 1;
    min-width: 0;
}

.app-toast__label {
    font-size: 0.8rem;
    font-weight: 800;
    margin-bottom: 2px;
    opacity: 0.85;
}

.app-toast__message {
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1.45;
    word-break: break-word;
}

.app-toast--success .app-toast__icon {
    background: color-mix(in srgb, var(--primary) 14%, white);
    color: var(--primary);
}

.app-toast--error .app-toast__icon {
    background: color-mix(in srgb, #ef4444 14%, white);
    color: #ef4444;
}

.app-toast--warning .app-toast__icon {
    background: color-mix(in srgb, #f59e0b 16%, white);
    color: #d97706;
}

.app-toast--info .app-toast__icon {
    background: color-mix(in srgb, var(--accent) 16%, white);
    color: var(--accent);
}

/* ==========================================
   Skeleton Loading
   ========================================== */
.skeleton {
    position: relative;
    overflow: hidden;
    background: color-mix(in srgb, var(--bg-color) 88%, white);
    border-radius: 10px;
}

.skeleton::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.45),
        transparent
    );
    animation: skeleton-loading 1.4s infinite;
}

@keyframes skeleton-loading {
    0% {
        transform: translateX(-100%);
    }

    100% {
        transform: translateX(100%);
    }
}

.skeleton-card {
    min-height: 80px;
    border-radius: 14px;
}

.skeleton-text {
    height: 16px;
    border-radius: 6px;
}

.skeleton-text-lg {
    height: 22px;
    border-radius: 6px;
}

.skeleton-circle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

/* ==========================================
   Surfaces & Generic UI Helpers
   ========================================== */
.surface-soft {
    background: var(--bg-color);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.divider {
    border: 0;
    border-top: 1px solid var(--border);
    margin: 20px 0;
}

.avatar {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    border: 2px solid var(--accent);
    object-fit: cover;
    flex-shrink: 0;
}

/* ==========================================
   Utilities
   ========================================== */
.is-hidden {
    display: none !important;
}

.no-select {
    user-select: none;
    -webkit-user-select: none;
}

.w-full {
    width: 100%;
}

.h-full {
    height: 100%;
}

.mb-0 {
    margin-bottom: 0 !important;
}

.mb-8 {
    margin-bottom: 8px !important;
}

.mb-12 {
    margin-bottom: 12px !important;
}

.mb-15 {
    margin-bottom: 15px !important;
}

.mb-20 {
    margin-bottom: 20px !important;
}

.mt-15 {
    margin-top: 15px !important;
}

.mt-20 {
    margin-top: 20px !important;
}

.mt-25 {
    margin-top: 25px !important;
}

.mt-35 {
    margin-top: 35px !important;
}

.p-0 {
    padding: 0 !important;
}

.rounded-sm {
    border-radius: var(--radius-sm) !important;
}

.rounded-md {
    border-radius: var(--radius-md) !important;
}

.rounded-lg {
    border-radius: var(--radius-lg) !important;
}

.border-soft {
    border: 1px solid var(--border) !important;
}

.shadow-soft {
    box-shadow: var(--shadow-sm) !important;
}

.shadow-medium {
    box-shadow: var(--shadow-md) !important;
}

.bg-card {
    background: var(--card-bg) !important;
}

.bg-soft {
    background: var(--bg-color) !important;
}

.color-primary {
    color: var(--primary) !important;
}

.color-accent {
    color: var(--accent) !important;
}

.color-danger {
    color: #ef4444 !important;
}

.flex-1 {
    flex: 1 !important;
}

.justify-start {
    justify-content: flex-start !important;
}

.justify-center {
    justify-content: center !important;
}

.align-center {
    align-items: center !important;
}

.overflow-auto {
    overflow: auto !important;
}

.overflow-y-auto {
    overflow-y: auto !important;
}

/* ==========================================
   Banners (Offline & Update)
   ========================================== */
.banner {
    position: sticky;
    top: 72px; /* ارتفاع الهيدر */
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    font-weight: 700;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.banner--warning {
    background: #fff3cd;
    color: #856404;
    border-color: #ffeeba;
}

.banner--info {
    background: #d1ecf1;
    color: #0c5460;
    border-color: #bee5eb;
}

.banner .btn--small {
    padding: 4px 10px;
    font-size: 0.85rem;
    min-height: auto;
}

/* ==========================================
   Empty States
   ========================================== */
.empty-state {
    text-align: center;
    padding: 30px 20px;
    color: var(--text-sub);
    font-size: 1rem;
}

/* ==========================================
   Task completed state
   ========================================== */
.task-card.is-completed {
    opacity: 0.7;
    background: color-mix(in srgb, var(--card-bg) 98%, var(--primary));
}

.task-card.is-completed .task-text {
    text-decoration: line-through;
    color: var(--text-sub);
}

/* ==========================================
   Silent button active state
   ========================================== */
.silent-active {
    color: var(--accent);
}

/* ==========================================
   Motion Preferences
   ========================================== */
@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}