/* ============================================================
 *  BASE CSS — Design system, reset, shared components
 * ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.5;
  overflow-x: hidden;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
button { cursor: pointer; font: inherit; border: none; background: none; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }
img { max-width: 100%; display: block; }
svg { display: block; }

/* ---------- CSS variables ---------- */
:root {
  /* background */
  --bg:             #f9fafb;
  --bg-surface:     #ffffff;
  --bg-elevated:    #ffffff;
  --bg-hover:       #f3f4f6;
  --bg-overlay:     rgba(17, 24, 39, 0.4);
  --bg-glass:       rgba(255, 255, 255, 0.85);

  /* accent */
  --accent:         #111827; /* Dark near black for primary */
  --accent-light:   #374151;
  --accent-glow:    transparent;
  --accent2:        #4f46e5;
  --accent2-glow:   transparent;

  /* status */
  --status-new:        #3b82f6;
  --status-progress:   #f59e0b;
  --status-hold:       #ef4444;
  --status-completed:  #10b981;
  --status-cancelled:  #6b7280;

  /* text */
  --text-primary:   #111827;
  --text-secondary: #4b5563;
  --text-muted:     #9ca3af;
  --text-inverse:   #ffffff;

  /* border */
  --border:         #e5e7eb;
  --border-light:   #f3f4f6;
  --border-focus:   #111827;

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

  /* spacing */
  --sp-xs: 4px;
  --sp-sm: 8px;
  --sp-md: 16px;
  --sp-lg: 24px;
  --sp-xl: 32px;
  --sp-2xl: 48px;

  /* shadow */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -2px rgba(0, 0, 0, 0.025);
  --shadow-glow: none;

  /* transition */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --t-fast: 150ms;
  --t-base: 200ms;
  --t-slow: 300ms;

  /* z-index */
  --z-base: 1;
  --z-header: 100;
  --z-modal: 500;
  --z-toast: 900;
  --z-drag: 1000;
}

/* ---------- scrollbar ---------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* ---------- typography ---------- */
.mono { font-family: 'JetBrains Mono', monospace; }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.text-lg { font-size: 1.125rem; }
.text-xl { font-size: 1.25rem; }
.text-muted { color: var(--text-muted); }
.text-accent { color: var(--accent); }
.fw-500 { font-weight: 500; }
.fw-600 { font-weight: 600; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--r-md);
  font-weight: 500; font-size: 0.875rem;
  transition: all var(--t-fast) var(--ease);
  white-space: nowrap; position: relative;
  justify-content: center;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: #000; }

.btn-secondary {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}
.btn-secondary:hover { background: var(--bg-hover); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover { color: var(--text-primary); background: var(--bg-hover); }

.btn-danger {
  background: var(--bg-surface);
  color: var(--status-hold);
  border: 1px solid var(--border);
}
.btn-danger:hover { background: #fef2f2; border-color: #fca5a5; }

.btn-sm { padding: 6px 12px; font-size: 0.8125rem; }
.btn-icon {
  width: 32px; height: 32px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-sm);
  color: var(--text-secondary);
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: var(--r-md);
  font-size: 0.75rem; font-weight: 500;
}
.badge-new        { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }
.badge-progress   { background: #fffbeb; color: #b45309; border: 1px solid #fde68a; }
.badge-hold       { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.badge-completed  { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.badge-cancelled  { background: #f3f4f6; color: #374151; border: 1px solid #e5e7eb; }

/* ---------- form inputs ---------- */
.input-group { display: flex; flex-direction: column; gap: 6px; }
.input-group label {
  font-size: 0.8125rem; font-weight: 500;
  color: var(--text-secondary);
}
.input, .textarea, .select {
  width: 100%; padding: 8px 12px;
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--r-md); color: var(--text-primary);
  transition: all var(--t-fast);
  outline: none; font-size: 0.875rem;
  box-shadow: var(--shadow-sm);
}
.input::placeholder, .textarea::placeholder { color: var(--text-muted); }
.input:focus, .textarea:focus, .select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(17, 24, 39, 0.1);
}
.textarea { resize: vertical; min-height: 80px; }
.select {
  -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='4 6 8 10 12 6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}
.input-row { display: flex; gap: var(--sp-md); }
.input-row .input-group { flex: 1; }

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: var(--bg-overlay);
  backdrop-filter: blur(2px);
  z-index: var(--z-modal);
  display: flex; align-items: center; justify-content: center;
  padding: var(--sp-md);
  opacity: 0; visibility: hidden;
  transition: all var(--t-base) var(--ease);
}
.modal-overlay.active { opacity: 1; visibility: visible; }

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  width: 100%; max-width: 500px; max-height: 90vh;
  overflow-y: auto; box-shadow: var(--shadow-lg);
  transform: translateY(10px) scale(0.98);
  transition: transform var(--t-slow) var(--ease-spring);
}
.modal-overlay.active .modal { transform: translateY(0) scale(1); }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1rem; font-weight: 600; color: var(--text-primary); }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.modal-footer {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: #f9fafb;
}

/* ---------- toast ---------- */
.toast-container {
  position: fixed; bottom: 20px; right: 20px;
  z-index: var(--z-toast);
  display: flex; flex-direction: column-reverse; gap: 8px;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-radius: var(--r-md);
  background: var(--bg-surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-md); font-size: 0.875rem; font-weight: 500;
  transform: translateX(120%); opacity: 0;
  transition: all var(--t-base) var(--ease-spring);
}
.toast.show { transform: translateX(0); opacity: 1; }
.toast-icon { display: flex; }
.toast-success .toast-icon { color: var(--status-completed); }
.toast-error .toast-icon { color: var(--status-hold); }
.toast-warning .toast-icon { color: var(--status-progress); }
.toast-info .toast-icon { color: var(--status-new); }

/* ---------- chip / tag ---------- */
.chip {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: var(--r-sm);
  font-size: 0.75rem; font-weight: 500;
  background: var(--bg); color: var(--text-secondary);
  border: 1px solid var(--border);
}

/* ---------- empty state ---------- */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 40px 20px;
  text-align: center; gap: 12px;
}
.empty-state-icon { color: var(--border); margin-bottom: 8px; }
.empty-state-title { font-size: 0.875rem; font-weight: 500; color: var(--text-secondary); }

/* ---------- progress bar ---------- */
.progress-bar {
  height: 4px; border-radius: 2px;
  background: var(--border); overflow: hidden;
}
.progress-fill {
  height: 100%; border-radius: 2px;
  background: var(--accent);
  transition: width var(--t-slow) var(--ease);
}

/* ---------- confetti ---------- */
.confetti-container {
  position: fixed; pointer-events: none; z-index: 9999;
}
.confetti-piece {
  position: absolute; width: 6px; height: 6px;
  border-radius: 2px; opacity: 1;
  animation: confetti-burst 0.8s var(--delay, 0s) forwards var(--ease);
}
@keyframes confetti-burst {
  0%   { transform: translate(0,0) rotate(0deg); opacity: 1; }
  100% { transform: translate(calc(cos(var(--angle)) * var(--dist)), calc(sin(var(--angle)) * var(--dist) - 40px)) rotate(720deg); opacity: 0; }
}

/* ---------- skeleton loader ---------- */
.skeleton {
  background: linear-gradient(90deg, #f3f4f6 25%, #e5e7eb 50%, #f3f4f6 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease infinite;
  border-radius: var(--r-sm);
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---------- loading spinner ---------- */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--text-secondary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- animations ---------- */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.anim-fade    { animation: fadeIn var(--t-base) var(--ease); }
.anim-slide   { animation: slideUp var(--t-base) var(--ease); }

.stagger-item {
  opacity: 0;
  animation: slideUp var(--t-base) var(--ease) forwards;
}

/* ---------- drag states ---------- */
.drag-ghost {
  position: fixed; z-index: var(--z-drag); pointer-events: none;
  opacity: 0.9; transform: rotate(2deg);
  box-shadow: var(--shadow-lg); border-radius: var(--r-md);
  transition: none;
}
.drag-placeholder {
  border: 2px dashed var(--border);
  border-radius: var(--r-md);
  background: var(--bg);
  margin: var(--sp-sm) 0;
  transition: height var(--t-fast);
}
.dragging { opacity: 0.4 !important; }
body.is-dragging { user-select: none; cursor: grabbing !important; }

/* ---------- search input ---------- */
.search-wrap {
  position: relative; display: flex; align-items: center;
}
.search-wrap .search-icon {
  position: absolute; left: 10px;
  color: var(--text-muted);
  pointer-events: none;
}
.search-wrap .input {
  padding-left: 32px;
}

/* ---------- sync indicator ---------- */
.sync-badge {
  position: absolute; top: -6px; right: -6px;
  min-width: 16px; height: 16px;
  background: var(--status-hold); color: #fff;
  border-radius: 8px; font-size: 0.625rem;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; padding: 0 4px; border: 2px solid var(--bg-surface);
}
.syncing .spinner { border-top-color: var(--accent); }

/* ---------- hide/show by mode ---------- */
.mobile-only { display: none; }
.desktop-only { display: none; }

@media (max-width: 767px) {
  .mobile-only { display: flex; }
  .desktop-only { display: none !important; }
}
@media (min-width: 768px) {
  .mobile-only { display: none !important; }
  .desktop-only { display: flex; }
}
