/* ============================================================================
   main.css — Tavroo
   Variables + Reset + Typography + Layout (Sidebar, Topbar, Main)
   ============================================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=IBM+Plex+Sans+Arabic:wght@400;500;600;700&display=swap');

/* ============================================================================
   1. CSS VARIABLES
   ============================================================================ */

:root {
  /* Primary — Sky Blue */
  --color-primary-50:  #F0F9FF;
  --color-primary-100: #E0F2FE;
  --color-primary-200: #BAE6FD;
  --color-primary-300: #7DD3FC;
  --color-primary-400: #38BDF8;
  --color-primary-500: #0EA5E9;
  --color-primary-600: #0284C7;
  --color-primary-700: #0369A1;
  --color-primary-800: #075985;
  --color-primary-900: #0C4A6E;

  /* Neutral — Cool Gray */
  --color-gray-50:  #F8FAFC;
  --color-gray-100: #F1F5F9;
  --color-gray-200: #E2E8F0;
  --color-gray-300: #CBD5E1;
  --color-gray-400: #94A3B8;
  --color-gray-500: #64748B;
  --color-gray-600: #475569;
  --color-gray-700: #334155;
  --color-gray-800: #1E293B;
  --color-gray-900: #0F172A;

  /* Accent — Orange */
  --color-accent-400: #FB923C;
  --color-accent-500: #F97316;
  --color-accent-600: #EA6C0A;
  --color-accent-700: #C2570A;

  /* Semantic */
  --color-success:  #10B981;
  --color-warning:  #F59E0B;
  --color-danger:   #EF4444;
  --color-info:     #0EA5E9;

  /* Task Priority Colors */
  --priority-urgent:  #EF4444;
  --priority-high:    #F97316;
  --priority-medium:  #F59E0B;
  --priority-low:     #10B981;
  --priority-none:    #94A3B8;

  /* Task Status Colors */
  --status-todo:        #94A3B8;
  --status-inprogress:  #0EA5E9;
  --status-review:      #8B5CF6;
  --status-done:        #10B981;
  --status-cancelled:   #EF4444;

  /* Surfaces */
  --surface-app:      #F1F5F9;
  --surface-sidebar:  #1E293B;
  --surface-card:     #FFFFFF;
  --surface-hover:    #F8FAFC;
  --surface-active:   #E0F2FE;

  /* Typography */
  --text-primary:    #1E293B;
  --text-secondary:  #475569;
  --text-muted:      #94A3B8;
  --text-inverse:    #FFFFFF;
  --text-on-sidebar: #CBD5E1;
  --text-on-sidebar-active: #FFFFFF;

  /* Borders */
  --border-light:  #E2E8F0;
  --border-medium: #CBD5E1;
  --border-focus:  #0EA5E9;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.05);

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;

  /* Radius */
  --radius-sm:  4px;
  --radius-md:  8px;
  --radius-lg:  12px;
  --radius-xl:  16px;
  --radius-full: 9999px;

  /* Typography Stacks */
  --font-sans-en: 'Inter', system-ui, -apple-system, sans-serif;
  --font-sans-ar: 'IBM Plex Sans Arabic', 'Inter', system-ui, sans-serif;
  --font-sans:    var(--font-sans-en);
  --font-mono:    'JetBrains Mono', 'Fira Code', monospace;

  /* Transitions */
  --transition-fast:   150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow:   400ms ease;

  /* Layout */
  --sidebar-width:           240px;
  --sidebar-width-collapsed:  56px;
  --topbar-height:            56px;
  --z-modal:        1000;
  --z-dropdown:      500;
  --z-tooltip:       999;
  --z-sidebar:       100;
  --z-topbar:         90;
}

/* استخدم الخط العربي عند dir="rtl" */
[dir="rtl"] {
  --font-sans: var(--font-sans-ar);
}

/* ============================================================================
   2. RESET & BASE
   ============================================================================ */

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

html {
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--surface-app);
  min-height: 100vh;
  overflow: hidden; /* الـ scroll يكون داخل main-content */
}

img, svg, video {
  display: block;
  max-width: 100%;
}

button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

ul, ol { list-style: none; }

hr {
  border: none;
  border-top: 1px solid var(--border-light);
}

::selection {
  background: var(--color-primary-200);
  color: var(--color-primary-900);
}

:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Hide outline لكن خلّي focus-visible يشتغل */
:focus:not(:focus-visible) {
  outline: none;
}

/* ============================================================================
   3. TYPOGRAPHY UTILITIES
   ============================================================================ */

.text-xs   { font-size: 11px; line-height: 16px; }
.text-sm   { font-size: 12px; line-height: 18px; }
.text-base { font-size: 14px; line-height: 20px; }
.text-lg   { font-size: 16px; line-height: 24px; }
.text-xl   { font-size: 18px; line-height: 28px; }
.text-2xl  { font-size: 22px; line-height: 32px; }
.text-3xl  { font-size: 28px; line-height: 36px; }

.font-medium   { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold     { font-weight: 700; }

.text-primary    { color: var(--text-primary); }
.text-secondary  { color: var(--text-secondary); }
.text-muted      { color: var(--text-muted); }
.text-inverse    { color: var(--text-inverse); }
.text-success    { color: var(--color-success); }
.text-warning    { color: var(--color-warning); }
.text-danger     { color: var(--color-danger); }

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

.text-center { text-align: center; }
.text-start  { text-align: start; }
.text-end    { text-align: end; }

/* ============================================================================
   4. APP LAYOUT
   ============================================================================ */

.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: var(--topbar-height) 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar main";
  height: 100vh;
  width: 100vw;
  transition: grid-template-columns var(--transition-normal);
}

.app-layout.sidebar-collapsed {
  grid-template-columns: var(--sidebar-width-collapsed) 1fr;
}

.app-sidebar {
  grid-area: sidebar;
  background: var(--surface-sidebar);
  color: var(--text-on-sidebar);
  z-index: var(--z-sidebar);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width var(--transition-normal);
}

.app-topbar {
  grid-area: topbar;
  background: var(--surface-card);
  border-bottom: 1px solid var(--border-light);
  z-index: var(--z-topbar);
  display: flex;
  align-items: center;
  padding: 0 var(--space-6);
  gap: var(--space-4);
}

.app-main {
  grid-area: main;
  background: var(--surface-app);
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
}

.app-main.is-loading {
  opacity: 0.6;
  pointer-events: none;
}

/* ============================================================================
   5. SIDEBAR
   ============================================================================ */

.sidebar-header {
  padding: var(--space-5) var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  border-bottom: 1px solid rgb(255 255 255 / 0.06);
  flex-shrink: 0;
}

.sidebar-logo {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--color-primary-400), var(--color-primary-600));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgb(14 165 233 / 0.3);
}

.sidebar-brand {
  font-size: 18px;
  font-weight: 700;
  color: white;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
}

.app-layout.sidebar-collapsed .sidebar-brand,
.app-layout.sidebar-collapsed .sidebar-section-label,
.app-layout.sidebar-collapsed .nav-item-label,
.app-layout.sidebar-collapsed .org-switcher {
  display: none;
}

.sidebar-org {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid rgb(255 255 255 / 0.06);
  flex-shrink: 0;
}

.org-switcher {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: rgb(255 255 255 / 0.04);
  color: var(--text-on-sidebar);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition-fast);
  width: 100%;
}

.org-switcher:hover {
  background: rgb(255 255 255 / 0.08);
  color: white;
}

.org-switcher-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: start;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-2) 0;
}

.sidebar-nav::-webkit-scrollbar {
  width: 4px;
}
.sidebar-nav::-webkit-scrollbar-thumb {
  background: rgb(255 255 255 / 0.1);
  border-radius: 2px;
}

.sidebar-section {
  padding: var(--space-2) 0;
}

.sidebar-section-label {
  padding: var(--space-2) var(--space-4);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--color-gray-500);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 8px var(--space-4);
  margin: 1px var(--space-2);
  border-radius: var(--radius-md);
  color: var(--text-on-sidebar);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  position: relative;
}

.nav-item:hover {
  background: rgb(255 255 255 / 0.08);
  color: white;
}

.nav-item.is-active {
  background: var(--color-primary-500);
  color: white;
  box-shadow: 0 2px 8px rgb(14 165 233 / 0.4);
}

.nav-item-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-item-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-item-badge {
  background: rgb(255 255 255 / 0.15);
  color: white;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

.nav-item.is-nested {
  padding-inline-start: 36px;
  font-size: 12px;
}

.sidebar-divider {
  height: 1px;
  background: rgb(255 255 255 / 0.06);
  margin: var(--space-2) var(--space-3);
}

.sidebar-footer {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid rgb(255 255 255 / 0.06);
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.sidebar-user:hover {
  background: rgb(255 255 255 / 0.08);
}

.sidebar-user-info {
  flex: 1;
  overflow: hidden;
  min-width: 0;
}

.sidebar-user-name {
  color: white;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-email {
  color: var(--color-gray-500);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-layout.sidebar-collapsed .sidebar-user-info {
  display: none;
}

.sidebar-toggle {
  position: absolute;
  top: 16px;
  inset-inline-end: -12px;
  width: 24px;
  height: 24px;
  background: var(--surface-card);
  border: 1px solid var(--border-light);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 1;
  box-shadow: var(--shadow-sm);
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.sidebar-toggle:hover {
  color: var(--text-primary);
  border-color: var(--border-medium);
}

/* ============================================================================
   6. TOPBAR
   ============================================================================ */

.topbar-search {
  flex: 1;
  max-width: 480px;
  position: relative;
}

.topbar-search-input {
  width: 100%;
  height: 36px;
  background: var(--color-gray-100);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 0 var(--space-3);
  padding-inline-start: 36px;
  padding-inline-end: 60px;
  font-size: 13px;
  color: var(--text-primary);
  transition: all var(--transition-fast);
}

.topbar-search-input:hover {
  background: var(--color-gray-50);
  border-color: var(--border-light);
}

.topbar-search-input:focus {
  background: white;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgb(14 165 233 / 0.1);
  outline: none;
}

.topbar-search-icon {
  position: absolute;
  inset-inline-start: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.topbar-search-shortcut {
  position: absolute;
  inset-inline-end: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--text-muted);
  background: var(--surface-card);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  font-family: var(--font-mono);
  pointer-events: none;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin-inline-start: auto;
}

.topbar-action {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
}

.topbar-action:hover {
  background: var(--color-gray-100);
  color: var(--text-primary);
}

.topbar-action-badge {
  position: absolute;
  top: 6px;
  inset-inline-end: 6px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  background: var(--color-danger);
  color: white;
  font-size: 10px;
  font-weight: 600;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--surface-card);
}

.topbar-divider {
  width: 1px;
  height: 24px;
  background: var(--border-light);
  margin: 0 var(--space-2);
}

.topbar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  transition: box-shadow var(--transition-fast);
  flex-shrink: 0;
}

.topbar-avatar:hover {
  box-shadow: 0 0 0 3px var(--color-primary-100);
}

/* ============================================================================
   7. RESPONSIVE — Mobile
   ============================================================================ */

@media (max-width: 768px) {
  .app-layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "main";
  }

  .app-sidebar {
    position: fixed;
    inset-inline-start: 0;
    top: 0;
    height: 100vh;
    width: var(--sidebar-width);
    transform: translateX(-100%);
    transition: transform var(--transition-normal);
  }

  [dir="rtl"] .app-sidebar {
    transform: translateX(100%);
  }

  .app-layout.sidebar-open .app-sidebar {
    transform: translateX(0);
  }

  .topbar-search {
    display: none;
  }

  .sidebar-toggle {
    display: none;
  }
}

/* ============================================================================
   8. UTILITIES
   ============================================================================ */

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }

.hidden { display: none !important; }
.invisible { visibility: hidden; }

.w-full { width: 100%; }
.h-full { height: 100%; }

.rounded-full { border-radius: var(--radius-full); }
.rounded-md   { border-radius: var(--radius-md); }
.rounded-lg   { border-radius: var(--radius-lg); }

.shadow-sm { box-shadow: var(--shadow-sm); }
.shadow-md { box-shadow: var(--shadow-md); }
.shadow-lg { box-shadow: var(--shadow-lg); }

.cursor-pointer { cursor: pointer; }

/* ============================================================================
   9. ANIMATIONS
   ============================================================================ */

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(12px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

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

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

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

.animate-fadeIn  { animation: fadeIn 200ms ease; }
.animate-slideUp { animation: slideUp 250ms ease; }
.animate-spin    { animation: spin 1s linear infinite; }
.animate-pulse   { animation: pulse 1.5s ease-in-out infinite; }

/* ============================================================================
   10. SCROLLBAR (custom)
   ============================================================================ */

.app-main::-webkit-scrollbar,
.scroll-area::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.app-main::-webkit-scrollbar-track,
.scroll-area::-webkit-scrollbar-track {
  background: transparent;
}

.app-main::-webkit-scrollbar-thumb,
.scroll-area::-webkit-scrollbar-thumb {
  background: var(--color-gray-300);
  border-radius: 4px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

.app-main::-webkit-scrollbar-thumb:hover,
.scroll-area::-webkit-scrollbar-thumb:hover {
  background: var(--color-gray-400);
  background-clip: padding-box;
  border: 2px solid transparent;
}

/* ============================================================================
   11. RTL ADJUSTMENTS
   ============================================================================ */

[dir="rtl"] body {
  letter-spacing: 0;
}

/* أرقام لاتينية في contexts معينة (تواريخ، أرقام) */
.tabular-nums {
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum';
}

/* ============================================================================
   12. ROUTE LOADING / ERROR STATES
   ============================================================================ */

.route-error {
  padding: var(--space-12);
  text-align: center;
  color: var(--text-secondary);
}

.route-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
}
