/**
 * Knowledge Map Visualization Styles
 * Styling for the interactive knowledge graph
 */

/* ==========================================================================
   Container & Layout
   ========================================================================== */

.kg-container {
  display: flex;
  width: 100%;
  height: 70vh;
  min-height: 500px;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  overflow: hidden;
  background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
}

.kg-graph-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-width: 0;  /* Prevent flex overflow */
  min-height: 400px;  /* Ensure minimum height */
  width: calc(100% - 280px);  /* Account for sidebar */
}

.kg-svg {
  width: 100%;
  height: 100%;
  cursor: grab;
}

.kg-svg:active {
  cursor: grabbing;
}

/* ==========================================================================
   Nodes
   ========================================================================== */

.kg-node {
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease;
}

.kg-node:hover,
.kg-node.kg-node-hover {
  transform: scale(1.15);
}

.kg-node.kg-node-selected {
  filter: drop-shadow(0 0 8px var(--current-part-color, #2C3E50));
}

.kg-node.kg-node-dim {
  opacity: 0.25;
}

.kg-node-label {
  pointer-events: none;
  user-select: none;
}

/* Indicators */
.kg-indicator {
  pointer-events: none;
}

/* ==========================================================================
   Edges
   ========================================================================== */

.kg-edge {
  fill: none;
  pointer-events: none;
  transition: stroke-opacity 0.15s ease, stroke-width 0.15s ease;
}

.kg-edge-prerequisite {
  stroke: #E74C3C;
}

.kg-edge-next {
  stroke: #3498DB;
}

.kg-edge-related {
  stroke: #95A5A6;
}

.kg-edge-parent-child {
  stroke: #BDC3C7;
}

.kg-edge.kg-edge-highlight {
  stroke-opacity: 0.9 !important;
  stroke-width: 3px !important;
}

.kg-edge.kg-edge-dim {
  stroke-opacity: 0.1 !important;
}

/* ==========================================================================
   Tooltip
   ========================================================================== */

.kg-tooltip {
  position: fixed;
  display: none;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  padding: 16px;
  max-width: 320px;
  z-index: 10000;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.kg-tooltip-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.kg-tooltip-part {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.kg-tooltip-difficulty {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: #f0f0f0;
  color: #666;
}

.kg-difficulty-beginner {
  background: #D5F4E6;
  color: #1E8449;
}

.kg-difficulty-intermediate {
  background: #FEF5E7;
  color: #B7950B;
}

.kg-difficulty-advanced {
  background: #FADBD8;
  color: #922B21;
}

.kg-tooltip-title {
  margin: 0 0 8px 0;
  font-size: 15px;
  font-weight: 600;
  color: #2C3E50;
}

.kg-tooltip-desc {
  margin: 0 0 12px 0;
  color: #666;
  font-size: 13px;
}

.kg-tooltip-meta {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: #888;
  margin-bottom: 12px;
}

.kg-tooltip-objectives {
  margin-bottom: 12px;
  padding: 8px;
  background: #f8f9fa;
  border-radius: 4px;
}

.kg-tooltip-objectives strong {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  color: #666;
}

.kg-tooltip-objectives ul {
  margin: 0;
  padding-left: 18px;
  font-size: 12px;
  color: #555;
}

.kg-tooltip-objectives li {
  margin-bottom: 2px;
}

.kg-tooltip-actions {
  padding-top: 8px;
  border-top: 1px solid #eee;
}

.kg-tooltip-actions a {
  color: var(--current-part-color, #2C3E50);
  text-decoration: none;
  font-weight: 500;
}

.kg-tooltip-actions a:hover {
  text-decoration: underline;
}

/* ==========================================================================
   Sidebar
   ========================================================================== */

.kg-sidebar {
  width: 280px;
  min-width: 280px;
  background: #fafafa;
  border-left: 1px solid #e0e0e0;
  display: flex;
  flex-direction: column;
  transition: width 0.3s ease, min-width 0.3s ease;
  position: relative;
}

.kg-sidebar.kg-sidebar-collapsed {
  width: 40px;
  min-width: 40px;
}

.kg-sidebar.kg-sidebar-collapsed .kg-sidebar-content {
  display: none;
}

.kg-sidebar-toggle {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 24px;
  height: 24px;
  border: none;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  cursor: pointer;
  font-size: 12px;
  z-index: 10;
}

.kg-sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 40px 12px 12px;
}

.kg-sidebar-section {
  margin-bottom: 16px;
}

.kg-sidebar-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: #888;
  margin-bottom: 8px;
}

/* Search */
.kg-search-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.kg-search-input:focus {
  border-color: var(--current-part-color, #2C3E50);
}

/* View Buttons */
.kg-view-buttons {
  display: flex;
  gap: 4px;
}

.kg-view-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px;
  border: 1px solid #ddd;
  background: #fff;
  border-radius: 6px;
  font-size: 10px;
  cursor: pointer;
  transition: all 0.2s;
  color: #666;
}

.kg-view-btn:hover {
  border-color: #999;
}

.kg-view-btn.active {
  background: var(--current-part-color, #2C3E50);
  border-color: var(--current-part-color, #2C3E50);
  color: #fff;
}

.kg-view-btn svg {
  width: 20px;
  height: 20px;
}

/* Collapsible Sections */
.kg-sidebar-collapsible .kg-section-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: #888;
}

.kg-section-toggle {
  font-size: 10px;
}

.kg-sidebar-collapsible.collapsed .kg-section-content {
  display: none;
}

/* Filter Items */
.kg-filter-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 13px;
  cursor: pointer;
}

.kg-filter-item input[type="checkbox"] {
  margin: 0;
}

.kg-part-color {
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.kg-select-all-btn {
  display: inline-block;
  padding: 4px 8px;
  margin-right: 4px;
  margin-top: 8px;
  border: 1px solid #ddd;
  background: #fff;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
}

.kg-select-all-btn:hover {
  background: #f0f0f0;
}

/* Difficulty Badges */
.kg-difficulty-badge {
  font-size: 10px;
}

.kg-difficulty-badge.kg-difficulty-beginner { color: #27AE60; }
.kg-difficulty-badge.kg-difficulty-intermediate { color: #F39C12; }
.kg-difficulty-badge.kg-difficulty-advanced { color: #E74C3C; }

/* Zoom Controls */
.kg-zoom-controls {
  display: flex;
  gap: 4px;
}

.kg-zoom-btn {
  width: 32px;
  height: 32px;
  border: 1px solid #ddd;
  background: #fff;
  border-radius: 6px;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.2s;
}

.kg-zoom-btn:hover {
  background: #f0f0f0;
}

/* Legend */
.kg-legend-items {
  font-size: 12px;
}

.kg-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  color: #666;
}

.kg-legend-shape {
  width: 16px;
  text-align: center;
}

.kg-legend-circle { color: #27AE60; }
.kg-legend-square { color: #F39C12; }
.kg-legend-hexagon { color: #E74C3C; }

.kg-legend-line {
  font-family: monospace;
  font-size: 10px;
}

.kg-legend-solid { color: #E74C3C; }
.kg-legend-dashed { color: #95A5A6; }
.kg-legend-dotted { color: #3498DB; }

.kg-legend-divider {
  height: 1px;
  background: #e0e0e0;
  margin: 8px 0;
}

/* Stats */
.kg-stats {
  padding-top: 12px;
  border-top: 1px solid #e0e0e0;
}

.kg-stat {
  text-align: center;
}

.kg-stat-value {
  display: block;
  font-size: 24px;
  font-weight: 700;
  color: var(--current-part-color, #2C3E50);
}

.kg-stat-label {
  font-size: 11px;
  color: #888;
  text-transform: uppercase;
}

/* ==========================================================================
   Tree View Specific
   ========================================================================== */

.kg-tree-link {
  transition: stroke-opacity 0.15s;
}

.kg-tree-node:hover .kg-tree-link {
  stroke-opacity: 1;
}

/* ==========================================================================
   Radial View Specific
   ========================================================================== */

.kg-radial-spoke {
  pointer-events: none;
}

.kg-radial-chapter-line {
  pointer-events: none;
}

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

@media (max-width: 992px) {
  .kg-container {
    flex-direction: column-reverse;
    height: auto;
    min-height: auto;
  }

  .kg-sidebar {
    width: 100%;
    min-width: 100%;
    border-left: none;
    border-top: 1px solid #e0e0e0;
    max-height: 300px;
  }

  .kg-sidebar.kg-sidebar-collapsed {
    max-height: 40px;
  }

  .kg-graph-area {
    height: 60vh;
    min-height: 400px;
  }

  .kg-sidebar-content {
    padding: 12px;
  }

  .kg-sidebar-toggle {
    top: 8px;
    right: 10px;
    left: auto;
  }
}

@media (max-width: 768px) {
  .kg-container {
    border-radius: 0;
  }

  .kg-graph-area {
    height: 50vh;
    min-height: 350px;
  }

  .kg-view-buttons {
    flex-wrap: wrap;
  }

  .kg-view-btn {
    flex: 0 0 calc(33% - 4px);
  }

  .kg-tooltip {
    max-width: 280px;
    font-size: 13px;
  }
}

@media (max-width: 480px) {
  .kg-graph-area {
    height: 40vh;
    min-height: 300px;
  }

  .kg-sidebar {
    max-height: 250px;
  }

  .kg-tooltip {
    left: 10px !important;
    right: 10px !important;
    max-width: none !important;
    bottom: 60px !important;
    top: auto !important;
  }
}

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

.kg-node:focus,
.kg-view-btn:focus,
.kg-zoom-btn:focus {
  outline: 2px solid var(--current-part-color, #2C3E50);
  outline-offset: 2px;
}

.kg-search-input:focus {
  box-shadow: 0 0 0 3px rgba(44, 62, 80, 0.1);
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .kg-node,
  .kg-edge,
  .kg-sidebar,
  .kg-view-btn,
  .kg-tooltip {
    transition: none !important;
  }
}

/* High contrast */
@media (prefers-contrast: high) {
  .kg-container {
    border-width: 2px;
  }

  .kg-node circle,
  .kg-node rect,
  .kg-node polygon {
    stroke-width: 2px !important;
  }

  .kg-edge {
    stroke-width: 2px !important;
  }
}

/* ==========================================================================
   Print
   ========================================================================== */

@media print {
  .kg-sidebar {
    display: none;
  }

  .kg-container {
    height: auto;
    border: none;
  }

  .kg-tooltip {
    display: none !important;
  }
}
