:root {
  --bg: #f6efe4;
  --panel: #fff9ef;
  --ink: #1d2939;
  --muted: #6f6b63;
  --accent: #0f766e;
  --accent-2: #d97706;
  --danger: #b42318;
  --line: #e7dcc8;
  --shadow: 0 10px 30px rgba(47, 39, 30, 0.12);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 10%, rgba(217, 119, 6, 0.13), transparent 28%),
    radial-gradient(circle at 85% 80%, rgba(15, 118, 110, 0.12), transparent 35%),
    var(--bg);
  font-family: "Source Han Sans SC", "Noto Sans SC", "PingFang SC", sans-serif;
}

#app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

#app.login-mode {
  max-width: none;
  margin: 0;
  padding: 0 16px;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.title {
  margin: 0;
  font-size: 26px;
  letter-spacing: 0.3px;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.login-card {
  width: min(560px, 100%);
  padding: 28px 24px;
}

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

.login-actions {
  justify-content: center;
  margin-top: 0;
}

.login-actions .primary-btn {
  min-width: 260px;
}

.login-help {
  text-align: center;
}

.token-login-collapse {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.token-login-collapse summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  user-select: none;
}

.token-login-row {
  margin-top: 10px;
}

.token-login-actions {
  margin-top: 10px;
}

.row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.row-inline-action {
  display: flex;
  align-items: flex-end;
}

label {
  font-size: 13px;
  color: var(--muted);
  display: block;
  margin-bottom: 4px;
}

input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #ffffff;
  color: #1d2939;
  font-size: 14px;
  -webkit-spell-checking: none;
  spell-checking: none;
}

option {
  background: #ffffff;
  color: #1d2939;
}

input:focus, textarea:focus, select:focus {
  outline: 2px solid rgba(15, 118, 110, 0.2);
  border-color: var(--accent);
}

.primary-btn,
.ghost-btn,
.danger-btn {
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 10px 14px;
  font-size: 14px;
  cursor: pointer;
}

.primary-btn {
  background: var(--accent);
  color: #fff;
}

.primary-btn:hover {
  filter: brightness(0.95);
}

.ghost-btn {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

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

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.projects-filter-row {
  margin: 0;
  margin-left: auto;
}

.create-project-actions {
  width: 100%;
  align-items: center;
}

.projects-filter-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  cursor: pointer;
  color: var(--ink);
  position: relative;
}

.switch-input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-track {
  position: relative;
  width: 44px;
  height: 24px;
  border-radius: 999px;
  background: #cbd5e1;
  transition: background 0.2s ease;
  flex-shrink: 0;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.25);
  transition: transform 0.2s ease;
}

.switch-input:checked + .switch-track {
  background: var(--accent);
}

.switch-input:checked + .switch-track::after {
  transform: translateX(20px);
}

.switch-input:focus-visible + .switch-track {
  outline: 2px solid rgba(15, 118, 110, 0.25);
  outline-offset: 2px;
}

.project-list,
.dataset-list,
.image-grid {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px;
}

.item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: #fff;
  position: relative;
}

.item-delete-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.item-delete-btn:hover {
  background: #fef2f2;
  color: var(--danger);
  border-color: var(--danger);
}

.item h4 {
  margin: 0 0 8px;
  font-size: 15px;
}

.item p {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.classes-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.class-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 13px;
  color: var(--ink);
  position: relative;
  cursor: pointer;
  user-select: none;
}

.class-tag:hover {
  border-color: var(--accent, #4a90e2);
  background: var(--hover, #f0f4ff);
}

.class-tag-delete-btn {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #e53935;
  color: #fff;
  border: none;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 1;
}

.class-tag:hover .class-tag-delete-btn {
  opacity: 1;
}

.class-tag-idx {
  font-size: 11px;
  color: var(--muted);
  min-width: 14px;
}

.image-list {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.upload-dual-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.upload-panel {
  margin-top: 0;
}

.image-list-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  flex-wrap: nowrap;
}

.image-list-stat {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.unlabeled-warn {
  color: var(--danger);
  font-weight: 600;
}

#sort-order {
  width: auto;
  flex-shrink: 0;
}

.image-list-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

#page-size {
  width: auto;
  flex-shrink: 0;
}

.pagination-row {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.pagination-stat {
  font-size: 13px;
  color: var(--muted);
  min-width: 90px;
  text-align: center;
}

.image-list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
}

.image-list-row .item-delete-btn {
  position: static;
  flex-shrink: 0;
}

.image-list-name {
  font-size: 14px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.label-status {
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}

.label-ok {
  background: #d1fae5;
  color: #065f46;
}

.label-missing {
  background: #fee2e2;
  color: #991b1b;
}

.split-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.split-dual-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.split-panel {
  margin-top: 0;
}

.split-actions-row {
  align-items: center;
}

.split-view-btn {
  margin-left: auto;
}

.badge {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--muted);
  margin-left: 8px;
}

.help {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.management-section {
  margin-top: 12px;
}

.management-group {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.72);
}

.project-detail-layout {
  margin-top: 16px;
  display: grid;
  grid-template-columns: 176px minmax(0, 1fr);
  gap: 14px;
}

.project-detail-nav {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.72);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-self: start;
  position: sticky;
  top: 14px;
}

.project-nav-btn {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  font-size: 14px;
}

.project-nav-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.project-nav-btn.active {
  border-color: var(--accent);
  background: rgba(15, 118, 110, 0.08);
  color: #0b5b55;
  font-weight: 600;
}

.project-detail-content {
  margin-top: 0;
}

.management-section-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  margin-bottom: 8px;
}

.management-section-title-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.management-section-title {
  margin: 0;
  font-size: 16px;
}

.section-arrow-btn {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
  font-size: 12px;
}

.section-arrow-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.section-arrow-btn:focus {
  outline: 2px solid rgba(15, 118, 110, 0.2);
  border-color: var(--accent);
}

.management-section-body {
  display: block;
}

.training-advanced-toggle-wrap {
  margin-top: 12px;
}

.training-advanced-title {
  font-size: 14px;
}

.training-advanced-panel {
  margin-top: 12px;
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.72);
}

.training-task-list-card {
  margin-top: 12px;
}

.training-task-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.training-task-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.package-task-item {
  cursor: pointer;
}

.training-task-info {
  flex: 1;
  min-width: 0;
}

.package-task-info {
  cursor: pointer;
}

.package-task-info:hover strong {
  color: var(--accent);
}

.training-task-item strong {
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
}

.training-task-item p {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.training-task-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.training-task-btn {
  padding: 6px 12px;
  font-size: 13px;
}

.training-job-status {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.training-job-status--success {
  background: #d1fae5;
  color: #065f46;
  border: 1px solid #6ee7b7;
}

.training-job-status--running {
  background: #dbeafe;
  color: #1e40af;
  border: 1px solid #93c5fd;
}

.training-job-status--failed {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
}

.training-job-status--pending {
  background: #fef9c3;
  color: #854d0e;
  border: 1px solid #fde047;
}

.package-dataset-picker-btn {
  width: 100%;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.upload-progress-wrap {
  margin-top: 12px;
}

.upload-progress-bar {
  height: 8px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.upload-progress-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.25s ease;
}

.upload-progress-label {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.toast {
  position: fixed;
  top: 18px;
  right: 18px;
  min-width: 260px;
  max-width: min(420px, calc(100vw - 32px));
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  padding: 12px 16px;
  box-shadow: 0 14px 32px rgba(15, 23, 42, 0.28);
  z-index: 120;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.45;
  letter-spacing: 0.1px;
  backdrop-filter: blur(8px);
  animation: toast-enter 0.24s ease-out;
  transform-origin: top right;
}

.toast-info {
  background: linear-gradient(135deg, #0f172a, #1f2937);
}

.toast-success {
  background: linear-gradient(135deg, #065f46, #0f766e);
  border-color: rgba(167, 243, 208, 0.34);
}

.toast-warn {
  background: linear-gradient(135deg, #92400e, #d97706);
  border-color: rgba(253, 230, 138, 0.38);
}

.toast-error {
  background: linear-gradient(135deg, #991b1b, #dc2626);
  border-color: rgba(254, 202, 202, 0.36);
}

.toast-leave {
  animation: toast-leave 0.22s ease-in forwards;
}

@keyframes toast-enter {
  from {
    opacity: 0;
    transform: translateY(-10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes toast-leave {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(-8px) scale(0.98);
  }
}

.hidden {
  display: none !important;
}

.busy-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.32);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 140;
  padding: 16px;
}

.busy-card {
  min-width: 260px;
  max-width: min(420px, calc(100vw - 32px));
  background: linear-gradient(135deg, #fff9ef, #ffffff);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 18px 44px rgba(15, 23, 42, 0.22);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.busy-spinner {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  border: 3px solid rgba(15, 118, 110, 0.18);
  border-top-color: var(--accent);
  animation: busy-spin 0.8s linear infinite;
  flex-shrink: 0;
}

.busy-text {
  margin: 0;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
}

@keyframes busy-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99;
  padding: 16px;
}

.modal-card {
  width: min(980px, 100%);
  max-height: 92vh;
  overflow: auto;
  background: #fff;
  border-radius: 14px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 14px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.modal-body {
  margin-top: 10px;
  display: grid;
  grid-template-columns: minmax(640px, 2fr) minmax(300px, 1fr);
  gap: 12px;
}

.label-left-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.canvas-wrap {
  border: 1px solid var(--line);
  border-radius: 12px;
  min-height: 360px;
  aspect-ratio: 16 / 9;
  background: #fbf7ef;
  overflow: hidden;
  position: relative;
}

#label-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

.label-editor-wrap {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 360px;
  max-height: 680px;
  height: auto;
  overflow: auto;
}

.classes-under-canvas {
  background: #fff;
}

.editor-block {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  background: #fffdf8;
}

.class-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.class-chip {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 12px;
}

.class-chip.active {
  background: #e6fffb;
  border-color: var(--accent);
  color: #065f46;
}

.selected-box-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.label-box-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  height: 220px;
  max-height: 220px;
  overflow: auto;
}

.label-box-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  background: #fff;
  cursor: pointer;
  font-size: 12px;
}

.label-box-item.active {
  border-color: var(--accent);
  background: #f0fdfa;
}

.label-box-item p {
  margin: 2px 0;
  color: var(--muted);
  font-size: 12px;
}

.label-nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: auto;
  padding-top: 6px;
}

.selected-box-class-row {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
}

.selected-box-class-row label {
  flex-shrink: 0;
  font-size: 13px;
}

.selected-box-class-row select {
  flex: 1;
  min-width: 0;
}

.selected-box-class-row .danger-btn {
  flex-shrink: 0;
  white-space: nowrap;
}

.split-preview-card {
  width: min(980px, 100%);
}

.package-picker-modal-card {
  width: min(640px, 100%);
}

.package-task-detail-modal-card {
  width: min(860px, 100%);
}

.package-task-detail-body {
  margin-top: 10px;
}

.package-task-detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px 12px;
}

.package-task-detail-grid p {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.package-task-detail-grid strong {
  color: var(--ink);
}

.package-task-log-wrap {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 10px;
}

.package-task-log-pre {
  margin: 0;
  max-height: 40vh;
  overflow: auto;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: #0f172a;
}

.package-picker-body {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.package-picker-list {
  max-height: 46vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.package-picker-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
}

.package-picker-item input {
  width: auto;
}

.split-preview-body {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.split-preview-summary {
  margin: 0;
}

.split-preview-summary + .split-preview-summary {
  margin-top: 6px;
}

.split-preview-table-wrap {
  max-height: 52vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.split-preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.split-preview-table th,
.split-preview-table td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: left;
  white-space: nowrap;
}

.split-preview-table th {
  position: sticky;
  top: 0;
  background: #fff9ef;
  z-index: 1;
}

@media (max-width: 900px) {
  .project-detail-layout {
    grid-template-columns: 1fr;
  }

  .project-detail-nav {
    position: static;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .modal-body {
    grid-template-columns: 1fr;
  }

  .canvas-wrap,
  .label-editor-wrap {
    height: auto;
    min-height: 320px;
    max-height: none;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }
}
