/**
 * Ontology Viewer Styles
 * Phase 3: Enhanced Search, Highlighting, Navigation
 * Phase 4: Flow View
 */

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: #0d1117;
  color: #e6edf3;
  min-height: 100vh;
  overflow: hidden;
}

/* Layout */
.viewer-container {
  display: grid;
  grid-template-rows: 52px 1fr;
  grid-template-columns: 240px 1fr 320px;
  grid-template-areas:
    "header header header"
    "sidebar main detail";
  height: 100vh;
}

/* Header */
.viewer-header {
  grid-area: header;
  background: #161b22;
  border-bottom: 1px solid #30363d;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.viewer-title {
  font-size: 15px;
  font-weight: 600;
  color: #58a6ff;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.version-badge {
  font-size: 9px;
  background: #30363d;
  padding: 2px 5px;
  border-radius: 8px;
  color: #8b949e;
}

/* Navigation buttons */
.nav-buttons {
  display: flex;
  gap: 2px;
}

.nav-btn {
  width: 28px;
  height: 28px;
  border: 1px solid #30363d;
  border-radius: 4px;
  background: transparent;
  color: #8b949e;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-btn:hover:not(:disabled) {
  background: #21262d;
  color: #e6edf3;
}

.nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* Search */
.search-box {
  flex: 1;
  max-width: 350px;
  position: relative;
  display: flex;
  align-items: center;
}

#search-input {
  width: 100%;
  padding: 6px 60px 6px 10px;
  border: 1px solid #30363d;
  border-radius: 6px;
  background: #0d1117;
  color: #e6edf3;
  font-size: 13px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#search-input:focus {
  outline: none;
  border-color: #58a6ff;
  box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.15);
}

#search-input::placeholder {
  color: #6e7681;
}

.search-results {
  position: absolute;
  right: 28px;
  font-size: 11px;
  color: #58a6ff;
  background: rgba(56, 139, 253, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  display: none;
}

.clear-btn {
  position: absolute;
  right: 6px;
  width: 20px;
  height: 20px;
  border: none;
  background: transparent;
  color: #6e7681;
  font-size: 16px;
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.clear-btn:hover {
  background: #30363d;
  color: #e6edf3;
}

/* View Tabs */
.view-tabs {
  display: flex;
  gap: 3px;
}

.view-tab {
  padding: 6px 12px;
  border: 1px solid #30363d;
  border-radius: 6px;
  background: transparent;
  color: #8b949e;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.view-tab:hover {
  color: #e6edf3;
  border-color: #8b949e;
}

.view-tab.active {
  background: #21262d;
  color: #e6edf3;
  border-color: #58a6ff;
}

.back-link {
  color: #8b949e;
  text-decoration: none;
  font-size: 12px;
  white-space: nowrap;
  padding: 6px 10px;
  border-radius: 6px;
  transition: all 0.15s;
}

.back-link:hover {
  color: #e6edf3;
  background: #21262d;
}

/* Sidebar */
.viewer-sidebar {
  grid-area: sidebar;
  background: #161b22;
  border-right: 1px solid #30363d;
  padding: 12px;
  overflow-y: auto;
  font-size: 12px;
}

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

.sidebar-section h3 {
  font-size: 10px;
  text-transform: uppercase;
  color: #8b949e;
  margin-bottom: 8px;
  letter-spacing: 0.5px;
}

/* Quick Filters */
.quick-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.quick-filter {
  padding: 4px 10px;
  border: 1px solid #30363d;
  border-radius: 12px;
  background: transparent;
  color: #8b949e;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
}

.quick-filter:hover {
  border-color: #58a6ff;
  color: #58a6ff;
}

.quick-filter.active {
  background: #58a6ff;
  border-color: #58a6ff;
  color: #fff;
}

/* Filters */
.filter-group, .legend-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-item {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  padding: 2px 0;
}

.filter-item input[type="checkbox"] {
  width: 12px;
  height: 12px;
  accent-color: #58a6ff;
  cursor: pointer;
}

.filter-label {
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.filter-color, .legend-color {
  width: 8px;
  height: 8px;
  border-radius: 2px;
}

.edge-color {
  width: 16px;
  height: 2px;
  border-radius: 1px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  font-size: 11px;
  color: #8b949e;
}

.sidebar-help {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid #30363d;
}

.help-item {
  font-size: 11px;
  color: #6e7681;
  padding: 2px 0;
  display: flex;
  align-items: center;
  gap: 4px;
}

kbd {
  background: #30363d;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 10px;
  font-family: inherit;
}

/* Main View Area */
.viewer-main {
  grid-area: main;
  background: #0d1117;
  overflow: hidden;
  position: relative;
}

#tree-view {
  padding: 12px;
  overflow-y: auto;
  height: 100%;
}

#graph-view {
  width: 100%;
  height: 100%;
  display: none;
  background: radial-gradient(circle at center, #161b22 0%, #0d1117 100%);
}

#flow-view {
  width: 100%;
  height: 100%;
  display: none;
  overflow-y: auto;
  padding: 20px;
  background: linear-gradient(180deg, #161b22 0%, #0d1117 100%);
}

/* Tree View */
.tree-category {
  margin-bottom: 4px;
}

.category-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: #161b22;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
  user-select: none;
}

.category-header:hover {
  background: #21262d;
}

.expand-icon {
  font-size: 9px;
  color: #6e7681;
  width: 12px;
}

.category-icon {
  font-size: 12px;
}

.category-name {
  font-weight: 500;
  font-size: 12px;
  flex: 1;
}

.category-count {
  font-size: 10px;
  color: #6e7681;
  background: #30363d;
  padding: 1px 6px;
  border-radius: 8px;
}

.category-items {
  padding-left: 16px;
  margin-top: 2px;
}

.category-items.collapsed {
  display: none;
}

.tree-node {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  margin: 1px 0;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.1s;
}

.tree-node:hover {
  background: #21262d;
}

.tree-node.selected {
  background: rgba(56, 139, 253, 0.15);
  outline: 1px solid #388bfd;
}

.node-color {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.node-label {
  flex: 1;
  font-size: 12px;
}

.node-label mark {
  background: #f0883e;
  color: #0d1117;
  padding: 0 2px;
  border-radius: 2px;
}

.node-code {
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 10px;
  color: #7d8590;
  background: #30363d;
  padding: 1px 5px;
  border-radius: 3px;
}

.no-results {
  text-align: center;
  color: #6e7681;
  padding: 40px;
  font-size: 13px;
}

/* Detail Panel */
.viewer-detail {
  grid-area: detail;
  background: #161b22;
  border-left: 1px solid #30363d;
  overflow-y: auto;
  font-size: 12px;
}

.detail-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #6e7681;
  text-align: center;
  padding: 30px;
}

.empty-icon {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: 0.4;
}

.empty-text {
  font-size: 13px;
}

.empty-hint {
  font-size: 11px;
  color: #484f58;
  margin-top: 4px;
}

.detail-header {
  padding: 14px 16px;
  background: #21262d;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.detail-icon {
  font-size: 24px;
  line-height: 1;
}

.detail-title {
  flex: 1;
}

.detail-title h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
  line-height: 1.2;
}

.detail-meta {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.meta-type {
  font-size: 10px;
  color: #58a6ff;
  background: rgba(56, 139, 253, 0.15);
  padding: 1px 6px;
  border-radius: 3px;
}

.meta-category {
  font-size: 10px;
  color: #8b949e;
  background: #30363d;
  padding: 1px 6px;
  border-radius: 3px;
}

.meta-code {
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 10px;
  color: #7d8590;
}

/* Breadcrumb */
.detail-breadcrumb {
  padding: 8px 16px;
  background: #0d1117;
  border-bottom: 1px solid #21262d;
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.breadcrumb-item {
  color: #58a6ff;
  cursor: pointer;
}

.breadcrumb-item:hover {
  text-decoration: underline;
}

.breadcrumb-sep {
  color: #484f58;
}

.breadcrumb-current {
  color: #8b949e;
}

.detail-section {
  padding: 12px 16px;
  border-bottom: 1px solid #21262d;
}

.detail-section h3 {
  font-size: 10px;
  text-transform: uppercase;
  color: #8b949e;
  margin-bottom: 8px;
  letter-spacing: 0.5px;
}

.section-content {
  font-size: 12px;
  line-height: 1.5;
  color: #c9d1d9;
}

/* Properties */
.properties-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.property-item {
  display: flex;
  gap: 6px;
  font-size: 11px;
  line-height: 1.4;
}

.property-key {
  color: #8b949e;
  min-width: 90px;
  flex-shrink: 0;
}

.property-key::after {
  content: ':';
}

.property-value {
  color: #c9d1d9;
  word-break: break-word;
}

.property-value code {
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 10px;
  background: #0d1117;
  padding: 2px 4px;
  border-radius: 3px;
  display: inline-block;
  white-space: pre-wrap;
}

.property-value em {
  color: #6e7681;
  font-style: italic;
}

/* Effects */
.effects-list {
  list-style: none;
  font-size: 11px;
}

.effects-list li {
  padding: 3px 0;
  padding-left: 18px;
  position: relative;
  color: #c9d1d9;
}

.effects-list li::before {
  content: '⚡';
  position: absolute;
  left: 0;
  font-size: 10px;
}

.char-list li::before {
  content: '•';
  color: #58a6ff;
}

.block-list li::before {
  content: '🚫';
}

.strategy-list li::before {
  content: '💡';
}

/* Config List */
.config-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.config-item {
  display: flex;
  gap: 8px;
  font-size: 11px;
  padding: 4px 8px;
  background: #0d1117;
  border-radius: 4px;
  align-items: flex-start;
}

.config-item.threshold {
  border-left: 2px solid #f0883e;
}

.config-key {
  color: #58a6ff;
  font-family: 'SF Mono', Monaco, monospace;
  font-weight: 500;
  flex-shrink: 0;
  min-width: 60px;
}

.config-value {
  color: #c9d1d9;
  word-break: break-word;
}

/* Material Behavior */
.material-behavior {
  padding: 8px 10px;
  background: #0d1117;
  border-radius: 6px;
  margin-bottom: 6px;
}

.mat-name {
  font-weight: 600;
  font-size: 12px;
  color: #e6edf3;
  margin-bottom: 4px;
}

.mat-desc {
  font-size: 11px;
  color: #8b949e;
  margin-bottom: 6px;
}

.badge {
  display: inline-block;
  font-size: 9px;
  padding: 2px 6px;
  border-radius: 4px;
  margin-right: 4px;
  font-weight: 500;
}

.badge-fatal {
  background: rgba(248, 81, 73, 0.2);
  color: #f85149;
}

.badge-blocked {
  background: rgba(240, 136, 62, 0.2);
  color: #f0883e;
}

.badge-safe {
  background: rgba(63, 185, 80, 0.2);
  color: #3fb950;
}

/* Validator Badge */
.validator-badge {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.validator-desc {
  font-size: 11px;
  color: #8b949e;
  line-height: 1.4;
}

/* Entangled relationship */
.relationship-item.entangled {
  background: rgba(255, 87, 34, 0.1);
  padding: 6px 8px;
  border-radius: 4px;
  border-left: 2px solid #ff5722;
}

.relationship-item.entangled .rel-arrow {
  color: #ff5722;
}

/* Interactions List */
.interactions-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.interaction-item {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  font-size: 11px;
  padding: 4px 0;
}

.interaction-with {
  color: #58a6ff;
  font-weight: 500;
}

.interaction-cond {
  color: #f0883e;
  font-size: 10px;
  background: rgba(240, 136, 62, 0.1);
  padding: 1px 4px;
  border-radius: 3px;
}

.interaction-result {
  color: #c9d1d9;
}

/* Relationships */
.relationships-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.relationship-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  flex-wrap: wrap;
  padding: 3px 0;
}

.rel-arrow {
  color: #6e7681;
  font-weight: bold;
  font-size: 12px;
}

.rel-type {
  font-weight: 500;
  font-size: 10px;
}

.rel-label {
  color: #f0883e;
  font-size: 10px;
  background: rgba(240, 136, 62, 0.1);
  padding: 0 4px;
  border-radius: 3px;
}

.rel-link {
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
}

.rel-link:hover {
  text-decoration-style: solid;
}

.rel-condition {
  color: #6e7681;
  font-size: 10px;
  font-style: italic;
}

/* Detail Actions */
.detail-actions {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.action-btn {
  width: 100%;
  padding: 8px 12px;
  background: #21262d;
  border: 1px solid #30363d;
  border-radius: 6px;
  color: #c9d1d9;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
}

.action-btn:hover {
  background: #30363d;
  border-color: #8b949e;
}

/* ===================== */
/* FLOW VIEW STYLES      */
/* ===================== */

.flow-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #6e7681;
  text-align: center;
}

/* Flow Tile Selector */
.flow-selector {
  max-width: 800px;
  margin: 0 auto;
}

.flow-selector-header {
  text-align: center;
  margin-bottom: 24px;
}

.flow-selector-header h2 {
  font-size: 20px;
  color: #e6edf3;
  margin-bottom: 8px;
}

.flow-selector-header p {
  font-size: 13px;
  color: #8b949e;
}

.flow-tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.flow-tile-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: #21262d;
  border: 2px solid #30363d;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s;
}

.flow-tile-card:hover {
  background: #30363d;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.flow-tile-icon {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: bold;
  color: #fff;
  flex-shrink: 0;
}

.flow-tile-info {
  flex: 1;
  min-width: 0;
}

.flow-tile-name {
  font-size: 14px;
  font-weight: 500;
  color: #e6edf3;
  margin-bottom: 2px;
}

.flow-tile-effects {
  font-size: 11px;
  color: #8b949e;
}

.flow-header {
  text-align: center;
  margin-bottom: 24px;
  position: relative;
}

.flow-back-btn {
  position: absolute;
  left: 0;
  top: 0;
  padding: 6px 12px;
  background: #21262d;
  border: 1px solid #30363d;
  border-radius: 6px;
  color: #8b949e;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.flow-back-btn:hover {
  background: #30363d;
  color: #e6edf3;
  border-color: #8b949e;
}

.flow-header h2 {
  font-size: 18px;
  color: #e6edf3;
  margin-bottom: 4px;
}

.flow-header p {
  font-size: 12px;
  color: #8b949e;
}

.flow-diagram {
  max-width: 600px;
  margin: 0 auto;
}

.flow-tree {
  position: relative;
}

.flow-row {
  display: flex;
  align-items: center;
  margin: 8px 0;
  position: relative;
}

.flow-connector {
  width: 24px;
  position: relative;
}

.flow-connector.has-line::before {
  content: '';
  position: absolute;
  left: 8px;
  top: -20px;
  width: 2px;
  height: 20px;
  background: #30363d;
}

.flow-connector.has-line::after {
  content: '';
  position: absolute;
  left: 8px;
  top: 0;
  width: 16px;
  height: 2px;
  background: #30363d;
}

.flow-node {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: #21262d;
  border: 2px solid #30363d;
  border-radius: 8px;
  min-width: 200px;
  transition: all 0.15s;
}

.flow-node[data-node-id] {
  cursor: pointer;
}

.flow-node[data-node-id]:hover {
  border-color: #58a6ff;
  background: #30363d;
}

.flow-icon {
  font-size: 16px;
}

.flow-label {
  font-size: 12px;
  color: #c9d1d9;
  flex: 1;
}

/* Flow node types */
.flow-start {
  border-color: #3fb950;
  background: rgba(63, 185, 80, 0.1);
}

.flow-start .flow-icon { color: #3fb950; }

.flow-condition {
  border-color: #f0883e;
  background: rgba(240, 136, 62, 0.1);
  border-style: dashed;
}

.flow-condition .flow-icon { color: #f0883e; }

.flow-effect, .flow-movement, .flow-transform, .flow-collect {
  border-color: #a371f7;
  background: rgba(163, 113, 247, 0.1);
}

.flow-effect .flow-icon,
.flow-movement .flow-icon,
.flow-transform .flow-icon,
.flow-collect .flow-icon { color: #a371f7; }

.flow-fatal {
  border-color: #f85149;
  background: rgba(248, 81, 73, 0.1);
}

.flow-fatal .flow-icon { color: #f85149; }

.flow-success {
  border-color: #3fb950;
  background: rgba(63, 185, 80, 0.1);
}

.flow-success .flow-icon { color: #3fb950; }

/* Flow Legend */
.flow-legend {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid #30363d;
  flex-wrap: wrap;
}

.flow-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: #8b949e;
}

.flow-node-sample {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 2px solid;
}

.flow-node-sample.flow-start { border-color: #3fb950; background: rgba(63, 185, 80, 0.2); }
.flow-node-sample.flow-condition { border-color: #f0883e; background: rgba(240, 136, 62, 0.2); border-style: dashed; }
.flow-node-sample.flow-effect { border-color: #a371f7; background: rgba(163, 113, 247, 0.2); }
.flow-node-sample.flow-fatal { border-color: #f85149; background: rgba(248, 81, 73, 0.2); }
.flow-node-sample.flow-success { border-color: #3fb950; background: rgba(63, 185, 80, 0.2); }

/* Graph SVG */
#graph-view .node circle {
  transition: r 0.15s, stroke-width 0.15s;
}

#graph-view .node:hover circle {
  filter: brightness(1.2);
}

#graph-view text {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  pointer-events: none;
  text-shadow: 0 1px 2px rgba(0,0,0,0.8), 0 0 8px rgba(0,0,0,0.5);
}

/* Responsive */
@media (max-width: 1100px) {
  .viewer-container {
    grid-template-columns: 200px 1fr 280px;
  }
  
  .viewer-title span:nth-child(2) {
    display: none;
  }
}

@media (max-width: 900px) {
  .viewer-container {
    grid-template-columns: 1fr;
    grid-template-rows: 52px 1fr auto;
    grid-template-areas:
      "header"
      "main"
      "detail";
  }
  
  .viewer-sidebar {
    display: none;
  }
  
  .viewer-detail {
    border-left: none;
    border-top: 1px solid #30363d;
    max-height: 35vh;
  }
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #30363d;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #484f58;
}

/* Animation */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.tree-category {
  animation: fadeIn 0.15s ease-out;
}

.flow-row {
  animation: fadeIn 0.2s ease-out;
  animation-fill-mode: both;
}

.flow-row:nth-child(1) { animation-delay: 0s; }
.flow-row:nth-child(2) { animation-delay: 0.05s; }
.flow-row:nth-child(3) { animation-delay: 0.1s; }
.flow-row:nth-child(4) { animation-delay: 0.15s; }
.flow-row:nth-child(5) { animation-delay: 0.2s; }
.flow-row:nth-child(6) { animation-delay: 0.25s; }

/* Header Links */
.back-link {
  color: #8b949e;
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 6px;
  transition: all 0.2s;
  font-size: 13px;
  white-space: nowrap;
}

.back-link:hover {
  color: #e6edf3;
  background: #21262d;
}
