/* =============================================================
 * WPM CRM — Component Library
 * shadcn-style primitives, plain CSS, Tailwind-compatible
 * Stack: vanilla-JS + Tailwind CDN + this file.
 * Loaded after style.css; adds missing primitives
 * (button variants, cards, inputs, badges, tabs, modals,
 *  toasts, empty states, skeletons).
 * 2026-07-23 ~16:50 MYT — initial import from preview.html.
 * ============================================================= */

/* ---------- Body baseline (overrides style.css if conflicts) ---------- */
body.ui-modern {
  background: #09090b;
  color: #fafafa;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

/* ==============================================================
 *  Mobile floating nav  (2026-07-23 ~17:25 MYT — DORMANT)
 *  Implementation preserved but hidden everywhere because DX
 *  prefers the side-bar menu. Re-enable by removing the first
 *  two declarations below (display: none !important; pointer-
 *  events: none;) and the .mobile-topbar { display: none !important }
 *  override in public/index.html's @media block.
 * ============================================================ */
.mobile-floating-nav {
  display: none !important;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  padding: calc(env(safe-area-inset-top, 0px) + 0.5rem) 0.75rem 0.5rem;
  pointer-events: none !important;
  transition: transform 220ms cubic-bezier(0.16, 1, 0.3, 1),
              opacity 220ms cubic-bezier(0.16, 1, 0.3, 1);
  will-change: transform;
}
.mobile-floating-nav.nav-hidden {
  transform: translateY(calc(-100% - env(safe-area-inset-top, 0px) - 0.5rem));
  opacity: 0;
}
.mobile-floating-nav.nav-open .mobile-floating-items {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
#mobile-floating-btn {
  pointer-events: auto;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 9999px;
  background: rgba(24, 24, 27, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(245, 158, 11, 0.25);
  color: #fbbf24;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4),
              0 0 0 1px rgba(255, 255, 255, 0.05) inset;
  margin: 0 auto 0.5rem;
  transition: background 150ms, transform 150ms, border-color 150ms;
}
#mobile-floating-btn:hover {
  background: rgba(245, 158, 11, 0.12);
  border-color: #fbbf24;
  transform: scale(1.05);
}
#mobile-floating-btn:active {
  transform: scale(0.95);
}
.mobile-floating-items {
  pointer-events: auto;
  display: flex;
  flex-wrap: nowrap;
  gap: 0.25rem;
  padding: 0.375rem 0.5rem;
  margin: 0 auto;
  background: rgba(24, 24, 27, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid #27272a;
  border-radius: 9999px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  max-width: calc(100% - 1.5rem);
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  opacity: 0;
  transform: translateY(-6px) scale(0.97);
  transition: opacity 180ms ease, transform 180ms ease;
}
.mobile-floating-items::-webkit-scrollbar { display: none; }
.mobile-floating-items .mf-item {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  height: 2.25rem;
  padding: 0 0.875rem;
  border-radius: 9999px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: #e4e4e7;
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background 120ms, color 120ms, border-color 120ms;
  user-select: none;
}
.mobile-floating-items .mf-item:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #fafafa;
}
.mobile-floating-items .mf-item.active {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border-color: rgba(245, 158, 11, 0.4);
}
.mobile-floating-items .mf-item i {
  font-size: 0.8125rem;
  width: 14px;
  text-align: center;
}
.mobile-floating-items .mf-sep {
  flex-shrink: 0;
  width: 1px;
  height: 1.25rem;
  background: #3f3f46;
  margin: 0 0.125rem;
  align-self: center;
}
/* Hide in dark desktop viewports (handled in style.css but defensive) */
@media (min-width: 1024px) {
  .mobile-floating-nav { display: none !important; }
}
@media (max-width: 1023.98px) {
  /* DORMANT — see header comment above. Re-enable by changing
     to `display: block;` and dropping the base .mobile-floating-nav
     hide. Currently the floating nav is hidden everywhere because
     DX prefers the side-bar menu. */
  .mobile-floating-nav { display: none !important; }
}

/* ============================================================ Button == */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  white-space: nowrap;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1;
  transition: background 100ms ease, color 100ms ease, border-color 100ms ease, box-shadow 100ms ease;
  cursor: pointer;
  height: 2.25rem;
  padding: 0 1rem;
  border: 1px solid transparent;
  user-select: none;
  text-decoration: none;
}
.btn:focus-visible { outline: 2px solid #f59e0b; outline-offset: 2px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

.btn-primary    { background: #fafafa; color: #18181b; }
.btn-primary:hover    { background: #e4e4e7; }

.btn-secondary  { background: #27272a; color: #fafafa; border-color: #3f3f46; }
.btn-secondary:hover  { background: #3f3f46; }

.btn-outline    { background: transparent; border-color: #3f3f46; color: #fafafa; }
.btn-outline:hover    { background: #27272a; }

.btn-ghost      { background: transparent; color: #e4e4e7; }
.btn-ghost:hover      { background: #27272a; color: #fafafa; }

.btn-destructive   { background: #7f1d1d; color: #fafafa; }
.btn-destructive:hover   { background: #991b1b; }

.btn-link       { background: transparent; color: #fbbf24; text-decoration: underline; text-underline-offset: 2px; height: auto; padding: 0; }
.btn-link:hover       { color: #fde68a; }

.btn-icon       { width: 2.25rem; padding: 0; }
.btn-sm         { height: 2rem;    padding: 0 0.75rem; font-size: 0.8125rem; }
.btn-lg         { height: 2.75rem; padding: 0 1.5rem;  font-size: 1rem; }

/* ============================================================== Card === */
.card-modern {
  background: #18181b;
  border: 1px solid #27272a;
  border-radius: 0.5rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}
.card-modern > .card-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid #27272a;
  background: rgba(255, 255, 255, 0.01);
}
.card-modern > .card-header h3 {
  font-size: 1rem;
  font-weight: 600;
  color: #fafafa;
  letter-spacing: -0.01em;
}
.card-modern > .card-header p {
  font-size: 0.875rem;
  color: #a1a1aa;
  margin-top: 0.25rem;
}
.card-modern > .card-body { padding: 1.5rem; }

/* ============================================================ Inputs === */
.field-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: #e4e4e7;
  margin-bottom: 0.375rem;
}
.input-modern {
  display: flex;
  width: 100%;
  height: 2.25rem;
  padding: 0 0.75rem;
  border-radius: 0.375rem;
  border: 1px solid #3f3f46;
  background: #18181b;
  color: #fafafa;
  font-size: 0.875rem;
  font-family: inherit;
  line-height: 1;
  transition: border-color 100ms, box-shadow 100ms;
}
.input-modern::placeholder { color: #71717a; }
.input-modern:focus-visible {
  outline: none;
  border-color: #f59e0b;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.15);
}
.input-modern:disabled { opacity: 0.5; cursor: not-allowed; }
textarea.input-modern { height: auto; padding: 0.5rem 0.75rem; line-height: 1.4; }
select.input-modern   { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 0.625rem center; padding-right: 2rem; appearance: none; }

/* ============================================================ Badges === */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.25;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge-default  { background: #27272a; color: #fafafa; }
.badge-success  { background: #064e3b; color: #6ee7b7; }
.badge-warn     { background: #78350f; color: #fcd34d; }
.badge-error    { background: #7f1d1d; color: #fca5a5; }
.badge-info     { background: #1e3a8a; color: #93c5fd; }
.badge-muted    { background: transparent; color: #a1a1aa; border-color: #3f3f46; }

/* ========================================================== Sections === */
.section-divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, #27272a 50%, transparent);
  margin: 1.5rem 0;
  border: 0;
}

/* ============================================================== Tabs == */
.tab-bar {
  display: flex;
  gap: 0;
  border-bottom: 1px solid #27272a;
  padding: 0 0.5rem;
  overflow-x: auto;
  scrollbar-width: none;
}
.tab-bar::-webkit-scrollbar { display: none; }
.tab-trigger {
  padding: 0.625rem 0.875rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: #a1a1aa;
  border: none;
  background: transparent;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color 150ms, border-color 150ms;
  white-space: nowrap;
}
.tab-trigger:hover { color: #fafafa; }
.tab-trigger.active {
  color: #f59e0b;
  border-bottom-color: #f59e0b;
}

/* ============================================================ Modal === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  animation: modalFadeIn 150ms ease;
}
@keyframes modalFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.modal-panel {
  background: #18181b;
  border: 1px solid #27272a;
  border-radius: 0.5rem;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.9);
  max-width: 36rem;
  width: calc(100% - 2rem);
  max-height: 90vh;
  overflow-y: auto;
  animation: modalSlideIn 200ms ease;
}
@keyframes modalSlideIn {
  from { transform: translateY(8px); opacity: 0; }
  to   { transform: translateY(0);   opacity: 1; }
}
.modal-panel .modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid #27272a;
}
.modal-panel .modal-header h2 {
  font-size: 1.125rem;
  font-weight: 600;
  color: #fafafa;
}
.modal-panel .modal-body { padding: 1.5rem; }
.modal-panel .modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid #27272a;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* ============================================================ Toast === */
.toast-stack {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 9999;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: #18181b;
  border: 1px solid #27272a;
  border-left: 3px solid #f59e0b;
  border-radius: 0.375rem;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  color: #fafafa;
  min-width: 18rem;
  max-width: 24rem;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  animation: toastSlideIn 250ms ease;
}
.toast-success { border-left-color: #6ee7b7; }
.toast-error   { border-left-color: #fca5a5; }
.toast-info    { border-left-color: #93c5fd; }
@keyframes toastSlideIn {
  from { transform: translateX(120%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ======================================================= Empty state == */
.empty-state {
  padding: 3rem 1.5rem;
  text-align: center;
  color: #71717a;
}
.empty-state .empty-icon {
  font-size: 2.5rem;
  opacity: 0.4;
  margin-bottom: 0.75rem;
  display: block;
}
.empty-state .empty-title { color: #e4e4e7; font-weight: 500; }

/* ========================================================== Skeleton == */
.skeleton {
  background: linear-gradient(90deg, #27272a 0%, #3f3f46 50%, #27272a 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: 0.25rem;
  height: 1rem;
  display: block;
}
@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* =========================================================== Tables == */
.table-modern {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.875rem;
}
.table-modern thead th {
  background: #09090b;
  color: #a1a1aa;
  text-align: left;
  padding: 0.625rem 1rem;
  font-weight: 500;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid #27272a;
  position: sticky;
  top: 0;
  z-index: 1;
}
.table-modern tbody td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #1f1f23;
  color: #e4e4e7;
  vertical-align: middle;
}
.table-modern tbody tr {
  transition: background 75ms ease;
}
.table-modern tbody tr:hover { background: rgba(255, 255, 255, 0.025); }
.table-modern tbody tr:last-child td { border-bottom: none; }
.table-modern tbody tr.clickable { cursor: pointer; }

/* =========================================================== Alerts == */
.alert {
  padding: 0.875rem 1rem;
  border-radius: 0.375rem;
  border: 1px solid;
  font-size: 0.875rem;
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
}
.alert-info    { background: #1e3a8a33; border-color: #1e40af; color: #dbeafe; }
.alert-warn    { background: #78350f33; border-color: #92400e; color: #fef3c7; }
.alert-error   { background: #7f1d1d33; border-color: #991b1b; color: #fee2e2; }
.alert-success { background: #064e3b33; border-color: #047857; color: #d1fae5; }

/* ===================================================== Typography == */
.heading-1 { font-size: 1.5rem; font-weight: 700; color: #fafafa; letter-spacing: -0.02em; }
.heading-2 { font-size: 1.125rem; font-weight: 600; color: #fafafa; letter-spacing: -0.01em; }
.heading-3 { font-size: 1rem; font-weight: 600; color: #fafafa; }
.text-muted { color: #a1a1aa; }
.text-subtle { color: #71717a; }
.mono { font-family: ui-monospace, 'SF Mono', Menlo, monospace; }

/* ======================================================= Utilities == */
.flex-row { display: flex; align-items: center; gap: 0.5rem; }
.flex-col { display: flex; flex-direction: column; gap: 0.5rem; }
.space-between { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }

/* ----- Backwards-compatible aliases for the existing CRM UI ----- */
.btn-secondary { /* matches the old tailwind `.btn-secondary` style if needed */
  background: #27272a; color: #fafafa; border: 1px solid #3f3f46;
}
