/* ============================================================================
   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 {
  /* Brand aliases (use with var(--copper), etc.) */
  --text-900:           #1C1C1E;
  --text-700:           #3A3A3C;
  --text-500:           #6B6B70;
  --copper:             #C4956A;
  --copper-dark:        #A67A52;
  --copper-light:       #F5EDE3;
  --border:             #E8E4DC;

  /* Brand — white / copper */
  --white:              #FFFFFF;
  --warm-white:         #FAF9F7;
  --cream:              #F4F1EB;
  --cream-dark:         #EAE4D8;

  /* Primary — Copper */
  --color-primary-50:   #F5EDE3;
  --color-primary-100:  #EDD9C4;
  --color-primary-200:  #E4CCB0;
  --color-primary-300:  #D9B88F;
  --color-primary-400:  #D4A87A;
  --color-primary-500:  #C4956A;
  --color-primary-600:  #A67A52;
  --color-primary-700:  #8B6644;
  --color-primary-800:  #6E5036;
  --color-primary-900:  #523C29;

  /* Neutral — warm gray (keeps existing utility names) */
  --color-gray-50:  #FAFAF9;
  --color-gray-100: #F4F1EB;
  --color-gray-200: #E8E4DC;
  --color-gray-300: #D4CFC5;
  --color-gray-400: #ADADB8;
  --color-gray-500: #8E8E93;
  --color-gray-600: #6B6B70;
  --color-gray-700: #4A4A4D;
  --color-gray-800: #3A3A3C;
  --color-gray-900: #1C1C1E;

  /* Accent — copper tone (legacy hooks) */
  --color-accent-400: #D4A87A;
  --color-accent-500: #C4956A;
  --color-accent-600: #A67A52;
  --color-accent-700: #8B6644;

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

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

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

  /* Surfaces */
  --surface-app:           #FAF9F7;
  --surface-sidebar:     #FFFFFF;
  --surface-card:        #FFFFFF;
  --surface-hover:       #F4F1EB;
  --surface-active:      #F5EDE3;
  --bg-elevated:         var(--surface-card);
  --color-surface:       var(--surface-card);
  --color-border:        var(--border-light);

  /* Typography */
  --text-primary:    #1C1C1E;
  --text-secondary:  #6B6B70;
  --text-muted:      #ADADB8;
  --text-inverse:    #FFFFFF;
  --text-on-sidebar:        #3A3A3C;
  --text-on-sidebar-muted:  #6B6B70;
  --text-on-sidebar-active: #C4956A;

  /* Borders */
  --border-light:  #E8E4DC;
  --border-medium: #D4CFC5;
  --border-focus:  #C4956A;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgb(28 28 30 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(28 28 30 / 0.07), 0 2px 4px -2px rgb(28 28 30 / 0.05);
  --shadow-lg: 0 10px 15px -3px rgb(28 28 30 / 0.08), 0 4px 6px -4px rgb(28 28 30 / 0.05);
  --shadow-xl: 0 32px 80px rgb(28 28 30 / 0.12), 0 8px 24px rgb(28 28 30 / 0.06);

  /* 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;
  --sidebar-font-org:         14px;
  --sidebar-font-nav:         14px;
  --sidebar-font-project:     13px;
  --sidebar-font-section:     12px;
  --sidebar-row-pad-y:        10px;
  --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);
}

/* ============================================================================
   1b. DARK MODE — [data-theme="dark"] on <html>
   Set/toggled by app/core/theme.js. Overrides only the semantic surface /
   text / border / shadow tokens — component CSS keeps using var(--...) so it
   automatically follows.
   ============================================================================ */

[data-theme="dark"] {
  --surface-app:    #0F1117;
  --surface-sidebar: #1A1D27;
  --surface-card:   #1A1D27;
  --surface-hover:  #222536;
  --surface-active: #2A2340;

  --cream:          #222536;
  --cream-dark:     #2A2340;
  --warm-white:     #1A1D27;
  --color-gray-50:  #161822;
  --color-gray-100: #222536;
  --color-gray-200: #2D3148;
  --color-gray-300: #3D4166;

  --text-primary:   #F0F2F5;
  --text-secondary: #9BA3AF;
  --text-muted:     #6B7280;
  --text-on-sidebar:        #F0F2F5;
  --text-on-sidebar-muted:  #9BA3AF;

  --border-light:   #2D3148;
  --border-medium:  #3D4166;
  --border-focus:   #C4956A;

  --color-primary-500: #C4956A;
  --color-primary-50: rgba(196, 149, 106, 0.15);
  --color-primary-600: #D4A87A;
  --copper-light: rgba(196, 149, 106, 0.15);

  --color-gray-400: #9BA3AF;
  --color-gray-500: #9BA3AF;
  --color-gray-700: #E5E7EB;
  --color-gray-900: #F0F2F5;
  --color-white: #1A1D27;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg: 0 16px 48px rgba(0,0,0,0.5);
}

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

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

/* Smooth cross-fade when [data-theme] flips between light/dark */
*, *::before, *::after {
  transition: background-color 0.2s ease,
              border-color 0.2s ease,
              color 0.2s ease;
}

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%;
}

/* Author `display` on component classes beats the UA `[hidden] { display: none }`
   rule, so `el.hidden = true` would not hide spinners/menus. Keep hidden winning. */
[hidden] {
  display: none !important;
}

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);
  border-inline-end: 1px solid var(--border-light);
  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 var(--border-light);
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  min-width: 0;
}

.sidebar-brand img {
  display: block;
  height: 36px;
  width: auto;
  max-width: 100%;
  object-fit: contain;
}

.app-layout.sidebar-collapsed .sidebar-section-label,
.app-layout.sidebar-collapsed .nav-item-label,
.app-layout.sidebar-collapsed .org-switcher,
.app-layout.sidebar-collapsed .sidebar-current-org-name,
.app-layout.sidebar-collapsed .org-name,
.app-layout.sidebar-collapsed .sidebar-org-workspaces,
.app-layout.sidebar-collapsed .sidebar-org-add-ws,
.app-layout.sidebar-collapsed .sidebar-org-chevron,
.app-layout.sidebar-collapsed .sidebar-ws-chevron,
.app-layout.sidebar-collapsed .sidebar-org-ws-label {
  display: none;
}

/* Collapsed rail: keep the brand, swap to the icon-only asset via JS */
.app-layout.sidebar-collapsed .sidebar-brand {
  display: flex;
  justify-content: center;
  width: 100%;
}

.app-layout.sidebar-collapsed .sidebar-brand img {
  height: 28px;
  width: 28px;
}

.sidebar-org {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-light);
  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: var(--surface-hover);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition-fast);
  width: 100%;
}

.org-switcher:hover {
  background: var(--surface-active);
  color: var(--text-primary);
}

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

/* Grouped org → workspace → project tree */
.sidebar-current-org {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-current-org-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.sidebar-current-org-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-org-section {
  margin-bottom: 4px;
}

.sidebar-org-section.is-current .sidebar-org-header {
  background: var(--surface-hover);
}

.sidebar-org-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  font-size: var(--sidebar-font-org, 14px);
  font-weight: 700;
  color: var(--text-primary);
  border-radius: 8px;
}

.sidebar-org-header:hover {
  background: var(--surface-hover);
}

.sidebar-org-header .org-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  color: inherit;
  text-align: start;
  padding: 0;
}

.org-badge {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
  line-height: 1;
  overflow: hidden;
}

.org-badge img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.chevron {
  display: flex;
  transition: transform 0.15s;
  flex-shrink: 0;
  color: var(--text-muted);
}

.chevron.expanded {
  transform: rotate(90deg);
}

[dir="rtl"] .chevron:not(.expanded) {
  transform: scaleX(-1);
}

[dir="rtl"] .chevron.expanded {
  transform: rotate(-90deg);
}

.sidebar-org-chevron,
.sidebar-ws-chevron {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: var(--text-muted);
  flex-shrink: 0;
}

.sidebar-org-workspaces {
  padding-inline-start: 20px;
}

.sidebar-org-ws-label {
  padding-inline-start: 12px;
  padding-top: 4px;
  padding-bottom: 2px;
}

.sidebar-workspace-item {
  margin-bottom: 2px;
}

.sidebar-workspace-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.sidebar-workspace-item button {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px;
  min-width: 36px;
  min-height: 36px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: var(--sidebar-font-nav, 13px);
  color: var(--text-secondary);
  border-radius: 6px;
}

.sidebar-workspace-item button:hover {
  background: var(--surface-hover);
}

.sidebar-ws-chevron {
  padding: 6px 4px;
}

.sidebar-workspace-link {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  padding: var(--sidebar-row-pad-y) 8px;
  min-height: 40px;
  border-radius: 8px;
  font-size: var(--sidebar-font-nav);
  color: var(--text-secondary);
  text-decoration: none;
  overflow: hidden;
}

.sidebar-workspace-link span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-workspace-link:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.sidebar-workspace-link.is-active {
  background: var(--copper-light, #F5EDE3);
  color: var(--copper, #C4956A);
  font-weight: 600;
}

.sidebar-projects-list {
  padding-inline-start: 20px;
}

.sidebar-project-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: var(--sidebar-row-pad-y) 10px;
  min-height: 40px;
  font-size: var(--sidebar-font-project);
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-project-link:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.sidebar-project-link.is-active {
  background: var(--copper-light, #F5EDE3);
  color: var(--copper, #C4956A);
  font-weight: 600;
}

.sidebar-tree-hint {
  padding: 8px 12px;
  font-size: var(--sidebar-font-section);
  color: var(--text-muted);
  font-style: italic;
  line-height: 1.4;
}

.sidebar-tree-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  font-style: normal;
}

.sidebar-tree-all-projects {
  display: block;
  margin: 2px 12px 8px;
  padding: 6px 0;
  min-height: 32px;
  font-size: var(--sidebar-font-section);
  letter-spacing: 0.02em;
  font-weight: 600;
  color: var(--copper, #C4956A);
  background: none;
  border: none;
  cursor: pointer;
  text-align: start;
}

.sidebar-tree-all-projects:hover {
  text-decoration: underline;
}

.entity-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: #fff;
  flex-shrink: 0;
}

.entity-badge svg {
  display: block;
  width: 15px;
  height: 15px;
}

.entity-badge--sm {
  width: 22px;
  height: 22px;
  border-radius: 6px;
}

.entity-badge--sm svg {
  width: 12px;
  height: 12px;
}

.entity-badge--md {
  width: 28px;
  height: 28px;
}

.entity-badge--lg {
  width: 32px;
  height: 32px;
}

.entity-badge--lg svg {
  width: 17px;
  height: 17px;
}

.entity-icon-picker {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 6px;
}

.entity-icon-picker-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  padding: 0;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  background: var(--surface-card);
  color: var(--text-secondary);
  cursor: pointer;
}

.entity-icon-picker-btn:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.entity-icon-picker-btn.is-selected {
  border-color: var(--copper, #C4956A);
  background: var(--copper-light, #F5EDE3);
  color: var(--copper-dark, #A67A52);
  box-shadow: 0 0 0 2px rgba(196, 149, 106, 0.22);
}

.entity-appearance .input-group + .input-group {
  margin-top: var(--space-3);
}

.app-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: start;
  padding: 10px 12px;
  min-height: 44px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  color: var(--text-primary);
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
}

.app-menu-item:hover,
.app-menu-item:focus-visible {
  background: var(--surface-hover);
}

.app-menu-item:active {
  background: var(--surface-active, var(--color-gray-100));
}

.app-menu-item.is-danger {
  color: var(--color-danger, #EF4444);
}

.app-menu-item.is-danger:hover {
  background: rgb(239 68 68 / 0.1);
}

[data-theme="dark"] .sidebar-project-link.is-active,
[data-theme="dark"] .sidebar-workspace-link.is-active {
  background: rgba(196, 149, 106, 0.18);
  color: var(--copper, #C4956A);
}

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

.sidebar-nav::-webkit-scrollbar {
  width: 4px;
}
.sidebar-nav::-webkit-scrollbar-thumb {
  background: var(--border-medium);
  border-radius: 2px;
}

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

.sidebar-section-label {
  padding: 10px var(--space-4) 6px;
  font-size: var(--sidebar-font-section);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

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

.nav-item:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.nav-item.is-active {
  background: var(--copper-light);
  color: var(--copper);
  box-shadow: none;
}

.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: var(--color-primary-100);
  color: var(--color-primary-700);
  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: var(--sidebar-font-project);
}

.nav-item--admin {
  color: #B45309;
}

.nav-item--admin:hover {
  background: rgb(245 158 11 / 0.12);
  color: #92400E;
}

.nav-item--admin.is-active {
  background: rgb(245 158 11 / 0.18);
  color: #78350F;
  box-shadow: none;
}

.sidebar-divider--main-nav {
  margin: var(--space-2) var(--space-4) var(--space-1);
  background: var(--border-light);
}

.sidebar-divider {
  height: 1px;
  background: var(--border-light);
  margin: var(--space-2) var(--space-3);
}

.sidebar-footer {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border-light);
  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: var(--surface-hover);
}

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

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

.sidebar-user-email {
  color: var(--text-muted);
  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(--surface-hover);
  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(--surface-active);
  border-color: var(--border-light);
}

.topbar-search-input:focus {
  background: var(--surface-card);
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgb(196 149 106 / 0.18);
  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-create-wrap {
  position: relative;
  margin-inline-end: var(--space-1);
}

.topbar-create-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.topbar-create-menu {
  position: absolute;
  top: calc(100% + 6px);
  inset-inline-end: 0;
  min-width: 200px;
  padding: var(--space-2);
  background: var(--surface-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 220;
  flex-direction: column;
  gap: 2px;
}

/* Author `display` must not override the `hidden` attribute (default menu closed). */
.topbar-create-menu[hidden] {
  display: none !important;
}

.topbar-create-menu:not([hidden]) {
  display: flex;
}

.topbar-create-menu.is-sheet:not([hidden]) {
  display: flex;
  border-radius: 16px 16px 0 0;
  padding: 16px 12px calc(16px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.18);
  animation: topbar-sheet-up 0.2s ease-out;
}

@keyframes topbar-sheet-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.topbar-create-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: start;
  padding: 10px 12px;
  min-height: 44px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
}

.topbar-create-menu-item:hover,
.topbar-create-menu-item:focus-visible {
  background: var(--surface-hover);
}

.topbar-create-menu-item:active {
  background: var(--surface-active, var(--color-gray-100));
}

.topbar-create-menu-item-icon {
  display: inline-flex;
  flex-shrink: 0;
  color: var(--copper, #C4956A);
}

.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(--surface-hover);
  color: var(--text-primary);
}

.topbar-lang-toggle {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  min-width: 36px;
}

.topbar-lang-toggle-label {
  line-height: 1;
}

.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-notif-wrap {
  position: relative;
  z-index: 10;
  flex-shrink: 0;
}

.topbar-notif-btn {
  min-width: 40px;
  min-height: 40px;
  position: relative;
  z-index: 10;
}

.topbar-notif-dropdown,
.notification-dropdown {
  position: fixed;
  top: 56px;
  inset-inline-end: 12px;
  width: min(360px, calc(100vw - 24px));
  max-height: 70vh;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--surface-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  padding: var(--space-2);
  -webkit-overflow-scrolling: touch;
}

.topbar-notif-empty {
  padding: var(--space-6);
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.topbar-notif-item {
  padding: var(--space-3);
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.topbar-notif-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px 6px;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 4px;
}

.topbar-notif-header-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.topbar-notif-item.is-unread {
  background: rgba(196, 149, 106, 0.1);
}

.topbar-notif-item.is-unread .topbar-notif-text {
  font-weight: 600;
}

.topbar-notif-item-main {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
}

.topbar-notif-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-primary-500);
  flex-shrink: 0;
  margin-top: 5px;
  opacity: 0;
}

.topbar-notif-item.is-unread .topbar-notif-dot {
  opacity: 1;
}

.topbar-notif-text {
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.4;
}

.topbar-notif-time {
  font-size: 11px;
  color: var(--text-muted);
  padding-inline-start: 16px;
}

.topbar-notif-markall {
  width: 100%;
  margin-top: var(--space-2);
}

.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);
}

.topbar-running-timer {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 10px;
  margin-inline-end: var(--space-1);
  border-radius: var(--radius-md);
  background: rgb(196 149 106 / 0.12);
  color: var(--copper, #C4956A);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  border: 1px solid rgb(196 149 106 / 0.35);
  transition: background var(--transition-fast), color var(--transition-fast);
}

.topbar-running-timer:hover {
  background: rgb(196 149 106 / 0.22);
}

.topbar-running-timer[hidden] {
  display: none !important;
}

.topbar-user-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.topbar-user-dropdown {
  position: fixed;
  top: 0;
  inset-inline-end: auto;
  width: min(260px, 92vw);
  background: var(--surface-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 4000;
  padding: var(--space-2);
}

.topbar-user-dropdown-header {
  padding: var(--space-2) var(--space-3) var(--space-3);
}

.topbar-user-dropdown-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-user-dropdown-email {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.topbar-user-dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: 10px 12px;
  min-height: 44px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: start;
}

.topbar-user-dropdown-item:hover {
  background: var(--surface-hover);
}

.topbar-user-dropdown-item--danger {
  color: var(--color-danger);
}

.topbar-user-dropdown-item--danger:hover {
  background: rgb(239 68 68 / 0.1);
}

.topbar-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition-fast);
}

.topbar-menu-btn:hover {
  background: var(--surface-hover, #F4F1EB);
}

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

@media (max-width: 768px) {
  /* Typography */
  h1 { font-size: clamp(20px, 5vw, 28px) !important; }
  h2 { font-size: clamp(18px, 4vw, 24px) !important; }

  /* Touch targets — exclude topbar chrome (space-constrained) */
  button,
  .btn,
  a.btn {
    min-height: 44px;
    min-width: 44px;
  }

  .app-topbar button,
  .app-topbar .btn,
  .app-topbar .btn-sm,
  .app-topbar a.btn {
    min-height: 40px !important;
    min-width: 40px !important;
  }

  .btn-sm,
  .btn-icon-sm {
    min-height: 44px;
    min-width: 44px;
  }

  /* Prevent page-level horizontal overflow */
  html,
  body {
    overflow-x: hidden;
    max-width: 100vw;
  }

  /* App layout - single column, sidebar out of flow */
  .app-layout {
    display: grid !important;
    grid-template-columns: 1fr !important;
    grid-template-rows: 56px 1fr !important;
    grid-template-areas:
      "topbar"
      "main" !important;
    height: 100dvh !important;
    width: 100% !important;
    max-width: 100vw !important;
    overflow: hidden !important;
  }

  .app-layout.sidebar-collapsed {
    grid-template-columns: 1fr !important;
  }

  /* Topbar - full width; physical left = hamburger */
  .app-topbar {
    grid-area: topbar !important;
    grid-column: 1 !important;
    grid-row: 1 !important;
    width: 100% !important;
    max-width: 100% !important;
    height: 56px !important;
    min-height: 56px !important;
    padding: 0 12px !important;
    gap: 8px !important;
    display: grid !important;
    grid-template-columns: 44px minmax(0, 1fr) auto !important;
    align-items: center !important;
    overflow: visible !important;
    box-sizing: border-box !important;
  }

  .topbar-menu-btn {
    display: flex !important;
    grid-column: 1 !important;
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
    min-height: 40px !important;
    align-items: center !important;
    justify-content: center !important;
    flex-shrink: 0 !important;
  }

  .topbar-search {
    display: none !important;
  }

  .topbar-actions {
    grid-column: 3 !important;
    gap: 4px !important;
    flex-shrink: 0 !important;
    margin-inline-start: 0 !important;
    max-width: 100% !important;
    overflow: visible !important;
  }

  .topbar-lang-toggle-label {
    display: none !important;
  }

  .topbar-lang-toggle {
    display: none !important;
  }

  .topbar-create-btn {
    padding: 8px 10px !important;
    font-size: 13px !important;
    width: auto !important;
    min-width: 40px !important;
    justify-content: center !important;
  }

  .topbar-create-btn .topbar-create-label {
    display: inline !important;
  }

  .topbar-create-btn .topbar-create-chevron {
    display: none !important;
  }

  .topbar-running-timer {
    max-width: 64px;
    padding: 0 6px;
    font-size: 11px;
  }

  .topbar-running-timer-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topbar-action {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
  }

  .topbar-divider {
    display: none;
  }

  /* Main content area */
  .app-main {
    grid-area: main !important;
    grid-column: 1 !important;
    grid-row: 2 !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    width: 100% !important;
    max-width: 100vw !important;
    min-width: 0 !important;
  }

  /* Sidebar - overlay drawer from the right (out of grid) */
  .app-sidebar {
    position: fixed !important;
    top: 0 !important;
    right: 0 !important;
    left: auto !important;
    bottom: 0 !important;
    width: 280px !important;
    max-width: 85vw !important;
    z-index: 200 !important;
    transform: translateX(100%) !important;
    transition: transform 0.3s ease !important;
    overflow-y: auto !important;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.15) !important;
    grid-area: unset !important;
    grid-column: unset !important;
    grid-row: unset !important;
  }

  html[dir="ltr"] .app-sidebar {
    right: auto !important;
    left: 0 !important;
    transform: translateX(-100%) !important;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15) !important;
  }

  .app-sidebar.is-open {
    transform: translateX(0) !important;
  }

  /* Overlay backdrop */
  .sidebar-overlay {
    display: none !important;
    position: fixed !important;
    inset: 0 !important;
    background: rgba(0, 0, 0, 0.5) !important;
    z-index: 199 !important;
  }

  .sidebar-overlay.is-visible {
    display: block !important;
  }

  .sidebar-toggle {
    display: none;
  }

  .sidebar-mobile-lang {
    display: flex !important;
  }

  .nav-item {
    font-size: 15px !important;
    min-height: 48px;
  }

  .app-sidebar {
    --sidebar-font-org: 16px;
    --sidebar-font-nav: 15px;
    --sidebar-font-project: 15px;
    --sidebar-font-section: 12px;
    --sidebar-row-pad-y: 12px;
  }

  .sidebar-workspace-link,
  .sidebar-project-link {
    min-height: 48px;
    font-size: var(--sidebar-font-nav);
  }

  .sidebar-org-header {
    min-height: 48px;
  }

  .btn-icon,
  .btn-icon-sm,
  .task-card-menu-btn,
  .topbar-action,
  .workspace-project-menu-btn,
  .task-detail-more-btn,
  .topbar-menu-btn,
  .entity-icon-picker-btn {
    min-width: 44px !important;
    min-height: 44px !important;
    width: 44px !important;
    height: 44px !important;
  }

  .entity-icon-picker {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  /* Dashboard cards */
  .dashboard-cards {
    grid-template-columns: 1fr !important;
    padding: 16px !important;
  }

  /* All views - reduce padding */
  .view-container,
  .analytics-view,
  .goals-view,
  .teams-view,
  .settings-view,
  .automations-view,
  .workload-view,
  .calendar-view,
  .timeline-view,
  [class$="-view"] {
    padding: 16px !important;
    max-width: 100% !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
  }

  /* Input groups full width — prevents iOS zoom */
  .input-group {
    width: 100% !important;
  }

  .input,
  select,
  textarea,
  .input-group .input,
  .input-group select,
  .input-group textarea {
    font-size: 16px !important;
    width: 100% !important;
    max-width: 100%;
  }

  /* Create button - icon only on very small screens */
  @media (max-width: 380px) {
    .topbar-create-btn span:not(.topbar-create-icon),
    .topbar-create-btn .topbar-create-label {
      display: none !important;
    }

    .topbar-create-btn {
      padding: 0 !important;
      width: 40px !important;
    }
  }
}

/* Mobile-only lang toggle inside sidebar (hidden on desktop) */
.sidebar-mobile-lang {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  margin-bottom: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  background: var(--surface-hover, #F4F1EB);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
}

.sidebar-mobile-lang:hover {
  background: var(--surface-card);
}

@media (max-width: 480px) {
  .app-topbar {
    padding: 0 8px !important;
    gap: 4px !important;
  }

  .topbar-actions {
    gap: 2px !important;
  }
}

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

/* Toggle switch (e.g. dark mode switch in Settings) */
.toggle-switch { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--border-medium); border-radius: 24px;
  transition: 0.3s;
}
.toggle-slider::before {
  content: ''; position: absolute; height: 18px; width: 18px;
  inset-inline-start: 3px; bottom: 3px; background: white; border-radius: 50%;
  transition: 0.3s;
}
input:checked + .toggle-slider { background: var(--copper, #C4956A); }
input:checked + .toggle-slider::before { transform: translateX(20px); }
[dir="rtl"] input:checked + .toggle-slider::before { transform: translateX(-20px); }

/* ============================================================================
   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);
}

/* Top-of-screen navigation progress (router) */
#route-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  z-index: 10050;
  pointer-events: none;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.2s ease;
}

#route-progress.route-progress--active {
  opacity: 1;
}

#route-progress.route-progress--out {
  opacity: 0;
}

.route-progress-bar {
  height: 100%;
  width: 35%;
  background: linear-gradient(90deg, #C4956A, #D4A87A, #C4956A);
  border-radius: 0 2px 2px 0;
  animation: routeProgressSweep 0.85s ease-in-out infinite;
}

html[dir="rtl"] .route-progress-bar {
  margin-inline-start: auto;
  animation-name: routeProgressSweepRtl;
}

@keyframes routeProgressSweep {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}

@keyframes routeProgressSweepRtl {
  0% { transform: translateX(100%); }
  100% { transform: translateX(-400%); }
}
