/* =========================================
   CLEAR-4 DESIGN SYSTEM
   Shared Styles & Design Tokens
   ========================================= */

:root {
  /* 4px Spacing Grid */
  --s4: 4px;
  --s8: 8px;
  --s12: 12px;
  --s16: 16px;
  --s20: 20px;
  --s24: 24px;
  --s32: 32px;
  --s40: 40px;
  --s48: 48px;
  --s64: 64px;
  
  /* Typography */
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --fs-xs: 11px;
  --fs-sm: 13px;
  --fs-base: 15px;
  --fs-lg: 17px;
  --fs-xl: 20px;
  --fs-2xl: 24px;
  --fs-3xl: 32px;
  --fs-4xl: 40px;
  
  --lh-tight: 1.2;
  --lh-normal: 1.5;
  --lh-relaxed: 1.7;
  
  --tracking-tight: -0.02em;
  --tracking-normal: 0;
  --tracking-wide: 0.08em;
  
  /* Radius */
  --r4: 4px;
  --r8: 8px;
  --r12: 12px;
  --r16: 16px;
  --r20: 20px;
  --r-pill: 999px;
  
  /* Shadows */
  --sh-soft: 0 4px 12px rgba(0, 0, 0, 0.06);
  --sh-medium: 0 8px 24px rgba(0, 0, 0, 0.10);
  --sh-deep: 0 18px 45px rgba(0, 0, 0, 0.16);
  --sh-premium: 0 1px 1px rgba(0, 0, 0, 0.04), 0 10px 30px rgba(0, 0, 0, 0.08);
  
  /* Transitions */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --duration-fast: 150ms;
  --duration-normal: 220ms;
  --duration-slow: 320ms;
  
  /* Layout */
  --page-max: 1120px;
  --header-height: 64px;
  
  /* Colors - Default Theme */
  --bg: #f5f5f4;
  --bg-alt: #ececea;
  --surface: #ffffff;
  --surface-soft: #fafaf9;
  --border: #e0e0de;
  --border-light: rgba(0, 0, 0, 0.06);
  
  --text: #1f2937;
  --text-soft: #4b5563;
  --text-muted: #9ca3af;
  
  --brand: #0f766e;
  --brand-hover: #0d6560;
  --brand-soft: rgba(15, 118, 110, 0.08);
  
  --accent: #c9a227;
  --accent-soft: rgba(201, 162, 39, 0.12);
  
  --success: #059669;
  --warning: #d97706;
  --error: #dc2626;
  --info: #0284c7;
}

/* Theme Variants */
.theme-handwerk {
  --bg: #f5eee3;
  --surface: #ffffff;
  --border: rgba(56, 44, 30, 0.18);
  --text: #2c2419;
  --text-soft: rgba(44, 36, 25, 0.85);
  --text-muted: rgba(44, 36, 25, 0.66);
  --brand: #b47836;
  --brand-hover: #9f6327;
  --brand-soft: rgba(180, 120, 54, 0.16);
  --accent: #e0b37b;
}

.theme-landwirtschaft {
  --bg: #f4f3ea;
  --surface: #ffffff;
  --border: rgba(51, 63, 39, 0.18);
  --text: #253421;
  --text-soft: rgba(37, 52, 33, 0.88);
  --brand: #799b3b;
  --brand-hover: #637f30;
  --brand-soft: rgba(121, 155, 59, 0.16);
  --accent: #c59d4e;
}

.theme-premium {
  --bg: #fbfbfc;
  --surface: #ffffff;
  --border: rgba(2, 6, 23, 0.10);
  --text: #0b1220;
  --text-soft: rgba(11, 18, 32, 0.78);
  --brand: #0f766e;
  --accent: #c9a227;
}

.theme-dark {
  --bg: #0f0f0f;
  --bg-alt: #1a1a1a;
  --surface: #1f1f1f;
  --surface-soft: #2a2a2a;
  --border: rgba(255, 255, 255, 0.10);
  --border-light: rgba(255, 255, 255, 0.05);
  --text: #f5f5f5;
  --text-soft: rgba(245, 245, 245, 0.80);
  --text-muted: rgba(245, 245, 245, 0.55);
  --brand: #5eead4;
  --brand-hover: #2dd4bf;
  --brand-soft: rgba(94, 234, 212, 0.12);
  --accent: #fbbf24;
  --accent-soft: rgba(251, 191, 36, 0.15);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: var(--lh-normal);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }

/* Library Page Layout */
.library-page {
  min-height: 100vh;
  display: flex;
}

.library-sidebar {
  width: 260px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: var(--s24);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.library-sidebar h2 {
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: var(--s12);
  margin-top: var(--s24);
}

.library-sidebar h2:first-child {
  margin-top: 0;
}

.library-sidebar a {
  display: block;
  padding: var(--s8) var(--s12);
  font-size: var(--fs-sm);
  color: var(--text-soft);
  border-radius: var(--r8);
  transition: all var(--duration-fast);
}

.library-sidebar a:hover {
  background: var(--brand-soft);
  color: var(--brand);
}

.library-sidebar a.active {
  background: var(--brand);
  color: #fff;
}

.library-content {
  flex: 1;
  padding: var(--s32);
  max-width: calc(100% - 260px);
}

.library-header {
  margin-bottom: var(--s32);
  padding-bottom: var(--s24);
  border-bottom: 1px solid var(--border);
}

.library-title {
  font-size: var(--fs-3xl);
  font-weight: 700;
  margin-bottom: var(--s8);
}

.library-description {
  font-size: var(--fs-lg);
  color: var(--text-soft);
  max-width: 640px;
}

/* Component Preview */
.component-section {
  margin-bottom: var(--s48);
}

.component-title {
  font-size: var(--fs-xl);
  font-weight: 600;
  margin-bottom: var(--s16);
}

.component-description {
  font-size: var(--fs-base);
  color: var(--text-soft);
  margin-bottom: var(--s16);
  max-width: 640px;
}

.component-preview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r16);
  padding: var(--s24);
  margin-bottom: var(--s16);
}

.component-code {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--r12);
  padding: var(--s16);
  font-family: 'SF Mono', Monaco, monospace;
  font-size: var(--fs-sm);
  overflow-x: auto;
  white-space: pre;
}

.component-label {
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: var(--s12);
}

/* Utility Grid */
.preview-grid {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s16);
}

.preview-row {
  display: flex;
  align-items: center;
  gap: var(--s12);
  flex-wrap: wrap;
}

@media (max-width: 768px) {
  .library-page { flex-direction: column; }
  .library-sidebar { width: 100%; height: auto; position: relative; }
  .library-content { max-width: 100%; }
}

/* =========================================
   COMPONENT LIBRARY
   Buttons, Cards, Badges, Alerts, Forms, Tables
   ========================================= */

/* --- Buttons --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s8);
  padding: var(--s12) var(--s20);
  border-radius: var(--r-pill);
  font-family: var(--font);
  font-size: var(--fs-base);
  font-weight: 500;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: all var(--duration-fast) var(--ease-out);
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; box-shadow: var(--sh-soft); }
.btn-primary:hover:not(:disabled) { background: var(--brand-hover); transform: translateY(-1px); box-shadow: var(--sh-medium); }
.btn-secondary { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }
.btn-ghost { background: transparent; color: var(--text-soft); padding: var(--s8) var(--s12); }
.btn-ghost:hover:not(:disabled) { background: rgba(0,0,0,.04); color: var(--text); }
.btn-gold { background: var(--accent); color: var(--text); box-shadow: var(--sh-soft); }
.btn-gold:hover:not(:disabled) { transform: translateY(-1px); box-shadow: var(--sh-medium); }
.btn-full { width: 100%; }
.btn-group { display: flex; gap: var(--s8); flex-wrap: wrap; }

/* --- Cards --- */
.card {
  background: var(--surface);
  border-radius: var(--r16);
  border: 1px solid var(--border);
  padding: var(--s20);
  box-shadow: var(--sh-soft);
  transition: all var(--duration-normal) var(--ease-out);
}
.card:hover { transform: translateY(-2px); box-shadow: var(--sh-medium); }
.card-title { font-size: var(--fs-lg); font-weight: 600; margin-bottom: var(--s4); }
.card-subtitle { font-size: var(--fs-sm); color: var(--text-muted); }
.card-body { font-size: var(--fs-base); color: var(--text-soft); line-height: var(--lh-relaxed); }
.card-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: var(--s24); }
.card-grid-2 { grid-template-columns: repeat(2,1fr); }
@media (max-width: 900px) { .card-grid { grid-template-columns: repeat(2,1fr); } }
@media (max-width: 600px) { .card-grid, .card-grid-2 { grid-template-columns: 1fr; } }

/* --- Badges --- */
.badge {
  display: inline-flex; align-items: center;
  padding: var(--s4) var(--s12);
  border-radius: var(--r-pill);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  border: 1px solid var(--border);
  background: var(--bg-alt);
  color: var(--text-soft);
}
.badge-success { background: rgba(5,150,105,.10); border-color: rgba(5,150,105,.25); color: var(--success); }
.badge-warning { background: rgba(217,119,6,.10); border-color: rgba(217,119,6,.25); color: var(--warning); }
.badge-error { background: rgba(220,38,38,.10); border-color: rgba(220,38,38,.25); color: var(--error); }
.badge-info { background: rgba(2,132,199,.10); border-color: rgba(2,132,199,.25); color: var(--info); }

/* --- Alerts --- */
.alert {
  border: 1px solid var(--border);
  border-radius: var(--r16);
  padding: var(--s16) var(--s16);
  background: var(--surface);
  box-shadow: var(--sh-soft);
}
.alert-title { font-weight: 600; margin-bottom: var(--s4); }
.alert-text { color: var(--text-soft); font-size: var(--fs-sm); line-height: var(--lh-relaxed); }
.alert-info { border-color: rgba(2,132,199,.25); background: rgba(2,132,199,.06); }
.alert-success { border-color: rgba(5,150,105,.25); background: rgba(5,150,105,.06); }
.alert-warning { border-color: rgba(217,119,6,.25); background: rgba(217,119,6,.06); }
.alert-error { border-color: rgba(220,38,38,.25); background: rgba(220,38,38,.06); }

/* --- Forms --- */
.form-group { display: flex; flex-direction: column; gap: var(--s8); margin-bottom: var(--s16); }
.form-label { font-size: var(--fs-sm); font-weight: 500; color: var(--text-soft); }
.form-input, .form-textarea, .form-select {
  width: 100%; padding: var(--s12) var(--s16);
  border: 1px solid var(--border); border-radius: var(--r12);
  font-family: var(--font); font-size: var(--fs-base);
  background: var(--surface); color: var(--text);
  transition: all var(--duration-fast) var(--ease-out);
}
.form-input:focus, .form-textarea:focus, .form-select:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft);
}
.form-hint { font-size: var(--fs-xs); color: var(--text-muted); }
.form-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s16); }
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }

/* --- Tables --- */
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r16);
  overflow: hidden;
}
.table th, .table td {
  padding: var(--s12) var(--s16);
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.table th {
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--bg-alt);
}
.table tbody tr:hover { background: var(--surface-soft); }
.table td { font-size: var(--fs-sm); color: var(--text-soft); }
.table td strong { color: var(--text); }

/* --- Template (monospace block) --- */
.template {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  white-space: pre-wrap;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--r16);
  padding: var(--s16);
  color: var(--text-soft);
}

/* --- Micro (small disclaimer text) --- */
.micro {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  line-height: var(--lh-relaxed);
}

/* --- Utility Classes --- */
.text-right { text-align: right; }
.ul-grid {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 10px;
  color: var(--text-soft);
}

/* --- Pricing Badge Offset --- */
.pricing-badge-inset { top: 14px; }

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

/* Skip to main content link */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--s16);
  padding: var(--s8) var(--s16);
  background: var(--brand);
  color: #fff;
  border-radius: var(--r8);
  font-size: var(--fs-sm);
  font-weight: 600;
  z-index: 1000;
  transition: top var(--duration-fast) var(--ease-out);
}
.skip-link:focus {
  top: var(--s16);
}

/* Focus-visible styles (keyboard navigation) */
.btn:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}
.form-input:focus-visible, .form-textarea:focus-visible, .form-select:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}
a:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: var(--r4);
}

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

/* Respect system dark mode preference */
@media (prefers-color-scheme: dark) {
  :root:not(.theme-handwerk):not(.theme-landwirtschaft):not(.theme-premium):not([class*="theme-"]) {
    --bg: #0f0f0f;
    --bg-alt: #1a1a1a;
    --surface: #1f1f1f;
    --surface-soft: #2a2a2a;
    --border: rgba(255, 255, 255, 0.10);
    --border-light: rgba(255, 255, 255, 0.05);
    --text: #f5f5f5;
    --text-soft: rgba(245, 245, 245, 0.80);
    --text-muted: rgba(245, 245, 245, 0.55);
    --brand: #5eead4;
    --brand-hover: #2dd4bf;
    --brand-soft: rgba(94, 234, 212, 0.12);
    --accent: #fbbf24;
    --accent-soft: rgba(251, 191, 36, 0.15);
  }
}
