/**
 * MASTER CODEX FINANCIAL - CSS LAYER
 * Marlowe Partners Influence & UX Layer
 * 140 Micro-Interactions Implementation
 * 
 * All classes namespaced with .cdx- for strict isolation
 * Mobile-first with iOS/Safari focus
 */

/* ==========================================================================
   PART 1: EFFICIENCY LAYER - Base Styles
   ========================================================================== */

:root {
  --cdx-primary: #E07A3A;
  --cdx-primary-dark: #C4652E;
  --cdx-text: #222222;
  --cdx-text-muted: #666666;
  --cdx-bg: #FFFFFF;
  --cdx-bg-warm: #FDF8F3;
  --cdx-bg-dark: #1A1A1A;
  --cdx-border: #E5E5E5;
  --cdx-success: #10B981;
  --cdx-error: #EF4444;
  --cdx-warning: #F59E0B;
  --cdx-spacer: 1rem;
  --cdx-font-size: 16px;
  --cdx-safe-bottom: env(safe-area-inset-bottom, 0px);
  --cdx-safe-top: env(safe-area-inset-top, 0px);
}

.cdx-dark {
  --cdx-text: #F5F5F5;
  --cdx-text-muted: #A0A0A0;
  --cdx-bg: #1A1A1A;
  --cdx-bg-warm: #252525;
  --cdx-border: #333333;
}

.cdx-interactive {
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
  touch-action: manipulation;
}

/* ==========================================================================
   PART 2: POLISH LAYER (51-100)
   ========================================================================== */

.cdx-lift { transition: transform 0.2s ease, box-shadow 0.2s ease; }
.cdx-lift:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); }

.cdx-press { transition: transform 0.1s ease; }
.cdx-press:active { transform: scale(0.98); }

.cdx-focus-glow:focus, .cdx-focus-glow:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(224, 122, 58, 0.35);
}

.cdx-skeleton {
  background: linear-gradient(90deg, var(--cdx-border) 25%, #F0F0F0 50%, var(--cdx-border) 75%);
  background-size: 200% 100%;
  animation: cdx-shimmer 1.5s infinite;
  border-radius: 4px;
}

@keyframes cdx-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.cdx-menu-slide {
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}
.cdx-menu-slide.cdx-open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.cdx-btn, button, [role="button"], a[href], input[type="submit"], input[type="button"] {
  cursor: pointer;
}

.cdx-link { transition: color 0.2s ease, opacity 0.2s ease; }
.cdx-link:hover { opacity: 0.8; }

.cdx-sticky { position: sticky; top: 0; z-index: 100; background: var(--cdx-bg); }

.cdx-toast {
  position: fixed;
  bottom: calc(20px + var(--cdx-safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--cdx-text);
  color: var(--cdx-bg);
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  z-index: 2147483647;
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  max-width: calc(100vw - 40px);
  text-align: center;
}
.cdx-toast.cdx-show { transform: translateX(-50%) translateY(0); opacity: 1; }
.cdx-toast.cdx-success { background: var(--cdx-success); }
.cdx-toast.cdx-error { background: var(--cdx-error); }

.cdx-progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: var(--cdx-primary);
  z-index: 2147483647;
  width: 0%;
  transition: width 0.1s linear;
}

.cdx-readable { line-height: 1.6; }
.cdx-prose { max-width: 75ch; margin-left: auto; margin-right: auto; }

.cdx-h1 { font-size: 2.5rem; font-weight: 700; line-height: 1.2; margin-bottom: 1rem; }
.cdx-h2 { font-size: 2rem; font-weight: 600; line-height: 1.3; margin-bottom: 0.875rem; }
.cdx-h3 { font-size: 1.75rem; font-weight: 600; line-height: 1.4; margin-bottom: 0.75rem; }

.cdx-high-contrast { color: var(--cdx-text); background: var(--cdx-bg); }

.cdx-system-font {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.cdx-link-styled {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}
.cdx-link-styled:hover { text-decoration-thickness: 2px; }

.cdx-mb-1 { margin-bottom: 0.25rem; }
.cdx-mb-2 { margin-bottom: 0.5rem; }
.cdx-mb-3 { margin-bottom: 1rem; }
.cdx-mb-4 { margin-bottom: 1.5rem; }
.cdx-mb-5 { margin-bottom: 2rem; }

.cdx-error-text { color: var(--cdx-error); font-size: 0.875rem; margin-top: 0.25rem; }

.cdx-btn-primary {
  background: var(--cdx-text);
  color: var(--cdx-bg);
  border: none;
  padding: 12px 24px;
  border-radius: 6px;
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.cdx-btn-primary:hover { background: #333333; }
.cdx-btn-primary:active { transform: scale(0.98); }

.cdx-touch-target { min-height: 44px; min-width: 44px; display: inline-flex; align-items: center; justify-content: center; }

.cdx-float-label { position: relative; }
.cdx-float-label input, .cdx-float-label textarea {
  padding: 20px 12px 8px;
  width: 100%;
  border: 1px solid var(--cdx-border);
  border-radius: 6px;
  font-size: 16px;
  background: var(--cdx-bg);
  transition: border-color 0.2s ease;
}
.cdx-float-label label {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
  color: var(--cdx-text-muted);
  pointer-events: none;
  transition: all 0.2s ease;
}
.cdx-float-label input:focus + label, .cdx-float-label input:not(:placeholder-shown) + label {
  top: 8px;
  transform: translateY(0);
  font-size: 12px;
  color: var(--cdx-primary);
}
.cdx-float-label input:focus { outline: none; border-color: var(--cdx-primary); }

.cdx-breadcrumbs { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--cdx-text-muted); }
.cdx-breadcrumbs a { color: var(--cdx-text-muted); text-decoration: none; transition: color 0.2s ease; }
.cdx-breadcrumbs a:hover { color: var(--cdx-primary); }
.cdx-breadcrumbs .cdx-current { color: var(--cdx-text); font-weight: 500; }

.cdx-visited:visited { color: #6B5B95; opacity: 0.85; }

.cdx-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
  color: var(--cdx-text-muted);
}

.cdx-back-top {
  position: fixed;
  bottom: calc(80px + var(--cdx-safe-bottom));
  right: 20px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--cdx-primary);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
.cdx-back-top.cdx-visible { opacity: 1; transform: translateY(0); }
.cdx-back-top:hover { background: var(--cdx-primary-dark); }

.cdx-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 2147483646;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}
.cdx-modal-backdrop.cdx-open { opacity: 1; pointer-events: auto; }

.cdx-lazy { filter: blur(10px); transition: filter 0.5s ease; }
.cdx-lazy.cdx-loaded { filter: blur(0); }

.cdx-aspect-16-9 { aspect-ratio: 16 / 9; object-fit: cover; }
.cdx-aspect-4-3 { aspect-ratio: 4 / 3; object-fit: cover; }
.cdx-aspect-1-1 { aspect-ratio: 1 / 1; object-fit: cover; }

.cdx-alt-warn { outline: 3px solid var(--cdx-error) !important; outline-offset: 2px; }

@media (min-width: 768px) { .cdx-hide-tablet { display: none !important; } }
@media (max-width: 767px) { .cdx-hide-mobile { display: none !important; } }

.cdx-fast-tap { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

.cdx-external-link::after { content: " ↗"; font-size: 0.8em; opacity: 0.7; }

::selection { background: var(--cdx-primary); color: white; }

/* ==========================================================================
   PART 3: ANTICIPATORY LAYER (101-120)
   ========================================================================== */

.cdx-velocity-bold h1, .cdx-velocity-bold h2, .cdx-velocity-bold h3 { font-weight: 800 !important; }

.cdx-trajectory-glow { box-shadow: 0 0 20px rgba(224, 122, 58, 0.4); }

@media (hover: hover) and (pointer: fine) {
  .cdx-magnet { transition: transform 0.15s ease-out; }
}

.cdx-circadian-morning { background: linear-gradient(135deg, #FFF8F0 0%, #FFFFFF 100%); }
.cdx-circadian-day { background: var(--cdx-bg); }
.cdx-circadian-evening { background: linear-gradient(135deg, #FFF5E6 0%, #FDF8F3 100%); }
.cdx-circadian-night { background: linear-gradient(135deg, #1A1A2E 0%, #16213E 100%); color: #F5F5F5; }

.cdx-focus-tunnel *:not(:focus):not(:focus-within) { opacity: 0.3; transition: opacity 0.3s ease; }
.cdx-focus-tunnel *:focus, .cdx-focus-tunnel *:focus-within { opacity: 1; }

.cdx-compact { --cdx-spacer: 0.5rem; }
.cdx-compact .cdx-mb-3 { margin-bottom: 0.5rem; }
.cdx-compact .cdx-mb-4 { margin-bottom: 0.75rem; }

.cdx-patina-1 { filter: brightness(0.98); }
.cdx-patina-2 { filter: brightness(0.96); }
.cdx-patina-3 { filter: brightness(0.94); }
.cdx-patina-4 { filter: brightness(0.92); }
.cdx-patina-5 { filter: brightness(0.90); }

.cdx-wait { cursor: wait !important; }
.cdx-wait * { cursor: wait !important; }

.cdx-new-badge { position: relative; }
.cdx-new-badge::after {
  content: "NEW";
  position: absolute;
  top: -8px;
  right: -8px;
  background: var(--cdx-primary);
  color: white;
  font-size: 9px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  letter-spacing: 0.5px;
}

/* ==========================================================================
   PART 4: PSYCHOLOGICAL CODEX (121-140)
   ========================================================================== */

.cdx-long-duration .cdx-noise { filter: blur(4px); opacity: 0.5; pointer-events: none; }

.cdx-gated-content { filter: blur(8px); pointer-events: none; user-select: none; }
.cdx-gated-content.cdx-unlocked { filter: none; pointer-events: auto; user-select: auto; }

.cdx-silent-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(224, 122, 58, 0.1);
  color: var(--cdx-primary);
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.cdx-peer-note {
  font-family: "Caveat", "Comic Sans MS", cursive;
  font-size: 1.1em;
  color: #6B5B95;
  background: linear-gradient(transparent 60%, rgba(255, 255, 0, 0.3) 60%);
  padding: 0 4px;
  margin-left: 8px;
}

.cdx-empty-chair { font-size: 12px; color: var(--cdx-text-muted); font-style: italic; }

.cdx-quiet-room {
  position: fixed;
  inset: 0;
  background: #F5F0E8;
  z-index: 2147483647;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}
.cdx-quiet-room.cdx-active { opacity: 1; pointer-events: auto; }
.cdx-quiet-room-content {
  max-width: 600px;
  text-align: center;
  font-family: "Crimson Text", Georgia, serif;
  font-size: 1.5rem;
  line-height: 1.8;
  color: #333;
}
.cdx-quiet-room-close {
  position: absolute;
  top: 20px;
  right: 20px;
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: #666;
}

.cdx-disqualify {
  background: rgba(239, 68, 68, 0.05);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}
.cdx-disqualify-title { font-weight: 600; color: var(--cdx-error); margin-bottom: 8px; }
.cdx-disqualify-text { font-size: 14px; color: var(--cdx-text-muted); }

.cdx-window-closed {
  background: var(--cdx-border);
  color: var(--cdx-text-muted);
  padding: 24px;
  border-radius: 8px;
  text-align: center;
}
.cdx-window-closed-title { font-size: 1.25rem; font-weight: 600; margin-bottom: 8px; }

.cdx-underwriting table, .cdx-underwriting .highcharts-container, .cdx-underwriting .recharts-wrapper, .cdx-underwriting svg:not(.cdx-icon) {
  filter: grayscale(100%);
  font-family: "SF Mono", "Monaco", "Inconsolata", "Fira Mono", monospace !important;
}
.cdx-underwriting table { border-collapse: collapse; }
.cdx-underwriting table td, .cdx-underwriting table th {
  border: 1px solid #333;
  padding: 8px;
  font-family: "SF Mono", "Monaco", "Inconsolata", "Fira Mono", monospace !important;
}

.cdx-legacy-font { font-family: "Crimson Text", Georgia, "Times New Roman", serif; }

.cdx-privacy-banner {
  background: var(--cdx-bg-warm);
  border-top: 1px solid var(--cdx-border);
  padding: 12px 20px;
  text-align: center;
  font-size: 13px;
  color: var(--cdx-text-muted);
}
.cdx-privacy-banner strong { color: var(--cdx-text); }

.cdx-pacing-tooltip {
  position: fixed;
  bottom: calc(100px + var(--cdx-safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 1000;
  pointer-events: none;
}
.cdx-pacing-tooltip.cdx-show { opacity: 1; transform: translateX(-50%) translateY(0); }

.cdx-patient-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--cdx-text-muted);
  font-size: 12px;
  font-style: italic;
}
.cdx-patient-tag::before { content: "∞"; font-style: normal; font-size: 16px; }

/* ==========================================================================
   SPECIAL COMPONENTS
   ========================================================================== */

.cdx-fab {
  position: fixed;
  bottom: calc(20px + var(--cdx-safe-bottom));
  left: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--cdx-primary);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(224, 122, 58, 0.4);
  z-index: 1000;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.cdx-fab:hover { transform: scale(1.05); box-shadow: 0 6px 20px rgba(224, 122, 58, 0.5); }
.cdx-fab:active { transform: scale(0.95); }

.cdx-command-menu {
  position: fixed;
  bottom: calc(90px + var(--cdx-safe-bottom));
  left: 20px;
  background: var(--cdx-bg);
  border: 1px solid var(--cdx-border);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  padding: 8px;
  min-width: 200px;
  z-index: 1001;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}
.cdx-command-menu.cdx-open { opacity: 1; transform: translateY(0); pointer-events: auto; }

.cdx-command-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease;
  font-size: 14px;
  color: var(--cdx-text);
}
.cdx-command-item:hover { background: rgba(224, 122, 58, 0.1); }

.cdx-palette {
  position: fixed;
  top: 20%;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  width: 90%;
  max-width: 500px;
  background: var(--cdx-bg);
  border: 1px solid var(--cdx-border);
  border-radius: 12px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.2);
  z-index: 2147483647;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.cdx-palette.cdx-open { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }

.cdx-palette-input {
  width: 100%;
  padding: 16px 20px;
  border: none;
  border-bottom: 1px solid var(--cdx-border);
  font-size: 16px;
  background: transparent;
  outline: none;
}

.cdx-palette-results { max-height: 300px; overflow-y: auto; padding: 8px; }

.cdx-night-shift {
  position: fixed;
  inset: 0;
  background: rgba(255, 180, 100, 0.15);
  pointer-events: none;
  z-index: 2147483640;
  mix-blend-mode: multiply;
}

.cdx-pulse { animation: cdx-pulse 1.5s ease-in-out infinite; }
@keyframes cdx-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

.cdx-read-time { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--cdx-text-muted); }
.cdx-read-time::before { content: "⏱"; }

.cdx-code-wrapper { position: relative; }
.cdx-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--cdx-border);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.cdx-code-wrapper:hover .cdx-copy-btn { opacity: 1; }

.cdx-welcome-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 10000; /* Reduced z-index to not block everything */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  -webkit-overflow-scrolling: touch;
}
.cdx-welcome-modal.cdx-show { opacity: 1; pointer-events: auto; }

.cdx-welcome-content {
  background: #FFFFFF; /* Explicit white, not CSS variable */
  border-radius: 16px;
  padding: 32px 24px;
  max-width: 450px;
  width: calc(100% - 40px);
  text-align: center;
  position: relative;
  max-height: calc(100vh - 100px);
  max-height: calc(100dvh - 100px); /* Dynamic viewport height for mobile */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.cdx-welcome-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 40px; /* Larger touch target */
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  border-radius: 50%;
  background: #f0f0f0; /* Explicit color */
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: #666666;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  z-index: 10;
}
.cdx-welcome-close:hover, .cdx-welcome-close:active { background: #e0e0e0; }
.cdx-welcome-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 16px; color: #222222; }
.cdx-welcome-text { color: #666666; margin-bottom: 24px; line-height: 1.6; font-size: 15px; }

@media (max-width: 480px) {
  .cdx-welcome-modal { padding: 16px; align-items: flex-start; padding-top: 60px; }
  .cdx-welcome-content { padding: 24px 20px; border-radius: 12px; max-height: calc(100dvh - 120px); }
  .cdx-welcome-title { font-size: 1.25rem; }
  .cdx-welcome-text { font-size: 14px; }
  .cdx-welcome-close { top: 8px; right: 8px; width: 44px; height: 44px; font-size: 22px; }
}

.cdx-exit-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 2147483647;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.cdx-exit-overlay.cdx-show { opacity: 1; pointer-events: auto; }

.cdx-exit-content {
  background: var(--cdx-bg);
  border-radius: 16px;
  padding: 40px;
  max-width: 400px;
  text-align: center;
  transform: scale(0.9);
  transition: transform 0.3s ease;
}
.cdx-exit-overlay.cdx-show .cdx-exit-content { transform: scale(1); }

.cdx-zen-mode > *:not(article):not(main):not(.cdx-zen-content) { display: none !important; }
.cdx-zen-mode article, .cdx-zen-mode main, .cdx-zen-mode .cdx-zen-content {
  max-width: 700px;
  margin: 0 auto;
  padding: 40px 20px;
}

@media print {
  .cdx-no-print, .cdx-fab, .cdx-back-top, .cdx-toast, .cdx-progress-bar, nav, footer, .cdx-command-menu, .cdx-palette {
    display: none !important;
  }
  body { background: white !important; color: black !important; }
  a { text-decoration: underline; }
  a[href]::after { content: " (" attr(href) ")"; font-size: 0.8em; color: #666; }
}
