/* Annotation Studio - Label Studio Style */

:root {
  --studio-bg: #1a1a1a;
  --studio-sidebar-bg: #242424;
  --studio-toolbar-bg: #2a2a2a;
  --studio-border: #3a3a3a;
  --studio-text: #e0e0e0;
  --studio-text-muted: #888;
  --studio-accent: #4a9eff;
  --studio-accent-hover: #6bb0ff;
  --studio-success: #28a745;
  --studio-warning: #ffc107;
  --studio-danger: #dc3545;
}

/* Main Container */
body {
  margin: 0;
  padding: 0;
  overflow: hidden;
}

.annotation-studio {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--studio-bg);
  color: var(--studio-text);
  overflow: hidden;
  margin: 0;
  padding: 0;
}

/* Toolbar */
.studio-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: var(--studio-toolbar-bg);
  border-bottom: 1px solid var(--studio-border);
  height: 60px;
  flex-shrink: 0;
}

.toolbar-left,
.toolbar-center,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.toolbar-left {
  flex: 1;
}

.toolbar-center {
  flex: 0 0 auto;
}

.toolbar-right {
  flex: 1;
  justify-content: flex-end;
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  background: var(--studio-border);
  margin: 0 0.5rem;
}

.image-counter {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--studio-accent);
  padding: 0.25rem 1rem;
  background: rgba(74, 158, 255, 0.1);
  border-radius: 4px;
}

/* Content Area */
.studio-content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebars */
.studio-sidebar {
  display: flex;
  flex-direction: column;
  background: var(--studio-sidebar-bg);
  border-right: 1px solid var(--studio-border);
  overflow: hidden;
}

.studio-sidebar-left {
  width: 320px;
  flex-shrink: 0;
}

.studio-sidebar-right {
  width: 320px;
  flex-shrink: 0;
  border-right: none;
  border-left: 1px solid var(--studio-border);
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  border-bottom: 1px solid var(--studio-border);
}

.sidebar-header h6 {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--studio-text-muted);
}

/* Image Table View */
.image-table-view {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.image-table-view .table {
  margin: 0;
  font-size: 0.75rem;
}

.image-table-view thead th {
  position: sticky;
  top: 0;
  background: var(--studio-toolbar-bg);
  border-bottom: 1px solid var(--studio-border);
  padding: 0.4rem 0.3rem;
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.65rem;
  letter-spacing: 0.5px;
  z-index: 10;
}

.image-table-view tbody tr {
  cursor: pointer;
  border-bottom: 1px solid var(--studio-border);
  transition: background-color 0.2s;
}

.image-table-view tbody tr:hover {
  background-color: rgba(255, 255, 255, 0.05);
}

.image-table-view tbody tr.active {
  background-color: rgba(74, 158, 255, 0.2);
  border-left: 3px solid var(--studio-accent);
}

.image-table-view tbody td {
  padding: 0.4rem 0.3rem;
  vertical-align: middle;
  border: none;
  font-size: 0.75rem;
}

.image-table-view .table-thumbnail {
  width: 45px;
  height: 30px;
  object-fit: cover;
  border-radius: 2px;
  border: 1px solid var(--studio-border);
  display: block;
}

.image-table-view .annotation-count {
  display: inline-block;
  min-width: 20px;
  text-align: center;
  padding: 0.125rem 0.375rem;
  background: rgba(74, 158, 255, 0.2);
  border-radius: 3px;
  font-size: 0.7rem;
  font-weight: 600;
}

.image-table-view .annotation-count.zero {
  background: rgba(255, 255, 255, 0.1);
  color: var(--studio-text-muted);
}

.image-table-view .image-id {
  font-family: monospace;
  color: var(--studio-text-muted);
  font-size: 0.7rem;
}

.image-table-view .upload-time {
  font-size: 0.7rem;
  color: var(--studio-text-muted);
  white-space: nowrap;
}

.image-table-view tbody tr.active .image-id,
.image-table-view tbody tr.active .upload-time {
  color: var(--studio-text);
}

.image-table-view tbody tr.active .annotation-count {
  background: var(--studio-accent);
  color: white;
}

/* Thumbnail Gallery */
.thumbnail-gallery {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

.thumbnail-item {
  position: relative;
  margin-bottom: 0.5rem;
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: 4px;
  overflow: hidden;
  transition: all 0.2s;
}

.thumbnail-item:hover {
  border-color: var(--studio-accent);
  transform: translateX(4px);
}

.thumbnail-item.active {
  border-color: var(--studio-accent);
  box-shadow: 0 0 0 2px rgba(74, 158, 255, 0.3);
}

.thumbnail-item img {
  width: 100%;
  height: 100px;
  object-fit: cover;
  display: block;
}

.thumbnail-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
  padding: 0.5rem;
  font-size: 0.75rem;
}

.thumbnail-status {
  position: absolute;
  top: 0.25rem;
  right: 0.25rem;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--studio-success);
}

.thumbnail-status.processing {
  background: var(--studio-warning);
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Canvas Container */
.studio-canvas,
.studio-canvas-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--studio-bg);
}

.canvas-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1rem;
  background: var(--studio-toolbar-bg);
  border-bottom: 1px solid var(--studio-border);
  height: 50px;
  flex-shrink: 0;
}

.canvas-tools {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.canvas-info {
  font-size: 0.875rem;
  color: var(--studio-text-muted);
}

.canvas-wrapper {
  position: relative;
  flex: 1;
  overflow: auto; /* Allow scrolling for zoomed images */
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--studio-bg);
  min-height: 0; /* Important for flex child */
}

#annotationCanvas {
  display: block;
  image-rendering: crisp-edges;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
}

.canvas-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

#annotationSvg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: all;
}

.canvas-empty-state {
  text-align: center;
  color: var(--studio-text-muted);
}

.processing-indicator {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  background: rgba(0, 0, 0, 0.8);
  padding: 2rem;
  border-radius: 8px;
}

/* Label Studio Embedded Container */
.label-studio-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--studio-bg);
  z-index: 900;
  display: flex;
  flex-direction: column;
}

.label-studio-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: var(--studio-toolbar-bg);
  border-bottom: 1px solid var(--studio-border);
}

.label-studio-header span {
  font-weight: 600;
  color: var(--studio-text);
}

.label-studio-header .btn {
  margin-left: 0.5rem;
}

#labelStudioFrame {
  flex: 1;
  width: 100%;
  border: none;
  background: white;
}

/* Processing Indicator */
.processing-indicator {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  background: rgba(0, 0, 0, 0.8);
  padding: 2rem;
  border-radius: 8px;
  z-index: 1000;
}

/* Right Sidebar Tabs */
.sidebar-tabs {
  border-bottom: 1px solid var(--studio-border);
  background: var(--studio-toolbar-bg);
}

.sidebar-tabs .nav-link {
  color: var(--studio-text-muted);
  border: none;
  border-bottom: 2px solid transparent;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
}

.sidebar-tabs .nav-link:hover {
  color: var(--studio-text);
  border-bottom-color: var(--studio-border);
}

.sidebar-tabs .nav-link.active {
  color: var(--studio-accent);
  background: transparent;
  border-bottom-color: var(--studio-accent);
}

.sidebar-content {
  flex: 1;
  overflow: hidden;
}

.tab-pane {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* Regions Panel */
.regions-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  border-bottom: 1px solid var(--studio-border);
}

.regions-header h6 {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
}

.regions-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

.region-item {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--studio-border);
  border-radius: 4px;
  padding: 0.75rem;
  margin-bottom: 0.5rem;
  cursor: pointer;
  transition: all 0.2s;
}

.region-item:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--studio-accent);
}

.region-item.selected {
  background: rgba(74, 158, 255, 0.15);
  border-color: var(--studio-accent);
}

.region-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.region-label {
  font-weight: 600;
  font-size: 0.875rem;
}

.region-confidence {
  font-size: 0.75rem;
  color: var(--studio-text-muted);
}

.region-actions {
  display: flex;
  gap: 0.25rem;
}

.region-actions .btn {
  padding: 0.125rem 0.375rem;
  font-size: 0.75rem;
}

.region-coords {
  font-size: 0.75rem;
  color: var(--studio-text-muted);
  font-family: monospace;
}

/* Hotkeys Panel */
.hotkeys-content {
  padding: 1rem;
  overflow-y: auto;
}

.hotkeys-section {
  margin-bottom: 1.5rem;
}

.hotkeys-section h6 {
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--studio-text-muted);
  margin-bottom: 0.75rem;
}

.hotkey-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.hotkey-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 4px;
  font-size: 0.8rem;
  transition: background 0.2s;
}

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

.hotkey-keys {
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
}

.hotkey-desc {
  color: var(--studio-text-muted);
  text-align: right;
  font-size: 0.75rem;
}

.hotkey-item kbd {
  min-width: 24px;
  text-align: center;
}

/* Quick label specific styling */
.hotkey-quick-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.35rem 0.5rem;
  background: rgba(74, 158, 255, 0.05);
  border: 1px solid rgba(74, 158, 255, 0.2);
  border-radius: 4px;
  font-size: 0.75rem;
  transition: all 0.2s;
  cursor: move;
  position: relative;
}

.hotkey-quick-item:hover {
  background: rgba(74, 158, 255, 0.1);
  border-color: rgba(74, 158, 255, 0.4);
}

.hotkey-quick-item.dragging {
  opacity: 0.5;
}

.hotkey-quick-item.drag-over {
  border-color: var(--studio-accent);
  background: rgba(74, 158, 255, 0.2);
}

.hotkey-quick-remove {
  position: absolute;
  top: 0.25rem;
  right: 0.25rem;
  width: 16px;
  height: 16px;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(220, 53, 69, 0.8);
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.65rem;
  color: white;
}

.hotkey-quick-item:hover .hotkey-quick-remove {
  display: flex;
}

.hotkey-quick-key {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.hotkey-quick-key kbd {
  background: rgba(74, 158, 255, 0.2);
  border-color: var(--studio-accent);
  color: var(--studio-accent);
  font-weight: 600;
  min-width: 24px;
  font-size: 0.7rem;
  padding: 0.1rem 0.25rem;
}

.hotkey-quick-label {
  font-weight: 500;
  color: var(--studio-text);
  font-size: 0.75rem;
}

.hotkey-desc {
  font-size: 0.7rem;
}

/* All Classes List */
.all-classes-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.4rem;
  max-height: 300px;
  overflow-y: auto;
}

.class-badge {
  display: flex;
  flex-direction: column;
  padding: 0.4rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--studio-border);
  border-radius: 4px;
  font-size: 0.7rem;
  transition: all 0.2s;
  cursor: move;
  position: relative;
}

.class-badge:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--studio-accent);
  transform: translateY(-1px);
}

.class-badge.dragging {
  opacity: 0.5;
}

.class-badge.in-quick-labels {
  opacity: 0.3;
  pointer-events: none;
}

.class-badge-code {
  font-weight: 600;
  color: var(--studio-accent);
  font-size: 0.75rem;
  margin-bottom: 0.2rem;
}

.class-badge-label {
  color: var(--studio-text-muted);
  font-size: 0.65rem;
  line-height: 1.2;
}

.class-badge-index {
  position: absolute;
  top: 0.25rem;
  right: 0.25rem;
  font-size: 0.65rem;
  color: var(--studio-text-muted);
  opacity: 0.5;
}

/* Info Panel */
.info-content {
  padding: 1rem;
  overflow-y: auto;
}

.info-section {
  margin-bottom: 1.5rem;
}

.info-section h6 {
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--studio-text-muted);
  margin-bottom: 0.75rem;
}

.info-item {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--studio-border);
  font-size: 0.875rem;
}

.info-label {
  color: var(--studio-text-muted);
}

.info-value {
  font-weight: 500;
  text-align: right;
}

/* Status Bar */
.studio-statusbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1rem;
  background: var(--studio-toolbar-bg);
  border-top: 1px solid var(--studio-border);
  height: 40px;
  flex-shrink: 0;
  font-size: 0.875rem;
}

.statusbar-left,
.statusbar-center,
.statusbar-right {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.statusbar-left {
  flex: 1;
}

.statusbar-center {
  flex: 0 0 auto;
}

.statusbar-right {
  flex: 1;
  justify-content: flex-end;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  color: var(--studio-text-muted);
}

.hotkey-hint {
  background: rgba(74, 158, 255, 0.1);
  padding: 0.25rem 0.75rem;
  border-radius: 4px;
  border: 1px solid rgba(74, 158, 255, 0.3);
  color: var(--studio-accent);
  font-size: 0.8rem;
  animation: fadeIn 0.3s ease-in;
}

.hotkey-hint kbd {
  background: rgba(74, 158, 255, 0.2);
  border-color: var(--studio-accent);
  color: var(--studio-accent);
  font-size: 0.75rem;
  padding: 0.1rem 0.3rem;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Upload Modal */
.upload-zone {
  border: 2px dashed var(--studio-border);
  border-radius: 8px;
  padding: 3rem;
  text-align: center;
  transition: all 0.3s;
  cursor: pointer;
}

.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--studio-accent);
  background: rgba(74, 158, 255, 0.05);
}

.upload-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 4px;
  margin-bottom: 0.5rem;
}

.upload-item-name {
  flex: 1;
  font-size: 0.875rem;
}

.upload-item-progress {
  width: 100px;
}

/* Buttons */
.btn-outline-light {
  color: var(--studio-text);
  border-color: var(--studio-border);
  background: transparent;
}

.btn-outline-light:hover {
  color: var(--studio-text);
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--studio-text-muted);
}

/* Modal Overrides */
.modal-content {
  background: var(--studio-sidebar-bg);
  color: var(--studio-text);
  border: 1px solid var(--studio-border);
}

.modal-header {
  border-bottom-color: var(--studio-border);
}

.modal-footer {
  border-top-color: var(--studio-border);
}

.btn-close {
  filter: invert(1);
}

/* Scrollbar Styling */
.thumbnail-gallery::-webkit-scrollbar,
.regions-list::-webkit-scrollbar,
.hotkeys-content::-webkit-scrollbar,
.all-classes-list::-webkit-scrollbar,
.info-content::-webkit-scrollbar,
.image-table-view::-webkit-scrollbar,
.canvas-wrapper::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.thumbnail-gallery::-webkit-scrollbar-track,
.regions-list::-webkit-scrollbar-track,
.hotkeys-content::-webkit-scrollbar-track,
.all-classes-list::-webkit-scrollbar-track,
.info-content::-webkit-scrollbar-track,
.image-table-view::-webkit-scrollbar-track,
.canvas-wrapper::-webkit-scrollbar-track {
  background: var(--studio-bg);
}

.thumbnail-gallery::-webkit-scrollbar-thumb,
.regions-list::-webkit-scrollbar-thumb,
.hotkeys-content::-webkit-scrollbar-thumb,
.all-classes-list::-webkit-scrollbar-thumb,
.info-content::-webkit-scrollbar-thumb,
.image-table-view::-webkit-scrollbar-thumb,
.canvas-wrapper::-webkit-scrollbar-thumb {
  background: var(--studio-border);
  border-radius: 4px;
}

.thumbnail-gallery::-webkit-scrollbar-thumb:hover,
.regions-list::-webkit-scrollbar-thumb:hover,
.hotkeys-content::-webkit-scrollbar-thumb:hover,
.all-classes-list::-webkit-scrollbar-thumb:hover,
.info-content::-webkit-scrollbar-thumb:hover,
.image-table-view::-webkit-scrollbar-thumb:hover,
.canvas-wrapper::-webkit-scrollbar-thumb:hover {
  background: var(--studio-text-muted);
}

/* Keyboard Shortcuts Table */
.table {
  color: var(--studio-text);
}

.table td {
  border-color: var(--studio-border);
  padding: 0.5rem;
}

kbd {
  background: var(--studio-toolbar-bg);
  border: 1px solid var(--studio-border);
  border-radius: 3px;
  padding: 0.125rem 0.375rem;
  font-size: 0.875rem;
  color: var(--studio-text);
}

/* Responsive */
@media (max-width: 1400px) {
  .studio-sidebar-left {
    width: 280px;
  }
  
  .studio-sidebar-right {
    width: 280px;
  }
}

@media (max-width: 1200px) {
  .studio-sidebar-left {
    width: 240px;
  }
  
  .studio-sidebar-right {
    width: 260px;
  }
  
  .image-table-view .upload-time {
    font-size: 0.65rem;
  }
}

@media (max-width: 992px) {
  .studio-sidebar-left {
    width: 200px;
  }
  
  .thumbnail-item img {
    height: 80px;
  }
  
  .image-table-view thead th {
    font-size: 0.65rem;
    padding: 0.4rem 0.2rem;
  }
  
  .image-table-view tbody td {
    padding: 0.4rem 0.2rem;
  }
}

/* Annotations on Canvas */
.annotation-box {
  fill: none;
  stroke-width: 2;
  cursor: pointer;
  transition: stroke-width 0.2s;
}

.annotation-box:hover {
  stroke-width: 3;
}

.annotation-box.selected {
  stroke-width: 3;
  stroke-dasharray: 5, 5;
  animation: dash 0.5s linear infinite;
}

@keyframes dash {
  to {
    stroke-dashoffset: -10;
  }
}

.annotation-label {
  font-size: 12px;
  font-weight: 600;
  fill: white;
  pointer-events: none;
}

.annotation-label-bg {
  fill: rgba(0, 0, 0, 0.7);
  pointer-events: none;
}

/* Loading States */
.spinner-border-sm {
  width: 1rem;
  height: 1rem;
  border-width: 0.15rem;
}

/* Compression Options */
#compressionOptions {
  animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
  from {
    opacity: 0;
    max-height: 0;
  }
  to {
    opacity: 1;
    max-height: 100px;
  }
}
