/* ============================================================================
   App — global styles + primitives
   ============================================================================ */

html, body {
  background: var(--surface-0);
  color: var(--text-primary);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

.celebrate-william-img {
  width: 132px;
  height: 132px;
  object-fit: contain;
  filter: drop-shadow(0 22px 28px rgb(0 0 0 / 0.24));
  animation: celebrate-william-pop 0.72s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.celebrate-panel-large { max-width: 560px !important; }
.celebrate-panel-large .celebrate-william-img { width: 184px; height: 184px; }
.celebrate-panel-mega .celebrate-william-img { width: 210px; height: 210px; }
.celebrate-panel-mega { max-width: 620px !important; }
@keyframes celebrate-william-pop {
  0% { opacity: 0; transform: translateY(18px) scale(0.78) rotate(-4deg); }
  55% { opacity: 1; transform: translateY(-6px) scale(1.06) rotate(2deg); }
  100% { opacity: 1; transform: translateY(0) scale(1) rotate(0); }
}

*:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

/* ─── Scrollbar ───────────────────────────────────────────────────────── */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: var(--radius-full);
  border: 2px solid var(--surface-0);
}
*::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ─── Typography utilities ────────────────────────────────────────────── */
.font-display { font-family: var(--font-display); letter-spacing: -0.02em; }
.font-mono { font-family: var(--font-mono); }
.tabular-nums { font-variant-numeric: tabular-nums; }

/* ─── Surface helpers (map to CSS vars — use these over raw Tailwind) ──── */
.surface-1 { background: var(--surface-1); }
.surface-2 { background: var(--surface-2); }
.surface-3 { background: var(--surface-3); }

.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }

.border-subtle { border-color: var(--border-subtle); }
.border-default { border-color: var(--border-default); }

/* ─── Button primitive (ui/button.html uses these) ────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0.5rem 0.875rem;
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: 0.875rem;
  line-height: 1.25rem;
  transition: all var(--dur-fast) var(--ease-out);
  cursor: pointer;
  user-select: none;
  border: 1px solid transparent;
  white-space: nowrap;
}
.btn:disabled, .btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn:active:not(:disabled) { transform: scale(0.97); }

.btn-primary {
  background: var(--brand-600);
  color: #fff;
  box-shadow: 0 1px 2px rgb(79 70 229 / 0.2), inset 0 1px 0 rgb(255 255 255 / 0.08);
}
.btn-primary:hover:not(:disabled) { background: var(--brand-700); }

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

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text-primary);
}

.btn-danger {
  background: var(--danger-600);
  color: #fff;
}
.btn-danger:hover:not(:disabled) { background: var(--danger-700); }

.btn-success {
  background: var(--accent-600);
  color: #fff;
}
.btn-success:hover:not(:disabled) { background: var(--accent-700); }

.btn-sm { padding: 0.375rem 0.625rem; font-size: 0.8125rem; border-radius: var(--radius-sm); }
.btn-lg { padding: 0.625rem 1.125rem; font-size: 0.9375rem; border-radius: var(--radius-lg); }
.btn-icon { padding: 0.5rem; width: 2.25rem; height: 2.25rem; }
.btn-icon.btn-sm { padding: 0.375rem; width: 1.875rem; height: 1.875rem; }

/* ─── Card ──────────────────────────────────────────────────────────── */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}
.card-raised {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}
.card-flat {
  background: var(--surface-2);
  border-radius: var(--radius-lg);
}
.card-header {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.card-body { padding: var(--space-5); }
.card-footer {
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--border-subtle);
  background: var(--surface-2);
  border-bottom-left-radius: var(--radius-lg);
  border-bottom-right-radius: var(--radius-lg);
}

/* ─── Badge ─────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.5rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1rem;
  white-space: nowrap;
}
.badge-dot::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: currentColor;
  flex-shrink: 0;
}
.badge-gray { background: var(--gray-100); color: var(--gray-700); }
.badge-brand { background: var(--brand-50); color: var(--brand-700); }
.badge-accent { background: var(--accent-50); color: var(--accent-700); }
.badge-warn { background: var(--warn-50); color: var(--warn-700); }
.badge-danger { background: var(--danger-50); color: var(--danger-700); }
.badge-info { background: var(--info-50); color: var(--info-600); }

[data-theme="dark"] .badge-gray { background: var(--gray-200); color: var(--gray-700); }
[data-theme="dark"] .badge-brand { background: rgb(99 102 241 / 0.15); color: var(--brand-300); }
[data-theme="dark"] .badge-accent { background: rgb(16 185 129 / 0.15); color: var(--accent-300); }
[data-theme="dark"] .badge-warn { background: rgb(245 158 11 / 0.15); color: #fcd34d; }
[data-theme="dark"] .badge-danger { background: rgb(239 68 68 / 0.15); color: #fca5a5; }
[data-theme="dark"] .badge-info { background: rgb(59 130 246 / 0.15); color: #93c5fd; }

/* Mortgage coin reward pill — used on unread coaching / transcript / scorecard tabs. */
.coin-icon {
  width: 22px;
  height: 22px;
  object-fit: contain;
  flex-shrink: 0;
  filter: drop-shadow(0 2px 3px rgb(120 53 15 / 0.22));
}
.coin-icon-sm { width: 16px; height: 16px; }
.coin-icon-xs { width: 13px; height: 13px; }
.coin-icon-lg { width: 34px; height: 34px; }

.xp-reward-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 7px 1px 4px;
  border-radius: 999px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.02em;
  background: linear-gradient(135deg, #fef3c7, #fbbf24 45%, #f59e0b);
  color: #78350f;
  box-shadow: 0 1px 2px rgb(251 191 36 / 0.45), inset 0 0 0 1px rgb(255 255 255 / 0.35);
  text-shadow: 0 1px 0 rgb(255 255 255 / 0.25);
  white-space: nowrap;
}
.xp-reward-pill::before {
  content: "";
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: url("../img/coins/01_william_coin_happy_gold.a4fa9a00829c.png") center / contain no-repeat;
  filter: drop-shadow(0 1px 1px rgb(120 53 15 / 0.28));
}
[data-theme="dark"] .xp-reward-pill {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #fffbeb;
  box-shadow: 0 1px 3px rgb(245 158 11 / 0.55), inset 0 0 0 1px rgb(255 255 255 / 0.18);
}

/* Stage-specific colored pills (used in kanban, contact detail) */
.stage-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.625rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
}
.stage-pill::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: rgb(255 255 255 / 0.75);
}
.stage-new_lead { background: var(--stage-new_lead); }
.stage-contacted { background: var(--stage-contacted); }
.stage-warm { background: var(--stage-warm); }
.stage-nurturing { background: var(--stage-nurturing); }
.stage-meeting_set { background: var(--stage-meeting_set); }
.stage-active_partner { background: var(--stage-active_partner); }
.stage-freezer { background: var(--stage-freezer); }
.stage-lost { background: var(--stage-lost); }

/* ─── Input ─────────────────────────────────────────────────────────── */
.input,
.textarea,
.select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--surface-1);
  color: var(--text-primary);
  font-size: 0.875rem;
  line-height: 1.25rem;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.input:hover, .textarea:hover, .select:hover { border-color: var(--border-strong); }
.input:focus, .textarea:focus, .select:focus {
  border-color: var(--brand-500);
  outline: none;
  box-shadow: var(--focus-ring);
}
.input::placeholder, .textarea::placeholder { color: var(--text-tertiary); }

.input-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.375rem;
}

.input-help {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  margin-top: 0.25rem;
}

.input-error {
  font-size: 0.75rem;
  color: var(--danger-600);
  margin-top: 0.25rem;
}

/* ─── Avatar ────────────────────────────────────────────────────────── */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  background: var(--brand-100);
  color: var(--brand-700);
  font-weight: 600;
  overflow: hidden;
  flex-shrink: 0;
  user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-xs { width: 1.25rem; height: 1.25rem; font-size: 0.625rem; }
.avatar-sm { width: 1.75rem; height: 1.75rem; font-size: 0.75rem; }
.avatar-md { width: 2.25rem; height: 2.25rem; font-size: 0.8125rem; }
.avatar-lg { width: 3rem; height: 3rem; font-size: 1rem; }
.avatar-xl { width: 4rem; height: 4rem; font-size: 1.25rem; }

[data-theme="dark"] .avatar { background: rgb(99 102 241 / 0.2); color: var(--brand-300); }

/* ─── Toast ─────────────────────────────────────────────────────────── */
.toast-host {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-lg);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  min-width: 280px;
  max-width: 380px;
  font-size: 0.875rem;
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
}

/* ─── Modal ─────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgb(15 23 42 / 0.6);
  backdrop-filter: blur(4px);
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}
.modal-panel {
  background: var(--surface-1);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-2xl);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow: auto;
  border: 1px solid var(--border-subtle);
}

/* ─── Tooltip ───────────────────────────────────────────────────────── */
.tooltip {
  position: absolute;
  background: var(--gray-900);
  color: #fff;
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  pointer-events: none;
  z-index: var(--z-tooltip);
  white-space: nowrap;
}
[data-theme="dark"] .tooltip { background: var(--gray-300); color: var(--gray-900); }

/* ─── KBD ───────────────────────────────────────────────────────────── */
.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  height: 1.25rem;
  padding: 0 0.375rem;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--surface-2);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  box-shadow: 0 1px 0 var(--border-default);
  line-height: 1;
}

/* ─── Skeleton ──────────────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
}
@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ─── Divider ───────────────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--border-subtle);
  border: none;
  margin: var(--space-4) 0;
}

/* ─── Animations ────────────────────────────────────────────────────── */
@keyframes fade-in { from { opacity: 0 } to { opacity: 1 } }
@keyframes slide-up { from { opacity: 0; transform: translateY(8px) } to { opacity: 1; transform: translateY(0) } }
@keyframes slide-down { from { opacity: 0; transform: translateY(-8px) } to { opacity: 1; transform: translateY(0) } }
@keyframes scale-in { from { opacity: 0; transform: scale(0.95) } to { opacity: 1; transform: scale(1) } }
@keyframes pulse-soft { 0%, 100% { opacity: 1 } 50% { opacity: 0.6 } }

.anim-fade-in { animation: fade-in var(--dur-base) var(--ease-out) both; }
.anim-slide-up { animation: slide-up var(--dur-base) var(--ease-out) both; }
.anim-slide-down { animation: slide-down var(--dur-base) var(--ease-out) both; }
.anim-scale-in { animation: scale-in var(--dur-base) var(--ease-spring) both; }
.anim-pulse-soft { animation: pulse-soft 2s ease-in-out infinite; }

/* ─── Empty state ───────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--space-12) var(--space-6);
  color: var(--text-tertiary);
}
.empty-state-icon {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-4);
  color: var(--text-secondary);
  font-size: 1.5rem;
}
.empty-state-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-1);
}
.empty-state-desc {
  font-size: 0.875rem;
  color: var(--text-secondary);
  max-width: 320px;
  margin-bottom: var(--space-4);
}

/* ─── Dark-mode overrides for Tailwind tint utilities used in contacts list,
       kanban, task list, etc. These classes come from Tailwind CDN and don't
       honor --data-theme="dark" on their own. We tone them so selects + pills
       stay legible on dark surfaces. ───────────────────────────────────── */
[data-theme="dark"] .bg-white { background-color: var(--surface-1) !important; }
[data-theme="dark"] .bg-gray-50,
[data-theme="dark"] .bg-slate-50 { background-color: var(--surface-2) !important; }
[data-theme="dark"] .bg-gray-100,
[data-theme="dark"] .bg-slate-100 { background-color: var(--surface-3) !important; }
[data-theme="dark"] .bg-gray-200 { background-color: var(--surface-3) !important; }

[data-theme="dark"] .text-gray-900,
[data-theme="dark"] .text-slate-900 { color: var(--text-primary) !important; }
[data-theme="dark"] .text-gray-800 { color: var(--text-primary) !important; }
[data-theme="dark"] .text-gray-700 { color: var(--text-secondary) !important; }
[data-theme="dark"] .text-gray-600 { color: var(--text-secondary) !important; }
[data-theme="dark"] .text-gray-500 { color: var(--text-tertiary) !important; }
[data-theme="dark"] .text-gray-400 { color: var(--text-tertiary) !important; }
[data-theme="dark"] .text-gray-300 { color: var(--text-disabled) !important; }

[data-theme="dark"] .border-gray-100,
[data-theme="dark"] .border-gray-200 { border-color: var(--border-subtle) !important; }
[data-theme="dark"] .border-gray-300 { border-color: var(--border-default) !important; }

/* Coloured tint utilities (stage / call-status pills) */
[data-theme="dark"] .bg-yellow-50,
[data-theme="dark"] .bg-yellow-100,
[data-theme="dark"] .bg-amber-50,
[data-theme="dark"] .bg-amber-100 { background-color: color-mix(in srgb, #f59e0b 22%, var(--surface-2)) !important; }
[data-theme="dark"] .text-yellow-700,
[data-theme="dark"] .text-yellow-800,
[data-theme="dark"] .text-amber-700,
[data-theme="dark"] .text-amber-800 { color: #fcd34d !important; }

[data-theme="dark"] .bg-green-50,
[data-theme="dark"] .bg-green-100,
[data-theme="dark"] .bg-emerald-50,
[data-theme="dark"] .bg-emerald-100 { background-color: color-mix(in srgb, #10b981 22%, var(--surface-2)) !important; }
[data-theme="dark"] .text-green-700,
[data-theme="dark"] .text-green-800,
[data-theme="dark"] .text-emerald-700,
[data-theme="dark"] .text-emerald-800 { color: #6ee7b7 !important; }

[data-theme="dark"] .bg-red-50,
[data-theme="dark"] .bg-red-100 { background-color: color-mix(in srgb, #ef4444 22%, var(--surface-2)) !important; }
[data-theme="dark"] .text-red-600,
[data-theme="dark"] .text-red-700,
[data-theme="dark"] .text-red-800 { color: #fca5a5 !important; }

[data-theme="dark"] .bg-blue-50,
[data-theme="dark"] .bg-blue-100 { background-color: color-mix(in srgb, #3b82f6 22%, var(--surface-2)) !important; }
[data-theme="dark"] .text-blue-700,
[data-theme="dark"] .text-blue-800 { color: #93c5fd !important; }

[data-theme="dark"] .bg-indigo-50,
[data-theme="dark"] .bg-indigo-100,
[data-theme="dark"] .bg-purple-50,
[data-theme="dark"] .bg-purple-100 { background-color: color-mix(in srgb, #6366f1 22%, var(--surface-2)) !important; }
[data-theme="dark"] .text-indigo-600,
[data-theme="dark"] .text-indigo-700,
[data-theme="dark"] .text-indigo-800,
[data-theme="dark"] .text-purple-700 { color: #a5b4fc !important; }

[data-theme="dark"] .bg-orange-50,
[data-theme="dark"] .bg-orange-100 { background-color: color-mix(in srgb, #f97316 22%, var(--surface-2)) !important; }
[data-theme="dark"] .text-orange-700,
[data-theme="dark"] .text-orange-800 { color: #fdba74 !important; }

[data-theme="dark"] .bg-teal-50,
[data-theme="dark"] .bg-teal-100,
[data-theme="dark"] .bg-cyan-50,
[data-theme="dark"] .bg-cyan-100 { background-color: color-mix(in srgb, #14b8a6 22%, var(--surface-2)) !important; }
[data-theme="dark"] .text-teal-700,
[data-theme="dark"] .text-teal-800,
[data-theme="dark"] .text-cyan-700 { color: #5eead4 !important; }

/* Kanban stage column light backgrounds (hex hard-coded in kanban.html) */
[data-theme="dark"] [class*="stage-col-"] { background: color-mix(in srgb, var(--surface-2) 94%, transparent) !important; }

/* Row hover brightness-95 becomes darker surface shift in dark mode */
[data-theme="dark"] tr.hover\:brightness-95:hover { filter: brightness(1.15); }

/* Stage-row tints (e.g. `.stage-row-warm { background:#fffdf5; }`) must
   neutralize in dark. */
[data-theme="dark"] [class*="stage-row-"] { background: transparent !important; }

/* Select dropdowns inherit dark surface so text stays legible */
[data-theme="dark"] select.stage-select,
[data-theme="dark"] select.cs-select { background-color: transparent !important; color: inherit !important; }
[data-theme="dark"] select option { background-color: var(--surface-1); color: var(--text-primary); }

/* Review Mode: ensure buttons/stats keep decent contrast */
[data-theme="dark"] kbd {
  background: var(--surface-3); color: var(--text-secondary);
  padding: 1px 6px; border-radius: 4px; font-family: var(--font-mono); font-size: 0.6875rem;
  border: 1px solid var(--border-subtle);
}
kbd {
  background: var(--surface-3); color: var(--text-secondary);
  padding: 1px 6px; border-radius: 4px; font-family: var(--font-mono); font-size: 0.6875rem;
  border: 1px solid var(--border-subtle);
}

/* Stage-pill dark-mode: keep colored but add subtle outline for contrast */
[data-theme="dark"] .stage-pill {
  box-shadow: 0 0 0 1px color-mix(in srgb, currentColor 30%, transparent);
}

/* Contact list row: swap tailwind border-b border-gray-100 subtle in dark */
[data-theme="dark"] tr.stage-row-new_lead,
[data-theme="dark"] tr.stage-row-contacted,
[data-theme="dark"] tr.stage-row-warm,
[data-theme="dark"] tr.stage-row-nurturing,
[data-theme="dark"] tr.stage-row-meeting_set,
[data-theme="dark"] tr.stage-row-active_partner,
[data-theme="dark"] tr.stage-row-freezer,
[data-theme="dark"] tr.stage-row-lost {
  background: transparent;
  border-bottom-color: var(--border-subtle);
}

/* ─── Hover-lift for cards + rows ───────────────────────────────────── */
.kanban-card {
  transition: transform var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out), background-color var(--dur-fast);
  will-change: transform;
}
.kanban-card:hover { transform: translateY(-1px); }

tr[data-contact-id] {
  transition: transform var(--dur-fast) var(--ease-out), background-color var(--dur-fast);
}

/* ─── Activity-column freshness dots ────────────────────────────────── */
.freshness {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-tertiary);
}
.freshness::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--text-tertiary);
}
.freshness--hot::before { background: var(--accent-500); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-500) 20%, transparent); }
.freshness--hot { color: var(--accent-600); }
.freshness--warm::before { background: var(--warn-500); }
.freshness--warm { color: var(--warn-700); }
.freshness--cold::before { background: var(--text-tertiary); }
