/* css/metrics-debug.css v1.4 */
/* 
 * v1.4 Updates:
 * - Consistent green/red coloring (no purple for SPY/VT)
 * - Smart scroll containment (overscroll-behavior)
 * - Improved code block scroll isolation
 * - Removed format_diff status (only match/mismatch now)
 */

/* ============================================================================
   MAIN PANEL
   ============================================================================ */
#metricsDebugPanel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 0;
  background: linear-gradient(180deg, #0d0d14 0%, #151520 100%);
  border-top: 2px solid #4a9eff;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.6);
  z-index: 9999;
  overflow: hidden;
  transition: height 0.3s ease;
  font-family: 'Inter', -apple-system, sans-serif;
  color: #e0e0e0;
  font-size: 12px;
  display: flex;
  flex-direction: column;
}

#metricsDebugPanel.visible {
  height: 50vh;
}

/* ============================================================================
   DRAG HANDLE
   ============================================================================ */
.debug-drag-handle {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 6px 0;
  cursor: ns-resize;
  background: rgba(74, 158, 255, 0.1);
  border-bottom: 1px solid rgba(74, 158, 255, 0.2);
  position: relative;
  flex-shrink: 0;
}

.drag-bar {
  width: 50px;
  height: 4px;
  background: rgba(74, 158, 255, 0.4);
  border-radius: 2px;
}

.size-btns {
  position: absolute;
  right: 15px;
  display: flex;
  gap: 4px;
}

.size-btn {
  width: 24px;
  height: 20px;
  border: 1px solid rgba(74, 158, 255, 0.3);
  background: rgba(74, 158, 255, 0.1);
  color: #4a9eff;
  font-size: 10px;
  cursor: pointer;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.size-btn:hover {
  background: rgba(74, 158, 255, 0.25);
  transform: scale(1.05);
}

.size-btn:active {
  transform: scale(0.95);
}

/* ============================================================================
   HEADER
   ============================================================================ */
.debug-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 15px;
  background: rgba(0, 0, 0, 0.3);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.debug-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 13px;
}

.debug-ver {
  font-size: 10px;
  color: #666;
  padding: 1px 5px;
  background: rgba(74, 158, 255, 0.1);
  border-radius: 3px;
}

.debug-actions {
  display: flex;
  gap: 6px;
}

.dbtn {
  padding: 5px 10px;
  border: 1px solid rgba(74, 158, 255, 0.3);
  background: rgba(74, 158, 255, 0.08);
  color: #4a9eff;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
}

.dbtn:hover {
  background: rgba(74, 158, 255, 0.2);
}

.dbtn-close {
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.3);
  color: #ef4444;
}

.dbtn-close:hover {
  background: rgba(239, 68, 68, 0.2);
}

/* ============================================================================
   TABS
   ============================================================================ */
.debug-tabs {
  display: flex;
  gap: 2px;
  padding: 6px 15px;
  background: rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}

.dtab {
  padding: 6px 12px;
  border: none;
  background: transparent;
  color: #777;
  font-size: 11px;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.15s;
}

.dtab:hover {
  color: #aaa;
  background: rgba(255, 255, 255, 0.04);
}

.dtab.active {
  color: #4a9eff;
  background: rgba(74, 158, 255, 0.12);
}

/* ============================================================================
   CONTENT - v1.4 SMART SCROLL
   ============================================================================ */
.debug-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 15px;
  /* Prevent scroll from leaking to background page */
  overscroll-behavior: contain;
}

.debug-loading {
  text-align: center;
  padding: 40px;
  color: #666;
}

.debug-empty, .debug-error {
  text-align: center;
  padding: 40px;
  color: #888;
}

.debug-error {
  color: #ef4444;
}

/* ============================================================================
   FOOTER
   ============================================================================ */
.debug-footer {
  display: flex;
  justify-content: space-between;
  padding: 6px 15px;
  background: rgba(0, 0, 0, 0.3);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 10px;
  color: #666;
  flex-shrink: 0;
}

.debug-footer .debug-legend {
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 12px;
  opacity: 0.9;
}

.debug-footer .debug-legend .lg {
  white-space: nowrap;
}

/* ============================================================================
   COMPARISON TABLE - v1.4 CONSISTENT COLORING
   ============================================================================ */
.comparison-wrap {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.comp-summary {
  display: flex;
  gap: 14px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  margin: 10px 10px 0 10px;
  background: rgba(255, 255, 255, 0.03);
  font-size: 12px;
  flex-wrap: wrap;
}

.comp-controls {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  margin: 10px 0 14px 0;
  background: rgba(0, 0, 0, 0.18);
  flex-wrap: wrap;
}

.comp-search {
  flex: 1;
  min-width: 220px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.35);
  color: #e5e7eb;
  outline: none;
}

.comp-search:focus {
  border-color: rgba(74, 158, 255, 0.5);
}

.comp-only {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 12px;
  opacity: 0.9;
}

.comp-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: inherit;
  padding: 6px 10px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.15s;
}

.comp-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.comp-group {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 6px;
  overflow: hidden;
}

.comp-group-title {
  padding: 8px 12px;
  background: rgba(74, 158, 255, 0.1);
  color: #4a9eff;
  font-weight: 600;
  font-size: 11px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.comp-count {
  opacity: 0.7;
  font-weight: 400;
}

.comp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.comp-table th {
  padding: 6px 8px;
  text-align: left;
  font-weight: 500;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.comp-table .header-main th {
  background: rgba(0, 0, 0, 0.3);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.comp-table .header-sub th {
  background: rgba(0, 0, 0, 0.2);
  color: #888;
  font-size: 9px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.comp-table td {
  padding: 5px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.comp-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

/* Column widths */
.col-key {
  width: 140px;
  font-family: 'Monaco', monospace;
  font-size: 10px;
  color: #aaa;
}

/* v1.4: ALL section headers use same blue color */
.col-section {
  text-align: center;
  font-size: 11px;
  color: #4a9eff;
  opacity: 0.9;
}

.col-raw {
  font-family: 'Monaco', monospace;
  font-size: 10px;
  color: #888;
  width: 90px;
}

/* v1.4: ALL formatted values use consistent green color */
.col-fmt {
  font-weight: 500;
  width: 70px;
  color: #10b981;
}

.col-gap {
  width: 15px;
  background: rgba(255, 255, 255, 0.02);
  border-left: 1px solid rgba(255, 255, 255, 0.06);
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.col-ui {
  white-space: nowrap;
}

.col-delta {
  font-family: 'Monaco', monospace;
  font-size: 10px;
  color: #9ca3af;
}

/* v1.4: Simplified status colors - match (green) or mismatch (red) */
.st-match {
  color: #34d399;
}

.st-mismatch {
  color: #f87171;
}

.st-none {
  color: #9ca3af;
}

.row-issue td {
  background: rgba(255, 0, 0, 0.04);
}

/* Sortable headers */
th.sortable {
  cursor: pointer;
  user-select: none;
}

th.sortable:hover {
  text-decoration: underline;
}

/* ============================================================================
   RAW DATA / CURATED / PIPELINE - v1.4 SCROLL ISOLATION
   ============================================================================ */
.raw-wrap, .curated-wrap, .pipeline-wrap {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.raw-section {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 6px;
  overflow: hidden;
}

.raw-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.25);
  font-size: 11px;
  font-weight: 500;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.raw-count {
  font-size: 10px;
  color: #666;
  padding: 2px 6px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 3px;
}

/* v1.4: Code blocks with click-to-activate scroll */
.code-block {
  position: relative;
  max-height: 350px;
  overflow: hidden; /* Hidden by default - no scroll */
  overscroll-behavior: contain;
  transition: box-shadow 0.15s;
}

/* When clicked/active, enable scrolling */
.code-block.scroll-active {
  overflow: auto;
  box-shadow: inset 0 0 0 2px rgba(74, 158, 255, 0.4);
}

.code-block pre {
  margin: 0;
  padding: 12px;
  font-family: 'Monaco', 'Consolas', monospace;
  font-size: 10px;
  line-height: 1.5;
  color: #bbb;
  white-space: pre-wrap;
  word-break: break-word;
}

.copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 24px;
  border: 1px solid rgba(74, 158, 255, 0.3);
  background: rgba(0, 0, 0, 0.5);
  color: #4a9eff;
  border-radius: 3px;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
  transition: all 0.15s;
}

.copy-btn:hover {
  background: rgba(74, 158, 255, 0.2);
}

/* Pipeline diagram */
.pipeline-diagram {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
}

.pstep {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 14px;
  background: rgba(74, 158, 255, 0.1);
  border: 1px solid rgba(74, 158, 255, 0.25);
  border-radius: 6px;
  min-width: 80px;
}

.picon {
  font-size: 20px;
  margin-bottom: 4px;
}

.pname {
  font-size: 10px;
  font-weight: 500;
  color: #ccc;
}

.parrow {
  color: #4a9eff;
  font-size: 16px;
  font-weight: bold;
}

/* ============================================================================
   SANITY TAB
   ============================================================================ */
.sanity-wrap {
  padding: 10px;
}

.sanity-top {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.sanity-card {
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 14px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.03);
}

.sanity-card.good {
  border-color: rgba(90, 255, 120, 0.22);
}

.sanity-card.bad {
  border-color: rgba(255, 90, 90, 0.25);
}

.sanity-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}

.sanity-sub {
  font-size: 12px;
  opacity: 0.9;
  margin-bottom: 10px;
}

.dbtn.small {
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 10px;
}

.sanity-section {
  margin-top: 10px;
}

.sanity-header {
  font-weight: 700;
  opacity: 0.95;
  margin: 8px 0;
}

.sanity-list {
  margin: 0;
  padding-left: 18px;
}

.sanity-list li {
  margin: 6px 0;
  font-size: 12px;
}

.sanity-none {
  opacity: 0.8;
  font-size: 12px;
  padding: 6px 0;
}

/* ============================================================================
   SCROLLBAR
   ============================================================================ */
#metricsDebugPanel ::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

#metricsDebugPanel ::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.2);
}

#metricsDebugPanel ::-webkit-scrollbar-thumb {
  background: rgba(74, 158, 255, 0.3);
  border-radius: 3px;
}

#metricsDebugPanel ::-webkit-scrollbar-thumb:hover {
  background: rgba(74, 158, 255, 0.5);
}

/* ============================================================================
   RESPONSIVE
   ============================================================================ */
@media (max-width: 900px) {
  .sanity-top {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .debug-header {
    flex-direction: column;
    gap: 8px;
  }
  
  .debug-actions {
    flex-wrap: wrap;
    justify-content: center;
  }
  
  .comp-table {
    font-size: 10px;
  }
  
  .col-raw {
    display: none;
  }
  
  .col-gap {
    width: 8px;
  }
  
  .pipeline-diagram {
    flex-wrap: wrap;
  }
}