/* Port Manager Component Styles */

/* Basic/Advanced toggle — when the .show-advanced class isn't on the
   .port-manager root, fields tagged .port-field-advanced collapse out so
   the basic view stays simple. */
.port-manager:not(.show-advanced) .port-field-advanced { display: none; }

.port-manager-header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.port-manager-advanced-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 13px;
  color: var(--text-secondary, #a0a0a0);
  cursor: pointer;
  user-select: none;
}

.port-manager-advanced-toggle input { margin: 0; }

/* Ensure help icons are always visible in port manager */
.port-manager .help-icon {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 14px !important;
  height: 14px !important;
  background: var(--primary-color) !important;
  color: white !important;
  border-radius: 50% !important;
  font-size: 9px !important;
  font-weight: bold !important;
  cursor: help !important;
  position: relative !important;
  opacity: 1 !important;
  visibility: visible !important;
}

/* Custom speech bubble tooltip for port manager */
.port-manager .help-icon:hover::after {
  content: attr(title);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--card-bg, #2a2a2a);
  color: var(--text-primary, #fff);
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  text-transform: none; /* Ensure normal case */
  white-space: nowrap;
  max-width: 200px;
  white-space: normal;
  z-index: 99999;
  border: 2px solid var(--primary-color, var(--accent));
}

/* Speech bubble triangle pointing down */
.port-manager .help-icon:hover::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 1px);
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid var(--card-bg, #2a2a2a);
  z-index: 100000;
}

/* Enhanced tooltips for main config help icons */
.help-icon:hover::after {
  content: attr(title);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--card-bg, #2a2a2a);
  color: var(--text-primary, #fff);
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  text-transform: none; /* Ensure normal case */
  white-space: nowrap;
  max-width: 200px;
  white-space: normal;
  z-index: 99999;
  border: 2px solid var(--primary-color, var(--accent));
}

/* Speech bubble triangle for main config */
.help-icon:hover::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 1px);
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid var(--card-bg, #2a2a2a);
  z-index: 100000;
}

/* Auto-match indicator styling */
.auto-match-indicator {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 14px !important;
  height: 14px !important;
  background: var(--status-success) !important;
  color: white !important;
  border-radius: 50% !important;
  font-size: 9px !important;
  font-weight: bold !important;
  cursor: help !important;
  position: relative !important;
  margin-left: 4px !important;
  opacity: 0 !important;
  visibility: hidden !important;
  transition: all 0.2s ease !important;
}

.auto-match-indicator[style*="display: inline-flex"] {
  opacity: 1 !important;
  visibility: visible !important;
}

/* Auto-match indicator tooltip */
.auto-match-indicator:hover::after {
  content: attr(title);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--status-success);
  color: var(--text-primary);
  padding: 6px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  text-transform: none;
  white-space: nowrap;
  min-width: 160px;
  text-align: center;
  z-index: 99999;
  border: 2px solid var(--accent);
}

/* Auto-match indicator triangle */
.auto-match-indicator:hover::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 1px);
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid var(--status-success);
  z-index: 100000;
}

/* Ensure form fields allow tooltips to overflow */
.form-field {
  overflow: visible !important;
}

.panel-fields {
  overflow: visible !important;
}

/* Hide form field labels for port manager containers */
.form-field[id^="PORT_"] .form-label {
  display: none;
}

.form-field[id^="PORT_"] .form-help {
  display: none;
}

/* Hide the entire port field containers except the first one */
.form-field[id^="PORT_"]:not(:first-of-type) {
  display: none !important;
}

/* Override panel-fields layout for port managers specifically */
div.panel-fields > div.form-field[id^="PORT_"] {
  grid-column: 1 / -1 !important;
  width: 100% !important;
}

/* Target the new full-width class */
.panel-fields .form-field:has(.port-manager-full-width) {
  grid-column: 1 / -1 !important;
  width: 100% !important;
}

/* Alternative targeting */
.panel-fields .form-field[id^="PORT_"] {
  grid-column: 1 / -1 !important; /* Make form fields with PORT_ IDs span full width */
}

.panel-fields .port-manager-container {
  width: 100%; /* Ensure full width */
}

.port-manager {
  margin: 0px 0;
}

.port-manager-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--primary-color, var(--accent));
}

.port-manager-header h4 {
  margin: 0;
  color: var(--text-primary, #fff);
  font-size: 18px;
  font-weight: 600;
}

.add-port-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 14px;
  background: var(--primary-color, var(--accent));
  color: var(--text-primary);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.add-port-btn:hover {
  background: var(--primary-color-hover, var(--accent));
  transform: translateY(-1px);
}

.add-icon {
  font-size: 16px;
  font-weight: bold;
}

.port-manager-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: visible; /* Allow tooltips to escape */
}

/* Port card border colors based on access type */
.port-card[data-access="public"] {
  border-color: var(--status-success); /* Green for public */
  box-shadow: 0 0 0 1px var(--status-success);
}

.port-card[data-access="private"] {
  border-color: var(--status-warning); /* Orange for private */
  box-shadow: 0 0 0 1px var(--status-warning);
}

.port-card[data-access="disabled"] {
  border-color: var(--status-danger); /* Red for disabled */
  box-shadow: 0 0 0 1px var(--status-danger);
}

/* Hover effects maintain the access color theme */
.port-card[data-access="public"]:hover {
  border-color: var(--accent);
}

.port-card[data-access="private"]:hover {
  border-color: var(--status-warning);
}

.port-card[data-access="disabled"]:hover {
  border-color: var(--status-danger);
}

/* Default fallback */
.port-card {
  background: var(--card-bg, #2a2a2a);
  border: 1px solid var(--border-color, #444);
  border-radius: 8px;
  overflow: visible; /* Changed from hidden to allow tooltips to escape */
  transition: all 0.2s ease;
  margin-bottom: 16px;
}

.port-card:hover {
  border-color: var(--primary-color, var(--accent));
}

.port-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: rgba(var(--text-rgb), 0.05);
  border-bottom: 1px solid rgba(var(--text-rgb), 0.10);
  border-radius: 8px 8px 0 0;
}

.port-card-title {
  font-weight: 600;
  color: var(--text-secondary, #ccc);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.remove-port-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: var(--status-danger);
  color: var(--text-primary);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 12px;
  font-weight: bold;
}

.remove-port-btn:hover {
  background: var(--status-danger-hover);
  transform: scale(1.1);
}

.remove-icon {
  line-height: 1;
}

.port-card-body {
  padding: 16px;
  overflow: visible; /* Allow tooltips to escape */
}

.port-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.port-row:last-child {
  margin-bottom: 0;
}

.port-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.port-field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary, #ccc);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.port-field input,
.port-field select {
  padding: 8px 12px;
  background: var(--input-bg, #3a3a3a);
  border: 1px solid var(--border-color, #555);
  border-radius: 4px;
  color: var(--text-primary, #fff);
  font-size: 14px;
  transition: all 0.2s ease;
}

.port-field input:focus,
.port-field select:focus {
  outline: none;
  border-color: var(--primary-color, var(--accent));
  box-shadow: 0 0 0 2px rgba(var(--accent-rgb), 0.2);
}

.port-field input[type="checkbox"] {
  width: auto;
  margin: 0;
  transform: scale(1.2);
}

.port-manager-hidden {
  display: none;
}

/* Modal Styles */
.port-manager-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(var(--bg-rgb), 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.port-manager-modal {
  background: var(--card-bg, #2a2a2a);
  border: 1px solid var(--border-color, #444);
  border-radius: 8px;
  max-width: 400px;
  width: 90%;
  max-height: 90vh;
  overflow: auto;
}

.port-manager-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color, #444);
}

.port-manager-modal-header h3 {
  margin: 0;
  color: var(--text-primary, #fff);
  font-size: 18px;
  font-weight: 600;
}

.port-manager-modal-close {
  background: none;
  border: none;
  color: var(--text-secondary, #ccc);
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.port-manager-modal-close:hover {
  background: var(--hover-bg, #444);
  color: var(--text-primary, #fff);
}

.port-manager-modal-body {
  padding: 20px;
}

.port-manager-modal-body p {
  margin: 0;
  color: var(--text-primary, #fff);
  line-height: 1.5;
}

.port-manager-modal-footer {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  padding: 16px 20px;
  border-top: 1px solid var(--border-color, #444);
}

/* Responsive Design */
@media (max-width: 768px) {
  .port-manager-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .port-row {
    grid-template-columns: 1fr;
  }

  .port-manager-modal {
    width: 95%;
    margin: 20px;
  }

  .port-manager-modal-footer {
    flex-direction: column;
  }

  .port-manager-modal-footer button {
    width: 100%;
  }
}

/* Button Styles (reuse existing) */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-primary {
  background: var(--primary-color, var(--accent));
  color: var(--text-primary);
}

.btn-primary:hover {
  background: var(--primary-color-hover, var(--accent));
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--secondary-color, var(--text-muted));
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: var(--secondary-color-hover, var(--text-muted));
}

.btn-danger {
  background: var(--status-danger);
  color: var(--text-primary);
}

.btn-danger:hover {
  background: var(--status-danger-hover);
}

.btn-sm {
  padding: 4px 8px;
  font-size: 12px;
}

.btn-xs {
  padding: 2px 6px;
  font-size: 11px;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .port-manager-modal-overlay {
    background: rgba(var(--bg-rgb), 0.8);
  }
}

/* Manual dark mode class support */
body.dark .port-manager-modal-overlay,
[data-theme="dark-blue"],
[data-theme="nebula"] .port-manager-modal-overlay,
.dark .port-manager-modal-overlay {
  background: rgba(var(--bg-rgb), 0.8);
}
