/* Curated modern theme for Box & Center Annotation Studio */

:root {
  --font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  
  /* Light Theme Variables */
  --bg-app: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-hover: #f1f5f9;
  --border-color: #e2e8f0;
  --border-color-active: #cbd5e1;
  --text-main: #0f172a;
  --text-muted: #64748b;
  
  --primary: #5b21b6;
  --primary-hover: #4c1d95;
  --primary-contrast: #ffffff;
  --accent: #2563eb;
  
  --success: #16a34a;
  --warning: #ea580c;
  --danger: #dc2626;
  --info: #0284c7;
  
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  
  --focus-ring: 0 0 0 3px rgba(91, 33, 182, 0.4);
  --border-radius: 8px;
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

/* Dark Theme Variables */
[data-theme="dark"] {
  --bg-app: #0f172a;
  --bg-surface: #1e293b;
  --bg-surface-hover: #334155;
  --border-color: #334155;
  --border-color-active: #475569;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  
  --primary: #8b5cf6;
  --primary-hover: #a78bfa;
  --primary-contrast: #0f172a;
  --accent: #3b82f6;
  
  --success: #22c55e;
  --warning: #f97316;
  --danger: #ef4444;
  --info: #38bdf8;
  
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.5);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.4), 0 2px 4px -2px rgb(0 0 0 / 0.4);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4), 0 4px 6px -4px rgb(0 0 0 / 0.4);
  
  --focus-ring: 0 0 0 3px rgba(139, 92, 246, 0.4);
}

/* Base resets */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-app);
  color: var(--text-main);
  font-family: var(--font-family);
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;
  transition: background-color var(--transition-normal), color var(--transition-normal);
}

/* Layout Containers */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Headers and Toolbars */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  z-index: 10;
  flex-shrink: 0;
}

.app-title {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.toolbar-group {
  display: flex;
  gap: 8px;
  align-items: center;
}

.autosave-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
  white-space: nowrap;
  cursor: pointer;
}

#import-conflict-list .coord-row {
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
}

#import-conflict-list .coord-row .meta {
  overflow-wrap: anywhere;
}

/* Buttons styling */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface);
  color: var(--text-main);
  font-family: var(--font-family);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
}

.btn:hover {
  background-color: var(--bg-surface-hover);
  border-color: var(--border-color-active);
}

.btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background-color: var(--primary);
  border-color: var(--primary);
  color: var(--primary-contrast);
}

.btn-primary:hover {
  background-color: var(--primary-hover);
  border-color: var(--primary-hover);
  color: var(--primary-contrast);
}

.btn-danger {
  background-color: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}

.btn-danger:hover {
  background-color: #b91c1c;
  border-color: #b91c1c;
}

.btn-icon {
  padding: 8px;
  min-width: 38px;
}

.btn-toggle[aria-pressed="true"] {
  background-color: var(--primary);
  border-color: var(--primary);
  color: var(--primary-contrast);
}

.btn-group {
  display: inline-flex;
  border-radius: var(--border-radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.btn-group .btn {
  border-radius: 0;
}

.btn-group .btn:not(:last-child) {
  border-right: none;
}

.btn-group-vertical {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

/* Secondary Toolbar */
.toolbar-secondary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  padding: 10px 24px;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.toolbar-section {
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-label {
  font-weight: 550;
  color: var(--text-muted);
}

select {
  padding: 8px 12px;
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface);
  color: var(--text-main);
  font-family: var(--font-family);
  font-weight: 500;
  outline: none;
}

select:focus {
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}

/* Status Bar */
.status-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 20px;
  padding: 8px 24px;
  background-color: var(--bg-surface-hover);
  border-bottom: 1px solid var(--border-color);
  font-size: 0.85rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-label {
  font-weight: 600;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
}

.badge-warning {
  background-color: rgba(234, 88, 12, 0.15);
  color: var(--warning);
}

.badge-error {
  background-color: rgba(220, 38, 38, 0.15);
  color: var(--danger);
}

/* Main Image Grid Container */
.grid-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: grid;
  gap: 20px;
  grid-template-columns: repeat(var(--grid-cols, 2), minmax(0, 1fr));
  grid-template-rows: repeat(var(--grid-rows, 2), minmax(0, 1fr));
  align-content: start;
}

/* Image Tile */
.image-tile {
  background-color: var(--bg-surface);
  border: 2px solid var(--border-color);
  border-radius: var(--border-radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-normal);
  aspect-ratio: 4 / 3;
}

.image-tile.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary), var(--shadow-md);
}

.tile-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background-color: var(--bg-surface-hover);
  border-bottom: 1px solid var(--border-color);
  font-size: 0.8rem;
  flex-shrink: 0;
}

.tile-title {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60%;
  color: var(--text-main);
}

.tile-meta {
  color: var(--text-muted);
  font-family: monospace;
}

.tile-body {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #000000;
}

.tile-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

.tile-overlay-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.tile-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-top: 1px solid var(--border-color);
  background-color: var(--bg-surface);
  font-size: 0.8rem;
  flex-shrink: 0;
}

.tile-badges {
  display: flex;
  gap: 6px;
  align-items: center;
}

.task-badge {
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 500;
}

.task-badge.pending {
  background-color: var(--border-color);
  color: var(--text-muted);
}

.task-badge.completed {
  background-color: rgba(22, 163, 74, 0.15);
  color: var(--success);
}

.task-badge.negative, .task-badge.not_visible {
  background-color: rgba(220, 38, 38, 0.15);
  color: var(--danger);
}

.task-badge.skipped {
  background-color: rgba(2, 132, 199, 0.15);
  color: var(--info);
}

.tile-error-badge {
  background-color: var(--danger);
  color: #ffffff;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  cursor: pointer;
}

/* Footer Section */
.app-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 24px;
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  font-size: 0.8rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.app-footer .help-text {
  font-weight: 400;
}

.app-footer .disclaimer {
  font-style: italic;
  font-weight: 500;
  text-align: right;
  max-width: 50%;
}

/* Modals general styling */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.2s ease-out;
}

.modal-content {
  background-color: var(--bg-surface);
  border-radius: 12px;
  border: 1px solid var(--border-color);
  width: 90%;
  max-width: 600px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: var(--shadow-lg);
  max-height: 85vh;
}

.modal-content h2 {
  font-size: 1.25rem;
  font-weight: 600;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 12px;
}

.modal-scroll-area {
  overflow-y: auto;
  flex: 1;
  padding-right: 6px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  border-top: 1px solid var(--border-color);
  padding-top: 16px;
}

/* Focus Modal Details */
.focus-modal .modal-content.focus-content {
  width: 96vw;
  height: 94vh;
  max-width: none;
  max-height: none;
  padding: 0;
  overflow: hidden;
}

.focus-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background-color: var(--bg-surface-hover);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.focus-header h2 {
  border-bottom: none;
  padding-bottom: 0;
  font-size: 1.15rem;
}

.focus-header .meta {
  color: var(--text-muted);
  font-family: monospace;
}

.btn-close {
  background: none;
  border: none;
  font-size: 1.75rem;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  padding: 0 8px;
}

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

.focus-body {
  display: flex;
  flex: 1;
  min-height: 0;
}

.focus-viewport {
  flex: 1;
  background-color: #000000;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.focus-viewport canvas {
  cursor: crosshair;
  display: block;
}

.focus-sidebar {
  width: 320px;
  background-color: var(--bg-surface);
  border-left: 1px solid var(--border-color);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
  flex-shrink: 0;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-section h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sidebar-section h4 {
  font-size: 0.85rem;
  font-weight: 550;
  margin-bottom: 4px;
}

.separator {
  height: 1px;
  background-color: var(--border-color);
  margin: 8px 0;
}

.task-status-group select {
  width: 100%;
}

.meta {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* Coordinate editor inputs */
#focus-coordinate-editor {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background-color: var(--bg-surface-hover);
  padding: 12px;
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
}

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

.coord-row label {
  width: 24px;
  font-weight: 600;
  color: var(--text-muted);
}

.coord-row input[type="number"] {
  width: 70px;
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface);
  color: var(--text-main);
}

.coord-row select {
  flex: 1;
  padding: 4px 8px;
}

/* Loupe Overlay style */
.loupe {
  position: absolute;
  width: 140px;
  height: 140px;
  border: 3px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  overflow: hidden;
  z-index: 200;
  background-color: #000000;
}

.loupe canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Class List row editing styling */
.class-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  border-radius: 4px;
  background-color: var(--bg-surface-hover);
  margin-bottom: 6px;
  border: 1px solid var(--border-color);
}

.class-list-item:hover {
  border-color: var(--border-color-active);
}

.class-add-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  margin-bottom: 20px;
}

.class-add-row input {
  flex: 1;
  padding: 6px 12px;
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface);
  color: var(--text-main);
}

/* Validation report panel */
.validation-issue-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 14px;
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
  margin-bottom: 8px;
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.validation-issue-row:hover {
  background-color: var(--bg-surface-hover);
}

.validation-issue-row.error {
  border-left: 4px solid var(--danger);
}

.validation-issue-row.warning {
  border-left: 4px solid var(--warning);
}

.issue-message {
  font-weight: 550;
}

.issue-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: monospace;
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Responsive boundaries */
@media (max-width: 1023px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .toolbar-group {
    width: 100%;
    flex-wrap: wrap;
  }
  
  .toolbar-secondary {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .toolbar-section {
    max-width: 100%;
    flex-wrap: wrap;
  }
  
  .grid-container {
    grid-template-columns: 1fr !important;
    grid-template-rows: auto !important;
  }
  
  .app-footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  
  .app-footer .disclaimer {
    max-width: 100%;
    text-align: left;
  }
}

@media (max-width: 600px) {
  .app-header,
  .toolbar-secondary,
  .status-bar,
  .app-footer {
    padding-left: 16px;
    padding-right: 16px;
  }

  .status-bar {
    gap: 10px 16px;
  }

  .grid-container {
    padding: 12px;
    gap: 12px;
  }

  .focus-modal .modal-content.focus-content {
    width: 100vw;
    height: 100vh;
  }

  .focus-body {
    flex-direction: column;
  }

  .focus-sidebar {
    width: 100%;
    max-height: 42%;
    border-left: none;
    border-top: 1px solid var(--border-color);
  }
}
