/* ============================================================
   YBT Health — Legal Pages Design System
   Matches the YBT Health app: warm neutrals, bronze accent,
   Inter + Playfair Display, grain texture, soft shadows.
   ============================================================ */

/* --- Google Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Playfair+Display:wght@400;500;600;700;800&display=swap');

/* --- Design Tokens (Light) --- */
:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-serif: 'Playfair Display', Georgia, 'Times New Roman', serif;

  --color-bg: #f8f5f0;
  --color-bg-subtle: #f0ebe2;
  --color-bg-card: #ffffff;
  --color-bg-code: #f5f0ea;

  --color-text: #1a1a1a;
  --color-text-secondary: #4a4540;
  --color-text-muted: #8a7e6b;
  --color-text-light: #b0a694;

  --color-accent: #9a7352;
  --color-accent-light: #c49a6c;
  --color-accent-bg: #faf5ef;
  --color-accent-hover: #7d5c3f;

  --color-border: #e8e0d4;
  --color-border-light: #f0ebe2;

  --color-header-bg: rgba(248, 245, 240, 0.95);
  --color-footer-bg: #f0ebe2;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.03);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06), 0 2px 4px rgba(0, 0, 0, 0.03);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.08), 0 4px 8px rgba(0, 0, 0, 0.04);

  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;

  --ease-luxury: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-snappy: cubic-bezier(0.2, 0, 0, 1);

  --header-height: 3.5rem;
  --toc-width: 260px;
}

/* --- Dark Mode Tokens --- */
[data-theme="dark"] {
  --color-bg: #141210;
  --color-bg-subtle: #1c1815;
  --color-bg-card: #1e1a15;
  --color-bg-code: #252017;

  --color-text: #f0ebe2;
  --color-text-secondary: #c8bfb0;
  --color-text-muted: #a89c8a;
  --color-text-light: #6b6055;

  --color-accent: #c49a6c;
  --color-accent-light: #d4a878;
  --color-accent-bg: #2a2318;
  --color-accent-hover: #dbb48a;

  --color-border: #3d3429;
  --color-border-light: #2a2318;

  --color-header-bg: rgba(20, 18, 16, 0.95);
  --color-footer-bg: #1c1815;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.12);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.16), 0 1px 2px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.2), 0 2px 4px rgba(0, 0, 0, 0.12);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.28), 0 4px 8px rgba(0, 0, 0, 0.16);
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-height) + 2rem);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.7;
  color: var(--color-text);
  background-color: var(--color-bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.3s var(--ease-luxury), color 0.3s var(--ease-luxury);
}

/* --- Grain Texture Overlay --- */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.03;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
}

/* --- Header --- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-height);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-header-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  transition: background-color 0.3s var(--ease-luxury), border-color 0.3s var(--ease-luxury);
}

.header-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 1.25rem;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo-link {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  text-decoration: none;
  color: var(--color-text);
}

.logo-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-md);
  background: var(--color-text);
  flex-shrink: 0;
}

.logo-mark span {
  font-family: var(--font-sans);
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--color-bg-card);
}

.logo-text {
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--color-text);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Theme Toggle */
.theme-toggle {
  appearance: none;
  border: none;
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  color: var(--color-text-muted);
  transition: color 0.2s, background-color 0.2s;
}

.theme-toggle:hover {
  color: var(--color-text);
  background: var(--color-bg-subtle);
}

.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
  width: 1.125rem;
  height: 1.125rem;
}

[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
:root:not([data-theme="dark"]) .theme-toggle .icon-sun,
body:not([data-theme="dark"]) .theme-toggle .icon-sun { display: none; }
:root:not([data-theme="dark"]) .theme-toggle .icon-moon,
body:not([data-theme="dark"]) .theme-toggle .icon-moon { display: block; }

/* --- Page Layout --- */
.page-wrapper {
  position: relative;
  z-index: 1;
  flex: 1;
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
}

@media (min-width: 960px) {
  .page-wrapper {
    grid-template-columns: var(--toc-width) 1fr;
    gap: 3rem;
    padding: 2.5rem 1.5rem 5rem;
  }
}

/* --- Table of Contents (Sidebar) --- */
.toc-container {
  display: none;
}

@media (min-width: 960px) {
  .toc-container {
    display: block;
    position: relative;
  }

  .toc-sidebar {
    position: sticky;
    top: calc(var(--header-height) + 2rem);
    max-height: calc(100vh - var(--header-height) - 4rem);
    overflow-y: auto;
    padding-right: 1rem;
    scrollbar-width: thin;
    scrollbar-color: var(--color-border) transparent;
  }
}

.toc-label {
  font-family: var(--font-sans);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin-bottom: 0.75rem;
}

.toc-list {
  list-style: none;
  padding: 0;
  border-left: 2px solid var(--color-border-light);
}

.toc-list li {
  position: relative;
}

.toc-list a {
  display: block;
  padding: 0.375rem 0 0.375rem 1rem;
  font-size: 0.8125rem;
  line-height: 1.4;
  color: var(--color-text-muted);
  text-decoration: none;
  border-left: 2px solid transparent;
  margin-left: -2px;
  transition: color 0.2s var(--ease-snappy), border-color 0.2s var(--ease-snappy);
}

.toc-list a:hover {
  color: var(--color-text-secondary);
}

.toc-list a.active {
  color: var(--color-accent);
  border-left-color: var(--color-accent);
  font-weight: 500;
}

/* --- Mobile TOC --- */
.toc-mobile {
  display: block;
  margin-bottom: 1.5rem;
}

@media (min-width: 960px) {
  .toc-mobile {
    display: none;
  }
}

.toc-mobile-toggle {
  appearance: none;
  border: 1px solid var(--color-border);
  background: var(--color-bg-card);
  border-radius: var(--radius-lg);
  padding: 0.75rem 1rem;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-text-secondary);
  box-shadow: var(--shadow-xs);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.toc-mobile-toggle:hover {
  border-color: var(--color-accent);
}

.toc-mobile-toggle svg {
  width: 1rem;
  height: 1rem;
  transition: transform 0.2s var(--ease-snappy);
}

.toc-mobile-toggle[aria-expanded="true"] svg {
  transform: rotate(180deg);
}

.toc-mobile-list {
  list-style: none;
  padding: 0;
  margin-top: 0.5rem;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  display: none;
}

.toc-mobile-list.open {
  display: block;
}

.toc-mobile-list a {
  display: block;
  padding: 0.625rem 1rem;
  font-size: 0.8125rem;
  color: var(--color-text-secondary);
  text-decoration: none;
  border-bottom: 1px solid var(--color-border-light);
  transition: background-color 0.15s, color 0.15s;
}

.toc-mobile-list li:last-child a {
  border-bottom: none;
}

.toc-mobile-list a:hover,
.toc-mobile-list a.active {
  background: var(--color-accent-bg);
  color: var(--color-accent);
}

/* --- Main Content --- */
.content {
  min-width: 0;
}

.content-header {
  margin-bottom: 2.5rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--color-border);
}

.content-header h1 {
  font-family: var(--font-serif);
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  font-weight: 700;
  line-height: 1.2;
  color: var(--color-text);
  margin-bottom: 0.75rem;
  letter-spacing: -0.02em;
}

.content-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
}

.content-meta span {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
}

.content-meta .badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.625rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
  background: var(--color-accent-bg);
  color: var(--color-accent);
  border: 1px solid var(--color-accent);
  border-color: rgba(154, 115, 82, 0.2);
}

.content-meta .badge svg {
  width: 0.75rem;
  height: 0.75rem;
}

/* --- Legal Content Sections --- */
.legal-section {
  margin-bottom: 2.5rem;
  scroll-margin-top: calc(var(--header-height) + 2rem);
}

.legal-section h2 {
  font-family: var(--font-serif);
  font-size: 1.375rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--color-border-light);
  letter-spacing: -0.01em;
}

.legal-section h3 {
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
}

.legal-section p {
  margin-bottom: 0.875rem;
  color: var(--color-text-secondary);
}

.legal-section ul,
.legal-section ol {
  margin-bottom: 0.875rem;
  padding-left: 1.5rem;
  color: var(--color-text-secondary);
}

.legal-section li {
  margin-bottom: 0.375rem;
}

.legal-section li::marker {
  color: var(--color-accent);
}

.legal-section strong {
  color: var(--color-text);
  font-weight: 600;
}

.legal-section a {
  color: var(--color-accent);
  text-decoration: underline;
  text-decoration-color: rgba(154, 115, 82, 0.3);
  text-underline-offset: 2px;
  transition: text-decoration-color 0.2s;
}

.legal-section a:hover {
  text-decoration-color: var(--color-accent);
}

/* Callout / highlight box */
.callout {
  background: var(--color-accent-bg);
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-accent);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  margin: 1.25rem 0;
}

.callout p {
  margin-bottom: 0;
  font-size: 0.875rem;
}

.callout strong {
  color: var(--color-accent);
}

/* Contact card */
.contact-card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  margin-top: 1rem;
}

.contact-card p {
  margin-bottom: 0.5rem;
}

.contact-card p:last-child {
  margin-bottom: 0;
}

/* --- Back to Top Button --- */
.back-to-top {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  border: 1px solid var(--color-border);
  background: var(--color-bg-card);
  box-shadow: var(--shadow-md);
  color: var(--color-text-muted);
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transform: translateY(0.5rem);
  transition: opacity 0.3s var(--ease-luxury), visibility 0.3s, transform 0.3s var(--ease-luxury), color 0.2s, border-color 0.2s;
}

.back-to-top:hover {
  color: var(--color-accent);
  border-color: var(--color-accent);
}

.back-to-top.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.back-to-top svg {
  width: 1.125rem;
  height: 1.125rem;
}

/* --- Footer --- */
.site-footer {
  position: relative;
  z-index: 1;
  border-top: 1px solid var(--color-border);
  background: var(--color-footer-bg);
  padding: 1.5rem 0;
  margin-top: auto;
  transition: background-color 0.3s var(--ease-luxury), border-color 0.3s var(--ease-luxury);
}

.footer-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

@media (min-width: 640px) {
  .footer-inner {
    flex-direction: row;
    justify-content: space-between;
  }
}

.footer-copy {
  font-size: 0.6875rem;
  color: var(--color-text-light);
}

.footer-links {
  display: flex;
  gap: 1.25rem;
}

.footer-links a {
  font-size: 0.6875rem;
  color: var(--color-text-light);
  text-decoration: none;
  transition: color 0.2s;
}

.footer-links a:hover {
  color: var(--color-text);
}

/* --- Landing Page --- */
.landing-hero {
  text-align: center;
  padding: 4rem 1.25rem 3rem;
  max-width: 640px;
  margin: 0 auto;
}

.landing-hero h1 {
  font-family: var(--font-serif);
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 700;
  line-height: 1.15;
  color: var(--color-text);
  margin-bottom: 0.75rem;
  letter-spacing: -0.02em;
}

.landing-hero p {
  font-size: 1.0625rem;
  line-height: 1.6;
  color: var(--color-text-muted);
  max-width: 480px;
  margin: 0 auto;
}

.landing-cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
  max-width: 720px;
  margin: 0 auto;
  padding: 0 1.25rem 5rem;
}

@media (min-width: 640px) {
  .landing-cards {
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
  }
}

.landing-card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: 1.75rem;
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  color: var(--color-text);
  transition: border-color 0.25s var(--ease-luxury), box-shadow 0.25s var(--ease-luxury), transform 0.25s var(--ease-luxury);
}

.landing-card:hover {
  border-color: var(--color-accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.landing-card-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: var(--radius-lg);
  background: var(--color-accent-bg);
  color: var(--color-accent);
  margin-bottom: 1rem;
}

.landing-card-icon svg {
  width: 1.25rem;
  height: 1.25rem;
}

.landing-card h2 {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  letter-spacing: -0.01em;
}

.landing-card p {
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--color-text-muted);
  margin-bottom: 1rem;
}

.landing-card .card-link {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-accent);
}

.landing-card .card-link svg {
  width: 0.875rem;
  height: 0.875rem;
  transition: transform 0.2s var(--ease-snappy);
}

.landing-card:hover .card-link svg {
  transform: translateX(2px);
}

/* --- Print Styles --- */
@media print {
  body::before,
  .site-header,
  .site-footer,
  .toc-container,
  .toc-mobile,
  .back-to-top,
  .theme-toggle {
    display: none !important;
  }

  body {
    background: white;
    color: black;
    font-size: 12pt;
  }

  .page-wrapper {
    display: block;
    max-width: none;
    padding: 0;
  }

  .content-header h1 {
    font-size: 24pt;
  }

  .legal-section h2 {
    font-size: 16pt;
    break-after: avoid;
  }

  .legal-section {
    break-inside: avoid;
  }

  a {
    color: black;
    text-decoration: underline;
  }

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

  .callout {
    border: 1px solid #ccc;
    background: #f9f9f9;
  }
}

/* --- Accessibility --- */
@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;
  }
}

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

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