/* Mobile-First Typography & Style Guide Components */
/* Optimized for Mobile PageSpeed - Minimal, Fast, Clean */

/* ============================================
   Mobile-First Base Typography
   ============================================ */

:root {
  /* Fluid typography variables */
  --fluid-min-width: 320;
  --fluid-max-width: 1200;
  --fluid-base-size: 16;
  --fluid-scale-max: 1.25;

  /* Mobile-first spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
}

/* Mobile-first fluid base font size */
html {
  font-size: 16px; /* Base for mobile */
}

@media (min-width: 480px) {
  html {
    font-size: calc(16px + (18 - 16) * ((100vw - 320px) / (1200 - 320)));
  }
}

@media (min-width: 1200px) {
  html {
    font-size: 18px;
  }
}

/* Mobile-first heading sizes - smaller on mobile for better readability */
h1 {
  font-size: 1.75rem;
  line-height: 1.2;
  margin-bottom: var(--space-md);
}

h2 {
  font-size: 1.5rem;
  line-height: 1.25;
  margin-bottom: var(--space-md);
}

h3 {
  font-size: 1.25rem;
  line-height: 1.3;
  margin-bottom: var(--space-sm);
}

h4 {
  font-size: 1.125rem;
  line-height: 1.35;
  margin-bottom: var(--space-sm);
}

h5, h6 {
  font-size: 1rem;
  line-height: 1.4;
  margin-bottom: var(--space-sm);
}

/* Larger screens get bigger headings */
@media (min-width: 768px) {
  h1 { font-size: 2.5rem; }
  h2 { font-size: 2rem; }
  h3 { font-size: 1.5rem; }
  h4 { font-size: 1.25rem; }
  h5 { font-size: 1.125rem; }
}

/* Mobile-optimized paragraph spacing */
p {
  margin-bottom: var(--space-md);
  line-height: 1.6;
}

/* Mobile-first lead paragraph */
.lead {
  font-size: 1.125rem;
  line-height: 1.5;
  margin-bottom: var(--space-lg);
}

@media (min-width: 768px) {
  .lead {
    font-size: 1.25rem;
    line-height: 1.6;
  }
}

/* ============================================
   Table of Contents / Quick Navigation
   ============================================ */

/* Mobile-first TOC grid */
.toc-container,
[href="#headings"],
[href="#paragraphs"],
[href="#lists"],
[href="#buttons"] {
  scroll-margin-top: 60px; /* Account for fixed headers on mobile */
}

/* Navigation grid - single column on mobile */
.nav-grid,
.toc-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-lg);
}

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

@media (min-width: 768px) {
  .nav-grid,
  .toc-grid {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-xl);
  }
}

/* TOC section styling */
.toc-section {
  padding: var(--space-md);
  background: #f8f9fa;
  border-radius: 0.5rem;
}

.toc-section h3 {
  font-size: 1.125rem;
  margin-bottom: var(--space-sm);
  color: #333;
}

.toc-section ul {
  margin: 0;
  padding-left: 1.25rem;
  list-style: none;
}

.toc-section li {
  margin-bottom: var(--space-xs);
}

.toc-section a {
  display: block;
  padding: 0.25rem 0;
  text-decoration: none;
  transition: color 0.2s;
}

/* ============================================
   PDF Export Button - Mobile Optimized
   ============================================ */

.pdf-export-container {
  position: fixed;
  z-index: 100;
  /* Mobile: bottom right corner */
  bottom: 20px;
  right: 10px;
}

@media (min-width: 768px) {
  .pdf-export-container {
    /* Desktop: top right */
    top: 100px;
    bottom: auto;
    right: 20px;
  }
}

.generate-pdf {
  background: #fff;
  border: 2px solid #0066cc;
  color: #0066cc;
  padding: var(--space-sm) var(--space-md);
  border-radius: 0.5rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.875rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  transition: all 0.2s;
  white-space: nowrap;
}

/* Mobile: smaller button */
@media (max-width: 480px) {
  .generate-pdf {
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.75rem;
  }
}

.generate-pdf:hover,
.generate-pdf:focus {
  background: #0066cc;
  color: white;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,102,204,0.3);
}

.generate-pdf:active {
  transform: translateY(0);
}

/* ============================================
   Color Palette Display
   ============================================ */

.color-grid,
.brand-colors {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-sm);
  margin-bottom: var(--space-xl);
}

@media (min-width: 480px) {
  .color-grid,
  .brand-colors {
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-md);
  }
}

@media (min-width: 768px) {
  .color-grid,
  .brand-colors {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: var(--space-lg);
  }
}

.color-swatch {
  text-align: center;
}

.color-swatch > div {
  height: 80px;
  border-radius: 0.5rem;
  margin-bottom: var(--space-xs);
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

@media (min-width: 480px) {
  .color-swatch > div {
    height: 100px;
    margin-bottom: var(--space-sm);
  }
}

.color-swatch small {
  font-size: 0.75rem;
  color: #6c757d;
}

/* ============================================
   Cards - Mobile Optimized
   ============================================ */

.card {
  background: white;
  border: 1px solid #e0e0e0;
  border-radius: 0.5rem;
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
  margin-bottom: var(--space-md);
}

/* Reduce animations on mobile for performance */
@media (max-width: 768px) {
  .card {
    transition: none;
  }

  .card:hover {
    transform: none;
  }
}

@media (min-width: 769px) {
  .card:hover,
  .card:focus-within {
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
  }
}

.card.selected {
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15);
  border-color: #0066cc;
}

.card-content {
  padding: var(--space-md);
}

@media (min-width: 768px) {
  .card-content {
    padding: var(--space-lg);
  }
}

.card img {
  width: 100%;
  height: auto;
  display: block;
}

/* ============================================
   Chart & QR Code Containers
   ============================================ */

.chart-container,
.qr-code-container {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: var(--space-md);
  background: #f8f9fa;
  border-radius: 0.5rem;
  margin: var(--space-md) 0;
  min-height: 200px;
}

.chart-container {
  max-width: 100%;
  overflow-x: auto;
}

.qr-code-container {
  flex-direction: column;
  text-align: center;
}

.qr-code-container[data-qr-download="true"]::after {
  content: "Tap to download";
  display: block;
  margin-top: var(--space-sm);
  font-size: 0.75rem;
  color: #6c757d;
}

@media (min-width: 768px) {
  .qr-code-container[data-qr-download="true"]::after {
    content: "Click to download";
  }
}

/* ============================================
   Code Blocks - Mobile Optimized
   ============================================ */

pre {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background-color: #f8f9fa;
  padding: var(--space-md);
  border-radius: 0.25rem;
  margin-bottom: var(--space-md);
  font-size: 0.875rem;
  max-width: 100%;
}

@media (min-width: 768px) {
  pre {
    padding: var(--space-lg);
    font-size: 0.9375rem;
  }
}

code {
  background-color: #f8f9fa;
  color: #e83e8c;
  padding: 0.125em 0.25em;
  font-size: 0.875em;
  border-radius: 0.25rem;
  word-break: break-word;
}

pre code {
  background: none;
  color: inherit;
  padding: 0;
  font-size: inherit;
  word-break: normal;
}

/* ============================================
   Tables - Mobile Responsive
   ============================================ */

.table-wrapper,
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: var(--space-md);
}

table {
  min-width: 100%;
  font-size: 0.875rem;
}

@media (min-width: 768px) {
  table {
    font-size: 1rem;
  }
}

th, td {
  padding: var(--space-sm);
  text-align: left;
}

@media (min-width: 768px) {
  th, td {
    padding: 0.75rem;
  }
}

/* Mobile: Compact table headers */
thead th {
  font-size: 0.75rem;
  font-weight: 600;
  background: #f8f9fa;
  position: sticky;
  top: 0;
  z-index: 10;
}

@media (min-width: 768px) {
  thead th {
    font-size: 0.875rem;
  }
}

/* ============================================
   Blockquotes - Mobile Optimized
   ============================================ */

blockquote {
  border-left: 3px solid #0066cc;
  margin: 0 0 var(--space-md);
  padding: var(--space-sm) var(--space-md);
  background-color: #f8f9fa;
  border-radius: 0.25rem;
  font-size: 1rem;
}

@media (min-width: 768px) {
  blockquote {
    border-left-width: 4px;
    padding: var(--space-md) var(--space-lg);
    font-size: 1.125rem;
  }
}

blockquote footer {
  font-size: 0.875rem;
  color: #6c757d;
  margin-top: var(--space-sm);
}

/* ============================================
   Lists - Mobile Spacing
   ============================================ */

ul, ol {
  margin: 0 0 var(--space-md);
  padding-left: 1.5rem;
}

@media (min-width: 768px) {
  ul, ol {
    padding-left: 2rem;
  }
}

li {
  margin-bottom: var(--space-xs);
}

/* Nested lists */
ul ul, ol ul, ul ol, ol ol {
  margin-top: var(--space-xs);
  margin-bottom: 0;
}

/* ============================================
   Buttons - Mobile Touch Targets
   ============================================ */

.btn {
  /* Minimum 44x44px touch target for mobile */
  min-height: 44px;
  min-width: 44px;
  padding: 0.625rem 1.25rem;
  font-size: 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}

@media (min-width: 768px) {
  .btn {
    min-height: auto;
    padding: 0.5rem 1.5rem;
  }
}

.btn-sm {
  min-height: 36px;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
}

.btn-lg {
  min-height: 52px;
  padding: 0.75rem 1.5rem;
  font-size: 1.125rem;
}

@media (min-width: 768px) {
  .btn-lg {
    padding: 0.75rem 2rem;
  }
}

/* ============================================
   Mobile Performance Optimizations
   ============================================ */

/* Reduce animations on mobile for better performance */
@media (max-width: 768px) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  /* Keep essential transitions */
  a,
  button,
  .btn,
  summary {
    transition-duration: 0.2s !important;
  }
}

/* Optimize scrolling performance */
@media (max-width: 768px) {
  body {
    -webkit-overflow-scrolling: touch;
  }

  /* Reduce repaints during scroll */
  .fixed,
  .pdf-export-container {
    will-change: transform;
  }
}

/* Mobile spacing adjustments */
@media (max-width: 768px) {
  /* Reduce section padding on mobile */
  .dnd_section {
    padding-top: 30px !important;
    padding-bottom: 30px !important;
  }

  /* Reduce container padding on mobile */
  .content-wrapper,
  .dnd-section__content,
  .dnd_area {
    padding-left: 15px !important;
    padding-right: 15px !important;
  }

  /* Tighter heading spacing on mobile */
  h1, h2, h3, h4, h5, h6 {
    margin-top: 0;
  }

  h2[id] {
    /* Styled section headers */
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
  }
}

/* ============================================
   Utility Classes - Mobile First
   ============================================ */

/* Hide on mobile, show on desktop */
.hide-mobile {
  display: none;
}

@media (min-width: 768px) {
  .hide-mobile {
    display: initial;
  }
}

/* Show on mobile, hide on desktop */
.show-mobile {
  display: initial;
}

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

/* Text alignment utilities */
.text-center-mobile {
  text-align: center;
}

@media (min-width: 768px) {
  .text-center-mobile {
    text-align: initial;
  }
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
  /* Hide interactive elements */
  .pdf-export-container,
  .generate-pdf {
    display: none !important;
  }

  /* Ensure all accordions are expanded */
  details {
    open: true;
  }

  details > *:not(summary) {
    display: block !important;
  }

  /* Reset colors for print */
  body {
    color: black;
    background: white;
  }

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

/* ============================================
   High Contrast Mode Support
   ============================================ */

@media (prefers-contrast: high) {
  .card,
  details,
  blockquote {
    border-width: 2px;
  }

  .btn {
    border-width: 2px;
    font-weight: 600;
  }
}

/* ============================================
   Dark Mode Support (System Preference)
   ============================================ */

@media (prefers-color-scheme: dark) {
  .color-swatch > div {
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
  }

  .pdf-export-container .generate-pdf {
    background: #1a1a1a;
    border-color: #4a9eff;
    color: #4a9eff;
  }

  .pdf-export-container .generate-pdf:hover {
    background: #4a9eff;
    color: #1a1a1a;
  }
}