/*
 * Thesis Grey - Custom CSS
 * Built on Bootstrap 5.3.0
 * Provides project-specific styles and customizations
 */

/* =============================================================================
   Root Variables - Agent Grey Theme Colors
   ============================================================================= */
:root {
  /* Agent Grey Brand Colors - Following Style Guide */
  --tg-primary: #0A2D45;
  --tg-primary-dark: #071e2f;
  --tg-primary-light: #00A0A0;

  /* Secondary Colors */
  --tg-secondary: #7B8794;
  --tg-secondary-dark: #5a6470;
  --tg-secondary-light: #E4E6E8;

  /* Accent Colors */
  --tg-accent: #00A0A0;
  --tg-accent-dark: #007d7d;
  --tg-accent-light: #4dcccc;

  /* Status Colors - Agent Grey Aligned */
  --tg-success: #2E8540;
  --tg-warning: #F6A623;
  --tg-danger: #D72638;
  --tg-info: #0A2D45;

  /* Neutral Colors */
  --tg-light: #F9F9F7;
  --tg-dark: #0A2D45;
  --tg-muted: #7B8794;

  /* Layout */
  --tg-border-radius: 0.375rem;
  --tg-border-width: 1px;
  --tg-box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
  --tg-box-shadow-lg: 0 1rem 3rem rgba(0, 0, 0, 0.175);
}

/* =============================================================================
   Base Styles
   ============================================================================= */
body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.6;
  color: var(--tg-dark);
  background-color: var(--tg-light);
}

/* =============================================================================
   Navigation Customizations
   ============================================================================= */
.navbar-brand {
  font-weight: 700;
  font-size: 1.5rem;
  color: white !important;
}

.navbar-nav .nav-link {
  font-weight: 500;
  transition: color 0.15s ease-in-out;
  color: rgba(255, 255, 255, 0.8) !important;
}

.navbar-nav .nav-link:hover {
  color: var(--tg-accent) !important;
}

/* =============================================================================
   Card Components
   ============================================================================= */
.card {
  border: var(--tg-border-width) solid rgba(0, 0, 0, 0.125);
  border-radius: var(--tg-border-radius);
  box-shadow: var(--tg-box-shadow);
  transition: box-shadow 0.15s ease-in-out;
}

.card:hover {
  box-shadow: var(--tg-box-shadow-lg);
}

.card-header {
  background-color: rgba(var(--bs-primary-rgb), 0.1);
  border-bottom: var(--tg-border-width) solid rgba(var(--bs-primary-rgb), 0.2);
  font-weight: 600;
}

/* =============================================================================
   Button Customizations
   ============================================================================= */
.btn {
  font-weight: 500;
  border-radius: var(--tg-border-radius);
  transition: all 0.15s ease-in-out;
}

.btn-primary {
  background-color: var(--tg-info);
  border-color: var(--tg-info);
}

.btn-primary:hover {
  background-color: #071e2f;
  border-color: #071e2f;
}

.btn-outline-primary {
  color: var(--tg-info);
  border-color: var(--tg-info);
}

.btn-outline-primary:hover {
  background-color: var(--tg-info);
  border-color: var(--tg-info);
  color: white;
}

/* =============================================================================
   Form Elements
   ============================================================================= */
.form-control {
  border-radius: var(--tg-border-radius);
  border: var(--tg-border-width) solid #ced4da;
  transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.form-control:focus {
  border-color: var(--tg-primary-light);
  box-shadow: 0 0 0 0.2rem rgba(var(--bs-primary-rgb), 0.25);
}

.form-label {
  font-weight: 600;
  color: var(--tg-dark);
  margin-bottom: 0.5rem;
}

.form-text {
  color: var(--tg-muted);
  font-size: 0.875rem;
}

/* =============================================================================
   Alert Components
   ============================================================================= */
.alert {
  border-radius: var(--tg-border-radius);
  border-width: var(--tg-border-width);
}

.alert-success {
  background-color: rgba(var(--bs-success-rgb), 0.1);
  border-color: rgba(var(--bs-success-rgb), 0.2);
  color: var(--tg-success);
}

.alert-danger {
  background-color: rgba(var(--bs-danger-rgb), 0.1);
  border-color: rgba(var(--bs-danger-rgb), 0.2);
  color: var(--tg-danger);
}

.alert-warning {
  background-color: rgba(var(--bs-warning-rgb), 0.1);
  border-color: rgba(var(--bs-warning-rgb), 0.2);
  color: #664d03;
}

.alert-info {
  background-color: rgba(var(--bs-info-rgb), 0.1);
  border-color: rgba(var(--bs-info-rgb), 0.2);
  color: var(--tg-info);
}

/* =============================================================================
   Table Components
   ============================================================================= */
.table {
  border-radius: var(--tg-border-radius);
  overflow: hidden;
}

.table thead th {
  background-color: var(--tg-light);
  border-bottom: 2px solid var(--tg-primary);
  font-weight: 600;
  color: var(--tg-dark);
}

.table tbody tr:hover {
  background-color: rgba(var(--bs-primary-rgb), 0.05);
}

/* =============================================================================
   Pagination
   ============================================================================= */
.pagination .page-link {
  color: var(--tg-primary);
  border-color: #dee2e6;
  border-radius: var(--tg-border-radius);
}

.pagination .page-link:hover {
  background-color: var(--tg-primary-light);
  color: white;
}

.pagination .page-item.active .page-link {
  background-color: var(--tg-primary);
  border-color: var(--tg-primary);
}

/* =============================================================================
   Badge Components
   ============================================================================= */
.badge {
  font-weight: 500;
  border-radius: var(--tg-border-radius);
}

/* =============================================================================
   Layout Utilities
   ============================================================================= */
.content-wrapper {
  min-height: calc(100vh - 160px); /* Account for navbar + footer */
}

.section-header {
  border-bottom: 2px solid var(--tg-primary);
  padding-bottom: 0.5rem;
  margin-bottom: 1.5rem;
}

.section-header h1,
.section-header h2,
.section-header h3 {
  color: var(--tg-primary);
  margin-bottom: 0;
}

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

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

/* =============================================================================
   Footer Styles
   ============================================================================= */
footer {
  margin-top: auto;
}

footer p {
  margin-bottom: 0;
  font-size: 0.875rem;
  opacity: 0.8;
}

/* =============================================================================
   Responsive Utilities
   ============================================================================= */
@media (max-width: 768px) {
  .container {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .navbar-brand {
    font-size: 1.25rem;
  }

  .card {
    margin-bottom: 1rem;
  }
}

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

/* Focus indicators */
.btn:focus,
.form-control:focus,
.form-select:focus,
.form-check-input:focus {
  outline: 2px solid var(--tg-primary);
  outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  :root {
    --tg-primary: #0000ff;
    --tg-secondary: #000000;
    --tg-success: #008000;
    --tg-danger: #ff0000;
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  :root {
    --tg-light: #212529;
    --tg-dark: #f8f9fa;
  }

  body {
    background-color: var(--tg-dark);
    color: var(--tg-light);
  }
}

/* =============================================================================
   Print Styles
   ============================================================================= */
@media print {
  .navbar,
  .btn,
  footer {
    display: none;
  }

  .card {
    border: 1px solid #000;
    box-shadow: none;
  }

  .container {
    max-width: none;
  }
}

/* =============================================================================
   Progress Bars - Agent Grey Amber Gold
   ============================================================================= */
.progress-bar {
  background-color: var(--tg-warning) !important;
  color: var(--tg-primary) !important;
}

.session-progress .progress-bar {
  background-color: var(--tg-warning) !important;
  color: var(--tg-primary) !important;
}

/* Override Bootstrap progress bar variants */
.progress-bar.bg-primary {
  background-color: var(--tg-warning) !important;
  color: var(--tg-primary) !important;
}

/* =============================================================================
   Tag Input Validation & Feedback Styles
   ============================================================================= */

/* Pending input visual feedback */
.keyword-input.has-pending-input {
  border: 2px solid #ffc107 !important;
  background-color: #fff9e6;
  animation: pulse-warning 1.5s ease-in-out infinite;
}

@keyframes pulse-warning {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 193, 7, 0.4); }
  50% { box-shadow: 0 0 0 4px rgba(255, 193, 7, 0.1); }
}

.pending-input-warning {
  position: absolute;
  bottom: -25px;
  left: 0;
  color: #856404;
  background-color: #fff3cd;
  border: 1px solid #ffeaa7;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 1000;
}

.pending-input-warning i {
  color: #ffc107;
}

/* Domain count badge */
.badge.badge-info {
  font-size: 11px;
  vertical-align: super;
  margin-left: 4px;
}

/* Enhanced tag styling with animation */
.keyword-tag {
  animation: tag-appear 0.2s ease-out;
}

@keyframes tag-appear {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.keyword-tag.removing {
  animation: tag-remove 0.2s ease-out forwards;
}

@keyframes tag-remove {
  to {
    opacity: 0;
    transform: scale(0.5);
  }
}

/* Domain validation error styling */
.domain-validation-error {
  position: absolute;
  bottom: -25px;
  left: 0;
  color: #721c24;
  background-color: #f8d7da;
  border: 1px solid #f5c6cb;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 1000;
}

.domain-validation-error i {
  color: #dc3545;
}

/* Ensure keyword-input-container has relative positioning */
.keyword-input-container {
  position: relative;
}

/* =============================================================================
   Utility Classes
   ============================================================================= */
.cursor-pointer {
  cursor: pointer;
}

/* =============================================================================
   Real-Time Execution Feed Styles
   ============================================================================= */
.query-text-container {
  position: relative;
}

.query-text-display {
  font-family: "Menlo", "Monaco", "Courier New", monospace;
  font-size: 0.9em;
  line-height: 1.6;
  max-height: 160px;
  overflow-y: auto;
  word-break: break-word;
  white-space: pre-wrap;
}

.query-text-display code {
  background: transparent;
  color: inherit;
}

.copy-query-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  opacity: 0.75;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.copy-query-btn:hover {
  opacity: 1;
  transform: translateY(-1px);
}

.copy-query-btn:focus {
  opacity: 1;
  outline: 2px solid #0d6efd;
  outline-offset: 2px;
}

.query-operator {
  color: #0d6efd;
  font-weight: 600;
}

.query-filetype {
  color: #fd7e14;
  font-weight: 600;
}

.highlight-update {
  animation: highlightPulse 0.35s ease;
}

@keyframes highlightPulse {
  0%,
  100% {
    color: inherit;
    transform: scale(1);
  }
  50% {
    color: #198754;
    font-weight: 600;
    transform: scale(1.08);
  }
}

.timeline {
  position: relative;
  padding-left: 0;
}

.timeline-item {
  position: relative;
  padding-left: 42px;
  padding-bottom: 20px;
  border-left: 2px solid #e9ecef;
}

.timeline-item:last-child {
  border-left: none;
}

.timeline-marker {
  position: absolute;
  left: -13px;
  top: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 4px #fff;
}

.timeline-content {
  background: #f8f9fa;
  border-left: 3px solid #198754;
  border-radius: 8px;
  padding: 12px;
}

.query-preview {
  display: block;
  max-width: 420px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fade-in {
  animation: fadeIn 0.4s ease-in forwards;
  opacity: 0;
}

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

#page-progress-bar {
  transition: width 0.3s ease;
}

#query-page-badge {
  transition: all 0.3s ease;
}

#execution-feed-container {
  animation: slideIn 0.35s ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 768px) {
  .query-text-display {
    font-size: 0.8em;
    max-height: 120px;
  }

  .timeline-item {
    padding-left: 34px;
  }

  .timeline-marker {
    left: -11px;
    width: 20px;
    height: 20px;
  }

  .query-preview {
    max-width: 260px;
  }
}
