/**
 * CuliUptime Shared Components CSS
 * Reusable UI components for consistency across pages
 */

/* Import Inter font once for all components */
@import url('../fonts/inter.css');

/* CSS Variables for consistency */
:root {
  /* CuliUptime Brand Colors */
  --culiuptime-primary: #066fd1;
  --culiuptime-success: #2fb344;
  --culiuptime-warning: #f59f00;
  --culiuptime-danger: #d63939;
  --culiuptime-info: #4299e1;

  /* Agent Health Colors */
  --agent-health-excellent: var(--culiuptime-success);
  --agent-health-good: var(--culiuptime-warning);
  --agent-health-poor: var(--culiuptime-danger);

  /* Spacing */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;

  /* Font family */
  --tblr-font-sans-serif: 'Inter Var', Inter, -apple-system, BlinkMacSystemFont, San Francisco, Segoe UI, Roboto, Helvetica Neue, sans-serif;
}

/* Global font family override */
body {
  font-family: var(--tblr-font-sans-serif);
}

/* Shared Component Classes */

/* Agent Health Status */
.agent-health-excellent { color: var(--agent-health-excellent); }
.agent-health-good { color: var(--agent-health-good); }
.agent-health-poor { color: var(--agent-health-poor); }

/* Agent Location Flag */
.agent-location-flag {
  width: 20px;
  height: 15px;
  margin-right: var(--spacing-sm);
  border-radius: 2px;
  object-fit: cover;
}

/* Status Indicators */
.status-dot-animated::before {
  animation: status-pulse 2s infinite;
}

@keyframes status-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Enhanced status dots for better visibility */
.status-dot {
  display: inline-block;
  border-radius: 50%;
  min-width: 8px;
  min-height: 8px;
}

.status-dot.bg-success {
  background-color: var(--tblr-success, #2fb344) !important;
  box-shadow: 0 0 0 2px rgba(47, 179, 68, 0.2);
}

.status-dot.bg-danger {
  background-color: var(--tblr-danger, #d63939) !important;
  box-shadow: 0 0 0 2px rgba(214, 57, 57, 0.2);
}

.status-dot.bg-warning {
  background-color: var(--tblr-warning, #f59f00) !important;
  box-shadow: 0 0 0 2px rgba(245, 159, 0, 0.2);
}

/* Enhanced status badges for agent management */
.badge.bg-danger-lt {
  background-color: rgba(214, 57, 57, 0.1) !important;
  border: 1px solid rgba(214, 57, 57, 0.2);
}

.badge.text-danger {
  color: var(--tblr-danger, #d63939) !important;
  font-weight: 600;
}

.badge.bg-success {
  background-color: var(--tblr-success, #2fb344) !important;
  color: white !important;
  font-weight: 600;
}

.badge.bg-warning {
  background-color: var(--tblr-warning, #f59f00) !important;
  color: var(--tblr-dark, #1d273b) !important;
  font-weight: 600;
}

/* Loading States */
.loading-spinner {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border: 2px solid transparent;
  border-top: 2px solid currentColor;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Cards */
.card-stats {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card-stats:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Buttons */
.btn-action {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-xs);
  transition: all 0.2s ease;
}

.btn-action:hover {
  transform: translateY(-1px);
}

/* Form Validation */
.validation-status {
  margin-top: var(--spacing-sm);
  padding: var(--spacing-sm);
  border-radius: 6px;
  font-size: 0.875rem;
}

.validation-status.validation-success {
  color: var(--culiuptime-success);
  background-color: rgba(47, 179, 68, 0.1);
  border: 1px solid rgba(47, 179, 68, 0.2);
}

.validation-status.validation-error {
  color: var(--culiuptime-danger);
  background-color: rgba(214, 57, 57, 0.1);
  border: 1px solid rgba(214, 57, 57, 0.2);
}

.validation-status.validation-loading {
  color: var(--culiuptime-info);
  background-color: rgba(66, 153, 225, 0.1);
  border: 1px solid rgba(66, 153, 225, 0.2);
}

/* Legacy aliases for backward compatibility */
.validation-status.success {
  color: var(--culiuptime-success);
  background-color: rgba(47, 179, 68, 0.1);
  border: 1px solid rgba(47, 179, 68, 0.2);
}

.validation-status.error {
  color: var(--culiuptime-danger);
  background-color: rgba(214, 57, 57, 0.1);
  border: 1px solid rgba(214, 57, 57, 0.2);
}

.validation-status.loading {
  color: var(--culiuptime-info);
  background-color: rgba(66, 153, 225, 0.1);
  border: 1px solid rgba(66, 153, 225, 0.2);
}

/* Responsive Table Improvements */
@media (max-width: 768px) {
  .table-responsive-mobile {
    font-size: 0.8rem;
  }

  .table-responsive-mobile .d-none-mobile {
    display: none !important;
  }
}

/* Page Loading Overlay */
.page-loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.page-loading.hidden {
  display: none;
}

/* Utility Classes */
.text-muted-light { opacity: 0.7; }
.text-muted-strong { opacity: 0.8; }

/* Animations */
.fade-in {
  animation: fadeIn 0.3s ease-in;
}

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

/* Error States */
.error-state {
  text-align: center;
  padding: var(--spacing-xl);
  color: var(--culiuptime-danger);
}

.empty-state {
  text-align: center;
  padding: var(--spacing-xl);
  color: rgba(0, 0, 0, 0.5);
}

/* Toast Notifications (for future use) */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 1050;
}

.toast {
  margin-bottom: var(--spacing-sm);
  min-width: 300px;
}

/* Shared Navigation Components */
.culiuptime-nav {
  /* Navigation container styling */
}

.culiuptime-nav .nav-item.active .nav-link {
  background-color: var(--culiuptime-primary);
  color: white;
}

.culiuptime-nav .nav-link:hover:not(.active) {
  background-color: rgba(var(--culiuptime-primary-rgb), 0.1);
}

/* User Avatar Dropdown */
.user-avatar-dropdown .dropdown-header {
  background-color: var(--tblr-bg-surface-secondary);
}

.user-avatar-dropdown .dropdown-item:hover {
  background-color: var(--tblr-bg-surface-tertiary);
}

/* Page Header Components */
.page-header-actions {
  display: flex;
  gap: var(--spacing-sm);
  align-items: center;
}

.page-header-breadcrumb {
  margin-bottom: var(--spacing-sm);
}

/* Card Header Actions */
.card-header-actions {
  margin-left: auto;
  display: flex;
  gap: var(--spacing-xs);
}

/* Shared Table Styles */
.data-table {
  /* Common table styling */
}

.data-table .table-avatar {
  width: 2.5rem;
  height: 2.5rem;
  margin-right: var(--spacing-sm);
}

.data-table .table-actions {
  white-space: nowrap;
}

.data-table .table-status {
  min-width: 80px;
}

/* Shared Form Styles */
.form-section {
  padding: var(--spacing-lg);
  border-bottom: 1px solid var(--tblr-border-color);
}

.form-section:last-child {
  border-bottom: none;
}

.form-section-title {
  margin-bottom: var(--spacing-md);
  color: var(--tblr-body-color);
  font-weight: 600;
}

/* Shared Modal Styles */
.modal-loading {
  text-align: center;
  padding: var(--spacing-xl);
}

.modal-error {
  color: var(--culiuptime-danger);
  background-color: rgba(214, 57, 57, 0.1);
  padding: var(--spacing-md);
  border-radius: 6px;
  margin: var(--spacing-sm) 0;
}

/* Shared Metric Cards */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--spacing-md);
  margin-bottom: var(--spacing-lg);
}

.metric-card {
  padding: var(--spacing-lg);
  background: var(--tblr-card-bg);
  border: 1px solid var(--tblr-border-color);
  border-radius: 8px;
  text-align: center;
  transition: all 0.2s ease;
}

.metric-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.metric-card .metric-icon {
  font-size: 1.5rem;
  margin-bottom: var(--spacing-sm);
}

.metric-card .metric-value {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: var(--spacing-xs);
}

.metric-card .metric-label {
  color: var(--tblr-body-color-secondary);
  font-size: 0.875rem;
}

/* Agent Detail Page Styles */
.agent-hero {
  background: linear-gradient(135deg, var(--tblr-primary) 0%, var(--tblr-primary-dark) 100%);
  color: white;
}

.agent-hero .text-secondary {
  color: rgba(255, 255, 255, 0.7) !important;
}

/* Better contrast for pending status hero card */
.agent-hero.status-pending {
  color: var(--tblr-dark, #1d273b) !important;
}

.agent-hero.status-pending .text-secondary {
  color: rgba(29, 39, 59, 0.7) !important;
}

/* Ensure warning status badge is visible on warning background */
.agent-hero .status.status-warning {
  background-color: rgba(255, 255, 255, 0.9) !important;
  color: var(--tblr-warning-dark, #f59f00) !important;
  border: 1px solid rgba(255, 255, 255, 0.5);
  font-weight: 600;
}

.agent-hero .status.status-warning .status-dot {
  background-color: var(--tblr-warning-dark, #f59f00) !important;
}

/* Ensure success status badge is visible on success background */
.agent-hero .status.status-success {
  background-color: rgba(255, 255, 255, 0.9) !important;
  color: var(--tblr-success-dark, #2fb344) !important;
  border: 1px solid rgba(255, 255, 255, 0.5);
  font-weight: 600;
}

.agent-hero .status.status-success .status-dot {
  background-color: var(--tblr-success-dark, #2fb344) !important;
}

.protocol-badge {
  display: inline-flex;
  align-items: center;
  margin: 0.125rem;
  font-size: 0.75rem;
  font-weight: 500;
}

/* Enhanced Active Agent Styling */
.agent-status-active {
  box-shadow: 0 0 0 2px rgba(47, 179, 68, 0.2);
  animation: active-pulse 3s ease-in-out infinite;
}

@keyframes active-pulse {
  0%, 100% {
    box-shadow: 0 0 0 2px rgba(47, 179, 68, 0.2);
  }
  50% {
    box-shadow: 0 0 0 4px rgba(47, 179, 68, 0.1);
  }
}

.agent-avatar-active {
  box-shadow: 0 0 0 3px rgba(47, 179, 68, 0.3);
  animation: avatar-glow 4s ease-in-out infinite;
}

@keyframes avatar-glow {
  0%, 100% {
    box-shadow: 0 0 0 3px rgba(47, 179, 68, 0.3);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(47, 179, 68, 0.15);
  }
}

/* Active agent row highlighting */
tr:has(.agent-status-active) {
  background-color: rgba(47, 179, 68, 0.03) !important;
  border-left: 3px solid var(--tblr-success);
}

tr:has(.agent-status-active):hover {
  background-color: rgba(47, 179, 68, 0.05) !important;
}

/* Enhanced success badges for active agents */
.badge.bg-success-subtle {
  background-color: rgba(47, 179, 68, 0.1) !important;
  border: 1px solid rgba(47, 179, 68, 0.2);
  font-weight: 600;
}

.text-success-emphasis {
  color: var(--tblr-success-darker, #1a6329) !important;
  font-weight: 600;
}

/* Live indicator styling */
.fs-7 {
  font-size: 0.75rem !important;
}

/* Active agent dropdown styling */
.dropdown-toggle.btn-success:focus {
  box-shadow: 0 0 0 0.25rem rgba(47, 179, 68, 0.25);
}

.dropdown-menu .dropdown-item-text {
  padding: 0.5rem 1rem;
  margin-bottom: 0;
  font-size: 0.875rem;
  color: var(--tblr-secondary);
}

/* Active status metrics in dropdown */
.dropdown-menu .dropdown-item-text .icon {
  opacity: 0.7;
}

/* HMAC Authentication Styling */
.hmac-auth-section {
  border-left: 3px solid var(--tblr-primary);
  padding-left: 1rem;
}

.hmac-auth-section.configured {
  border-left-color: var(--tblr-success);
}

.hmac-auth-section.not-configured {
  border-left-color: var(--tblr-warning);
}

/* Security badge styling */
.badge.security-status {
  font-weight: 600;
  padding: 0.375rem 0.75rem;
}

.badge.security-status.secured {
  background-color: rgba(47, 179, 68, 0.1) !important;
  color: var(--tblr-success-darker, #1a6329) !important;
  border: 1px solid rgba(47, 179, 68, 0.2);
}

.badge.security-status.not-secured {
  background-color: rgba(245, 159, 0, 0.1) !important;
  color: var(--tblr-warning-darker, #c7930a) !important;
  border: 1px solid rgba(245, 159, 0, 0.2);
}

/* HMAC Modal Styling */
.hmac-modal .modal-content {
  border: 1px solid var(--tblr-primary);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}

.hmac-modal .modal-header {
  background-color: var(--tblr-primary-light);
  border-bottom: 1px solid var(--tblr-primary);
}

.hmac-modal .modal-header .modal-title {
  color: var(--tblr-primary-darker);
  font-weight: 600;
}

/* Code block styling for PHP configuration */
.hmac-modal pre code {
  background-color: var(--tblr-dark);
  color: var(--tblr-light);
  padding: 1rem;
  border-radius: 6px;
  font-family: 'JetBrains Mono', 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  font-size: 0.875rem;
  line-height: 1.4;
}

/* Input group styling for credentials */
.hmac-credentials-input .form-control {
  font-family: 'JetBrains Mono', 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  font-size: 0.875rem;
  letter-spacing: 0.5px;
}

.hmac-credentials-input .btn {
  border-left: 1px solid var(--tblr-border-color);
}

/* Authentication status indicators */
.auth-status-indicator {
  position: relative;
  padding-left: 1.5rem;
}

.auth-status-indicator::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--tblr-secondary);
}

.auth-status-indicator.secured::before {
  background-color: var(--tblr-success);
  animation: status-pulse 2s infinite;
}

.auth-status-indicator.not-secured::before {
  background-color: var(--tblr-warning);
}

/* Enhanced security alert styling */
.security-alert {
  border-left: 4px solid var(--tblr-info);
  background-color: rgba(66, 153, 225, 0.05);
  padding: 1rem 1.5rem;
  margin-bottom: 1rem;
}

.security-alert .alert-icon {
  color: var(--tblr-info);
  margin-right: 0.75rem;
  flex-shrink: 0;
}

.security-alert h4 {
  color: var(--tblr-info-darker);
  margin-bottom: 0.5rem;
  font-weight: 600;
}

/* Copy button animations */
.copy-btn {
  transition: all 0.2s ease;
}

.copy-btn:hover {
  background-color: var(--tblr-primary);
  color: white;
  transform: translateY(-1px);
}

.copy-btn.copied {
  background-color: var(--tblr-success);
  color: white;
}

.copy-btn.copied::after {
  content: 'Copied!';
  position: absolute;
  top: -2rem;
  left: 50%;
  transform: translateX(-50%);
  background-color: var(--tblr-dark);
  color: white;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  white-space: nowrap;
  z-index: 1000;
}

/* Responsive improvements for large monitors */
@media (min-height: 800px) {
  /* Standard large monitors (1080p+) */
  .page-wrapper {
    min-height: calc(100vh - 60px); /* Account for navbar height */
  }

  .page-body {
    padding-top: 2rem;
    padding-bottom: 2rem;
  }

  .card {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  }
}

@media (min-height: 1000px) {
  /* Tall monitors (1440p+) */
  .page-body {
    padding-top: 3rem;
    padding-bottom: 3rem;
  }

  .container-xl {
    max-width: 1400px; /* Prevent excessive stretching on ultra-wide */
  }

  .card {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  }

  .card-body {
    padding: 1.5rem;
  }
}

@media (min-height: 1200px) {
  /* Very tall monitors (4K, ultrawide vertical) */
  .page-body {
    padding-top: 4rem;
    padding-bottom: 4rem;
  }

  .card {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
  }

  .card-body {
    padding: 2rem;
  }

  .page-header {
    padding-top: 2rem;
    padding-bottom: 2rem;
  }
}

/* Width-based responsive improvements for ultra-wide monitors */
@media (min-width: 1600px) {
  .container-xl {
    max-width: 1500px;
  }

  /* Prevent excessive card stretching on ultra-wide displays */
  .row-deck .col-sm-6.col-lg-3 {
    flex: 0 0 20%; /* 5 cards per row on ultra-wide */
    max-width: 20%;
  }

  /* Dashboard-specific override: maintain 4-card layout for optimal spacing */
  .row-deck.dashboard-stats-row .col-sm-6.col-lg-3 {
    flex: 0 0 25%; /* Keep 4 cards per row */
    max-width: 25%;
  }
}

@media (min-width: 2000px) {
  .container-xl {
    max-width: 1600px;
  }

  /* Even more columns on 4K+ displays */
  .row-deck .col-sm-6.col-lg-3 {
    flex: 0 0 16.666667%; /* 6 cards per row */
    max-width: 16.666667%;
  }

  /* Dashboard-specific override: maintain 4-card layout for optimal spacing */
  .row-deck.dashboard-stats-row .col-sm-6.col-lg-3 {
    flex: 0 0 25%; /* Keep 4 cards per row */
    max-width: 25%;
  }
}

/* Combined width + height optimizations for premium displays */
@media (min-width: 1400px) and (min-height: 1000px) {
  .page-body {
    padding: 4rem 0;
  }

  .page-header {
    padding: 2.5rem 0;
  }

  .card-body {
    padding: 2rem;
  }

  /* Better spacing for large displays */
  .row-deck {
    --tblr-gutter-y: 2rem;
  }
}

/* Page loading spinner optimization for tall displays */
.d-flex.justify-content-center.align-items-center[style*="minHeight"] {
  min-height: 60vh !important;
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .agent-status-active,
  .agent-avatar-active {
    animation: none !important;
  }
}
