/* Modal System Styles - COMPLETELY REDESIGNED for Modern UX/UI */

/* ========================================
   MODAL CONTAINER & BACKDROP
======================================== */
.modal { 
  position: fixed; 
  top: 0; 
  left: 0; 
  width: 100%; 
  height: 100%; 
  background: rgba(0, 0, 0, 0.75);
  display: flex; 
  align-items: center; 
  justify-content: center; 
  z-index: 1001;
  padding: 20px;
  box-sizing: border-box;
  backdrop-filter: blur(12px);
  animation: modalFadeIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow: hidden;
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
    backdrop-filter: blur(0px);
  }
  to {
    opacity: 1;
    backdrop-filter: blur(12px);
  }
}

@keyframes modalFadeOut {
  from {
    opacity: 1;
    backdrop-filter: blur(12px);
  }
  to {
    opacity: 0;
    backdrop-filter: blur(0px);
  }
}

/* ========================================
   MODAL CONTENT CONTAINER
======================================== */
.modal-content { 
  background: #ffffff;
  border-radius: 16px; 
  width: 100%;
  max-width: 420px;
  max-height: calc(100vh - 40px);
  overflow: hidden;
  box-shadow: 
    0 24px 48px rgba(0, 0, 0, 0.15),
    0 12px 24px rgba(0, 0, 0, 0.08),
    0 0 0 1px rgba(255, 255, 255, 0.1);
  display: flex;
  flex-direction: column;
  animation: modalSlideIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

@keyframes modalSlideIn {
  from {
    transform: translateY(40px) scale(0.9);
    opacity: 0;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

/* ========================================
   MODAL CLOSE BUTTON
======================================== */
.modal-close-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  background: rgba(0, 0, 0, 0.1);
  border: none;
  border-radius: 50%;
  color: #6b7280;
  font-size: 18px;
  font-weight: 300;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  z-index: 10;
  line-height: 1;
  padding: 0;
  outline: none;
}

.modal-close-btn:hover {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
  transform: scale(1.1);
}

.modal-close-btn:active {
  transform: scale(0.95);
}

.modal-close-btn:focus-visible {
  outline: 2px solid #667eea;
  outline-offset: 2px;
}

/* Settings panel close button */
.panel .modal-close-btn {
  top: 12px;
  right: 12px;
  background: rgba(255, 255, 255, 0.1);
  color: #374151;
  border-radius: 6px;
  width: 28px;
  height: 28px;
  font-size: 16px;
}

.panel .modal-close-btn:hover {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}

/* ========================================
   MODAL HEADER
======================================== */
.modal-content h2 {
  margin: 0;
  padding: 20px 24px 16px;
  font-size: 20px;
  font-weight: 700;
  color: #1a202c;
  display: flex;
  align-items: center;
  gap: 12px;
  line-height: 1.3;
  border-bottom: 1px solid #f1f5f9;
  background: linear-gradient(145deg, #ffffff 0%, #f8fafc 100%);
  border-radius: 16px 16px 0 0;
  letter-spacing: -0.02em;
  position: relative;
}

.modal-content h2::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 24px;
  right: 24px;
  height: 1px;
  background: linear-gradient(90deg, transparent 0%, #e2e8f0 50%, transparent 100%);
}

.modal-content h2 .person-icon {
  width: 28px;
  height: 28px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
  box-shadow: 
    0 4px 12px rgba(102, 126, 234, 0.4),
    0 2px 4px rgba(102, 126, 234, 0.2);
  position: relative;
  overflow: hidden;
}

.modal-content h2 .person-icon::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.2) 50%, transparent 70%);
  transform: rotate(45deg);
  animation: shimmer 2s ease-in-out infinite;
}

@keyframes shimmer {
  0%, 100% { transform: translateX(-100%) translateY(-100%) rotate(45deg); }
  50% { transform: translateX(100%) translateY(100%) rotate(45deg); }
}

/* ========================================
   MODAL BODY
======================================== */
.modal-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 24px 8px;
  scrollbar-width: none;
  -ms-overflow-style: none;
  scroll-behavior: smooth;
}

.modal-body::-webkit-scrollbar {
  display: none;
}

/* ========================================
   FORM GROUPS - ENHANCED DESIGN
======================================== */
.form-group { 
  margin-bottom: 20px;
  position: relative;
  animation: fadeInUp 0.4s ease-out;
  animation-fill-mode: both;
}

.form-group:nth-child(1) { animation-delay: 0.1s; }
.form-group:nth-child(2) { animation-delay: 0.15s; }
.form-group:nth-child(3) { animation-delay: 0.2s; }
.form-group:nth-child(4) { animation-delay: 0.25s; }
.form-group:nth-child(5) { animation-delay: 0.3s; }
.form-group:nth-child(6) { animation-delay: 0.35s; }
.form-group:nth-child(7) { animation-delay: 0.4s; }
.form-group:nth-child(8) { animation-delay: 0.45s; }

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

.form-group:last-of-type {
  margin-bottom: 24px;
}

.form-group label { 
  display: block; 
  margin-bottom: 8px; 
  font-weight: 600;
  color: #374151;
  font-size: 14px;
  line-height: 1.4;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  font-size: 12px;
  opacity: 0.8;
  transition: all 0.2s ease;
}

.form-group:focus-within label {
  color: #667eea;
  opacity: 1;
  transform: translateY(-2px);
}

.form-group label .required {
  color: #ef4444;
  margin-left: 4px;
  font-size: 14px;
}

.form-group input, 
.form-group select { 
  width: 100%; 
  padding: 14px 16px; 
  font-size: 15px;
  border: 2px solid #e5e7eb; 
  border-radius: 12px; 
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-sizing: border-box;
  background: #ffffff;
  font-family: inherit;
  line-height: 1.5;
  color: #374151;
  font-weight: 500;
  position: relative;
  outline: none;
  backdrop-filter: blur(10px);
  background: rgba(255, 255, 255, 0.95);
}

.form-group input:not(:placeholder-shown),
.form-group select:not(:empty) {
  border-color: #d1d5db;
  background: #ffffff;
}

.form-group input:hover,
.form-group select:hover {
  border-color: #d1d5db;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  transform: translateY(-1px);
}

.form-group input:focus, 
.form-group select:focus {
  border-color: #667eea;
  box-shadow: 
    0 0 0 4px rgba(102, 126, 234, 0.15),
    0 8px 24px rgba(0, 0, 0, 0.12);
  background: #ffffff;
  transform: translateY(-2px);
}

.form-group input::placeholder {
  color: #9ca3af;
  font-weight: 400;
  opacity: 0.7;
}

/* ========================================
   GENDER RADIO BUTTONS - REDESIGNED
======================================== */
.gender-radio-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 12px;
}

.gender-radio-option {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  padding: 16px 20px;
  border-radius: 12px;
  border: 2px solid #e5e7eb;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  background: #ffffff;
  position: relative;
  overflow: hidden;
  min-height: 52px;
  user-select: none;
}

.gender-radio-option::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.05) 0%, rgba(118, 75, 162, 0.05) 100%);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.gender-radio-option:hover {
  border-color: #d1d5db;
  background: #f9fafb;
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

.gender-radio-option:hover::before {
  opacity: 1;
}

.gender-radio-option:has(input[type="radio"]:checked) {
  border-color: #667eea;
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
  color: #667eea;
  font-weight: 600;
  box-shadow: 
    0 0 0 4px rgba(102, 126, 234, 0.15),
    0 8px 24px rgba(102, 126, 234, 0.2);
  transform: translateY(-2px);
}

.gender-radio-option input[type="radio"] {
  width: 20px;
  height: 20px;
  cursor: pointer;
  accent-color: #667eea;
  margin: 0;
  position: relative;
  pointer-events: none;
}

.gender-radio-option label {
  cursor: pointer;
  font-weight: 600;
  margin: 0;
  font-size: 15px;
  white-space: nowrap;
  user-select: none;
  position: relative;
  z-index: 1;
  pointer-events: none;
}

/* ========================================
   SEARCHABLE SELECT STYLING
======================================== */
.searchable-select {
  position: relative;
}

.searchable-select .select-input {
  width: 100%;
  padding: 14px 16px;
  font-size: 15px;
  border: 2px solid #e5e7eb;
  border-radius: 12px;
  background: #ffffff;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.searchable-select .select-input:hover {
  border-color: #d1d5db;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  transform: translateY(-1px);
}

.searchable-select .select-input:focus {
  border-color: #667eea;
  box-shadow: 
    0 0 0 4px rgba(102, 126, 234, 0.15),
    0 8px 24px rgba(0, 0, 0, 0.12);
  transform: translateY(-2px);
}

/* ========================================
   HELP TEXT
======================================== */
.help-text { 
  font-size: 12px; 
  color: #6b7280; 
  margin-top: 4px;
  line-height: 1.4;
  display: block;
  padding: 6px 0;
  background: none;
  border: none;
  font-style: italic;
}

/* Remove the colored icon element */

/* ========================================
   FORM ACTIONS - COMPLETELY REDESIGNED
======================================== */
.form-actions {
  position: relative;
  background: linear-gradient(145deg, #ffffff 0%, #f8fafc 100%);
  border-top: 1px solid #f1f5f9;
  padding: 18px 24px;
  margin: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  flex-shrink: 0;
  border-radius: 0 0 16px 16px;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.06);
  gap: 12px;
}

/* Ensure desktop grid layout doesn't interfere on mobile */
@media (min-width: 769px) {
  .form-actions {
    display: grid !important;
    grid-template-columns: auto 1fr auto auto !important;
    flex-direction: unset !important;
  }
}

.form-actions::before {
  content: '';
  position: absolute;
  top: 0;
  left: 24px;
  right: 24px;
  height: 1px;
  background: linear-gradient(90deg, transparent 0%, #e2e8f0 50%, transparent 100%);
}

.form-actions-right {
  display: flex;
  gap: 12px;
  align-items: center;
  grid-column: 3 / 5;
  justify-self: end;
}

/* ========================================
   BUTTONS - MODERN DESIGN SYSTEM
======================================== */
.form-actions button {
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  min-width: 100px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  line-height: 1;
  position: relative;
  user-select: none;
  white-space: nowrap;
  text-decoration: none;
  outline: none;
  overflow: hidden;
}

.form-actions button::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.3) 50%, transparent 70%);
  transform: translateX(-100%);
  transition: transform 0.6s ease;
}

.form-actions button:hover::before {
  transform: translateX(100%);
}

.form-actions button:active {
  transform: translateY(2px) scale(0.98);
}

.form-actions button:focus-visible {
  box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.3);
}

/* DELETE BUTTON */
.form-actions button[id*="delete"] {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  color: #ffffff;
  box-shadow: 
    0 8px 24px rgba(239, 68, 68, 0.3),
    0 4px 12px rgba(239, 68, 68, 0.2);
  grid-column: 1;
  justify-self: start;
}

.form-actions button[id*="delete"]:hover {
  background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
  transform: translateY(-2px);
  box-shadow: 
    0 12px 32px rgba(239, 68, 68, 0.4),
    0 8px 16px rgba(239, 68, 68, 0.3);
}

.form-actions button[id*="delete"]:active {
  transform: translateY(1px) scale(0.98);
}

/* CANCEL BUTTON */
.form-actions button[id*="cancel"] { 
  background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%);
  color: #ffffff;
  box-shadow: 
    0 8px 24px rgba(107, 114, 128, 0.3),
    0 4px 12px rgba(107, 114, 128, 0.2);
}

.form-actions button[id*="cancel"]:hover {
  background: linear-gradient(135deg, #4b5563 0%, #374151 100%);
  transform: translateY(-2px);
  box-shadow: 
    0 12px 32px rgba(107, 114, 128, 0.4),
    0 8px 16px rgba(107, 114, 128, 0.3);
}

/* SAVE/APPLY BUTTON */
.form-actions button[id*="save"],
.form-actions button[id*="apply"] { 
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #ffffff;
  box-shadow: 
    0 8px 24px rgba(16, 185, 129, 0.3),
    0 4px 12px rgba(16, 185, 129, 0.2);
  position: relative;
}

.form-actions button[id*="save"]:hover,
.form-actions button[id*="apply"]:hover {
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
  transform: translateY(-2px);
  box-shadow: 
    0 12px 32px rgba(16, 185, 129, 0.4),
    0 8px 16px rgba(16, 185, 129, 0.3);
}

/* ========================================
   LOADING STATES
======================================== */
.form-actions button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

.form-actions button.loading {
  position: relative;
  color: transparent;
  pointer-events: none;
}

.form-actions button.loading::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  border: 3px solid transparent;
  border-top: 3px solid currentColor;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
}

@keyframes spin {
  0% { transform: translate(-50%, -50%) rotate(0deg); }
  100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* ========================================
   ERROR STATES
======================================== */
.form-group.error input,
.form-group.error select,
.form-group.error .select-input {
  border-color: #ef4444 !important;
  box-shadow: 
    0 0 0 4px rgba(239, 68, 68, 0.15),
    0 4px 12px rgba(239, 68, 68, 0.1) !important;
  background: rgba(239, 68, 68, 0.02);
}

.form-group.error .gender-radio-option {
  border-color: #ef4444 !important;
  background: rgba(239, 68, 68, 0.02) !important;
}

.error-message {
  color: #ef4444;
  font-size: 13px;
  margin-top: 8px;
  animation: slideDown 0.3s ease-out;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: rgba(239, 68, 68, 0.05);
  border-radius: 12px;
  border-left: 3px solid #ef4444;
}

.error-message::before {
  content: "⚠️";
  font-size: 14px;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
    max-height: 0;
  }
  to {
    opacity: 1;
    transform: translateY(0);
    max-height: 100px;
  }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* ========================================
   CONFIRMATION MODALS
======================================== */
#deleteConfirmModal,
#clearAllConfirmModal,
#lineRemovalModal {
  z-index: 1050 !important;
  background: rgba(0, 0, 0, 0.85) !important;
  backdrop-filter: blur(16px);
}

.confirmation-modal {
  max-width: 420px !important;
}

.confirmation-content {
  text-align: center;
  padding: 8px 0 16px;
}

.warning-icon,
.info-icon {
  font-size: 48px;
  margin-bottom: 16px;
  display: block;
  animation: pulse 2s ease-in-out infinite;
}

.warning-icon {
  color: #ef4444;
}

.info-icon {
  color: #667eea;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.05); opacity: 0.8; }
}

.confirmation-message {
  font-size: 16px;
  line-height: 1.6;
  color: #374151;
  margin-bottom: 24px;
  font-weight: 500;
}

.consequence-list {
  background: rgba(243, 244, 246, 0.7);
  border-radius: 12px;
  padding: 16px 20px;
  margin: 0 auto;
  max-width: 320px;
  text-align: left;
}

.consequence-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 8px;
  font-size: 14px;
  color: #6b7280;
  line-height: 1.5;
}

.consequence-item:last-child {
  margin-bottom: 0;
}

.consequence-item .bullet {
  color: #ef4444;
  font-weight: 700;
  font-size: 16px;
  margin-top: 1px;
  flex-shrink: 0;
}

#lineRemovalModal .consequence-item .bullet {
  color: #667eea;
}

/* Confirmation modal specific button styling */
.confirmation-modal .form-actions {
  padding: 20px 32px 24px;
  justify-content: center;
}

.confirmation-modal .form-actions-right {
  justify-content: center;
  width: 100%;
  max-width: 300px;
}

.confirmation-modal .form-actions button {
  min-width: 140px;
}

/* Compact confirmation modals on mobile */
@media (max-width: 768px) {
  .confirmation-modal .form-actions {
    padding: 14px 18px;
    display: flex;
    flex-direction: row;
    justify-content: center;
    gap: 10px;
  }
  
  .confirmation-modal .form-actions-right {
    display: flex;
    gap: 10px;
    max-width: none;
    width: auto;
  }
  
  .confirmation-modal .form-actions button {
    min-width: 110px;
    height: 40px;
    font-size: 13px;
    flex: 1;
  }
  
  .confirmation-content {
    padding: 4px 0 12px;
  }
  
  .warning-icon,
  .info-icon {
    font-size: 36px;
    margin-bottom: 12px;
  }
  
  .confirmation-message {
    font-size: 15px;
    margin-bottom: 16px;
  }
  
  .consequence-list {
    padding: 12px 16px;
    margin: 0 8px;
  }
  
  .consequence-item {
    font-size: 13px;
    margin-bottom: 6px;
  }
}

@media (max-width: 480px) {
  .confirmation-modal .form-actions {
    padding: 12px 16px;
    gap: 8px;
  }
  
  .confirmation-modal .form-actions-right {
    gap: 8px;
  }
  
  .confirmation-modal .form-actions button {
    min-width: 100px;
    height: 40px;
    font-size: 12px;
    padding: 8px 12px;
  }
  
  .warning-icon,
  .info-icon {
    font-size: 32px;
    margin-bottom: 10px;
  }
  
  .confirmation-message {
    font-size: 14px;
    margin-bottom: 14px;
  }
  
  .consequence-list {
    padding: 10px 14px;
    margin: 0 4px;
  }
  
  .consequence-item {
    font-size: 12px;
    margin-bottom: 5px;
  }
}

/* Enhanced confirmation button styling */
.confirmation-modal button[id*="confirm"] {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  color: #ffffff;
  font-weight: 700;
  position: relative;
  overflow: hidden;
}

.confirmation-modal button[id*="confirm"]:hover {
  background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
  transform: translateY(-2px);
  box-shadow: 
    0 12px 32px rgba(239, 68, 68, 0.5),
    0 8px 16px rgba(239, 68, 68, 0.3);
}

.confirmation-modal button[id*="confirm"]::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
  transition: left 0.5s ease;
}

.confirmation-modal button[id*="confirm"]:hover::before {
  left: 100%;
}

/* Line removal modal specific styling */
#lineRemovalModal button[id*="confirm"] {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

#lineRemovalModal button[id*="confirm"]:hover {
  background: linear-gradient(135deg, #5a67d8 0%, #6b46c1 100%);
  box-shadow: 
    0 12px 32px rgba(102, 126, 234, 0.5),
    0 8px 16px rgba(102, 126, 234, 0.3);
}

/* ========================================
   CONNECTION MODAL STYLES
======================================== */
.connection-content {
  text-align: center;
  margin-bottom: 24px;
  padding: 0 8px;
}

.connection-content p {
  font-size: 18px;
  margin-bottom: 24px;
  color: #374151;
  font-weight: 500;
  line-height: 1.6;
}

.connection-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.connection-btn {
  padding: 20px 24px;
  font-size: 15px;
  font-weight: 600;
  border: 2px solid #667eea;
  background: #ffffff;
  color: #667eea;
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.connection-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.connection-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(102, 126, 234, 0.3);
  color: #ffffff;
}

.connection-btn:hover::before {
  opacity: 1;
}

.connection-btn:active {
  transform: translateY(1px) scale(0.98);
}

.connection-btn.line-only {
  border-color: #8b5cf6;
  color: #8b5cf6;
}

.connection-btn.line-only::before {
  background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
}

.connection-btn.line-only:hover {
  box-shadow: 0 8px 24px rgba(139, 92, 246, 0.3);
}

/* ========================================
   DESKTOP COMPACT OPTIMIZATION
======================================== */
@media (min-width: 769px) {
  .modal-content {
    max-width: 400px;
  }
  
  .modal-body {
    padding: 0 20px 8px;
  }
  
  .form-group {
    margin-bottom: 16px;
  }
  
  .form-group:last-of-type {
    margin-bottom: 20px;
  }
  
  .form-group input,
  .form-group select {
    padding: 12px 14px;
    font-size: 14px;
  }
  
  .searchable-select .select-input {
    padding: 12px 14px;
    font-size: 14px;
  }
  
  .gender-radio-option {
    padding: 14px 16px;
    min-height: 48px;
  }
  
  .gender-radio-option label {
    font-size: 14px;
  }
  
  .form-actions {
    padding: 16px 20px;
    gap: 10px;
  }
  
  .form-actions-right {
    gap: 10px;
  }
  
  .form-actions button {
    padding: 10px 20px;
    height: 40px;
    font-size: 13px;
    min-width: 90px;
  }
}

/* ========================================
   RESPONSIVE DESIGN - COMPACT MOBILE
======================================== */
@media (max-width: 768px) {
  /* Support for dynamic viewport height (mobile URL bar) */
  .modal {
    padding: 12px;
    align-items: flex-start;
    padding-top: max(16px, env(safe-area-inset-top));
    padding-bottom: max(40px, env(safe-area-inset-bottom, 40px));
    /* Use dvh when available, fallback to vh */
    height: 100dvh;
    height: 100vh;
    /* Ensure modal respects mobile URL bar */
    min-height: 100vh;
    min-height: 100dvh;
  }
  
  .modal-content {
    /* Account for URL bar and keyboard in mobile browsers */
    max-height: calc(100dvh - 96px);
    max-height: calc(100vh - 96px);
    max-height: calc(100svh - 96px); /* Small viewport height */
    width: 100%;
    max-width: none;
    margin: 0;
    border-radius: 12px;
    /* Ensure content doesn't get cut off */
    margin-bottom: 24px;
  }
  
  .modal-content h2 {
    font-size: 18px;
    padding: 16px 20px 12px;
  }
  
  .modal-content h2::after {
    left: 20px;
    right: 20px;
  }
  
  .modal-content h2 .person-icon {
    width: 24px;
    height: 24px;
    font-size: 11px;
    border-radius: 8px;
  }
  
  .modal-body {
    padding: 0 20px 4px;
  }
  
  /* COMPACT FORM GROUPS */
  .form-group { 
    margin-bottom: 18px;
  }
  
  .form-group:last-of-type {
    margin-bottom: 20px;
  }
  
  .form-group label {
    margin-bottom: 6px;
    font-size: 11px;
  }
  
  .form-group input, 
  .form-group select {
    padding: 12px 16px;
    font-size: 16px;
    border-radius: 12px;
  }
  
  /* COMPACT GENDER BUTTONS */
  .gender-radio-group {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 8px;
  }
  
  .gender-radio-option {
    padding: 12px 16px;
    min-height: 48px;
    border-radius: 12px;
  }
  
  .gender-radio-option label {
    font-size: 14px;
  }
  
  /* COMPACT HELP TEXT */
  .help-text {
    font-size: 11px;
    margin-top: 3px;
    padding: 4px 0;
  }
  
  /* COMPACT ACTIONS - ALL BUTTONS IN ONE ROW */
  .form-actions,
  .form-actions-enhanced {
    padding: 16px 20px !important;
    display: flex !important;
    flex-direction: row !important;
    justify-content: space-between !important;
    align-items: center !important;
    gap: 8px !important;
    grid-template-columns: none !important;
    margin-top: 0 !important;
    border-top: 1px solid #f1f5f9 !important;
  }
  
  .form-actions::before {
    left: 20px;
    right: 20px;
  }
  
  .form-actions-right {
    display: flex !important;
    flex-direction: row !important;
    gap: 8px !important;
    grid-column: unset !important;
    justify-self: unset !important;
    flex: 0 0 auto !important;
    justify-content: flex-end !important;
    width: auto !important;
  }
  
  /* COMPACT BUTTONS - ALL IN ONE ROW */
  .form-actions button {
    height: 44px !important;
    font-size: 13px !important;
    font-weight: 600;
    padding: 10px 16px !important;
    min-width: 80px !important;
    border-radius: 12px !important;
    flex-shrink: 0;
    margin: 0 !important;
  }
  
  /* Delete button - direct child of form-actions */
  .form-actions > button[id*="delete"] {
    flex: 0 0 auto;
    margin-right: auto !important;
  }
  
  /* Buttons inside form-actions-right */
  .form-actions-right button[id*="cancel"] {
    flex: 0 0 auto;
  }
  
  .form-actions-right button[id*="save"],
  .form-actions-right button[id*="apply"] {
    flex: 0 0 auto;
  }
  
  /* COMPACT CONNECTION BUTTONS */
  .connection-buttons {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .connection-btn {
    padding: 14px 20px;
    font-size: 15px;
    min-height: 50px;
    border-radius: 12px;
  }
  
  /* COMPACT SEARCHABLE SELECTS */
  .searchable-select .select-input {
    padding: 12px 16px;
    font-size: 16px;
    border-radius: 12px;
  }
}

@media (max-width: 480px) {
  .modal {
    padding: 8px;
    padding-top: max(12px, env(safe-area-inset-top));
    padding-bottom: max(50px, env(safe-area-inset-bottom, 50px));
    /* Use dvh when available, fallback to vh */
    height: 100dvh;
    height: 100vh;
    /* Ensure modal respects mobile URL bar */
    min-height: 100vh;
    min-height: 100dvh;
  }
  
  .modal-content {
    border-radius: 10px;
    /* Account for URL bar and keyboard in mobile browsers */
    max-height: calc(100dvh - 120px);
    max-height: calc(100vh - 120px);
    max-height: calc(100svh - 120px); /* Small viewport height */
    /* Ensure content doesn't get cut off */
    margin-bottom: 30px;
  }
  
  .modal-content h2 {
    font-size: 16px;
    padding: 14px 16px 10px;
  }
  
  .modal-content h2::after {
    left: 16px;
    right: 16px;
  }
  
  .modal-content h2 .person-icon {
    width: 20px;
    height: 20px;
    font-size: 10px;
    border-radius: 6px;
  }
  
  .modal-body {
    padding: 0 16px 4px;
  }
  
  /* EXTRA COMPACT FORM GROUPS */
  .form-group { 
    margin-bottom: 14px;
  }
  
  .form-group:last-of-type {
    margin-bottom: 16px;
  }
  
  .form-group label {
    margin-bottom: 5px;
    font-size: 10px;
  }
  
  .form-group input, 
  .form-group select {
    padding: 10px 14px;
    font-size: 16px;
    border-radius: 10px;
  }
  
  /* EXTRA COMPACT GENDER BUTTONS */
  .gender-radio-option {
    padding: 10px 14px;
    min-height: 42px;
    border-radius: 10px;
  }
  
  .gender-radio-option label {
    font-size: 13px;
  }
  
  /* EXTRA COMPACT ACTIONS */
  .form-actions,
  .form-actions-enhanced {
    padding: 12px 16px !important;
    gap: 6px !important;
    display: flex !important;
    flex-direction: row !important;
    justify-content: space-between !important;
    align-items: center !important;
  }
  
  .form-actions::before {
    left: 16px;
    right: 16px;
  }
  
  .form-actions-right {
    gap: 6px !important;
    display: flex !important;
    flex-direction: row !important;
    width: auto !important;
  }
  
  /* EXTRA COMPACT BUTTONS */
  .form-actions button {
    height: 40px !important;
    font-size: 12px !important;
    font-weight: 600;
    padding: 8px 12px !important;
    min-width: 70px !important;
    border-radius: 10px !important;
  }
  
  /* Delete button positioning for small screens */
  .form-actions > button[id*="delete"] {
    margin-right: auto !important;
  }
  
  /* COMPACT HELP TEXT */
  .help-text {
    font-size: 11px;
    padding: 5px 10px;
    border-radius: 6px;
  }
  
  /* COMPACT SEARCHABLE SELECTS */
  .searchable-select .select-input {
    padding: 10px 14px;
    border-radius: 10px;
  }
}

/* ========================================
   ENHANCED MODAL VARIANTS
======================================== */
.modal-enhanced {
  isolation: isolate;
  backdrop-filter: blur(16px);
  background: rgba(0, 0, 0, 0.8);
}

.modal-enhanced .modal-content {
  box-shadow: 
    0 32px 64px rgba(0, 0, 0, 0.25),
    0 16px 32px rgba(0, 0, 0, 0.15),
    0 0 0 1px rgba(255, 255, 255, 0.1);
}

.modal-open {
  overflow: hidden !important;
}

/* ========================================
   KEYBOARD SHORTCUTS HINT
======================================== */
.modal-content::after {
  content: 'Press ESC to close • TAB to navigate • ENTER to submit';
  position: absolute;
  bottom: -24px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: rgba(255, 255, 255, 0.7);
  background: rgba(0, 0, 0, 0.6);
  padding: 4px 12px;
  border-radius: 8px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 1;
}

/* ========================================
   ENHANCED FOCUS MANAGEMENT
======================================== */
.modal-open {
  overflow: hidden !important;
}

.modal[aria-hidden="false"] {
  display: flex;
}

.modal[aria-hidden="true"] {
  display: none;
}

/* Trap focus within modal */
.modal-content {
  isolation: isolate;
}

.modal-content:focus-within {
  outline: none;
}

/* Enhanced tab order */
.form-group input[tabindex="1"],
.form-group select[tabindex="1"] {
  outline-color: #667eea;
  outline-width: 3px;
  outline-style: solid;
  outline-offset: 2px;
}

/* ========================================
   ACCESSIBILITY & MOTION
======================================== */
@media (prefers-reduced-motion: reduce) {
  .modal,
  .modal-content,
  .form-actions button,
  .gender-radio-option,
  .form-group input,
  .form-group select,
  .form-group {
    animation: none !important;
    transition: none !important;
  }
  
  .form-actions button::before,
  .modal-content h2 .person-icon::before {
    display: none;
  }
  
  .warning-icon,
  .info-icon {
    animation: none !important;
  }
}

@media (prefers-contrast: high) {
  .modal-content {
    border: 2px solid #000000;
  }
  
  .form-actions {
    border-top: 2px solid #000000;
  }
  
  .form-group input,
  .form-group select,
  .gender-radio-option {
    border-width: 2px;
  }
}

/* ========================================
   FOCUS IMPROVEMENTS
======================================== */
.form-actions button:focus-visible,
.form-group input:focus-visible,
.form-group select:focus-visible,
.gender-radio-option:focus-visible {
  outline: 3px solid #667eea;
  outline-offset: 2px;
  z-index: 1;
}

.gender-radio-option input[type="radio"]:focus-visible {
  outline: 2px solid #667eea;
  outline-offset: 2px;
}

/* ========================================
   SHAPE OPTIONS STYLES
======================================== */
.shape-options {
  margin: 1rem 0;
  padding: 1rem;
  background: rgba(15, 134, 108, 0.05);
  border-radius: 8px;
  border: 1px solid rgba(15, 134, 108, 0.2);
}

.shape-help {
  margin: 0.5rem 0;
  padding: 0.75rem;
  background: rgba(52, 152, 219, 0.1);
  border-radius: 6px;
  border-left: 4px solid #3498db;
  font-size: 0.9rem;
  color: #2c3e50;
  line-height: 1.4;
}

.setting-info {
  margin-top: 1rem;
  padding: 0.75rem;
  background: rgba(149, 165, 166, 0.1);
  border-radius: 6px;
  font-size: 0.85rem;
  color: #7f8c8d;
  line-height: 1.4;
  border-left: 3px solid #95a5a6;
}

.btn-secondary {
  background: linear-gradient(135deg, #95a5a6 0%, #7f8c8d 100%);
  color: white;
  border: none;
  padding: 0.6rem 1.2rem;
  border-radius: 6px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  position: relative;
  overflow: hidden;
}

.btn-secondary:hover {
  background: linear-gradient(135deg, #7f8c8d 0%, #6c7b7d 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(127, 140, 141, 0.3);
}

.btn-secondary:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(127, 140, 141, 0.4);
}

.btn-secondary:disabled {
  background: #bdc3c7;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}