/**
 * NischenKit Global Styles
 *
 * Contains:
 * - CSS Reset (minimal, modern)
 * - Base typography defaults
 * - CTA Button component
 * - Prose styles for article content
 * - Rating stars component
 * - Utility classes
 */

@import './variables.css';

/* ==========================================================================
   CSS RESET
   Minimal modern reset - no form element resets (deferred to later)
   ========================================================================== */

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

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

body {
  min-height: 100%;
  margin: 0;
  padding: 0;
  font-family: var(--font-family-base);
  font-size: var(--font-size-base);
  line-height: var(--line-height-normal);
  color: var(--color-neutral-800);
  background-color: var(--color-surface-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Remove default margins */
h1, h2, h3, h4, h5, h6,
p,
blockquote,
figure {
  margin: 0;
}

/* Responsive images by default */
img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Remove list styles on ul, ol with role="list" (accessibility pattern) */
ul[role='list'],
ol[role='list'] {
  list-style: none;
  padding: 0;
  margin: 0;
}

/* Inherit fonts for interactive elements */
button,
input,
select,
textarea {
  font: inherit;
}

/* Reduce motion for users who prefer it */
@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;
  }
}

/* ==========================================================================
   UTILITY CLASSES
   ========================================================================== */

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

/* ==========================================================================
   CTA BUTTON COMPONENT
   Three variants: primary, secondary, ghost
   Three sizes: sm, md, lg
   All sizes meet 44x44px minimum touch target
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  font-family: var(--font-family-base);
  font-weight: var(--font-weight-medium);
  text-decoration: none;
  text-align: center;
  white-space: nowrap;
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  transition: background-color var(--transition-fast),
              border-color var(--transition-fast),
              color var(--transition-fast),
              box-shadow var(--transition-fast);
}

/* Focus ring for accessibility - visible focus indicator */
.btn:focus {
  outline: none;
}

.btn:focus-visible {
  outline: 2px solid var(--color-primary-500);
  outline-offset: 2px;
}

/* Disabled state */
.btn:disabled,
.btn[aria-disabled='true'] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   Button Sizes
   All sizes meet 44x44px minimum touch target on mobile
   -------------------------------------------------------------------------- */

.btn-sm {
  min-height: 2.75rem; /* 44px - touch target */
  padding: var(--space-sm) var(--space-md);
  font-size: var(--font-size-sm);
}

.btn-md {
  min-height: 2.75rem; /* 44px - touch target */
  padding: var(--space-sm) var(--space-lg);
  font-size: var(--font-size-base);
}

.btn-lg {
  min-height: 3rem; /* 48px */
  padding: var(--space-md) var(--space-xl);
  font-size: var(--font-size-lg);
}

/* Larger touch targets on desktop where precision is easier */
@media (min-width: 768px) {
  .btn-sm {
    min-height: 2.25rem; /* 36px */
    padding: var(--space-xs) var(--space-md);
  }

  .btn-md {
    min-height: 2.5rem; /* 40px */
  }
}

/* --------------------------------------------------------------------------
   Button Variants
   -------------------------------------------------------------------------- */

/* Primary - Filled with primary color, white text */
.btn-primary {
  background-color: var(--color-primary-600);
  border-color: var(--color-primary-600);
  color: #ffffff;
}

.btn-primary:hover {
  background-color: var(--color-primary-700);
  border-color: var(--color-primary-700);
}

.btn-primary:active {
  background-color: var(--color-primary-800);
  border-color: var(--color-primary-800);
}

/* Secondary - Filled with secondary color */
.btn-secondary {
  background-color: var(--color-secondary-600);
  border-color: var(--color-secondary-600);
  color: #ffffff;
}

.btn-secondary:hover {
  background-color: var(--color-secondary-700);
  border-color: var(--color-secondary-700);
}

.btn-secondary:active {
  background-color: var(--color-secondary-800);
  border-color: var(--color-secondary-800);
}

/* Ghost - Transparent background, visible border, primary text */
.btn-ghost {
  background-color: transparent;
  border-color: var(--color-neutral-300);
  color: var(--color-neutral-700);
}

.btn-ghost:hover {
  background-color: var(--color-neutral-100);
  border-color: var(--color-neutral-400);
  color: var(--color-neutral-900);
}

.btn-ghost:active {
  background-color: var(--color-neutral-200);
}

/* ==========================================================================
   PROSE STYLES
   Scoped under .prose class for article/guide content
   Optimized for readability with comfortable line length and spacing
   ========================================================================== */

.prose {
  max-width: 70ch; /* 65-75ch optimal reading line length */
  line-height: var(--line-height-relaxed);
  color: var(--color-neutral-800);
}

/* --------------------------------------------------------------------------
   Prose Headings
   Clear visual hierarchy with proper spacing
   -------------------------------------------------------------------------- */

.prose h1,
.prose h2,
.prose h3,
.prose h4,
.prose h5,
.prose h6 {
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
  color: var(--color-neutral-900);
}

.prose h1 {
  font-size: var(--font-size-4xl);
  margin-top: 0;
  margin-bottom: var(--space-lg);
}

.prose h2 {
  font-size: var(--font-size-3xl);
  margin-top: var(--space-2xl);
  margin-bottom: var(--space-md);
}

.prose h3 {
  font-size: var(--font-size-2xl);
  margin-top: var(--space-xl);
  margin-bottom: var(--space-sm);
}

.prose h4 {
  font-size: var(--font-size-xl);
  margin-top: var(--space-lg);
  margin-bottom: var(--space-sm);
}

.prose h5 {
  font-size: var(--font-size-lg);
  margin-top: var(--space-lg);
  margin-bottom: var(--space-xs);
}

.prose h6 {
  font-size: var(--font-size-base);
  margin-top: var(--space-md);
  margin-bottom: var(--space-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-neutral-600);
}

/* Adjust spacing when headings follow content */
.prose :is(h2, h3, h4, h5, h6) + :is(h2, h3, h4, h5, h6) {
  margin-top: var(--space-md);
}

/* --------------------------------------------------------------------------
   Prose Paragraphs and Inline Elements
   -------------------------------------------------------------------------- */

.prose p {
  margin-top: 0;
  margin-bottom: var(--space-md);
}

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

.prose strong {
  font-weight: var(--font-weight-semibold);
  color: var(--color-neutral-900);
}

.prose em {
  font-style: italic;
}

.prose a {
  color: var(--color-primary-600);
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color var(--transition-fast);
}

.prose a:hover {
  color: var(--color-primary-700);
}

.prose a:focus-visible {
  outline: 2px solid var(--color-primary-500);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.prose code {
  font-family: var(--font-family-mono);
  font-size: 0.875em;
  background-color: var(--color-neutral-100);
  padding: 0.125em 0.375em;
  border-radius: var(--radius-sm);
  color: var(--color-danger-600);
}

.prose pre {
  font-family: var(--font-family-mono);
  font-size: var(--font-size-sm);
  background-color: var(--color-neutral-900);
  color: var(--color-neutral-100);
  padding: var(--space-md);
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin-top: var(--space-md);
  margin-bottom: var(--space-md);
}

.prose pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

.prose hr {
  border: 0;
  border-top: 1px solid var(--color-neutral-200);
  margin: var(--space-xl) 0;
}

/* --------------------------------------------------------------------------
   Prose Lists
   Proper indentation, markers, and nested list support
   -------------------------------------------------------------------------- */

.prose ul,
.prose ol {
  margin-top: var(--space-md);
  margin-bottom: var(--space-md);
  padding-left: var(--space-lg);
}

.prose ul {
  list-style-type: disc;
}

.prose ol {
  list-style-type: decimal;
}

.prose li {
  margin-bottom: var(--space-sm);
}

.prose li:last-child {
  margin-bottom: 0;
}

/* Nested lists */
.prose li > ul,
.prose li > ol {
  margin-top: var(--space-sm);
  margin-bottom: 0;
}

.prose ul ul {
  list-style-type: circle;
}

.prose ul ul ul {
  list-style-type: square;
}

/* --------------------------------------------------------------------------
   Prose Blockquotes
   Left border accent with distinct styling
   -------------------------------------------------------------------------- */

.prose blockquote {
  border-left: 4px solid var(--color-primary-300);
  padding-left: var(--space-md);
  margin: var(--space-md) 0;
  font-style: italic;
  color: var(--color-neutral-600);
}

.prose blockquote p {
  margin-bottom: var(--space-sm);
}

.prose blockquote p:last-child {
  margin-bottom: 0;
}

.prose blockquote cite {
  display: block;
  font-style: normal;
  font-size: var(--font-size-sm);
  margin-top: var(--space-sm);
  color: var(--color-neutral-500);
}

.prose blockquote cite::before {
  content: '\2014\00a0'; /* em dash + non-breaking space */
}

/* --------------------------------------------------------------------------
   Prose Tables
   Bordered cells, header background, zebra striping
   -------------------------------------------------------------------------- */

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin-top: var(--space-md);
  margin-bottom: var(--space-md);
  font-size: var(--font-size-sm);
}

.prose thead {
  background-color: var(--color-neutral-100);
}

.prose th {
  font-weight: var(--font-weight-semibold);
  text-align: left;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--color-neutral-200);
  color: var(--color-neutral-900);
}

.prose td {
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--color-neutral-200);
  vertical-align: top;
}

/* Zebra striping for readability */
.prose tbody tr:nth-child(even) {
  background-color: var(--color-neutral-50);
}

/* Responsive table wrapper for mobile */
.prose-table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: var(--space-md) 0;
}

.prose-table-wrapper table {
  margin: 0;
}

/* --------------------------------------------------------------------------
   Prose Images and Figures
   -------------------------------------------------------------------------- */

.prose img {
  border-radius: var(--radius-md);
  margin-top: var(--space-md);
  margin-bottom: var(--space-md);
}

.prose figure {
  margin: var(--space-lg) 0;
}

.prose figure img {
  margin: 0;
}

.prose figcaption {
  font-size: var(--font-size-sm);
  color: var(--color-neutral-500);
  margin-top: var(--space-sm);
  text-align: center;
}

/* ==========================================================================
   RATING STARS COMPONENT
   CSS-only implementation with half-star support
   Uses inline SVG stars styled with CSS
   Scale: 1-5 stars (matches ProductFrontmatter schema)
   ========================================================================== */

.rating-stars {
  display: inline-flex;
  align-items: center;
  gap: 0.125rem;
}

/* Individual star container */
.rating-star {
  position: relative;
  width: 1.25rem;  /* 20px */
  height: 1.25rem;
  flex-shrink: 0;
}

/* Star SVG base styles */
.rating-star svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Empty star (background) */
.rating-star-empty {
  fill: var(--color-neutral-300);
}

/* Filled star */
.rating-star-filled {
  fill: var(--color-warning-400);
}

/* Half-star support using clip-path */
.rating-star-half {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  clip-path: inset(0 50% 0 0);
}

.rating-star-half svg {
  fill: var(--color-warning-400);
}

/* Alternative: CSS-only stars using unicode */
.rating-stars-css {
  display: inline-flex;
  align-items: center;
  font-size: 1.25rem;
  line-height: 1;
  letter-spacing: 0.125rem;
}

.rating-stars-css::before {
  content: attr(data-stars);
  color: var(--color-warning-400);
}

/* Size variants */
.rating-stars-sm .rating-star {
  width: 1rem;
  height: 1rem;
}

.rating-stars-lg .rating-star {
  width: 1.5rem;
  height: 1.5rem;
}

/* ==========================================================================
   RESPONSIVE ADJUSTMENTS
   Mobile-first approach with min-width media queries
   ========================================================================== */

/* Tablet and up */
@media (min-width: 768px) {
  .prose h1 {
    font-size: calc(var(--font-size-4xl) * 1.1);
  }

  .prose h2 {
    font-size: calc(var(--font-size-3xl) * 1.05);
  }
}

/* Desktop and up */
@media (min-width: 1024px) {
  .prose {
    max-width: 75ch;
  }
}
