/* ===========================================
   AIF Project Estimate Form Styles
   Version: 2.0.0
   
   Brand Colors:
   - Primary: #2F3A4A
   - Accent: #C4B5FD (purple)
   - Text: #121212
   - Background: #FAFAFC
   
   Dark Mode:
   - Background: #0F1319
   - Primary: #E2E6ED
   - Accent: #D8CCFF
   =========================================== */

/* ===========================================
   CSS Custom Properties (Design Tokens)
   =========================================== */
.aif-estimate {
  /* Light Theme (Default) */
  --aif-color-primary: #2F3A4A;
  --aif-color-accent: #C4B5FD;
  --aif-color-accent-hover: #B8A6F7;
  --aif-color-accent-subtle: rgba(196, 181, 253, 0.15);
  --aif-color-accent-ring: rgba(196, 181, 253, 0.45);
  
  --aif-color-text: #121212;
  --aif-color-text-secondary: #5B6573;
  --aif-color-text-muted: #6B7280;
  
  --aif-color-bg: #FAFAFC;
  --aif-color-bg-elevated: #FFFFFF;
  --aif-color-bg-hover: #F3F4F6;
  --aif-color-bg-input: #FFFFFF;
  
  --aif-color-border: #D8DDEA;
  --aif-color-border-strong: #C4CAD6;
  --aif-color-border-focus: #C4B5FD;
  
  --aif-color-error: #B91C1C;
  --aif-color-error-bg: #FEF2F2;
  --aif-color-error-border: #FECACA;
  --aif-color-error-text: #991B1B;
  
  --aif-color-success: #059669;
  --aif-color-success-bg: #ECFDF5;
  
  /* Spacing */
  --aif-space-xs: 0.25rem;
  --aif-space-sm: 0.5rem;
  --aif-space-md: 0.75rem;
  --aif-space-lg: 1rem;
  --aif-space-xl: 1.5rem;
  --aif-space-2xl: 2rem;
  
  /* Border Radius */
  --aif-radius-sm: 8px;
  --aif-radius-md: 12px;
  --aif-radius-lg: 16px;
  --aif-radius-full: 999px;
  
  /* Shadows */
  --aif-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --aif-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --aif-shadow-focus: 0 0 0 3px var(--aif-color-accent-ring);
  --aif-shadow-error: 0 0 0 3px rgba(185, 28, 28, 0.2);
  
  /* Typography */
  --aif-font-size-sm: 0.875rem;
  --aif-font-size-base: 1rem;
  --aif-font-size-lg: 1.125rem;
  --aif-line-height: 1.5;
  
  /* Transitions */
  --aif-transition-fast: 150ms ease;
  --aif-transition-base: 200ms ease;
  
  /* Focus ring */
  --aif-focus-ring-width: 3px;
  --aif-focus-ring-offset: 2px;
  
  /* Minimum touch target (WCAG 2.2 AAA: 44px) */
  --aif-touch-target: 44px;
}

/* ===========================================
   Dark Theme
   =========================================== */
@media (prefers-color-scheme: dark) {
  .aif-estimate {
    --aif-color-primary: #E2E6ED;
    --aif-color-accent: #D8CCFF;
    --aif-color-accent-hover: #E8E0FF;
    --aif-color-accent-subtle: rgba(216, 204, 255, 0.15);
    --aif-color-accent-ring: rgba(216, 204, 255, 0.4);
    
    --aif-color-text: #E2E6ED;
    /* These two used to repeat the light-theme values (#5B6573 / #6B7280), which
       against the dark card (--aif-color-bg-elevated: #1A1F2A) gave 2.79:1 and
       3.41:1 - both below the 4.5:1 minimum. It affected the unselected step tabs,
       the intro paragraph, the required-fields note, hint text and input
       placeholders, for anyone with OS dark mode on. #A8B0BE is the value
       aif-booking.css already uses for --aif-muted in its own dark block. */
    --aif-color-text-secondary: #A8B0BE;  /* 7.56:1 on #1A1F2A */
    --aif-color-text-muted: #949CAB;      /* 5.97:1 on #1A1F2A */
    
    --aif-color-bg: #0F1319;
    --aif-color-bg-elevated: #1A1F2A;
    --aif-color-bg-hover: #252B38;
    --aif-color-bg-input: #1A1F2A;
    
    --aif-color-border: #2D3748;
    --aif-color-border-strong: #4A5568;
    --aif-color-border-focus: #D8CCFF;
    
    --aif-color-error: #F87171;
    --aif-color-error-bg: rgba(185, 28, 28, 0.15);
    --aif-color-error-border: #991B1B;
    --aif-color-error-text: #FCA5A5;
    
    --aif-color-success: #34D399;
    --aif-color-success-bg: rgba(5, 150, 105, 0.15);
    
    --aif-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --aif-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  }
}

/* ===========================================
   High Contrast Mode
   =========================================== */
@media (prefers-contrast: more) {
  .aif-estimate {
    --aif-color-text: #000000;
    --aif-color-text-secondary: #1A1A1A;
    --aif-color-border: #000000;
    --aif-color-border-strong: #000000;
    --aif-color-accent: #6B21A8;
    --aif-color-accent-hover: #581C87;
    --aif-color-error: #7F1D1D;
    --aif-focus-ring-width: 4px;
  }
  
  @media (prefers-color-scheme: dark) {
    .aif-estimate {
      --aif-color-text: #FFFFFF;
      --aif-color-text-secondary: #E5E5E5;
      --aif-color-border: #FFFFFF;
      --aif-color-border-strong: #FFFFFF;
      --aif-color-bg: #000000;
      --aif-color-bg-elevated: #1A1A1A;
      --aif-color-accent: #E9D5FF;
      --aif-color-error: #FCA5A5;
    }
  }
}

/* ===========================================
   Reduced Motion
   =========================================== */
@media (prefers-reduced-motion: reduce) {
  .aif-estimate,
  .aif-estimate * {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

/* ===========================================
   Base Container
   
   Framing Structure (Two-Layer Padding):
   Layer 1 - Outer Container (.aif-estimate):
   - Provides equal horizontal borders/framing
   - Desktop: 1rem, Tablet: 0.75rem, Mobile: 0.5rem
   
   Layer 2 - Title/Intro & Form Container (.aif-steps):
   - Additional padding to create visual hierarchy
   - Title/intro get same padding as .aif-steps internals
   - Desktop: 1rem, Tablet/Mobile: 0.75rem

/* ===========================================
   Content Width Constraint
   Match engagement template layout
   =========================================== */
body.aif-estimate-request .site-content,
body.aif-estimate-request .grid-container {
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
}

.page-template-template-engagement-project .entry-header {
  padding-top: clamp(1rem, 2.5vw, 1.8rem);
}

/* ===========================================
   Page-level title and intro alignment
   (for elements outside .aif-estimate container)
   Match container padding + steps padding for proper alignment
   Using hard-coded values since CSS custom properties aren't available outside .aif-estimate
   Only applies to project estimate pages using this template
   =========================================== */
.page-template-template-engagement-project .entry-header .entry-title,
.page-template-template-engagement-project .entry-content .aif-intro {
  padding-left: 1.5rem; /* 1rem (container) + 0.5rem (steps) */
  padding-right: 1.5rem;
}

.page-template-template-engagement-project .entry-content .aif-intro {
  color: #5B6573;
  line-height: 1.6;
}

/* This rule sits outside .aif-estimate, so the theme tokens are not in scope and
   the colour has to be repeated literally - which means the dark theme has to be
   handled here too. #5B6573 on the dark page background is 2.90:1. #A8B0BE gives
   7.84:1 and matches what aif-engagement.css already uses for .aif-intro in dark. */
@media (prefers-color-scheme: dark) {
  .page-template-template-engagement-project .entry-content .aif-intro {
    color: #A8B0BE;
  }
}

@media (max-width: 720px) {
  .page-template-template-engagement-project .entry-header .entry-title,
  .page-template-template-engagement-project .entry-content .aif-intro {
    padding-left: 1.25rem; /* 0.75rem (container) + 0.5rem (steps) */
    padding-right: 1.25rem;
  }
}

@media (max-width: 400px) {
  .page-template-template-engagement-project .entry-header .entry-title,
  .page-template-template-engagement-project .entry-content .aif-intro {
    padding-left: 1rem; /* 0.5rem (container) + 0.5rem (steps) */
    padding-right: 1rem;
  }
}

/* ===========================================
   Base Container
.aif-estimate {
  max-width: 860px;
  margin: var(--aif-space-lg) auto var(--aif-space-2xl);
  padding: 0 var(--aif-space-lg); /* Layer 1: Outer framing */
  font-size: var(--aif-font-size-base);
  line-height: var(--aif-line-height);
  color: var(--aif-color-text);
}

/* Title styling - aligns with form fields inside .aif-steps */
.aif-estimate .aif-title {
  margin: 0 0 var(--aif-space-sm);
  font-weight: 700;
  color: var(--aif-color-text);
}

/* Intro paragraph - aligns with form fields inside .aif-steps */
.aif-estimate .aif-intro {
  margin: 0 0 var(--aif-space-lg);
  color: var(--aif-color-text-secondary);
  line-height: 1.6;
}

/* ===========================================
   Steps Container
   =========================================== */
.aif-steps {
  border: 1px solid var(--aif-color-border);
  border-radius: var(--aif-radius-lg);
  padding: var(--aif-space-sm);  /* Change from lg to sm (1rem → 0.5rem) */
  background: var(--aif-color-bg-elevated);
  box-shadow: var(--aif-shadow-sm);
  margin-top: var(--aif-space-xl);    /* Add this - 1.5rem spacing from top */
  margin-bottom: var(--aif-space-2xl); /* Add this - 2rem spacing from bottom */
}

/* ===========================================
   Step Navigation
   =========================================== */
.aif-stepnav {
  display: flex;
  gap: var(--aif-space-sm);
  flex-wrap: wrap;
  margin: 0 0 var(--aif-space-md);
  padding: 0;
  list-style: none;
}

.aif-stepnav button {
  border: 1px solid var(--aif-color-border);
  background: transparent;
  padding: var(--aif-space-sm) var(--aif-space-md);
  border-radius: var(--aif-radius-full);
  font: inherit;
  font-size: var(--aif-font-size-sm);
  color: var(--aif-color-text);
  cursor: pointer;
  min-height: var(--aif-touch-target);
  min-width: var(--aif-touch-target);
  transition: 
    border-color var(--aif-transition-fast),
    background-color var(--aif-transition-fast),
    box-shadow var(--aif-transition-fast);
}

.aif-stepnav button:hover {
  border-color: var(--aif-color-accent);
  background: var(--aif-color-accent-subtle);
}

.aif-stepnav button:focus-visible {
  outline: none;
  border-color: var(--aif-color-border-focus);
  box-shadow: var(--aif-shadow-focus);
}

.aif-stepnav button[aria-current="step"] {
  border-color: var(--aif-color-accent);
  border-width: 3px;
  background: var(--aif-color-accent-subtle);
  box-shadow: 0 0 0 2px var(--aif-color-accent-ring) inset;
  font-weight: 700;
}

.aif-stepnav button:not([aria-current="step"]) {
  border-color: var(--aif-color-border-strong); /* Darker border */
  color: var(--aif-color-text-secondary); 
}

.aif-stepnav button:not([aria-current="step"]):hover {
  border-color: var(--aif-color-accent);
  background: rgba(196, 181, 253, 0.05); /* Subtle hover tint */
}

/* ===========================================
   Progress Bar
   =========================================== */
.aif-progress {
  height: 10px;
  border-radius: var(--aif-radius-full);
  background: var(--aif-color-bg-hover);
  overflow: hidden;
  margin: var(--aif-space-xs) 0 var(--aif-space-lg);
}

.aif-progress > div {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--aif-color-accent), var(--aif-color-accent-hover));
  transition: width var(--aif-transition-base);
  border-radius: var(--aif-radius-full);
}

/* ===========================================
   Panels
   =========================================== */
.aif-panel {
  display: none;
}

/* Active panel = the one without `inert`. JS toggles `inert` on/off
   (previously aria-hidden true/false) — see panels.forEach in render(). */
.aif-panel:not([inert]) {
  display: block;
  animation: aif-fade-in var(--aif-transition-base);
}

@keyframes aif-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .aif-panel:not([inert]) {
    animation: none;
  }
}

/* ===========================================
   Fieldsets & Legends
   =========================================== */
.aif-fieldset {
  border: 0;
  padding: 0;
  margin: 0;
}

.aif-fieldset + .aif-fieldset {
  margin-top: var(--aif-space-lg);
}

.aif-legend {
  font-weight: 700;
  font-size: var(--aif-font-size-base);
  color: var(--aif-color-text);
  margin: 0 0 var(--aif-space-sm);
  display: block;
  width: 100%;
}

/* ===========================================
   Required Field Indicator
   =========================================== */
.aif-required {
  color: var(--aif-color-error);
  font-weight: 700;
  margin-left: 2px;
}

.aif-required-note {
  font-size: var(--aif-font-size-sm);
  color: var(--aif-color-text-secondary);
  margin: 0 0 var(--aif-space-lg);
  padding: var(--aif-space-sm) var(--aif-space-md);
  background: var(--aif-color-bg);
  border-radius: var(--aif-radius-sm);
}

/* ===========================================
   Form Row Layout
   =========================================== */
.aif-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--aif-space-lg) var(--aif-space-lg);
  margin-top: var(--aif-space-sm);
}

/* ===========================================
   Form Controls
   =========================================== */
.aif-control {
  display: flex;
  flex-direction: column;
}

.aif-control label {
  display: block;
  font-weight: 600;
  font-size: var(--aif-font-size-sm);
  color: var(--aif-color-text);
  margin: 0 0 var(--aif-space-xs);
}

/* Input, Select, Textarea Base Styles */
.aif-control input[type="text"],
.aif-control input[type="email"],
.aif-control input[type="url"],
.aif-control input[type="date"],
.aif-control input[type="number"],
.aif-control select,
.aif-control textarea {
  width: 100%;
  padding: var(--aif-space-md);
  border: 1px solid var(--aif-color-border);
  border-radius: var(--aif-radius-md);
  font: inherit;
  font-size: var(--aif-font-size-base);
  color: var(--aif-color-text);
  background-color: var(--aif-color-bg-input);
  min-height: var(--aif-touch-target);
  transition: 
    border-color var(--aif-transition-fast),
    box-shadow var(--aif-transition-fast),
    background-color var(--aif-transition-fast);
}

.aif-estimate .aif-control select {
  cursor: pointer;
  appearance: none;
  /* Custom dropdown arrow - light mode (uses primary color #2F3A4A) */
  /* Note: CSS background images are decorative and automatically hidden from screen readers */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%232F3A4A' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 20px 20px;
  padding-right: 44px;
}

/* Dark mode dropdown arrow (uses lighter text color for contrast) */
@media (prefers-color-scheme: dark) {
  .aif-control select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23E2E6ED' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  }
}

/* High contrast mode - ensure arrow remains visible */
@media (prefers-contrast: more) {
  .aif-control select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23000000' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  }
  
  @media (prefers-color-scheme: dark) {
    .aif-control select {
      background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23FFFFFF' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    }
  }
}

.aif-control textarea {
  min-height: 120px;
  resize: vertical;
}

/* Placeholder Styles */
.aif-control input::placeholder,
.aif-control textarea::placeholder {
  color: var(--aif-color-text-muted);
  opacity: 1;
}

/* Hover State */
.aif-control input:hover:not(:disabled):not(:focus),
.aif-control select:hover:not(:disabled):not(:focus),
.aif-control textarea:hover:not(:disabled):not(:focus) {
  border-color: var(--aif-color-border-strong);
}

/* Focus State - High Visibility */
.aif-control input:focus,
.aif-control select:focus,
.aif-control textarea:focus {
  outline: none;
  border-color: var(--aif-color-border-focus);
  box-shadow: var(--aif-shadow-focus);
}

/* Disabled State */
.aif-control input:disabled,
.aif-control select:disabled,
.aif-control textarea:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  background: var(--aif-color-bg-hover);
}

/* Standalone Checkbox in .aif-control (e.g., discovery call) */
.aif-control label:has(input[type="checkbox"]) {
  display: flex;
  align-items: center;
  font-weight: 400;
  padding: var(--aif-space-md);
  border: 1px solid var(--aif-color-border);
  border-radius: var(--aif-radius-md);
  min-height: var(--aif-touch-target);
  cursor: pointer;
  margin: 0;
  transition: 
    border-color var(--aif-transition-fast),
    background-color var(--aif-transition-fast);
}

.aif-control label:has(input[type="checkbox"]):hover {
  border-color: var(--aif-color-accent);
  background: var(--aif-color-accent-subtle);
}

.aif-control input[type="checkbox"] {
  width: 24px;
  height: 24px;
  margin: 0 var(--aif-space-sm) 0 0;
  cursor: pointer;
  flex-shrink: 0;
  accent-color: var(--aif-color-accent);
  border: 1px solid var(--aif-color-border-strong);
  border-radius: 4px;
}

.aif-control label:has(input[type="checkbox"]:checked) {
  border-color: var(--aif-color-border);
  background: var(--aif-color-accent-subtle);
}

.aif-control label:has(input[type="checkbox"]:focus-visible) {
  border-color: var(--aif-color-accent);
  border-width: 2px;
  outline: 2px solid var(--aif-color-accent);
  outline-offset: 2px;
  box-shadow: var(--aif-shadow-focus);
}

/* ===========================================
   Hint Text
   =========================================== */
.aif-hint {
  color: var(--aif-color-text-secondary);
  margin: var(--aif-space-xs) 0 0;
  font-size: var(--aif-font-size-sm);
  line-height: 1.4;
}

.aif-hint a {
  color: var(--aif-color-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.aif-hint a:hover {
  color: var(--aif-color-accent-hover);
}

.aif-hint a:focus-visible {
  outline: var(--aif-focus-ring-width) solid var(--aif-color-accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ===========================================
   Checkbox Group
   =========================================== */
.aif-checkbox-group {
  display: flex;
  flex-direction: column;
  gap: var(--aif-space-sm);
  margin-top: var(--aif-space-sm);
}

.aif-checkbox-group label {
  display: flex;
  align-items: center;
  font-weight: 400;
  font-size: var(--aif-font-size-base);
  color: var(--aif-color-text);
  /* Same colour the label already sits on (.aif-steps). Stating it explicitly
     rather than inheriting a transparent background means contrast checkers do
     not have to composite up the ancestor chain to work out what is behind the
     text - the step where several of them go wrong. Visually identical. */
  background-color: var(--aif-color-bg-elevated);
  cursor: pointer;
  padding: var(--aif-space-sm) var(--aif-space-md);
  border: 1px solid var(--aif-color-border);
  border-radius: var(--aif-radius-md);
  min-height: var(--aif-touch-target);
  transition: 
    border-color var(--aif-transition-fast),
    background-color var(--aif-transition-fast);
}

.aif-checkbox-group label:hover {
  border-color: var(--aif-color-accent);
  background: var(--aif-color-accent-subtle);
}

.aif-checkbox-group input[type="checkbox"] {
  width: 24px;
  height: 24px;
  margin: 0 var(--aif-space-sm) 0 0;
  cursor: pointer;
  flex-shrink: 0;
  accent-color: var(--aif-color-accent);
  border: 1px solid var(--aif-color-border-strong);
  border-radius: 4px;
}

.aif-checkbox-group label:has(input:checked) {
  border-color: var(--aif-color-border); /* Same as unselected */
  background: var(--aif-color-accent-subtle);
  border-width: 1px; /* Same as unselected */
}

.aif-checkbox-group label:has(input:focus-visible) {
  border-color: var(--aif-color-accent);
  border-width: 2px;
  outline: 2px solid var(--aif-color-accent);
  outline-offset: 2px;
  box-shadow: var(--aif-shadow-focus);
}

/* ===========================================
   Radio Group
   =========================================== */
.aif-radio-group {
  display: flex;
  flex-direction: column;
  gap: var(--aif-space-sm);
  margin-top: var(--aif-space-sm);
}

.aif-radio-group label {
  display: flex;
  align-items: center;
  padding: var(--aif-space-md);
  border: 1px solid var(--aif-color-border);
  border-radius: var(--aif-radius-md);
  cursor: pointer;
  font-weight: 400;
  font-size: var(--aif-font-size-base);
  color: var(--aif-color-text);
  min-height: var(--aif-touch-target);
  transition: 
    border-color var(--aif-transition-fast),
    background-color var(--aif-transition-fast),
    box-shadow var(--aif-transition-fast);
}

.aif-radio-group label:hover {
  border-color: var(--aif-color-accent);
  background: var(--aif-color-accent-subtle);
}

.aif-radio-group input[type="radio"] {
  margin: 0 var(--aif-space-sm) 0 0;
  width: 20px;
  height: 20px;
  cursor: pointer;
  flex-shrink: 0;
  accent-color: var(--aif-color-accent);
}

.aif-radio-group label:has(input:checked) {
  border-color: var(--aif-color-border); /* Same as unselected */
  border-width: 2px; /* Thicker border - non-color indicator */
  background: var(--aif-color-accent-subtle);
  box-shadow: 0 0 0 2px var(--aif-color-accent-ring);
  font-weight: 600;
}

.aif-radio-group label:has(input:checked) span {
  font-weight: 600;
}

.aif-radio-group label:has(input:focus-visible) {
  outline: none;
  border-color: var(--aif-color-border-focus);
  box-shadow: var(--aif-shadow-focus);
}

/* ===========================================
   Action Buttons
   =========================================== */
.aif-actions {
  display: flex;
  justify-content: space-between; /* Push buttons to opposite ends */
  gap: var(--aif-space-md);
  margin-top: var(--aif-space-xl);
  flex-wrap: wrap;
}

/* When only Next button exists (first step), align it to the right */
.aif-actions:has(.aif-primary:only-child) {
  justify-content: flex-end;
}

.aif-actions button {
  font: inherit;
  font-size: var(--aif-font-size-base);
  font-weight: 600;
  border-radius: var(--aif-radius-md);
  padding: var(--aif-space-md) var(--aif-space-xl);
  border: 2px solid var(--aif-color-border);
  background: transparent;
  color: var(--aif-color-text);
  cursor: pointer;
  min-height: var(--aif-touch-target);
  min-width: 120px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--aif-space-sm);
  transition: 
    border-color var(--aif-transition-fast),
    background-color var(--aif-transition-fast),
    color var(--aif-transition-fast),
    box-shadow var(--aif-transition-fast),
    transform var(--aif-transition-fast);
}

/* Back button - Left arrow */
.aif-actions .aif-secondary::before {
  font-size: 1.25em;
  line-height: 1;
  margin-right: -0.25rem; /* Fine-tune spacing */
}

/* Next/Submit button - Right arrow */
.aif-actions .aif-primary::after {
  font-size: 1.25em;
  line-height: 1;
  margin-left: -0.25rem; /* Fine-tune spacing */
}

.aif-actions button:focus-visible {
  outline: none;
  box-shadow: var(--aif-shadow-focus);
}

.aif-actions button:active {
  transform: scale(0.98);
}

/* Secondary Button */
.aif-actions .aif-secondary {
  border-color: var(--aif-color-primary);
  color: var(--aif-color-primary);
  background: transparent;
}

.aif-actions .aif-secondary:hover {
  background: var(--aif-color-bg-hover);
}

.aif-actions .aif-secondary:focus-visible {
  border-color: var(--aif-color-border-focus);
}

/* Primary Button */
.aif-actions .aif-primary {
  border-color: var(--aif-color-primary);
  background: var(--aif-color-primary);
  color: var(--aif-color-bg);
}

.aif-actions .aif-primary:hover {
  background: var(--aif-color-text);
  border-color: var(--aif-color-text);
}

.aif-actions .aif-primary:focus-visible {
  box-shadow: var(--aif-shadow-focus);
}

.aif-actions .aif-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* ===========================================
   Summary Section
   =========================================== */
.aif-summary {
  border: 1px solid var(--aif-color-border);
  border-radius: var(--aif-radius-lg);
  padding: var(--aif-space-lg);
  background: var(--aif-color-bg);
}

.aif-summary h3 {
  margin: 0 0 var(--aif-space-md);
  font-size: var(--aif-font-size-lg);
  color: var(--aif-color-text);
}

.aif-summary p {
  margin: var(--aif-space-sm) 0;
  color: var(--aif-color-text);
}

.aif-summary strong {
  color: var(--aif-color-text);
}

/* ===========================================
   Error States
   =========================================== */

/* Error Message */
.aif-field-error {
  color: var(--aif-color-error-text);
  font-size: var(--aif-font-size-sm);
  font-weight: 500;
  margin-top: var(--aif-space-sm);
  display: flex;
  align-items: flex-start;
  gap: var(--aif-space-sm);
  padding: var(--aif-space-sm) var(--aif-space-md);
background: transparent;
  border-left: 3px solid var(--aif-color-error);
  border-radius: var(--aif-radius-sm);
  line-height: 1.4;
}

.aif-field-error-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  margin-top: 1px;
}

/* Error message within checkbox/radio groups */
.aif-checkbox-group .aif-field-error,
.aif-radio-group .aif-field-error {
  margin-top: var(--aif-space-md);
}

.aif-checkbox-group.aif-has-error {
  padding: var(--aif-space-sm);
  border: 2px solid var(--aif-color-error);
  border-radius: var(--aif-radius-md);
  background: transparent; /* No background, only border */
}

.aif-radio-group.aif-has-error {
  padding: var(--aif-space-sm);
  border: 2px solid var(--aif-color-error);
  border-radius: var(--aif-radius-md);
  background: transparent; /* No background, only border */
}

/* Consistent error styling for text inputs and dropdowns - matches checkbox/radio groups */
.aif-control.aif-has-error {
  padding: var(--aif-space-sm);
  border: 2px solid var(--aif-color-error);
  border-radius: var(--aif-radius-md);
  background: transparent;
}

/* Ensure the input/select/textarea inside error state doesn't double-border */
.aif-control.aif-has-error input,
.aif-control.aif-has-error select,
.aif-control.aif-has-error textarea {
  border-color: var(--aif-color-border) !important;
  box-shadow: none !important;
}

/* ===========================================
   Scope Sections (conditional)
   =========================================== */
.aif-scope-section {
  padding: var(--aif-space-lg);
  background: var(--aif-color-bg);
  border-radius: var(--aif-radius-md);
  margin-bottom: var(--aif-space-md);
}

.aif-scope-section .aif-fieldset {
  margin: 0;
}

/* ===========================================
   Screen Reader Only Text
   =========================================== */
.screen-reader-text {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* ===========================================
   Mobile Responsive Styles
   =========================================== */
@media (max-width: 720px) {
  .aif-estimate {
    margin: var(--aif-space-md) 0 var(--aif-space-xl); /* Remove horizontal margins */
    padding: 0 var(--aif-space-md); /* Slightly tighter framing on mobile, matches .aif-steps */
  }

  .aif-steps {
  padding: var(--aif-space-sm);  /* Change from md to sm (0.75rem → 0.5rem) */
    border-radius: var(--aif-radius-md);
  }
  
  .aif-row {
    grid-template-columns: 1fr;
    gap: var(--aif-space-md);
  }
  
  .aif-stepnav {
    gap: var(--aif-space-xs);
  }
  
  .aif-stepnav button {
    padding: var(--aif-space-sm);
    font-size: var(--aif-font-size-sm);
    min-height: 48px;
  }
  
  /* Larger touch targets on mobile */
  .aif-control input[type="text"],
  .aif-control input[type="email"],
  .aif-control input[type="url"],
  .aif-control input[type="date"],
  .aif-control input[type="number"],
  .aif-control select,
  .aif-control textarea {
    padding: var(--aif-space-md) var(--aif-space-lg);
    min-height: 48px;
    font-size: 16px; /* Prevents zoom on iOS */
  }
  
  .aif-checkbox-group label,
  .aif-radio-group label {
    padding: var(--aif-space-md);
    min-height: 44px;
  }
  
  /* Standalone checkbox (e.g., discovery call) */
  .aif-control label:has(input[type="checkbox"]) {
    padding: var(--aif-space-md);
    min-height: 44px;
  }
  
  .aif-checkbox-group input[type="checkbox"],
  .aif-radio-group input[type="radio"],
  .aif-control input[type="checkbox"] {
    width: 24px;
    height: 24px;
  }
  
  .aif-actions {
    flex-direction: column-reverse; /* Back button goes below Next button on mobile */
  }
  
  .aif-actions button {
    width: 100%;
    min-height: 44px;
    justify-content: center;
  }
  
  /* On mobile, always align both buttons to stretch full width */
  .aif-actions:has(.aif-primary:only-child) {
    justify-content: stretch; /* Override the flex-end on mobile */
  }
  
  .aif-summary {
    padding: var(--aif-space-md);
  }
  
  .aif-scope-section {
    padding: var(--aif-space-md);
  }
/* Enhanced error visibility on mobile */
  .aif-field-error {
    padding: var(--aif-space-md);
    font-size: 0.9375rem; /* 15px for better readability */
    gap: var(--aif-space-md);
  }
  
  .aif-field-error-icon {
    width: 20px;
    height: 20px;
  }
  
  .aif-has-error select,
  .aif-has-error input,
  .aif-has-error textarea {
    border-width: 2px !important;
  }
}

/* ===========================================
   Small Mobile (< 400px)
   =========================================== */
@media (max-width: 400px) {
  .aif-estimate {
    padding: 0 var(--aif-space-sm); /* Even tighter framing on very small screens */
  }

  .aif-stepnav {
    flex-direction: column;
  }
  
  .aif-stepnav button {
    width: 100%;
    text-align: center;
  }
}

/* ===========================================
   Print Styles
   =========================================== */
@media print {
  .aif-estimate {
    max-width: 100%;
    margin: 0;
  }
  
  .aif-steps {
    border: 1px solid #000;
    box-shadow: none;
  }
  
  .aif-stepnav,
  .aif-progress,
  .aif-actions {
    display: none;
  }
  
  /* Print: show every panel regardless of inert state. */
  .aif-panel,
  .aif-panel[inert] {
    display: block !important;
  }
}

/* ===========================================
   Focus-Visible Polyfill Support
   (for browsers that don't support :focus-visible)
   =========================================== */
.aif-estimate *:focus {
  outline: none;
}

.aif-estimate .js-focus-visible *:focus:not(.focus-visible) {
  outline: none;
  box-shadow: none;
}

/* ===========================================
   Additional Accessibility Enhancements
   =========================================== */

/* Ensure links are distinguishable */
.aif-estimate a {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.aif-estimate a:focus-visible {
  outline: var(--aif-focus-ring-width) solid var(--aif-color-accent);
  outline-offset: var(--aif-focus-ring-offset);
  border-radius: 2px;
}

/* Skip to content link (if added) */
.aif-estimate .skip-link {
  position: absolute;
  top: -100px;
  left: 0;
  background: var(--aif-color-primary);
  color: var(--aif-color-bg);
  padding: var(--aif-space-md);
  z-index: 1000;
  border-radius: var(--aif-radius-md);
}

.aif-estimate .skip-link:focus {
  top: var(--aif-space-md);
}

/* High Contrast - Enhanced Focus */
@media (prefers-contrast: more) {
  .aif-control input:focus,
  .aif-control select:focus,
  .aif-control textarea:focus,
  .aif-actions button:focus-visible,
  .aif-stepnav button:focus-visible {
    outline: 3px solid currentColor !important;
    outline-offset: 2px !important;
    box-shadow: none !important;
  }
  
  .aif-checkbox-group label:has(input:focus-visible),
  .aif-radio-group label:has(input:focus-visible),
  .aif-control label:has(input[type="checkbox"]:focus-visible) {
    outline: 3px solid currentColor !important;
    outline-offset: 2px !important;
  }
}

/* ===========================================
   Forced Colors Mode (Windows High Contrast)
   =========================================== */
@media (forced-colors: active) {
  .aif-steps {
    border: 2px solid CanvasText;
  }
  
  .aif-stepnav button {
    border: 2px solid ButtonBorder;
    background: ButtonFace;
    color: ButtonText;
  }
  
  .aif-stepnav button[aria-current="step"] {
    border: 3px solid Highlight;
    background: Highlight;
    color: HighlightText;
  }
  
  .aif-progress > div {
    background: Highlight;
  }
  
  .aif-control input,
  .aif-control select,
  .aif-control textarea {
    border: 2px solid CanvasText;
  }
  
  .aif-actions .aif-primary {
    background: ButtonFace;
    border: 2px solid ButtonBorder;
    color: ButtonText;
    forced-color-adjust: none;
  }
  
  .aif-has-error input,
  .aif-has-error select,
  .aif-has-error textarea {
    border: 3px solid Mark !important;
  }
  
  .aif-checkbox-group label:has(input:checked),
  .aif-radio-group label:has(input:checked),
  .aif-control label:has(input[type="checkbox"]:checked) {
    border: 2px solid Highlight;
    background: transparent;
  }
}
