/**
 * Legal Pages Styling
 *
 * Sharp, professional, readable legal aesthetic for Terms of Use and Privacy Policy.
 * Maintains MWANGI brand personality while feeling credible and modern.
 *
 * Design philosophy:
 * - Professional but not corporate-boring
 * - Sharp and modern
 * - Easy to scan and digest
 * - Branded with MWANGI personality (electric blue accents, dark mode)
 *
 * @package MWANGI
 * @version 1.0.0
 */

/* ========================================================================
   PAGE CONTAINER & LAYOUT
   ======================================================================== */

.legal-page-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-2xl) var(--space-lg);
}

/* ========================================================================
   PAGE HEADER
   ======================================================================== */

.legal-page-header {
  text-align: center;
  margin-bottom: var(--space-3xl);
  padding-bottom: var(--space-xl);
  border-bottom: 1px solid rgba(41, 181, 237, 0.2);
}

.legal-page-header h1 {
  font-size: 2rem;              /* ~32px - 35% reduction from default */
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin-bottom: var(--space-md);
  color: var(--color-text-primary);
}

.legal-page-meta {
  display: flex;
  justify-content: center;
  gap: var(--space-xl);
  flex-wrap: wrap;
  color: var(--color-text-tertiary);
  font-size: var(--font-size-sm);
  margin-top: var(--space-md);
}

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

/* ========================================================================
   BREADCRUMB NAVIGATION
   ======================================================================== */

.legal-breadcrumb {
  margin-bottom: var(--space-2xl);
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

.legal-breadcrumb a {
  color: var(--color-primary);
  text-decoration: none;
  transition: color var(--transition-base);
}

.legal-breadcrumb a:hover {
  color: var(--color-primary-hover);
  text-decoration: underline;
}

.legal-breadcrumb-separator {
  margin: 0 var(--space-sm);
  color: var(--color-text-tertiary);
}

/* ========================================================================
   TABLE OF CONTENTS
   ======================================================================== */

.legal-toc {
  background: rgba(21, 21, 21, 0.6);
  backdrop-filter: blur(20px);
  border: 1px solid var(--color-border-secondary);
  border-radius: var(--border-radius-lg);
  padding: var(--space-xl);
  margin-bottom: var(--space-3xl);
  box-shadow: var(--shadow-md);
}

.legal-toc h2 {
  font-size: 1.25rem;           /* ~20px */
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.3;
  margin-top: 0;
  margin-bottom: var(--space-lg);
  color: var(--color-text-primary);
}

.legal-toc ol {
  columns: 2;
  -webkit-columns: 2;
  -moz-columns: 2;
  column-gap: var(--space-xl);
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: toc-counter;
}

.legal-toc li {
  break-inside: avoid;
  page-break-inside: avoid;
  margin-bottom: var(--space-md);
  counter-increment: toc-counter;
}

.legal-toc a {
  display: block;
  color: var(--color-text-secondary);
  text-decoration: none;
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--border-radius-sm);
  transition: all var(--transition-base);
  font-size: var(--font-size-sm);
  line-height: 1.5;
}

.legal-toc a::before {
  content: counter(toc-counter) ". ";
  color: var(--color-primary);
  font-weight: 600;
  margin-right: var(--space-xs);
}

.legal-toc a:hover {
  background: rgba(41, 181, 237, 0.1);
  color: var(--color-primary);
  transform: translateX(4px);
}

.legal-toc a.active {
  background: rgba(41, 181, 237, 0.15);
  color: var(--color-primary);
  font-weight: 500;
  border-left: 2px solid var(--color-primary);
  padding-left: var(--space-md);
}

/* Mobile: Collapsible TOC */
.legal-toc-toggle {
  display: none; /* Hidden on desktop */
  width: 100%;
  background: transparent;
  border: none;
  color: var(--color-primary);
  font-weight: 600;
  font-size: var(--font-size-base);
  padding: var(--space-sm);
  cursor: pointer;
  text-align: left;
  transition: all var(--transition-base);
}

.legal-toc-toggle:hover {
  background: rgba(41, 181, 237, 0.1);
}

.legal-toc-toggle::after {
  content: "▼";
  float: right;
  transition: transform var(--transition-base);
}

.legal-toc.collapsed .legal-toc-toggle::after {
  transform: rotate(-90deg);
}

.legal-toc.collapsed ol {
  display: none;
}

/* ========================================================================
   MAIN CONTENT AREA
   ======================================================================== */

.legal-content {
  max-width: 800px;
  margin: 0 auto;
  line-height: 1.7;
}

/* Section spacing */
.legal-section {
  margin-bottom: var(--space-3xl);
  padding-top: var(--space-xl);
}

.legal-section:not(:last-child) {
  /** border-bottom: 1px solid rgba(255, 255, 255, 0.05); **/
  padding-bottom: var(--space-xl);
}

/* ========================================================================
   TYPOGRAPHY HIERARCHY (35% REDUCTION)
   ======================================================================== */

.legal-content h2 {
  font-size: 1.5rem;            /* ~24px - 35% reduction */
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.3;
  color: var(--color-text-primary);
  margin-top: var(--space-2xl);
  margin-bottom: var(--space-lg);
  scroll-margin-top: var(--space-2xl); /* Offset for smooth scroll */
  counter-increment: section;
}

.legal-content h2::before {
  content: counter(section) ". ";
  color: var(--color-primary);
  font-weight: 700;
  margin-right: var(--space-xs);
}

.legal-content h3 {
  font-size: 1.125rem;          /* ~18px - 35% reduction */
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1.4;
  color: var(--color-text-primary);
  margin-top: var(--space-xl);
  margin-bottom: var(--space-md);
}

.legal-content h4 {
  font-size: 1rem;              /* ~16px */
  font-weight: 600;
  line-height: 1.5;
  color: var(--color-text-secondary);
  margin-top: var(--space-lg);
  margin-bottom: var(--space-sm);
}

/* Body text */
.legal-content p {
  font-size: var(--font-size-base);
  line-height: 1.7;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-lg);
  max-width: 75ch; /* Optimal line length */
}

/* Lists */
.legal-content ul,
.legal-content ol {
  margin-bottom: var(--space-lg);
  padding-left: var(--space-xl);
  color: var(--color-text-secondary);
}

.legal-content li {
  margin-bottom: var(--space-sm);
  line-height: 1.7;
}

.legal-content li > ul,
.legal-content li > ol {
  margin-top: var(--space-sm);
  margin-bottom: var(--space-sm);
}

/* Definition lists */
.legal-content dl {
  margin-bottom: var(--space-lg);
}

.legal-content dt {
  font-weight: 600;
  color: var(--color-primary);
  margin-top: var(--space-md);
  margin-bottom: var(--space-xs);
}

.legal-content dd {
  margin-left: var(--space-xl);
  margin-bottom: var(--space-md);
  color: var(--color-text-secondary);
  line-height: 1.7;
}

/* ========================================================================
   SPECIAL ELEMENTS
   ======================================================================== */

/* Highlight boxes for important information */
.legal-notice {
  background: rgba(41, 181, 237, 0.08);
  border-left: 4px solid var(--color-primary);
  padding: var(--space-lg) var(--space-xl);
  margin: var(--space-xl) 0;
  border-radius: var(--border-radius-sm);
}

.legal-notice p {
  margin-bottom: var(--space-sm);
  color: var(--color-text-primary);
}

.legal-notice p:last-child {
  margin-bottom: 0;
}

/* Legal terms with tooltips */
.legal-term {
  font-weight: 600;
  color: var(--color-primary);
  cursor: help;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-decoration-color: rgba(41, 181, 237, 0.4);
}

.legal-term:hover {
  color: var(--color-primary-hover);
  text-decoration-color: var(--color-primary);
}

/* Tables */
.legal-content table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--space-xl) 0;
  font-size: var(--font-size-sm);
  background: var(--color-bg-secondary);
  border-radius: var(--border-radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.legal-content thead {
  background: rgba(41, 181, 237, 0.1);
}

.legal-content th {
  padding: var(--space-md);
  text-align: left;
  font-weight: 600;
  color: var(--color-text-primary);
  border-bottom: 2px solid var(--color-primary);
}

.legal-content td {
  padding: var(--space-md);
  border-bottom: 1px solid var(--color-border-secondary);
  color: var(--color-text-secondary);
  vertical-align: top;
}

.legal-content tbody tr:hover {
  background: rgba(41, 181, 237, 0.05);
}

.legal-content tbody tr:last-child td {
  border-bottom: none;
}

/* Code/technical terms */
.legal-content code {
  background: var(--color-bg-tertiary);
  padding: 0.2em 0.4em;
  border-radius: var(--border-radius-sm);
  color: var(--color-primary);
  font-size: 0.9em;
  border: 1px solid var(--color-border-secondary);
}

/* Strong emphasis */
.legal-content strong {
  font-weight: 600;
  color: var(--color-text-primary);
}

/* Links */
.legal-content a {
  color: var(--color-primary);
  text-decoration: underline;
  text-decoration-color: rgba(41, 181, 237, 0.3);
  transition: all var(--transition-base);
}

.legal-content a:hover {
  color: var(--color-primary-hover);
  text-decoration-color: var(--color-primary);
}

/* ========================================================================
   BACK TO TOP BUTTON
   ======================================================================== */

.back-to-top {
  position: fixed;
  bottom: var(--space-2xl);
  right: var(--space-2xl);
  width: 48px;
  height: 48px;
  background: var(--gradient-primary);
  color: #FFFFFF;
  border: none;
  border-radius: var(--border-radius-full);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  box-shadow: var(--shadow-lg), 0 0 20px rgba(41, 181, 237, 0.4);
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px);
  transition: all var(--transition-smooth);
  z-index: 100;
}

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

.back-to-top:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-xl), 0 0 30px rgba(41, 181, 237, 0.6);
}

.back-to-top:active {
  transform: translateY(-2px);
}

.back-to-top::before {
  content: "↑";
}

/* ========================================================================
   SECTION DIVIDERS
   ======================================================================== */

.legal-content hr {
  border: none;
  height: 1px;
  background: linear-gradient(
    to right,
    transparent 0%,
    rgba(255, 255, 255, 0.1) 20%,
    rgba(255, 255, 255, 0.1) 80%,
    transparent 100%
  );
  margin: var(--space-3xl) 0;
}

/* ========================================================================
   FOOTER NOTE
   ======================================================================== */

.legal-footer-note {
  text-align: center;
  margin-top: var(--space-3xl);
  padding-top: var(--space-2xl);
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  color: var(--color-text-tertiary);
  font-size: var(--font-size-sm);
}

.legal-footer-note strong {
  color: var(--color-text-secondary);
}

/* ========================================================================
   RESPONSIVE DESIGN
   ======================================================================== */

/* Tablet (768px - 968px) */
@media (max-width: 968px) {
  .legal-page-container {
    padding: var(--space-xl) var(--space-md);
  }

  .legal-toc ol {
    columns: 1;
    -webkit-columns: 1;
    -moz-columns: 1;
  }

  .legal-content h2 {
    font-size: 1.375rem;      /* Scale down slightly */
  }

  .legal-content h3 {
    font-size: 1.0625rem;     /* Scale down slightly */
  }
}

/* Mobile (< 768px) */
@media (max-width: 768px) {
  .legal-page-header h1 {
    font-size: 1.75rem;       /* Further reduction on mobile */
  }

  .legal-page-meta {
    flex-direction: column;
    gap: var(--space-sm);
  }

  .legal-toc {
    padding: var(--space-md);
  }

  .legal-toc-toggle {
    display: block;
  }

  .legal-toc ol {
    margin-top: var(--space-md);
  }

  .legal-content h2 {
    font-size: 1.25rem;       /* Mobile heading size */
  }

  .legal-content h3 {
    font-size: 1rem;
  }

  .back-to-top {
    bottom: var(--space-lg);
    right: var(--space-lg);
    width: 44px;
    height: 44px;
  }

  /* Make tables scrollable on mobile */
  .legal-content table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  /* Mobile adjustments for new legal components */
  .affiliate-disclosure {
    padding: 1rem;
    margin: 1.5rem 0;
  }

  .affiliate-badge {
    display: block;
    margin-left: 0;
    margin-top: 0.25rem;
    width: fit-content;
  }

  .ccpa-link {
    width: 100%;
    justify-content: center;
  }

  .ftc-disclosure,
  .legal-important,
  .coppa-section {
    padding: 1rem;
    margin: 1.5rem 0;
  }
}

/* Small mobile (< 480px) */
@media (max-width: 480px) {
  .legal-page-container {
    padding: var(--space-lg) var(--space-sm);
  }

  .legal-page-header {
    margin-bottom: var(--space-2xl);
  }

  .legal-page-header h1 {
    font-size: 1.5rem;
  }

  .legal-notice,
  .legal-content table {
    margin-left: calc(-1 * var(--space-sm));
    margin-right: calc(-1 * var(--space-sm));
    border-radius: 0;
  }
}

/* ========================================================================
   PRINT STYLES
   ======================================================================== */

@media print {
  .legal-page-container {
    max-width: 100%;
  }

  .legal-toc,
  .back-to-top,
  .legal-breadcrumb {
    display: none;
  }

  .legal-content {
    max-width: 100%;
  }

  body {
    background: white;
    color: black;
  }

  .legal-content h2,
  .legal-content h3,
  .legal-content h4,
  .legal-content p,
  .legal-content li {
    color: black;
  }

  .legal-content a {
    color: black;
    text-decoration: underline;
  }

  .legal-content a::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
    color: #666;
  }

  /* Affiliate and legal component print styles */
  .affiliate-badge {
    background: transparent;
    border: 1px solid #000;
    color: #000;
  }

  .affiliate-link {
    color: #000;
    border-bottom: 1px solid #000;
  }

  .legal-important,
  .coppa-section,
  .ftc-disclosure,
  .affiliate-disclosure {
    border-left-color: #000;
    background: #f0f0f0;
    page-break-inside: avoid;
  }

  .ccpa-link {
    border: 1px solid #000;
    color: #000;
    background: transparent;
  }

  .ccpa-link::before {
    content: "";
  }

  /* Show URLs for affiliate links */
  .affiliate-link::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
    color: #666;
  }

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

  .legal-content h2 {
    page-break-before: always;
  }

  .legal-content h2:first-of-type {
    page-break-before: avoid;
  }
}

/* ========================================================================
   AFFILIATE & FTC DISCLOSURE COMPONENTS
   ======================================================================== */

/* Affiliate Disclosure Box - Professional with brand accent */
.affiliate-disclosure {
  background: rgba(41, 181, 237, 0.1);
  border-left: 4px solid #29b5ed;
  padding: 1.25rem 1.5rem;
  margin: 2rem 0;
  border-radius: 4px;
  transition: all var(--transition-base);
}

.affiliate-disclosure:hover {
  background: rgba(41, 181, 237, 0.14);
  box-shadow: 0 4px 12px rgba(41, 181, 237, 0.15);
}

.affiliate-disclosure .disclosure-text {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.6;
  color: #e0e0e0;
}

.affiliate-disclosure strong {
  color: #29b5ed;
  font-weight: 600;
}

/* Affiliate Link Styling */
.affiliate-link {
  position: relative;
  color: #29b5ed;
  text-decoration: none;
  border-bottom: 1px dashed rgba(41, 181, 237, 0.5);
  transition: all 0.2s ease;
}

.affiliate-link:hover {
  color: #6366f1;
  border-bottom-color: #6366f1;
  text-decoration: none;
}

.affiliate-link:focus-visible {
  outline: 2px solid #29b5ed;
  outline-offset: 2px;
  border-radius: 2px;
}

/* Affiliate Badge - Transparent disclosure */
.affiliate-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  color: #29b5ed;
  background: rgba(41, 181, 237, 0.15);
  padding: 2px 6px;
  border-radius: 3px;
  margin-left: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  vertical-align: middle;
  transition: all 0.2s ease;
}

.affiliate-badge:hover {
  background: rgba(41, 181, 237, 0.25);
  transform: scale(1.05);
}

/* FTC Disclosure Section - Compliance focus */
.ftc-disclosure {
  background: rgba(255, 193, 7, 0.1);
  border-left: 4px solid #ffc107;
  padding: 1.5rem;
  margin: 2rem 0;
  border-radius: 4px;
}

.ftc-disclosure h3 {
  color: #ffc107;
  margin-top: 0;
  margin-bottom: 1rem;
  font-size: 1.125rem;
  font-weight: 600;
}

.ftc-disclosure p {
  color: #e0e0e0;
  line-height: 1.7;
}

.ftc-disclosure ul {
  margin-top: 0.75rem;
  color: #d0d0d0;
}

/* ========================================================================
   CCPA "DO NOT SELL" LINK STYLING
   ======================================================================== */

.ccpa-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: #29b5ed;
  font-weight: 500;
  text-decoration: none;
  padding: 0.5rem 1rem;
  border: 1px solid rgba(41, 181, 237, 0.3);
  border-radius: 6px;
  transition: all 0.2s ease;
  background: rgba(41, 181, 237, 0.05);
}

.ccpa-link:hover {
  background: rgba(41, 181, 237, 0.15);
  border-color: #29b5ed;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(41, 181, 237, 0.2);
}

.ccpa-link:active {
  transform: translateY(0);
}

.ccpa-link::before {
  content: "🔒";
  font-size: 1.1rem;
}

.ccpa-link:focus-visible {
  outline: 2px solid #29b5ed;
  outline-offset: 2px;
}

/* ========================================================================
   IMPORTANT LEGAL NOTICES
   ======================================================================== */

/* General important legal notice */
.legal-important {
  background: linear-gradient(135deg, rgba(255, 107, 107, 0.1) 0%, rgba(255, 107, 107, 0.05) 100%);
  border-left: 4px solid #ff6b6b;
  padding: 1.5rem;
  margin: 2rem 0;
  border-radius: 4px;
}

.legal-important h3 {
  color: #ff6b6b;
  margin-top: 0;
  margin-bottom: 1rem;
  font-size: 1.125rem;
  font-weight: 600;
}

.legal-important p {
  color: #e0e0e0;
  line-height: 1.7;
}

/* COPPA Section - Child privacy focus */
.coppa-section {
  background: rgba(76, 175, 80, 0.1);
  border-left: 4px solid #4caf50;
  padding: 1.5rem;
  margin: 2rem 0;
  border-radius: 4px;
}

.coppa-section h3 {
  color: #4caf50;
  margin-top: 0;
  margin-bottom: 1rem;
  font-size: 1.125rem;
  font-weight: 600;
}

.coppa-section p {
  color: #e0e0e0;
  line-height: 1.7;
}

.coppa-section ul {
  margin-top: 0.75rem;
  color: #d0d0d0;
}

/* ========================================================================
   ACCESSIBILITY
   ======================================================================== */

/* Skip to content link */
.skip-to-content {
  position: absolute;
  top: -100px;
  left: 0;
  background: var(--color-primary);
  color: #FFFFFF;
  padding: var(--space-sm) var(--space-md);
  text-decoration: none;
  font-weight: 600;
  border-radius: 0 0 var(--border-radius-md) 0;
  z-index: 1000;
  transition: top var(--transition-base);
}

.skip-to-content:focus {
  top: 0;
}

/* Screen reader only text */
.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;
}

/* Focus indicators */
.legal-toc a:focus-visible,
.back-to-top:focus-visible,
.affiliate-link:focus-visible,
.ccpa-link:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 4px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .affiliate-disclosure,
  .legal-important,
  .coppa-section,
  .ftc-disclosure {
    border-width: 3px;
  }

  .affiliate-badge {
    border: 2px solid currentColor;
  }

  .ccpa-link {
    border-width: 2px;
  }
}

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

  .affiliate-link,
  .affiliate-badge,
  .ccpa-link {
    transition: none;
  }

  .affiliate-link:hover,
  .ccpa-link:hover {
    transform: none;
  }
}
