/* Custom CSS for The Digital Executor */

/* CSS Custom Properties for brand colors */
:root {
  --color-deep-teal: #004F5D;
  --color-warm-bronze: #A97142;
  --color-off-white: #F5F5F0;
  --color-near-black: #1C1C1C;
}

/* Fallback font stack to minimize layout shift */
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
}

h1, h2, h3, h4, h5, h6, .font-serif {
  font-family: 'Source Serif 4', 'Georgia', 'Cambria', 'Times New Roman', Times, serif;
}

/* Focus styles for accessibility */
.focus-ring:focus {
  outline: 2px solid var(--color-deep-teal);
  outline-offset: 2px;
}

/* Screen reader only content */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.sr-only:focus {
  position: static;
  width: auto;
  height: auto;
  padding: 0.5rem 1rem;
  margin: 0;
  overflow: visible;
  clip: auto;
  white-space: normal;
  border: 1px solid var(--color-deep-teal);
  background: var(--color-deep-teal);
  color: white;
  border-radius: 0.375rem;
  z-index: 50;
}

/* Typography enhancements */
body {
  font-size: 20px;
  line-height: 1.7;
}

h1, h2, h3, h4, h5, h6 {
  line-height: 1.4;
  font-weight: 600;
}

/* Explicit font-size for h1 elements to fix deprecated API warning */
h1 {
  font-size: 3.5rem;
}

/* Responsive h1 font-sizes */
@media (max-width: 1024px) {
  h1 {
    font-size: 3rem;
  }
}

@media (max-width: 768px) {
  h1 {
    font-size: 2.5rem;
  }
}

@media (max-width: 640px) {
  h1 {
    font-size: 2.25rem;
  }
}

/* Improve paragraph and text readability */
p {
  font-size: 1.1em;
  line-height: 1.7;
}

/* Better form text readability */
input, textarea, select {
  font-size: 1em;
  line-height: 1.5;
}

label {
  font-size: 1em;
}

/* Ensure buttons have readable text */
button, .btn-primary, .btn-secondary {
  font-size: 1em;
  line-height: 1.5;
}

/* Smooth scrolling for better UX with hardware acceleration */
html {
  scroll-behavior: smooth;
}

/* Hardware acceleration for scroll containers */
html, body {
  transform: translateZ(0);
  will-change: scroll-position;
}

/* Global cursor pointer for interactive elements */
a,
button,
input[type="button"],
input[type="submit"],
input[type="reset"],
[role="button"],
.btn-primary,
.btn-secondary,
.faq-toggle {
  cursor: pointer;
}

/* Enhanced button styles */
.btn-primary {
  background-color: var(--color-deep-teal);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 0.5rem;
  font-weight: 500;
  transition: background-color 0.2s ease, transform 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  border: none;
  will-change: background-color, transform;
}

.btn-primary:hover {
  background-color: rgba(0, 79, 93, 0.9);
  transform: translateY(-1px);
}

.btn-primary:focus {
  outline: 2px solid var(--color-deep-teal);
  outline-offset: 2px;
}

.btn-secondary {
  border: 2px solid var(--color-deep-teal);
  color: var(--color-deep-teal);
  background-color: transparent;
  padding: 0.75rem 1.5rem;
  border-radius: 0.5rem;
  font-weight: 500;
  transition: background-color 0.2s ease, color 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  will-change: background-color, color;
}

.btn-secondary:hover {
  background-color: var(--color-deep-teal);
  color: white;
}

/* Form enhancements */
input:focus,
textarea:focus,
select:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--color-deep-teal);
  border-color: transparent;
}

/* Custom checkbox and radio styles */
input[type="checkbox"]:checked,
input[type="radio"]:checked {
  background-color: var(--color-deep-teal);
  border-color: var(--color-deep-teal);
}

input[type="checkbox"]:focus,
input[type="radio"]:focus {
  box-shadow: 0 0 0 2px var(--color-deep-teal);
}

/* FAQ accordion styles */
.faq-toggle {
  transition: all 0.2s ease-in-out;
}

.faq-toggle:hover {
  background-color: rgba(0, 79, 93, 0.05);
}

.faq-content {
  transition: all 0.3s ease-in-out;
  padding-top: 0.75rem !important;
}

/* Loading states */
.loading {
  opacity: 0.6;
  pointer-events: none;
}

.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid var(--color-deep-teal);
  border-radius: 50%;
  border-top-color: transparent;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Mobile menu animation */
#mobile-menu {
  transition: all 0.3s ease-in-out;
}

/* Hero section enhancements */
.hero-gradient {
  background: linear-gradient(135deg, var(--color-off-white) 0%, rgba(245, 245, 240, 0.8) 100%);
}

/* Card shadow enhancements */
.card-shadow {
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.card-shadow:hover {
  box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.15), 0 10px 20px -5px rgba(0, 0, 0, 0.08);
  transform: translateY(-2px);
  transition: all 0.3s ease-in-out;
}

/* Performance optimizations */
img {
  max-width: 100%;
  height: auto;
}

/* Prevent CLS (Cumulative Layout Shift) */
.aspect-w-4 {
  position: relative;
  padding-bottom: 75%; /* 4:3 aspect ratio */
}

.aspect-w-4 > img,
.aspect-w-4 > video {
  position: absolute;
  height: 100%;
  width: 100%;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}

/* Prevent layout shift from images */
img[width][height] {
  height: auto;
}

/* Font loading optimization to prevent CLS */
body {
  font-display: swap;
}

h1, h2, h3, h4, h5, h6, .font-serif {
  font-display: swap;
}

/* Grid layout optimization to prevent CLS */
.hero-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 3rem;
  align-items: center;
}

@media (min-width: 1024px) {
  .hero-grid {
    grid-template-columns: 1fr 1fr;
  }
  
  .hero-text {
    order: 1;
  }
  
  .hero-image {
    order: 2;
  }
}

/* Prevent content shift during loading */
.hero-section {
  min-height: 600px;
}

@media (min-width: 1024px) {
  .hero-section {
    min-height: 500px;
  }
}

/* Additional CLS prevention */
.hero-text {
  min-height: 400px;
}

.hero-image {
  min-height: 300px;
}

@media (min-width: 1024px) {
  .hero-text {
    min-height: auto;
  }
  
  .hero-image {
    min-height: auto;
  }
}

/* Prevent text reflow on font load */
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
  font-feature-settings: 'kern' 1;
  text-rendering: optimizeLegibility;
}

/* Optimize critical rendering path */
.above-fold {
  contain: layout style paint;
}

/* Prevent button layout shifts */
.btn-primary, .btn-secondary {
  min-height: 48px;
  min-width: 120px;
}

/* Prevent form layout shifts */
input[type="text"],
input[type="email"],
input[type="tel"],
textarea,
select {
  min-height: 44px;
}

/* Section spacing optimization */
section {
  contain: layout;
}

/* FAQ content height to prevent shifts */
.faq-content {
  min-height: 0;
  overflow: hidden;
  transition: min-height 0.3s ease, padding 0.3s ease;
}

.faq-content.open {
  min-height: auto;
}

/* Mobile menu stability */
.mobile-menu {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  transform: translateY(-100%);
  transition: transform 0.3s ease;
  z-index: 50;
}

.mobile-menu.open {
  transform: translateY(0);
}

/* Content containment for better performance */
.card, .article-card, .faq-item {
  contain: layout style;
}

/* Prevent CLS in article images */
.article-image {
  aspect-ratio: 16/9;
  object-fit: cover;
  width: 100%;
  height: auto;
}

/* Button stability */
button, .btn, a[role="button"] {
  contain: layout;
  min-height: 44px;
}

/* Optimize hero sections across all pages */
.hero-section .hero-grid {
  contain: layout;
}

/* Prevent shifts in dynamic content */
.htmx-indicator {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

/* Optimize FAQ accordion to prevent CLS */
.faq-content {
  will-change: max-height, opacity;
  contain: layout style;
}

/* Loading state optimization */
[data-loading] {
  min-height: 2rem;
  position: relative;
}

/* Lazy loading placeholder */
.img-placeholder {
  background-color: #f3f4f6;
  background-image: linear-gradient(45deg, transparent 40%, rgba(255, 255, 255, 0.5) 50%, transparent 60%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

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

/* High contrast mode support */
@media (prefers-contrast: high) {
  :root {
    --color-deep-teal: #000000;
    --color-warm-bronze: #8B4513;
    --color-near-black: #000000;
  }
}

/* Additional accessibility improvements */
/* Improved focus indicators */
*:focus {
  outline: 3px solid var(--color-deep-teal) !important;
  outline-offset: 2px !important;
}

/* Better text contrast for gray text */
.text-gray-700 {
  color: #374151 !important; /* Darker for better contrast */
}

.text-gray-600 {
  color: #4B5563 !important; /* Darker for better contrast */
}

/* Enhanced spacing for better readability */
p + p {
  margin-top: 1.5rem;
}

/* List improvements */
ul, ol {
  line-height: 1.8 !important;
}

li {
  margin-bottom: 0.5rem;
}

/* Card content spacing */
.space-y-6 > * + * {
  margin-top: 2rem !important;
}

.space-y-4 > * + * {
  margin-top: 1.5rem !important;
}

.space-y-2 > * + * {
  margin-top: 0.75rem !important;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Print styles */
@media print {
  .no-print {
    display: none !important;
  }
  
  a[href]:after {
    content: " (" attr(href) ")";
  }
  
  .page-break {
    page-break-before: always;
  }
}

/* Error and success message styles */
.alert {
  padding: 1rem;
  border-radius: 0.5rem;
  margin-bottom: 1rem;
}

.alert-success {
  background-color: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
}

.alert-error {
  background-color: #fef2f2;
  border: 1px solid #fecaca;
  color: #dc2626;
}

.alert-warning {
  background-color: #fffbeb;
  border: 1px solid #fed7aa;
  color: #d97706;
}

/* FAQ accordion optimizations */
.faq-answer {
  transition: max-height 0.3s ease, opacity 0.3s ease;
  will-change: max-height, opacity;
  transform: translateZ(0); /* Hardware acceleration */
}

.faq-toggle svg {
  transition: transform 0.2s ease;
  will-change: transform;
  transform: translateZ(0); /* Hardware acceleration */
}

/* Performance optimizations for animations */
* {
  backface-visibility: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Optimize hover states */
.hover-optimize {
  will-change: transform, opacity;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

/* Mobile menu optimizations */
.mobile-menu {
  transform: translateZ(0);
  will-change: transform, opacity;
  transition: transform 0.3s ease, opacity 0.3s ease;
}
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--color-off-white);
}

::-webkit-scrollbar-thumb {
  background: var(--color-deep-teal);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 79, 93, 0.8);
}

/* Skip link styling */
.skip-link {
  position: absolute;
  top: -40px;
  left: 6px;
  background: var(--color-deep-teal);
  color: white;
  padding: 8px;
  border-radius: 4px;
  text-decoration: none;
  z-index: 100;
  transition: top 0.3s;
}

.skip-link:focus {
  top: 6px;
}

/* Responsive utilities */
@media (max-width: 640px) {
  body {
    font-size: 18px;
  }
  
  p {
    font-size: 1.1em;
  }
  
  h2 {
    font-size: 2.25rem !important;
  }
  
  h3 {
    font-size: 1.5rem !important;
  }
  
  /* Enhanced mobile text sizes */
  .text-lg {
    font-size: 1.25rem !important;
  }
  
  .text-base {
    font-size: 1.05rem !important;
  }
  
  .text-sm {
    font-size: 0.95rem !important;
  }
  
  /* Ensure mobile forms are readable */
  input, textarea, select {
    font-size: 16px; /* Prevents zoom on iOS */
    padding: 0.875rem;
  }
  
  /* Mobile button improvements */
  .btn-primary, .btn-secondary, button[type="submit"] {
    font-size: 1.05rem !important;
    padding: 1rem 1.5rem !important;
  }
  
  /* Mobile navigation */
  nav a {
    font-size: 1.05rem !important;
    padding: 0.75rem !important;
  }
}

/* HTMX loading indicators */
.htmx-indicator {
  opacity: 0;
  transition: opacity 500ms ease-in;
}

.htmx-request .htmx-indicator {
  opacity: 1;
}

.htmx-request.htmx-indicator {
  opacity: 1;
}

/* Enhanced readability for older users */
.text-lg {
  font-size: 1.3rem !important;
  line-height: 1.7 !important;
}

.text-base {
  font-size: 1.1rem !important;
  line-height: 1.7 !important;
}

.text-sm {
  font-size: 1rem !important;
  line-height: 1.6 !important;
}

/* Navigation text enhancement */
nav a {
  font-size: 1.1rem !important;
  font-weight: 500 !important;
}

/* FAQ and content text improvements */
.faq-toggle h3 {
  font-size: 1.3rem !important;
  line-height: 1.6 !important;
  font-weight: 600 !important;
}

/* FAQ answer formatting improvements */
.faq-content p {
  font-size: 1.1rem !important;
  line-height: 1.7 !important;
}

/* Footer text readability */
footer {
  font-size: 1rem !important;
}

footer .text-sm {
  font-size: 1rem !important;
}

/* Button text improvements */
.btn-primary, .btn-secondary, button[type="submit"] {
  font-size: 1.1rem !important;
  padding: 0.875rem 1.75rem !important;
}

/* Hero section button improvements */
#for-families .flex a,
#for-attorneys .flex a {
  font-size: 0.95rem !important;
  padding: 0.75rem 1.2rem !important;
  white-space: nowrap;
}

/* Button container optimization */
#for-families .flex.flex-col,
#for-attorneys .flex.flex-col {
  flex-wrap: nowrap;
}

@media (min-width: 640px) {
  #for-families .flex.flex-col,
  #for-attorneys .flex.flex-col {
    flex-direction: row !important;
    flex-wrap: nowrap;
    gap: 0.75rem;
  }
}

/* Responsive hero button sizing */
@media (min-width: 768px) {
  #for-families .flex a,
  #for-attorneys .flex a {
    font-size: 1rem !important;
    padding: 0.8rem 1.3rem !important;
  }
}

@media (min-width: 1024px) {
  #for-families .flex a,
  #for-attorneys .flex a {
    font-size: 1.05rem !important;
    padding: 0.85rem 1.4rem !important;
  }
}

@media (min-width: 1280px) {
  #for-families .flex a,
  #for-attorneys .flex a {
    font-size: 1.1rem !important;
    padding: 0.875rem 1.5rem !important;
  }
}

/* Form label improvements */
label {
  font-weight: 600 !important;
  color: var(--color-near-black) !important;
}

/* Link text improvements for better readability */
a {
  font-weight: 500;
}

/* Heading size improvements for better hierarchy */
h2 {
  font-size: 2.5rem !important;
  line-height: 1.3 !important;
}

h3 {
  font-size: 1.75rem !important;
  line-height: 1.4 !important;
}
