/*
Theme Name: In The Loop
Theme URI: https://itlsoftware.company
Author: In The Loop Software Company
Author URI: https://worzl.ai
Description: Civic Gazette & Sovereign Commerce Full Site Editing (FSE) block theme for In The Loop hyper-local market town directory, voucher engine, and Small Business OS.
Version: 2.0.0
Requires at least: 6.6
Tested up to: 6.7
Requires PHP: 8.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: intheloop-theme
Tags: full-site-editing, block-patterns, block-styles, custom-colors, custom-typography, fluid-layout, wide-blocks, mobile-responsive
*/

/* ==========================================================================
   1. CIVIC GAZETTE & SOVEREIGN COMMERCE DESIGN TOKENS
   ========================================================================== */

:root {
  /* --- Typography Font Families --- */
  --font-serif: 'Newsreader', Georgia, serif;
  --font-heading: 'Newsreader', Georgia, serif;
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-body: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* --- Fluid Typography Scales (320px -> 1320px Viewport) --- */
  --text-xs: clamp(0.75rem, calc(0.12vw + 0.73rem), 0.8125rem);
  --text-s: clamp(0.875rem, calc(0.18vw + 0.84rem), 0.9375rem);
  --text-m: clamp(1rem, calc(0.22vw + 0.95rem), 1.0625rem);
  --text-l: clamp(1.125rem, calc(0.4vw + 1.05rem), 1.3125rem);
  --text-xl: clamp(1.375rem, calc(0.7vw + 1.22rem), 1.75rem);
  --text-2xl: clamp(1.85rem, calc(1.3vw + 1.55rem), 2.65rem);
  --text-3xl: clamp(2.35rem, calc(2.2vw + 1.85rem), 3.65rem);
  --text-4xl: clamp(2.75rem, calc(2.75vw + 2.2rem), 4.25rem);

  /* --- Fluid Spacing Rhythm --- */
  --space-3xs: clamp(0.25rem, calc(0.08vw + 0.23rem), 0.375rem);
  --space-2xs: clamp(0.5rem, calc(0.15vw + 0.47rem), 0.625rem);
  --space-xs: clamp(0.75rem, calc(0.25vw + 0.70rem), 1rem);
  --space-s: clamp(1rem, calc(0.35vw + 0.93rem), 1.25rem);
  --space-m: clamp(1.5rem, calc(0.65vw + 1.37rem), 2rem);
  --space-l: clamp(2rem, calc(1.05vw + 1.79rem), 3rem);
  --space-xl: clamp(3rem, calc(1.45vw + 2.71rem), 4rem);
  --space-2xl: clamp(4rem, calc(1.85vw + 3.63rem), 5rem);
  --space-3xl: clamp(5rem, calc(2.25vw + 4.55rem), 6.25rem);

  /* --- Civic Gazette Color Tokens --- */
  --base: #FAF7F2;              /* Warm Alabaster Paper */
  --surface: #FFFFFF;           /* Pure Ivory */
  --surface-low: #F2ECE1;       /* Warm Limestone */
  --primary: #14362B;           /* British Heritage Forest */
  --primary-light: #1F4E3E;     /* Heritage Sage */
  --contrast-stage: #0D1F18;    /* Woodland Obsidian */
  --accent: #C85A32;            /* Burnished Terracotta Copper */
  --town-gold: #C59B27;         /* Champagne Brass */
  --brass: #C59B27;             /* Champagne Brass Alias */
  --contrast: #18181B;          /* Espresso Ink */
  --muted: #57534E;             /* Warm Stone */
  --border-stone: #E6E0D5;      /* Neutral 200 Warm Hairline */
  --border-parchment: #D1C9BC;  /* Neutral 300 Aged Parchment */

  /* --- Legacy Core Framework Aliases --- */
  --bg-body: var(--base);
  --bg-surface: var(--surface);
  --bg-contrast: var(--contrast-stage);
  --text-title: var(--contrast);
  --text-body: var(--muted);

  /* --- Shadows & Radii --- */
  --shadow-sm: 0 2px 6px rgba(20, 54, 43, 0.05);
  --shadow-md: 0 10px 30px -10px rgba(20, 54, 43, 0.08);
  --shadow-lg: 0 20px 40px -12px rgba(13, 31, 24, 0.16);
  --shadow-brass: 0 12px 28px -8px rgba(197, 155, 39, 0.22);
  --shadow-copper: 0 10px 24px -6px rgba(200, 90, 50, 0.28);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-pill: 9999px;
  --ease-spring: cubic-bezier(0.22, 1, 0.36, 1);
}

/* ==========================================================================
   2. BASE RESETS, ACCESSIBILITY & GUTENBERG MOBILE ENHANCEMENTS
   ========================================================================== */

html, body, body * {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background-color: var(--base);
  color: var(--contrast);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, .itl-serif {
  font-family: var(--font-serif);
  letter-spacing: -0.02em;
}

code, pre, .itl-mono {
  font-family: var(--font-mono);
}

/* Crisp WCAG 2.2 Keyboard Focus Ring (Burnished Terracotta Copper) */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[role="button"]:focus-visible,
[data-copy-code]:focus-visible,
[data-itl-filter]:focus-visible,
.wp-element-button:focus-visible,
.wp-block-button__link:focus-visible {
  outline: 2px solid #C85A32 !important;
  outline-offset: 2px !important;
}

/* Sticky Header with Warm Paper Glass Elevation */
#header,
header.wp-block-template-part {
  position: sticky;
  top: 0;
  z-index: 1000;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

/* Mobile Navigation Breakpoint & Drawer Fix */
body .wp-block-navigation__responsive-container-open:not(.always-shown) {
  display: block !important;
}
body .wp-block-navigation__responsive-container:not(.hidden-by-default):not(.is-menu-open) {
  display: none !important;
}
@media (min-width: 768px) {
  body .wp-block-navigation__responsive-container-open:not(.always-shown) {
    display: none !important;
  }
  body .wp-block-navigation__responsive-container:not(.hidden-by-default):not(.is-menu-open) {
    display: block !important;
  }
}

/* Navigation alignment & logo link fix */
.wp-block-navigation__container {
  flex-wrap: nowrap;
}
.wp-block-navigation-item__label {
  text-align: center;
  line-height: 1.25;
}
.wp-block-site-logo a {
  width: 100%;
}
ul.wp-block-navigation-submenu {
  left: -1px !important;
  min-width: unset !important;
}

/* Fix Mobile Column Flex-Basis Stacking (Gutenberg Bugfix) */
@media (max-width: 781px) {
  .wp-block-columns:not(.is-not-stacked-on-mobile) > .wp-block-column {
    flex-basis: 0 !important;
    min-width: 100% !important;
  }
}
:where(.wp-block-columns) {
  margin-bottom: 0 !important;
}

/* Cover Block Inner Container Flex Inheritance */
.wp-block-cover__inner-container {
  display: flex;
  justify-content: inherit;
  align-content: inherit;
  align-items: inherit;
  flex-direction: inherit;
}

/* Image & Featured Image Overflow & Border Radius Fix */
.wp-block-post-featured-image {
  overflow: hidden;
}
.wp-block-image figure {
  overflow: hidden !important;
}
.wp-block-image img,
.wp-block-image picture,
.wp-block-image picture img,
html :where(img[class*=wp-image-]) {
  width: 100%;
  border-radius: inherit !important;
}

/* Remove top margin on first heading/paragraph inside cards */
div > p:first-child:not(.heroHeader *),
div > a:first-child:not(.heroHeader *),
div > .wp-block-heading:first-child:not(.heroHeader *),
div > .wp-block-post-title:first-child:not(.heroHeader *),
div > .wp-block-post-date:first-child:not(.heroHeader *) {
  margin-top: 0;
}

/* Touch Target Mandate (>= 44x44px) & Tactile Button Transitions */
.wp-element-button,
.wp-block-button__link,
.itl-town-pill,
.itl-copy-btn,
[data-copy-code],
[data-itl-filter] {
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.22s var(--ease-spring), box-shadow 0.22s var(--ease-spring), background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.wp-element-button:hover,
.wp-block-button__link:hover {
  transform: translateY(-2px);
  filter: brightness(1.06);
}

.wp-element-button:active,
.wp-block-button__link:active,
.itl-copy-btn:active {
  transform: translateY(0);
}

/* ==========================================================================
   3. CIVIC GAZETTE & SOVEREIGN COMMERCE SIGNATURE COMPONENTS
   ========================================================================== */

/* 3.1 Perforated Voucher Stub (shaped-cutouts guidance) */
.itl-voucher-stub {
  position: relative;
  background-color: var(--surface-low);
  color: var(--contrast);
  border: 1.5px dashed var(--town-gold);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.75rem !important;
  -webkit-mask-image: radial-gradient(circle at 0 50%, transparent 10px, black 10.5px), radial-gradient(circle at 100% 50%, transparent 10px, black 10.5px);
  -webkit-mask-composite: destination-in;
  mask-image: radial-gradient(circle at 0 50%, transparent 10px, black 10.5px), radial-gradient(circle at 100% 50%, transparent 10px, black 10.5px);
  mask-composite: intersect;
  transition: transform 0.22s var(--ease-spring), border-color 0.2s ease;
}

.itl-voucher-stub--dark {
  background-color: rgba(20, 54, 43, 0.72);
  color: var(--base);
  border-color: rgba(197, 155, 39, 0.65);
}

/* 3.2 Deferred Below-the-Fold Section Rendering (defer-rendering-heavy-content) */
.itl-section-deferred {
  content-visibility: auto;
  contain-intrinsic-size: auto 520px;
  contain-intrinsic-size: auto none auto 520px;
}

/* 3.3 12-Column Editorial Bento Grid & Cards */
.itl-bento-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 1.5rem;
  width: 100%;
}

.itl-bento-span-12 { grid-column: span 12 / span 12; }
.itl-bento-span-8  { grid-column: span 8 / span 8; }
.itl-bento-span-7  { grid-column: span 7 / span 7; }
.itl-bento-span-6  { grid-column: span 6 / span 6; }
.itl-bento-span-5  { grid-column: span 5 / span 5; }
.itl-bento-span-4  { grid-column: span 4 / span 4; }

@media (max-width: 960px) {
  .itl-bento-span-8,
  .itl-bento-span-7,
  .itl-bento-span-6,
  .itl-bento-span-5,
  .itl-bento-span-4 {
    grid-column: span 6 / span 6;
  }
}

@media (max-width: 767px) {
  .itl-bento-grid {
    grid-template-columns: 1fr;
    gap: 1.25rem;
  }
  .itl-bento-span-12,
  .itl-bento-span-8,
  .itl-bento-span-7,
  .itl-bento-span-6,
  .itl-bento-span-5,
  .itl-bento-span-4 {
    grid-column: 1 / -1;
  }
}

.itl-bento-card {
  position: relative;
  background-color: var(--surface);
  border: 1px solid var(--border-stone);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  transition: transform 0.24s var(--ease-spring), box-shadow 0.24s var(--ease-spring), border-color 0.24s ease;
  overflow: hidden;
}

.itl-bento-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--town-gold);
}

.itl-bento-card--promoted {
  border-top: 3px solid var(--town-gold);
}

/* 3.4 Verified Regional Trades & B2B Supply Chain Guild Card */
.itl-trade-card {
  position: relative;
  background-color: rgba(20, 54, 43, 0.55);
  border: 1px solid rgba(197, 155, 39, 0.32);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  color: var(--base);
  transition: transform 0.22s var(--ease-spring), border-color 0.22s ease, background-color 0.22s ease;
}

.itl-trade-card:hover {
  transform: translateY(-2px);
  border-color: var(--town-gold);
  background-color: rgba(31, 78, 62, 0.72);
}

.itl-trade-card--light {
  background-color: var(--surface);
  color: var(--contrast);
  border: 1px solid var(--border-parchment);
  border-left: 4px solid var(--primary);
  box-shadow: var(--shadow-sm);
}

/* 3.5 Champagne Brass Sovereign Partner Seal */
.itl-brass-seal {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.85rem;
  border-radius: var(--radius-pill);
  background: rgba(197, 155, 39, 0.14);
  color: #9A7414;
  border: 1px solid rgba(197, 155, 39, 0.48);
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  line-height: 1.2;
}

.has-contrast-stage-background-color .itl-brass-seal,
.itl-stage-dark .itl-brass-seal {
  background: rgba(197, 155, 39, 0.18);
  color: #E8C75A;
  border-color: rgba(197, 155, 39, 0.55);
}

/* 3.6 Town Switcher & Filter Pills */
.itl-town-pill {
  padding: 0.5rem 1rem;
  border-radius: var(--radius-pill);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none !important;
  color: var(--contrast);
  background-color: var(--surface);
  border: 1px solid var(--border-parchment);
  gap: 0.4rem;
}

.itl-town-pill:hover,
.itl-town-pill.is-active,
[data-itl-filter].is-active {
  background-color: var(--primary) !important;
  color: var(--base) !important;
  border-color: var(--primary) !important;
}

/* 3.7 Voucher Copy Button */
.itl-copy-btn {
  padding: 0.5rem 1.1rem;
  border-radius: var(--radius-sm);
  background-color: var(--accent);
  color: #FFFFFF !important;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  border: 1px solid transparent;
  text-decoration: none !important;
  gap: 0.45rem;
  box-shadow: var(--shadow-sm);
}

.itl-copy-btn:hover {
  background-color: #B24C26;
  transform: translateY(-1px);
  box-shadow: var(--shadow-copper);
}

.itl-copy-btn.is-copied {
  background-color: var(--primary) !important;
  border-color: var(--town-gold) !important;
  color: #FFFFFF !important;
}

/* 3.8 Saturday High Street Itinerary Step */
.itl-itinerary-step {
  position: relative;
  background-color: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(197, 155, 39, 0.28);
  border-top: 3px solid var(--town-gold);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  transition: transform 0.22s var(--ease-spring), border-color 0.22s ease, background-color 0.22s ease;
}

.itl-itinerary-step:hover {
  transform: translateY(-3px);
  background-color: rgba(255, 255, 255, 0.07);
  border-color: var(--town-gold);
}

/* 3.9 Sticky Storefront Sidebar (Map, Parking, Hours) */
.itl-sticky-sidebar {
  position: sticky;
  top: 6rem;
  align-self: start;
}

@media (max-width: 960px) {
  .itl-sticky-sidebar {
    position: static;
  }
}

/* Zero-Reload Category Filter State */
.itl-filterable-card.is-filtered-out {
  display: none !important;
}

/* ==========================================================================
   4. LEGACY CORE FRAMEWORK UTILITY COMPATIBILITY
   ========================================================================== */

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  gap: 0.5rem;
  background-color: var(--primary) !important;
  color: var(--base) !important;
  font-weight: 700;
  font-size: var(--text-s);
  padding: 12px 26px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  border: 1px solid var(--primary);
  transition: transform 0.22s var(--ease-spring), box-shadow 0.22s var(--ease-spring);
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover {
  transform: translateY(-2px);
  background-color: var(--primary-light) !important;
  box-shadow: var(--shadow-md);
}

.btn-accent {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  gap: 0.5rem;
  background-color: var(--accent) !important;
  color: #FFFFFF !important;
  font-weight: 700;
  font-size: var(--text-s);
  padding: 12px 26px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  border: 1px solid var(--accent);
  transition: transform 0.22s var(--ease-spring), box-shadow 0.22s var(--ease-spring);
  box-shadow: var(--shadow-sm);
}
.btn-accent:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-copper);
}

.btn-outline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  gap: 0.5rem;
  background: transparent !important;
  color: var(--contrast) !important;
  font-weight: 700;
  font-size: var(--text-s);
  padding: 12px 26px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  border: 1px solid var(--border-parchment) !important;
  transition: transform 0.22s var(--ease-spring), background-color 0.2s ease;
}
.btn-outline:hover {
  background: var(--surface-low) !important;
  transform: translateY(-1px);
}

.card-glass {
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-stone);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.card-dark-glass {
  background: rgba(13, 31, 24, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(197, 155, 39, 0.28);
  border-radius: var(--radius-lg);
  color: var(--base);
  box-shadow: var(--shadow-lg);
}

.badge-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.badge-amber {
  background: rgba(197, 155, 39, 0.14);
  color: #9A7414;
  border: 1px solid rgba(197, 155, 39, 0.45);
}
.badge-teal,
.badge-verified {
  background: rgba(20, 54, 43, 0.10);
  color: var(--primary);
  border: 1px solid rgba(20, 54, 43, 0.28);
}

/* Logged-in vs Logged-out Dynamic Menu Helpers */
.logged-in-only { display: none !important; }
body.logged-in .logged-in-only { display: flex !important; }
body.logged-in .logged-out-only { display: none !important; }

/* ==========================================================================
   5. REDUCED MOTION SAFEGUARD (WCAG 2.2)
   ========================================================================== */

@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;
  }

  .itl-bento-card:hover,
  .itl-trade-card:hover,
  .itl-itinerary-step:hover,
  .wp-element-button:hover,
  .wp-block-button__link:hover,
  .itl-copy-btn:hover,
  .btn-primary:hover,
  .btn-accent:hover,
  .btn-outline:hover {
    transform: none !important;
  }
}
