/* ============================================================
   Apex Ticketing System — Main Stylesheet
   Dark-first design with red accents (Apex Operations branding)
   ============================================================ */

/* ------------------------------------------------------------------
   1. CSS Variables — Dark Theme (default)
   ------------------------------------------------------------------ */
:root {
  --red-400: #f87171;
  --red-500: #ef4444;
  --red-600: #dc2626;
  --red-700: #b91c1c;
  --red-800: #991b1b;

  /* Status badge colors */
  --clr-done:           #16a34a;
  --clr-working:        #2563eb;
  --clr-stuck:          #dc2626;
  --clr-not-completed:  #6b7280;

  /* Overall status */
  --clr-building:  #d97706;
  --clr-qc:        #7c3aed;
  --clr-review:    #ca8a04;
  --clr-completed: #16a34a;
  --clr-on-hold:   #6b7280;

  /* Priority */
  --clr-low:    #6b7280;
  --clr-medium: #2563eb;
  --clr-high:   #d97706;
  --clr-urgent: #dc2626;

  /* Sidebar dimensions */
  --sidebar-width: 260px;
  --sidebar-collapsed-width: 68px;
  --topbar-height: 64px;

  /* Transitions */
  --transition: 0.2s ease;
  --transition-slow: 0.35s ease;
}

/* ------------------------------------------------------------------
   2. Theme tokens
   ------------------------------------------------------------------ */
[data-theme="dark"],
:root {
  --bg-base:        #0a0a0a;
  --bg-surface:     #111111;
  --bg-card:        #181818;
  --bg-card-hover:  #202020;
  --bg-input:       #111111;
  --bg-modal:       #1a1a1a;
  --bg-sidebar:     #0d0d0d;
  --bg-topbar:      #0d0d0d;
  --bg-table-head:  #111111;
  --bg-row-hover:   #1f1f1f;
  --bg-row-alt:     #141414;

  --border:         #2a2a2a;
  --border-focus:   #dc2626;

  --text-primary:   #f4f4f5;
  --text-secondary: #a1a1aa;
  --text-muted:     #71717a;

  --shadow-sm:   0 1px 3px rgba(0,0,0,.6);
  --shadow-md:   0 4px 12px rgba(0,0,0,.7);
  --shadow-lg:   0 10px 30px rgba(0,0,0,.8);

  --scrollbar-track: #111;
  --scrollbar-thumb: #2a2a2a;
}

[data-theme="light"] {
  --bg-base:        #f0f0f0;
  --bg-surface:     #e8e8e8;
  --bg-card:        #ffffff;
  --bg-card-hover:  #f9f9f9;
  --bg-input:       #ffffff;
  --bg-modal:       #ffffff;
  --bg-sidebar:     #0d0d0d;
  --bg-topbar:      #ffffff;
  --bg-table-head:  #f3f4f6;
  --bg-row-hover:   #f9fafb;
  --bg-row-alt:     #fdfdfd;

  --border:         #e2e2e2;
  --border-focus:   #dc2626;

  --text-primary:   #111111;
  --text-secondary: #4b5563;
  --text-muted:     #9ca3af;

  --shadow-sm:   0 1px 3px rgba(0,0,0,.08);
  --shadow-md:   0 4px 12px rgba(0,0,0,.1);
  --shadow-lg:   0 10px 30px rgba(0,0,0,.15);

  --scrollbar-track: #f0f0f0;
  --scrollbar-thumb: #d1d5db;
}

/* ------------------------------------------------------------------
   3. Reset & Base
   ------------------------------------------------------------------ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

a {
  color: var(--red-600);
  text-decoration: none;
}
a:hover { color: var(--red-500); }

img { max-width: 100%; }

ul, ol { list-style: none; }

/* ------------------------------------------------------------------
   4. Scrollbar
   ------------------------------------------------------------------ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--red-700); }

/* ------------------------------------------------------------------
   5. Layout — Sidebar + Main
   ------------------------------------------------------------------ */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid #1f1f1f;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 200;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform var(--transition-slow), width var(--transition-slow);
}

.sidebar-logo {
  padding: 1.5rem 1.25rem 1rem;
  border-bottom: 1px solid #1f1f1f;
  flex-shrink: 0;
}

.sidebar-logo a {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  text-decoration: none;
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: var(--red-600);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.logo-icon svg { color: #fff; }

.logo-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.logo-text .brand-apex {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--red-500);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.logo-text .brand-sub {
  font-size: 0.62rem;
  font-weight: 500;
  color: #666;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* Nav */
.sidebar-nav {
  flex: 1;
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-section-label {
  font-size: 0.65rem;
  font-weight: 600;
  color: #444;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 0.75rem 0.5rem 0.25rem;
  margin-top: 0.5rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  color: #888;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition), color var(--transition);
  position: relative;
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  stroke-width: 1.75;
}

.nav-item:hover {
  background: rgba(255,255,255,.04);
  color: #ccc;
}

.nav-item.active {
  background: rgba(220, 38, 38, 0.15);
  color: var(--red-500);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 20%;
  bottom: 20%;
  width: 3px;
  background: var(--red-600);
  border-radius: 0 3px 3px 0;
}

/* Sidebar boards list */
.sidebar-boards {
  padding: 0 0.75rem 0.5rem;
}

.sidebar-board-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  font-size: 0.8rem;
  color: #666;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition), color var(--transition);
}

.sidebar-board-item:hover {
  background: rgba(255,255,255,.04);
  color: #aaa;
}

.sidebar-board-item .board-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Sidebar board tree ──────────────────────────────────── */
.nav-board-group {
  display: flex;
  flex-direction: column;
}

.nav-board-row {
  display: flex;
  align-items: center;
}

.nav-board-row .nav-item {
  flex: 1;
  min-width: 0;
}

.nav-board-toggle {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 5px;
  border: none;
  background: transparent;
  color: #555;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 4px;
  transition: background var(--transition), color var(--transition);
  padding: 0;
}

.nav-board-toggle:hover {
  background: rgba(255,255,255,.07);
  color: #aaa;
}

.nav-board-toggle svg {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
  transition: transform 0.18s ease;
}

.nav-board-toggle.open svg {
  transform: rotate(90deg);
}

.nav-board-children {
  display: none;
  flex-direction: column;
  gap: 1px;
  padding-left: 1rem;
  border-left: 1px solid rgba(255,255,255,.06);
  margin-left: 1.1rem;
  margin-bottom: 2px;
  overflow: hidden;
}

.nav-board-children.open {
  display: flex;
}

.nav-subboard-item {
  font-size: 0.78rem !important;
  padding: 0.42rem 0.6rem !important;
  color: #666 !important;
}

.nav-subboard-item:hover {
  color: #bbb !important;
}

/* Sidebar bottom — user info */
.sidebar-footer {
  border-top: 1px solid #1f1f1f;
  padding: 1rem 0.75rem;
  flex-shrink: 0;
}

.user-card {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--red-700);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

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

.user-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: #ccc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 0.65rem;
  color: #555;
  text-transform: capitalize;
}

.sidebar-logout {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  color: #555;
  transition: all var(--transition);
  flex-shrink: 0;
}
.sidebar-logout:hover { background: rgba(220,38,38,.15); color: var(--red-500); }
.sidebar-logout svg { width: 15px; height: 15px; }

/* ------------------------------------------------------------------
   6. Main Content Area
   ------------------------------------------------------------------ */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left var(--transition-slow);
}

/* Topbar */
.topbar {
  height: var(--topbar-height);
  background: var(--bg-topbar);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.75rem;
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 1rem;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}

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

.hamburger {
  display: none;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
}
.hamburger svg { width: 18px; height: 18px; }
.hamburger:hover { color: var(--text-primary); }

.page-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--text-primary); }
.breadcrumb .sep { color: var(--border); }

/* Dark mode toggle */
.theme-toggle {
  position: relative;
  width: 44px;
  height: 24px;
}

.theme-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.theme-toggle-track {
  position: absolute;
  inset: 0;
  background: #2a2a2a;
  border-radius: 12px;
  cursor: pointer;
  transition: background var(--transition);
}

[data-theme="light"] .theme-toggle-track { background: #d1d5db; }

.theme-toggle-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #aaa;
  transition: transform var(--transition), background var(--transition);
}

.theme-toggle input:checked + .theme-toggle-track::after {
  transform: translateX(20px);
  background: var(--red-500);
}

/* Page content */
.page-content {
  padding: 1.75rem;
  flex: 1;
}

/* ------------------------------------------------------------------
   7. Cards
   ------------------------------------------------------------------ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  gap: 1rem;
}

.card-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* Stats cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  position: relative;
  overflow: hidden;
  transition: border-color var(--transition), transform var(--transition);
}

.stat-card:hover {
  border-color: var(--red-700);
  transform: translateY(-2px);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent-color, var(--red-600));
}

.stat-card.accent-green  { --accent-color: #16a34a; }
.stat-card.accent-blue   { --accent-color: #2563eb; }
.stat-card.accent-red    { --accent-color: #dc2626; }
.stat-card.accent-gray   { --accent-color: #6b7280; }
.stat-card.accent-orange { --accent-color: #d97706; }
.stat-card.accent-purple { --accent-color: #7c3aed; }

.stat-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat-value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
}

.stat-icon {
  position: absolute;
  right: 1.25rem;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0.08;
}
.stat-icon svg { width: 48px; height: 48px; }

/* Board cards */
.boards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.board-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  cursor: pointer;
  text-decoration: none;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  transition: border-color var(--transition), transform var(--transition), box-shadow var(--transition);
  position: relative;
  overflow: hidden;
}

.board-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--board-color, var(--red-600));
}

.board-card:hover {
  border-color: rgba(220,38,38,.4);
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.board-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.board-icon {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.board-icon svg { width: 20px; height: 20px; color: #fff; }

.board-actions-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: color var(--transition), background var(--transition);
}
.board-actions-btn:hover { color: var(--text-primary); background: var(--bg-surface); }
.board-actions-btn svg { width: 16px; height: 16px; }

.board-card-name {
  font-size: 0.975rem;
  font-weight: 700;
  color: var(--text-primary);
}

.board-card-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.board-card-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: auto;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.board-card-meta span {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}
.board-card-meta svg { width: 13px; height: 13px; }

/* Sub-board pills */
.sub-boards-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.75rem 0;
}

.sub-board-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.625rem;
  border-radius: 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all var(--transition);
}
.sub-board-pill:hover {
  background: rgba(220,38,38,.1);
  border-color: var(--red-700);
  color: var(--red-400);
}
.sub-board-pill svg { width: 13px; height: 13px; }

/* ------------------------------------------------------------------
   8. Badges / Pills
   ------------------------------------------------------------------ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.625rem;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: default;
  white-space: nowrap;
}

/* Status badges */
.badge-done           { background: rgba(22,163,74,.15);  color: #4ade80; border: 1px solid rgba(22,163,74,.3);  }
.badge-working        { background: rgba(37,99,235,.15);  color: #60a5fa; border: 1px solid rgba(37,99,235,.3);  }
.badge-stuck          { background: rgba(220,38,38,.15);  color: #f87171; border: 1px solid rgba(220,38,38,.3);  }
.badge-not-completed  { background: rgba(107,114,128,.12);color: #9ca3af; border: 1px solid rgba(107,114,128,.25);}

/* Overall status */
.badge-building   { background: rgba(217,119,6,.15);  color: #fbbf24; border: 1px solid rgba(217,119,6,.3);  }
.badge-qc         { background: rgba(124,58,237,.15); color: #a78bfa; border: 1px solid rgba(124,58,237,.3); }
.badge-review     { background: rgba(202,138,4,.15);  color: #fde047; border: 1px solid rgba(202,138,4,.3);  }
.badge-completed  { background: rgba(22,163,74,.15);  color: #4ade80; border: 1px solid rgba(22,163,74,.3);  }
.badge-on-hold    { background: rgba(107,114,128,.12);color: #9ca3af; border: 1px solid rgba(107,114,128,.25);}

/* Priority */
.badge-priority-low    { background: rgba(107,114,128,.12);color: #9ca3af; border: 1px solid rgba(107,114,128,.25);}
.badge-priority-medium { background: rgba(37,99,235,.15);  color: #60a5fa; border: 1px solid rgba(37,99,235,.3);  }
.badge-priority-high   { background: rgba(217,119,6,.15);  color: #fbbf24; border: 1px solid rgba(217,119,6,.3);  }
.badge-priority-urgent { background: rgba(220,38,38,.15);  color: #f87171; border: 1px solid rgba(220,38,38,.3);  }

.badge-role-admin       { background: rgba(220,38,38,.15);  color: #f87171; border: 1px solid rgba(220,38,38,.3); }
.badge-role-user        { background: rgba(37,99,235,.15);  color: #60a5fa; border: 1px solid rgba(37,99,235,.3); }
.badge-role-qa          { background: rgba(124,58,237,.15); color: #a78bfa; border: 1px solid rgba(124,58,237,.3); }
.badge-role-copywriter  { background: rgba(234,179,8,.15);  color: #fde047; border: 1px solid rgba(234,179,8,.3); }
.badge-role-manager     { background: rgba(20,184,166,.15); color: #5eead4; border: 1px solid rgba(20,184,166,.3); }

/* Clickable badges (for inline status change) */
.badge-clickable {
  cursor: pointer;
  transition: opacity var(--transition), transform var(--transition);
}
.badge-clickable:hover { opacity: 0.8; transform: scale(1.04); }

/* Light mode badge adjustments */
[data-theme="light"] .badge-done           { color: #15803d; }
[data-theme="light"] .badge-working        { color: #1d4ed8; }
[data-theme="light"] .badge-stuck          { color: #b91c1c; }
[data-theme="light"] .badge-not-completed  { color: #6b7280; }
[data-theme="light"] .badge-building       { color: #b45309; }
[data-theme="light"] .badge-qc             { color: #6d28d9; }
[data-theme="light"] .badge-review         { color: #a16207; }
[data-theme="light"] .badge-completed      { color: #15803d; }
[data-theme="light"] .badge-on-hold        { color: #6b7280; }
[data-theme="light"] .badge-priority-low    { color: #6b7280; }
[data-theme="light"] .badge-priority-medium { color: #1d4ed8; }
[data-theme="light"] .badge-priority-high   { color: #b45309; }
[data-theme="light"] .badge-priority-urgent { color: #b91c1c; }

/* ------------------------------------------------------------------
   9. Buttons
   ------------------------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.btn-sm {
  padding: 0.3rem 0.75rem;
  font-size: 0.8rem;
  border-radius: 6px;
}
.btn-sm svg { width: 14px; height: 14px; }

.btn-lg {
  padding: 0.7rem 1.5rem;
  font-size: 1rem;
  border-radius: 10px;
}

/* Primary — red */
.btn-primary {
  background: var(--red-600);
  color: #fff;
  border-color: var(--red-600);
}
.btn-primary:hover { background: var(--red-700); border-color: var(--red-700); color: #fff; }

/* Secondary */
.btn-secondary {
  background: var(--bg-surface);
  color: var(--text-secondary);
  border-color: var(--border);
}
.btn-secondary:hover { border-color: #555; color: var(--text-primary); }

/* Ghost */
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--bg-surface); color: var(--text-primary); }

/* Danger */
.btn-danger {
  background: rgba(220,38,38,.12);
  color: #f87171;
  border-color: rgba(220,38,38,.3);
}
.btn-danger:hover { background: rgba(220,38,38,.2); border-color: rgba(220,38,38,.5); }

.btn-icon {
  padding: 0.4rem;
  border-radius: 6px;
}
.btn-icon svg { margin: 0; }

/* ------------------------------------------------------------------
   10. Forms
   ------------------------------------------------------------------ */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1.25rem;
}

.form-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
}

.form-control {
  width: 100%;
  padding: 0.6rem 0.875rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 0.875rem;
  font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.form-control:focus {
  border-color: var(--red-600);
  box-shadow: 0 0 0 3px rgba(220,38,38,.12);
}

.form-control::placeholder { color: var(--text-muted); }

select.form-control {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.5rem;
}

textarea.form-control {
  resize: vertical;
  min-height: 100px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.form-error {
  font-size: 0.75rem;
  color: #f87171;
}

/* ------------------------------------------------------------------
   11. Alerts
   ------------------------------------------------------------------ */
.alert {
  padding: 0.875rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  border: 1px solid transparent;
}

.alert-success {
  background: rgba(22,163,74,.12);
  color: #4ade80;
  border-color: rgba(22,163,74,.3);
}

.alert-error {
  background: rgba(220,38,38,.12);
  color: #f87171;
  border-color: rgba(220,38,38,.3);
}

.alert-info {
  background: rgba(37,99,235,.12);
  color: #60a5fa;
  border-color: rgba(37,99,235,.3);
}

.alert-warning {
  background: rgba(217,119,6,.12);
  color: #fbbf24;
  border-color: rgba(217,119,6,.3);
}

[data-theme="light"] .alert-success { color: #15803d; }
[data-theme="light"] .alert-error   { color: #b91c1c; }
[data-theme="light"] .alert-info    { color: #1d4ed8; }
[data-theme="light"] .alert-warning { color: #b45309; }

/* ------------------------------------------------------------------
   12. Table
   ------------------------------------------------------------------ */
.table-container {
  overflow-x: auto;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.table th {
  background: var(--bg-table-head);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: color var(--transition);
}

.table th:hover { color: var(--text-primary); }
.table th .sort-icon { display: inline; margin-left: 4px; opacity: 0.4; }
.table th.sorted .sort-icon { opacity: 1; color: var(--red-500); }

.table td {
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: none; }

.table tbody tr {
  transition: background var(--transition);
}

.table tbody tr:hover { background: var(--bg-row-hover); }

.table tbody tr:nth-child(even) { background: var(--bg-row-alt); }
.table tbody tr:nth-child(even):hover { background: var(--bg-row-hover); }

.ticket-title-cell {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.ticket-title-text {
  font-weight: 600;
  color: var(--text-primary);
  max-width: 280px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ticket-id-text {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.assigned-cell {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.assigned-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--red-800);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.due-date-cell {
  white-space: nowrap;
  font-size: 0.8rem;
}
.due-date-cell.overdue { color: #f87171; }
.due-date-cell.due-soon { color: #fbbf24; }

.actions-cell {
  white-space: nowrap;
  text-align: right;
  vertical-align: middle;
}

.actions-cell .btn {
  margin-left: 2px;
}
.actions-cell .btn:first-child {
  margin-left: 0;
}

/* Filters bar */
.filters-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
  padding: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 1rem;
}

.filters-bar .form-group {
  margin-bottom: 0;
  min-width: 140px;
}

.filters-bar .form-label {
  font-size: 0.7rem;
}

.search-input-wrap {
  position: relative;
  flex: 1;
  min-width: 200px;
}
.search-input-wrap svg {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}
.search-input-wrap .form-control { padding-left: 2.25rem; }

/* ------------------------------------------------------------------
   13. Modals
   ------------------------------------------------------------------ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.75);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: scale(.96) translateY(12px);
  transition: transform var(--transition);
}

.modal-overlay.active .modal { transform: scale(1) translateY(0); }

.modal-lg { max-width: 700px; }

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}
.modal-close:hover { background: var(--bg-surface); color: var(--text-primary); }
.modal-close svg { width: 18px; height: 18px; }

.modal-body { padding: 1.5rem; }
.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* Dropdown popup (for inline status change) */
.dropdown-popup {
  position: absolute;
  z-index: 500;
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  min-width: 180px;
  overflow: hidden;
  display: none;
}

.dropdown-popup.show { display: block; }

.dropdown-popup-item {
  padding: 0.6rem 1rem;
  font-size: 0.825rem;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.625rem;
  transition: background var(--transition), color var(--transition);
}
.dropdown-popup-item:hover { background: var(--bg-row-hover); color: var(--text-primary); }

/* ------------------------------------------------------------------
   14. Login Page
   ------------------------------------------------------------------ */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-base);
  padding: 2rem;
  position: relative;
  overflow: hidden;
}

.login-page::before {
  content: '';
  position: absolute;
  top: -200px;
  right: -200px;
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, rgba(220,38,38,.08) 0%, transparent 70%);
  pointer-events: none;
}

.login-page::after {
  content: '';
  position: absolute;
  bottom: -150px;
  left: -150px;
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, rgba(220,38,38,.05) 0%, transparent 70%);
  pointer-events: none;
}

.login-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  position: relative;
  z-index: 1;
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.login-logo .logo-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
}

.login-logo .brand-apex { font-size: 1.1rem; }

.login-heading {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 0.375rem;
}

.login-subheading {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 1.75rem;
}

.login-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5rem 0;
}

.login-footer {
  text-align: center;
  margin-top: 1.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ------------------------------------------------------------------
   15. Ticket activity log
   ------------------------------------------------------------------ */
.activity-log {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.activity-item {
  display: flex;
  gap: 0.875rem;
  padding: 0.875rem 0;
  border-bottom: 1px solid var(--border);
  position: relative;
}
.activity-item:last-child { border-bottom: none; }

.activity-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--red-800);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  margin-top: 2px;
}

.activity-content {
  flex: 1;
  min-width: 0;
}

.activity-text {
  font-size: 0.825rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.activity-text strong { color: var(--text-primary); }

.activity-time {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

/* ------------------------------------------------------------------
   16. Users table / page
   ------------------------------------------------------------------ */
.users-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

/* ------------------------------------------------------------------
   17. Empty states
   ------------------------------------------------------------------ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  text-align: center;
  color: var(--text-muted);
  gap: 1rem;
}

.empty-state svg {
  width: 56px;
  height: 56px;
  opacity: 0.3;
}

.empty-state h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.empty-state p {
  font-size: 0.875rem;
  max-width: 320px;
}

/* ------------------------------------------------------------------
   18. Settings page
   ------------------------------------------------------------------ */
.settings-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 1.5rem;
}

.settings-section-header {
  padding: 1.1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.settings-section-header svg { width: 16px; height: 16px; color: var(--red-500); }

.settings-body { padding: 1.5rem; }

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 0;
  border-bottom: 1px solid var(--border);
  gap: 1rem;
}
.settings-row:last-child { border-bottom: none; }

.settings-row-info h4 {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.2rem;
}

.settings-row-info p {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ------------------------------------------------------------------
   19. Pagination
   ------------------------------------------------------------------ */
.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.375rem;
  padding-top: 1rem;
}

.page-btn {
  min-width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.5rem;
  transition: all var(--transition);
  text-decoration: none;
}
.page-btn:hover { border-color: var(--red-600); color: var(--red-500); }
.page-btn.active { background: var(--red-600); border-color: var(--red-600); color: #fff; }
.page-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* ------------------------------------------------------------------
   20. Toast notifications
   ------------------------------------------------------------------ */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  pointer-events: none;
}

.toast {
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.875rem 1.125rem;
  font-size: 0.875rem;
  color: var(--text-primary);
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-width: 240px;
  max-width: 360px;
  animation: toastIn .3s ease forwards;
  pointer-events: all;
}

.toast.toast-success { border-left: 3px solid #16a34a; }
.toast.toast-error   { border-left: 3px solid #dc2626; }
.toast.toast-info    { border-left: 3px solid #2563eb; }
.toast.toast-exit    { animation: toastOut .3s ease forwards; }

.toast svg { width: 16px; height: 16px; flex-shrink: 0; }
.toast-success svg { color: #4ade80; }
.toast-error svg   { color: #f87171; }
.toast-info svg    { color: #60a5fa; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(8px); }
}

/* ------------------------------------------------------------------
   21. Utility Classes
   ------------------------------------------------------------------ */
.flex         { display: flex; }
.flex-col     { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.w-full { width: 100%; }
.text-sm   { font-size: 0.875rem; }
.text-xs   { font-size: 0.75rem; }
.text-muted { color: var(--text-muted); }
.text-red   { color: var(--red-500); }
.font-bold  { font-weight: 700; }
.hidden { display: none !important; }
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.25rem 0;
}

/* Loading spinner */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--red-500);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------
   22. Responsive
   ------------------------------------------------------------------ */
@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

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

  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.6);
    z-index: 199;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
  }

  .sidebar-overlay.show {
    opacity: 1;
    pointer-events: all;
  }

  .main-content { margin-left: 0; }

  .hamburger { display: flex; }

  .topbar { padding: 0 1rem; }

  .page-content { padding: 1rem; }

  .stats-grid { grid-template-columns: repeat(2, 1fr); }

  .boards-grid { grid-template-columns: 1fr; }

  .form-row { grid-template-columns: 1fr; }

  .filters-bar { flex-direction: column; }
  .filters-bar .form-group,
  .filters-bar .search-input-wrap { min-width: 100%; }

  .login-box { padding: 1.75rem 1.5rem; }

  .modal { margin: 0.5rem; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .page-title { font-size: 0.95rem; }
  .table th, .table td { padding: 0.625rem 0.75rem; }
}

/* ------------------------------------------------------------------
   23. Notification Bell & Dropdown
   ------------------------------------------------------------------ */
.notif-wrap {
  position: relative;
}

.notif-btn {
  position: relative;
  background: rgba(255,255,255,.05);
  border: 1px solid var(--border);
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 9px;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  padding: 0;
}
[data-theme="light"] .notif-btn { background: #f5f5f5; }

.notif-btn:hover {
  background: rgba(220,38,38,.1);
  border-color: rgba(220,38,38,.3);
  color: var(--red-500);
}

.notif-btn svg { pointer-events: none; }

.notif-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--red-600);
  color: #fff;
  font-size: 0.55rem;
  font-weight: 800;
  min-width: 17px;
  height: 17px;
  border-radius: 9px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  pointer-events: none;
  border: 2px solid var(--bg-topbar);
  animation: badgePop .2s ease;
}

@keyframes badgePop {
  from { transform: scale(0); }
  to   { transform: scale(1); }
}

/* Dropdown — positioned via JS using position:fixed so it never clips */
.notif-dropdown {
  position: fixed;
  width: 360px;
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 8px 32px rgba(0,0,0,.55);
  z-index: 9000;
  display: none;
  overflow: hidden;
}
[data-theme="light"] .notif-dropdown { box-shadow: 0 8px 32px rgba(0,0,0,.18); }

.notif-dropdown.show {
  display: block;
  animation: notifIn .18s ease;
}

@keyframes notifIn {
  from { opacity: 0; transform: translateY(-8px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.notif-dropdown-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.125rem 0.875rem;
  border-bottom: 1px solid var(--border);
}

.notif-mark-read {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--red-500);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0;
  font-family: inherit;
}
.notif-mark-read:hover { color: var(--red-400); text-decoration: underline; }

.notif-list { max-height: 380px; overflow-y: auto; }

.notif-empty {
  padding: 2.5rem 1.5rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.82rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}
.notif-empty svg { opacity: 0.25; }

.notif-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.875rem 1.125rem;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--bg-row-hover); }

.notif-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: transparent;
  flex-shrink: 0;
  margin-top: 4px;
}
.notif-item.unread .notif-dot { background: var(--red-500); }

.notif-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(220,38,38,.12);
  color: var(--red-500);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.notif-icon svg { width: 15px; height: 15px; }

.notif-item-body { flex: 1; min-width: 0; }

.notif-msg {
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.5;
  word-break: break-word;
}
.notif-item.unread .notif-msg { color: var(--text-primary); font-weight: 500; }

.notif-time {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
}

/* ------------------------------------------------------------------
   24. Drag & Drop
   ------------------------------------------------------------------ */
.drag-handle {
  cursor: grab;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity var(--transition);
  text-align: center;
  user-select: none;
  width: 2rem;
  padding: 0.875rem 0.5rem !important;
}
.table tbody tr:hover .drag-handle { opacity: 1; }
.drag-handle:active { cursor: grabbing; }

tr.drag-source { opacity: 0.35; }
tr.drag-over   { outline: 2px solid var(--red-500); outline-offset: -1px; }

.board-card.drag-source { opacity: 0.4; transform: scale(.98); }
.board-card.drag-over   { box-shadow: 0 0 0 2px var(--red-500); }
