/* ---------------------------------------------------------
   1. VARIABLES & THEME SETUP
--------------------------------------------------------- */
:root {
  /* Colors */
  --primary: #0d47a1;       /* Blue Dark */
  --primary-light: #1565c0; /* Blue Light */
  --secondary: #ffcc00;     /* Yellow */
  --success: #16a34a;       /* Green */
  --danger: #dc2626;        /* Red */
  --text-main: #0f172a;     /* Dark Text */
  --text-muted: #64748b;    /* Light Text */
  --bg-body: #f8fafc;       /* Light Gray BG */
  --bg-card: #ffffff;
  --border-color: #e2e8f0;

  /* Spacing & Sizing */
  --radius: 12px;
  --radius-sm: 8px;
  --header-height: 64px;
  --container-width: 1200px;
  
  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);

  /* Transitions */
  --transition: all 0.2s ease-in-out;
}

/* ---------------------------------------------------------
   2. GLOBAL RESET & BASE STYLES
--------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: 'Tajawal', system-ui, -apple-system, sans-serif;
  direction: rtl;
  background-color: var(--bg-body);
  color: var(--text-main);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ---------------------------------------------------------
   3. LAYOUT & STRUCTURE
--------------------------------------------------------- */
.container {
  max-width: var(--container-width);
  margin: 2rem auto;
  padding: 0 1rem;
  width: 100%;
}

/* Grid System Utility */
.row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: flex-end;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.5rem;
}

/* ---------------------------------------------------------
   4. HEADER & NAV
--------------------------------------------------------- */
.site-header {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--secondary);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.top-nav {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.top-nav a {
  color: rgba(255, 255, 255, 0.9);
  text-decoration: none;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  transition: var(--transition);
}

.top-nav a:hover,
.top-nav a.active {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

/* ---------------------------------------------------------
   5. COMPONENTS (Cards, Forms, Buttons)
--------------------------------------------------------- */

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

/* Forms */
label {
  display: block;
  font-size: 0.9rem;
  color: #334155;
  margin-bottom: 0.5rem;
  font-weight: 500;
}

input, select, textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: #fff;
  font-size: 1rem;
  color: var(--text-main);
  transition: var(--transition);
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(21, 101, 192, 0.15);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.25rem;
  border: none;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  line-height: 1;
}

.btn:active {
  transform: scale(0.97);
}

.btn-green { background-color: var(--success); color: #fff; }
.btn-green:hover { background-color: #15803d; }

.btn-blue { background-color: var(--primary-light); color: #fff; }
.btn-blue:hover { background-color: var(--primary); }

.btn-red { background-color: var(--danger); color: #fff; }
.btn-red:hover { background-color: #b91c1c; }

.btn-yellow { background-color: var(--secondary); color: #000; }
.btn-yellow:hover { background-color: #eab308; }

/* Tables */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  min-width: 600px; /* Forces scroll on small screens */
}

th {
  background: var(--primary);
  color: #fff;
  padding: 1rem;
  text-align: center;
  font-weight: 600;
  white-space: nowrap;
}

td {
  padding: 0.875rem;
  border-bottom: 1px solid var(--border-color);
  text-align: center;
  vertical-align: middle;
}

tr:nth-child(even) { background-color: #f8fafc; }
tr:hover { background-color: #f1f5f9; }

/* ---------------------------------------------------------
   6. UTILITIES & ANIMATIONS
--------------------------------------------------------- */
.actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
}

.badge {
  display: inline-block;
  background: #f1f5f9;
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 0.25rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.text-center { text-align: center; }
.small { font-size: 0.85rem; color: var(--text-muted); }

/* Animation */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.fade-in, .animate-up {
  animation: fadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* ---------------------------------------------------------
   7. MEDIA QUERIES (Mobile)
--------------------------------------------------------- */
@media (max-width: 768px) {
  body {
    font-size: 15px;
  }
  
  .container {
    margin: 1rem auto;
  }
  
  .site-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }
  
  .top-nav {
    justify-content: center;
  }

  /* Stack form elements on mobile */
  .row {
    flex-direction: column;
    align-items: stretch;
  }
  
  .row > * {
    width: 100%;
  }

  /* Make buttons easier to tap */
  .btn, input, select {
    min-height: 48px; 
  }
  
  th, td {
    padding: 0.75rem 0.5rem;
  }
  
  .actions .btn {
    flex: 1; /* Buttons take full width in groups */
    padding: 0.75rem;
  }
}

/* ---------------------------------------------------------
   8. PRINT STYLES
--------------------------------------------------------- */
@media print {
  .site-header, .btn, .actions, form, nav, .no-print {
    display: none !important;
  }

  body {
    background: #fff;
    color: #000;
  }

  .container, .card {
    max-width: 100%;
    margin: 0;
    padding: 0;
    box-shadow: none;
    border: none;
  }

  table {
    width: 100%;
    border: 1px solid #000;
    font-size: 12pt;
  }

  th, td {
    border: 1px solid #000;
    padding: 8px;
    color: #000;
  }
}