/*
 * FieldLgx Design System — Terraform Pro Aesthetic
 * #9dd850 lime on deep black, Manrope headlines, Inter body
 * Ghost borders, atmosphere shadows, gradient nav
 */

:root {
  color-scheme: dark;

  /* Surface hierarchy */
  --bg: #131313;
  --bg-elevated: #1c1b1b;
  --bg-surface: #201f1f;
  --bg-surface-hover: #2a2a2a;

  --surface-lowest: #0e0e0e;
  --surface-low: #131313;
  --surface-container: #201f1f;
  --surface-high: #2a2a2a;
  --surface-highest: #353534;
  --surface-bright: #3a3939;
  --surface-variant: #353534;
  --surface: var(--surface-container);
  --surface-alt: var(--surface-low);

  /* Ghost borders */
  --border: rgba(66, 72, 68, 0.2);
  --border-hover: rgba(66, 72, 68, 0.4);
  --border-focus: #9dd850;

  /* Text */
  --text: #e5e2e1;
  --text-secondary: #c2c8c2;
  --text-muted: #8c928d;
  --text-disabled: #424844;

  /* Primary — Terraform lime */
  --primary: #9dd850;
  --primary-hover: #b7f569;
  --primary-light: rgba(157, 216, 80, 0.08);
  --primary-glow: rgba(157, 216, 80, 0.1);
  --primary-container: #132400;
  --on-primary: #111;

  --accent: #b7f569;
  --accent-subtle: rgba(183, 245, 105, 0.06);

  --secondary: #c8c6c5;
  --secondary-container: #474746;
  --tertiary: #e2c19b;
  --tertiary-container: #2e1c03;

  /* Glass */
  --glass: rgba(19, 19, 19, 0.7);
  --glass-strong: rgba(19, 19, 19, 0.85);
  --glass-border: rgba(66, 72, 68, 0.2);

  /* Spacing */
  --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;
  --space-16: 64px;
  --space-20: 80px;
  --space-24: 96px;
  --space-32: 128px;

  /* Typography — Inter body, Manrope headlines */
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-headline: 'Manrope', sans-serif;
  --font-mono: 'Inter', monospace;

  --text-xs: 10px;
  --text-sm: 13px;
  --text-base: 14px;
  --text-lg: 16px;
  --text-xl: 20px;
  --text-2xl: 24px;
  --text-3xl: 34px;

  --type-label-size: var(--text-xs);
  --type-caption-size: var(--text-sm);
  --type-body-size: var(--text-base);
  --type-control-size: var(--text-lg);
  --type-title-size: var(--text-xl);
  --type-metric-size: var(--text-3xl);
  --type-label-weight: 900;
  --type-body-weight: 500;
  --type-strong-weight: 800;
  --type-display-weight: 900;
  --type-label-spacing: 0.12em;

  --h1: clamp(28px, 4vw, 40px);
  --h2: clamp(22px, 3vw, 28px);
  --h3: clamp(16px, 2vw, 20px);
  --h4: clamp(14px, 1.8vw, 16px);
  --h5: clamp(13px, 1.5vw, 14px);

  --line-height-tight: 0.95;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.6;

  --letter-spacing-tight: 0;
  --letter-spacing-normal: 0;

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

  /* Atmosphere shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 24px 48px rgba(0, 0, 0, 0.4);
  --shadow-xl: 0 48px 96px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px rgba(157, 216, 80, 0.1);

  /* Motion */
  --motion-fast: 150ms;
  --motion-base: 200ms;
  --motion-slow: 300ms;
  --motion-ease: cubic-bezier(0.4, 0, 0.2, 1);
  --motion-ease-out: cubic-bezier(0.16, 1, 0.3, 1);

  /* Gradient */
  --gradient-primary: linear-gradient(135deg, #9dd850, #132400);
  --gradient-bg: var(--bg);
  --gradient-surface: var(--surface-container);

  /* Z-index */
  --z-base: 1;
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-modal: 300;
  --z-toast: 400;
}

/* Light Theme */
[data-theme="light"] {
  color-scheme: light;

  --bg: #f6f8f2;
  --bg-elevated: #ffffff;
  --bg-surface: #fdfef9;
  --bg-surface-hover: #eff3e8;

  --surface-lowest: #ffffff;
  --surface-low: #f6f8f2;
  --surface-container: #ffffff;
  --surface-high: #eff3e8;
  --surface-highest: #e2ead9;
  --surface-bright: #ffffff;
  --surface-variant: #e8efe0;
  --surface: var(--surface-container);
  --surface-alt: var(--surface-low);

  --border: rgba(23, 33, 22, 0.13);
  --border-hover: rgba(23, 33, 22, 0.26);
  --border-focus: #80b936;

  --text: #11180f;
  --text-secondary: #44503f;
  --text-muted: #6a7464;
  --text-disabled: #a8b0a2;

  --primary: #9dd850;
  --primary-hover: #7fb936;
  --primary-light: rgba(126, 185, 54, 0.12);
  --primary-glow: rgba(126, 185, 54, 0.18);
  --primary-container: #e8f7d6;
  --on-primary: #081006;

  --accent: #648f2a;
  --accent-subtle: rgba(126, 185, 54, 0.09);

  --secondary: #53604d;
  --secondary-container: #eef3e7;
  --tertiary: #8a6430;
  --tertiary-container: #fbefd9;

  --glass: rgba(255, 255, 255, 0.78);
  --glass-strong: rgba(255, 255, 255, 0.92);
  --glass-border: rgba(23, 33, 22, 0.14);

  --shadow-sm: 0 1px 3px rgba(24, 34, 22, 0.08);
  --shadow-md: 0 8px 20px rgba(24, 34, 22, 0.10);
  --shadow-lg: 0 18px 42px rgba(24, 34, 22, 0.13);
  --shadow-xl: 0 32px 74px rgba(24, 34, 22, 0.16);
  --shadow-glow: 0 0 26px rgba(126, 185, 54, 0.16);

  --gradient-primary: linear-gradient(135deg, #b9f56d, #9dd850);
  --gradient-bg: linear-gradient(180deg, #fbfcf7, #f2f5ec);
  --gradient-surface: linear-gradient(145deg, rgba(255, 255, 255, 0.98), rgba(244, 248, 237, 0.92));
}

/* System preference: auto-apply light when user prefers it and no explicit theme set */
@media (prefers-color-scheme: light) {
  [data-theme="system"] {
    color-scheme: light;

    --bg: #f6f8f2;
    --bg-elevated: #ffffff;
    --bg-surface: #fdfef9;
    --bg-surface-hover: #eff3e8;

    --surface-lowest: #ffffff;
    --surface-low: #f6f8f2;
    --surface-container: #ffffff;
    --surface-high: #eff3e8;
    --surface-highest: #e2ead9;
    --surface-bright: #ffffff;
    --surface-variant: #e8efe0;
    --surface: var(--surface-container);
    --surface-alt: var(--surface-low);

    --border: rgba(23, 33, 22, 0.13);
    --border-hover: rgba(23, 33, 22, 0.26);
    --border-focus: #80b936;

    --text: #11180f;
    --text-secondary: #44503f;
    --text-muted: #6a7464;
    --text-disabled: #a8b0a2;

    --primary: #9dd850;
    --primary-hover: #7fb936;
    --primary-light: rgba(126, 185, 54, 0.12);
    --primary-glow: rgba(126, 185, 54, 0.18);
    --primary-container: #e8f7d6;
    --on-primary: #081006;

    --accent: #648f2a;
    --accent-subtle: rgba(126, 185, 54, 0.09);

    --secondary: #53604d;
    --secondary-container: #eef3e7;
    --tertiary: #8a6430;
    --tertiary-container: #fbefd9;

    --glass: rgba(255, 255, 255, 0.78);
    --glass-strong: rgba(255, 255, 255, 0.92);
    --glass-border: rgba(23, 33, 22, 0.14);

    --shadow-sm: 0 1px 3px rgba(24, 34, 22, 0.08);
    --shadow-md: 0 8px 20px rgba(24, 34, 22, 0.10);
    --shadow-lg: 0 18px 42px rgba(24, 34, 22, 0.13);
    --shadow-xl: 0 32px 74px rgba(24, 34, 22, 0.16);
    --shadow-glow: 0 0 26px rgba(126, 185, 54, 0.16);

    --gradient-primary: linear-gradient(135deg, #b9f56d, #9dd850);
    --gradient-bg: linear-gradient(180deg, #fbfcf7, #f2f5ec);
    --gradient-surface: linear-gradient(145deg, rgba(255, 255, 255, 0.98), rgba(244, 248, 237, 0.92));
  }
}

/* Base Styles */
* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

body {
  margin: 0;
  font-family: var(--font-family);
  font-size: var(--text-base);
  line-height: var(--line-height-normal);
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  letter-spacing: var(--letter-spacing-normal);
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  margin: 0;
  font-weight: 700;
  line-height: var(--line-height-tight);
  letter-spacing: var(--letter-spacing-tight);
  color: var(--text);
}

h1 { font-size: var(--h1); }
h2 { font-size: var(--h2); }
h3 { font-size: var(--h3); }
h4 { font-size: var(--h4); }
h5 { font-size: var(--h5); }

p {
  margin: 0;
  line-height: var(--line-height-relaxed);
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--motion-base) var(--motion-ease);
}

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

/* Buttons — gradient primary, ghost-border secondary */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  font-family: var(--font-family);
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.3;
  border-radius: 1rem;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  user-select: none;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0) scale(0.97);
  transition-duration: 0.05s;
}

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

.btn-primary {
  background: var(--primary);
  color: var(--on-primary);
  border-color: transparent;
  box-shadow: 0 2px 8px rgba(157, 216, 80, 0.15), 0 0 0 0 rgba(157, 216, 80, 0);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
}

.btn-primary:hover {
  background: #a8e05a;
  box-shadow: 0 4px 16px rgba(157, 216, 80, 0.3), 0 0 0 0 rgba(157, 216, 80, 0);
  color: var(--on-primary);
  transform: translateY(-2px);
}

.btn-primary:active {
  background: #8cc644;
  box-shadow: 0 1px 4px rgba(157, 216, 80, 0.2);
  transform: translateY(0) scale(0.97);
}

.btn-secondary {
  background: var(--surface-container);
  color: var(--text);
  border-color: var(--border);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.btn-secondary:hover {
  background: var(--surface-high);
  border-color: var(--border-hover);
  color: var(--text);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.15);
  transform: translateY(-1px);
}

.btn-secondary:active {
  background: var(--surface-highest);
  box-shadow: 0 0 0 rgba(0, 0, 0, 0);
  transform: translateY(0) scale(0.97);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}

.btn-ghost:hover {
  background: var(--bg-surface);
  color: var(--text);
}

.btn-ghost:active {
  background: var(--surface-high);
}

.btn-sm {
  padding: 5px 10px;
  font-size: var(--text-xs);
}

/* Cards — Terraform surface container with ghost border */
.card {
  background: var(--surface-container);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}

.card:hover {
  background: var(--surface-high);
}

/* Tab navigation pills — used across Jobs, Estimates, Financials, etc. */
.billing-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
  scrollbar-width: none;
}
.billing-tabs::-webkit-scrollbar { display: none; }
.billing-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  font-size: var(--type-body-size);
  font-weight: var(--type-strong-weight);
  border-radius: 1rem;
  text-decoration: none;
  color: var(--text-muted);
  background: var(--surface-container);
  border: 1px solid var(--border);
  transition: all 0.15s ease;
  white-space: nowrap;
  cursor: pointer;
}
.billing-tab:hover {
  color: var(--text);
  border-color: var(--border-hover);
  transform: translateY(-1px);
}
.billing-tab.active {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(157, 216, 80, 0.08);
  font-weight: 700;
}
@media (max-width: 768px) {
  .billing-tab { min-height: 44px; padding: 10px 16px; font-size: var(--text-sm); }
}

/* Containers */
.shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--space-6);
}

@media (max-width: 768px) {
  .shell {
    padding: 0 var(--space-4);
  }
}

/* Section spacing */
.section {
  padding: var(--space-32) 0;
}

@media (max-width: 768px) {
  .section {
    padding: var(--space-16) 0;
  }
}

/* Grid system */
.grid {
  display: grid;
  gap: var(--space-6);
}

.grid-2 {
  grid-template-columns: repeat(2, 1fr);
}

.grid-3 {
  grid-template-columns: repeat(3, 1fr);
}

.grid-4 {
  grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 1024px) {
  .grid-3, .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr;
  }
}

/* Utility classes */
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }

.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }

.mb-1 { margin-bottom: var(--space-1); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.mb-8 { margin-bottom: var(--space-8); }

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-in {
  animation: fadeIn var(--motion-slow) var(--motion-ease-out);
}

/* Focus & Accessibility */
*:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: 420px;
}

@media (max-width: 768px) {
  .toast-container {
    top: auto;
    bottom: calc(96px + env(safe-area-inset-bottom, 0px));
    right: 16px;
    left: 16px;
    max-width: none;
  }
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  color: var(--text);
  pointer-events: auto;
  cursor: pointer;
  animation: toastIn var(--motion-slow) var(--motion-ease-out) forwards;
  backdrop-filter: blur(12px);
}

.toast.toast-removing {
  animation: toastOut var(--motion-base) var(--motion-ease) forwards;
}

.toast-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
}

.toast-success { border-color: rgba(34, 197, 94, 0.4); }
.toast-success .toast-icon { color: #86efac; }
.toast-error { border-color: rgba(239, 68, 68, 0.4); }
.toast-error .toast-icon { color: #fca5a5; }
.toast-warning { border-color: rgba(234, 179, 8, 0.4); }
.toast-warning .toast-icon { color: #fde047; }
.toast-info { border-color: rgba(34, 197, 94, 0.4); }
.toast-info .toast-icon { color: #6ee7b7; }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(24px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(24px); }
}

/* Loading Skeletons */
.skeleton {
  background: linear-gradient(90deg, var(--bg-surface) 25%, var(--bg-surface-hover) 50%, var(--bg-surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

.skeleton-text {
  height: 16px;
  margin-bottom: 8px;
  width: 80%;
}

.skeleton-heading {
  height: 28px;
  width: 50%;
  margin-bottom: 16px;
}

.skeleton-card {
  height: 120px;
  border-radius: var(--radius-lg);
}

.skeleton-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Empty States */
.empty-state {
  text-align: center;
  padding: var(--space-16) var(--space-6);
  max-width: 400px;
  margin: 0 auto;
}

.empty-state-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto var(--space-4);
  color: var(--text-muted);
  opacity: 0.4;
}

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

.empty-state-desc {
  color: var(--text-muted);
  font-size: var(--text-sm);
  line-height: var(--line-height-relaxed);
  margin-bottom: var(--space-6);
}

/* Status Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: var(--type-caption-size);
  font-weight: var(--type-strong-weight);
  line-height: 1.4;
  white-space: nowrap;
}

.badge-success {
  background: rgba(34, 197, 94, 0.15);
  color: #86efac;
}

.badge-warning {
  background: rgba(234, 179, 8, 0.15);
  color: #fde047;
}

.badge-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
}

.badge-info {
  background: rgba(34, 197, 94, 0.15);
  color: #6ee7b7;
}

.badge-neutral {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
}

/* Status badges — used across invoice, estimate, agreement, and job status */
.status-active, .status-paid, .status-completed { color: #86efac; }
.status-draft, .status-scheduled { color: var(--text-muted); }
.status-sent, .status-in-progress { color: #93c5fd; }
.status-overdue, .status-expired { color: #fca5a5; }
.status-void, .status-cancelled, .status-skipped { color: var(--text-disabled); text-decoration: line-through; }

/* Empty state pattern */
.empty-state {
  text-align: center;
  padding: var(--space-12) var(--space-6);
  color: var(--text-muted);
}
.empty-state svg { margin-bottom: var(--space-4); opacity: 0.4; }
.empty-state p { font-size: var(--text-base); margin-bottom: var(--space-3); }
.empty-state a { color: var(--primary); font-weight: 500; }

/* Row entrance animation — apply to data table bodies */
@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.data-table tbody tr {
  animation: fadeSlideUp var(--motion-slow) var(--motion-ease-out) both;
}
.data-table tbody tr:nth-child(1) { animation-delay: 0ms; }
.data-table tbody tr:nth-child(2) { animation-delay: 30ms; }
.data-table tbody tr:nth-child(3) { animation-delay: 60ms; }
.data-table tbody tr:nth-child(4) { animation-delay: 90ms; }
.data-table tbody tr:nth-child(5) { animation-delay: 120ms; }
.data-table tbody tr:nth-child(n+6) { animation-delay: 150ms; }

/* ──────────────────────────────────────────
   FORM CONTROLS — Consistent, animated
   ────────────────────────────────────────── */
.form-control {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-family);
  font-size: var(--text-sm);
  line-height: var(--line-height-normal);
  transition: border-color var(--motion-base) var(--motion-ease),
              box-shadow var(--motion-base) var(--motion-ease),
              background var(--motion-base) var(--motion-ease);
  outline: none;
}

.form-control::placeholder {
  color: var(--text-muted);
  transition: color var(--motion-base) var(--motion-ease);
}

.form-control:hover {
  border-color: var(--border-hover);
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15), var(--shadow-sm);
  background: var(--bg-surface);
}

.form-control:focus::placeholder {
  color: var(--text-disabled);
}

.form-control.is-error {
  border-color: #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.12);
}

.form-control.is-success {
  border-color: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.12);
}

.form-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
  transition: color var(--motion-base) var(--motion-ease);
}

.form-group {
  margin-bottom: var(--space-5);
}

.form-group:focus-within .form-label {
  color: var(--primary);
}

.form-help {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--space-1);
}

/* Labels inside form groups inherit design system styling */
.form-group > label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

.form-group:focus-within > label {
  color: var(--primary);
}

/* Safety net: bare inputs/selects/textareas inside forms inherit .form-control styles */
.form-group input:not([type="checkbox"]):not([type="radio"]):not(.form-control),
.form-group select:not(.form-control),
.form-group textarea:not(.form-control) {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-family);
  font-size: var(--text-sm);
  line-height: var(--line-height-normal);
  transition: border-color var(--motion-base) var(--motion-ease),
              box-shadow var(--motion-base) var(--motion-ease);
  outline: none;
}

.form-group input:not([type="checkbox"]):not([type="radio"]):not(.form-control):focus,
.form-group select:not(.form-control):focus,
.form-group textarea:not(.form-control):focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15), var(--shadow-sm);
  background: var(--bg-surface);
}

.form-error {
  font-size: var(--text-xs);
  color: #fca5a5;
  margin-top: var(--space-1);
  animation: shakeX 0.4s var(--motion-ease);
}

@keyframes shakeX {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}

/* ──────────────────────────────────────────
   LOADING STATES — Spinners, button loading
   ────────────────────────────────────────── */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: var(--radius-full);
  animation: spin 0.6s linear infinite;
}

.spinner-sm {
  width: 14px;
  height: 14px;
  border-width: 1.5px;
}

.spinner-lg {
  width: 32px;
  height: 32px;
  border-width: 3px;
}

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

.btn.is-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
  transform: none !important;
}

.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: var(--radius-full);
  animation: spin 0.6s linear infinite;
}

/* Ripple effect on click */
.btn-ripple {
  overflow: hidden;
}
.btn-ripple::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at var(--ripple-x, 50%) var(--ripple-y, 50%), rgba(255,255,255,0.2) 0%, transparent 60%);
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}
.btn-ripple:active::before {
  opacity: 1;
  transition-duration: 0.05s;
}

/* ──────────────────────────────────────────
   STAGGERED ANIMATIONS — Lists, grids
   ────────────────────────────────────────── */
@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-12px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.animate-in {
  animation: slideUp var(--motion-slow) var(--motion-ease-out) both;
}

.stagger-list > * {
  animation: slideUp var(--motion-slow) var(--motion-ease-out) both;
}

.stagger-list > *:nth-child(1) { animation-delay: 0ms; }
.stagger-list > *:nth-child(2) { animation-delay: 50ms; }
.stagger-list > *:nth-child(3) { animation-delay: 100ms; }
.stagger-list > *:nth-child(4) { animation-delay: 150ms; }
.stagger-list > *:nth-child(5) { animation-delay: 200ms; }
.stagger-list > *:nth-child(6) { animation-delay: 250ms; }
.stagger-list > *:nth-child(7) { animation-delay: 300ms; }
.stagger-list > *:nth-child(8) { animation-delay: 350ms; }
.stagger-list > *:nth-child(n+9) { animation-delay: 400ms; }

/* ──────────────────────────────────────────
   DROPDOWN & POPOVER ANIMATIONS
   ────────────────────────────────────────── */
@keyframes dropdownIn {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

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

.dropdown-animated {
  animation: dropdownIn var(--motion-base) var(--motion-ease-out);
  transform-origin: top center;
}

.popover-animated {
  animation: popoverIn var(--motion-base) var(--motion-ease-out);
  transform-origin: bottom center;
}

/* ──────────────────────────────────────────
   TABLE ENHANCEMENTS
   ────────────────────────────────────────── */
.data-table tbody tr {
  transition: background var(--motion-fast) var(--motion-ease),
              transform var(--motion-fast) var(--motion-ease);
}

.data-table tbody tr:hover {
  background: rgba(34, 197, 94, 0.06);
}

.data-table tbody tr:active {
  background: rgba(34, 197, 94, 0.1);
}

.data-table a {
  transition: color var(--motion-fast) var(--motion-ease);
}

/* ──────────────────────────────────────────
   LINK UNDERLINE ANIMATION
   ────────────────────────────────────────── */
.link-animated {
  position: relative;
  text-decoration: none;
}

.link-animated::after {
  content: "";
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 0;
  height: 1px;
  background: currentColor;
  transition: width var(--motion-base) var(--motion-ease);
}

.link-animated:hover::after {
  width: 100%;
}

/* ──────────────────────────────────────────
   GRADIENT BORDER — Featured/highlighted
   ────────────────────────────────────────── */
.gradient-border {
  position: relative;
  border: none !important;
  background: var(--bg-surface);
  isolation: isolate;
}

.gradient-border::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: var(--gradient-primary);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

/* ──────────────────────────────────────────
   TOOLTIP
   ────────────────────────────────────────── */
.tooltip {
  position: relative;
}

.tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  padding: 4px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--motion-fast) var(--motion-ease),
              transform var(--motion-fast) var(--motion-ease);
  z-index: var(--z-dropdown);
}

.tooltip:hover::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ──────────────────────────────────────────
   SCROLLBAR — Minimal, dark themed
   ────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-hover);
}

/* ──────────────────────────────────────────
   COUNTER ANIMATION — Animated numbers
   ────────────────────────────────────────── */
@keyframes countUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.counter-animate {
  animation: countUp 0.6s var(--motion-ease-out) both;
}

/* ──────────────────────────────────────────
   GLOW EFFECT — Subtle hover glow
   ────────────────────────────────────────── */
.glow-hover {
  transition: box-shadow var(--motion-base) var(--motion-ease);
}

.glow-hover:hover {
  box-shadow: var(--shadow-md), 0 0 20px rgba(34, 197, 94, 0.15);
}

/* ──────────────────────────────────────────
   DIVIDER
   ────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--border);
  margin: var(--space-6) 0;
  border: none;
}

/* ──────────────────────────────────────────
   BREADCRUMB
   ────────────────────────────────────────── */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-bottom: var(--space-4);
}

.breadcrumb a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--motion-fast) var(--motion-ease);
}

.breadcrumb a:hover {
  color: var(--text);
}

.breadcrumb-sep {
  color: var(--text-disabled);
  font-size: var(--text-xs);
}

/* ──────────────────────────────────────────
   ADDITIONAL UTILITIES
   ────────────────────────────────────────── */
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }

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

.w-full { width: 100%; }
.min-w-0 { min-width: 0; }

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.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;
}

/* ──────────────────────────────────────────
   MOBILE OPTIMIZATION
   ────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Responsive tables: horizontal scroll with snap */
  .data-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
  }
  .data-table thead,
  .data-table tbody,
  .data-table tr { display: revert; }
  .data-table th,
  .data-table td {
    padding: 10px 8px;
    font-size: var(--text-sm);
  }
  /* Hide columns with .hide-mobile class */
  .hide-mobile { display: none !important; }

  /* Bigger touch targets on buttons */
  .btn { min-height: 44px; padding: 10px 16px; }
  .btn-sm { min-height: 36px; padding: 8px 12px; }

  /* Cards: less padding on mobile */
  .card { padding: var(--space-4); }

  /* Page headers: tighter spacing */
  .page-header { margin-bottom: 16px; }
  .page-header h1 { font-size: var(--text-2xl); }

  /* Forms: ensure 16px to prevent iOS zoom */
  .form-control { font-size: var(--type-control-size); padding: 12px 14px; min-height: 44px; }
  select.form-control { min-height: 44px; }

  /* Same sizing for bare inputs inside form groups (safety net) */
  .form-group input:not([type="checkbox"]):not([type="radio"]):not(.form-control),
  .form-group select:not(.form-control),
  .form-group textarea:not(.form-control) {
    font-size: var(--type-control-size);
    padding: 12px 14px;
    min-height: 44px;
  }

  /* Empty states: less vertical padding */
  .empty-state { padding: var(--space-8) var(--space-4); }
  .empty-state-icon { width: 44px; height: 44px; }

  /* Stack action buttons */
  .quick-actions { flex-direction: column; }
  .quick-actions .btn { width: 100%; justify-content: center; }
}

/* ──────────────────────────────────────────
   TABLET OPTIMIZATION (iPad / 769-1024px)
   ────────────────────────────────────────── */
@media (min-width: 769px) and (max-width: 1024px) {
  /* Two-column grid layouts instead of 3 */
  .grid-3, .stats-grid, .dashboard-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Cards: medium padding */
  .card { padding: var(--space-5); }

  /* Tables: show more columns than mobile, scroll for extras */
  .data-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .data-table th:first-child,
  .data-table td:first-child { position: sticky; left: 0; z-index: 1; background: var(--bg-surface); }

  /* Slightly smaller touch targets */
  .btn { min-height: 40px; }
  .form-control { min-height: 40px; }

  /* Page headers: slightly tighter */
  .page-header h1 { font-size: var(--h2); }

  /* Form rows: keep 2-column layout */
  .form-row { grid-template-columns: 1fr 1fr; }
}

/* Body scroll lock when modals/overlays are open */
body.modal-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
  touch-action: none;
}

/* Touch devices: remove hover transforms that feel janky */
@media (hover: none) {
  .card:hover { transform: none; }
  .data-table tbody tr:hover { background: transparent; }
  .data-table tbody tr:active { background: rgba(169, 255, 172, 0.04); }
}

/* Mobile: disable GPU-heavy backdrop-filter on all cards */
@media (max-width: 768px) {
  .card {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    box-shadow: none !important;
  }
}

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