/* ========================================
   ИИ-Медиатор — Design System
   ======================================== */

/* ---- Theme Variables ---- */
:root {
  /* Spacing — 4px base grid */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;

  /* Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  /* Typography */
  --text-xs: 11px;
  --text-sm: 12px;
  --text-base: 14px;
  --text-md: 16px;
  --text-lg: 20px;
  --text-xl: 24px;
  --text-2xl: 28px;

  /* Transitions */
  --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --duration-fast: 0.15s;
  --duration-base: 0.25s;
  --duration-slow: 0.4s;

  /* Shadows (layered for realism) */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04), 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.04), 0 10px 20px rgba(0,0,0,0.08);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.08), 0 20px 48px rgba(0,0,0,0.12);
  --shadow-glow: 0 0 60px rgba(99, 102, 241, 0.08);

  /* Dark theme (default) */
  --bg-body: #09090b;
  --bg-surface: #18181b;
  --bg-elevated: #27272a;
  --bg-card: #27272a;
  --bg-hover: #3f3f46;

  --text-primary: #fafafa;
  --text-secondary: #a1a1aa;
  --text-tertiary: #71717a;
  --text-muted: #52525b;

  --accent-primary: #6366f1;
  --accent-secondary: #8b5cf6;
  --accent-tertiary: #22c55e;

  --accent-primary-15: rgba(99, 102, 241, 0.15);
  --accent-primary-25: rgba(99, 102, 241, 0.25);

  --status-active: #10b981;
  --status-active-bg: rgba(16, 185, 129, 0.15);
  --status-warn: #f59e0b;
  --status-warn-bg: rgba(245, 158, 11, 0.12);
  --status-review: #3b82f6;
  --status-review-bg: rgba(59, 130, 246, 0.12);

  --border-subtle: rgba(255,255,255,0.06);
  --border-default: rgba(255,255,255,0.1);
  --border-focus: rgba(99, 102, 241, 0.5);

  --orb-primary: rgba(99, 102, 241, 0.35);
  --orb-secondary: rgba(139, 92, 246, 0.25);
}

/* Light theme — auto from system */
@media (prefers-color-scheme: light) {
  :root {
    --bg-body: #f8f9fa;
    --bg-surface: #ffffff;
    --bg-elevated: #f1f3f4;
    --bg-card: #ffffff;
    --bg-hover: #e8eaed;

    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --text-tertiary: #9ca3af;
    --text-muted: #d1d5db;

    --accent-primary: #4f46e5;
    --accent-secondary: #7c3aed;

    --accent-primary-15: rgba(79, 70, 229, 0.12);
    --accent-primary-25: rgba(79, 70, 229, 0.2);

    /* Same vivid green for both themes */
    --status-active: #059669;
    --status-active-bg: rgba(5, 150, 105, 0.12);
    --status-warn: #d97706;
    --status-warn-bg: rgba(217, 119, 6, 0.12);
    --status-review: #2563eb;
    --status-review-bg: rgba(37, 99, 235, 0.12);

    --border-subtle: rgba(0,0,0,0.06);
    --border-default: rgba(0,0,0,0.1);
    --border-focus: rgba(79, 70, 229, 0.4);

    --orb-primary: rgba(99, 102, 241, 0.15);
    --orb-secondary: rgba(139, 92, 246, 0.1);

    --shadow-sm: 0 1px 2px rgba(0,0,0,0.06), 0 1px 3px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.04), 0 10px 20px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.06), 0 20px 48px rgba(0,0,0,0.08);
    --shadow-glow: 0 0 60px rgba(99, 102, 241, 0.06);
  }
}

/* Light override via data attribute */
[data-theme="light"] {
  --bg-body: #f8f9fa;
  --bg-surface: #ffffff;
  --bg-elevated: #f1f3f4;
  --bg-card: #ffffff;
  --bg-hover: #e8eaed;

  --text-primary: #1f2937;
  --text-secondary: #6b7280;
  --text-tertiary: #9ca3af;
  --text-muted: #d1d5db;

  --accent-primary: #4f46e5;
  --accent-secondary: #7c3aed;

  --accent-primary-15: rgba(79, 70, 229, 0.12);
  --accent-primary-25: rgba(79, 70, 229, 0.2);

  /* Same vivid green for both themes */
  --status-active: #059669;
  --status-active-bg: rgba(5, 150, 105, 0.12);
  --status-warn: #d97706;
  --status-warn-bg: rgba(217, 119, 6, 0.12);
  --status-review: #2563eb;
  --status-review-bg: rgba(37, 99, 235, 0.12);

  --border-subtle: rgba(0,0,0,0.06);
  --border-default: rgba(0,0,0,0.1);
  --border-focus: rgba(79, 70, 229, 0.4);

  --orb-primary: rgba(99, 102, 241, 0.15);
  --orb-secondary: rgba(139, 92, 246, 0.1);

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.06), 0 1px 3px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.04), 0 10px 20px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.06), 0 20px 48px rgba(0,0,0,0.08);
  --shadow-glow: 0 0 60px rgba(99, 102, 241, 0.06);
}

[data-theme="dark"] {
  --bg-body: #09090b;
  --bg-surface: #18181b;
  --bg-elevated: #27272a;
  --bg-card: #27272a;
  --bg-hover: #3f3f46;

  --text-primary: #fafafa;
  --text-secondary: #a1a1aa;
  --text-tertiary: #71717a;
  --text-muted: #52525b;

  --accent-primary: #6366f1;
  --accent-secondary: #8b5cf6;

  --accent-primary-15: rgba(99, 102, 241, 0.15);
  --accent-primary-25: rgba(99, 102, 241, 0.25);

  --border-subtle: rgba(255,255,255,0.06);
  --border-default: rgba(255,255,255,0.1);
  --border-focus: rgba(99, 102, 241, 0.5);

  --orb-primary: rgba(99, 102, 241, 0.35);
  --orb-secondary: rgba(139, 92, 246, 0.25);

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04), 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.04), 0 10px 20px rgba(0,0,0,0.08);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.08), 0 20px 48px rgba(0,0,0,0.12);
  --shadow-glow: 0 0 60px rgba(99, 102, 241, 0.08);
}

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

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', Helvetica, Roboto, sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100dvh;
  overflow-x: hidden;
  transition: background var(--duration-base) var(--ease-smooth);
}

/* ========================================
   App Container
   ======================================== */

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-5) var(--space-8);
  position: relative;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  isolation: isolate;
}

/* ---- Background Orbs (GPU optimized, no clip) ---- */
.orb-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: visible;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  will-change: transform;
  transform: translateZ(0);
  backface-visibility: hidden;
}

.orb-a {
  width: 500px;
  height: 500px;
  background: var(--orb-primary);
  top: -120px;
  right: -150px;
  animation: orbFloatA 25s ease-in-out infinite;
}

.orb-b {
  width: 400px;
  height: 400px;
  background: var(--orb-secondary);
  bottom: 5%;
  left: -120px;
  animation: orbFloatB 20s ease-in-out infinite;
  animation-delay: -8s;
}

@keyframes orbFloatA {
  0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
  33% { transform: translate3d(30px, -20px, 0) scale(1.05); }
  66% { transform: translate3d(-20px, 15px, 0) scale(0.97); }
}

@keyframes orbFloatB {
  0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
  50% { transform: translate3d(-25px, -30px, 0) scale(1.03); }
}

/* ========================================
   Header
   ======================================== */

.app-header {
  position: relative;
  z-index: 1;
  margin-bottom: var(--space-6);
  animation: fadeSlideDown var(--duration-slow) var(--ease-smooth) both;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-5);
}

.header-controls {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.brand-icon {
  width: 32px;
  height: 32px;
  color: var(--accent-primary);
}

.brand-name {
  font-weight: 700;
  font-size: var(--text-base);
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.live-badge {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  background: var(--accent-primary-15);
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--status-active);
  animation: livePulse 2s ease-in-out infinite;
}

@keyframes livePulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

.live-text {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--status-active);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.app-header h1 {
  font-size: var(--text-2xl);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
  margin-bottom: var(--space-2);
  background: linear-gradient(135deg, var(--text-primary) 0%, var(--accent-primary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  font-weight: 400;
  letter-spacing: 0.01em;
}

/* ---- Chat Link Button ---- */
.chat-link-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-5);
  padding: var(--space-4) var(--space-6);
  background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
  border: none;
  border-radius: var(--radius-full);
  color: #fff;
  text-decoration: none;
  font-size: var(--text-base);
  font-weight: 600;
  transition: all var(--duration-base) var(--ease-smooth);
  box-shadow: var(--shadow-md);
}

.chat-link-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.chat-link-btn:active {
  transform: translateY(0) scale(0.97);
}

.chat-link-btn svg {
  width: 18px;
  height: 18px;
}

/* ========================================
   Affirmation
   ======================================== */

.affirmation-bar {
  position: relative;
  z-index: 1;
  margin-bottom: var(--space-5);
  padding: var(--space-4) var(--space-5);
  background: linear-gradient(135deg, var(--accent-primary-15) 0%, rgba(139, 92, 246, 0.1) 100%);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  font-style: italic;
  font-weight: 400;
  color: var(--text-secondary);
  text-align: center;
  letter-spacing: 0.01em;
  line-height: 1.5;
  animation: fadeSlideDown var(--duration-slow) 0.05s var(--ease-smooth) both;
}

/* ========================================
   Freedom Timer
   ======================================== */

.freedom-timer {
  position: relative;
  z-index: 1;
  margin-bottom: var(--space-6);
  padding: var(--space-5);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  animation: fadeSlideUp var(--duration-slow) 0.08s var(--ease-smooth) both;
}

.timer-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.timer-label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
}

.timer-date {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  font-weight: 500;
  margin-left: auto;
}

.timer-track {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.timer-bar-bg {
  flex: 1;
  height: 4px;
  background: var(--bg-hover);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.timer-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
  border-radius: var(--radius-full);
  transition: width 0.6s var(--ease-smooth);
  min-width: 4px;
}

.timer-days {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--accent-primary);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ========================================
   Category Tabs
   ======================================== */

.category-tabs {
  position: relative;
  z-index: 1;
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  padding-bottom: var(--space-1);
  margin-bottom: var(--space-5);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  animation: fadeSlideDown var(--duration-slow) 0.1s var(--ease-smooth) both;
}

.category-tabs::-webkit-scrollbar { display: none; }

.tab-pill {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  border-radius: var(--radius-full);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-smooth);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.tab-pill svg {
  width: 16px;
  height: 16px;
  opacity: 0.6;
  transition: opacity var(--duration-fast) var(--ease-smooth);
}

.tab-pill:hover {
  border-color: var(--border-default);
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.tab-pill:hover svg { opacity: 1; }

.tab-pill.active {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #fff;
  box-shadow: var(--shadow-md);
}

.tab-pill.active svg { opacity: 1; color: #fff; }

/* ========================================
   Stats Row
   ======================================== */

.stats-row {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-3);
  margin-bottom: var(--space-5);
  animation: fadeSlideUp var(--duration-slow) 0.12s var(--ease-smooth) both;
}

.stat-item {
  padding: var(--space-4) var(--space-3);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  text-align: center;
  transition: all var(--duration-base) var(--ease-smooth);
  contain: layout style paint;
}

.stat-item:hover {
  transform: translateY(-2px);
  border-color: var(--border-default);
  box-shadow: var(--shadow-md);
}

.stat-icon {
  display: flex;
  justify-content: center;
  margin-bottom: var(--space-2);
  color: var(--text-tertiary);
}

.stat-item.total .stat-icon { color: var(--accent-primary); }
.stat-item.resolved .stat-icon { color: var(--status-active); }
.stat-item.dispute .stat-icon { color: var(--status-warn); }

.stat-value {
  font-size: var(--text-xl);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1;
  margin-bottom: var(--space-1);
  font-variant-numeric: tabular-nums;
}

.stat-item.total .stat-value { color: var(--accent-primary); }
.stat-item.resolved .stat-value { color: var(--status-active); }
.stat-item.dispute .stat-value { color: var(--status-warn); }

.stat-label {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ========================================
   Filter Bar
   ======================================== */

.filter-bar {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-4);
  animation: fadeSlideUp var(--duration-slow) 0.14s var(--ease-smooth) both;
}

.filter-select {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: border-color var(--duration-fast) var(--ease-smooth);
}

.filter-select:focus-within { border-color: var(--border-focus); }

.filter-select svg {
  width: 14px;
  height: 14px;
  color: var(--text-tertiary);
}

.filter-select select {
  background: transparent;
  border: none;
  outline: none;
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

.filter-select select option {
  background: var(--bg-surface);
  color: var(--text-primary);
}

.last-update {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  font-weight: 400;
}

/* ========================================
   Cards Container
   ======================================== */

.cards-container {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-height: 200px;
}

/* ========================================
   Agreement Card
   ======================================== */

.agreement-card {
  padding: var(--space-5);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  transition: all var(--duration-base) var(--ease-smooth);
  animation: cardEnter var(--duration-slow) var(--ease-smooth) both;
  position: relative;
  overflow: hidden;
  contain: layout style paint;
}

.agreement-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 3px;
  height: 100%;
  border-radius: 0 2px 2px 0;
  transition: width var(--duration-base) var(--ease-smooth);
}

.agreement-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-default);
}

.agreement-card:hover::before { width: 4px; }

.agreement-card.status-resolved::before { background: var(--status-active); }
.agreement-card.status-dispute::before { background: var(--status-warn); }
.agreement-card.status-review::before { background: var(--status-review); }

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-3);
}

.category-badge {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--accent-primary-15);
  color: var(--accent-primary);
}

.status-badge {
  font-size: var(--text-xs);
  font-weight: 600;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
}

.status-badge.resolved { background: var(--status-active-bg); color: var(--status-active); }
.status-badge.dispute { background: var(--status-warn-bg); color: var(--status-warn); }
.status-badge.review { background: var(--status-review-bg); color: var(--status-review); }

.card-description {
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--text-primary);
  margin-bottom: var(--space-3);
  font-weight: 400;
}

.card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-date {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  font-weight: 400;
}

.card-id {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-family: 'SF Mono', SFMono-Regular, ui-monospace, monospace;
  letter-spacing: 0.02em;
}

/* Stagger animation */
.agreement-card:nth-child(1) { animation-delay: 0.02s; }
.agreement-card:nth-child(2) { animation-delay: 0.04s; }
.agreement-card:nth-child(3) { animation-delay: 0.06s; }
.agreement-card:nth-child(4) { animation-delay: 0.08s; }
.agreement-card:nth-child(5) { animation-delay: 0.1s; }
.agreement-card:nth-child(6) { animation-delay: 0.12s; }

/* ========================================
   Status Rule Card
   ======================================== */

.status-rule-card {
  padding: var(--space-5);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  transition: all var(--duration-base) var(--ease-smooth);
  animation: cardEnter var(--duration-slow) var(--ease-smooth) both;
  position: relative;
  overflow: hidden;
  margin-bottom: var(--space-3);
  contain: layout style paint;
}

.status-rule-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 3px;
  height: 100%;
  border-radius: 0 2px 2px 0;
  transition: width var(--duration-base) var(--ease-smooth);
}

.status-rule-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-default);
}

.status-rule-card.status-active::before { background: var(--status-active); }
.status-rule-card.status-violated::before { background: var(--status-warn); }

.status-rule-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-3);
}

.status-rule-badge {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
}

.status-rule-badge.active { background: var(--status-active-bg); color: var(--status-active); }
.status-rule-badge.violated { background: var(--status-warn-bg); color: var(--status-warn); }

.status-rule-owner {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  font-weight: 400;
}

.status-rule-description {
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

.status-rule-meta {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

/* ========================================
   Empty State
   ======================================== */

.empty-state {
  text-align: center;
  padding: var(--space-12) var(--space-5);
  color: var(--text-tertiary);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin: 0 auto var(--space-4);
  color: var(--text-muted);
  opacity: 0.5;
}

.empty-state h3 {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

.empty-state p {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
}

/* ========================================
   Loading State
   ======================================== */

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding: var(--space-12) var(--space-5);
  color: var(--text-tertiary);
}

.spinner {
  width: 28px;
  height: 28px;
  border: 2.5px solid var(--border-subtle);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  will-change: transform;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ========================================
   Footer
   ======================================== */

.app-footer {
  position: relative;
  z-index: 1;
  text-align: center;
  padding-top: var(--space-8);
  margin-top: auto;
}

.footer-line {
  width: 32px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent-primary), transparent);
  margin: 0 auto var(--space-4);
  border-radius: 1px;
  opacity: 0.3;
}

.app-footer p {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-weight: 400;
  letter-spacing: 0.02em;
}

/* ========================================
   Theme Toggle (2-state)
   ======================================== */

.theme-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: var(--space-1);
}

.theme-toggle-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-smooth);
}

.theme-toggle-btn.active {
  background: var(--accent-primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

/* ========================================
   Onboarding
   ======================================== */

.onboarding-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-slow) var(--ease-smooth);
}

.onboarding-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.onboarding-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  padding: var(--space-8) var(--space-6);
  max-width: 400px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px) scale(0.95);
  transition: transform var(--duration-slow) var(--ease-spring);
}

.onboarding-overlay.active .onboarding-card {
  transform: translateY(0) scale(1);
}

.onboarding-card h2 {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-3);
  letter-spacing: -0.02em;
}

.onboarding-card p {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: var(--space-6);
}

.onboarding-steps {
  display: flex;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
  justify-content: center;
}

.step-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--bg-hover);
  transition: all var(--duration-base) var(--ease-smooth);
}

.step-dot.active { background: var(--accent-primary); transform: scale(1.2); }

.onboarding-buttons {
  display: flex;
  gap: var(--space-3);
  justify-content: center;
}

.onboarding-btn {
  padding: var(--space-3) var(--space-6);
  border-radius: var(--radius-full);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-smooth);
  -webkit-tap-highlight-color: transparent;
}

.onboarding-btn.primary {
  background: var(--accent-primary);
  color: #fff;
  border: none;
}

.onboarding-btn.primary:hover {
  background: var(--accent-secondary);
  transform: translateY(-1px);
}

.onboarding-btn.secondary {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-default);
}

.onboarding-btn.secondary:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ========================================
   Animations
   ======================================== */

@keyframes fadeSlideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes cardEnter {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ========================================
   Scrollbar & Selection
   ======================================== */

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-default); border-radius: 2px; }

::selection {
  background: var(--accent-primary-15);
  color: var(--accent-primary);
}

/* Safe area */
@supports (padding-top: env(safe-area-inset-top)) {
  .app {
    padding-top: max(var(--space-6), env(safe-area-inset-top));
    padding-bottom: max(var(--space-8), env(safe-area-inset-bottom));
  }
}

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