/* ==========================================================================
   TASKFLOW - PREMIUM DARK SAAS DESIGN SYSTEM
   Visual Direction: Linear, ClickUp, Notion Calendar & Enterprise SaaS
   100% Production Quality & Comprehensive Responsive System
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. CSS Custom Properties / Color System
   -------------------------------------------------------------------------- */
:root {
  /* Dark Navy Backgrounds (Default Primary Theme) */
  --bg-app: #07111F;
  --bg-surface: #0B1827;
  --bg-card: #101F31;
  --bg-card-hover: #15273D;
  --bg-tertiary: #1E293B;

  /* Typography Colors */
  --text-primary: #F8FAFC;
  --text-secondary: #94A3B8;
  --text-muted: #64748B;
  --text-inverse: #0F172A;

  /* Borders & Dividers */
  --border-color: rgba(255, 255, 255, 0.08);
  --border-subtle: rgba(255, 255, 255, 0.04);
  --border-focus: #8B5CF6;

  /* Purple / Violet Accent System */
  --primary: #8B5CF6;
  --primary-hover: #7C3AED;
  --primary-gradient: linear-gradient(135deg, #7C3AED 0%, #8B5CF6 100%);
  --primary-light: rgba(139, 92, 246, 0.15);
  --primary-glow: 0 0 20px rgba(124, 58, 237, 0.35);

  /* Status & Priority Accents */
  --success: #10B981;
  --success-light: rgba(16, 185, 129, 0.15);
  --warning: #F59E0B;
  --warning-light: rgba(245, 158, 11, 0.15);
  --danger: #EF4444;
  --danger-light: rgba(239, 68, 68, 0.15);
  --info: #3B82F6;
  --info-light: rgba(59, 130, 246, 0.15);

  --priority-urgent: #EF4444;
  --priority-high: #F97316;
  --priority-medium: #3B82F6;
  --priority-low: #64748B;
  --priority-none: #475569;

  /* Shadows & Radius */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.5);
  --shadow-purple: 0 4px 14px rgba(124, 58, 237, 0.3);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 18px;
  --radius-full: 9999px;

  --sidebar-width: 250px;
  --topbar-height: 64px;

  --font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Light Theme Support */
[data-theme="light"] {
  --bg-app: #F8FAFC;
  --bg-surface: #FFFFFF;
  --bg-card: #FFFFFF;
  --bg-card-hover: #F1F5F9;
  --bg-tertiary: #E2E8F0;

  --text-primary: #0F172A;
  --text-secondary: #475569;
  --text-muted: #94A3B8;
  --text-inverse: #FFFFFF;

  --border-color: #E2E8F0;
  --border-subtle: #F1F5F9;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
}

/* --------------------------------------------------------------------------
   2. Base Reset & Layout Constraints (PREVENT GLOBAL SCROLLOVERFLOW)
   -------------------------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  width: 100%;
  font-family: var(--font-family);
  background-color: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.5;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body.sidebar-open {
  overflow: hidden !important;
}

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

button {
  cursor: pointer;
  border: none;
  background: none;
  touch-action: manipulation;
}

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

/* Explicit Icon Dimensions Safety Rules (NO HUGE BLACK BLOCKS EVER) */
svg.ico, .ico, svg {
  max-width: 100%;
}

.ico, svg.ico {
  width: 1.25rem !important;
  height: 1.25rem !important;
  min-width: 1.25rem !important;
  min-height: 1.25rem !important;
  max-width: 1.25rem !important;
  max-height: 1.25rem !important;
  flex-shrink: 0 !important;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sidebar-nav .ico, .sidebar-nav svg {
  width: 18px !important;
  height: 18px !important;
  min-width: 18px !important;
  min-height: 18px !important;
}

/* Scrollbar Customization */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* --------------------------------------------------------------------------
   3. App Layout Container
   -------------------------------------------------------------------------- */
#app {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  position: relative;
}

/* --------------------------------------------------------------------------
   4. Left Sidebar (~250px) & Mobile Drawer
   -------------------------------------------------------------------------- */
.sidebar {
  width: var(--sidebar-width);
  height: 100%;
  background-color: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: transform var(--transition-normal);
  z-index: 100;
  flex-shrink: 0;
  user-select: none;
}

.sidebar-header {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  border-bottom: 1px solid var(--border-subtle);
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--primary-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-purple);
}

.brand-name {
  background: linear-gradient(135deg, #FFFFFF 0%, #CBD5E1 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.nav-section {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nav-section-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 6px 12px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.875rem;
  transition: all var(--transition-fast);
  position: relative;
  width: 100%;
  text-align: left;
}

.nav-item:hover {
  background-color: rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
}

/* Translucent Purple Active Navigation State */
.nav-item.active {
  background: var(--primary-light);
  color: #FFFFFF;
  font-weight: 600;
  border: 1px solid rgba(139, 92, 246, 0.3);
  box-shadow: 0 0 12px rgba(124, 58, 237, 0.2);
}

.nav-item.active .ico {
  color: #A855F7;
}

.nav-item .badge {
  margin-left: auto;
  background-color: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: var(--radius-full);
}

.nav-item.active .badge {
  background-color: var(--primary);
  color: #FFFFFF;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* User Profile Sidebar Card (MEGHARI Abderrahmane Tarek) */
.user-profile-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: var(--radius-md);
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  width: 100%;
}

.user-avatar {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  background: var(--primary-gradient);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.9rem;
  box-shadow: var(--shadow-purple);
  flex-shrink: 0;
}

/* When the avatar is a real <button> (topbar profile trigger), reset native
   button chrome so it renders identically to the decorative div version and
   gets a visible focus ring for keyboard users. */
button.user-avatar {
  border: none;
  font-family: inherit;
  cursor: pointer;
}

button.user-avatar:focus-visible {
  outline: 2px solid var(--primary-purple, #8B5CF6);
  outline-offset: 2px;
}

.user-details {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.user-name {
  font-weight: 700;
  font-size: 0.825rem;
  color: var(--text-primary);
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.user-role {
  font-size: 0.72rem;
  color: var(--primary-purple);
  font-weight: 600;
}

/* Backdrop Overlay for Mobile Drawer */
#app-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(5, 11, 20, 0.75);
  backdrop-filter: blur(4px);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}

#app.sidebar-open #app-backdrop {
  opacity: 1;
  pointer-events: auto;
}

/* --------------------------------------------------------------------------
   5. Top Header Navigation Bar
   -------------------------------------------------------------------------- */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-app);
}

.topbar {
  height: var(--topbar-height);
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 30;
  flex-shrink: 0;
  gap: 12px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

#menu-btn {
  display: none;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 500;
  white-space: nowrap;
}

.breadcrumb-current {
  color: var(--text-primary);
  font-weight: 700;
}

/* Global Search Input Box */
.topbar-search {
  display: flex;
  align-items: center;
  gap: 10px;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 6px 14px;
  border-radius: var(--radius-full);
  width: 280px;
  transition: all var(--transition-fast);
  flex-shrink: 1;
}

.topbar-search:focus-within {
  border-color: var(--primary);
  box-shadow: var(--shadow-purple);
}

.topbar-search input {
  border: none;
  background: none;
  outline: none;
  font-size: 0.875rem;
  width: 100%;
  color: var(--text-primary);
}

.search-kbd {
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  font-family: monospace;
  flex-shrink: 0;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* Purple Gradient New Task Button */
.btn-primary {
  background: var(--primary-gradient);
  color: #FFFFFF;
  padding: 8px 16px;
  border-radius: var(--radius-full);
  font-weight: 600;
  font-size: 0.875rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: var(--shadow-purple);
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(124, 58, 237, 0.45);
}

.btn-secondary {
  background-color: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.875rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn-secondary:hover {
  background-color: var(--bg-card-hover);
  border-color: rgba(255, 255, 255, 0.15);
}

.btn-danger {
  background-color: rgba(239, 68, 68, 0.15);
  color: #EF4444;
  border: 1px solid rgba(239, 68, 68, 0.3);
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.875rem;
  transition: all var(--transition-fast);
}

.btn-danger:hover {
  background-color: #EF4444;
  color: #FFFFFF;
}

.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.btn-icon:hover {
  background-color: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
}

/* Content Main Workspace Area */
.content-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  position: relative;
}

/* --------------------------------------------------------------------------
   6. Dashboard View & KPI Cards
   -------------------------------------------------------------------------- */
.dashboard-page {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.greeting-title {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.greeting-name {
  background: linear-gradient(135deg, #A855F7 0%, #6366F1 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* KPI Cards Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
}

.card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.card:hover {
  border-color: rgba(255, 255, 255, 0.15);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.kpi-card {
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.kpi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.kpi-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.kpi-icon-box {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

.kpi-value {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  line-height: 1.1;
}

.kpi-trend {
  font-size: 0.8rem;
  font-weight: 600;
  margin-top: 8px;
}

/* Dashboard Layout Grid */
.dashboard-widgets-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
}

.dashboard-bottom-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

/* --------------------------------------------------------------------------
   7. Table & Kanban Responsive Containers
   -------------------------------------------------------------------------- */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-responsive table {
  min-width: 680px;
}

.kanban-board-container {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 12px;
}

.kanban-board {
  display: flex;
  gap: 16px;
  align-items: start;
  min-width: max-content;
}

.kanban-column {
  width: 280px;
  min-width: 280px;
  max-width: 280px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 500px;
  flex-shrink: 0;
}

.task-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  cursor: grab;
  transition: transform var(--transition-fast), border-color var(--transition-fast);
}

.task-card:hover {
  border-color: var(--primary-purple);
  transform: translateY(-2px);
}

.badge-priority-urgent { background: rgba(239,68,68,0.15); color: #EF4444; border: 1px solid rgba(239,68,68,0.3); }
.badge-priority-high { background: rgba(249,115,22,0.15); color: #F97316; border: 1px solid rgba(249,115,22,0.3); }
.badge-priority-medium { background: rgba(59,130,246,0.15); color: #3B82F6; border: 1px solid rgba(59,130,246,0.3); }
.badge-priority-low { background: rgba(100,116,139,0.15); color: #94A3B8; border: 1px solid rgba(100,116,139,0.3); }

/* --------------------------------------------------------------------------
   8. Modals & Overlays
   -------------------------------------------------------------------------- */
/* Visually hides an element while keeping it available to assistive tech —
   used for form labels that are programmatically required (Phase 8 accessibility
   fix) but would be visually redundant given the existing design. */
.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;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(5, 11, 20, 0.75);
  backdrop-filter: blur(6px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  width: min(92vw, 560px);
  max-height: 90vh;
  overflow-y: auto;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-lg);
}

.form-control {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 0.9rem;
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition-fast);
  min-height: 42px;
}

.form-control:focus {
  border-color: var(--primary);
}

/* --------------------------------------------------------------------------
   9. COMPREHENSIVE RESPONSIVE BREAKPOINT SYSTEM
   -------------------------------------------------------------------------- */

/* Desktop Large (≥ 1440px) */
@media (min-width: 1440px) {
  .content-area { padding: 32px; }
  .kpi-grid { gap: 24px; }
}

/* Laptop & Tablet Landscape (1024px – 1279px) */
@media (max-width: 1279px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-bottom-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Tablet Portrait & Mobile Drawer Trigger (< 1024px) */
@media (max-width: 1023px) {
  #menu-btn { display: inline-flex; }
  .breadcrumb { display: none; }
  
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
    box-shadow: 0 0 25px rgba(0, 0, 0, 0.5);
  }

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

  .dashboard-widgets-grid {
    grid-template-columns: 1fr;
  }
}

/* Large Mobile (640px – 767px) */
@media (max-width: 767px) {
  .topbar { padding: 0 16px; }
  .topbar-search { width: 180px; }
  .topbar-search .search-kbd { display: none; }
  .dashboard-bottom-grid { grid-template-columns: 1fr; }
  .content-area { padding: 16px; }
}

/* Small Mobile (≤ 480px) */
@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .greeting-title { font-size: 1.4rem; }
  
  .topbar-search { width: 140px; padding: 6px 10px; }
  .topbar-search input { font-size: 0.8rem; }

  .btn-primary { padding: 8px 12px; font-size: 0.8rem; }
  .btn-primary span { display: inline-block; }

  .kanban-column { width: 260px; min-width: 260px; }
  .modal-card { padding: 18px; width: 95vw; }
}

/* Very Small Mobile (≤ 360px) */
@media (max-width: 360px) {
  .topbar-search { display: none; }
  .btn-primary span { display: none; }
  .btn-primary { padding: 8px; border-radius: 50%; }
}
