/* ==========================================
   Base Styles & Reset
   ========================================== */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  line-height: 1.6;
  color: #1f2937;
  background-color: #f9fafb;
  min-height: 100vh;
}

/* ==========================================
   Layout
   ========================================== */

main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem;
}

header {
  text-align: center;
  margin-bottom: 2rem;
}

h1 {
  font-size: 2rem;
  font-weight: 700;
  color: #111827;
  margin-bottom: 0.5rem;
}

.subtitle {
  font-size: 1.125rem;
  color: #6b7280;
}

/* ==========================================
   Filter Controls
   ========================================== */

.filter-panel {
  position: relative;
  background-color: white;
  border-radius: 8px;
  padding: 1.5rem;
  margin-bottom: 2rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  
  /* Add grid layout for collapse transition */
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
  transition: grid-template-rows 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Collapsed state */
.filter-panel.collapsed {
  grid-template-rows: auto 0fr;
}

/* Filter header - flexbox container for h2 and icons */
.filter-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  gap: 1rem;
  min-width: 0;
}

.filter-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
  color: #111827;
  flex: 1 1 0%;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin: 0;
  padding-right: 0;
}

/* Icon wrapper - groups fullscreen and collapse icons */
.filter-header-icons {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
  align-items: center;
}

/* Filter content wrapper - required for CSS Grid 0fr/1fr transitions */
.filter-content {
  min-height: 0;
  overflow: hidden;
}

/* Collapse toggle button */
.collapse-toggle {
  position: relative;
  cursor: pointer;
  padding: 8px;
  border: none;
  background: transparent;
  color: #374151;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  min-height: 40px;
  flex-shrink: 0;
  border-radius: 4px;
  transition: background-color 0.2s ease, opacity 0.2s ease;
}

.collapse-toggle:hover {
  background-color: rgba(0, 0, 0, 0.05);
}

.collapse-toggle:active {
  background-color: rgba(0, 0, 0, 0.1);
}

.collapse-toggle:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

.collapse-toggle:focus:not(:focus-visible) {
  outline: none;
}

.collapse-toggle:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

/* Chevron icon rotation */
.chevron-icon {
  width: 16px;
  height: 16px;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  transform: rotate(0deg);
  transform-origin: center;
  pointer-events: none;
}

.collapse-toggle[aria-expanded="false"] .chevron-icon {
  transform: rotate(180deg);
}

/* Fullscreen icon - update for flexbox layout */
#fullscreen-toggle {
  position: relative;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  padding: 8px;
  border: none;
  background: transparent;
  color: #374151;
  cursor: pointer;
  border-radius: 4px;
  transition: background-color 0.2s ease;
}

#fullscreen-toggle:hover {
  background-color: rgba(0, 0, 0, 0.05);
}

#fullscreen-toggle:active {
  background-color: rgba(0, 0, 0, 0.1);
}

#fullscreen-toggle:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

#fullscreen-toggle:focus:not(:focus-visible) {
  outline: none;
}

#fullscreen-toggle:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

/* Tooltip styles for collapse and fullscreen icons */
.collapse-toggle::before,
#fullscreen-toggle::before {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background-color: rgba(0, 0, 0, 0.8);
  color: #fff;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.875rem;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  margin-bottom: 0.5rem;
  z-index: 1000;
}

.collapse-toggle::after,
#fullscreen-toggle::after {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: rgba(0, 0, 0, 0.8);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  margin-bottom: 0.25rem;
  z-index: 1000;
}

.collapse-toggle:hover::before,
.collapse-toggle:hover::after,
#fullscreen-toggle:hover::before,
#fullscreen-toggle:hover::after {
  opacity: 1;
}

.collapse-toggle:focus::before,
.collapse-toggle:focus::after,
#fullscreen-toggle:focus::before,
#fullscreen-toggle:focus::after {
  opacity: 0;
}

/* Accessibility: prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  .filter-panel {
    transition: none;
  }
  
  .chevron-icon {
    transition: none;
  }
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .filter-header {
    gap: 0.75rem;
  }
  
  .filter-header h2 {
    font-size: 1.125rem;
  }
  
  .filter-header-icons {
    gap: 0.375rem;
  }
  
  .collapse-toggle,
  #fullscreen-toggle {
    min-width: 44px;
    min-height: 44px;
  }
}

@media (max-width: 480px) {
  .filter-header h2 {
    font-size: 1rem;
    max-width: 60%;
  }
}

.filter-group {
  margin-bottom: 1rem;
}

.filter-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: #374151;
  margin-bottom: 0.25rem;
}

.filter-group select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  color: #1f2937;
  background-color: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.filter-group select:hover {
  border-color: #9ca3af;
}

.filter-group select:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.filter-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid #e5e7eb;
}

.btn-secondary {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: #374151;
  background-color: #f3f4f6;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.2s, border-color 0.2s;
}

.btn-secondary:hover {
  background-color: #e5e7eb;
  border-color: #9ca3af;
}

.btn-secondary:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

.filter-status {
  font-size: 0.875rem;
  color: #6b7280;
  font-style: italic;
}

/* ==========================================
   Network Container
   ========================================== */

#network-container {
  width: 100%;
  height: 600px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background-color: #ffffff;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}

/* ==========================================
   Loading Indicator
   ========================================== */

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid #e5e7eb;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading p {
  margin-top: 1rem;
  font-size: 1rem;
  color: #6b7280;
}

/* ==========================================
   Error Message
   ========================================== */

.error {
  text-align: center;
  padding: 3rem;
  background-color: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
}

.error h2 {
  font-size: 1.5rem;
  color: #991b1b;
  margin-bottom: 1rem;
}

.error p {
  font-size: 1rem;
  color: #7f1d1d;
  margin-bottom: 1.5rem;
}

.btn-primary {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  color: #ffffff;
  background-color: #3b82f6;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.btn-primary:hover {
  background-color: #2563eb;
}

.btn-primary:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

/* ==========================================
   Utility Classes
   ========================================== */

.hidden {
  display: none !important;
}

.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;
}

/* ==========================================
   NoScript Message
   ========================================== */

.noscript-message {
  max-width: 600px;
  margin: 4rem auto;
  padding: 2rem;
  text-align: center;
  background-color: #fef3c7;
  border: 1px solid #fbbf24;
  border-radius: 8px;
}

.noscript-message h1 {
  font-size: 1.5rem;
  color: #78350f;
  margin-bottom: 1rem;
}

.noscript-message p {
  font-size: 1rem;
  color: #92400e;
  margin-bottom: 0.5rem;
}

/* ==========================================
   Network Visualization Enhancements
   ========================================== */

/* Additional visual cues for colorblind users */
/* vis-network will apply these through node groups */
.vis-network canvas {
  border-radius: 8px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  #network-container {
    border-width: 2px;
    border-color: #000000;
  }
}

/* Cursor states for interaction */
#network-container canvas {
  cursor: default;
}

#network-container canvas:active {
  cursor: grab;
}

#network-container canvas.dragging {
  cursor: grabbing;
}

/* Focus indicators for selected elements */
#network-container:focus-within {
  outline: 3px solid #3b82f6;
  outline-offset: -3px;
}

/* ==========================================
   Accessibility
   ========================================== */

/* Focus visible for keyboard navigation */
*:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

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

/* ==========================================
   Responsive Design
   ========================================== */

@media (max-width: 768px) {
  main {
    padding: 1rem;
  }

  h1 {
    font-size: 1.5rem;
  }

  .subtitle {
    font-size: 1rem;
  }

  .filter-panel {
    padding: 1rem;
  }

  .filter-panel h2 {
    font-size: 1.125rem;
  }

  .filter-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .btn-secondary {
    width: 100%;
  }

  .filter-status {
    text-align: center;
    margin-top: 0.5rem;
  }

  #network-container {
    height: 500px;
  }
}

/* ==========================================
   Fullscreen Toggle Icon
   ========================================== */

.fullscreen-icon {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 10;
  width: 40px;
  height: 40px;
  background-color: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

.fullscreen-icon svg {
  fill: #374151;
  transition: fill 0.2s ease;
}

.fullscreen-icon:hover {
  background-color: rgba(255, 255, 255, 1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.fullscreen-icon:hover svg {
  fill: #1f2937;
}

.fullscreen-icon:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

.fullscreen-icon:active {
  transform: scale(0.95);
}

/* 
.fullscreen-icon {
  position: relative;
}
*/

/* Tooltip */

.fullscreen-icon::before {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  background-color: rgba(0, 0, 0, 0.85);
  color: white;
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 14px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.fullscreen-icon:hover::before,
.fullscreen-icon:focus::before {
  opacity: 1;
}

/* Tooltip arrow */
.fullscreen-icon::after {
  content: '';
  position: absolute;
  bottom: calc(100% + 2px);
  right: 8px;
  border: 6px solid transparent;
  border-top-color: rgba(0, 0, 0, 0.85);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.fullscreen-icon:hover::after,
.fullscreen-icon:focus::after {
  opacity: 1;
}

/* Respect user preference for reduced motion */
@media (prefers-reduced-motion: reduce) {
  .fullscreen-icon,
  .fullscreen-icon svg,
  .fullscreen-icon::before,
  .fullscreen-icon::after {
    transition: none;
  }
}

/* Responsive scaling for small screens */
@media (max-width: 768px) {
  .fullscreen-icon {
    width: 44px;
    height: 44px;
  }
  
  .fullscreen-icon svg {
    width: 26px;
    height: 26px;
  }
}
