/* ============================================
   TROF System v2.0 — Base
   ============================================
   Reset + Typography + Global Styles
   يعتمد على tokens.css
   ============================================ */

/* ==========================================
   🔄 RESET — إعادة التعيين
   ========================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

* {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html {
  color-scheme: dark;
  scroll-behavior: smooth;
  line-height: 1.15;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: 'kern' 1, 'liga' 1, 'calt' 1;
}

[data-theme="light"] html,
html[data-theme="light"] {
  color-scheme: light;
}

/* ==========================================
   📄 HTML & BODY
   ========================================== */

html {
  height: 100%;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--f-sans);
  font-size: var(--fs-base);
  font-weight: var(--fw-normal);
  line-height: var(--lh-base);
  overflow-x: hidden;
  position: relative;
}

/* Background Hero Effect */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: var(--g-hero);
  pointer-events: none;
  z-index: 0;
}

body > * {
  position: relative;
  z-index: 1;
}

/* ==========================================
   📐 TYPOGRAPHY — الطباعة
   ========================================== */

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--f-display);
  font-weight: var(--fw-black);
  line-height: var(--lh-tight);
  letter-spacing: var(--ls-tight);
  color: var(--c-text);
  margin: 0;
  text-wrap: balance;
}

h1 {
  font-size: clamp(var(--fs-3xl), 5vw, var(--fs-5xl));
}

h2 {
  font-size: clamp(var(--fs-2xl), 4vw, var(--fs-4xl));
}

h3 {
  font-size: clamp(var(--fs-xl), 3vw, var(--fs-3xl));
}

h4 {
  font-size: var(--fs-2xl);
}

h5 {
  font-size: var(--fs-xl);
}

h6 {
  font-size: var(--fs-lg);
}

/* Paragraphs */
p {
  margin: 0;
  line-height: var(--lh-base);
}

p + p {
  margin-top: var(--s-3);
}

/* Text Styles */
strong,
b {
  font-weight: var(--fw-bold);
  color: var(--c-text-hi);
}

em,
i {
  font-style: italic;
}

small {
  font-size: var(--fs-sm);
  color: var(--c-text-mut);
}

mark {
  background: var(--c-primary-500);
  color: var(--c-text-inv);
  padding: 0 4px;
  border-radius: var(--r-xs);
}

/* ==========================================
   🔗 LINKS — الروابط
   ========================================== */

a {
  color: var(--c-primary-400);
  text-decoration: none;
  transition: var(--tr-colors);
  cursor: pointer;
  background-color: transparent;
}

a:hover {
  color: var(--c-primary-200);
}

a:active {
  color: var(--c-primary-600);
}

a:focus-visible {
  outline: var(--focus-ring-width) solid var(--focus-ring-color);
  outline-offset: var(--focus-ring-offset);
  border-radius: var(--r-xs);
}

/* Links styled as text */
a.plain {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

a.plain:hover {
  color: var(--c-primary-400);
}

/* ==========================================
   📝 LISTS — القوائم
   ========================================== */

ul,
ol {
  list-style: none;
  padding: 0;
  margin: 0;
}

/* Nested lists (content area) */
.content ul,
.content ol {
  padding-inline-start: var(--s-6);
  margin: var(--s-3) 0;
}

.content ul {
  list-style: disc;
}

.content ol {
  list-style: decimal;
}

.content li {
  margin-bottom: var(--s-2);
  line-height: var(--lh-relaxed);
}

.content li::marker {
  color: var(--c-primary-500);
}

/* ==========================================
   🖼️ MEDIA — الوسائط
   ========================================== */

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

img {
  border-style: none;
  user-select: none;
  -webkit-user-drag: none;
}

svg {
  overflow: hidden;
  vertical-align: middle;
}

/* Iframe */
iframe {
  border: 0;
  max-width: 100%;
}

/* Figure */
figure {
  margin: 0;
}

figcaption {
  font-size: var(--fs-sm);
  color: var(--c-text-mut);
  margin-top: var(--s-2);
  text-align: center;
}

/* ==========================================
   📋 FORMS — النماذج
   ========================================== */

button,
input,
optgroup,
select,
textarea {
  font-family: inherit;
  font-size: 100%;
  line-height: 1.15;
  margin: 0;
  color: inherit;
}

button {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  overflow: visible;
  text-transform: none;
  -webkit-appearance: button;
}

button::-moz-focus-inner {
  border-style: none;
  padding: 0;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

input,
textarea {
  outline: none;
  background: transparent;
  border: none;
}

input[type='checkbox'],
input[type='radio'] {
  accent-color: var(--c-primary-500);
  cursor: pointer;
}

input[type='color'] {
  cursor: pointer;
}

input[type='number']::-webkit-outer-spin-button,
input[type='number']::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type='number'] {
  -moz-appearance: textfield;
  appearance: textfield;
}

/* Remove default select styling */
select {
  cursor: pointer;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

/* File input */
input[type='file'] {
  cursor: pointer;
}

/* Focus */
:focus-visible {
  outline: var(--focus-ring-width) solid var(--focus-ring-color);
  outline-offset: var(--focus-ring-offset);
}

/* Placeholder */
::placeholder {
  color: var(--c-text-dim);
  opacity: 1;
}

:-ms-input-placeholder {
  color: var(--c-text-dim);
}

::-ms-input-placeholder {
  color: var(--c-text-dim);
}

/* ==========================================
   💻 CODE & PRE — الكود
   ========================================== */

code,
pre,
kbd,
samp {
  font-family: var(--f-mono);
  font-size: 0.9em;
}

code {
  padding: 2px 6px;
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: var(--r-xs);
  color: var(--c-primary-300);
  font-weight: var(--fw-medium);
}

pre {
  padding: var(--s-4);
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  overflow-x: auto;
  line-height: var(--lh-relaxed);
  font-size: var(--fs-sm);
}

pre code {
  padding: 0;
  background: none;
  border: none;
  color: var(--c-text);
}

kbd {
  padding: 2px 6px;
  background: var(--c-surface-3);
  border: 1px solid var(--c-border);
  border-bottom-width: 2px;
  border-radius: var(--r-xs);
  font-size: 0.85em;
  color: var(--c-text);
  font-weight: var(--fw-bold);
}

/* ==========================================
   📊 TABLES — الجداول
   ========================================== */

table {
  width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
  font-size: var(--fs-sm);
}

th,
td {
  padding: var(--s-3) var(--s-4);
  text-align: start;
  border-bottom: 1px solid var(--c-border);
}

th {
  font-weight: var(--fw-bold);
  color: var(--c-text);
  background: var(--c-surface-2);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: var(--ls-wider);
}

tbody tr {
  transition: background var(--t-fast) var(--ease);
}

tbody tr:hover {
  background: var(--c-surface-2);
}

tbody tr:last-child td {
  border-bottom: none;
}

caption {
  text-align: start;
  font-size: var(--fs-sm);
  color: var(--c-text-mut);
  margin-bottom: var(--s-2);
}

/* ==========================================
   ➖ HR — الفواصل
   ========================================== */

hr {
  border: none;
  border-top: 1px solid var(--c-border);
  margin: var(--s-6) 0;
  height: 0;
  overflow: visible;
}

/* ==========================================
   🎯 SELECTION — التحديد
   ========================================== */

::selection {
  background: var(--c-primary-500);
  color: var(--c-text-inv);
  text-shadow: none;
}

::-moz-selection {
  background: var(--c-primary-500);
  color: var(--c-text-inv);
  text-shadow: none;
}

/* ==========================================
   📜 SCROLLBAR — شريط التمرير
   ========================================== */

/* Webkit (Chrome, Safari, Edge) */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: var(--c-bg);
}

::-webkit-scrollbar-thumb {
  background: var(--c-surface-3);
  border-radius: var(--r-full);
  border: 2px solid var(--c-bg);
  transition: background var(--t-fast);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--c-border-hi);
}

::-webkit-scrollbar-thumb:active {
  background: var(--c-primary-600);
}

::-webkit-scrollbar-corner {
  background: var(--c-bg);
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--c-surface-3) var(--c-bg);
}

/* ==========================================
   🎬 ANIMATIONS (بديهية) — الحركات
   ========================================== */

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

@keyframes ping {
  75%, 100% {
    transform: scale(2);
    opacity: 0;
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes fade-out {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

@keyframes slide-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@keyframes scale-in {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes scale-out {
  from {
    opacity: 1;
    transform: scale(1);
  }
  to {
    opacity: 0;
    transform: scale(0.95);
  }
}

/* Animation Utilities */
.fade-in {
  animation: fade-in var(--t-base) var(--ease);
}

.fade-out {
  animation: fade-out var(--t-base) var(--ease);
}

.slide-in {
  animation: slide-in var(--t-base) var(--ease);
}

.scale-in {
  animation: scale-in var(--t-base) var(--ease-bounce);
}

/* ==========================================
   🎨 THEME SWITCHING — تبديل الثيمات
   ========================================== */

html {
  transition: background-color var(--t-base) var(--ease),
              color var(--t-base) var(--ease);
}

body,
body * {
  transition-property: background-color, border-color, color;
  transition-duration: var(--t-base);
  transition-timing-function: var(--ease);
}

/* إلغاء transition للعناصر التي لا تحتاجه */
input,
textarea,
select,
img,
video,
canvas,
svg {
  transition-property: none;
}

/* استعادة transitions للأزرار */
button,
.btn,
[role='button'] {
  transition: var(--tr-base);
}

/* إلغاء transitions عموماً في prefers-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;
  }
}

/* ==========================================
   📦 LAYOUT UTILITIES — أدوات التخطيط
   ========================================== */

/* Container */
.container {
  width: 100%;
  max-width: var(--w-container);
  margin-inline: auto;
  padding-inline: var(--s-5);
}

.container-narrow {
  max-width: var(--w-narrow);
}

.container-wide {
  max-width: var(--w-wide);
}

.container-full {
  max-width: 100%;
  padding-inline: var(--s-4);
}

/* Sections */
.section {
  padding-block: var(--s-16);
}

.section-sm {
  padding-block: var(--s-10);
}

.section-lg {
  padding-block: var(--s-24);
}

/* Grid System */
.grid {
  display: grid;
  gap: var(--s-4);
}

.grid-2 {
  grid-template-columns: repeat(2, 1fr);
}

.grid-3 {
  grid-template-columns: repeat(3, 1fr);
}

.grid-4 {
  grid-template-columns: repeat(4, 1fr);
}

.grid-auto {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.grid-auto-sm {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.grid-auto-lg {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

/* Flex Utilities */
.flex {
  display: flex;
}

.flex-col {
  flex-direction: column;
}

.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.flex-start {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.flex-end {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.flex-wrap {
  flex-wrap: wrap;
}

.flex-1 {
  flex: 1;
}

.items-center {
  align-items: center;
}

.items-start {
  align-items: flex-start;
}

.items-end {
  align-items: flex-end;
}

.justify-center {
  justify-content: center;
}

.justify-between {
  justify-content: space-between;
}

.justify-end {
  justify-content: flex-end;
}

.gap-1 { gap: var(--s-1); }
.gap-2 { gap: var(--s-2); }
.gap-3 { gap: var(--s-3); }
.gap-4 { gap: var(--s-4); }
.gap-5 { gap: var(--s-5); }
.gap-6 { gap: var(--s-6); }
.gap-8 { gap: var(--s-8); }

/* Spacing Utilities */
.m-0 { margin: 0; }
.m-auto { margin: auto; }
.mt-2 { margin-top: var(--s-2); }
.mt-4 { margin-top: var(--s-4); }
.mt-6 { margin-top: var(--s-6); }
.mt-8 { margin-top: var(--s-8); }
.mb-2 { margin-bottom: var(--s-2); }
.mb-4 { margin-bottom: var(--s-4); }
.mb-6 { margin-bottom: var(--s-6); }
.mb-8 { margin-bottom: var(--s-8); }

.p-2 { padding: var(--s-2); }
.p-4 { padding: var(--s-4); }
.p-6 { padding: var(--s-6); }
.p-8 { padding: var(--s-8); }

/* Text Utilities */
.text-center { text-align: center; }
.text-start { text-align: start; }
.text-end { text-align: end; }

.text-xs { font-size: var(--fs-xs); }
.text-sm { font-size: var(--fs-sm); }
.text-base { font-size: var(--fs-base); }
.text-lg { font-size: var(--fs-lg); }
.text-xl { font-size: var(--fs-xl); }

.font-bold { font-weight: var(--fw-bold); }
.font-black { font-weight: var(--fw-black); }

.text-muted { color: var(--c-text-mut); }
.text-dim { color: var(--c-text-dim); }
.text-primary { color: var(--c-primary-400); }
.text-success { color: var(--c-success); }
.text-danger { color: var(--c-danger); }
.text-warning { color: var(--c-warning); }
.text-info { color: var(--c-info); }

.uppercase { text-transform: uppercase; }
.capitalize { text-transform: capitalize; }
.lowercase { text-transform: lowercase; }

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

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

/* ==========================================
   ♿ ACCESSIBILITY — إمكانية الوصول
   ========================================== */

/* 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: 0;
}

.sr-only-focusable:focus,
.sr-only-focusable:active {
  position: static;
  width: auto;
  height: auto;
  padding: inherit;
  margin: inherit;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* Skip to content */
.skip-link {
  position: absolute;
  top: -40px;
  inset-inline-start: 0;
  background: var(--c-primary-500);
  color: var(--c-text-inv);
  padding: var(--s-3) var(--s-4);
  z-index: var(--z-max);
  border-radius: 0 0 var(--r-md) 0;
  transition: top var(--t-fast);
}

.skip-link:focus {
  top: 0;
}

/* No outline for mouse clicks */
:focus:not(:focus-visible) {
  outline: none;
}

/* ==========================================
   📱 RESPONSIVE — التجاوب
   ========================================== */

@media (max-width: 768px) {
  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
  }

  .section {
    padding-block: var(--s-10);
  }

  .container {
    padding-inline: var(--s-4);
  }
}

@media (max-width: 480px) {
  body {
    font-size: var(--fs-sm);
  }

  h1 {
    font-size: var(--fs-3xl);
  }

  h2 {
    font-size: var(--fs-2xl);
  }
}

/* ==========================================
   🖨️ PRINT — الطباعة
   ========================================== */

@media print {
  *,
  *::before,
  *::after {
    background: transparent !important;
    color: #000 !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }

  a,
  a:visited {
    text-decoration: underline;
  }

  a[href]::after {
    content: ' (' attr(href) ')';
  }

  img {
    max-width: 100% !important;
    page-break-inside: avoid;
  }

  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    page-break-after: avoid;
    page-break-inside: avoid;
  }

  pre,
  blockquote {
    border: 1px solid #999;
    page-break-inside: avoid;
  }

  thead {
    display: table-header-group;
  }

  tr,
  img {
    page-break-inside: avoid;
  }

  p,
  h2,
  h3 {
    orphans: 3;
    widows: 3;
  }

  .no-print,
  nav,
  footer,
  .sidebar {
    display: none !important;
  }
}

/* ==========================================
   🎯 RTL/LTR SUPPORT
   ========================================== */

html[dir='rtl'] {
  direction: rtl;
  text-align: right;
}

html[dir='ltr'] {
  direction: ltr;
  text-align: left;
}

/* Flip icons in RTL */
html[dir='rtl'] [data-icon='arrow'] {
  transform: scaleX(-1);
}

/* ==========================================
   🌐 MISC — متفرقات
   ========================================== */

/* No scroll */
.no-scroll {
  overflow: hidden !important;
}

.no-select {
  user-select: none;
}

.no-pointer {
  pointer-events: none;
}

.hidden {
  display: none !important;
}

.invisible {
  visibility: hidden;
}

.visible {
  visibility: visible;
}

.cursor-pointer {
  cursor: pointer;
}

.cursor-not-allowed {
  cursor: not-allowed;
}

/* ==========================================
   📦 ASPECT RATIO
   ========================================== */

.aspect-square {
  aspect-ratio: var(--ar-square);
}

.aspect-video {
  aspect-ratio: var(--ar-video);
}

.aspect-photo {
  aspect-ratio: var(--ar-photo);
}

.aspect-portrait {
  aspect-ratio: var(--ar-portrait);
}

/* ==========================================
   🎬 LOADING STATE
   ========================================== */

.loading {
  position: relative;
  pointer-events: none;
}

.loading::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  border-radius: inherit;
  z-index: 10;
}

.loading::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 24px;
  height: 24px;
  margin: -12px 0 0 -12px;
  border: 2px solid var(--c-primary-500);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  z-index: 11;
}

/* ==========================================
   ✨ SPECIAL EFFECTS
   ========================================== */

/* Glow */
.glow {
  box-shadow: var(--sh-gold-glow);
}

/* Gradient Text */
.gradient-text {
  background: var(--g-gold);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
}

/* Glass Effect */
.glass {
  background: var(--g-glass);
  backdrop-filter: var(--blur-md);
  -webkit-backdrop-filter: var(--blur-md);
  border: 1px solid rgba(255, 255, 255, 0.1);
}