/* ============================================================
   HQ Design System — style.css
   Surface hierarchy, motion, components, responsive
   ============================================================ */

/* --- Custom Properties --- */
:root {
  --surface-0: #ffffff;
  --surface-1: #f9fafb;
  --surface-2: #f4f4f5;
  --surface-3: #e4e4e7;
  --text-primary: #18181b;
  --text-secondary: #52525b;
  --text-muted: #a1a1aa;
  --border-default: rgba(0,0,0,0.08);
  --border-subtle: rgba(0,0,0,0.04);
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-glow: rgba(99,102,241,0.15);
  --violet: #8b5cf6;
  --emerald: #10b981;
  --rose: #f43f5e;
  --amber: #f59e0b;
  --ring-focus: 0 0 0 2px var(--accent), 0 0 0 4px rgba(99,102,241,0.2);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
  --transition-fast: 120ms ease;
  --transition-normal: 160ms ease-out;
  --transition-state: 200ms ease-in-out;
}

.dark {
  --surface-0: #0A0A0C;
  --surface-1: #111113;
  --surface-2: #18181B;
  --surface-3: #1F1F23;
  --text-primary: #fafafa;
  --text-secondary: #a1a1aa;
  --text-muted: #63636e;
  --border-default: rgba(255,255,255,0.06);
  --border-subtle: rgba(255,255,255,0.03);
  --accent-glow: rgba(99,102,241,0.12);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
}

/* --- Base --- */
* { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
body { font-family: 'Inter', system-ui, -apple-system, sans-serif; }

/* --- Focus visible --- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
:focus:not(:focus-visible) {
  outline: none;
}

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* ============================================================
   NAV BAR
   ============================================================ */
.nav-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 50;
  height: 56px;
  border-bottom: 1px solid var(--border-default);
  background: rgba(255,255,255,0.80);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
}
.dark .nav-bar {
  background: rgba(10,10,12,0.80);
}

.nav-inner {
  max-width: 1400px;
  margin: 0 auto;
  height: 100%;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-left { display: flex; align-items: center; gap: 24px; }

.nav-logo {
  display: flex; align-items: center; gap: 8px;
  text-decoration: none; color: inherit;
}
.nav-logo-icon { width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; }
.nav-logo-text { font-size: 14px; font-weight: 600; letter-spacing: -0.02em; }

.nav-links { display: none; align-items: center; gap: 2px; }
@media (min-width: 768px) { .nav-links { display: flex; } }

.nav-link {
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--transition-fast), background var(--transition-fast);
  position: relative;
}
.nav-link:hover {
  color: var(--text-primary);
  background: var(--border-subtle);
}
.nav-link--active {
  color: var(--text-primary);
  background: var(--border-default);
}
.dark .nav-link--active {
  background: rgba(255,255,255,0.06);
}

/* Right side */
.nav-right { display: flex; align-items: center; gap: 4px; }

.nav-action {
  position: relative;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 32px; height: 32px;
  border-radius: 8px;
  border: none; background: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: color var(--transition-fast), background var(--transition-fast);
}
.nav-action:hover {
  color: var(--text-primary);
  background: var(--border-subtle);
}
.nav-action-shortcut {
  display: none;
}
@media (min-width: 768px) {
  #btn-cmd-k {
    width: auto; padding: 0 10px; gap: 8px;
  }
  #btn-cmd-k .nav-action-shortcut {
    display: flex;
  }
  .nav-action-shortcut kbd {
    font-family: inherit;
    font-size: 11px;
    padding: 1px 5px;
    border-radius: 4px;
    border: 1px solid var(--border-default);
    background: var(--surface-2);
    color: var(--text-muted);
    line-height: 1;
  }
}

/* Notification dot */
.notif-dot {
  position: absolute;
  top: 6px; right: 6px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--rose);
  border: 1.5px solid var(--surface-0);
}

/* Theme toggle icons */
.dark .theme-icon-sun { display: block; }
.dark .theme-icon-moon { display: none; }
.theme-icon-sun { display: none; }
.theme-icon-moon { display: block; }
#btn-theme svg {
  transition: transform 0.3s ease;
}
#btn-theme:hover svg {
  transform: rotate(15deg);
}

/* User avatar */
.nav-user-wrap { position: relative; margin-left: 4px; }
.nav-avatar-btn {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: none; padding: 0;
  cursor: pointer;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white;
  font-size: 12px;
  font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  transition: box-shadow var(--transition-fast);
}
.nav-avatar-btn:hover {
  box-shadow: 0 0 0 2px var(--surface-0), 0 0 0 4px var(--accent);
}
.nav-avatar {
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

/* User dropdown */
.user-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 220px;
  background: var(--surface-1);
  border: 1px solid var(--border-default);
  border-radius: 10px;
  padding: 4px;
  box-shadow: var(--shadow-lg);
  z-index: 60;
  animation: dropdownIn 0.15s ease-out;
}
@keyframes dropdownIn {
  from { opacity: 0; transform: translateY(-4px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.user-dropdown-head { padding: 10px 12px 8px; }
.user-dropdown-name { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.user-dropdown-email { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.user-dropdown-sep { height: 1px; background: var(--border-default); margin: 4px 0; }
.user-dropdown-item {
  display: block;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: 6px;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.user-dropdown-item:hover {
  background: var(--border-subtle);
  color: var(--text-primary);
}
.user-dropdown-item--danger:hover {
  color: var(--rose);
  background: rgba(244,63,94,0.08);
}

/* ============================================================
   MOBILE NAV
   ============================================================ */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 50;
  height: 60px;
  padding-bottom: env(safe-area-inset-bottom, 0);
  border-top: 1px solid var(--border-default);
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  align-items: center;
  justify-content: space-around;
}
.dark .mobile-nav {
  background: rgba(10,10,12,0.92);
}
@media (max-width: 767px) { .mobile-nav { display: flex; } }

.mobile-nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 10px; font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--transition-fast);
}
.mobile-nav-item--active {
  color: var(--accent);
}
.mobile-nav-item:hover { color: var(--text-primary); }

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
  padding-top: 56px;
  padding-bottom: 0;
  min-height: 100vh;
}
@media (max-width: 767px) {
  .main-content { padding-bottom: 60px; }
}
.main-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px 16px;
}
@media (min-width: 768px) {
  .main-inner { padding: 32px 24px; }
}

/* Page entry animation */
.main-inner > * {
  animation: fadeInUp 0.3s ease both;
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Staggered children */
.stagger > * {
  animation: fadeInUp 0.3s ease both;
}
.stagger > *:nth-child(1) { animation-delay: 0ms; }
.stagger > *:nth-child(2) { animation-delay: 60ms; }
.stagger > *:nth-child(3) { animation-delay: 120ms; }
.stagger > *:nth-child(4) { animation-delay: 180ms; }
.stagger > *:nth-child(5) { animation-delay: 240ms; }
.stagger > *:nth-child(6) { animation-delay: 300ms; }
.stagger > *:nth-child(7) { animation-delay: 360ms; }
.stagger > *:nth-child(8) { animation-delay: 420ms; }

/* ============================================================
   CARD SYSTEM
   ============================================================ */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border-default);
  border-radius: 10px;
  padding: 16px;
  transition: transform var(--transition-normal), box-shadow var(--transition-normal), border-color var(--transition-normal);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06);
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md), 0 0 0 1px rgba(99,102,241,0.1);
}
.dark .card {
  box-shadow: 0 0 0 1px rgba(255,255,255,0.04);
}
.dark .card:hover {
  box-shadow: var(--shadow-md), 0 0 0 1px rgba(99,102,241,0.15);
  border-color: rgba(99,102,241,0.15);
}

/* Stat card */
.stat-card { cursor: default; }
.stat-card .stat-label {
  font-size: 11px; font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.stat-card .stat-value {
  font-size: 28px; font-weight: 600;
  color: var(--text-primary);
  line-height: 1.2;
  margin-top: 8px;
}
.stat-card .stat-delta {
  font-size: 12px; margin-top: 4px;
}
.stat-delta--positive { color: var(--emerald); }
.stat-delta--warning { color: var(--amber); }
.stat-delta--critical { color: var(--rose); }

/* Gradient border utility */
.gradient-border {
  position: relative;
}
.gradient-border::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(135deg, rgba(99,102,241,0.2), rgba(139,92,246,0.2));
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

/* ============================================================
   COMMAND PALETTE
   ============================================================ */
.cmd-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 20vh;
  animation: cmdBackdropIn 0.15s ease-out;
}
@keyframes cmdBackdropIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.cmd-palette {
  width: 560px;
  max-width: calc(100vw - 32px);
  background: var(--surface-1);
  border: 1px solid var(--border-default);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: cmdPaletteIn 0.16s ease-out;
}
@keyframes cmdPaletteIn {
  from { opacity: 0; transform: translateY(-8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.cmd-input-row {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-default);
  gap: 10px;
}
.cmd-search-icon { color: var(--text-muted); flex-shrink: 0; }
.cmd-input {
  flex: 1;
  border: none;
  background: none;
  font-size: 15px;
  color: var(--text-primary);
  outline: none;
  font-family: inherit;
}
.cmd-input::placeholder { color: var(--text-muted); }
.cmd-kbd {
  font-family: inherit;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border-default);
  background: var(--surface-2);
  color: var(--text-muted);
}
.cmd-results {
  max-height: 340px;
  overflow-y: auto;
  padding: 8px;
}
.cmd-empty {
  padding: 32px 16px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}
.cmd-result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  transition: background var(--transition-fast);
}
.cmd-result-item:hover, .cmd-result-item--focused {
  background: var(--border-subtle);
  color: var(--text-primary);
}
.cmd-result-type {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--accent-glow);
  color: var(--accent);
  flex-shrink: 0;
}

/* ============================================================
   TOAST SYSTEM
   ============================================================ */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 110;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  pointer-events: none;
}
@media (max-width: 767px) {
  .toast-container { left: 16px; right: 16px; bottom: 76px; }
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  color: var(--text-primary);
  animation: toastIn 0.25s ease-out;
  max-width: 380px;
}
.toast--success { border-left: 3px solid var(--emerald); }
.toast--error { border-left: 3px solid var(--rose); }
.toast--info { border-left: 3px solid var(--accent); }
.toast-exit {
  animation: toastOut 0.15s ease-in forwards;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(4px) scale(0.96); }
}

/* ============================================================
   HTMX PROGRESS BAR
   ============================================================ */
.htmx-progress-bar {
  position: fixed;
  top: 0; left: 0;
  width: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--violet));
  z-index: 200;
  transition: width 0.3s ease;
  pointer-events: none;
}
.htmx-progress-bar.active {
  width: 70%;
  transition: width 4s cubic-bezier(0.1, 0.5, 0.2, 1);
}
.htmx-progress-bar.done {
  width: 100%;
  transition: width 0.2s ease;
  opacity: 0;
  transition: width 0.2s ease, opacity 0.3s ease 0.2s;
}

/* ============================================================
   SKELETON / SHIMMER
   ============================================================ */
.skeleton {
  background: linear-gradient(90deg,
    var(--surface-2) 25%,
    var(--surface-3) 50%,
    var(--surface-2) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 6px;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ============================================================
   KANBAN (from existing) — enhanced
   ============================================================ */
.kanban-col { min-height: 60vh; }
.drag-over {
  background: var(--accent-glow);
  border-color: var(--accent) !important;
  border-style: dashed;
}
.card-dragging {
  opacity: 0.5;
  transform: rotate(1.5deg) scale(1.02);
  transition: transform 0.15s ease;
}

/* ============================================================
   BADGE SYSTEM
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 100px;
  line-height: 1.4;
}
.badge--indigo { background: rgba(99,102,241,0.12); color: #818cf8; }
.badge--violet { background: rgba(139,92,246,0.12); color: #a78bfa; }
.badge--emerald { background: rgba(16,185,129,0.12); color: #34d399; }
.badge--rose { background: rgba(244,63,94,0.12); color: #fb7185; }
.badge--amber { background: rgba(245,158,11,0.12); color: #fbbf24; }
.badge--neutral { background: var(--border-default); color: var(--text-secondary); }

/* ============================================================
   BUTTON SYSTEM
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast), box-shadow var(--transition-fast), transform 80ms ease;
  text-decoration: none;
  line-height: 1;
}
.btn:active { transform: scale(0.97); }

.btn--primary {
  background: linear-gradient(135deg, #6366f1, #7c3aed);
  color: white;
  border: none;
  box-shadow: 0 1px 2px rgba(99,102,241,0.3);
}
.btn--primary:hover {
  box-shadow: 0 4px 12px rgba(99,102,241,0.35);
}

.btn--secondary {
  background: var(--surface-2);
  color: var(--text-primary);
  border-color: var(--border-default);
}
.btn--secondary:hover {
  background: var(--surface-3);
}

.btn--ghost {
  background: none;
  color: var(--text-secondary);
}
.btn--ghost:hover {
  background: var(--border-subtle);
  color: var(--text-primary);
}

.btn--sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn--lg { padding: 10px 20px; font-size: 14px; }

/* ============================================================
   FORM INPUTS
   ============================================================ */
.input {
  width: 100%;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text-primary);
  background: var(--surface-0);
  border: 1px solid var(--border-default);
  border-radius: 8px;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.dark .input { background: var(--surface-2); }
.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.input::placeholder { color: var(--text-muted); }

.input--error {
  border-color: var(--rose);
  box-shadow: 0 0 0 3px rgba(244,63,94,0.1);
}

/* ============================================================
   SVG SPARKLINE AREA
   ============================================================ */
.sparkline-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.5;
  opacity: 0.8;
}
.sparkline-area {
  fill: var(--accent);
  opacity: 0.08;
}
.sparkline-dot {
  fill: var(--accent);
  r: 3;
}

/* ============================================================
   PRINT
   ============================================================ */
@media print {
  .nav-bar, .mobile-nav, .toast-container, .cmd-backdrop,
  .htmx-progress-bar, #btn-cmd-k, #btn-theme, #btn-notif { display: none !important; }
  .main-content { padding-top: 0; }
  .card { break-inside: avoid; box-shadow: none; border: 1px solid #ddd; }
  body { background: white; color: black; }
}
