/**
 * Custom Forms CSS
 * Unified styling for all form elements across ShowMyIP tools
 * Includes responsive design and accessibility improvements
 */

/* Main form container */
.custom-form {
  max-width: 700px;
  margin: 20px auto;
  padding: 0 15px;
}

/* Form control enhancements */
.custom-form .form-control {
  border-radius: 4px;
  border-color: #ddd;
  padding: 12px;
  font-size: 16px;
  line-height: 1.5;
  color: #474747;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.custom-form .form-control:focus {
  border-color: #f15a23;
  box-shadow: 0 0 0 0.2rem rgba(241, 90, 35, 0.25);
  outline: 2px solid #f15a23; /* Enhanced focus outline for accessibility */
}

.custom-form .form-control::placeholder {
  color: #767676; /* WCAG 2.1 AA compliant contrast for placeholder text */
  opacity: 1; /* Ensure placeholder is visible for screen readers */
}

/* Labels */
.custom-form .form-label {
  display: block;
  font-weight: 600;
  color: #474747;
  margin-bottom: 0.5rem;
  font-size: 16px;
}

/* Required field indication */
.custom-form .form-label.required::after {
  content: " *";
  color: #d9534f;
}

/* Button styling */
.custom-form .btn {
  padding: 10px 18px;
  font-size: 16px;
  border-radius: 4px;
  font-weight: 500;
  transition: all 0.3s ease;
  min-height: 44px; /* Ensure touch target size for accessibility */
}

.custom-form .btn-primary {
  background-color: #f15a23;
  border-color: #f15a23;
  color: #fff; /* Ensure contrast */
}

.custom-form .btn-primary:hover,
.custom-form .btn-primary:focus {
  background-color: #d64a1a;
  border-color: #d64a1a;
  color: #fff;
  outline: 2px solid #d64a1a; /* Enhanced focus outline */
}

.custom-form .btn-secondary {
  background-color: #6c757d;
  border-color: #6c757d;
  color: #fff; /* Ensure contrast */
}

.custom-form .btn-secondary:hover,
.custom-form .btn-secondary:focus {
  background-color: #5a6268;
  border-color: #545b62;
  color: #fff;
  outline: 2px solid #545b62; /* Enhanced focus outline */
}

.custom-form .btn-sm {
  padding: 0.25rem 0.5rem;
  font-size: 0.875rem;
  min-height: 32px; /* Smaller but still accessible */
}

/* Focus visible enhancement for keyboard users */
.custom-form button:focus-visible,
.custom-form input:focus-visible,
.custom-form select:focus-visible,
.custom-form textarea:focus-visible {
  outline: 3px solid #2196f3;
  outline-offset: 2px;
  z-index: 9;
}

/* Form groups */
.custom-form .form-group {
  margin-bottom: 1.25rem;
}

/* Input groups */
.custom-form .input-group {
  display: flex;
  width: 100%;
}

.custom-form .input-group .form-control {
  flex: 1;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.custom-form .input-group-append {
  display: flex;
}

.custom-form .input-group-append .btn {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  display: flex;
  align-items: center;
}

/* Form helpers */
.custom-form .form-text {
  color: #6c757d;
  font-size: 0.875rem;
  margin-top: 0.25rem;
}

/* Error messages - improved accessibility */
.custom-form .error-message {
  color: #d9534f;
  font-size: 0.875rem;
  margin-top: 0.25rem;
  font-weight: 500;
}

/* Field validation states */
.custom-form .is-invalid {
  border-color: #d9534f;
}

.custom-form .is-valid {
  border-color: #5cb85c;
}

/* ARIA support for invalid fields */
.custom-form .form-control[aria-invalid="true"] {
  border-color: #d9534f;
}

/* Check/Radio controls */
.custom-form .form-check {
  padding-left: 1.5rem;
  margin-bottom: 0.5rem;
}

.custom-form .form-check-input {
  margin-left: -1.5rem;
  margin-top: 0.3rem;
  float: left;
  min-width: 18px; /* Ensure toggle controls are large enough to tap */
  min-height: 18px;
}

.custom-form .form-check-label {
  margin-bottom: 0;
  cursor: pointer;
}

/* Custom file input */
.custom-form .custom-file {
  position: relative;
  display: inline-block;
  width: 100%;
  height: calc(1.5em + 0.75rem + 2px);
}

.custom-form .custom-file-input {
  position: relative;
  z-index: 2;
  width: 100%;
  height: calc(1.5em + 0.75rem + 2px);
  margin: 0;
  opacity: 0;
}

.custom-form .custom-file-label {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  z-index: 1;
  height: calc(1.5em + 0.75rem + 2px);
  padding: 0.375rem 0.75rem;
  font-weight: 400;
  line-height: 1.5;
  color: #495057;
  background-color: #fff;
  border: 1px solid #ced4da;
  border-radius: 0.25rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custom-form .custom-file-input:focus ~ .custom-file-label {
  border-color: #f15a23;
  box-shadow: 0 0 0 0.2rem rgba(241, 90, 35, 0.25);
}

/* Form switches (toggle switches) */
.custom-form .form-switch {
  padding-left: 2.5rem;
}

.custom-form .form-switch .form-check-input {
  width: 2rem;
  margin-left: -2.5rem;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='rgba%280, 0, 0, 0.25%29'/%3e%3c/svg%3e");
  background-position: left center;
  border-radius: 2rem;
  transition: background-position .15s ease-in-out;
}

.custom-form .form-switch .form-check-input:checked {
  background-position: right center;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%23fff'/%3e%3c/svg%3e");
}

/* Alert messages within forms */
.custom-form .alert {
  padding: 0.75rem 1.25rem;
  margin-bottom: 1rem;
  border: 1px solid transparent;
  border-radius: 0.25rem;
}

.custom-form .alert-danger {
  color: #721c24;
  background-color: #f8d7da;
  border-color: #f5c6cb;
}

.custom-form .alert-warning {
  color: #856404;
  background-color: #fff3cd;
  border-color: #ffeeba;
}

.custom-form .alert-success {
  color: #155724;
  background-color: #d4edda;
  border-color: #c3e6cb;
}

/* Copy button */
.custom-form .copy-btn {
  background-color: #f8f9fa;
  border: 1px solid #ddd;
  color: #495057;
  padding: 4px 8px;
  font-size: 0.9em;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  margin-left: 5px;
  display: inline-flex;
  align-items: center;
}

.custom-form .copy-btn:hover {
  background-color: #e9ecef;
  border-color: #c6c8ca;
}

/* Form tabs */
.custom-form .form-tabs {
  display: flex;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.custom-form .tab-btn {
  padding: 8px 16px;
  background: #f5f5f5;
  border: 1px solid #ddd;
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  margin-right: 4px;
  cursor: pointer;
  position: relative;
  transition: all 0.2s;
}

.custom-form .tab-btn.active {
  background: #fff;
  border-bottom: 1px solid #fff;
  margin-bottom: -1px;
  font-weight: 600;
}

.custom-form .tab-content {
  display: none;
  padding: 15px;
  border: 1px solid #ddd;
  border-radius: 0 4px 4px 4px;
}

.custom-form .tab-content.active {
  display: block;
}

/* Loading indicator */
.custom-form .loading-indicator {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  text-align: center;
}

.custom-form .loading-indicator img {
  max-width: 50px;
}

/* Results container */
.results-container {
  margin-top: 1.5rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

/* Network Analysis Tool Specific Styles */

/* Terminal-like output for command results */
.network-terminal {
  background-color: #222;
  color: #f8f8f8;
  font-family: 'Courier New', monospace;
  border-radius: 4px;
  padding: 15px;
  margin-bottom: 1rem;
  overflow-x: auto;
  white-space: pre-wrap;
  line-height: 1.5;
  min-height: 100px;
  max-height: 400px;
  overflow-y: auto;
}

.network-terminal.with-header {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

.network-terminal-header {
  background-color: #333;
  color: #f8f8f8;
  font-family: 'Courier New', monospace;
  border-top-left-radius: 4px;
  border-top-right-radius: 4px;
  padding: 8px 15px;
  font-weight: bold;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Network terminal colors */
.terminal-success {
  color: #5cb85c;
}

.terminal-error {
  color: #d9534f;
}

.terminal-warning {
  color: #f0ad4e;
}

.terminal-info {
  color: #5bc0de;
}

.terminal-timestamp {
  color: #aaa;
  font-size: 0.9em;
}

.terminal-hostname {
  color: #f15a23;
  font-weight: bold;
}

.terminal-ip {
  color: #5cb85c;
  font-weight: bold;
}

/* Result item for traceroute/ping entries */
.network-result-item {
  display: flex;
  padding: 8px 0;
  border-bottom: 1px solid #444;
}

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

.hop-number {
  width: 40px;
  text-align: center;
  font-weight: bold;
  color: #f15a23;
}

.hop-address {
  flex: 1;
}

.hop-time {
  width: 80px;
  text-align: right;
  color: #aaa;
}

/* Progress indicators for network tools */
.network-progress {
  height: 8px;
  width: 100%;
  background-color: #eee;
  border-radius: 4px;
  margin: 10px 0;
  overflow: hidden;
}

.network-progress-bar {
  height: 100%;
  background-color: #f15a23;
  transition: width 0.3s ease;
}

/* Network stats display */
.network-stats {
  display: flex;
  flex-wrap: wrap;
  margin: 15px 0;
}

.network-stat-item {
  flex: 1;
  min-width: 120px;
  margin: 5px;
  padding: 10px;
  background-color: #f8f8f8;
  border-radius: 4px;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.network-stat-value {
  font-size: 1.5rem;
  font-weight: bold;
  color: #474747;
  display: block;
}

.network-stat-label {
  font-size: 0.9rem;
  color: #6c757d;
  display: block;
}

/* Speed test gauge */
.speed-gauge-container {
  text-align: center;
  margin: 20px 0;
  position: relative;
}

.speed-gauge {
  width: 200px;
  height: 100px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

.speed-gauge-arc {
  position: absolute;
  width: 200px;
  height: 200px;
  top: 0;
  border-radius: 50%;
  border: 10px solid #eee;
  border-top: 10px solid #f15a23;
  border-right: 10px solid #f15a23;
  transform: rotate(45deg);
  box-sizing: border-box;
}

.speed-gauge-value {
  position: absolute;
  bottom: 0;
  width: 100%;
  text-align: center;
  font-size: 1.8rem;
  font-weight: bold;
}

.speed-gauge-units {
  font-size: 1rem;
  color: #6c757d;
}

/* Responsive adjustments */
@media (max-width: 767px) {
  .custom-form {
    max-width: 100%;
    padding: 0 10px;
    margin: 15px auto;
  }

  .custom-form .form-control {
    padding: 10px;
    font-size: 14px;
  }

  .custom-form .form-label {
    font-size: 14px;
  }

  .custom-form .btn {
    padding: 8px 14px;
    font-size: 14px;
    min-height: 40px;
  }

  .custom-form .input-group {
    flex-direction: column;
  }

  .custom-form .input-group .form-control {
    border-radius: 4px;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    width: 100%;
  }

  .custom-form .input-group-append .btn {
    border-radius: 4px;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    width: 100%;
  }

  .custom-form .form-check {
    padding-left: 1.2rem;
  }

  .custom-form .form-check-input {
    margin-left: -1.2rem;
  }

  .results-container table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
  
  /* Network tool specific responsive adjustments */
  .network-stat-item {
    min-width: 100px;
    padding: 8px;
  }
  
  .network-stat-value {
    font-size: 1.2rem;
  }
  
  .speed-gauge {
    width: 150px;
    height: 75px;
  }
  
  .speed-gauge-arc {
    width: 150px;
    height: 150px;
  }
  
  .speed-gauge-value {
    font-size: 1.4rem;
  }
}

/* Accessibility helpers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* High contrast mode support */
@media (forced-colors: active) {
  .custom-form .btn-primary,
  .custom-form .btn-secondary,
  .custom-form .btn {
    forced-color-adjust: none;
  }
  
  .custom-form .form-control:focus,
  .custom-form button:focus-visible,
  .custom-form input:focus-visible {
    outline: 3px solid CanvasText;
    outline-offset: 2px;
  }
}

/**
 * Tool-Specific Extensions
 * These styles handle edge cases and tool-specific requirements 
 * while maintaining visual consistency with the standard form styling
 */

/* ----- File Upload Forms ----- */
/* Used in bulk-ip-lookup.php and other tools with file upload capabilities */
.custom-form .custom-file {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  margin-bottom: 1rem;
}

.custom-form .custom-file-input {
  position: relative;
  z-index: 2;
  width: 100%;
  height: calc(1.5em + 0.75rem + 2px);
  margin: 0;
  opacity: 0;
}

.custom-form .custom-file-label {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  z-index: 1;
  height: calc(1.5em + 0.75rem + 2px);
  padding: 0.375rem 0.75rem;
  font-weight: 400;
  line-height: 1.5;
  color: #474747;
  background-color: #fff;
  border: 1px solid #ddd;
  border-radius: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custom-form .custom-file-input:focus ~ .custom-file-label {
  border-color: #f15a23;
  box-shadow: 0 0 0 0.2rem rgba(241, 90, 35, 0.25);
  outline: 2px solid #f15a23;
}

/* ----- Form Helpers ----- */
/* Small utility buttons that appear beneath the main form inputs */
/* Used in ip-whois-lookup.php and similar tools */
.custom-form .form-helpers {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.custom-form .form-helpers .btn {
  padding: 0.25rem 0.5rem;
  font-size: 0.875rem;
}

/* ----- Advanced Options Toggle ----- */
/* Used in ping.php and other tools with collapsible option sections */
.custom-form .advanced-options-toggle {
  margin: 1rem 0;
  text-align: left;
}

.custom-form .advanced-options-toggle a {
  display: inline-flex;
  align-items: center;
  color: #474747;
  font-weight: 500;
  text-decoration: none;
  font-size: 0.95rem;
}

.custom-form .advanced-options-toggle a:hover {
  color: #f15a23;
}

.custom-form .advanced-options-toggle i {
  transition: transform 0.3s ease;
  margin-left: 0.3rem;
  font-size: 0.75rem;
}

.custom-form .advanced-options-toggle a.active i {
  transform: rotate(180deg);
}

.custom-form .advanced-options {
  display: none;
  background-color: rgba(0, 0, 0, 0.02);
  border-radius: 4px;
  padding: 1rem;
  margin-bottom: 1rem;
}

/* Grid layout for option groups within advanced options */
.custom-form .options-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.custom-form .option-group {
  margin-bottom: 0.5rem;
}

.custom-form .checkbox-group {
  display: flex;
  align-items: center;
  margin-top: 1.5rem;
}

/* ----- Loading Indicators ----- */
/* Standardized loading indicator for AJAX requests */
/* Used across multiple tools */
.custom-form-loading,
#loading {
  text-align: center;
  margin: 1.5rem 0;
}

.custom-form-loading p,
#loading p {
  margin-bottom: 0.5rem;
  color: #474747;
  font-weight: 500;
}

.progress-bar {
  height: 4px;
  background-color: #f0f0f0;
  border-radius: 2px;
  overflow: hidden;
  margin: 0.5rem 0;
}

.progress-bar .progress {
  height: 100%;
  background-color: #f15a23;
  width: 0;
  animation: progress-animation 2s ease-in-out infinite;
}

@keyframes progress-animation {
  0% { width: 0; }
  50% { width: 70%; }
  100% { width: 100%; }
}

/* ----- Multi-tab Forms ----- */
/* Used in bulk-ip-lookup.php */
.custom-form .form-tabs {
  display: flex;
  margin-bottom: 1rem;
  border-bottom: 1px solid #dee2e6;
}

.custom-form .tab-btn {
  background: none;
  border: none;
  padding: 0.5rem 1rem;
  font-weight: 500;
  color: #6c757d;
  cursor: pointer;
  margin-bottom: -1px;
}

.custom-form .tab-btn.active {
  color: #f15a23;
  border-bottom: 2px solid #f15a23;
}

.custom-form .tab-content {
  display: none;
  padding: 1rem 0;
}

.custom-form .tab-content.active {
  display: block;
}

/* File format and limit information text */
.custom-form .file-format-info,
.custom-form .limit-info {
  font-size: 0.85rem;
  color: #6c757d;
  margin-bottom: 1rem;
}

/* ----- Button Groups ----- */
/* Used in bulk-ip-lookup.php and other tools with multiple action buttons */
.custom-form .button-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

/* ----- Responsive Adjustments for Tool-Specific Extensions ----- */
@media (max-width: 767px) {
  .custom-form .options-grid {
    grid-template-columns: 1fr;
  }
  
  .custom-form .button-group {
    flex-direction: column;
    width: 100%;
  }
  
  .custom-form .button-group .btn {
    width: 100%;
    margin-bottom: 0.5rem;
  }
  
  .custom-form .form-helpers {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .custom-form .form-helpers .btn {
    width: 100%;
  }
} 