/* ============================================
   TOUMAI — BASE CSS
   Variables, Reset, Typography, Animations,
   Toast, Utilities
   ============================================ */

/* === CSS VARIABLES === */
:root {
    /* Primary Colors */
    --primary-gold: #c4a059;
    --gold-dark: #b38b45;
    --gold-light: #d4b876;
    --gold-glow: rgba(196, 160, 89, 0.3);

    /* Neutral Colors */
    --pure-pearl: #ffffff;
    --surface-white: #f8f9fa;
    --border-light: #e5e7eb;
    --border-medium: #d1d5db;

    /* Text Colors */
    --charcoal-text: #1a1a1a;
    --muted-text: #6b7280;
    --light-text: #9ca3af;

    /* Status Colors */
    --success-emerald: #27ae60;
    --success-light: rgba(39, 174, 96, 0.1);
    --error-coral: #e74c3c;
    --error-light: rgba(231, 76, 60, 0.1);
    --warning-amber: #f39c12;
    --warning-light: rgba(243, 156, 18, 0.1);
    --info-blue: #3498db;
    --info-light: rgba(52, 152, 219, 0.1);

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.08);
    --shadow-royal: 0 10px 30px rgba(196, 160, 89, 0.08);
    --shadow-royal-hover: 0 14px 40px rgba(196, 160, 89, 0.15);
    --shadow-gold-glow: 0 0 20px rgba(196, 160, 89, 0.25);

    /* Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 24px;
    --radius-full: 9999px;

    /* Transitions */
    --transition-fast: all 0.2s ease;
    --transition-normal: all 0.3s ease;
    --transition-elastic: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-bounce: all 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);

    /* Fonts */
    --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-arabic: 'Tajawal', 'Cairo', var(--font-primary);

    /* Font Sizes */
    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
    --text-3xl: 1.875rem;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;
}

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

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-primary);
    font-size: var(--text-base);
    line-height: 1.6;
    color: var(--charcoal-text);
    background: var(--surface-white);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

/* RTL Font Override */
.body--rtl {
    font-family: var(--font-arabic);
}

a {
    text-decoration: none;
    color: inherit;
    transition: var(--transition-fast);
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

button, input, select, textarea {
    font-family: inherit;
    font-size: inherit;
    outline: none;
    border: none;
    background: none;
}

button {
    cursor: pointer;
}

ul, ol {
    list-style: none;
}

/* === SELECTION === */
::selection {
    background: var(--primary-gold);
    color: var(--pure-pearl);
}

/* === SCROLLBAR === */
::-webkit-scrollbar {
    width: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--border-medium);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-gold);
}

/* ============================================
   ANIMATIONS — KEYFRAMES
   ============================================ */

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

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

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

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); }
    20%, 40%, 60%, 80% { transform: translateX(4px); }
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

@keyframes goldShimmer {
    0% { background-position: -200% center; }
    100% { background-position: 200% center; }
}

@keyframes ripple {
    to {
        transform: scale(4);
        opacity: 0;
    }
}

@keyframes progressShrink {
    from { width: 100%; }
    to { width: 0%; }
}

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

@keyframes spinSlow {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.body--rtl @keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateX(-100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes toastSlideOut {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

/* === ANIMATION UTILITIES === */
[data-animate] {
    opacity: 0;
    transform: translateY(25px);
    transition: opacity 0.6s var(--transition-elastic), transform 0.6s var(--transition-elastic);
}

[data-animate].animated {
    opacity: 1;
    transform: translateY(0);
}

.reveal {
    opacity: 0;
    transform: translateY(40px);
    transition: all 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

.reveal--visible {
    opacity: 1;
    transform: translateY(0);
}

/* ============================================
   TOAST NOTIFICATIONS
   ============================================ */

.toast-container {
    position: fixed;
    top: var(--space-lg);
    right: var(--space-lg);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    max-width: 380px;
    width: calc(100% - 32px);
}

.body--rtl .toast-container {
    right: auto;
    left: var(--space-lg);
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    background: var(--pure-pearl);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    border-left: 4px solid var(--info-blue);
    position: relative;
    overflow: hidden;
    opacity: 0;
    transform: translateX(100%);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.body--rtl .toast {
    border-left: none;
    border-right: 4px solid var(--info-blue);
    transform: translateX(-100%);
}

.toast--visible {
    opacity: 1;
    transform: translateX(0);
}

.toast--leaving {
    opacity: 0;
    transform: translateX(100%) scale(0.95);
}

.body--rtl .toast--leaving {
    transform: translateX(-100%) scale(0.95);
}

.toast--success { border-left-color: var(--success-emerald); }
.toast--error { border-left-color: var(--error-coral); }
.toast--warning { border-left-color: var(--warning-amber); }
.toast--info { border-left-color: var(--info-blue); }

.body--rtl .toast--success { border-right-color: var(--success-emerald); border-left: none; }
.body--rtl .toast--error { border-right-color: var(--error-coral); border-left: none; }
.body--rtl .toast--warning { border-right-color: var(--warning-amber); border-left: none; }
.body--rtl .toast--info { border-right-color: var(--info-blue); border-left: none; }

.toast__icon {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    margin-top: 2px;
}

.toast--success .toast__icon { color: var(--success-emerald); }
.toast--error .toast__icon { color: var(--error-coral); }
.toast--warning .toast__icon { color: var(--warning-amber); }
.toast--info .toast__icon { color: var(--info-blue); }

.toast__content {
    flex: 1;
    min-width: 0;
}

.toast__title {
    font-weight: 600;
    font-size: var(--text-sm);
    margin-bottom: 2px;
    color: var(--charcoal-text);
}

.toast__message {
    font-size: var(--text-sm);
    color: var(--muted-text);
    line-height: 1.4;
    word-wrap: break-word;
}

.toast__close {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--light-text);
    transition: var(--transition-fast);
    cursor: pointer;
}

.toast__close:hover {
    background: var(--surface-white);
    color: var(--charcoal-text);
}

.toast__progress {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: rgba(0, 0, 0, 0.05);
}

.toast__progress-bar {
    height: 100%;
    border-radius: 0 var(--radius-sm) 0 0;
    animation: progressShrink linear forwards;
}

.toast--success .toast__progress-bar { background: var(--success-emerald); }
.toast--error .toast__progress-bar { background: var(--error-coral); }
.toast--warning .toast__progress-bar { background: var(--warning-amber); }
.toast--info .toast__progress-bar { background: var(--info-blue); }

/* ============================================
   RIPPLE EFFECT
   ============================================ */

.ripple-effect {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.35);
    width: 20px;
    height: 20px;
    transform: scale(0);
    animation: ripple 0.7s linear;
    pointer-events: none;
    margin-left: -10px;
    margin-top: -10px;
}

/* ============================================
   BACK TO TOP
   ============================================ */

.back-to-top {
    position: fixed;
    bottom: 90px;
    right: var(--space-md);
    width: 44px;
    height: 44px;
    border-radius: var(--radius-full);
    background: var(--primary-gold);
    color: var(--pure-pearl);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    z-index: 900;
    opacity: 0;
    transform: scale(0.8);
    transition: var(--transition-elastic);
    cursor: pointer;
}

.body--rtl .back-to-top {
    right: auto;
    left: var(--space-md);
}

.back-to-top--visible {
    opacity: 1;
    transform: scale(1);
}

.back-to-top:hover {
    background: var(--gold-dark);
    transform: scale(1.1);
}

/* ============================================
   RESPONSIVE TOAST (MOBILE)
   ============================================ */

@media (max-width: 480px) {
    .toast-container {
        top: var(--space-md);
        right: var(--space-md);
        left: var(--space-md);
        max-width: 100%;
    }

    .body--rtl .toast-container {
        right: var(--space-md);
        left: var(--space-md);
    }
}






/* ============================================
   PWA UPDATE TOAST
   ============================================ */

.pwa-update-toast {
    position: fixed;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    z-index: 10000;
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    pointer-events: none;
}

.pwa-update-toast--visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
    pointer-events: all;
}

.pwa-update-toast__content {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: 12px 16px 12px 20px;
    background: var(--charcoal-text);
    color: var(--pure-pearl);
    border-radius: var(--radius-full);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    font-size: var(--text-sm);
    font-weight: 600;
    white-space: nowrap;
}

.pwa-update-toast__btn {
    padding: 8px 16px;
    background: var(--primary-gold);
    color: var(--pure-pearl);
    border: none;
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition-fast);
    flex-shrink: 0;
}

.pwa-update-toast__btn:hover {
    background: var(--gold-light);
    transform: scale(1.05);
}

/* ============================================
   PWA STANDALONE MODE ADJUSTMENTS
   ============================================ */

@media (display-mode: standalone) {
    /* Remove extra padding in standalone PWA mode */
    body {
        -webkit-user-select: none;
        user-select: text;
        -webkit-tap-highlight-color: transparent;
    }

    /* Prevent pull-to-refresh on some browsers */
    html {
        overscroll-behavior-y: contain;
    }
}

/* iOS safe areas for PWA */
@supports (padding-top: env(safe-area-inset-top)) {
    @media (display-mode: standalone) {
        .page-topbar,
        .search-topbar,
        .auth-page__back {
            padding-top: calc(var(--space-md) + env(safe-area-inset-top));
        }

        .nav-bottom {
            padding-bottom: calc(8px + env(safe-area-inset-bottom));
        }
    }
}

/* ============================================
   PWA INSTALL BANNER
   ============================================ */

.pwa-install {
    position: fixed;
    bottom: 72px;
    left: 0;
    right: 0;
    z-index: 9999;
    padding: 0 var(--space-md);
    transform: translateY(200px);
    opacity: 0;
    transition: all 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    pointer-events: none;
}

.pwa-install--visible {
    transform: translateY(0);
    opacity: 1;
    pointer-events: all;
}

.pwa-install__content {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: 14px 16px;
    background: var(--charcoal-text);
    border-radius: var(--radius-lg);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
    max-width: 480px;
    margin: 0 auto;
}

.pwa-install__icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--primary-gold), var(--gold-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.pwa-install__icon span {
    font-size: 22px;
    font-weight: 800;
    color: white;
}

.pwa-install__text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.pwa-install__text strong {
    font-size: var(--text-sm);
    font-weight: 700;
    color: white;
}

.pwa-install__text span {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.6);
    line-height: 1.3;
}

.pwa-install__btn {
    padding: 10px 20px;
    background: var(--primary-gold);
    color: white;
    border: none;
    border-radius: var(--radius-full);
    font-size: var(--text-sm);
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition-fast);
    flex-shrink: 0;
    white-space: nowrap;
}

.pwa-install__btn:hover {
    background: var(--gold-light);
    transform: scale(1.05);
}

.pwa-install__btn:active {
    transform: scale(0.98);
}

.pwa-install__close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.4);
    font-size: 16px;
    cursor: pointer;
    flex-shrink: 0;
    border-radius: var(--radius-full);
    transition: var(--transition-fast);
}

.pwa-install__close:hover {
    color: white;
    background: rgba(255, 255, 255, 0.1);
}

/* iOS Safari Hint */
.pwa-install__ios-hint {
    width: 100%;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    margin-top: 4px;
    text-align: center;
}

.pwa-install__ios-hint span {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.7);
}

.pwa-install__ios-hint i {
    font-size: 14px;
    color: var(--primary-gold);
    margin: 0 4px;
    vertical-align: middle;
}

.pwa-install__ios-hint strong {
    color: white;
}

/* PWA standalone mode — hide install banner completely */
@media (display-mode: standalone) {
    .pwa-install {
        display: none !important;
    }
}