/**
 * Base CSS - Reset, Typography & RTL Foundation
 * Phase 3.1 - Premium Theme System
 */

/* =====================
 * CSS RESET (Modern)
 * ===================== */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    min-height: 100vh;
    font-family: var(--font-family-base);
    font-size: var(--font-size-base);
    line-height: var(--line-height-normal);
    color: var(--color-text);
    background-color: var(--color-background);
    direction: rtl;
    text-align: right;
}

img, picture, video, canvas, svg {
    display: block;
    max-width: 100%;
    height: auto;
}

input, button, textarea, select {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
    border: none;
    background: none;
}

a {
    color: inherit;
    text-decoration: none;
}

ul, ol {
    list-style: none;
}

table {
    border-collapse: collapse;
    border-spacing: 0;
}

/* =====================
 * TYPOGRAPHY
 * ===================== */

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-family-heading);
    font-weight: var(--font-weight-bold);
    line-height: var(--line-height-tight);
    color: var(--color-text);
    margin-bottom: var(--spacing-md);
}

h1 {
    font-size: var(--font-size-5xl);
    letter-spacing: -0.02em;
}

h2 {
    font-size: var(--font-size-4xl);
    letter-spacing: -0.01em;
}

h3 {
    font-size: var(--font-size-3xl);
}

h4 {
    font-size: var(--font-size-2xl);
}

h5 {
    font-size: var(--font-size-xl);
}

h6 {
    font-size: var(--font-size-lg);
}

p {
    margin-bottom: var(--spacing-md);
    line-height: var(--line-height-relaxed);
}

.lead {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-light);
    color: var(--color-text-light);
    line-height: var(--line-height-relaxed);
}

.small {
    font-size: var(--font-size-sm);
}

.caption {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}

strong, b {
    font-weight: var(--font-weight-bold);
}

em, i {
    font-style: italic;
}

/* Links */
.link {
    color: var(--color-primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.link:hover {
    color: var(--color-primary-dark);
    text-decoration: underline;
}

/* =====================
 * RTL FOUNDATION
 * ===================== */

[dir="rtl"] {
    text-align: right;
}

[dir="rtl"] .text-start {
    text-align: right !important;
}

[dir="rtl"] .text-end {
    text-align: left !important;
}

/* Flip margins and paddings for RTL */
[dir="rtl"] .ms-auto { margin-right: auto !important; margin-left: 0 !important; }
[dir="rtl"] .me-auto { margin-left: auto !important; margin-right: 0 !important; }
[dir="rtl"] .ps-0 { padding-right: 0 !important; }
[dir="rtl"] .pe-0 { padding-left: 0 !important; }

/* Flex direction for RTL */
[dir="rtl"] .flex-row { flex-direction: row-reverse; }
[dir="rtl"] .flex-row-normal { flex-direction: row; }

/* =====================
 * LAYOUT CONTAINERS
 * ===================== */

.container {
    width: 100%;
    max-width: var(--container-width);
    margin-inline: auto;
    padding-inline: var(--container-padding);
}

.container-sm { max-width: 640px; }
.container-md { max-width: 768px; }
.container-lg { max-width: 1024px; }
.container-xl { max-width: 1280px; }
.container-full { max-width: 100%; }

/* Section wrapper */
.section {
    padding-block: var(--spacing-section);
}

.section-sm { padding-block: var(--spacing-2xl); }
.section-lg { padding-block: calc(var(--spacing-section) * 1.5); }

/* =====================
 * SELECTION & FOCUS
 * ===================== */

::selection {
    background-color: var(--color-primary);
    color: var(--color-primary-contrast);
}

:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* =====================
 * SCROLLBAR (WebKit)
 * ===================== */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--color-surface);
}

::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-muted);
}

/* =====================
 * UTILITY: VISUALLY HIDDEN
 * ===================== */

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Alpine.js cloak */
[x-cloak] { display: none !important; }
