/**
 * Master Codex Financial - CSS Layer
 * All 140 micro-interactions for Marlowe Partners
 * Mobile-First (iPhone/Safari Focus)
 * Namespace: .cdx-
 */

/* ==========================================================================
   PART 1: iOS/SAFARI FOUNDATION
   ========================================================================== */

/* Remove grey tap highlight on iOS */
* {
  -webkit-tap-highlight-color: transparent;
}

/* Force pointer cursor on all interactive elements (required for iOS click events) */
button,
[role="button"],
a,
input[type="submit"],
input[type="button"],
.cdx-clickable {
  cursor: pointer;
}

/* Fast tap - prevent double-tap zoom delay */
.cdx-fast-tap,
button,
a,
input,
select,
textarea {
  touch-action: manipulation;
}

/* Safe area insets 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 - CSS STYLES (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,
input:focus,
select:focus,
textarea:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(234, 88, 12, 0.25);
}

/* 54. Skeleton Animation - Gradient shimmer */
.cdx-skeleton {
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.05) 25%,
    rgba(255, 255, 255, 0.1) 50%,
    rgba(255, 255, 255, 0.05) 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 - Dropdown transitions */
.cdx-dropdown {
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}
.cdx-dropdown.cdx-open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* 56. Cursor Hand - Force pointer on buttons */
.cdx-btn,
button {
  cursor: pointer;
}

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

/* 58. Sticky Head */
.cdx-sticky {
  position: sticky;
  top: 0;
  z-index: 100;
  background: inherit;
}

/* 59. Toast Pop - Slide-up animation */
.cdx-toast {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #1a1a1a;
  color: #fff;
  padding: 12px 24px;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  z-index: 2147483647;
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  font-size: 14px;
  max-width: 90vw;
}
.cdx-toast.cdx-show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
.cdx-toast.cdx-success {
  border-left: 4px solid #22c55e;
}
.cdx-toast.cdx-error {
  border-left: 4px solid #ef4444;
}
.cdx-toast.cdx-warning {
  border-left: 4px solid #f59e0b;
}

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

/* 61. Line Height - Global 1.6 */
.cdx-readable {
  line-height: 1.6;
}

/* 62. Line Width - Max 75ch */
.cdx-prose {
  max-width: 75ch;
  margin-left: auto;
  margin-right: auto;
}

/* 63. Hierarchy - H1/H2/H3 sizing */
.cdx-h1 { font-size: 2.5rem; font-weight: 700; line-height: 1.2; }
.cdx-h2 { font-size: 2rem; font-weight: 600; line-height: 1.3; }
.cdx-h3 { font-size: 1.75rem; font-weight: 600; line-height: 1.4; }
.cdx-h4 { font-size: 1.5rem; font-weight: 500; line-height: 1.4; }

/* 64. Contrast - Text and background */
.cdx-contrast-light {
  color: #222;
  background: #fff;
}
.cdx-contrast-dark {
  color: #f5f5f5;
  background: #0a0a0a;
}

/* 65. System Fonts */
.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-styled {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 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; }
.cdx-mt-1 { margin-top: 0.25rem; }
.cdx-mt-2 { margin-top: 0.5rem; }
.cdx-mt-3 { margin-top: 1rem; }
.cdx-mt-4 { margin-top: 1.5rem; }
.cdx-mt-5 { margin-top: 2rem; }

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

/* 77. Btn Primary */
.cdx-btn-primary {
  background: #1a1a1a;
  color: #fff;
  border: none;
  padding: 12px 24px;
  border-radius: 6px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s ease;
  min-height: 44px;
  touch-action: manipulation;
}
.cdx-btn-primary:hover {
  background: #333;
}
.cdx-btn-primary:active {
  transform: scale(0.98);
}

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

/* 79. Label Float - Floating label pattern */
.cdx-float-label {
  position: relative;
}
.cdx-float-label input,
.cdx-float-label textarea {
  padding-top: 20px;
}
.cdx-float-label label {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  transition: all 0.2s ease;
  pointer-events: none;
  color: #888;
  font-size: 14px;
}
.cdx-float-label input:focus + label,
.cdx-float-label input:not(:placeholder-shown) + label,
.cdx-float-label textarea:focus + label,
.cdx-float-label textarea:not(:placeholder-shown) + label {
  top: 8px;
  font-size: 11px;
  color: #ea580c;
  transform: translateY(0);
}

/* 80. Breadcrumbs */
.cdx-breadcrumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #888;
}
.cdx-breadcrumbs a {
  color: #888;
  text-decoration: none;
}
.cdx-breadcrumbs a:hover {
  color: #ea580c;
}
.cdx-breadcrumbs .cdx-separator::after {
  content: '/';
  margin: 0 4px;
}

/* 82. Visited Links */
.cdx-visited:visited {
  color: #6b7280;
}

/* 83. Empty State */
.cdx-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
  color: #888;
}
.cdx-empty-state svg {
  width: 120px;
  height: 120px;
  margin-bottom: 16px;
  opacity: 0.5;
}
.cdx-empty-state h3 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
  color: #fff;
}
.cdx-empty-state p {
  font-size: 14px;
  max-width: 300px;
}

/* 84. Custom 404 */
.cdx-404 {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #0a0a0a;
  color: #fff;
  z-index: 2147483647;
}
.cdx-404 h1 {
  font-size: 120px;
  font-weight: 700;
  color: #ea580c;
  margin: 0;
  line-height: 1;
}
.cdx-404 p {
  font-size: 18px;
  color: #888;
  margin-top: 16px;
}

/* 86. Back to Top */
.cdx-back-top {
  position: fixed;
  bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  right: 20px;
  width: 44px;
  height: 44px;
  background: rgba(234, 88, 12, 0.9);
  color: #fff;
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 1000;
  touch-action: manipulation;
}
.cdx-back-top.cdx-visible {
  opacity: 1;
  transform: translateY(0);
}
.cdx-back-top:hover {
  background: #ea580c;
}

/* 91. Lazy Class - Blur-up */
.cdx-lazy {
  filter: blur(10px);
  transition: filter 0.3s ease;
}
.cdx-lazy.cdx-loaded {
  filter: blur(0);
}

/* 92. Img Ratio - Aspect ratio boxes */
.cdx-ratio-16-9 {
  aspect-ratio: 16 / 9;
  object-fit: cover;
}
.cdx-ratio-4-3 {
  aspect-ratio: 4 / 3;
  object-fit: cover;
}
.cdx-ratio-1-1 {
  aspect-ratio: 1 / 1;
  object-fit: cover;
}

/* 93. Alt Warn - Red border on missing alts (dev mode) */
.cdx-dev-mode img:not([alt]),
.cdx-dev-mode img[alt=""] {
  border: 3px solid #ef4444 !important;
}

/* 94. Tablets - Media queries */
@media (min-width: 768px) {
  .cdx-hide-tablet { display: none; }
  .cdx-show-tablet { display: block; }
}
@media (max-width: 767px) {
  .cdx-hide-mobile { display: none; }
  .cdx-show-mobile { display: block; }
}

/* 100. Selection */
::selection {
  background: rgba(234, 88, 12, 0.3);
  color: inherit;
}

/* ==========================================================================
   PART 3: EFFICIENCY LAYER - CSS COMPONENTS
   ========================================================================== */

/* 2. Quick Actions FAB */
.cdx-fab {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  left: 20px;
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, #ea580c, #f97316);
  color: #fff;
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(234, 88, 12, 0.4);
  z-index: 1000;
  touch-action: manipulation;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.cdx-fab:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 24px rgba(234, 88, 12, 0.5);
}
.cdx-fab:active {
  transform: scale(0.95);
}
.cdx-fab svg {
  width: 24px;
  height: 24px;
}

/* FAB Menu */
.cdx-fab-menu {
  position: fixed;
  bottom: calc(90px + env(safe-area-inset-bottom, 0px));
  left: 20px;
  background: #1a1a1a;
  border-radius: 12px;
  padding: 8px 0;
  min-width: 200px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  z-index: 1000;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}
.cdx-fab-menu.cdx-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.cdx-fab-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s ease;
  touch-action: manipulation;
  min-height: 44px;
}
.cdx-fab-menu-item:hover {
  background: rgba(255, 255, 255, 0.1);
}
.cdx-fab-menu-item svg {
  width: 18px;
  height: 18px;
  color: #ea580c;
}

/* 3. Command Palette */
.cdx-command-palette {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 20vh;
  z-index: 2147483647;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.cdx-command-palette.cdx-open {
  opacity: 1;
  pointer-events: auto;
}
.cdx-command-palette-box {
  background: #1a1a1a;
  border-radius: 12px;
  width: 90%;
  max-width: 500px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}
.cdx-command-palette-input {
  width: 100%;
  padding: 16px 20px;
  background: transparent;
  border: none;
  border-bottom: 1px solid #333;
  color: #fff;
  font-size: 16px;
  outline: none;
}
.cdx-command-palette-input::placeholder {
  color: #666;
}
.cdx-command-palette-results {
  max-height: 300px;
  overflow-y: auto;
}
.cdx-command-palette-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  color: #fff;
  cursor: pointer;
  transition: background 0.2s ease;
  min-height: 44px;
}
.cdx-command-palette-item:hover,
.cdx-command-palette-item.cdx-selected {
  background: rgba(234, 88, 12, 0.2);
}
.cdx-command-palette-item svg {
  width: 18px;
  height: 18px;
  color: #888;
}
.cdx-command-palette-shortcut {
  margin-left: auto;
  font-size: 12px;
  color: #666;
  background: #333;
  padding: 2px 6px;
  border-radius: 4px;
}

/* 22. Zen Mode */
.cdx-zen-mode {
  position: fixed;
  inset: 0;
  background: #0a0a0a;
  z-index: 2147483646;
  overflow-y: auto;
  padding: 40px 20px;
}
.cdx-zen-mode-content {
  max-width: 65ch;
  margin: 0 auto;
  color: #e5e5e5;
  font-size: 18px;
  line-height: 1.8;
}
.cdx-zen-mode-close {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 44px;
  height: 44px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2147483647;
}

/* 31. Night Shift - Sepia filter */
.cdx-night-shift {
  filter: sepia(0.15) brightness(0.95);
}

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

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

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

/* ==========================================================================
   PART 4: PSYCHOLOGICAL CODEX - CSS
   ========================================================================== */

/* 124. Identity Toggle - Long-Duration View */
.cdx-noise {
  transition: filter 0.3s ease;
}
.cdx-long-duration .cdx-noise {
  filter: blur(4px);
  opacity: 0.5;
}

/* 128. Silent Badge - Social Proof */
.cdx-badge-social {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(234, 88, 12, 0.1);
  color: #ea580c;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* 129. Peer Notes - Handwritten annotations */
.cdx-peer-notes {
  font-family: 'Caveat', cursive;
  font-size: 16px;
  color: #ea580c;
  transform: rotate(-2deg);
  margin-left: 20px;
  opacity: 0.8;
}

/* 131. Quiet Room */
.cdx-quiet-room {
  position: fixed;
  inset: 0;
  background: #f5f0e8;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2147483647;
  padding: 40px;
}
.cdx-quiet-room-content {
  max-width: 600px;
  text-align: center;
  color: #333;
  font-size: 20px;
  line-height: 1.8;
}

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

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

/* 137. Privacy Banner */
.cdx-privacy-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #1a1a1a;
  color: #888;
  padding: 12px 20px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  font-size: 12px;
  text-align: center;
  z-index: 100;
  border-top: 1px solid #333;
}

/* 140. Patient Tag */
.cdx-patient-tag {
  display: inline-block;
  color: #666;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
}

/* ==========================================================================
   PART 5: MODAL & OVERLAY SYSTEM
   ========================================================================== */

.cdx-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(4px);
  z-index: 2147483646;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.cdx-modal-backdrop.cdx-open {
  opacity: 1;
  pointer-events: auto;
}

.cdx-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.95);
  background: #1a1a1a;
  border-radius: 12px;
  padding: 24px;
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  z-index: 2147483647;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.cdx-modal.cdx-open {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%) scale(1);
}

.cdx-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.cdx-modal-title {
  font-size: 18px;
  font-weight: 600;
  color: #fff;
}
.cdx-modal-close {
  width: 32px;
  height: 32px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: 50%;
  color: #888;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ==========================================================================
   PART 6: ANTICIPATORY LAYER - CSS
   ========================================================================== */

/* 102. Trajectory Glow */
.cdx-trajectory-glow {
  box-shadow: 0 0 20px rgba(234, 88, 12, 0.5);
}

/* 106. Circadian BG */
.cdx-circadian-warm {
  filter: sepia(0.1) brightness(0.98);
}
.cdx-circadian-cool {
  filter: saturate(1.05) brightness(1.02);
}

/* 107. Focus Tunnel */
.cdx-focus-tunnel *:not(:focus):not(:focus-within) {
  opacity: 0.3;
}

/* 110. Density - Compact mode */
.cdx-compact {
  --cdx-spacer: 0.5rem;
}
.cdx-compact .cdx-mb-4 {
  margin-bottom: var(--cdx-spacer);
}

/* 111. Patina - Frequent button darkening */
.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); }

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

/* 117. Changelog - New badge */
.cdx-new-badge::after {
  content: 'NEW';
  display: inline-block;
  background: #ea580c;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  padding: 2px 5px;
  border-radius: 3px;
  margin-left: 6px;
  vertical-align: middle;
}

/* ==========================================================================
   PART 7: UTILITY CLASSES
   ========================================================================== */

.cdx-hidden { display: none !important; }
.cdx-visible { display: block !important; }
.cdx-flex { display: flex !important; }
.cdx-inline-flex { display: inline-flex !important; }
.cdx-center { align-items: center; justify-content: center; }
.cdx-between { justify-content: space-between; }
.cdx-gap-1 { gap: 0.25rem; }
.cdx-gap-2 { gap: 0.5rem; }
.cdx-gap-3 { gap: 1rem; }
.cdx-gap-4 { gap: 1.5rem; }
.cdx-text-center { text-align: center; }
.cdx-text-left { text-align: left; }
.cdx-text-right { text-align: right; }
.cdx-text-sm { font-size: 12px; }
.cdx-text-base { font-size: 14px; }
.cdx-text-lg { font-size: 16px; }
.cdx-text-xl { font-size: 18px; }
.cdx-text-muted { color: #888; }
.cdx-text-primary { color: #ea580c; }
.cdx-text-success { color: #22c55e; }
.cdx-text-error { color: #ef4444; }
.cdx-bg-dark { background: #0a0a0a; }
.cdx-bg-card { background: #1a1a1a; }
.cdx-rounded { border-radius: 6px; }
.cdx-rounded-lg { border-radius: 12px; }
.cdx-rounded-full { border-radius: 9999px; }
.cdx-shadow { box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); }
.cdx-shadow-lg { box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25); }
.cdx-p-1 { padding: 0.25rem; }
.cdx-p-2 { padding: 0.5rem; }
.cdx-p-3 { padding: 1rem; }
.cdx-p-4 { padding: 1.5rem; }
.cdx-w-full { width: 100%; }
.cdx-h-full { height: 100%; }
