/* ==========================================================================
   base.css — engine structural styles (reset, typography, layout, shared
   components: header, drawer, footer, buttons, prose, blog, pagination).
   Page/section styles belong in main.css, written per project by
   website-dev. Everything here consumes tokens.css.
   ========================================================================== */

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

* { margin: 0; }

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

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

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--color-text-primary);
  background-color: var(--color-base);
  -webkit-font-smoothing: antialiased;
}

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

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

h1, h2, h3, h4 {
  font-family: var(--font-display);
  color: var(--color-heading);
  line-height: 1.2;
  overflow-wrap: break-word;
}

h1 { font-size: var(--text-4xl); }
h2 { font-size: var(--text-3xl); }
h3 { font-size: var(--text-2xl); }
h4 { font-size: var(--text-xl); }

p { overflow-wrap: break-word; }

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

:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* ---------- Layout ---------- */
.container {
  width: 100%;
  max-width: var(--container-max);
  margin-inline: auto;
  padding-inline: var(--space-6);
}

.section { padding-block: var(--space-16); }

@media (min-width: 768px) {
  .section { padding-block: var(--space-20); }
}

/* ---------- Skip link ---------- */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-4);
  z-index: 200;
  padding: var(--space-2) var(--space-4);
  background: var(--color-structure);
  color: var(--color-text-inverse);
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: top var(--transition-fast);
}
.skip-link:focus { top: var(--space-4); color: var(--color-text-inverse); }

/* ---------- Buttons ---------- */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: var(--space-3) var(--space-6);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: var(--text-sm);
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}

.button--primary {
  background-color: var(--color-accent);
  color: var(--color-on-accent);
}
.button--primary:hover {
  background-color: var(--color-accent-hover);
  color: var(--color-on-accent);
}

.button--secondary {
  background-color: transparent;
  border-color: var(--color-border);
  color: var(--color-heading);
}
.button--secondary:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: color-mix(in srgb, var(--color-base) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid transparent;
  transition: border-color var(--transition-base), background-color var(--transition-base);
}
.site-header.is-scrolled { border-bottom-color: var(--color-border); }

.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-6);
  min-height: var(--header-height);
}

.site-header__brand { display: inline-flex; align-items: center; text-decoration: none; }
.site-header__logo { height: 2.5rem; width: auto; }

/* Theme-swapped lockup — only rendered when the project ships logo-dark.*
   (see includes/header.php). Same selector shape as the theme toggle icons:
   the attribute rules must beat the media query so a manual override wins. */
.site-header__logo--dark { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .site-header__logo--light { display: none; }
  :root:not([data-theme='light']) .site-header__logo--dark { display: block; }
}
:root[data-theme='dark'] .site-header__logo--light { display: none; }
:root[data-theme='dark'] .site-header__logo--dark { display: block; }
:root[data-theme='light'] .site-header__logo--light { display: block; }
:root[data-theme='light'] .site-header__logo--dark { display: none; }
.site-header__name {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-heading);
}

.site-nav__list {
  display: flex;
  gap: var(--space-6);
  list-style: none;
  padding: 0;
}
.site-nav__link {
  color: var(--color-text-secondary);
  text-decoration: none;
  font-size: var(--text-sm);
  font-weight: 500;
  transition: color var(--transition-fast);
}
.site-nav__link:hover,
.site-nav__link.is-active { color: var(--color-accent); }

.site-header__actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* Voice line — deliberately quiet: it sits beside the primary CTA and must
   not compete with it. Icon-only below 1024px so the header never crowds. */
.site-header__phone {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
  padding-inline: var(--space-2);
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  text-decoration: none;
  white-space: nowrap;
  transition: color var(--transition-fast);
}
.site-header__phone:hover { color: var(--color-accent); }
.site-header__phone svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
@media (max-width: 1023px) {
  .site-header__phone-text {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
  }
}

.site-header__lang {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--color-text-secondary);
  text-decoration: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-2);
}
.site-header__lang:hover { color: var(--color-accent); border-color: var(--color-accent); }

/* Mobile drawer */
.site-header__toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  padding: 10px;
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.site-header__toggle-bar {
  display: block;
  height: 2px;
  width: 100%;
  background: var(--color-heading);
  transition: transform var(--transition-fast), opacity var(--transition-fast);
}

@media (max-width: 860px) {
  .site-header__toggle { display: flex; }
  .site-header__cta { display: none; }

  .site-nav {
    position: fixed;
    inset: var(--header-height) 0 auto 0;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: var(--space-4) var(--space-6) var(--space-6);
    transform: translateY(-110%);
    visibility: hidden;
    transition: transform var(--transition-base), visibility var(--transition-base);
  }
  .site-nav.is-open { transform: translateY(0); visibility: visible; }

  .site-nav__list { flex-direction: column; gap: var(--space-2); }
  .site-nav__link { display: block; padding: var(--space-3) 0; font-size: var(--text-base); }

  body.nav-open { overflow: hidden; }

  .site-header__toggle[aria-expanded="true"] .site-header__toggle-bar:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  .site-header__toggle[aria-expanded="true"] .site-header__toggle-bar:nth-child(2) { opacity: 0; }
  .site-header__toggle[aria-expanded="true"] .site-header__toggle-bar:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
}

/* ---------- Footer ---------- */
.site-footer {
  margin-top: var(--space-24);
  background: var(--color-structure);
  color: var(--color-text-inverse);
  padding-block: var(--space-12) var(--space-8);
}

.site-footer__top {
  display: grid;
  gap: var(--space-8);
  padding-bottom: var(--space-8);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}
@media (min-width: 768px) {
  .site-footer__top { grid-template-columns: 2fr 1fr 1fr; }
}

.site-footer__name {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
}

.site-footer__nav ul { list-style: none; padding: 0; display: grid; gap: var(--space-2); }
.site-footer a { color: rgba(255, 255, 255, 0.75); text-decoration: none; }
.site-footer a:hover { color: #ffffff; }

.site-footer__bottom {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding-top: var(--space-6);
  font-size: var(--text-sm);
  color: rgba(255, 255, 255, 0.6);
}

.site-footer__legal {
  display: flex;
  gap: var(--space-4);
  list-style: none;
  padding: 0;
}

/* ---------- Prose (markdown output: posts, legal pages) ---------- */
.prose {
  max-width: 46rem;
  font-size: var(--text-lg);
  line-height: 1.75;
}
.prose > :first-child { margin-top: 0; }
.prose h1, .prose h2, .prose h3, .prose h4 { scroll-margin-top: calc(var(--header-height) + 1rem); }
.prose h1 { margin: 0 0 var(--space-6); }
.prose h2 { margin: var(--space-12) 0 var(--space-4); }
.prose h3 { margin: var(--space-8) 0 var(--space-3); }
.prose h4 { margin: var(--space-6) 0 var(--space-2); }
.prose p { margin: var(--space-4) 0; }
.prose ul, .prose ol { margin: var(--space-4) 0; padding-left: var(--space-6); }
.prose li { margin: var(--space-2) 0; }
.prose li::marker { color: var(--color-accent); }
.prose blockquote {
  margin: var(--space-6) 0;
  padding: var(--space-3) var(--space-6);
  border-left: 3px solid var(--color-accent);
  background: var(--color-accent-soft);
  color: var(--color-text-primary);
}
.prose code {
  font-size: 0.9em;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.1em 0.35em;
}
.prose pre {
  margin: var(--space-6) 0;
  padding: var(--space-4);
  overflow-x: auto;
  background: var(--color-structure);
  color: var(--color-text-inverse);
  border-radius: var(--radius-md);
}
.prose pre code { background: transparent; border: 0; padding: 0; color: inherit; }
.prose img { border-radius: var(--radius-md); margin: var(--space-6) 0; }
.prose hr { margin: var(--space-8) 0; border: 0; border-top: 1px solid var(--color-border); }
.prose table { width: 100%; margin: var(--space-6) 0; border-collapse: collapse; display: block; overflow-x: auto; }
.prose th, .prose td { padding: var(--space-3) var(--space-4); border: 1px solid var(--color-border); text-align: left; }
.prose th { background: var(--color-surface); }

/* ---------- Blog ---------- */
.blog-header { padding-block: var(--space-12) var(--space-8); }
.blog-header__meta { color: var(--color-text-secondary); font-size: var(--text-sm); display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); margin-top: var(--space-3); }

.blog-grid {
  display: grid;
  gap: var(--space-6);
  padding-bottom: var(--space-16);
}
@media (min-width: 700px) { .blog-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { .blog-grid { grid-template-columns: repeat(3, 1fr); } }

.post-card {
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: box-shadow var(--transition-base), transform var(--transition-base);
}
.post-card:hover { box-shadow: var(--shadow-card-hover); transform: translateY(-2px); }
.post-card__cover { aspect-ratio: 16 / 9; object-fit: cover; width: 100%; }
.post-card__body { display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-6); }
.post-card__meta { font-size: var(--text-xs); color: var(--color-text-secondary); display: flex; gap: var(--space-3); flex-wrap: wrap; }
.post-card__title { font-size: var(--text-xl); margin: 0; }
.post-card__title a { color: var(--color-heading); text-decoration: none; }
.post-card__title a:hover { color: var(--color-accent); }
.post-card__excerpt { color: var(--color-text-secondary); font-size: var(--text-sm); }
.post-card__more { margin-top: auto; padding-top: var(--space-3); font-size: var(--text-sm); font-weight: 600; text-decoration: none; }

.badge {
  display: inline-block;
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  background: var(--color-accent-soft);
  color: var(--color-accent);
  font-size: var(--text-xs);
  font-weight: 600;
  text-decoration: none;
}

.post-nav {
  display: grid;
  gap: var(--space-4);
  margin-top: var(--space-12);
  padding-top: var(--space-8);
  border-top: 1px solid var(--color-border);
}
@media (min-width: 640px) { .post-nav { grid-template-columns: 1fr 1fr; } }
.post-nav__item {
  display: block;
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  text-decoration: none;
  background: var(--color-surface);
}
.post-nav__item:hover { border-color: var(--color-accent); }
.post-nav__label { display: block; font-size: var(--text-xs); color: var(--color-text-secondary); margin-bottom: var(--space-1); }
.post-nav__title { font-weight: 600; color: var(--color-heading); }
.post-nav__item--next { text-align: right; }

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding-block: var(--space-8) var(--space-16);
}
.pagination__info { color: var(--color-text-secondary); font-size: var(--text-sm); }

.draft-banner {
  background: var(--color-draft);
  color: var(--color-on-draft);
  text-align: center;
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
}

/* ---------- Theme toggle ---------- */
/* One button, two icons. Which icon shows is driven purely by the resolved
   colour scheme, so it stays correct whether the theme came from the OS or
   from a stored manual choice. */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  padding: 0;
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-heading);
  cursor: pointer;
  transition: border-color var(--transition-fast), color var(--transition-fast);
}
.theme-toggle:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
}
.theme-toggle svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}
/* A button announces its ACTION, not its state: in light mode it offers the
   moon (go dark), in dark mode the sun (go light). */
.theme-toggle__moon { display: block; }
.theme-toggle__sun { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .theme-toggle__moon { display: none; }
  :root:not([data-theme='light']) .theme-toggle__sun { display: block; }
}
:root[data-theme='dark'] .theme-toggle__moon { display: none; }
:root[data-theme='dark'] .theme-toggle__sun { display: block; }
:root[data-theme='light'] .theme-toggle__moon { display: block; }
:root[data-theme='light'] .theme-toggle__sun { display: none; }

/* ---------- Reveal on scroll (opt-in per element) ---------- */
.reveal {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity var(--transition-slow), transform var(--transition-slow);
}
.reveal.is-visible { opacity: 1; transform: translateY(0); }

@media (prefers-reduced-motion: reduce) {
  .reveal { opacity: 1; transform: none; }
}

/* ---------- Utility ---------- */
.text-secondary { color: var(--color-text-secondary); }
.text-center { text-align: center; }
.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;
}
