/* Unified Design System Tokens (Web aligned with Flutter AppTheme) */
:root {
    /* Brand Core */
    --brand-primary: #1E40AF;
    --brand-primary-hover: #1D4ED8;
    --brand-primary-active: #1E3A8A;
    --brand-accent: #10B981;

    /* Blue Scale */
    --brand-50: #EFF6FF;
    --brand-100: #DBEAFE;
    --brand-200: #BFDBFE;
    --brand-300: #93C5FD;
    --brand-400: #60A5FA;
    --brand-500: #2563EB;
    --brand-600: #1E40AF;
    --brand-700: #1D4ED8;
    --brand-800: #1E3A8A;
    --brand-900: #172554;

    /* Surfaces & Typography */
    --surface-page: #F8FAFC;
    --surface-card: #FFFFFF;
    --surface-muted: #F1F5F9;
    --surface-border: #E2E8F0;
    --text-main: #0F172A;
    --text-secondary: #475569;
    --text-muted: #94A3B8;

    /* Status */
    --status-success: #16A34A;
    --status-success-bg: #DCFCE7;
    --status-warning: #F59E0B;
    --status-warning-bg: #FEF3C7;
    --status-error: #DC2626;
    --status-error-bg: #FEE2E2;

    /* Shape, spacing, motion */
    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 18px;
    --radius-xl: 24px;
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --shadow-card: 0 8px 24px rgba(15, 23, 42, 0.06);
    --shadow-card-hover: 0 12px 30px rgba(30, 64, 175, 0.12);
    --font-sans-ltr: 'Inter', 'Figtree', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-sans-rtl: 'Noto Sans Arabic', 'Cairo', sans-serif;
}

/* ============================================
   Global Base
   ============================================ */
html,
body {
    background-color: var(--surface-page);
    color: var(--text-main);
}

body {
    font-family: var(--font-sans-ltr);
}

html[dir="rtl"] body {
    font-family: var(--font-sans-rtl);
}

body.ds-body {
    min-height: 100dvh;
    background:
        radial-gradient(circle at 0% -10%, rgba(37, 99, 235, 0.12), transparent 42%),
        radial-gradient(circle at 100% -10%, rgba(16, 185, 129, 0.08), transparent 38%),
        var(--surface-page);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

.ds-page {
    background: var(--surface-page);
    color: var(--text-main);
}

.ds-main {
    position: relative;
    min-height: 100dvh;
    padding-bottom: clamp(1.5rem, 2vw, 2.5rem);
}

.ds-footer {
    border-top: 1px solid rgba(148, 163, 184, 0.2);
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.95), #0F172A);
}

.ds-card {
    background: var(--surface-card);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
}

.ds-card-muted {
    background: var(--surface-muted);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-md);
    transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
}

.ds-card-hover:hover {
    border-color: var(--brand-200);
    box-shadow: var(--shadow-card-hover);
    transition: all 180ms ease;
}

.ds-section-title {
    color: var(--text-main);
    font-size: clamp(1.25rem, 1.1rem + 0.6vw, 1.8rem);
    font-weight: 800;
    letter-spacing: -0.02em;
}

.ds-subtext {
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.5;
}

.ds-btn-primary {
    background-color: var(--brand-primary);
    color: #fff;
    border-radius: 12px;
    border: 1px solid transparent;
    font-weight: 700;
    transition: all 150ms ease;
}

.ds-btn-primary:hover {
    background-color: var(--brand-primary-hover);
}

.ds-btn-primary:active {
    background-color: var(--brand-primary-active);
}

.ds-btn-secondary {
    background: var(--surface-card);
    color: var(--brand-primary);
    border: 1px solid var(--brand-200);
    border-radius: 12px;
    font-weight: 700;
    transition: all 150ms ease;
}

.ds-btn-secondary:hover {
    background: var(--brand-50);
}

.ds-pill {
    border-radius: 999px;
    border: 1px solid var(--surface-border);
    background: var(--surface-card);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 12px;
    padding: 6px 10px;
}

.ds-input,
.ds-select,
.ds-textarea {
    border: 1px solid var(--surface-border);
    border-radius: 12px;
    background: var(--surface-card);
    color: var(--text-main);
    transition: border-color 150ms ease, box-shadow 150ms ease;
}

.ds-input:focus,
.ds-select:focus,
.ds-textarea:focus {
    outline: none;
    border-color: var(--brand-300);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18);
}

a,
button {
    transition: color 150ms ease, background-color 150ms ease, border-color 150ms ease, box-shadow 150ms ease,
        transform 150ms ease;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

/* ============================================
   Tailwind Override Mapping
   ============================================ */
.bg-blue-600, .hover\:bg-blue-600:hover { background-color: var(--brand-600) !important; }
.bg-blue-700, .hover\:bg-blue-700:hover { background-color: var(--brand-700) !important; }
.bg-blue-800, .hover\:bg-blue-800:hover { background-color: var(--brand-800) !important; }
.text-blue-600, .hover\:text-blue-600:hover { color: var(--brand-600) !important; }
.text-blue-700, .hover\:text-blue-700:hover { color: var(--brand-700) !important; }
.text-gray-900 { color: var(--text-main) !important; }
.text-gray-700, .text-gray-600 { color: var(--text-secondary) !important; }
.text-gray-500 { color: var(--text-muted) !important; }
.text-gray-400 { color: var(--text-muted) !important; }
a.text-blue-600, a:hover.text-blue-600 { color: var(--brand-600) !important; }

/* ============================================
   Status Color Overrides
   ============================================ */
/* Success */
.text-green-600, .text-green-500 { color: var(--status-success) !important; }
.bg-green-500, .bg-green-600 { background-color: var(--status-success) !important; }
.bg-green-100, .bg-green-50 { background-color: var(--status-success-bg) !important; }

/* Warning */
.text-yellow-600, .text-yellow-500, .text-amber-500 { color: var(--status-warning) !important; }
.bg-yellow-500, .bg-yellow-400, .bg-amber-500 { background-color: var(--status-warning) !important; }
.bg-yellow-100, .bg-amber-100 { background-color: var(--status-warning-bg) !important; }

/* Error */
.text-red-600, .text-red-500 { color: var(--status-error) !important; }
.bg-red-500, .bg-red-600 { background-color: var(--status-error) !important; }
.bg-red-100, .bg-red-50 { background-color: var(--status-error-bg) !important; }

.bg-gray-50 { background-color: var(--surface-page) !important; }
.bg-gray-100, .bg-gray-200 { background-color: var(--surface-muted) !important; }

/* ============================================
   Exam / Learning UI Specific Classes
   ============================================ */
.exam-correct {
    background-color: var(--status-success) !important;
    color: #FFFFFF !important;
    border-color: var(--status-success) !important;
}

.exam-wrong {
    background-color: var(--status-error) !important;
    color: #FFFFFF !important;
    border-color: var(--status-error) !important;
}

.exam-selected {
    background-color: var(--brand-100) !important; /* #DBEAFE */
    border-color: var(--brand-600) !important;
}

.exam-timer {
    color: var(--status-warning) !important;
}

/* ============================================
   Button Components (Generic)
   ============================================ */
.btn-primary {
    background-color: var(--brand-primary) !important;
    color: #FFFFFF !important;
}
.btn-primary:hover {
    background-color: var(--brand-primary-hover) !important;
}
.btn-primary:active {
    background-color: var(--brand-primary-active) !important;
}

/* Gradients Overrides to match new Blue */
.from-blue-600 { --tw-gradient-from: var(--brand-600) !important; }
.to-blue-600 { --tw-gradient-to: var(--brand-600) !important; }

/* ============================================
   Global Responsive Hardening
   ============================================ */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    max-width: 100%;
}

img,
svg,
video,
canvas,
iframe {
    max-width: 100%;
    height: auto;
}

p,
h1,
h2,
h3,
h4,
h5,
h6,
a,
span,
label,
li {
    overflow-wrap: anywhere;
}

.table-responsive,
.responsive-scroll {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 1024px) {
    .max-w-7xl,
    .max-w-6xl,
    .max-w-5xl,
    .max-w-4xl,
    .max-w-screen-2xl {
        width: 100%;
    }

    .mobile-safe-padding {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
}

@media (max-width: 767px) {
    body {
        overflow-x: hidden;
    }

    input,
    select,
    textarea,
    button {
        font-size: 16px;
    }
}

@media (max-width: 475px) {
    .grid[class*="grid-cols-2"]:not([class*="sm:grid-cols-2"]):not([class*="md:grid-cols-2"]):not([class*="lg:grid-cols-2"]):not([class*="xl:grid-cols-2"]) {
        grid-template-columns: repeat(1, minmax(0, 1fr)) !important;
    }

    .grid[class*="grid-cols-3"]:not([class*="sm:grid-cols-3"]):not([class*="md:grid-cols-3"]):not([class*="lg:grid-cols-3"]):not([class*="xl:grid-cols-3"]) {
        grid-template-columns: repeat(1, minmax(0, 1fr)) !important;
    }

    .grid[class*="grid-cols-4"]:not([class*="sm:grid-cols-4"]):not([class*="md:grid-cols-4"]):not([class*="lg:grid-cols-4"]):not([class*="xl:grid-cols-4"]) {
        grid-template-columns: repeat(1, minmax(0, 1fr)) !important;
    }
}

@media (max-width: 640px) {
    [class*="min-w-[320px]"],
    [class*="min-w-[300px]"],
    [class*="min-w-[280px]"],
    [class*="min-w-[260px]"] {
        min-width: 0 !important;
        width: 100% !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 1ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 1ms !important;
        scroll-behavior: auto !important;
    }
}
