:root {
  --bg: white;
  --fg: black;
  --bg-secondary: #f8f9fa;
  --border: #ddd;
  --btn-bg: #3498db;
  --btn-fg: white;
  --verified: #16803c;
  --verified-bg: #e8f7ed;
  --invalid: #c53030;
  --invalid-bg: #fff0f0;
}

:root.dark {
  --bg: #222;
  --fg: #eee;
  --bg-secondary: #2a2a2a;
  --border: #444;
  --btn-bg: #505050;
  --btn-fg: #e0e0e0;
  --verified: #6edb91;
  --verified-bg: #183a25;
  --invalid: #ff8585;
  --invalid-bg: #462323;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  margin: 0;
  padding: 20px;
  background: var(--bg) !important;
  color: var(--fg) !important;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  background-color: var(--bg) !important;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

html.dark .container {
  box-shadow: 0 2px 10px rgba(0,0,0,0.7);
}

html:not(.dark) .container {
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

h1 {
  color: #2c3e50;
  text-align: center;
  margin-bottom: 30px;
}

.controls {
  display: flex;
  justify-content: center;
  gap: 15px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

html.dark .controls button {
  border: 1px solid var(--border) !important;
}

html.dark .controls button:hover {
  background-color: #505050;
}

html:not(.dark) .controls button {
  border: 1px solid var(--border) !important;
}

input[type="file"] {
  padding: 8px 15px;
  border: 1px solid var(--border) !important;
  border-radius: 4px;
  background-color: var(--bg) !important;
  color: var(--fg) !important;
}

html.dark input[type="file"] {
  border: 1px solid var(--border) !important;
}

html:not(.dark) input[type="file"] {
  border: 1px solid var(--border) !important;
}

.filter-container {
  position: relative;
  margin-bottom: 15px;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.search-wrapper {
  position: relative;
  display: flex;
  flex: 1 1 360px;
  align-items: center;
}

.filter-input {
  flex: 1;
  padding: 10px 40px 10px 15px;
  border: 1px solid var(--border) !important;
  border-radius: 4px 0 0 4px;
  background-color: var(--bg) !important;
  color: var(--fg) !important;
  font-size: 14px;
  box-sizing: border-box;
}

.filter-input:focus {
  outline: none;
  border-color: #3498db;
  box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

.filter-icon {
  position: absolute;
  right: 50px;
  top: 50%;
  transform: translateY(-50%);
  color: #888;
  pointer-events: none;
}

.status-filter-label {
  font-size: 12px;
  font-weight: 600;
}

.status-filter {
  padding: 9px 28px 9px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--fg);
}

.keyboard-hint {
  color: #777;
  font-size: 11px;
  white-space: nowrap;
}

kbd {
  padding: 1px 4px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg-secondary);
  color: var(--fg);
  font-family: inherit;
  font-size: 10px;
}

.clear-filter-btn {
  padding: 10px 15px;
  border: 1px solid var(--border) !important;
  border-left: none;
  border-radius: 0 4px 4px 0;
  background-color: var(--btn-bg) !important;
  color: var(--btn-fg) !important;
  cursor: pointer;
  transition: background-color 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
}

.clear-filter-btn:hover {
  background-color: #2980b9 !important;
}

.clear-filter-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background-color: #ccc !important;
}

html.dark .clear-filter-btn:disabled {
  background-color: #555 !important;
}

html.dark .filter-input {
  border: 1px solid var(--border) !important;
  background-color: var(--bg) !important;
  color: var(--fg) !important;
}

html:not(.dark) .filter-input {
  border: 1px solid var(--border) !important;
  background-color: var(--bg) !important;
  color: var(--fg) !important;
}

button {
  padding: 8px 15px;
  background-color: var(--btn-bg) !important;
  color: var(--btn-fg) !important;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.3s;
}

button:hover {
  background-color: #2980b9;
}

.drop-zone {
  border: 2px dashed var(--border) !important;
  border-radius: 6px;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  margin-bottom: 10px;
  background-color: var(--bg) !important;
}

html.dark .drop-zone {
  border-color: var(--border) !important;
}

html:not(.dark) .drop-zone {
  border-color: var(--border) !important;
}

.drop-zone.hover {
  border-color: #888;
}

.table-container {
  overflow-x: auto;
  overflow-y: visible;
  margin-top: 20px;
  border: 1px solid var(--border) !important;
  border-radius: 4px;
  max-height: none;
}

.review-summary {
  display: flex;
  align-items: stretch;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  position: sticky;
  left: 0;
}

.review-summary[hidden] {
  display: none;
}

.review-metric {
  min-width: 92px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}

.review-metric-label {
  display: block;
  margin-bottom: 3px;
  color: #777;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.accuracy-metric strong {
  font-size: 20px;
}

.verified-metric strong {
  color: var(--verified);
}

.invalid-metric strong {
  color: var(--invalid);
}

.review-actions {
  margin-left: auto;
  align-self: center;
  display: flex;
  gap: 8px;
}

.approve-all-btn,
.export-reviews-btn,
.clear-reviews-btn {
  white-space: nowrap;
}

.approve-all-btn {
  background-color: var(--verified) !important;
  color: white !important;
}

.approve-all-btn i,
.export-reviews-btn i {
  margin-right: 5px;
}

.approve-all-btn:disabled,
.export-reviews-btn:disabled,
.clear-reviews-btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.save-status {
  align-self: center;
  color: #777;
  font-size: 11px;
  white-space: nowrap;
}

html.dark .table-container {
  border: 1px solid var(--border) !important;
}

html:not(.dark) .table-container {
  border: 1px solid var(--border) !important;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th, td {
  padding: 7px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border) !important;
}

.review-column {
  width: 104px;
  min-width: 104px;
  text-align: center;
  position: sticky;
  left: 0;
  z-index: 2;
  background-color: var(--bg) !important;
}

.review-controls {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.review-btn {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--border);
  background: var(--bg) !important;
  color: #888 !important;
}

.review-btn:hover {
  transform: translateY(-1px);
}

.verified-btn:hover,
.verified-btn.active {
  border-color: var(--verified);
  background: var(--verified) !important;
  color: white !important;
}

.invalid-btn:hover,
.invalid-btn.active {
  border-color: var(--invalid);
  background: var(--invalid) !important;
  color: white !important;
}

.note-btn:hover,
.note-btn.active {
  border-color: #b7791f;
  background: #b7791f !important;
  color: white !important;
}

.reset-review-btn:hover {
  border-color: #777;
  background: #777 !important;
  color: white !important;
}

.inline-review-note {
  display: inline-block;
  max-width: 320px;
  margin-left: 8px;
  padding: 2px 6px;
  overflow: hidden;
  border: 1px solid var(--invalid);
  border-radius: 10px;
  background: var(--invalid-bg);
  color: var(--invalid);
  font-size: 11px;
  text-overflow: ellipsis;
  vertical-align: middle;
  white-space: nowrap;
}

tr.active-review-row,
tr:focus {
  outline: 2px solid #3498db;
  outline-offset: -2px;
}

tr.review-verified td {
  background-color: var(--verified-bg);
}

tr.review-invalid td {
  background-color: var(--invalid-bg);
}

tr.review-verified td:first-child {
  box-shadow: inset 4px 0 var(--verified);
}

tr.review-invalid td:first-child {
  box-shadow: inset 4px 0 var(--invalid);
}

html.dark th {
  background-color: var(--bg-secondary) !important;
  color: var(--fg) !important;
}

html:not(.dark) th {
  background-color: var(--bg-secondary) !important;
  color: var(--fg) !important;
}

th {
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  position: relative;
  background-color: var(--bg-secondary) !important;
  color: var(--fg) !important;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  box-shadow: 0 1px 0 var(--border);
}

thead th.review-column {
  z-index: 4;
  background-color: var(--bg-secondary) !important;
}

th:hover {
  background-color: #e9ecef;
}

th.sorted-asc::after {
  content: '\2191';
  margin-left: 5px;
  font-size: 12px;
}

th.sorted-desc::after {
  content: '\2193';
  margin-left: 5px;
  font-size: 12px;
}

tr:hover {
  background-color: var(--bg-secondary) !important;
}

html.dark tr:hover {
  background-color: var(--bg-secondary) !important;
}

html:not(.dark) tr:hover {
  background-color: var(--bg-secondary) !important;
}

.expand-btn {
  background: none;
  border: none;
  color: #3498db;
  cursor: pointer;
  font-size: 16px;
  padding: 0 5px;
}

.nested-table {
  width: 100%;
  margin: 10px 0;
  background-color: var(--bg-secondary) !important;
  border: 1px solid var(--border) !important;
  border-radius: 4px;
}

html.dark .nested-table {
  background-color: var(--bg-secondary) !important;
  border-color: var(--border) !important;
}

html:not(.dark) .nested-table {
  background-color: var(--bg-secondary) !important;
  border-color: var(--border) !important;
}

.nested-table th {
  background-color: #e9ecef;
}

.diff-highlight {
  background-color: rgba(255, 0, 0, 0.1);
}

.diff-present {
  background-color: #ffe5e5 !important;
  color: #c0392b;
}

.json-value {
  white-space: pre-wrap;
  word-break: break-word;
}

.json-object, .json-array {
  background-color: var(--bg-secondary) !important;
  padding: 10px;
  border-radius: 4px;
  border-left: 3px solid #3498db;
  margin: 5px 0;
}

.json-string {
  color: #2ecc71;
}

.json-number {
  color: #e74c3c;
}

.json-boolean {
  color: #9b59b6;
}

.json-null {
  color: #7f8c8d;
}

.json-key {
  color: #3498db;
  font-weight: bold;
}

.json-brace {
  color: #2c3e50;
}

.clickable-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  background-color: #eaf4ff;
  padding: 5px;
  border-radius: 4px;
  color: #3498db;
  text-decoration: underline;
  cursor: pointer;
}

.clickable-title:hover {
  background-color: #d0e8ff;
  color: #2980b9;
}

.clickable-title span:first-child {
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.clickable-title span#secondaryToggleDiff {
  flex: none;
  margin-left: 10px;
  white-space: nowrap;
}

.btn {
  display: inline-block;
  padding: 8px 15px;
  background-color: var(--btn-bg) !important;
  color: var(--btn-fg) !important;
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
}

.btn:hover {
  background-color: #2980b9;
}

.instructions {
  text-align: center;
  margin-bottom: 20px;
}

.error-message {
  margin: 10px 0;
  padding: 10px 12px;
  border: 1px solid var(--invalid);
  border-radius: 4px;
  background: var(--invalid-bg);
  color: var(--invalid);
}

.error-message[hidden] {
  display: none;
}

.toggle-extra {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

/* Toggle switch */
.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 24px;
}
/* Hide default checkbox */
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: 0.4s;
}
.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.4s;
  border-radius: 50%;
}
input:checked + .slider {
  background-color: #3498db;
}
input:checked + .slider:before {
  transform: translateX(26px);
}
/* Rounded slider */
.slider.round {
  border-radius: 24px;
}

/* FORCE THEME VARIABLES ON COMPONENTS */
body,
.container,
.other-data {
  background-color: var(--bg) !important;
  color: var(--fg) !important;
}
.controls button,
.btn {
  background-color: var(--btn-bg) !important;
  color: var(--btn-fg) !important;
  border: 1px solid var(--border) !important;
}
input[type="file"],
.drop-zone {
  background-color: var(--bg) !important;
  color: var(--fg) !important;
  border: 1px solid var(--border) !important;
}
.table-container,
.nested-table {
  background-color: var(--bg) !important;
  border: 1px solid var(--border) !important;
}
th,
tr:hover {
  background-color: var(--bg-secondary) !important;
  color: var(--fg) !important;
}
td {
  border-bottom: 1px solid var(--border) !important;
  color: var(--fg) !important;
}

/* FINAL OVERRIDE: ensure base elements use theme vars */
html,
body,
.container,
.table-container,
.other-data,
.drop-zone {
  background-color: var(--bg) !important;
  color: var(--fg) !important;
}

@media (prefers-color-scheme: dark) {
  /* Optional fallback for browsers not supporting JS */
  body {
    background: #222;
    color: #eee;
  }
}

@media (max-width: 720px) {
  .review-summary {
    flex-wrap: wrap;
  }

  .review-metric {
    box-sizing: border-box;
    flex: 1 1 calc(50% - 10px);
  }

  .review-actions {
    margin-left: 0;
    width: 100%;
  }

  .approve-all-btn,
  .export-reviews-btn,
  .clear-reviews-btn {
    flex: 1;
  }

  .keyboard-hint {
    display: none;
  }
}
