/* ============================================================
   main.css — CSS custom properties, RTL base, Silatek-inspired theme
   ============================================================ */

/* ---- CSS Custom Properties ---- */
:root {
  /* Silatek Primary Green palette */
  --green-900: #14532d;
  --green-800: #166534;
  --green-700: #15803d;
  --green-600: #16a34a;
  --green-500: #30ab59;
  --green-400: #4ade80;
  --green-300: #86efac;
  --green-200: #bbf7d0;
  --green-100: #dcfce7;
  --green-50:  #f0fdf4;

  /* Silatek Secondary Blue (nav / headers) */
  --blue-900:  #1e3a5f;
  --blue-800:  #1e40af;
  --blue-700:  #1d4ed8;
  --blue-600:  #2563eb;
  --blue-500:  #3b82f6;
  --blue-400:  #60a5fa;
  --blue-300:  #93c5fd;
  --blue-200:  #bfdbfe;
  --blue-100:  #dbeafe;
  --blue-50:   #eff6ff;

  /* Brand */
  --primary:        #30ab59;
  --primary-dark:   #16a34a;
  --primary-light:  #f0fdf4;
  --secondary:      #4162a9;
  --secondary-dark: #2d4f8a;

  /* Gold accents (earnings) */
  --gold:       #c9a84c;
  --gold-light: #f4d03f;
  --gold-pale:  #fef9e7;

  /* Semantic colors */
  --danger:     #ef4444;
  --danger-bg:  #fef2f2;
  --warning:    #f97316;
  --warning-bg: #fff7ed;
  --info:       #3b82f6;
  --info-bg:    #eff6ff;
  --success:    var(--primary);
  --success-bg: var(--primary-light);

  /* Neutral — silatek scale */
  --text-dark:    #111827;
  --text-medium:  #4b5563;
  --text-light:   #f9fafb;
  --text-muted:   #6b7280;
  --border:       #e5e7eb;
  --border-light: #f3f4f6;
  --bg-page:      #f9fafb;
  --bg-card:      #ffffff;
  --bg-input:     #ffffff;

  /* Typography — Tajawal (silatek's Arabic font) */
  --font:        'Tajawal', 'Segoe UI', Arial, sans-serif;
  --font-size:   16px;
  --line-height: 1.6;

  /* Spacing */
  --space-xs:  4px;
  --space-sm:  8px;
  --space-md:  16px;
  --space-lg:  24px;
  --space-xl:  32px;
  --space-2xl: 48px;

  /* Borders & Shadows — silatek scale */
  --radius-xs:   2px;
  --radius-sm:   4px;
  --radius:      8px;
  --radius-lg:   12px;
  --radius-xl:   16px;
  --radius-2xl:  24px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 3px 0 rgba(0,0,0,.1), 0 1px 2px -1px rgba(0,0,0,.1);
  --shadow:    0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -2px rgba(0,0,0,.1);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -4px rgba(0,0,0,.1);

  /* Transitions */
  --transition: 0.2s ease;

  /* Focus ring — used on all interactive elements */
  --focus-ring:        0 0 0 3px rgba(48,171,89,.3);
  --focus-ring-danger: 0 0 0 3px rgba(239,68,68,.3);

  /* Z-index layers */
  --z-tabs:     10;
  --z-toast:    1000;
  --z-modal:    900;
  --z-confetti: 9999;
}

/* ---- CSS Reset & Base ---- */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: var(--font-size);
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  font-size: 1rem;
  line-height: var(--line-height);
  color: var(--text-dark);
  background-color: var(--bg-page);
  direction: rtl;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ---- Typography ---- */

h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  line-height: 1.3;
  color: var(--text-dark);
}

p {
  margin-bottom: var(--space-sm);
}

p:last-child {
  margin-bottom: 0;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  color: var(--primary-dark);
  text-decoration: underline;
}

a:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-xs);
}

/* ---- App Header — silatek gradient (green → blue) ---- */

.app-header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  color: var(--text-light);
  padding: var(--space-md) var(--space-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  box-shadow: var(--shadow-lg);
  position: sticky;
  top: 0;
  z-index: var(--z-tabs);
  flex-wrap: wrap;
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-shrink: 0;
}

.header-icon {
  font-size: 1.5rem;
  line-height: 1;
}

.header-titles {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.header-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-light);
  margin: 0;
  white-space: nowrap;
}

.family-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--gold-light);
  cursor: pointer;
  border-bottom: 1px dashed rgba(255,255,255,.4);
  padding-bottom: 1px;
  transition: color var(--transition), border-color var(--transition);
  display: inline-block;
}

.family-name:hover {
  color: #ffffff;
  border-color: rgba(255,255,255,.8);
}

.family-name:focus-visible {
  outline: 2px solid rgba(255,255,255,.8);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-shrink: 0;
  flex-wrap: wrap;
}

/* ---- Tabs Bar — silatek secondary blue ---- */

.tabs-bar {
  background-color: var(--secondary);
  display: flex;
  align-items: stretch;
  padding: 0 var(--space-sm);
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--blue-300) transparent;
  min-height: 48px;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
  position: sticky;
  top: 66px;
  z-index: calc(var(--z-tabs) - 1);
}

.tabs-bar::-webkit-scrollbar {
  height: 3px;
}
.tabs-bar::-webkit-scrollbar-thumb {
  background-color: var(--blue-300);
  border-radius: 2px;
}

/* Inner scroll container */
.tabs-scroll {
  display: flex;
  align-items: stretch;
  flex: 1;
  gap: 2px;
}

/* ---- Main Content ---- */

#app-main {
  padding: var(--space-lg);
  max-width: 1400px;
  margin: 0 auto;
}

/* ---- Welcome Screen ---- */

.welcome-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  padding: var(--space-2xl) var(--space-lg);
}

.welcome-card {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: var(--space-2xl);
  text-align: center;
  max-width: 520px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-md);
  border: 1px solid var(--border);
}

.welcome-icon {
  font-size: 4rem;
  line-height: 1;
  animation: welcome-bounce 2s ease-in-out infinite;
}

@keyframes welcome-bounce {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-8px); }
}

.welcome-card h2 {
  font-size: 1.5rem;
  color: var(--text-dark);
  margin: 0;
}

.welcome-card p {
  font-size: 1rem;
  color: var(--text-medium);
  margin: 0;
}

.welcome-note {
  font-size: 0.82rem !important;
  color: var(--text-muted) !important;
  background: var(--primary-light);
  border: 1px solid var(--green-200);
  border-radius: var(--radius);
  padding: var(--space-sm) var(--space-md);
}

/* ---- Toast Container ---- */

#toast-container {
  position: fixed;
  bottom: var(--space-lg);
  left: var(--space-lg);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  pointer-events: none;
  max-width: 360px;
}

/* ---- Hidden utility ---- */

.hidden {
  display: none !important;
}

/* ---- Scrollbar — silatek style ---- */

* {
  scrollbar-width: thin;
  scrollbar-color: var(--text-muted) transparent;
}

*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
*::-webkit-scrollbar-track {
  background: transparent;
  border-radius: 4px;
}
*::-webkit-scrollbar-thumb {
  background-color: var(--text-muted);
  border-radius: 4px;
}
*::-webkit-scrollbar-thumb:hover {
  background-color: #9ca3af;
}

/* ---- Responsive Breakpoints ---- */

@media (max-width: 900px) {
  #app-main {
    padding: var(--space-md);
  }
  .app-header {
    padding: var(--space-sm) var(--space-md);
  }
  .header-title {
    font-size: 0.95rem;
  }
}

@media (max-width: 600px) {
  :root {
    --font-size: 14px;
  }
  .app-header {
    padding: var(--space-sm);
    gap: var(--space-sm);
  }
  .header-right {
    flex: 1;
  }
  .header-actions {
    gap: 4px;
  }
  #app-main {
    padding: var(--space-sm);
  }
  .welcome-card {
    padding: var(--space-lg);
  }
  #toast-container {
    left: var(--space-sm);
    right: var(--space-sm);
    max-width: none;
  }
  .tabs-bar {
    top: 58px;
  }
}
