/* ==========================================================================
   Casa Scotia - Base Styles
   Foundation styles, variables, reset, layout, and utilities

   TABLE OF CONTENTS:
   1. CSS Custom Properties (Variables)
   2. Reset & Base Styles
   3. Typography
   4. Layout (Container, Grid, Sections)
   5. Utilities
   5.5. Mobile Foundation
   5.6. Global Focus Indicators
   6. Reduced Motion & Print Overrides
   ========================================================================== */

/* ==========================================================================
   1. CSS Custom Properties (Variables)
   ========================================================================== */

:root {
  /* Green - Primary accent */
  --green: #5D7652;
  --green-900: #3a4a33;
  --green-800: #43573b;
  --green-700: #4a6342;
  --green-600: #537049;
  --green-500: #5D7652; /* Primary */
  --green-400: #7d9974;
  --green-300: #9db896;
  --green-200: #c5d4bf;
  --green-100: #eef3ec;

  /* Gold - CTA accent */
  --gold: #e6b042;
  --gold-900: #8b6a1f;
  --gold-700: #c49830;
  --gold-600: #d4a438;
  --gold-500: #e6b042; /* Primary CTA */
  --gold-400: #ecc06a;
  --gold-200: #f5dea0;
  --gold-100: #fdf6e3;

  /* Charcoal - Text and dark sections */
  --charcoal-900: #1E1E1E;
  --charcoal-800: #2C2C2C;
  --charcoal-750: #333333;
  --charcoal-700: #3d3d3d;
  --charcoal-600: #4B5563;

  /* Neutrals - Backgrounds and borders */
  --white: #ffffff;
  --warm-white: #FAFAF8;
  --gray-50: #FAFAF8;
  --gray-100: #F0EDE8;
  --gray-200: #E0DDD8;
  --gray-300: #d1cdc7;
  --gray-400: #9CA3AF;
  --gray-500: #6B6B6B;
  --gray-600: #4B5563;
  --gray-700: #374151;

  /* Surface Elevation System */
  --surface-0: #ffffff;
  --surface-1: #FAFAF8;
  --surface-2: #F0EDE8;
  --surface-3: #E0DDD8;

  /* Feedback */
  --success: #2E7D32;
  --success-light: #dcfce7;
  --error: #D32F2F;
  --error-light: #fee2e2;
  --warning: #d97706;
  --warning-light: #fef3c7;

  /* Links */
  --link: #5D7652;
  --link-hover: #4a6342;
  --link-visited: #3a4a33;

  /* Typography */
  --font-display: "Montserrat", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-body:
    "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", Monaco, "Courier New", monospace;

  /* Type Scale (fluid with clamp) */
  --text-display-xl: clamp(2.5rem, 5vw, 4rem);
  --text-display-lg: clamp(2rem, 4vw, 3rem);
  --text-display-md: clamp(1.5rem, 3vw, 2rem);
  --text-3xl: 1.875rem;
  --text-2xl: 1.5rem;
  --text-xl: 1.25rem;
  --text-lg: 1.125rem;
  --text-base: 1rem;
  --text-sm: 0.875rem;
  --text-xs: 0.75rem;

  /* Line Heights */
  --leading-tight: 1.1;
  --leading-snug: 1.3;
  --leading-normal: 1.6;
  --leading-relaxed: 1.65;

  /* Letter Spacing */
  --tracking-tight: -0.02em;
  --tracking-normal: 0;
  --tracking-wide: 0.05em;
  --tracking-wider: 0.1em;

  /* Spacing (8px base with half-steps) */
  --space-px: 1px;
  --space-0-5: 0.125rem; /* 2px */
  --space-1: 0.25rem; /* 4px */
  --space-1-5: 0.375rem; /* 6px */
  --space-2: 0.5rem; /* 8px */
  --space-2-5: 0.625rem; /* 10px */
  --space-3: 0.75rem; /* 12px */
  --space-3-5: 0.875rem; /* 14px */
  --space-4: 1rem; /* 16px */
  --space-5: 1.25rem; /* 20px */
  --space-6: 1.5rem; /* 24px */
  --space-7: 1.75rem; /* 28px */
  --space-8: 2rem; /* 32px */
  --space-9: 2.25rem; /* 36px */
  --space-10: 2.5rem; /* 40px */
  --space-12: 3rem; /* 48px */
  --space-14: 3.5rem; /* 56px */
  --space-16: 4rem; /* 64px */
  --space-18: 4.5rem; /* 72px */
  --space-20: 5rem; /* 80px */
  --space-22: 5.5rem; /* 88px */
  --space-24: 6rem; /* 96px */
  --space-32: 8rem; /* 128px */

  /* Legacy spacing aliases (for existing pages) */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  --space-3xl: 4rem;
  --space-4xl: 6rem;
  --space-5xl: 8rem;

  /* Legacy color aliases (for existing pages) */
  --color-primary: #5D7652;
  --color-primary-dark: #4a6342;
  --color-secondary: #7d9974;
  --color-accent: #e6b042;
  --color-accent-dark: #d4a438;
  --color-bg: #FAFAF8;
  --color-bg-alt: #F0EDE8;
  --color-text: #2C2C2C;
  --color-text-light: #6B6B6B;
  --color-white: #FFFFFF;
  --color-border: #E0DDD8;
  --color-error: #D32F2F;
  --color-success: #2E7D32;
  --color-charcoal: #1E1E1E;
  --color-charcoal-light: #2A2A2A;
  --color-gray-400: #9CA3AF;
  --color-gray-600: #4B5563;
  --font-heading: "Montserrat", -apple-system, BlinkMacSystemFont, sans-serif; /* Legacy alias for --font-display */

  /* Container Widths */
  --container-sm: 640px;
  --container-md: 768px;
  --container-lg: 1024px;
  --container-xl: 1280px;
  --container-2xl: 1440px;
  --max-width: 1280px;
  --max-width-narrow: 800px;

  /* Touch Targets (WCAG 2.1 AA) */
  --touch-target-min: 44px;
  --touch-target-comfortable: 48px;
  --touch-spacing-min: 8px;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg:
    0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl:
    0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
  /* Unused — available for future use */
  --shadow-green: 0 4px 14px 0 rgb(93 118 82 / 0.3);
  --shadow-green-lg: 0 8px 24px 0 rgb(93 118 82 / 0.4);
  --shadow-gold: 0 4px 14px 0 rgb(230 176 66 / 0.3);
  --shadow-gold-lg: 0 8px 24px 0 rgb(230 176 66 / 0.4);
  --shadow-elevated:
    0 1px 2px rgb(0 0 0 / 0.04), 0 4px 8px rgb(0 0 0 / 0.04),
    0 12px 24px rgb(0 0 0 / 0.06);
  --shadow-focus: 0 0 0 3px rgb(230 176 66 / 0.15);
  --shadow-focus-green: 0 0 0 3px rgb(93 118 82 / 0.15);
  --shadow-focus-error: 0 0 0 3px rgb(211 47 47 / 0.15);

  /* Legacy shadow aliases */
  --shadow-glow-green: 0 4px 15px rgba(93, 118, 82, 0.3);
  --shadow-glow-accent: 0 4px 15px rgba(230, 176, 66, 0.3);

  /* Border Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-2xl: 24px;
  --radius-full: 9999px;

  /* Z-Index — Unused (all z-indexes are currently hardcoded) */
  --z-base: 0;
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-fixed: 300;
  --z-modal-backdrop: 400;
  --z-modal: 500;
  --z-popover: 600;
  --z-tooltip: 700;

  /* Animation */
  --ease-default: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  --ease-out: cubic-bezier(0, 0, 0.2, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-expo-out: cubic-bezier(0.16, 1, 0.3, 1);
  --duration-fast: 150ms;
  --duration-normal: 300ms;
  --duration-slow: 500ms;
  --duration-slower: 700ms;

  /* Legacy transition aliases */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 400ms ease;
}

/* ==========================================================================
   2. Reset & Base Styles
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--charcoal-900);
  background-color: var(--warm-white);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
  height: auto;
}

input,
button,
textarea,
select {
  font: inherit;
}

p,
h1,
h2,
h3,
h4,
h5,
h6 {
  overflow-wrap: break-word;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  text-wrap: balance;
}

a {
  color: inherit;
  text-decoration: none;
}

ul,
ol {
  list-style: none;
}

button {
  background: none;
  border: none;
  cursor: pointer;
}

/* ==========================================================================
   3. Typography
   ========================================================================== */

.text-hero {
  font-family: var(--font-display);
  font-size: var(--text-display-xl);
  font-weight: 700;
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
  color: var(--charcoal-900);
}

.text-section {
  font-family: var(--font-display);
  font-size: var(--text-display-lg);
  font-weight: 700;
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
  color: var(--charcoal-900);
}

.text-subsection {
  font-family: var(--font-display);
  font-size: var(--text-display-md);
  font-weight: 600;
  line-height: var(--leading-snug);
  color: var(--charcoal-900);
}

.text-lead {
  font-family: var(--font-body);
  font-size: var(--text-xl);
  font-weight: 400;
  line-height: var(--leading-normal);
  color: var(--gray-600);
}

.text-body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: 400;
  line-height: var(--leading-normal);
  color: var(--charcoal-900);
}

.text-stat {
  font-family: var(--font-mono);
  font-size: var(--text-display-lg);
  font-weight: 500;
  line-height: 1;
  color: var(--green-500);
}

.text-label {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--gray-500);
}

.text-button {
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
}

/* Legacy heading styles (for existing pages) */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: var(--leading-snug);
  color: var(--charcoal-900);
  letter-spacing: var(--tracking-tight);
}

h1 { font-size: var(--text-display-xl); }
h2 { font-size: var(--text-display-lg); }
h3 { font-size: var(--text-display-md); }
h4 { font-size: var(--text-xl); }
h5 { font-size: var(--text-lg); }
h6 { font-size: var(--text-base); }

/* Content Links - Enhanced underline animation */
.text-body a:not(.btn),
.text-lead a:not(.btn),
.content-block a:not(.btn),
p a:not(.btn) {
  color: var(--green-500);
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 4px;
  text-decoration-thickness: 2px;
  transition: text-decoration-color var(--duration-normal) var(--ease-out);
}

.text-body a:not(.btn):hover,
.text-lead a:not(.btn):hover,
.content-block a:not(.btn):hover,
p a:not(.btn):hover {
  text-decoration-color: var(--green-500);
}

/* ==========================================================================
   4. Layout (Container, Grid, Sections)
   ========================================================================== */

.container {
  width: 100%;
  max-width: var(--container-xl);
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--space-4);
  padding-right: var(--space-4);
}

@media (min-width: 768px) {
  .container {
    padding-left: var(--space-6);
    padding-right: var(--space-6);
  }
}

@media (min-width: 1024px) {
  .container {
    padding-left: var(--space-8);
    padding-right: var(--space-8);
  }
}

.container--narrow {
  max-width: var(--container-md);
}

.container--wide {
  max-width: var(--container-2xl);
}

/* Sections */
.section {
  padding-top: var(--space-10);
  padding-bottom: var(--space-10);
}

@media (min-width: 768px) {
  .section {
    padding-top: var(--space-18);
    padding-bottom: var(--space-18);
  }
}

@media (min-width: 1024px) {
  .section {
    padding-top: var(--space-22);
    padding-bottom: var(--space-22);
  }
}

.section--sm {
  padding-top: var(--space-12);
  padding-bottom: var(--space-12);
}

@media (min-width: 768px) {
  .section--sm {
    padding-top: var(--space-16);
    padding-bottom: var(--space-16);
  }
}

.section--alt {
  background-color: var(--gray-100);
}

.section--dark {
  background-color: var(--charcoal-800);
  color: var(--white);
}

.section--dark h2,
.section--dark h3 {
  color: var(--white);
}

.section--dark p {
  color: var(--gray-300);
}

.section__header {
  text-align: center;
  margin-bottom: var(--space-6);
}

@media (min-width: 768px) {
  .section__header {
    margin-bottom: var(--space-10);
  }
}

.section__title {
  margin-bottom: var(--space-4);
}

.section__subtitle {
  max-width: min(60ch, 100%);
  margin-left: auto;
  margin-right: auto;
}

/* Grid System */
.grid {
  display: grid;
  gap: var(--space-5);
}

.grid--2 {
  grid-template-columns: 1fr;
}

@media (min-width: 768px) {
  .grid--2 {
    grid-template-columns: repeat(2, 1fr);
  }
}

.grid--3 {
  grid-template-columns: 1fr;
}

@media (min-width: 640px) {
  .grid--3 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .grid--3 {
    grid-template-columns: repeat(3, 1fr);
  }
}

.grid--4 {
  grid-template-columns: repeat(2, 1fr);
}

@media (max-width: 479px) {
  .grid--4 {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 1024px) {
  .grid--4 {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* ==========================================================================
   5. Utilities
   ========================================================================== */

/* Text alignment */
.text-left { text-align: left; }
.text-center { text-align: center; }
.text-right { text-align: right; }

/* Display */
.hidden { display: none; }
.block { display: block; }
.flex { display: flex; }
.inline-flex { display: inline-flex; }

/* Flex utilities */
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.flex--center { display: flex; align-items: center; justify-content: center; }
.flex--between { display: flex; align-items: center; justify-content: space-between; }

/* Gap utilities */
.gap-2 { gap: var(--space-2); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }
.gap-8 { gap: var(--space-8); }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }

/* Margin utilities */
.mt-0 { margin-top: 0; }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }
.mt-12 { margin-top: var(--space-12); }
.mb-0 { margin-bottom: 0; }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.mb-8 { margin-bottom: var(--space-8); }
.mb-12 { margin-bottom: var(--space-12); }
.mx-auto { margin-left: auto; margin-right: auto; }

/* Legacy margin utilities */
.mt-xs  { margin-top: var(--space-xs); }
.mt-sm  { margin-top: var(--space-sm); }
.mt-md  { margin-top: var(--space-md); }
.mt-lg  { margin-top: var(--space-lg); }
.mt-xl  { margin-top: var(--space-xl); }
.mt-2xl { margin-top: var(--space-2xl); }
.mt-3xl { margin-top: var(--space-3xl); }
.mb-xs  { margin-bottom: var(--space-xs); }
.mb-sm  { margin-bottom: var(--space-sm); }
.mb-md  { margin-bottom: var(--space-md); }
.mb-lg  { margin-bottom: var(--space-lg); }
.mb-xl  { margin-bottom: var(--space-xl); }
.mb-2xl { margin-bottom: var(--space-2xl); }
.mb-3xl { margin-bottom: var(--space-3xl); }

/* Padding utilities */
.p-4 { padding: var(--space-4); }
.p-6 { padding: var(--space-6); }
.p-8 { padding: var(--space-8); }
.py-4 { padding-top: var(--space-4); padding-bottom: var(--space-4); }
.py-8 { padding-top: var(--space-8); padding-bottom: var(--space-8); }
.px-4 { padding-left: var(--space-4); padding-right: var(--space-4); }

/* Legacy padding */
.py-xs  { padding-block: var(--space-xs); }
.py-sm  { padding-block: var(--space-sm); }
.py-md  { padding-block: var(--space-md); }
.py-lg  { padding-block: var(--space-lg); }
.py-xl  { padding-block: var(--space-xl); }
.py-2xl { padding-block: var(--space-2xl); }
.py-3xl { padding-block: var(--space-3xl); }

/* Width */
.w-full { width: 100%; }
.max-w-prose { max-width: 65ch; }
.max-w-md { max-width: var(--container-md); }
.max-w-lg { max-width: var(--container-lg); }

/* Responsive visibility */
@media (max-width: 767px) {
  .hide-mobile { display: none !important; }
}
@media (min-width: 768px) {
  .hide-desktop { display: none !important; }
}

/* ==========================================================================
   5.5. Mobile Foundation
   ========================================================================== */

/* Touch Target Base Styles */
.touch-target {
  min-width: var(--touch-target-min);
  min-height: var(--touch-target-min);
}

/* Mobile-specific button sizing */
@media (max-width: 767px) {
  button,
  [role="button"],
  .btn,
  input[type="button"],
  input[type="submit"] {
    min-height: var(--touch-target-comfortable);
  }
}

/* Mobile Stack Utilities */
.mobile-stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

@media (min-width: 768px) {
  .mobile-stack {
    flex-direction: row;
  }
}

/* Mobile Full Width */
.mobile-full { width: 100%; }

@media (min-width: 768px) {
  .mobile-full { width: auto; }
}

/* Mobile Center */
@media (max-width: 767px) {
  .mobile-center {
    text-align: center;
    margin-left: auto;
    margin-right: auto;
  }
}

/* Responsive Text Alignment */
@media (max-width: 767px) {
  .md\:text-left { text-align: center; }
}
@media (min-width: 768px) {
  .md\:text-left { text-align: left; }
}

/* Responsive Gap */
.responsive-gap { gap: var(--space-4); }

@media (min-width: 768px) {
  .responsive-gap { gap: var(--space-6); }
}

@media (min-width: 1024px) {
  .responsive-gap { gap: var(--space-8); }
}

/* Prevent Horizontal Overflow */
.overflow-safe {
  max-width: 100%;
  overflow-x: hidden;
}

/* Mobile-Optimized Form Inputs */
@media (max-width: 767px) {
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="number"],
  input[type="password"],
  input[type="search"],
  input[type="url"],
  textarea,
  select {
    width: 100%;
    min-height: var(--touch-target-comfortable);
    font-size: 16px; /* Prevents iOS zoom on focus */
  }
}

/* Responsive Hide/Show Utilities */
.show-sm { display: none; }
.show-md { display: none; }
.show-lg { display: none; }

@media (min-width: 640px) {
  .hide-sm { display: none !important; }
  .show-sm { display: block; }
  .show-sm-flex { display: flex; }
}

@media (min-width: 768px) {
  .hide-md { display: none !important; }
  .show-md { display: block; }
  .show-md-flex { display: flex; }
}

@media (min-width: 1024px) {
  .hide-lg { display: none !important; }
  .show-lg { display: block; }
  .show-lg-flex { display: flex; }
}

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

/* ==========================================================================
   5.6. Global Focus Indicators
   ========================================================================== */

:focus-visible {
  outline: 2px solid var(--gold-500);
  outline-offset: 2px;
}

a:focus-visible {
  text-decoration: underline;
  text-decoration-color: var(--gold-500);
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
}

*:focus:not(:focus-visible) {
  outline: none;
}

/* ==========================================================================
   5.7. Skip Link (Accessibility)
   ========================================================================== */

.skip-link {
  position: absolute;
  top: -100%;
  left: 16px;
  z-index: 10000;
  padding: 12px 24px;
  background: var(--gold-500);
  color: var(--charcoal-900);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.875rem;
  text-decoration: none;
  border-radius: 0 0 8px 8px;
  transition: top 0.2s ease;
}

.skip-link:focus {
  top: 0;
  outline: 2px solid var(--gold-500);
  outline-offset: 2px;
}

/* ==========================================================================
   6. Reduced Motion & Print Overrides
   ========================================================================== */

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

  html {
    scroll-behavior: auto;
  }

  .reveal,
  .reveal-stagger > *,
  .animate-on-scroll {
    opacity: 1;
    transform: none;
  }
}

@media print {
  .header,
  .footer,
  .mobile-menu,
  .btn,
  .final-cta {
    display: none !important;
  }

  body {
    background: white;
    color: black;
  }

  .section,
  .section--alt,
  .section--dark {
    background: white;
    color: black;
    padding: 1rem 0;
  }

  .section--dark h2,
  .section--dark h3,
  .section--dark p {
    color: black;
  }

  .reveal,
  .animate-on-scroll {
    opacity: 1 !important;
    transform: none !important;
  }

  a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
    color: #666;
  }

  .section {
    break-inside: avoid;
  }

  h2, h3 {
    break-after: avoid;
  }
}
