/* Modern CSS Variables for consistency and maintainability */
:root {
  /* Color System */
  --primary: #3b82f6;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --secondary: #64748b;
  --secondary-light: #f1f5f9;
  
  --success: #10b981;
  --success-light: #d1fae5;
  --error: #ef4444;
  --error-light: #fee2e2;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  
  /* Neutrals */
  --white: #ffffff;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;
  
  /* Spacing Scale */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;
  
  /* Typography */
  --font-base: 'Inter', 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Monaco, 'Cascadia Code', monospace;
  
  /* Font Sizes (Fluid Typography) */
  --text-xs: clamp(0.75rem, 0.9vw, 0.875rem);
  --text-sm: clamp(0.875rem, 1vw, 1rem);
  --text-base: clamp(1rem, 1.1vw, 1.125rem);
  --text-lg: clamp(1.125rem, 1.3vw, 1.25rem);
  --text-xl: clamp(1.25rem, 1.5vw, 1.5rem);
  --text-2xl: clamp(1.5rem, 2vw, 2rem);
  --text-3xl: clamp(2rem, 2.5vw, 2.5rem);
  
  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  
  /* Border Radius */
  --radius-sm: 0.25rem;
  --radius: 0.5rem;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;
  --radius-xl: 1.5rem;
  --radius-full: 9999px;
  
  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 350ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Modern Reset */
*, *::before, *::after {
  box-sizing: border-box;
}

* {
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  text-size-adjust: 100%;
}

body {
  font-family: var(--font-base);
  background: linear-gradient(135deg, var(--gray-50) 0%, var(--white) 100%);
  color: var(--gray-800);
  line-height: 1.6;
  font-size: var(--text-base);
  min-height: 100vh;
  padding: var(--space-8) var(--space-4);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-8);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Modern Typography */
h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  color: var(--gray-900);
  letter-spacing: -0.025em;
  line-height: 1.2;
}

h1 {
  font-size: var(--text-3xl);
  margin-bottom: var(--space-8);
}

h2 {
  font-size: var(--text-2xl);
  margin-bottom: var(--space-6);
}

h3 {
  font-size: var(--text-xl);
  margin-bottom: var(--space-5);
}

/* Modern Links */
a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
  transition: all var(--transition-fast);
  position: relative;
}

a:hover {
  color: var(--primary-dark);
}

a:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Modern Button System */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-6);
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  user-select: none;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}

.btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

/* Primary Button */
.btn-primary, button:not([class]) {
  @extend .btn;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: var(--white);
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover, button:not([class]):hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-primary:active, button:not([class]):active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

/* Destructive Button */
.btn-delete {
  @extend .btn;
  background: linear-gradient(135deg, var(--error) 0%, #dc2626 100%);
  color: var(--white);
  box-shadow: var(--shadow-sm);
}

.btn-delete:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

/* Secondary Button */
.btn-secondary {
  @extend .btn;
  background: var(--white);
  color: var(--gray-700);
  border: 1px solid var(--gray-300);
  box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
  background: var(--gray-50);
  border-color: var(--gray-400);
  transform: translateY(-1px);
}

.btn-edit {
  @extend .btn-secondary;
  margin-right: var(--space-2);
}

/* Modern Form System */
form {
  width: 100%;
  max-width: 42rem;
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  padding: var(--space-8);
  background: var(--white);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--gray-200);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.form-label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--gray-700);
  letter-spacing: 0.025em;
}

.form-inline {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: var(--space-4);
  padding: var(--space-6);
  background: var(--gray-50);
  border-radius: var(--radius-lg);
  border: 1px solid var(--gray-200);
}

.form-inline input,
.form-inline select {
  flex: 1;
  min-width: 200px;
  margin: 0;
}

/* Modern Input System */
input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: var(--space-4) var(--space-4);
  font-size: var(--text-base);
  font-family: inherit;
  color: var(--gray-800);
  background: var(--white);
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-md);
  transition: all var(--transition);
  appearance: none;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
  transform: translateY(-1px);
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

input::placeholder,
textarea::placeholder {
  color: var(--gray-400);
  font-weight: 400;
}

/* Custom Select Styling */
select {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
  background-position: right var(--space-3) center;
  background-repeat: no-repeat;
  background-size: 1.5em 1.5em;
  padding-right: var(--space-10);
}

/* Textarea */
textarea {
  resize: vertical;
  min-height: 120px;
  font-family: var(--font-mono);
  line-height: 1.5;
}

/* Modern Table System */
.table-container {
  width: 100%;
  max-width: 72rem;
  background: var(--white);
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--gray-200);
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead {
  background: linear-gradient(135deg, var(--gray-900) 0%, var(--gray-800) 100%);
}

thead th {
  padding: var(--space-5) var(--space-6);
  font-weight: 600;
  font-size: var(--text-sm);
  text-align: left;
  color: var(--white);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

tbody tr {
  border-bottom: 1px solid var(--gray-200);
  transition: all var(--transition-fast);
}

tbody tr:hover {
  background: var(--gray-50);
}

tbody tr:last-child {
  border-bottom: none;
}

tbody td {
  padding: var(--space-4) var(--space-6);
  font-size: var(--text-sm);
  color: var(--gray-700);
  vertical-align: middle;
}

/* Modern Message System */
.msg, .error, .warning {
  padding: var(--space-4) var(--space-6);
  border-radius: var(--radius-lg);
  font-weight: 500;
  font-size: var(--text-sm);
  max-width: 42rem;
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  position: relative;
  border-left: 4px solid;
}

.msg {
  background: var(--success-light);
  color: var(--success);
  border-left-color: var(--success);
}

.error {
  background: var(--error-light);
  color: var(--error);
  border-left-color: var(--error);
}

.warning {
  background: var(--warning-light);
  color: var(--warning);
  border-left-color: var(--warning);
}

/* Modern Navigation */
nav {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  padding: var(--space-6);
  background: var(--white);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--gray-200);
  max-width: 42rem;
  width: 100%;
}

nav a {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: var(--white);
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: var(--text-sm);
  text-decoration: none;
  transition: all var(--transition);
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
}

nav a:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

nav a:active {
  transform: translateY(0);
}

/* Responsive Design */
@media (max-width: 768px) {
  :root {
    --space-4: 0.75rem;
    --space-6: 1.25rem;
    --space-8: 1.5rem;
  }
  
  body {
    padding: var(--space-4) var(--space-3);
    gap: var(--space-6);
  }
  
  form {
    padding: var(--space-6);
  }
  
  .form-inline {
    flex-direction: column;
    align-items: stretch;
  }
  
  .form-inline input,
  .form-inline select {
    min-width: auto;
  }
  
  nav {
    padding: var(--space-4);
  }
  
  nav a {
    flex: 1;
    justify-content: center;
  }
  
  .table-container {
    overflow-x: auto;
  }
  
  thead th,
  tbody td {
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-xs);
  }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
  :root {
    --white: #0f172a;
    --gray-50: #1e293b;
    --gray-100: #334155;
    --gray-200: #475569;
    --gray-300: #64748b;
    --gray-700: #cbd5e1;
    --gray-800: #e2e8f0;
    --gray-900: #f1f5f9;
  }
  
  body {
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  }
}

/* Accessibility Improvements */
@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;
  }
}

/* Focus Management */
.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;
}

/* Loading States */
.loading {
  position: relative;
  pointer-events: none;
}

.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1rem;
  height: 1rem;
  margin: -0.5rem 0 0 -0.5rem;
  border: 2px solid transparent;
  border-top: 2px solid var(--primary);
  border-radius: var(--radius-full);
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
