/**
 * Claude Theme Improvements
 * تحسينات قالب كلود - إصلاحات RTL، إمكانية الوصول، والأداء
 */

/* ========================================
   1. تحسينات RTL (دعم اللغة العربية)
   ======================================== */

[dir="rtl"] {
    text-align: right;
}

[dir="rtl"] .text-left {
    text-align: right !important;
}

[dir="rtl"] .text-right {
    text-align: left !important;
}

/* إصلاح الأيقونات في RTL */
[dir="rtl"] .chevron-right {
    transform: rotate(180deg);
}

[dir="rtl"] .arrow-right {
    transform: scaleX(-1);
}

/* تحسين المسافات للنصوص العربية */
[dir="rtl"] p,
[dir="rtl"] span,
[dir="rtl"] div {
    letter-spacing: normal;
}

[dir="rtl"] .tracking-wide,
[dir="rtl"] .tracking-wider,
[dir="rtl"] .tracking-widest {
    letter-spacing: normal !important;
}

/* تحسين line-height للنصوص العربية */
[dir="rtl"] {
    line-height: 1.8;
}

[dir="rtl"] .leading-tight {
    line-height: 1.6 !important;
}

/* إصلاح الـ tooltips */
[dir="rtl"] .tooltip {
    direction: rtl;
}

/* ========================================
   2. تحسينات إمكانية الوصول
   ======================================== */

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

/* Skip to main content */
.skip-to-main {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--c-primary);
    color: white;
    padding: 8px 16px;
    text-decoration: none;
    border-radius: 0 0 4px 0;
    z-index: 10000;
    font-weight: bold;
}

.skip-to-main:focus {
    top: 0;
}

/* تحسين مؤشرات التركيز */
*:focus-visible {
    outline: 2px solid var(--c-primary);
    outline-offset: 2px;
    border-radius: 0.375rem;
}

button:focus-visible,
a:focus-visible {
    box-shadow: 0 0 0 3px rgba(var(--c-primary-rgb), 0.3);
}

/* إزالة outline للماوس فقط */
*:focus:not(:focus-visible) {
    outline: none;
}

/* تحسين التباين للنصوص */
.text-c-muted {
    color: #6b7280;
}

[data-theme="dark"] .text-c-muted {
    color: #9ca3af;
}

/* ========================================
   3. تحسينات الأداء
   ======================================== */

/* Smooth scrolling مع performance optimization */
@media (prefers-reduced-motion: no-preference) {
    html {
        scroll-behavior: smooth;
    }
}

/* تقليل animation للمستخدمين الذين يفضلون reduced motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* تحسين rendering للصور */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

img[loading="lazy"] {
    content-visibility: auto;
}

/* Hardware acceleration للanimations */
.animate-fade,
.animate-slide,
.animate-scale {
    will-change: transform, opacity;
    backface-visibility: hidden;
    perspective: 1000px;
}

/* تحسين custom scrollbar */
.custom-scrollbar {
    scrollbar-width: thin;
    scrollbar-color: rgba(var(--c-primary-rgb), 0.3) transparent;
}

.custom-scrollbar::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: transparent;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background: rgba(var(--c-primary-rgb), 0.3);
    border-radius: 10px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: rgba(var(--c-primary-rgb), 0.5);
}

/* ========================================
   4. تحسينات Mobile UX
   ======================================== */

/* Touch targets - minimum 44x44px */
@media (max-width: 768px) {
    button,
    a,
    input[type="button"],
    input[type="submit"] {
        min-height: 44px;
        min-width: 44px;
    }

    /* Increase padding for better touch */
    .btn,
    .button {
        padding: 12px 20px;
    }

    /* Larger text inputs */
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="number"],
    select,
    textarea {
        font-size: 16px; /* Prevent zoom on iOS */
        min-height: 44px;
    }
}

/* Prevent text selection on interactive elements */
.no-select {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* Safe area for notch devices */
@supports (padding: max(0px)) {
    .safe-area-inset-top {
        padding-top: max(env(safe-area-inset-top), 0.5rem);
    }

    .safe-area-inset-bottom {
        padding-bottom: max(env(safe-area-inset-bottom), 0.5rem);
    }
}

/* ========================================
   5. تحسينات Typography
   ======================================== */

/* تحسين قراءة النصوص */
body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* منع orphans في النصوص */
p {
    orphans: 3;
    widows: 3;
}

/* تحسين line breaks للنصوص العربية */
[dir="rtl"] p,
[dir="rtl"] .break-words {
    word-break: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

/* ========================================
   6. Loading States & Skeletons
   ======================================== */

/* Skeleton loader animation */
@keyframes skeleton-loading {
    0% {
        background-position: -200px 0;
    }
    100% {
        background-position: calc(200px + 100%) 0;
    }
}

.skeleton {
    background: linear-gradient(
        90deg,
        rgba(var(--c-border-rgb), 0.2) 0%,
        rgba(var(--c-border-rgb), 0.4) 50%,
        rgba(var(--c-border-rgb), 0.2) 100%
    );
    background-size: 200px 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
}

/* Spinner animation */
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.animate-spin {
    animation: spin 1s linear infinite;
}

/* ========================================
   7. Error States & Validation
   ======================================== */

/* Error message styling */
.error-message {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 0.5rem;
    color: #dc2626;
    font-size: 0.875rem;
    margin-top: 0.5rem;
}

[data-theme="dark"] .error-message {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
}

/* Input validation states */
input.invalid,
select.invalid,
textarea.invalid {
    border-color: #ef4444 !important;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

input.valid,
select.valid,
textarea.valid {
    border-color: #10b981 !important;
}

/* ========================================
   8. Modal & Overlay Improvements
   ======================================== */

/* Prevent body scroll when modal is open */
body.modal-open {
    overflow: hidden;
}

/* Modal backdrop */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
}

/* Modal content */
.modal-content {
    position: relative;
    max-height: 90vh;
    overflow-y: auto;
    overscroll-behavior: contain;
}

/* ========================================
   9. Print Styles
   ======================================== */

@media print {
    /* Hide non-essential elements */
    header,
    footer,
    nav,
    .no-print,
    button,
    .cart-sidebar,
    .mobile-nav {
        display: none !important;
    }

    /* Optimize for print */
    body {
        background: white !important;
        color: black !important;
        font-size: 12pt;
    }

    a {
        text-decoration: underline;
    }

    /* Show URLs after links */
    a[href]:after {
        content: " (" attr(href) ")";
    }
}

/* ========================================
   10. Utility Classes
   ======================================== */

/* Fade in animation */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.3s ease-out;
}

/* Slide in from right */
@keyframes slideInRight {
    from {
        transform: translateX(100%);
    }
    to {
        transform: translateX(0);
    }
}

.slide-in-right {
    animation: slideInRight 0.3s ease-out;
}

[dir="rtl"] .slide-in-right {
    animation: slideInLeft 0.3s ease-out;
}

@keyframes slideInLeft {
    from {
        transform: translateX(-100%);
    }
    to {
        transform: translateX(0);
    }
}

/* Scale animation */
@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.scale-in {
    animation: scaleIn 0.2s ease-out;
}

/* Truncate text with ellipsis */
.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.truncate-2-lines {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.truncate-3-lines {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Aspect ratios */
.aspect-square {
    aspect-ratio: 1 / 1;
}

.aspect-video {
    aspect-ratio: 16 / 9;
}

.aspect-portrait {
    aspect-ratio: 3 / 4;
}

/* ========================================
   11. Dark Mode Improvements
   ======================================== */

@media (prefers-color-scheme: dark) {
    /* Improve image visibility in dark mode */
    img:not([src*=".svg"]) {
        opacity: 0.9;
    }

    /* Reduce bright backgrounds */
    .bg-white {
        background-color: #1f2937 !important;
    }
}

/* ========================================
   12. High Contrast Mode Support
   ======================================== */

@media (prefers-contrast: high) {
    :root {
        --c-border: #000000;
        --c-text: #000000;
        --c-bg: #ffffff;
    }

    [data-theme="dark"] {
        --c-border: #ffffff;
        --c-text: #ffffff;
        --c-bg: #000000;
    }

    button,
    a {
        border: 2px solid currentColor;
    }
}
