/**
 * MASTER CODEX FINANCIAL - CSS Layer
 * Marlowe Partners - Master Influence & UX Layer
 * Implements features 51-100 (The Polish Layer)
 * 
 * All classes namespaced with .cdx- for strict isolation
 * Mobile-first with iOS/Safari focus
 */

/* ============================================
   MOBILE-FIRST FOUNDATION
   ============================================ */

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

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

.cdx-toast-container {
  bottom: calc(1rem + env(safe-area-inset-bottom, 0));
}

/* ============================================
   FEATURE 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);
}

/* ============================================
   FEATURE 52: ACTIVE PRESS
   ============================================ */
.cdx-press {
  transition: transform 0.1s ease;
}

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

/* ============================================
   FEATURE 53: FOCUS GLOW
   ============================================ */
.cdx-focus-glow:focus,
input:focus,
textarea:focus,
select:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.25);
}

/* ============================================
   FEATURE 54: SKELETON ANIMATION
   ============================================ */
.cdx-skeleton {
  background: linear-gradient(
    90deg,
    #f0f0f0 25%,
    #e0e0e0 50%,
    #f0f0f0 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;
  }
}

/* ============================================
   FEATURE 55: MENU SLIDE
   ============================================ */
.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;
}

/* ============================================
   FEATURE 56: CURSOR HAND
   ============================================ */
button,
.cdx-btn,
[role="button"],
.cdx-clickable {
  cursor: pointer;
}

/* ============================================
   FEATURE 57: LINK FADE
   ============================================ */
a,
.cdx-link {
  transition: color 0.2s ease, opacity 0.2s ease;
}

a:hover,
.cdx-link:hover {
  opacity: 0.8;
}

/* ============================================
   FEATURE 58: STICKY HEAD
   ============================================ */
.cdx-sticky {
  position: sticky;
  top: 0;
  z-index: 100;
  background: inherit;
}

/* ============================================
   FEATURE 59: TOAST POP
   ============================================ */
.cdx-toast {
  position: fixed;
  bottom: calc(1rem + env(safe-area-inset-bottom, 0));
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #1e293b;
  color: #fff;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-size: 0.875rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  z-index: 2147483647;
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

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

@keyframes cdx-toast-pop {
  0% {
    transform: translateX(-50%) translateY(100px);
    opacity: 0;
  }
  100% {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
  }
}

/* ============================================
   FEATURE 60: PROGRESS BAR (Scroll-linked)
   ============================================ */
.cdx-progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: linear-gradient(90deg, #d97706, #f59e0b);
  z-index: 2147483647;
  transition: width 0.1s ease;
}

/* ============================================
   FEATURE 61: LINE HEIGHT
   ============================================ */
.cdx-readable,
article,
.cdx-content {
  line-height: 1.6;
}

/* ============================================
   FEATURE 62: LINE WIDTH (Max text width)
   ============================================ */
.cdx-prose,
article p,
.cdx-content p {
  max-width: 75ch;
}

/* ============================================
   FEATURE 63: HIERARCHY (Typography scale)
   ============================================ */
.cdx-h1, h1 { font-size: 2.5rem; font-weight: 700; line-height: 1.2; }
.cdx-h2, h2 { font-size: 2rem; font-weight: 600; line-height: 1.25; }
.cdx-h3, h3 { font-size: 1.75rem; font-weight: 600; line-height: 1.3; }
.cdx-h4, h4 { font-size: 1.5rem; font-weight: 500; line-height: 1.35; }
.cdx-h5, h5 { font-size: 1.25rem; font-weight: 500; line-height: 1.4; }
.cdx-h6, h6 { font-size: 1rem; font-weight: 500; line-height: 1.5; }

/* ============================================
   FEATURE 64: CONTRAST
   ============================================ */
.cdx-high-contrast {
  color: #222;
  background-color: #fff;
}

.cdx-dark-mode .cdx-high-contrast {
  color: #f5f5f5;
  background-color: #1a1a1a;
}

/* ============================================
   FEATURE 65: SYSTEM FONTS
   ============================================ */
.cdx-system-font {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 
    Oxygen, Ubuntu, Cantarell, 'Fira Sans', 'Droid Sans', 
    'Helvetica Neue', sans-serif;
}

/* ============================================
   FEATURE 68: LINK STYLE
   ============================================ */
.cdx-link-styled {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

/* ============================================
   FEATURE 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; }

/* ============================================
   FEATURE 76: ERROR TEXT
   ============================================ */
.cdx-error-text {
  color: #dc2626;
  font-size: 0.75rem;
  margin-top: 0.25rem;
}

/* ============================================
   FEATURE 77: BTN PRIMARY
   ============================================ */
.cdx-btn-primary {
  background: #1e293b;
  color: #fff;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 6px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease;
}

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

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

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

/* ============================================
   FEATURE 79: LABEL FLOAT
   ============================================ */
.cdx-float-label {
  position: relative;
}

.cdx-float-label input,
.cdx-float-label textarea {
  padding-top: 1.5rem;
}

.cdx-float-label label {
  position: absolute;
  top: 0.5rem;
  left: 0.75rem;
  font-size: 0.75rem;
  color: #64748b;
  transition: all 0.2s ease;
  pointer-events: none;
}

.cdx-float-label input:placeholder-shown + label {
  top: 1rem;
  font-size: 1rem;
}

.cdx-float-label input:focus + label {
  top: 0.5rem;
  font-size: 0.75rem;
  color: #d97706;
}

/* ============================================
   FEATURE 82: VISITED LINKS
   ============================================ */
a:visited,
.cdx-link:visited {
  opacity: 0.85;
}

/* ============================================
   FEATURE 83: EMPTY STATE
   ============================================ */
.cdx-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  text-align: center;
  color: #64748b;
}

.cdx-empty-state svg {
  width: 120px;
  height: 120px;
  margin-bottom: 1.5rem;
  opacity: 0.5;
}

/* ============================================
   FEATURE 84: CUSTOM 404
   ============================================ */
.cdx-404-overlay {
  position: fixed;
  inset: 0;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 2147483647;
}

.cdx-404-overlay h1 {
  font-size: 6rem;
  font-weight: 700;
  color: #d97706;
  margin-bottom: 1rem;
}

/* ============================================
   FEATURE 85: SEARCH POSITION
   ============================================ */
.cdx-search-pos {
  position: absolute;
  top: 1rem;
  right: 1rem;
}

/* ============================================
   FEATURE 86: BACK TO TOP
   ============================================ */
.cdx-back-top {
  position: fixed;
  bottom: calc(2rem + env(safe-area-inset-bottom, 0));
  right: 1rem;
  width: 44px;
  height: 44px;
  background: #1e293b;
  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;
}

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

.cdx-back-top:hover {
  background: #334155;
}

/* ============================================
   FEATURE 89: MODAL BACKDROP
   ============================================ */
.cdx-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 2147483646;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.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: #fff;
  border-radius: 12px;
  padding: 2rem;
  z-index: 2147483647;
  max-width: 90vw;
  max-height: 90vh;
  overflow: auto;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.cdx-modal.cdx-open {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* ============================================
   FEATURE 91: LAZY LOAD BLUR-UP
   ============================================ */
.cdx-lazy {
  filter: blur(10px);
  transition: filter 0.5s ease;
}

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

/* ============================================
   FEATURE 92: IMAGE RATIO
   ============================================ */
.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;
}

/* ============================================
   FEATURE 93: ALT WARNING (Dev Mode)
   ============================================ */
.cdx-dev-mode img:not([alt]),
.cdx-dev-mode img[alt=""] {
  outline: 3px solid #dc2626;
}

/* ============================================
   FEATURE 94: TABLET MEDIA QUERIES
   ============================================ */
@media (min-width: 768px) {
  .cdx-tablet-hide { display: none; }
  .cdx-tablet-show { display: block; }
  .cdx-tablet-flex { display: flex; }
}

@media (max-width: 767px) {
  .cdx-mobile-hide { display: none; }
  .cdx-mobile-show { display: block; }
  .cdx-mobile-stack { flex-direction: column; }
}

/* ============================================
   FEATURE 95: FAST TAP
   ============================================ */
.cdx-fast-tap {
  touch-action: manipulation;
}

/* ============================================
   FEATURE 97: EXTERNAL LINK ICON
   ============================================ */
a[target="_blank"]::after,
.cdx-external::after {
  content: " ↗";
  font-size: 0.75em;
  opacity: 0.7;
}

/* ============================================
   FEATURE 100: SELECTION COLOR
   ============================================ */
::selection {
  background: rgba(217, 119, 6, 0.3);
  color: inherit;
}

::-moz-selection {
  background: rgba(217, 119, 6, 0.3);
  color: inherit;
}

/* ============================================
   FEATURE 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; }
}

/* ============================================
   FEATURE 33: SKELETON UI
   ============================================ */
.cdx-skeleton-text {
  height: 1em;
  background: #e2e8f0;
  border-radius: 4px;
  animation: cdx-shimmer 1.5s infinite;
}

.cdx-skeleton-circle {
  border-radius: 50%;
  background: #e2e8f0;
  animation: cdx-shimmer 1.5s infinite;
}

.cdx-skeleton-rect {
  background: #e2e8f0;
  border-radius: 8px;
  animation: cdx-shimmer 1.5s infinite;
}

/* ============================================
   FEATURE 42: PRINT STYLES
   ============================================ */
@media print {
  .cdx-no-print,
  nav,
  footer,
  .cdx-fab,
  .cdx-toast,
  .cdx-back-top,
  .cdx-modal-backdrop {
    display: none !important;
  }
  
  body {
    background: #fff !important;
    color: #000 !important;
  }
  
  a {
    text-decoration: underline;
  }
  
  a[href]::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
  }
}

/* ============================================
   FLOATING ACTION BUTTON (FAB)
   ============================================ */
.cdx-fab {
  position: fixed;
  bottom: calc(1.5rem + env(safe-area-inset-bottom, 0));
  left: 1.5rem;
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, #d97706, #f59e0b);
  color: #fff;
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(217, 119, 6, 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 24px rgba(217, 119, 6, 0.5);
}

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

/* ============================================
   COMMAND PALETTE
   ============================================ */
.cdx-command-palette {
  position: fixed;
  top: 20%;
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  max-width: 600px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
  z-index: 2147483647;
  overflow: hidden;
}

.cdx-command-input {
  width: 100%;
  padding: 1rem 1.5rem;
  border: none;
  border-bottom: 1px solid #e2e8f0;
  font-size: 1.125rem;
  outline: none;
}

.cdx-command-results {
  max-height: 400px;
  overflow-y: auto;
}

.cdx-command-item {
  padding: 0.75rem 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  transition: background 0.15s ease;
}

.cdx-command-item:hover,
.cdx-command-item.cdx-active {
  background: #f1f5f9;
}

/* ============================================
   NIGHT SHIFT (Sepia filter after 8pm)
   ============================================ */
.cdx-night-shift {
  filter: sepia(0.15) saturate(0.9);
}

/* ============================================
   ZEN MODE
   ============================================ */
.cdx-zen-mode *:not(article):not(main):not(article *):not(main *) {
  opacity: 0.1 !important;
  pointer-events: none !important;
}

.cdx-zen-mode article,
.cdx-zen-mode main,
.cdx-zen-mode article *,
.cdx-zen-mode main * {
  opacity: 1 !important;
  pointer-events: auto !important;
}

/* ============================================
   UNDERWRITING MODE (Authority)
   ============================================ */
.cdx-underwriting table,
.cdx-underwriting .highcharts-container,
.cdx-underwriting .recharts-wrapper,
.cdx-underwriting svg {
  filter: grayscale(1);
  font-family: 'Courier New', monospace;
}

/* ============================================
   LEGACY FONT (Authority)
   ============================================ */
.cdx-legacy-font {
  font-family: 'Crimson Text', Georgia, serif;
}

/* ============================================
   QUIET ROOM (Scarcity)
   ============================================ */
.cdx-quiet-room {
  position: fixed;
  inset: 0;
  background: #f5f0e8;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2147483647;
  padding: 2rem;
}

.cdx-quiet-room-content {
  max-width: 600px;
  text-align: center;
  font-family: 'Crimson Text', Georgia, serif;
  font-size: 1.25rem;
  line-height: 1.8;
  color: #1e293b;
}

/* ============================================
   FOCUS TUNNEL (Anticipatory)
   ============================================ */
.cdx-focus-tunnel *:not(:focus):not(:focus-within) {
  opacity: 0.3;
}

.cdx-focus-tunnel *:focus,
.cdx-focus-tunnel *:focus-within {
  opacity: 1;
}

/* ============================================
   CIRCADIAN BACKGROUND
   ============================================ */
.cdx-circadian-warm {
  background-color: #fffbeb;
}

.cdx-circadian-cool {
  background-color: #f0f9ff;
}

/* ============================================
   RAGE CLICK INDICATOR
   ============================================ */
.cdx-rage-indicator {
  animation: cdx-shake 0.5s ease;
}

@keyframes cdx-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* ============================================
   PATINA (Frequently used buttons darken)
   ============================================ */
.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); }

/* ============================================
   WAIT CURSOR
   ============================================ */
.cdx-waiting {
  cursor: wait;
}

/* ============================================
   CHANGELOG BADGE
   ============================================ */
.cdx-new-badge::after {
  content: "NEW";
  font-size: 0.625rem;
  background: #d97706;
  color: #fff;
  padding: 0.125rem 0.375rem;
  border-radius: 4px;
  margin-left: 0.5rem;
  font-weight: 600;
  vertical-align: middle;
}

/* ============================================
   IDENTITY TOGGLE (Commitment)
   ============================================ */
.cdx-long-duration .cdx-noise {
  filter: blur(4px);
  user-select: none;
}

/* ============================================
   SILENT BADGE (Social Proof)
   ============================================ */
.cdx-silent-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  color: #64748b;
  font-style: italic;
}

.cdx-silent-badge::before {
  content: "★";
  color: #d97706;
}

/* ============================================
   PEER NOTES (Social Proof)
   ============================================ */
.cdx-peer-notes {
  font-family: 'Caveat', cursive;
  color: #1e40af;
  font-size: 0.875rem;
  margin-left: 1rem;
  opacity: 0.8;
}

/* ============================================
   PRIVACY BANNER (Affirmation)
   ============================================ */
.cdx-privacy-banner {
  background: #1e293b;
  color: #94a3b8;
  text-align: center;
  padding: 0.5rem;
  font-size: 0.75rem;
}

/* ============================================
   PATIENT TAG (Affirmation)
   ============================================ */
.cdx-patient-tag {
  font-size: 0.75rem;
  color: #64748b;
  font-style: italic;
  text-align: center;
  padding: 1rem;
}

/* ============================================
   COMPACT MODE (Density)
   ============================================ */
.cdx-compact {
  --cdx-spacer: 0.5rem;
}

.cdx-compact .cdx-mb-4 {
  margin-bottom: var(--cdx-spacer);
}

/* ============================================
   MAGNET CURSOR GLOW
   ============================================ */
.cdx-magnet-glow {
  box-shadow: 0 0 20px rgba(217, 119, 6, 0.4);
}

/* ============================================
   TRAJECTORY GLOW
   ============================================ */
.cdx-trajectory-glow {
  box-shadow: 0 0 15px rgba(217, 119, 6, 0.3);
  transition: box-shadow 0.15s ease;
}

/* ============================================
   VELOCITY TYPE (Fast scroll = heavier headers)
   ============================================ */
.cdx-velocity-heavy h1,
.cdx-velocity-heavy h2,
.cdx-velocity-heavy h3 {
  font-weight: 800;
}

/* ============================================
   READ TIME BADGE
   ============================================ */
.cdx-read-time {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.875rem;
  color: #64748b;
}

.cdx-read-time::before {
  content: "📖";
}

/* ============================================
   COPY CODE BUTTON
   ============================================ */
.cdx-code-wrapper {
  position: relative;
}

.cdx-copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: #1e293b;
  color: #fff;
  border: none;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.cdx-code-wrapper:hover .cdx-copy-btn {
  opacity: 1;
}

.cdx-copy-btn:hover {
  background: #334155;
}

/* ============================================
   GREETER
   ============================================ */
.cdx-greeter {
  font-size: 1.5rem;
  font-weight: 600;
  color: #1e293b;
  margin-bottom: 1rem;
}

/* ============================================
   ONBOARDING CHECKLIST
   ============================================ */
.cdx-onboarding {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.cdx-onboarding-title {
  font-weight: 600;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.cdx-onboarding-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid #f1f5f9;
}

.cdx-onboarding-item:last-child {
  border-bottom: none;
}

.cdx-onboarding-check {
  width: 20px;
  height: 20px;
  border: 2px solid #d97706;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cdx-onboarding-check.cdx-done {
  background: #d97706;
  color: #fff;
}

/* ============================================
   RECENT VIEW WIDGET
   ============================================ */
.cdx-recent-view {
  background: #f8fafc;
  border-radius: 8px;
  padding: 1rem;
}

.cdx-recent-view-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: #64748b;
  margin-bottom: 0.5rem;
}

.cdx-recent-view-item {
  padding: 0.5rem;
  border-radius: 4px;
  transition: background 0.15s ease;
  cursor: pointer;
}

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