@import './DesignTokens.css';

/* Expert UI/UX Modern Drone Config Card */
.drone-config-card {
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border-primary);
  border-radius: var(--border-radius-base);
  padding: 0;
  margin-bottom: var(--spacing-lg);
  transition: var(--transition-base);
  position: relative;
  max-width: 100%;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

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

/* Enhanced Status indicator - left border accent */
.drone-config-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--card-accent-color, var(--color-primary));
  z-index: 2;
  transition: var(--transition-base);
}

/* Status-based card variations */
.drone-config-card.status-online {
  --card-accent-color: var(--color-success);
  border-color: var(--color-success-border);
}

.drone-config-card.status-stale {
  --card-accent-color: var(--color-warning);
  border-color: var(--color-warning-border);
}

.drone-config-card.status-offline {
  --card-accent-color: var(--color-danger);
  border-color: var(--color-danger-border);
}

.drone-config-card.status-unknown {
  --card-accent-color: var(--color-text-tertiary);
  border-color: var(--color-border-secondary);
}

.drone-config-card.mismatch-drone {
  --card-accent-color: var(--color-danger);
  border-color: var(--color-danger-border);
}

/* Card Header - Status-Based Professional Design */
.drone-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: var(--spacing-base) var(--spacing-base) var(--spacing-base) calc(var(--spacing-base) + 4px);
  background: var(--header-bg-color, var(--color-bg-tertiary));
  border-bottom: 1px solid var(--color-border-primary);
  position: relative;
}

/* Status-based header backgrounds */
.drone-config-card.status-online .drone-card-header {
  --header-bg-color: linear-gradient(135deg, var(--color-success-light), var(--color-bg-tertiary));
}

.drone-config-card.status-stale .drone-card-header {
  --header-bg-color: linear-gradient(135deg, var(--color-warning-light), var(--color-bg-tertiary));
}

.drone-config-card.status-offline .drone-card-header {
  --header-bg-color: linear-gradient(135deg, var(--color-danger-light), var(--color-bg-tertiary));
}

.drone-config-card.status-unknown .drone-card-header {
  --header-bg-color: linear-gradient(135deg, var(--color-bg-quaternary), var(--color-bg-tertiary));
}

.drone-id-section {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
  min-width: 0;
  flex: 1;
}

.drone-title {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-bold);
  color: var(--color-text-primary);
  font-family: var(--font-family-primary);
  margin: 0 0 var(--spacing-xs) 0;
  line-height: var(--line-height-tight);
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-hover));
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: none;
  position: relative;
}

.drone-title::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 40px;
  height: 2px;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-hover));
  border-radius: 1px;
}

.drone-subtitle {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
}

.drone-hardware-id,
.drone-position-id {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  font-family: var(--font-family-mono);
  font-weight: var(--font-weight-medium);
}

.drone-hardware-id {
  color: var(--color-text-primary);
}

.drone-position-id {
  color: var(--color-text-tertiary);
}

/* Status Badge - Right aligned */
.card-actions {
  display: flex;
  gap: var(--spacing-xs);
  align-items: flex-start;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  padding: var(--spacing-sm) var(--spacing-base);
  border-radius: var(--border-radius-base);
  text-transform: none;
  letter-spacing: 0.2px;
  white-space: nowrap;
  min-height: 32px;
}

.status-text {
  font-weight: var(--font-weight-semibold);
}

.status-time {
  opacity: 0.8;
  font-weight: var(--font-weight-normal);
  margin-left: var(--spacing-xs);
}

.status-badge.online {
  background: var(--color-success-light);
  color: var(--color-success-text);
  border: 1px solid var(--color-success-border);
}

.status-badge.stale {
  background: var(--color-warning-light);
  color: var(--color-warning-text);
  border: 1px solid var(--color-warning-border);
}

.status-badge.offline {
  background: var(--color-danger-light);
  color: var(--color-danger-text);
  border: 1px solid var(--color-danger-border);
}

.status-badge.unknown {
  background: var(--color-bg-tertiary);
  color: var(--color-text-tertiary);
  border: 1px solid var(--color-border-primary);
}

/* Main Content - Left-aligned Grid */
.drone-content {
  display: grid;
  gap: var(--spacing-sm);
  padding: var(--spacing-base) var(--spacing-base) var(--spacing-base) calc(var(--spacing-base) + 4px);
}

/* Info Sections - Clean, Scannable */
.info-section {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--spacing-xs);
}

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--spacing-xs);
  background: var(--color-bg-tertiary);
  border-radius: var(--border-radius-sm);
  font-size: var(--font-size-sm);
  min-height: 32px;
}

.info-label {
  color: var(--color-text-secondary);
  font-weight: var(--font-weight-medium);
  min-width: 80px;
  flex-shrink: 0;
  text-align: left;
}

.info-value {
  color: var(--color-text-primary);
  font-family: var(--font-family-mono);
  font-size: var(--font-size-sm);
  text-align: right;
  min-width: 0;
  flex: 1;
  word-break: break-word;
}

.info-value.mismatch {
  color: var(--color-danger);
  font-weight: var(--font-weight-semibold);
}

/* Status Icons - Clean, Consistent */
.status-icon {
  width: 14px;
  height: 14px;
  margin-left: var(--spacing-xs);
  flex-shrink: 0;
}

.status-icon.online { color: var(--color-success); }
.status-icon.stale { color: var(--color-warning); }
.status-icon.offline { color: var(--color-danger); }
.status-icon.no-heartbeat { color: var(--color-text-tertiary); }
.status-icon.all-good { color: var(--color-success); }

/* Position ID Status - Simplified */
.position-section {
  border: 1px solid var(--color-border-primary);
  border-radius: var(--border-radius-sm);
  overflow: hidden;
  background: var(--color-bg-tertiary);
}

.position-header {
  background: var(--color-bg-quaternary);
  padding: var(--spacing-xs) var(--spacing-sm);
  border-bottom: 1px solid var(--color-border-primary);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-bold);
  color: var(--color-text-primary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  min-height: 28px;
}

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

.position-status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: var(--font-size-sm);
}

.position-status {
  padding: var(--spacing-sm) var(--spacing-base);
  border-radius: var(--border-radius-sm);
  border: 1px solid var(--color-border-primary);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
  min-height: auto;
}

.position-status.match {
  background: var(--color-success-light);
  color: var(--color-text-primary);
  border-color: var(--color-success-border);
  border-left: 3px solid var(--color-success);
}

.position-status.partial {
  background: var(--color-warning-light);
  color: var(--color-text-primary);
  border-color: var(--color-warning-border);
  border-left: 3px solid var(--color-warning);
}

.position-status.mismatch {
  background: var(--color-danger-light);
  color: var(--color-text-primary);
  border-color: var(--color-danger-border);
  border-left: 3px solid var(--color-danger);
}

.position-values {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-xs);
  margin-top: var(--spacing-xs);
}

.position-value {
  font-family: var(--font-family-mono);
  font-size: var(--font-size-xs);
  padding: var(--spacing-xs) var(--spacing-sm);
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border-primary);
  border-radius: var(--border-radius-sm);
  color: var(--color-text-primary);
  font-weight: var(--font-weight-medium);
}

/* Action Buttons - Modern Design */
.action-button {
  background: var(--color-primary);
  color: var(--color-text-primary);
  border: none;
  border-radius: var(--border-radius-sm);
  padding: var(--spacing-xs) var(--spacing-sm);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  cursor: pointer;
  transition: var(--transition-base);
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-xs);
  min-height: 28px;
}

.action-button:hover {
  background: var(--color-primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.action-button.secondary {
  background: var(--color-text-tertiary);
}

.action-button.secondary:hover {
  background: var(--color-text-secondary);
}

.action-button.danger {
  background: var(--color-danger);
}

.action-button.danger:hover {
  background: var(--color-danger-hover);
}

.action-button.success {
  background: var(--color-success);
}

.action-button.success:hover {
  background: var(--color-success-hover);
}

/* Edit Form Container */
.drone-edit-form {
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border-primary);
  border-radius: var(--border-radius-base);
  padding: 0;
  margin: 0;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.form-header {
  background: var(--color-bg-tertiary);
  padding: var(--spacing-base) var(--spacing-lg);
  border-bottom: 1px solid var(--color-border-primary);
  margin: 0;
}

.form-header h3 {
  margin: 0;
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
  color: var(--color-text-primary);
  font-family: var(--font-family-primary);
}

/* Form Fields - Clean, Professional */
.form-section {
  display: grid;
  gap: var(--spacing-base);
  padding: var(--spacing-lg);
  background: var(--color-bg-secondary);
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
}

.form-label {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin: 0;
}

.form-input,
.form-select {
  padding: var(--spacing-xs) var(--spacing-sm);
  border: 1px solid var(--color-border-primary);
  border-radius: var(--border-radius-sm);
  background: var(--color-bg-tertiary);
  color: var(--color-text-primary);
  font-family: var(--font-family-mono);
  font-size: var(--font-size-sm);
  transition: var(--transition-base);
  min-height: 32px;
}

.form-input:focus,
.form-select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 1px var(--color-primary-border);
  background: var(--color-bg-primary);
}

.form-input::placeholder {
  color: var(--color-text-tertiary);
  font-style: italic;
}

/* Error Messages */
.error-message {
  color: var(--color-danger);
  font-size: var(--font-size-xs);
  margin-top: var(--spacing-xs);
}

/* Button Groups */
.button-group {
  display: flex;
  gap: var(--spacing-sm);
  justify-content: flex-end;
  padding: var(--spacing-base) var(--spacing-lg);
  background: var(--color-bg-tertiary);
  border-top: 1px solid var(--color-border-primary);
  margin: 0;
}

/* Button group for read-only view */
.drone-content + .button-group {
  margin-top: var(--spacing-sm);
  padding: var(--spacing-sm);
  background: transparent;
  border-top: 1px solid var(--color-border-primary);
}

/* Network Info - Clean Professional Design */
.network-section {
  border: 1px solid var(--color-border-primary);
  border-radius: var(--border-radius-sm);
  overflow: hidden;
  margin-top: var(--spacing-sm);
}

.network-header {
  background: var(--color-bg-tertiary);
  padding: var(--spacing-xs) var(--spacing-sm);
  border-bottom: 1px solid var(--color-border-primary);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
}

.network-content {
  padding: var(--spacing-sm);
  background: var(--color-bg-secondary);
}

.network-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--spacing-xs) 0;
  font-size: var(--font-size-sm);
  border-bottom: 1px solid var(--color-border-primary);
}

.network-row:last-child {
  border-bottom: none;
}

.network-label {
  color: var(--color-text-secondary);
  font-weight: var(--font-weight-medium);
  min-width: 80px;
}

.network-value {
  font-family: var(--font-family-mono);
  color: var(--color-text-primary);
  font-size: var(--font-size-sm);
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
}

.network-status {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-xs);
  padding: 2px var(--spacing-xs);
  border-radius: var(--border-radius-sm);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
}

.network-status.connected {
  background: var(--color-success-light);
  color: var(--color-success-text);
  border: 1px solid var(--color-success-border);
}

.network-status.disconnected {
  background: var(--color-danger-light);
  color: var(--color-danger-text);
  border: 1px solid var(--color-danger-border);
}

.network-status.unknown {
  background: var(--color-bg-tertiary);
  color: var(--color-text-tertiary);
  border: 1px solid var(--color-border-primary);
}

/* Signal Strength Icons */
.wifi-icon {
  width: 14px;
  height: 14px;
  margin-left: var(--spacing-xs);
}

.wifi-icon.strong { color: var(--color-success); }
.wifi-icon.medium { color: var(--color-warning); }
.wifi-icon.weak { color: var(--color-danger); }
.wifi-icon.none { color: var(--color-text-tertiary); }

/* New Drone Badge */
.new-drone-badge {
  position: absolute;
  top: var(--spacing-xs);
  right: var(--spacing-xs);
  background: var(--color-success);
  color: var(--color-text-primary);
  padding: var(--spacing-xs);
  border-radius: var(--border-radius-full);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-bold);
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  z-index: 10;
}

/* Legacy Support - Clean up old styles */
.heartbeat-info,
.position-id-block,
.mismatch-row,
.accept-button {
  /* Override old styles */
  all: unset;
  display: block;
}

/* Accept buttons in mismatch scenarios */
.accept-buttons {
  display: flex;
  gap: var(--spacing-xs);
  margin-top: var(--spacing-xs);
  flex-wrap: wrap;
}

.accept-button {
  background: var(--color-info);
  color: var(--color-text-primary);
  border: none;
  border-radius: var(--border-radius-sm);
  padding: var(--spacing-xs) var(--spacing-sm);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  cursor: pointer;
  transition: var(--transition-base);
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-xs);
}

.accept-button:hover {
  background: var(--color-info-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.accept-assigned-btn {
  background: var(--color-success);
}

.accept-assigned-btn:hover {
  background: var(--color-success-hover);
}

/* Toggle Switch for Position ID */
.toggle-container {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  margin-top: var(--spacing-xs);
  padding: var(--spacing-xs);
  background: var(--color-bg-quaternary);
  border-radius: var(--border-radius-sm);
}

.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 24px;
}

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

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--color-text-tertiary);
  transition: var(--transition-base);
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: var(--color-bg-primary);
  transition: var(--transition-base);
}

input:checked + .slider {
  background-color: var(--color-primary);
}

input:focus + .slider {
  box-shadow: 0 0 1px var(--color-primary);
}

input:checked + .slider:before {
  transform: translateX(24px);
}

.slider.round {
  border-radius: 24px;
}

.slider.round:before {
  border-radius: 50%;
}

.toggle-label {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  font-weight: var(--font-weight-medium);
}

/* Missing Data States */
.mismatch-message {
  background: var(--color-warning-light);
  color: var(--color-warning-text);
  border: 1px solid var(--color-warning-border);
  border-radius: var(--border-radius-sm);
  padding: var(--spacing-sm);
  margin-top: var(--spacing-xs);
  font-size: var(--font-size-xs);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-sm);
  flex-wrap: wrap;
}

/* Data unavailable states */
.data-unavailable {
  color: var(--color-text-tertiary);
  font-style: italic;
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
}

.data-unavailable::before {
  content: "⚠";
  color: var(--color-warning);
  font-style: normal;
}

/* Responsive Design */
@media (max-width: 768px) {
  .drone-config-card {
    padding: var(--spacing-sm);
    margin-bottom: var(--spacing-sm);
  }

  .drone-card-header {
    flex-direction: column;
    gap: var(--spacing-xs);
    align-items: flex-start;
  }

  .card-actions {
    width: 100%;
    justify-content: space-between;
  }

  .info-row {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--spacing-xs);
  }

  .info-label {
    min-width: auto;
  }

  .info-value {
    text-align: left;
  }

  .position-status {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--spacing-xs);
  }

  .button-group {
    flex-direction: column;
  }

  .action-button {
    width: 100%;
    justify-content: center;
  }
}

/* High contrast support */
@media (prefers-contrast: high) {
  .drone-config-card,
  .info-row,
  .position-section,
  .form-input,
  .form-select {
    border-width: 2px;
  }
}

/* Confirmation Dialog */
.confirmation-dialog-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
}

.confirmation-dialog {
  background: var(--color-bg-primary);
  border: 2px solid var(--color-border-primary);
  border-radius: var(--border-radius-lg);
  padding: var(--spacing-xl);
  max-width: 400px;
  width: 90%;
  box-shadow: var(--shadow-lg);
  animation: slideDown 0.3s ease-out;
}

.confirmation-dialog h4 {
  color: var(--color-text-primary);
  margin: 0 0 var(--spacing-base) 0;
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
}

.confirmation-dialog p {
  color: var(--color-text-secondary);
  margin: var(--spacing-sm) 0;
  line-height: var(--line-height-normal);
}

.dialog-buttons {
  display: flex;
  gap: var(--spacing-sm);
  justify-content: flex-end;
  margin-top: var(--spacing-lg);
}

.confirm-button {
  background: var(--color-primary);
  color: var(--color-text-primary);
  border: none;
  border-radius: var(--border-radius-sm);
  padding: var(--spacing-sm) var(--spacing-lg);
  cursor: pointer;
  font-weight: var(--font-weight-semibold);
  transition: var(--transition-base);
}

.confirm-button:hover {
  background: var(--color-primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.cancel-button {
  background: var(--color-text-tertiary);
  color: var(--color-text-primary);
  border: none;
  border-radius: var(--border-radius-sm);
  padding: var(--spacing-sm) var(--spacing-lg);
  cursor: pointer;
  font-weight: var(--font-weight-semibold);
  transition: var(--transition-base);
}

.cancel-button:hover {
  background: var(--color-text-secondary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Accessibility and Focus States */
.action-button:focus,
.form-input:focus,
.form-select:focus,
.method-button:focus,
.ok-button:focus,
.cancel-button:focus,
.retry-button:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .drone-config-card {
    border-width: 2px;
    box-shadow: none;
  }

  .action-button,
  .status-badge {
    border-width: 2px;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .drone-config-card,
  .action-button,
  .form-input,
  .form-select,
  .drone-title::after {
    transition: none;
    animation: none;
  }

  .action-button:hover,
  .confirm-button:hover,
  .cancel-button:hover {
    transform: none;
  }

  .confirmation-dialog {
    animation: none;
  }
}

/* Print styles */
@media print {
  .drone-config-card {
    box-shadow: none;
    border: 1px solid #000;
    background: #fff !important;
    color: #000 !important;
    break-inside: avoid;
  }

  .action-button,
  .button-group {
    display: none;
  }
}