:root {
  /* Material Design 3 Dark Theme Tokens */
  --md-sys-color-primary: #80c4ff;
  --md-sys-color-on-primary: #003355;
  --md-sys-color-primary-container: #004b77;
  --md-sys-color-on-primary-container: #cbe6ff;
  
  --md-sys-color-tesla: #e82127;
  --md-sys-color-tesla-container: #470d0f;

  --md-sys-color-secondary: #b8c8d8;
  --md-sys-color-on-secondary: #23323f;
  --md-sys-color-secondary-container: #3a4856;
  --md-sys-color-on-secondary-container: #d4e4f5;

  --md-sys-color-tertiary: #d0c0e8;
  --md-sys-color-on-tertiary: #362b4b;

  --md-sys-color-error: #ffb4ab;
  --md-sys-color-error-container: #93000a;
  --md-sys-color-on-error: #690005;

  --md-sys-color-background: #0f1115;
  --md-sys-color-on-background: #e2e2e6;
  
  --md-sys-color-surface: #14161a;
  --md-sys-color-on-surface: #e2e2e6;
  --md-sys-color-surface-variant: #252830;
  --md-sys-color-on-surface-variant: #c4c6d0;

  --md-sys-color-surface-container-lowest: #0a0b0e;
  --md-sys-color-surface-container-low: #121418;
  --md-sys-color-surface-container: #1b1e24;
  --md-sys-color-surface-container-high: #242730;
  --md-sys-color-surface-container-highest: #2e323d;

  --md-sys-color-outline: #474b57;
  --md-sys-color-outline-variant: #2f333e;

  --md-sys-color-success: #4ade80;
  --md-sys-color-success-container: #0f3920;
  --md-sys-color-warning: #facc15;
  --md-sys-color-warning-container: #423200;

  /* Elevation Shadows */
  --md-sys-elevation-1: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
  --md-sys-elevation-2: 0 4px 8px rgba(0,0,0,0.45), 0 2px 4px rgba(0,0,0,0.3);
  --md-sys-elevation-3: 0 8px 24px rgba(0,0,0,0.55), 0 3px 8px rgba(0,0,0,0.35);
  --md-sys-elevation-4: 0 16px 36px rgba(0,0,0,0.65), 0 6px 12px rgba(0,0,0,0.4);

  /* Shape Radii */
  --md-shape-xs: 4px;
  --md-shape-sm: 8px;
  --md-shape-md: 12px;
  --md-shape-lg: 16px;
  --md-shape-xl: 24px;
  --md-shape-full: 9999px;

  /* Font */
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

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

html, body {
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
}

body {
  font-family: var(--font-family);
  background-color: var(--md-sys-color-background);
  color: var(--md-sys-color-on-background);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Material 3 Card */
.m3-card {
  background: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-shape-lg);
  padding: 20px;
  box-shadow: var(--md-sys-elevation-1);
  transition: box-shadow 0.25s ease, transform 0.25s ease;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

.m3-card-high {
  background: var(--md-sys-color-surface-container-high);
}

.m3-card-interactive:hover {
  box-shadow: var(--md-sys-elevation-2);
  transform: translateY(-1px);
}

/* Material 3 Buttons */
.m3-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 20px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--md-shape-full);
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s cubic-bezier(0.2, 0, 0, 1);
  white-space: nowrap;
}

.m3-button-filled {
  background-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

.m3-button-filled:hover {
  opacity: 0.92;
  box-shadow: var(--md-sys-elevation-1);
}

.m3-button-tesla {
  background-color: var(--md-sys-color-tesla);
  color: #ffffff;
}

.m3-button-tesla:hover {
  background-color: #d11a1f;
  box-shadow: 0 4px 14px rgba(232, 33, 39, 0.4);
}

.m3-button-outlined {
  background: transparent;
  color: var(--md-sys-color-primary);
  border: 1px solid var(--md-sys-color-outline);
}

.m3-button-outlined:hover {
  background-color: rgba(128, 196, 255, 0.08);
}

.m3-button-text {
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  padding: 0 12px;
}

.m3-button-text:hover {
  background-color: rgba(255, 255, 255, 0.06);
  color: var(--md-sys-color-on-surface);
}

.m3-button-danger {
  color: var(--md-sys-color-error);
}

.m3-button-danger:hover {
  background-color: rgba(255, 180, 171, 0.1);
}

.m3-button-danger-filled {
  background-color: var(--md-sys-color-error);
  color: #1e0002;
  font-weight: 600;
}

.m3-button-danger-filled:hover {
  opacity: 0.92;
  box-shadow: 0 4px 14px rgba(255, 180, 171, 0.35);
}

/* Material 3 Chips */
.m3-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: var(--md-shape-sm);
  font-size: 13px;
  font-weight: 500;
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
}

.m3-chip-success {
  background: var(--md-sys-color-success-container);
  color: #86efac;
  border-color: rgba(74, 222, 128, 0.3);
}

.m3-chip-warning {
  background: var(--md-sys-color-warning-container);
  color: #fde047;
  border-color: rgba(250, 204, 21, 0.3);
}

.m3-chip-warning .pulse-dot {
  background-color: #facc15;
}

.m3-chip-error {
  background: var(--md-sys-color-error-container);
  color: #fca5a5;
  border-color: rgba(255, 180, 171, 0.3);
}

.m3-chip-error .pulse-dot {
  background-color: #f87171;
}

/* Material 3 Outlined Input */
.m3-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.m3-field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
}

.m3-input, .m3-select {
  height: 48px;
  background: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-shape-xs);
  padding: 0 16px;
  color: var(--md-sys-color-on-surface);
  font-family: inherit;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.m3-input:focus, .m3-select:focus {
  border-color: var(--md-sys-color-primary);
  box-shadow: 0 0 0 2px rgba(128, 196, 255, 0.2);
}

/* Material 3 Switch */
.m3-switch-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  user-select: none;
  cursor: pointer;
}

.m3-switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 32px;
}

.m3-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.m3-switch-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: var(--md-sys-color-surface-variant);
  border: 2px solid var(--md-sys-color-outline);
  transition: 0.25s;
  border-radius: 34px;
}

.m3-switch-slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 5px;
  bottom: 5px;
  background-color: var(--md-sys-color-outline);
  transition: 0.25s cubic-bezier(0.2, 0, 0, 1);
  border-radius: 50%;
}

.m3-switch input:checked + .m3-switch-slider {
  background-color: var(--md-sys-color-primary);
  border-color: var(--md-sys-color-primary);
}

.m3-switch input:checked + .m3-switch-slider:before {
  transform: translateX(18px);
  background-color: var(--md-sys-color-on-primary);
  width: 22px;
  height: 22px;
  left: 4px;
  bottom: 3px;
}

/* Linear Progress Bar M3 */
.m3-progress-container {
  width: 100%;
  height: 6px;
  background-color: var(--md-sys-color-surface-variant);
  border-radius: var(--md-shape-full);
  overflow: hidden;
  position: relative;
}

.m3-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #3b82f6, #60a5fa);
  border-radius: var(--md-shape-full);
  transition: width 0.8s cubic-bezier(0.2, 0, 0, 1);
}

/* Modal Dialog */
.m3-dialog-backdrop {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.m3-dialog-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.m3-dialog {
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-shape-xl);
  padding: 24px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--md-sys-elevation-4);
  transform: scale(0.95);
  transition: transform 0.25s cubic-bezier(0.2, 0, 0, 1);
}

.m3-dialog-backdrop.open .m3-dialog {
  transform: scale(1);
}

.m3-dialog-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--md-sys-color-on-surface);
}

.m3-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 24px;
}

/* Snackbar / Toast */
.m3-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--md-sys-color-on-surface);
  color: var(--md-sys-color-surface);
  padding: 12px 20px;
  border-radius: var(--md-shape-sm);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--md-sys-elevation-3);
  z-index: 3000;
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.2, 0, 0, 1);
  display: flex;
  align-items: center;
  gap: 10px;
}

.m3-toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Pulse animation */
@keyframes pulseGlow {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.05); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.8; }
}

.pulse-dot {
  width: 8px;
  height: 8px;
  background-color: var(--md-sys-color-success);
  border-radius: 50%;
  display: inline-block;
  animation: pulseGlow 2s infinite ease-in-out;
}
