/**
 * Lufia Design System
 * Brand-compliant design tokens and component styles
 * 
 * Typography: Signika (body/UI) + Space Grotesk (functional/technical)
 * Color Palette: Nocturnal Soul, Quartz Mist, Mystic Pulse, Gentle Flame, Electric Amethyst
 * Spacing: 8px base unit system
 */

/* ============================================
   1. DESIGN TOKENS (CSS Custom Properties)
   ============================================ */

:root {
  /* === Core Brand Colors === */
  --color-nocturnal-soul: #0F031F;
  --color-quartz-mist: #EFE7E7;
  --color-mystic-pulse: #4325DA;
  --color-gentle-flame: #FF9452;
  --color-electric-amethyst: #972070;

  /* === UI Token Mapping === */
  --bg: var(--color-quartz-mist);
  --surface-1: rgba(239, 231, 231, 0.6);
  --surface-2: rgba(15, 3, 31, 0.08);
  
  --text-1: var(--color-nocturnal-soul);
  --text-2: rgba(15, 3, 31, 0.7);
  --text-inverse: var(--color-quartz-mist);
  
  --accent: var(--color-mystic-pulse);
  --accent-2: var(--color-gentle-flame);
  --accent-3: var(--color-electric-amethyst);
  
  --focus-ring: var(--color-mystic-pulse);
  --danger: var(--color-electric-amethyst);
  --warning: var(--color-gentle-flame);
  --divider: rgba(15, 3, 31, 0.12);

  /* === Gradients (use sparingly, hero panels only) === */
  --gradient-a: linear-gradient(45deg, #38132C 0%, #4325DA 65%, #F88E58 85%);
  --gradient-b: linear-gradient(45deg, #FF9452 0%, #FBBD97 100%);
  --gradient-c: linear-gradient(-135deg, #4325DA 0%, #972070 100%);

  /* === Typography Scale === */
  --font-family-body: 'Signika', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-family-ui: 'Space Grotesk', 'SF Mono', 'Monaco', 'Courier New', monospace;

  /* Display / Page title */
  --font-size-display: 36px;
  --font-weight-display: 700;
  --line-height-display: 1.15;

  /* Section title */
  --font-size-section: 24px;
  --font-weight-section: 600;
  --line-height-section: 1.2;

  /* Card title */
  --font-size-card-title: 20px;
  --font-weight-card-title: 500;
  --line-height-card-title: 1.25;

  /* Body */
  --font-size-body: 16px;
  --font-weight-body: 400;
  --line-height-body: 1.5;

  /* UI labels */
  --font-size-ui-label: 13px;
  --font-weight-ui-label: 500;
  --line-height-ui-label: 1.25;

  /* Helper text */
  --font-size-helper: 12px;
  --font-weight-helper: 400;
  --line-height-helper: 1.35;

  /* Buttons */
  --font-size-button: 14px;
  --font-weight-button: 500;
  --line-height-button: 1.1;

  /* === Spacing System (8px base) === */
  --spacing-unit: 8px;
  --spacing-xs: calc(var(--spacing-unit) * 1); /* 8px */
  --spacing-sm: calc(var(--spacing-unit) * 2); /* 16px */
  --spacing-md: calc(var(--spacing-unit) * 3); /* 24px */
  --spacing-lg: calc(var(--spacing-unit) * 4); /* 32px */
  --spacing-xl: calc(var(--spacing-unit) * 6); /* 48px */

  /* === Layout === */
  --container-max-width: 1200px;
  --page-padding-desktop: 24px;
  --page-padding-mobile: 16px;
  --card-padding: 24px;

  /* === Borders & Radius === */
  --border-width: 1px;
  --border-color: var(--divider);
  --border-color-strong: rgba(15, 3, 31, 0.2);
  
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 20px;

  /* === Focus Ring === */
  --focus-ring-width: 3px;
  --focus-ring-offset: 2px;
}

/* ============================================
   2. GLOBAL RESET & BASE STYLES
   ============================================ */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-family-body);
  font-size: var(--font-size-body);
  font-weight: var(--font-weight-body);
  line-height: var(--line-height-body);
  color: var(--text-1);
  background-color: var(--bg);
  min-height: 100vh;
}

/* ============================================
   3. TYPOGRAPHY HIERARCHY
   ============================================ */

h1, .display {
  font-family: var(--font-family-body);
  font-size: var(--font-size-display);
  font-weight: var(--font-weight-display);
  line-height: var(--line-height-display);
  letter-spacing: -0.02em;
}

h2, .section-title {
  font-family: var(--font-family-body);
  font-size: var(--font-size-section);
  font-weight: var(--font-weight-section);
  line-height: var(--line-height-section);
}

h3, .card-title {
  font-family: var(--font-family-body);
  font-size: var(--font-size-card-title);
  font-weight: var(--font-weight-card-title);
  line-height: var(--line-height-card-title);
}

p {
  font-family: var(--font-family-body);
  font-size: var(--font-size-body);
  font-weight: var(--font-weight-body);
  line-height: var(--line-height-body);
}

.ui-label {
  font-family: var(--font-family-ui);
  font-size: var(--font-size-ui-label);
  font-weight: var(--font-weight-ui-label);
  line-height: var(--line-height-ui-label);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.helper-text {
  font-family: var(--font-family-ui);
  font-size: var(--font-size-helper);
  font-weight: var(--font-weight-helper);
  line-height: var(--line-height-helper);
  color: var(--text-2);
}

/* ============================================
   4. LAYOUT COMPONENTS
   ============================================ */

.app-shell {
  min-height: 100vh;
  background-color: var(--bg);
}

.top-bar {
  background-color: var(--surface-1);
  border-bottom: var(--border-width) solid var(--divider);
  padding: var(--spacing-sm) var(--page-padding-desktop);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  height: 40px;
  min-height: 40px;
  object-fit: contain;
}

.nav {
  display: flex;
  gap: var(--spacing-md);
  align-items: center;
}

.container {
  max-width: var(--container-max-width);
  margin: 0 auto;
  padding: var(--spacing-lg) var(--page-padding-desktop);
}

/* ============================================
   5. BUTTONS
   ============================================ */

.btn {
  font-family: var(--font-family-ui);
  font-size: var(--font-size-button);
  font-weight: var(--font-weight-button);
  line-height: var(--line-height-button);
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-xs);
  text-decoration: none;
}

.btn:focus-visible {
  outline: var(--focus-ring-width) solid var(--focus-ring);
  outline-offset: var(--focus-ring-offset);
}

.btn-primary {
  background-color: var(--accent);
  color: var(--text-inverse);
}

.btn-primary:hover {
  background-color: rgba(67, 37, 218, 0.9);
}

.btn-primary:active {
  background-color: rgba(67, 37, 218, 0.8);
}

.btn-secondary {
  background-color: transparent;
  color: var(--accent);
  border: var(--border-width) solid var(--accent);
}

.btn-secondary:hover {
  background-color: rgba(67, 37, 218, 0.05);
}

.btn-secondary:active {
  background-color: rgba(67, 37, 218, 0.1);
}

.btn-destructive {
  background-color: var(--danger);
  color: var(--text-inverse);
}

.btn-destructive:hover {
  background-color: rgba(151, 32, 112, 0.9);
}

/* ============================================
   6. INPUTS & FORMS
   ============================================ */

.form-group {
  margin-bottom: var(--spacing-md);
}

.form-label {
  font-family: var(--font-family-ui);
  font-size: var(--font-size-ui-label);
  font-weight: var(--font-weight-ui-label);
  display: block;
  margin-bottom: var(--spacing-xs);
  color: var(--text-1);
}

.form-input,
.form-textarea,
.form-select {
  font-family: var(--font-family-body);
  font-size: var(--font-size-body);
  width: 100%;
  padding: 12px 16px;
  background-color: var(--surface-1);
  border: var(--border-width) solid var(--divider);
  border-radius: var(--radius-sm);
  color: var(--text-1);
  transition: all 0.2s ease;
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--text-2);
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 var(--focus-ring-width) rgba(67, 37, 218, 0.2);
}

.form-input.error,
.form-textarea.error,
.form-select.error {
  border-color: var(--danger);
}

.form-input.error:focus,
.form-textarea.error:focus,
.form-select.error:focus {
  box-shadow: 0 0 0 var(--focus-ring-width) rgba(151, 32, 112, 0.2);
}

.form-error {
  font-family: var(--font-family-ui);
  font-size: var(--font-size-helper);
  color: var(--danger);
  margin-top: var(--spacing-xs);
  display: block;
}

/* ============================================
   7. CARDS
   ============================================ */

.card {
  background-color: var(--surface-1);
  border: var(--border-width) solid var(--divider);
  border-radius: var(--radius-md);
  padding: var(--card-padding);
}

.card-header {
  margin-bottom: var(--spacing-md);
}

.card-title {
  font-family: var(--font-family-body);
  font-size: var(--font-size-card-title);
  font-weight: var(--font-weight-card-title);
  line-height: var(--line-height-card-title);
  margin-bottom: var(--spacing-xs);
}

.card-meta {
  font-family: var(--font-family-ui);
  font-size: var(--font-size-helper);
  color: var(--text-2);
}

.card-accent {
  border-top: 3px solid var(--accent);
}

.card-accent-2 {
  border-top: 3px solid var(--accent-2);
}

/* ============================================
   8. LINKS
   ============================================ */

a {
  color: var(--accent);
  text-decoration: none;
  transition: all 0.2s ease;
}

a:hover {
  text-decoration: underline;
}

a:focus-visible {
  outline: var(--focus-ring-width) solid var(--focus-ring);
  outline-offset: var(--focus-ring-offset);
  border-radius: 2px;
}

/* ============================================
   9. TAGS / CHIPS
   ============================================ */

.tag {
  font-family: var(--font-family-ui);
  font-size: var(--font-size-helper);
  font-weight: var(--font-weight-ui-label);
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  background-color: rgba(255, 148, 82, 0.15);
  color: var(--text-1);
  border-radius: 6px;
}

.tag-accent {
  background-color: rgba(67, 37, 218, 0.15);
}

.tag-accent-3 {
  background-color: rgba(151, 32, 112, 0.15);
}

/* ============================================
   10. TABLES
   ============================================ */

.table {
  width: 100%;
  border-collapse: collapse;
  margin-top: var(--spacing-md);
}

.table thead {
  font-family: var(--font-family-ui);
  font-size: var(--font-size-ui-label);
  font-weight: var(--font-weight-ui-label);
  text-align: left;
  border-bottom: var(--border-width) solid var(--border-color-strong);
}

.table th {
  padding: var(--spacing-sm);
  color: var(--text-1);
}

.table td {
  padding: var(--spacing-sm);
  border-bottom: var(--border-width) solid var(--divider);
  font-family: var(--font-family-body);
}

.table td.numeric {
  font-family: var(--font-family-ui);
  text-align: right;
}

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

.table tbody tr:hover {
  background-color: rgba(15, 3, 31, 0.02);
}

/* ============================================
   11. ALERTS / TOASTS
   ============================================ */

.alert {
  padding: var(--spacing-sm) var(--spacing-md);
  border-radius: var(--radius-sm);
  border-left: 4px solid;
  margin-bottom: var(--spacing-md);
}

.alert-info {
  background-color: rgba(67, 37, 218, 0.1);
  border-left-color: var(--accent);
  color: var(--text-1);
}

.alert-warning {
  background-color: rgba(255, 148, 82, 0.1);
  border-left-color: var(--warning);
  color: var(--text-1);
}

.alert-error {
  background-color: rgba(151, 32, 112, 0.1);
  border-left-color: var(--danger);
  color: var(--text-1);
}

/* ============================================
   12. LOADING SPINNER
   ============================================ */

.spinner {
  border: 4px solid rgba(15, 3, 31, 0.1);
  border-top: 4px solid var(--accent);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
  margin: var(--spacing-md) auto;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* ============================================
   13. RESPONSIVE ADJUSTMENTS
   ============================================ */

@media (max-width: 768px) {
  :root {
    --font-size-display: 28px;
    --font-size-section: 20px;
    --font-size-card-title: 18px;
    --page-padding-desktop: var(--page-padding-mobile);
  }

  .top-bar {
    padding: var(--spacing-sm) var(--page-padding-mobile);
  }

  .container {
    padding: var(--spacing-md) var(--page-padding-mobile);
  }

  .card {
    padding: var(--spacing-sm);
  }

  .nav {
    gap: var(--spacing-sm);
  }
}

/* ============================================
   14. UTILITY CLASSES
   ============================================ */

.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-2); }
.text-inverse { color: var(--text-inverse); }

.mt-xs { margin-top: var(--spacing-xs); }
.mt-sm { margin-top: var(--spacing-sm); }
.mt-md { margin-top: var(--spacing-md); }
.mt-lg { margin-top: var(--spacing-lg); }

.mb-xs { margin-bottom: var(--spacing-xs); }
.mb-sm { margin-bottom: var(--spacing-sm); }
.mb-md { margin-bottom: var(--spacing-md); }
.mb-lg { margin-bottom: var(--spacing-lg); }

.gap-xs { gap: var(--spacing-xs); }
.gap-sm { gap: var(--spacing-sm); }
.gap-md { gap: var(--spacing-md); }

.flex { display: flex; }
.flex-column { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
