/**
 * ============================================
 * Base Styles - Reset + Typography
 * ============================================
 * الأساسيات + Typography
 */

/* ==========================================
 * Modern CSS Reset
 * ========================================== */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;

    /* IMPORTANT: Prevent horizontal scroll */
    overflow-x: hidden;
}

body {
    font-family: var(--font-family-base);
    font-size: var(--text-base);
    font-weight: var(--font-normal);
    line-height: var(--leading-normal);
    color: var(--color-text-primary);
    background: var(--color-surface);
    min-height: 100vh;

    /* IMPORTANT: Prevent horizontal scroll */
    overflow-x: hidden;
    width: 100%;
    position: relative;
}

/* ==========================================
 * Typography - Headings
 * ========================================== */

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-family-heading);
    font-weight: var(--font-bold);
    line-height: var(--leading-tight);
    color: var(--color-text-primary);
    margin-bottom: var(--space-4);
}

h1 {
    font-size: var(--text-4xl);
    letter-spacing: -0.025em;
}

h2 {
    font-size: var(--text-3xl);
    letter-spacing: -0.025em;
}

h3 {
    font-size: var(--text-2xl);
}

h4 {
    font-size: var(--text-xl);
}

h5 {
    font-size: var(--text-lg);
}

h6 {
    font-size: var(--text-base);
    font-weight: var(--font-semibold);
}

/* Desktop Adjustments */
@media (min-width: 768px) {
    h1 { font-size: var(--text-5xl); }
    h2 { font-size: var(--text-4xl); }
    h3 { font-size: var(--text-3xl); }
}

/* ==========================================
 * Typography - Body Text
 * ========================================== */

p {
    margin-bottom: var(--space-4);
    line-height: var(--leading-relaxed);
    color: var(--color-text-primary);
}

p:last-child {
    margin-bottom: 0;
}

small {
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
}

strong, b {
    font-weight: var(--font-semibold);
    color: var(--color-text-primary);
}

em, i {
    font-style: italic;
}

/* ==========================================
 * Links
 * ========================================== */

a {
    color: var(--color-primary-600);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--color-primary-700);
}

a:focus-visible {
    outline: 2px solid var(--color-primary-500);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* ==========================================
 * Lists
 * ========================================== */

ul, ol {
    padding-left: var(--space-6);
    margin-bottom: var(--space-4);
}

li {
    margin-bottom: var(--space-2);
    color: var(--color-text-primary);
}

ul[class], ol[class] {
    list-style: none;
    padding: 0;
}

/* ==========================================
 * Images & Media
 * ========================================== */

img, picture, video, canvas, svg {
    display: block;
    max-width: 100%;
    height: auto;
}

img {
    border-style: none;
}

/* ==========================================
 * Forms - Reset
 * ========================================== */

button, input, optgroup, select, textarea {
    font-family: inherit;
    font-size: 100%;
    line-height: inherit;
    color: var(--color-text-primary);
    margin: 0;
}

button, select {
    text-transform: none;
}

button, [type='button'], [type='reset'], [type='submit'] {
    -webkit-appearance: button;
    cursor: pointer;
}

button:disabled, [disabled] {
    cursor: not-allowed;
    opacity: 0.5;
}

textarea {
    resize: vertical;
}

input::placeholder, textarea::placeholder {
    color: var(--color-text-disabled);
    opacity: 1;
}

/* Remove spinner from number inputs */
input[type='number']::-webkit-inner-spin-button,
input[type='number']::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type='number'] {
    -moz-appearance: textfield;
}

/* ==========================================
 * Tables
 * ========================================== */

table {
    border-collapse: collapse;
    width: 100%;
}

/* ==========================================
 * Focus Styles - Accessibility
 * ========================================== */

:focus-visible {
    outline: 2px solid var(--color-primary-500);
    outline-offset: 2px;
}

:focus:not(:focus-visible) {
    outline: none;
}

/* ==========================================
 * Selection Styling
 * ========================================== */

::selection {
    background-color: var(--color-primary-200);
    color: var(--color-primary-900);
}

::-moz-selection {
    background-color: var(--color-primary-200);
    color: var(--color-primary-900);
}

/* ==========================================
 * Scrollbar Styling (Webkit)
 * ========================================== */

::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

::-webkit-scrollbar-track {
    background: var(--color-gray-100);
}

::-webkit-scrollbar-thumb {
    background: var(--color-gray-400);
    border-radius: var(--radius-full);
    border: 3px solid var(--color-gray-100);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-gray-500);
}

/* ==========================================
 * Utility Classes - Text
 * ========================================== */

.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }
.text-2xl { font-size: var(--text-2xl); }

.font-normal { font-weight: var(--font-normal); }
.font-medium { font-weight: var(--font-medium); }
.font-semibold { font-weight: var(--font-semibold); }
.font-bold { font-weight: var(--font-bold); }

.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.text-primary { color: var(--color-primary-600); }
.text-success { color: var(--color-success-600); }
.text-warning { color: var(--color-warning-600); }
.text-danger { color: var(--color-danger-600); }
.text-gray { color: var(--color-text-secondary); }

.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ==========================================
 * Utility Classes - Display
 * ========================================== */

.hidden { display: none !important; }
.block { display: block; }
.inline-block { display: inline-block; }
.flex { display: flex; }
.inline-flex { display: inline-flex; }
.grid { display: grid; }

/* ==========================================
 * Utility Classes - Spacing
 * ========================================== */

.m-0 { margin: 0; }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }

.p-0 { padding: 0; }
.p-4 { padding: var(--space-4); }
.p-6 { padding: var(--space-6); }

/* ==========================================
 * Screen Reader Only
 * ========================================== */

.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;
}

/* ==========================================
 * Component Specific Colors
 * ألوان مخصصة للعناصر
 * ========================================== */

/* Active Navigation */
.nav-item.active {
    color: var(--color-primary-600);
    font-weight: 600;
}

/* Stat Card Value - Colored */
.stat-card-value {
    color: var(--color-primary-600);
}

/* Task Card Price - Green */
.task-card-price {
    color: var(--color-success-600);
}

/* Avatar - White text */
.avatar {
    color: #FFFFFF;
}

/* Ensure white backgrounds */
.card, .form-input, .form-select, .form-textarea,
.app-header, .stat-card {
    background: #FFFFFF !important;
}

/* Global Overflow Prevention */
#root {
    width: 100%;
    overflow-x: hidden;
    position: relative;
}

.main-content {
    width: 100%;
    overflow-x: hidden;
}

.container > *, .card > *, .grid > * {
    max-width: 100%;
    box-sizing: border-box;
}

/* ==========================================
 * Typography - Headings
 * ========================================== */

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-family-heading);
    font-weight: var(--font-bold);
    line-height: var(--leading-tight);
    color: var(--color-text-primary);
    margin-bottom: var(--space-4);
}

h1 {
    font-size: var(--text-4xl);
    letter-spacing: -0.025em;
}

h2 {
    font-size: var(--text-3xl);
    letter-spacing: -0.025em;
}

h3 {
    font-size: var(--text-2xl);
}

h4 {
    font-size: var(--text-xl);
}

h5 {
    font-size: var(--text-lg);
}

h6 {
    font-size: var(--text-base);
    font-weight: var(--font-semibold);
}

/* Desktop Adjustments */
@media (min-width: 768px) {
    h1 { font-size: var(--text-5xl); }
    h2 { font-size: var(--text-4xl); }
    h3 { font-size: var(--text-3xl); }
}

/* ==========================================
 * Typography - Body Text
 * ========================================== */

p {
    margin-bottom: var(--space-4);
    line-height: var(--leading-relaxed);
}

p:last-child {
    margin-bottom: 0;
}

small {
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
}

strong, b {
    font-weight: var(--font-semibold);
}

em, i {
    font-style: italic;
}

/* ==========================================
 * Links
 * ========================================== */

a {
    color: var(--color-primary-600);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--color-primary-700);
}

a:focus-visible {
    outline: 2px solid var(--color-primary-500);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* ==========================================
 * Lists
 * ========================================== */

ul, ol {
    padding-left: var(--space-6);
    margin-bottom: var(--space-4);
}

li {
    margin-bottom: var(--space-2);
}

ul[class], ol[class] {
    list-style: none;
    padding: 0;
}

/* ==========================================
 * Images & Media
 * ========================================== */

img, picture, video, canvas, svg {
    display: block;
    max-width: 100%;
    height: auto;
}

img {
    border-style: none;
}

/* ==========================================
 * Forms - Reset
 * ========================================== */

button, input, optgroup, select, textarea {
    font-family: inherit;
    font-size: 100%;
    line-height: inherit;
    color: inherit;
    margin: 0;
}

button, select {
    text-transform: none;
}

button, [type='button'], [type='reset'], [type='submit'] {
    -webkit-appearance: button;
    cursor: pointer;
}

button:disabled, [disabled] {
    cursor: not-allowed;
    opacity: 0.5;
}

textarea {
    resize: vertical;
}

input::placeholder, textarea::placeholder {
    color: var(--color-text-disabled);
    opacity: 1;
}

/* Remove spinner from number inputs */
input[type='number']::-webkit-inner-spin-button,
input[type='number']::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type='number'] {
    -moz-appearance: textfield;
}

/* ==========================================
 * Tables
 * ========================================== */

table {
    border-collapse: collapse;
    width: 100%;
}

/* ==========================================
 * Focus Styles - Accessibility
 * ========================================== */

:focus-visible {
    outline: 2px solid var(--color-primary-500);
    outline-offset: 2px;
}

:focus:not(:focus-visible) {
    outline: none;
}

/* ==========================================
 * Selection Styling
 * ========================================== */

::selection {
    background-color: var(--color-primary-200);
    color: var(--color-primary-900);
}

::-moz-selection {
    background-color: var(--color-primary-200);
    color: var(--color-primary-900);
}

/* ==========================================
 * Scrollbar Styling (Webkit)
 * ========================================== */

::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

::-webkit-scrollbar-track {
    background: var(--color-gray-100);
}

::-webkit-scrollbar-thumb {
    background: var(--color-gray-400);
    border-radius: var(--radius-full);
    border: 3px solid var(--color-gray-100);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-gray-500);
}

/* ==========================================
 * Utility Classes - Text
 * ========================================== */

.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }
.text-2xl { font-size: var(--text-2xl); }

.font-normal { font-weight: var(--font-normal); }
.font-medium { font-weight: var(--font-medium); }
.font-semibold { font-weight: var(--font-semibold); }
.font-bold { font-weight: var(--font-bold); }

.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.text-primary { color: var(--color-primary-600); }
.text-success { color: var(--color-success-600); }
.text-warning { color: var(--color-warning-600); }
.text-danger { color: var(--color-danger-600); }
.text-gray { color: var(--color-text-secondary); }

.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ==========================================
 * Utility Classes - Display
 * ========================================== */

.hidden { display: none !important; }
.block { display: block; }
.inline-block { display: inline-block; }
.flex { display: flex; }
.inline-flex { display: inline-flex; }
.grid { display: grid; }

/* ==========================================
 * Utility Classes - Spacing
 * ========================================== */

.m-0 { margin: 0; }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }

.p-0 { padding: 0; }
.p-4 { padding: var(--space-4); }
.p-6 { padding: var(--space-6); }

/* ==========================================
 * Screen Reader Only
 * ========================================== */

.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;
}