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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #0f0f0f;
  color: #e0e0e0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

header {
  padding: 12px 20px;
  background: #1a1a1a;
  border-bottom: 1px solid #333;
  display: flex;
  align-items: center;
  gap: 24px;
  flex-shrink: 0;
}

header h1 {
  font-size: 18px;
  font-weight: 600;
  white-space: nowrap;
  color: #fff;
}

.upload-area {
  flex: 1;
  border: 2px dashed #444;
  border-radius: 8px;
  padding: 10px 20px;
  transition: border-color 0.2s, background 0.2s;
  cursor: pointer;
}

.upload-area.dragover {
  border-color: #5b9cf5;
  background: rgba(91, 156, 245, 0.08);
}

.upload-content {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.upload-icon { font-size: 20px; }

#image-status {
  font-size: 13px;
  color: #aaa;
}

.upload-actions {
  display: flex;
  gap: 8px;
}

.upload-btn {
  background: #2a5db0;
  color: #fff;
  border: none;
  padding: 5px 14px;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}
.upload-btn:hover { background: #3a6dc0; }

.reset-btn {
  background: #444;
  color: #ccc;
  border: none;
  padding: 5px 14px;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}
.reset-btn:hover { background: #555; }

.upload-hint {
  font-size: 12px;
  color: #666;
}

/* Class confidence bar */
.class-conf-bar {
  background: #1a1a1a;
  border-bottom: 1px solid #333;
  flex-shrink: 0;
}

.class-conf-toggle {
  width: 100%;
  padding: 6px 20px;
  background: none;
  border: none;
  color: #aaa;
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 8px;
}
.class-conf-toggle:hover { color: #fff; }

.toggle-arrow {
  font-size: 10px;
  transition: transform 0.2s;
}
.class-conf-toggle.open .toggle-arrow {
  transform: rotate(180deg);
}

.class-conf-panel {
  padding: 12px 20px;
  border-top: 1px solid #333;
}

.class-conf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 6px 24px;
}

.class-conf-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.class-name {
  width: 130px;
  font-size: 13px;
  color: #ccc;
  white-space: nowrap;
}

.class-slider {
  width: 100px;
  accent-color: #5b9cf5;
}

.class-input {
  width: 48px;
  background: #2a2a2a;
  color: #e0e0e0;
  border: 1px solid #444;
  border-radius: 4px;
  padding: 4px 6px;
  text-align: center;
  font-size: 13px;
}

.class-conf-actions {
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.global-conf-label {
  font-size: 13px;
  color: #ccc;
  font-weight: 600;
}

.global-slider {
  width: 120px;
  accent-color: #5b9cf5;
}

.global-input {
  width: 48px;
  background: #2a2a2a;
  color: #e0e0e0;
  border: 1px solid #444;
  border-radius: 4px;
  padding: 4px 6px;
  text-align: center;
  font-size: 13px;
}

.reset-conf-btn {
  background: #444;
  color: #ccc;
  border: none;
  padding: 5px 14px;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
}
.reset-conf-btn:hover { background: #555; }

.conf-pct {
  font-size: 13px;
  color: #888;
}

/* Main comparison */
.comparison {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 4px 1fr;
  min-height: 0;
}

.comparison .divider {
  background: #5b9cf5;
  cursor: col-resize;
  position: relative;
}

.comparison .divider::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 40px;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 1px;
  box-shadow: -4px 0 0 rgba(255, 255, 255, 0.3), 4px 0 0 rgba(255, 255, 255, 0.3);
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #111;
  border: 2px solid #333;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  background: #1a1a1a;
  border-bottom: 1px solid #333;
  font-size: 14px;
  font-weight: 600;
  color: #ccc;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

/* Mosaic display */
.mosaic-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0a0a0a;
  min-height: 0;
  overflow: auto;
}

.mosaic-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
  cursor: pointer;
}

/* Loading overlay */
.loading {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
  color: #ccc;
  gap: 12px;
}

.loading.active {
  display: flex;
}

.loading p {
  font-size: 14px;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #333;
  border-top-color: #5b9cf5;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Zoom overlay */
.zoom-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #0f0f0f;
  display: flex;
  flex-direction: column;
}

.zoom-overlay[hidden] {
  display: none;
}

.zoom-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: #1a1a1a;
  border-bottom: 1px solid #333;
  flex-shrink: 0;
}

.zoom-title {
  font-size: 16px;
  font-weight: 600;
  color: #fff;
}

.zoom-close {
  background: #c0392b;
  color: #fff;
  border: none;
  padding: 6px 16px;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
}
.zoom-close:hover { background: #e74c3c; }

.zoom-comparison {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  min-height: 0;
  padding: 4px;
}

.zoom-panel {
  display: flex;
  flex-direction: column;
  background: #111;
  border: 1px solid #333;
  border-radius: 4px;
  overflow: hidden;
  min-height: 0;
}

.zoom-panel-label {
  padding: 6px 12px;
  background: #1a1a1a;
  border-bottom: 1px solid #333;
  font-size: 14px;
  font-weight: 600;
  color: #ccc;
  text-align: center;
  flex-shrink: 0;
}

.zoom-img-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0a0a0a;
  min-height: 0;
}

.zoom-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* Responsive */
@media (max-width: 900px) {
  .comparison {
    grid-template-columns: 1fr;
  }
  .comparison .divider {
    height: 4px;
    width: 100%;
  }
  header {
    flex-direction: column;
    align-items: stretch;
  }
  .zoom-comparison {
    grid-template-columns: 1fr;
  }
}
