/**
 * MASTER CODEX FINANCIAL - CSS Layer
 * Marlowe Partners UX Enhancement System
 * 
 * All classes namespaced with .cdx- for strict isolation
 * Mobile-first with iOS/Safari optimizations
 */

/* ============================================
   PART 1: BASE RESETS & MOBILE OPTIMIZATIONS
   ============================================ */

/* Remove iOS tap highlight */
.cdx-interactive,
.cdx-btn,
.cdx-link,
.cdx-fab,
[class*="cdx-"] button,
[class*="cdx-"] a {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  cursor: pointer;
}

/* Safe area handling for iPhone notch/home bar */
.cdx-safe-bottom {
  padding-bottom: env(safe-area-inset-bottom, 20px);
}

.cdx-safe-top {
  padding-top: env(safe-area-inset-top, 20px);
}

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

/* 51. Hover Lift */
.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);
}

/* 52. Active Press */
.cdx-press {
  transition: transform 0.1s ease;
}

.cdx-press:active {
  transform: scale(0.98);
}

/* 53. Focus Glow */
.cdx-focus-glow:focus,
.cdx-focus-glow:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.25);
}

/* Dark mode focus glow */
.dark .cdx-focus-glow:focus,
.dark .cdx-focus-glow:focus-visible {
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.4);
}

/* 54. Skeleton Animation */
.cdx-skeleton {
  background: linear-gradient(
    90deg,
    rgba(200, 200, 200, 0.2) 25%,
    rgba(200, 200, 200, 0.4) 50%,
    rgba(200, 200, 200, 0.2) 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; }
}

/* 55. Menu Slide */
.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;
}

/* 56. Cursor Hand - Force pointer on buttons */
.cdx-pointer,
button[class*="cdx-"],
[class*="cdx-"] button {
  cursor: pointer;
}

/* 57. Link Fade */
.cdx-link-fade {
  transition: color 0.2s ease, opacity 0.2s ease;
}

.cdx-link-fade:hover {
  opacity: 0.8;
}

/* 58. Sticky Header */
.cdx-sticky {
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(8px);
  background: rgba(255, 255, 255, 0.9);
}

.dark .cdx-sticky {
  background: rgba(17, 17, 17, 0.9);
}

/* 59. Toast Pop Animation */
.cdx-toast {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #1f1f1f;
  color: #fff;
  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;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.cdx-toast.cdx-show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* 60. Progress Bar (scroll-linked) */
.cdx-progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: linear-gradient(90deg, #FF9800, #F44336);
  z-index: 2147483647;
  transition: width 0.1s ease-out;
  width: 0%;
}

/* 61-63. Typography Hierarchy */
.cdx-typography {
  line-height: 1.6;
}

.cdx-typography h1 {
  font-size: 2.5rem;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 1rem;
}

.cdx-typography h2 {
  font-size: 2rem;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 0.875rem;
}

.cdx-typography h3 {
  font-size: 1.75rem;
  font-weight: 600;
  line-height: 1.35;
  margin-bottom: 0.75rem;
}

.cdx-typography p {
  max-width: 75ch;
}

/* 64-65. Contrast & System Fonts */
.cdx-contrast {
  color: #222;
  background: #fff;
}

.dark .cdx-contrast {
  color: #e5e7eb;
  background: #111;
}

.cdx-system-font {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}

/* 68. Link Style */
.cdx-link {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  transition: text-decoration-color 0.2s ease;
}

.cdx-link:hover {
  text-decoration-thickness: 2px;
}

/* 69. Whitespace Utilities */
.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; }

/* 76. Error Text */
.cdx-error-text {
  color: #ef4444;
  font-size: 0.75rem;
  margin-top: 4px;
}

/* 77. Button Primary */
.cdx-btn-primary {
  background: #1f1f1f;
  color: #fff;
  padding: 12px 24px;
  border-radius: 8px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease;
}

.cdx-btn-primary:hover {
  background: #333;
}

.cdx-btn-primary:active {
  transform: scale(0.98);
}

/* 78. Touch Target (iOS 44px minimum) */
.cdx-touch-target {
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* 79. Floating Label */
.cdx-float-label {
  position: relative;
}

.cdx-float-label input {
  padding: 20px 12px 8px;
  font-size: 16px;
}

.cdx-float-label label {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
  color: #666;
  pointer-events: none;
  transition: all 0.2s ease;
}

.cdx-float-label input:focus + label,
.cdx-float-label input:not(:placeholder-shown) + label {
  top: 8px;
  font-size: 12px;
  color: #FF9800;
}

/* 80. Breadcrumbs */
.cdx-breadcrumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: #666;
}

.cdx-breadcrumbs a {
  color: inherit;
  text-decoration: none;
  transition: color 0.2s ease;
}

.cdx-breadcrumbs a:hover {
  color: #FF9800;
}

.cdx-breadcrumbs .cdx-separator::after {
  content: '/';
  margin: 0 4px;
  opacity: 0.5;
}

/* 82. Visited Links */
.cdx-visited:visited {
  opacity: 0.7;
}

/* 83. Empty State */
.cdx-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
  color: #666;
}

.cdx-empty-state svg {
  width: 64px;
  height: 64px;
  margin-bottom: 16px;
  opacity: 0.5;
}

/* 86. Back to Top Button */
.cdx-back-top {
  position: fixed;
  bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  right: 20px;
  width: 44px;
  height: 44px;
  background: #1f1f1f;
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px);
  transition: all 0.3s ease;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.cdx-back-top.cdx-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.cdx-back-top:hover {
  background: #333;
  transform: translateY(-2px);
}

/* 89. Modal Backdrop */
.cdx-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 2147483646;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.cdx-modal-backdrop.cdx-open {
  opacity: 1;
  visibility: visible;
}

/* 91. Lazy Load Blur-up */
.cdx-lazy {
  filter: blur(10px);
  transition: filter 0.5s ease;
}

.cdx-lazy.cdx-loaded {
  filter: blur(0);
}

/* 92. Image Aspect Ratio */
.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;
}

/* 93. Alt Warning (Dev Mode) */
.cdx-alt-warn {
  outline: 3px solid #ef4444 !important;
  outline-offset: 2px;
}

/* 94. Tablet Media Queries */
@media (min-width: 768px) {
  .cdx-hide-tablet { display: none !important; }
  .cdx-show-tablet { display: block !important; }
}

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

/* 100. Selection Styling */
.cdx-selection::selection {
  background: rgba(255, 152, 0, 0.3);
  color: inherit;
}

.cdx-selection *::selection {
  background: rgba(255, 152, 0, 0.3);
  color: inherit;
}

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

/* 101. Velocity Type - Fast scroll header enhancement */
.cdx-velocity-header {
  transition: font-weight 0.3s ease;
}

.cdx-velocity-header.cdx-fast-scroll {
  font-weight: 800;
}

/* 102. Trajectory Glow */
.cdx-trajectory-glow {
  transition: box-shadow 0.15s ease;
}

.cdx-trajectory-glow.cdx-targeted {
  box-shadow: 0 0 20px rgba(255, 152, 0, 0.4);
}

/* 103. Magnet Cursor (Desktop) */
@media (hover: hover) {
  .cdx-magnet {
    transition: transform 0.15s ease;
  }
}

/* 106. Circadian Background */
.cdx-circadian {
  transition: filter 0.5s ease;
}

.cdx-circadian.cdx-warm {
  filter: sepia(0.1) saturate(1.1);
}

.cdx-circadian.cdx-night {
  filter: sepia(0.2) saturate(0.9) brightness(0.95);
}

/* 107. Focus Tunnel */
.cdx-focus-tunnel {
  transition: opacity 0.3s ease;
}

.cdx-focus-tunnel.cdx-dimmed {
  opacity: 0.3;
  pointer-events: none;
}

/* 110. Density Mode */
.cdx-density-compact {
  --cdx-spacer: 0.5rem;
}

.cdx-density-normal {
  --cdx-spacer: 1rem;
}

/* 111. Patina Effect */
.cdx-patina {
  transition: background 0.3s ease;
}

.cdx-patina[data-usage="high"] {
  background: rgba(255, 152, 0, 0.1);
}

/* 113. Wait Cursor */
.cdx-wait {
  cursor: progress !important;
}

/* 117. Changelog Badge */
.cdx-new-badge::after {
  content: 'NEW';
  position: absolute;
  top: -4px;
  right: -8px;
  background: #FF9800;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  text-transform: uppercase;
}

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

/* 128. Silent Badge */
.cdx-silent-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.cdx-silent-badge::before {
  content: '★';
  color: #FF9800;
}

/* 129. Peer Notes (Handwritten Font) */
.cdx-peer-notes {
  font-family: 'Caveat', 'Comic Sans MS', cursive;
  font-size: 1.1em;
  color: #666;
  transform: rotate(-1deg);
}

/* 131. Quiet Room Overlay */
.cdx-quiet-room {
  position: fixed;
  inset: 0;
  background: #f5f5dc;
  z-index: 2147483647;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

.cdx-quiet-room.cdx-active {
  opacity: 1;
  visibility: visible;
}

.cdx-quiet-room-content {
  max-width: 600px;
  text-align: center;
  font-size: 1.25rem;
  line-height: 1.8;
  color: #333;
}

/* 132. Disqualify Warning */
.cdx-disqualify {
  background: #fef3c7;
  border: 1px solid #f59e0b;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  font-size: 14px;
  color: #92400e;
}

/* 133. Dated Window */
.cdx-dated-window {
  position: relative;
}

.cdx-dated-window.cdx-closed::after {
  content: 'Window Closed';
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 600;
}

/* 134. Underwriting Mode */
.cdx-underwriting table,
.cdx-underwriting .highcharts-container,
.cdx-underwriting .recharts-wrapper,
.cdx-underwriting svg {
  filter: grayscale(1);
  font-family: 'Courier New', monospace !important;
}

/* 135. Legacy Font */
.cdx-legacy-font {
  font-family: 'Crimson Text', 'Times New Roman', serif;
}

/* 137. Privacy Banner */
.cdx-privacy-banner {
  background: #1f1f1f;
  color: #fff;
  padding: 12px 24px;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
}

/* 140. Patient Tag */
.cdx-patient-tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #666;
  font-style: italic;
}

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

/* Floating Action Button (FAB) */
.cdx-fab {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  left: 20px;
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, #FF9800, #F44336);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(255, 152, 0, 0.4);
  z-index: 1000;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.cdx-fab:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 24px rgba(255, 152, 0, 0.5);
}

.cdx-fab:active {
  transform: scale(0.95);
}

/* Command Palette */
.cdx-command-palette {
  position: fixed;
  top: 20%;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  width: 90%;
  max-width: 600px;
  background: #1f1f1f;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  z-index: 2147483647;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
}

.cdx-command-palette.cdx-open {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

.cdx-command-palette input {
  width: 100%;
  padding: 20px;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 18px;
  outline: none;
}

.cdx-command-palette input::placeholder {
  color: #666;
}

.cdx-command-results {
  max-height: 400px;
  overflow-y: auto;
  border-top: 1px solid #333;
}

.cdx-command-item {
  padding: 12px 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  color: #ccc;
  transition: background 0.15s ease;
}

.cdx-command-item:hover,
.cdx-command-item.cdx-selected {
  background: #333;
  color: #fff;
}

/* Night Shift Overlay */
.cdx-night-shift {
  position: fixed;
  inset: 0;
  background: rgba(255, 180, 100, 0.1);
  pointer-events: none;
  z-index: 2147483640;
  opacity: 0;
  transition: opacity 0.5s ease;
}

.cdx-night-shift.cdx-active {
  opacity: 1;
}

/* Zen Mode */
.cdx-zen-mode body > *:not(article):not(main):not(.cdx-zen-content) {
  display: none !important;
}

/* Confetti Canvas */
.cdx-confetti-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2147483647;
}

/* Feedback Widget */
.cdx-feedback {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: #f5f5f5;
  border-radius: 20px;
}

.dark .cdx-feedback {
  background: #2a2a2a;
}

.cdx-feedback button {
  padding: 8px;
  border-radius: 50%;
  transition: background 0.2s ease;
}

.cdx-feedback button:hover {
  background: rgba(0, 0, 0, 0.1);
}

/* Read Time Badge */
.cdx-read-time {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #666;
}

/* Copy Code Button */
.cdx-copy-code {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.cdx-copy-code:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Recent View Widget */
.cdx-recent-view {
  position: fixed;
  bottom: calc(90px + env(safe-area-inset-bottom, 0px));
  left: 20px;
  background: #1f1f1f;
  border-radius: 8px;
  padding: 12px;
  z-index: 999;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  max-width: 250px;
}

.cdx-recent-view-title {
  font-size: 11px;
  font-weight: 600;
  color: #666;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.cdx-recent-view-item {
  display: block;
  padding: 8px;
  color: #fff;
  text-decoration: none;
  font-size: 13px;
  border-radius: 4px;
  transition: background 0.2s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cdx-recent-view-item:hover {
  background: #333;
}

/* Greeter */
.cdx-greeter {
  font-size: 14px;
  color: #666;
  margin-bottom: 8px;
}

/* Print Styles */
@media print {
  .cdx-no-print,
  .cdx-fab,
  .cdx-back-top,
  .cdx-toast,
  .cdx-command-palette,
  nav,
  footer,
  .sidebar {
    display: none !important;
  }
  
  body {
    background: #fff !important;
    color: #000 !important;
  }
}
