/* ==============================================
   COMPARISON TOOL SPECIFIC STYLES
   Only styles unique to the comparison tool
   (Shared styles are in ../shared/)
   ============================================== */

/* Card Position for Overlay */
.comparison-side .card {
  position: relative; /* Position context for absolute overlay */
}

/* HTML Content Display */
.html-content {
  position: relative; /* Constrain absolutely positioned children (like JH5439 spans) */
  max-height: calc(100vh - 40px - 200px);
  overflow-y: auto;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  line-height: 1.8;
  user-select: text;
  cursor: text;
  transition: background 0.3s ease;
}

/* Light theme HTML content */
:root[data-theme="light"] .html-content {
  background: var(--html-content-bg, #ffffff);
  border: 1px solid var(--border);
}

/* Main Layout - Two Column Comparison */
.comparison-layout {
  padding: 20px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  min-height: calc(100vh - 70px);
}

.comparison-side {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Analysis Modal - Draggable & Resizable Popup */
.analysis-modal {
  position: fixed;
  background: linear-gradient(180deg, var(--card), var(--card-2));
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  z-index: 1000;
  min-width: 400px;
  width: 42vw;
  min-height: 250px;
  height: 80vh;
  max-width: 50vw;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  resize: both;
  /* Default position - will be overridden by JS */
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.analysis-modal.hidden {
  display: none;
}

.analysis-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,.03);
  cursor: move;
  user-select: none;
}

.analysis-modal-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
}

.analysis-close-btn {
  background: none !important;
  border: none !important;
  color: var(--sub) !important;
  font-size: 24px !important;
  cursor: pointer !important;
  width: 32px !important;
  height: 32px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  border-radius: 8px !important;
  transition: all 0.2s ease !important;
  padding: 0 !important;
}

.analysis-close-btn:hover {
  background: var(--hover) !important;
  color: var(--text) !important;
}

.analysis-modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
  position: relative;
}

/* Work in Progress Message */
.work-in-progress {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  min-height: 180px;
}

.work-in-progress h3 {
  color: var(--accent);
  font-size: 24px;
  margin-bottom: 12px;
  font-weight: 600;
}

.work-in-progress p {
  color: var(--sub);
  font-size: 16px;
  margin: 0;
}

/* IAA Results Display */
.comparison-loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(4px);
}

.iaa-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  min-height: 200px;
}

.iaa-loading .spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 16px;
}

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

.iaa-loading p {
  color: var(--sub);
  font-size: 14px;
}

.iaa-error {
  padding: 30px;
  text-align: center;
}

.iaa-error h3 {
  color: #ff6b6b;
  margin-bottom: 12px;
}

.iaa-error p {
  color: var(--sub);
  margin-bottom: 20px;
}

.iaa-error button {
  padding: 8px 20px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}

.iaa-results {
  padding: 20px;
}

.iaa-section {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
}

.iaa-section h3 {
  margin: 0 0 16px 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 8px;
}

.iaa-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.iaa-stat {
  background: var(--card-2);
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.iaa-label {
  color: var(--sub);
  font-size: 13px;
  font-weight: 500;
}

.iaa-value {
  color: var(--text);
  font-size: 18px;
  font-weight: 600;
}

.iaa-value.highlight {
  color: var(--accent);
  font-size: 20px;
}

.annotator-list {
  margin-top: 12px;
}

.annotator-list strong {
  color: var(--text);
  font-size: 14px;
}

.annotator-list ul {
  list-style: none;
  padding: 0;
  margin: 8px 0 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.annotator-list li {
  background: var(--card-2);
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--text);
}

.annotator-labels {
  margin-bottom: 16px;
}

.annotator-labels strong {
  color: var(--text);
  font-size: 14px;
  display: block;
  margin-bottom: 8px;
}

.label-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.label-chip {
  background: linear-gradient(135deg, var(--card-2), var(--card));
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.count-badge {
  background: var(--accent);
  color: white;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}

.overlap-card {
  background: var(--card-2);
  padding: 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: 12px;
}

.overlap-card h4 {
  margin: 0 0 12px 0;
  font-size: 14px;
  color: var(--text);
  font-weight: 600;
  text-transform: capitalize;
}

.label-types {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.label-type-badge {
  background: var(--accent);
  color: white;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* IAA Match Overlays - Non-intrusive visual indicators */
.iaa-overlay-container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 100;
  overflow: visible;
}

/* IAA Match Icons - styled like delete buttons, attached directly to labels */
manual_label .iaa-match-icon,
auto_label .iaa-match-icon {
  position: absolute;
  top: -8px;
  left: -8px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: help;
  z-index: 10;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
  transition: transform 0.2s ease;
}

manual_label .iaa-match-icon:hover,
auto_label .iaa-match-icon:hover {
  transform: scale(1.15);
}

manual_label .iaa-match-icon svg,
auto_label .iaa-match-icon svg {
  width: 11px;
  height: 11px;
  fill: white;
}

/* Tooltip styling */
.iaa-match-tooltip {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: rgba(0, 0, 0, 0.95);
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  white-space: normal;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  max-width: 300px;
  line-height: 1.4;
}

.iaa-match-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: rgba(0, 0, 0, 0.95);
}

.iaa-match-icon:hover .iaa-match-tooltip {
  opacity: 1;
}

.iaa-match-badge

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



/* Analysis Details */
.analysis-details {
  padding: 16px;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-y: auto;
  max-height: 300px;
}

/* ==============================================
   LABEL VIEWING STYLES (Read-Only)
   Copied from labelizer/style.css
   ============================================== */

/* Manual Labels - Copied from labelizer */
manual_label, auto_label {
  position: relative;
  display: inline;
  padding: 0px 4px;
  border-radius: 4px;
  font-weight: 500;
  margin: 0 1px;
  cursor: pointer;
  transition: opacity 0.2s ease;
  border: 1px solid rgba(255, 255, 255, 0.1);
  line-height: 1.2;
}

manual_label:hover, auto_label:hover {
  opacity: 0.8;
}

/* NOTE: Delete button styling removed for read-only view */
/* In labelizer: manual_label .delete-btn, auto_label .delete-btn { ... } */

/* Parameter Menu - Exact copy from labelizer/style.css lines 940-1100 */
.param-menu {
  position: fixed;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 16px;
  z-index: 1001;
  min-width: 280px;
  max-width: 400px;
}

.param-menu.hidden {
  display: none;
}

.param-menu h4 {
  color: var(--accent);
  font-size: 14px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  cursor: grab;
  user-select: none;
  padding: 4px 0 8px 0;
  margin: -4px 0 12px 0;
}

.param-menu h4:hover {
  cursor: grab;
}

.param-menu h4:active {
  cursor: grabbing;
}

.param-close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  color: var(--sub);
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.param-close-btn:hover {
  background: var(--hover);
  color: var(--text);
}

.param-close-btn:active {
  background: var(--danger);
  color: white;
}

/* Light theme parameter menu close button */
:root[data-theme="light"] .param-close-btn {
  color: #8a8a8a !important;
}

:root[data-theme="light"] .param-close-btn:hover {
  background: var(--hover) !important;
  color: #666666 !important;
}

:root[data-theme="light"] .param-close-btn:active {
  background: var(--danger) !important;
  color: white !important;
}

.param-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.param-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.param-row label {
  min-width: 80px;
  font-size: 13px;
  color: var(--sub);
  font-weight: 500;
}

/* Gold label styling for group ID parameters */
.param-row label.gold-label {
  color: #FFD700;
  font-weight: 700;
}

.param-row input,
.param-row select {
  flex: 1;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--hover);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
}

.param-row input:focus,
.param-row select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(106, 163, 255, 0.2);
}

.param-row select {
  cursor: pointer;
}

/* ==============================================
   SOURCE VIEW STYLES
   Read-only source view for documents A and B
   ============================================== */

.source-view {
  display: none; /* Hidden by default, toggled by JS */
  height: calc(100vh - 40px - 200px); /* Match html-content height */
  min-height: 300px;
  overflow-y: auto;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  /* Use the same background as html-content to respect user's luminosity settings */
  background: var(--html-content-bg, var(--bg));
  color: var(--text);
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  font-size: 0.875rem;
  line-height: 1.6;
  white-space: pre;
  resize: vertical; /* User can resize */
  outline: none;
  width: 100%;
  box-sizing: border-box;
  transition: background 0.3s ease;
}

/* Light theme source view - use the dynamic html-content-bg variable */
:root[data-theme="light"] .source-view {
  background: var(--html-content-bg, #ffffff);
  color: var(--text);
  border-color: var(--border);
}

/* Focus effect */
.source-view:focus {
  border-color: #6aa3ff;
  box-shadow: 0 0 0 2px rgba(106, 163, 255, 0.2);
}

/* ==============================================
   UPLOAD BUTTON
   Button to upload new file after initial load
   ============================================== */

.upload-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  height: 36px;
}

.upload-btn .upload-icon {
  width: 20px;
  height: 20px;
  display: block;
}

.upload-btn:hover {
  background: #5a8fff;
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(106, 163, 255, 0.3);
}

.upload-btn:active {
  transform: translateY(0);
}

/* Light theme */
:root[data-theme="light"] .upload-btn {
  background: #e3f2fd;
  color: var(--accent);
}

:root[data-theme="light"] .upload-btn:hover {
  background: #bbdefb;
}

/* ==============================================
   NAVIGATION BUTTONS
   Navigate between labels in document
   ============================================== */

.nav-buttons {
  display: flex;
  flex-direction: column;
  gap: 0;
  height: 36px; /* Match stats-btn height */
  justify-content: center;
}

.nav-btn {
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
  font-size: 16px; /* Reduced from 20px */
  line-height: 1;
  height: 18px; /* Fixed height */
  width: 24px; /* Fixed width */
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(254, 255, 255, 0.5);
  cursor: pointer;
  transition: color 0.2s;
  flex-shrink: 0;
}

.nav-btn:hover:not(:disabled) {
  color: var(--accent);
}

.nav-btn:disabled {
  color: rgba(254, 255, 255, 0.2); /* Only color change, no opacity */
  cursor: not-allowed;
}

:root[data-theme="light"] .nav-btn {
  color: #8a8a8a;
}

:root[data-theme="light"] .nav-btn:hover:not(:disabled) {
  color: var(--accent);
}

:root[data-theme="light"] .nav-btn:disabled {
  color: #d0d0d0; /* Only color change for light theme */
}

/* ==============================================
   COMPARISON VIEW BUTTON
   Toggle button for comparison view
   ============================================== */

.comparison-view-btn {
  padding: 8px 14px !important;
  font-size: 14px !important;
  line-height: 1 !important;
}

/* Active state when comparison view is enabled */
.comparison-view-btn.active {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.2);
  transform: rotate(180deg);
}

:root[data-theme="light"] .comparison-view-btn.active {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
  color: white !important;
}

/* ==============================================
   SYNCHRONIZED SCROLL BUTTON
   Toggle button for synchronized scrolling
   ============================================== */

.sync-scroll-btn {
  padding: 8px 14px !important;
  font-size: 18px !important;
  line-height: 1 !important;
  transition: all 0.3s ease !important;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Icon inside sync button */
.sync-icon {
  width: 18px;
  height: 18px;
  display: block;
  transition: all 0.3s ease;
  filter: brightness(0) invert(1);
}

.comparison-icon {
  width: 18px;
  height: 18px;
  display: block;
  filter: brightness(0) invert(1);
}

/* Active state when sync scroll is enabled */
.sync-scroll-btn.active {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.2);
  color: white !important;
}

:root[data-theme="light"] .sync-scroll-btn.active {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
  color: white !important;
}

/* ==============================================
   STATISTICS STYLES
   Display statistics on card back
   ============================================== */

.stats-container {
  width: 100%;
  height: 100%;
  overflow-y: auto;
}

.stats-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--sub);
  font-size: 14px;
}

.stats-content {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.stat-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  text-align: center;
  transition: all 0.2s ease;
}

.stat-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(106, 163, 255, 0.2);
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 8px;
}

.stat-label {
  font-size: 13px;
  color: var(--sub);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.label-breakdown {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

.label-breakdown h4 {
  margin: 0 0 16px 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.label-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.label-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: all 0.2s ease;
}

.label-list li:hover {
  border-color: var(--accent);
  background: var(--hover);
}

.label-name {
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
}

.label-count {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  background: rgba(106, 163, 255, 0.1);
  padding: 4px 12px;
  border-radius: 12px;
}

/* Label Tree Hierarchy */
.label-tree {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
}

.label-tree-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.label-tree-header h4 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.label-tree-summary {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 13px;
  color: var(--sub);
}

.label-tree-summary span {
  display: inline-block;
}

.label-tree-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.label-tree-parent {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.label-tree-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: all 0.2s ease;
}

.label-tree-item:hover {
  border-color: var(--accent);
  background: var(--hover);
}

.label-tree-item.parent-label {
  font-weight: 600;
  background: rgba(106, 163, 255, 0.05);
}

.label-tree-item.child-label {
  margin-left: 24px;
  font-size: 13px;
  opacity: 0.95;
  flex-direction: row;
  gap: 12px;
  padding: 8px 16px;
  align-items: center;
}

.sublabels-header {
  margin-left: 24px;
  font-size: 12px;
  color: var(--sub);
  font-style: italic;
  margin-bottom: 4px;
}

.label-count-text {
  font-size: 12px;
  font-weight: 600;
  color: var(--sub);
  flex: 0 0 auto;
  min-width: 80px;
}

.label-bar-container {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.label-bar {
  height: 18px;
  background: var(--border);
  border-radius: 0;
  display: flex;
  overflow: hidden;
  position: relative;
  border: 1px solid var(--border);
  min-width: 2px;
  max-width: 300px;
}

.bar-manual {
  height: 100%;
  background: #4a4a4a;
  transition: width 0.3s ease;
}

.bar-auto {
  height: 100%;
  background: #a0a0a0;
  transition: width 0.3s ease;
}

.label-percentage {
  font-size: 11px;
  color: var(--sub);
  min-width: 45px;
  text-align: right;
  font-weight: 600;
}

/* Overall Distribution Summary */
.label-summary-section {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.label-summary-section h4 {
  margin: 0 0 16px 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.label-summary-section h4:not(:first-child) {
  margin-top: 28px;
}

.overall-bar-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

/* Combined Bars Diagram */
.combined-bars-diagram {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  padding: 16px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border);
  border-radius: 0;
}

:root[data-theme="light"] .combined-bars-diagram {
  background: rgba(0, 0, 0, 0.03);
}

.diagram-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.diagram-label-name {
  font-size: 13px;
  color: var(--text);
  font-weight: 600;
  width: 100px;
  flex: 0 0 auto;
}

.diagram-bar-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.diagram-bar {
  display: flex;
  height: 18px;
  flex: 1 1 auto;
  min-width: 20px;
  background: var(--border);
  border-radius: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  position: relative;
}

.diagram-segment {
  height: 100%;
  transition: opacity 0.2s ease;
  cursor: pointer;
}

.diagram-segment:hover {
  opacity: 0.85;
}

.diagram-percentage {
  font-size: 11px;
  color: var(--sub);
  width: 45px;
  text-align: right;
  font-weight: 600;
  flex: 0 0 auto;
}

/* Parent Bars Styles */
.parent-bars-container {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.parent-bar-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px;
  background: var(--card-2);
  border-radius: 8px;
  border: 1px solid var(--border);
}

:root[data-theme="light"] .parent-bar-group {
  background: rgba(0, 0, 0, 0.02);
}

.parent-bar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.parent-bar-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.parent-bar-total {
  font-size: 12px;
  color: var(--sub);
  font-weight: 500;
}

.parent-bar-container {
  width: 100%;
  margin-bottom: 8px;
}

.parent-bar {
  display: flex;
  height: 32px;
  width: 100%;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.bar-segment {
  height: 100%;
  transition: opacity 0.2s ease;
  cursor: pointer;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
}

.bar-segment:last-child {
  border-right: none;
}

.bar-segment:hover {
  opacity: 0.85;
  filter: brightness(1.1);
}

.parent-bar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.bar-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}

.bar-legend-item .legend-color {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid var(--border);
}

.bar-legend-item .legend-name {
  color: var(--text);
  font-weight: 500;
}

.bar-legend-item .legend-count {
  color: var(--sub);
  font-size: 11px;
}

/* Pie Chart Styles */
.pie-chart-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 20px;
}

.pie-chart-svg {
  width: 100%;
  max-width: 400px;
  height: auto;
}

.pie-slice {
  cursor: pointer;
  transition: all 0.2s ease;
  stroke: var(--card);
  stroke-width: 1;
}

.pie-slice:hover {
  opacity: 0.85;
  filter: brightness(1.1);
  stroke-width: 2;
}

.pie-chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: center;
}

.overall-bar {
  display: flex;
  height: 40px;
  width: 100%;
  border: 1px solid var(--border);
  overflow: hidden;
  border-radius: 4px;
  margin-bottom: 8px;
}

.label-segment {
  display: flex;
  position: relative;
  height: 100%;
  border-right: 2px solid var(--border);
}

.label-segment.last-child {
  border-right: 3px solid var(--card);
}

.label-segment.parent-segment {
  border-left: 3px solid var(--card);
}

.overall-segment {
  display: flex;
  position: relative;
  height: 100%;
}

.segment-manual {
  height: 100%;
  position: relative;
  /* Hatching pattern for manual labels */
  background-image: repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 3px,
    rgba(0, 0, 0, 0.1) 3px,
    rgba(0, 0, 0, 0.1) 6px
  );
}

.segment-auto {
  height: 100%;
  position: relative;
  /* Diagonal stripes for auto labels */
  background-image: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 3px,
    rgba(255, 255, 255, 0.2) 3px,
    rgba(255, 255, 255, 0.2) 6px
  );
}

.segment-label {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 10px;
  font-weight: 600;
  color: white;
  text-shadow: 0 0 3px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  white-space: nowrap;
}

.overall-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.overall-legend-detailed {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.legend-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  background: var(--card-2);
  border-radius: 6px;
  border-left: 3px solid var(--border);
}

:root[data-theme="light"] .legend-group {
  background: rgba(0, 0, 0, 0.02);
}

.legend-sublabels {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-left: 24px;
  padding-left: 12px;
  border-left: 2px solid var(--border);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 6px 12px;
  background: var(--card-2);
  border-radius: 6px;
  transition: background 0.2s ease;
}

:root[data-theme="light"] .legend-item {
  background: rgba(0, 0, 0, 0.03);
}

.legend-item:hover {
  background: var(--card-hover);
}

.legend-item.parent-legend {
  font-weight: 600;
  font-size: 13px;
}

.legend-item.sublabel-legend {
  font-size: 11px;
}

.legend-color {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  border: 1px solid var(--border);
}

.legend-name {
  color: var(--text);
  font-weight: 500;
}

.legend-count {
  color: var(--sub);
  font-size: 11px;
}

.label-color-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.label-tree-item .label-name {
  flex: 0 0 auto;
  font-size: 14px;
  color: var(--text);
  min-width: 120px;
}

.label-tree-item.parent-label .label-name {
  flex: 1;
  font-weight: 600;
}

.label-tree-item.child-label .label-name {
  min-width: 100px;
  font-size: 13px;
}

.label-count-group {
  display: flex;
  gap: 6px;
  align-items: center;
}

.count-manual,
.count-auto {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 10px;
  min-width: 32px;
  text-align: center;
}

.count-manual {
  color: #6aa3ff;
  background: rgba(106, 163, 255, 0.15);
}

.count-auto {
  color: #20c997;
  background: rgba(32, 201, 151, 0.15);
}

.label-tree-children {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Light theme adjustments */
:root[data-theme="light"] .stat-card,
:root[data-theme="light"] .label-tree {
  background: rgba(0, 0, 0, 0.02);
}

:root[data-theme="light"] .label-tree-item {
  background: #f8f9fa;
}

:root[data-theme="light"] .label-tree-item:hover {
 

:root[data-theme="light"] .label-bar {
  background: #e9ecef;
  border-color: #dee2e6;
}

:root[data-theme="light"] .bar-manual {
  background: #6c757d;
}

:root[data-theme="light"] .bar-auto {
  background: #ced4da;
} background: #e9ecef;
}

:root[data-theme="light"] .label-tree-item.parent-label {
  background: rgba(106, 163, 255, 0.08);
}

/* ==============================================
   IAA HIGHLIGHTING STYLES
   Visual highlighting for matched labels
   ============================================== */

/* Labels with IAA match highlighting */
manual_label[data-iaa-match],
auto_label[data-iaa-match] {
  transition: all 0.2s ease;
}

/* Exact match highlighting - Green */
manual_label[data-iaa-match="exact"],
auto_label[data-iaa-match="exact"] {
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.3) !important;
  background-color: rgba(34, 197, 94, 0.15) !important;
  color: #22c55e !important;
}

/* Overlap match highlighting - Orange */
manual_label[data-iaa-match="overlap"],
auto_label[data-iaa-match="overlap"] {
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.3) !important;
  background-color: rgba(249, 115, 22, 0.15) !important;
  color: #f97316 !important;
}

/* No match highlighting - Red */
manual_label[data-iaa-match="no-match"],
auto_label[data-iaa-match="no-match"] {
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.3) !important;
  background-color: rgba(239, 68, 68, 0.15) !important;
  color: #ef4444 !important;
}

/* ==============================================
   IAA MODAL DISPLAY STYLES
   Results display in analysis modal
   ============================================== */

.iaa-section {
  margin-bottom: 24px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 12px;
  border: 1px solid var(--border);
}

.iaa-section h3 {
  margin: 0 0 12px 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
}

.iaa-method {
  padding: 12px;
  background: rgba(106, 163, 255, 0.1);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: 14px;
  color: var(--text);
  line-height: 1.6;
}

/* Summary Grid */
.iaa-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}

.iaa-summary-card {
  padding: 20px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  border: 2px solid transparent;
  text-align: center;
  transition: all 0.3s ease;
}

.iaa-summary-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.iaa-summary-card.exact {
  border-color: rgba(34, 197, 94, 0.3);
}

.iaa-summary-card.overlap {
  border-color: rgba(249, 115, 22, 0.3);
}

.iaa-summary-card.no-match {
  border-color: rgba(239, 68, 68, 0.3);
}

.iaa-summary-number {
  font-size: 32px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.iaa-summary-label {
  font-size: 14px;
  color: var(--sub);
  margin-bottom: 8px;
}

.iaa-summary-color {
  height: 4px;
  border-radius: 2px;
  margin: 0 auto;
  width: 60%;
}

.iaa-totals {
  display: flex;
  justify-content: space-around;
  padding: 12px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  font-size: 14px;
  color: var(--sub);
}

/* Metrics Display */
.iaa-metrics {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.iaa-metric-row {
  display: flex;
  justify-content: space-between;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  font-size: 14px;
}

.iaa-metric-label {
  color: var(--sub);
}

.iaa-metric-value {
  font-weight: 600;
  color: var(--accent);
  font-size: 16px;
}

/* Match List */
.iaa-matches-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 400px;
  overflow-y: auto;
  padding-right: 8px;
}

.iaa-match-item {
  background: rgba(255, 255, 255, 0.03);
  border-radius: 8px;
  overflow: hidden;
  transition: all 0.2s ease;
}

.iaa-match-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.iaa-match-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.2);
}

.iaa-match-badge {
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  color: white;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.iaa-match-overlap {
  font-size: 12px;
  color: var(--sub);
  font-weight: 600;
}

.iaa-match-details {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.iaa-match-side {
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
}

.iaa-match-side strong {
  color: var(--accent);
  margin-right: 8px;
}

.iaa-match-text {
  color: var(--sub);
  font-style: italic;
  margin-left: 4px;
}

/* Light theme adjustments */
:root[data-theme="light"] .iaa-section {
  background: rgba(0, 0, 0, 0.02);
}

:root[data-theme="light"] .iaa-method {
  background: rgba(106, 163, 255, 0.1);
}

:root[data-theme="light"] .iaa-summary-card {
  background: #f8f9fa;
}

:root[data-theme="light"] .iaa-match-item {
  background: #f8f9fa;
}

:root[data-theme="light"] .iaa-match-item:hover {
  background: #e9ecef;
}

:root[data-theme="light"] .iaa-match-header {
  background: #e9ecef;
}

/* IAA Results Display - New Styles */
.iaa-results {
  padding: 10px;
}

.iaa-summary h3 {
  color: var(--accent);
  font-size: 20px;
  margin-bottom: 20px;
  text-align: center;
  font-weight: 600;
}

.metric-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 30px;
}

.metric-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  text-align: center;
  transition: all 0.3s ease;
}

.metric-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.metric-card.highlight {
  background: linear-gradient(135deg, var(--accent) 0%, #4a90e2 100%);
  border-color: var(--accent);
}

.metric-card.highlight .metric-label,
.metric-card.highlight .metric-value,
.metric-card.highlight .metric-subtitle {
  color: white;
}

.metric-label {
  font-size: 12px;
  color: var(--sub);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  font-weight: 600;
}

.metric-value {
  font-size: 28px;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 4px;
}

.metric-value.f1-score {
  font-size: 32px;
}

.metric-subtitle {
  font-size: 11px;
  color: var(--sub);
  margin-bottom: 8px;
}

.metric-percentage {
  font-size: 18px;
  color: var(--accent);
  font-weight: 600;
}

.metric-card.highlight .metric-percentage {
  color: rgba(255, 255, 255, 0.9);
  font-size: 16px;
  margin-top: 8px;
}

.iaa-details {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
}

.iaa-details h4 {
  color: var(--accent);
  font-size: 16px;
  margin-bottom: 12px;
  font-weight: 600;
}

.detail-text {
  color: var(--text);
  font-size: 14px;
  line-height: 1.8;
  margin: 0;
}

.match-list {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

.match-list h4 {
  color: var(--accent);
  font-size: 16px;
  margin-bottom: 16px;
  font-weight: 600;
}

.matches-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.match-item {
  display: flex;
  gap: 12px;
  padding: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: all 0.2s ease;
}

.match-item:hover {
  background: var(--hover);
  transform: translateX(4px);
}

.match-number {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--accent);
  color: white;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}

.match-content {
  flex: 1;
  min-width: 0;
}

.match-text {
  color: var(--text);
  font-size: 13px;
  line-height: 1.6;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.match-score {
  color: var(--sub);
  font-size: 11px;
}

.matches-note {
  margin-top: 12px;
  text-align: center;
  color: var(--sub);
  font-size: 12px;
  font-style: italic;
}

/* Light theme adjustments for new styles */
:root[data-theme="light"] .metric-card {
  background: #f8f9fa;
}

:root[data-theme="light"] .iaa-details,
:root[data-theme="light"] .match-list {
  background: #f8f9fa;
}

:root[data-theme="light"] .match-item {
  background: white;
}

:root[data-theme="light"] .match-item:hover {
  background: #f1f3f5;
}

/* Label Breakdown Table */
.label-breakdown {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
}

.label-breakdown h4 {
  color: var(--accent);
  font-size: 16px;
  margin-bottom: 16px;
  font-weight: 600;
}

.breakdown-table-container {
  overflow-x: auto;
  border-radius: 8px;
}

.breakdown-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.breakdown-table thead {
  background: var(--card);
  position: sticky;
  top: 0;
  z-index: 1;
}

.breakdown-table th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  color: var(--accent);
  border-bottom: 2px solid var(--border);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.5px;
}

.breakdown-table td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.breakdown-table tbody tr {
  transition: background 0.2s ease;
}

.breakdown-table tbody tr:hover {
  background: var(--hover);
}

.breakdown-table tbody tr.parent-label {
  background: rgba(255, 255, 255, 0.02);
}

.breakdown-table tbody tr.parent-label:hover {
  background: var(--hover);
}

.breakdown-table tbody tr.sublabel td {
  padding-left: 8px;
}

.breakdown-table .label-name {
  font-weight: 500;
}

.breakdown-table .label-name strong {
  color: var(--accent);
  font-weight: 700;
}

.breakdown-table .label-name .indent {
  color: var(--text);
  padding-left: 12px;
  display: inline-block;
}

.breakdown-table .count {
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.breakdown-table .f1-cell {
  padding: 8px 16px;
}

.f1-bar-container {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
  width: 100%;
}

.f1-bar {
  height: 20px;
  background: linear-gradient(90deg, var(--accent), #4a90e2);
  border-radius: 4px;
  transition: width 0.3s ease;
  min-width: 2px;
}

.f1-text {
  font-weight: 600;
  color: var(--text);
  font-size: 12px;
  min-width: 45px;
  text-align: right;
}

/* Light theme adjustments for table */
:root[data-theme="light"] .label-breakdown {
  background: #f8f9fa;
}

:root[data-theme="light"] .breakdown-table thead {
  background: #e9ecef;
}

:root[data-theme="light"] .breakdown-table tbody tr.parent-label {
  background: #f1f3f5;
}

:root[data-theme="light"] .breakdown-table tbody tr:hover {
  background: #dee2e6;
}

/* Full Screen Button */
.fullscreen-btn {
  background: var(--card) !important;
  border: 1px solid var(--border) !important;
  padding: 8px 14px !important;
  cursor: pointer !important;
  transition: all 0.2s ease !important;
  display: flex;
  align-items: center;
  justify-content: center;
}

.fullscreen-btn:hover {
  background: var(--hover) !important;
  border-color: var(--accent) !important;
}

.fullscreen-icon {
  width: 16px;
  height: 16px;
  display: block;
  filter: brightness(0) invert(1);
}
