* { box-sizing: border-box; }
html, body { margin: 0; font-family: -apple-system, "Segoe UI", system-ui, sans-serif;
              background: #f0f2f5; color: #222; }
header {
  background: #1a2540; color: white; padding: 10px 20px;
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
header h1 { margin: 0; font-size: 22px; font-weight: 700; }
header .tag { font-size: 13px; color: #cdd8ee; margin-left: 14px; }
header .head-right { display: flex; align-items: center; gap: 18px; }
header input { padding: 4px 8px; border-radius: 4px; border: 1px solid #4a5878;
                background: #2a3550; color: white; font-size: 13px; }
header .stats { font-size: 12px; color: #cdd8ee;
                 display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.stat-pill {
  background: rgba(255,255,255,0.12); padding: 4px 10px; border-radius: 12px;
  font-size: 12px; color: white; white-space: nowrap;
}
.stat-pill.model-ver { background: rgba(40, 167, 69, 0.3); }
.stat-pill b { color: #ffe55c; font-weight: 700; }
.stat-due {
  background: #ffe55c; color: #4a3000; padding: 4px 10px;
  border-radius: 12px; font-size: 12px; font-weight: 700;
}
.stat-retraining {
  background: #ffcc00; color: #4a3000; padding: 4px 10px;
  border-radius: 12px; font-size: 12px; font-weight: 700;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.6; } }

.consent-banner {
  background: #e8f4ea; border-bottom: 2px solid #28a745;
  padding: 10px 20px; font-size: 13px; color: #155724;
  line-height: 1.5;
}
.consent-banner .consent-line { margin: 4px 0; }
.consent-banner .consent-why { font-size: 12.5px; color: #1a4a2a; }
.consent-banner strong { color: #0a3a17; }
.consent-banner em { font-style: italic; }
.consent-banner .learn-more {
  color: #28a745; font-weight: 600; text-decoration: none; margin-left: 6px;
}
.consent-banner .learn-more:hover { text-decoration: underline; }

main { padding: 20px; }

/* About / explainer panel */
.about-panel {
  max-width: 900px; margin: 14px auto; padding: 14px 22px;
  background: white; border: 1px solid #d8e0ec; border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
.about-panel summary {
  cursor: pointer; font-size: 15px; font-weight: 600;
  color: #1a2540; padding: 6px 0; user-select: none;
}
.about-panel summary:hover { color: #28a745; }
.about-panel[open] summary { border-bottom: 1px solid #eee; margin-bottom: 14px; }
.about-panel .hide-hint { font-weight: 400; font-size: 12px; color: #888; }
.about-panel .about-body { font-size: 14px; line-height: 1.65; color: #333; }
.about-panel h2 {
  font-size: 17px; color: #1a2540; margin: 18px 0 6px; font-weight: 700;
}
.about-panel ul { margin: 6px 0 10px; padding-left: 22px; }
.about-panel li { margin-bottom: 4px; }
.about-panel p { margin: 8px 0; }
.about-panel .dismiss-row {
  text-align: center; margin-top: 18px; padding-top: 12px;
  border-top: 1px solid #eee;
}
.spinner {
  width: 56px; height: 56px;
  border: 6px solid #d8e0ec; border-top-color: #1f4e79;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Inline mini-spinner shown on Save while the next image is fetching */
.mini-spinner {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: rgba(255,255,255,0.95); border: 2px solid #1f4e79;
  border-radius: 12px; padding: 24px 32px; z-index: 999;
  text-align: center; box-shadow: 0 4px 24px rgba(0,0,0,0.3);
}
.mini-spinner .spinner { margin: 0 auto 10px; width: 40px; height: 40px; border-width: 5px; }

#workspace {
  display: grid; grid-template-columns: 1fr 340px; gap: 20px;
  max-width: 1700px; margin: 0 auto;
}

.canvas-wrap { background: #ddd; border-radius: 8px; padding: 10px;
                display: flex; align-items: center; justify-content: center;
                min-height: 600px; position: relative; overflow: hidden; }
canvas { max-width: 100%; max-height: 80vh; cursor: crosshair;
          background: #888; border-radius: 4px; display: block; }

/* Loading overlay sits inside .canvas-wrap, covers the canvas while loading */
.loading-overlay {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(238, 238, 238, 0.97);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 14px; z-index: 5;
  color: #444; font-size: 18px;
  text-align: center;
}
.loading-overlay #loading-sub { font-size: 13px; color: #888; }
.loading-overlay.hidden { display: none; }

.retrain-banner {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
  background: #fff8c5; border: 2px solid #e0c000; padding: 8px 16px;
  border-radius: 6px; font-weight: 600; color: #856404;
}

.sidebar { background: white; border-radius: 8px; padding: 16px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06); }

.legend h2 { margin: 0 0 8px; font-size: 14px; color: #1a2540; }
.legend ol { padding-left: 20px; margin: 0 0 14px; font-size: 13px; line-height: 1.6; }
.legend-list { padding-left: 16px; list-style: none; margin-top: 4px; }
.legend-list li { font-size: 12px; padding: 2px 0; }
.legend-list .dot { display: inline-block; width: 11px; height: 11px;
                     border-radius: 50%; vertical-align: middle; margin-right: 4px; }
.dot-blue   { background: #3399ff; }
.dot-green  { background: #22dd22; }
.dot-orange { background: #ff8800; }
.green { color: #22aa22; font-weight: 600; }

.actions { display: flex; flex-direction: column; gap: 8px; margin: 16px 0; }
.actions button { padding: 12px; border: none; border-radius: 6px;
                   font-size: 15px; font-weight: 600; cursor: pointer; }
.btn-primary { background: #22aa22; color: white; }
.btn-primary:hover { background: #1a9a1a; }
.btn-secondary { background: #1f4e79; color: white; }
.btn-secondary:hover { background: #163c5e; }
.btn-ghost { background: #eee; color: #555; }
.btn-ghost:hover { background: #ddd; }
.btn-reject { background: #aa3333; color: white; margin-top: 6px; font-size: 13px; }
.btn-reject:hover { background: #882828; }

.legend-list.compact { margin-top: 2px; }
.legend-list.compact li { font-size: 11px; color: #666; }

/* Reject modal */
.modal {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal[hidden] { display: none; }
.modal-card {
  background: white; border-radius: 10px; padding: 24px;
  max-width: 500px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}
.modal-card h2 { margin: 0 0 8px; color: #aa3333; font-size: 18px; }
.modal-card p { font-size: 13px; color: #555; margin: 0 0 14px; }
.reject-options { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.reject-options label { font-size: 13px; padding: 6px 8px; border-radius: 4px; cursor: pointer; }
.reject-options label:hover { background: #f6f6f6; }
.reject-options input { margin-right: 8px; }
.modal-card textarea {
  width: 100%; padding: 6px 8px; border: 1px solid #ccc; border-radius: 4px;
  font-family: inherit; font-size: 13px; resize: vertical;
}
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.modal-actions button { padding: 8px 14px; border: none; border-radius: 4px; cursor: pointer; }

/* Live training console */
.train-console {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: #1a1f2e; color: #cdd8ee; border-top: 3px solid #ffcc00;
  z-index: 50; max-height: 40vh; display: flex; flex-direction: column;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.3);
}
.train-console[hidden] { display: none; }
.train-console-header {
  display: flex; align-items: center; gap: 10px;
  background: #2a3144; padding: 8px 16px; border-bottom: 1px solid #444;
}
.train-icon { font-size: 18px; animation: pulse 1.2s ease-in-out infinite; }
.train-title { font-weight: 700; color: #ffcc00; }
.train-sub { font-size: 12px; color: #98a3c0; flex: 1; }
.train-console-toggle {
  background: #444; color: white; border: none; padding: 4px 10px;
  border-radius: 4px; cursor: pointer; font-size: 12px;
}
.train-console-toggle:hover { background: #555; }
.train-console-log {
  margin: 0; padding: 12px 16px; overflow-y: auto;
  font-family: Consolas, "Courier New", monospace; font-size: 12px;
  line-height: 1.4; flex: 1; max-height: 30vh;
  white-space: pre-wrap; word-break: break-word;
}
.train-console.collapsed .train-console-log { display: none; }
.train-console.collapsed { max-height: none; }

.meta { font-size: 12px; color: #666; margin-top: 8px; padding-top: 12px;
         border-top: 1px solid #eee; }
.meta div { padding: 2px 0; font-family: Consolas, Menlo, monospace; }

.dot-on-canvas {
  position: absolute; width: 22px; height: 22px; border-radius: 50%;
  cursor: grab; pointer-events: auto;
  border: 3px solid white; box-shadow: 0 0 0 2px rgba(0,0,0,0.4);
  transform: translate(-50%, -50%);
}
.dot-on-canvas:active { cursor: grabbing; }
.dot-label {
  position: absolute; pointer-events: none; font-size: 12px; font-weight: 700;
  background: rgba(255, 255, 255, 0.9); padding: 1px 5px; border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.2); transform: translate(14px, -22px);
}

@media (max-width: 1100px) {
  #workspace { grid-template-columns: 1fr; }
}

/* Right-click context menu */
.kp-menu {
  position: fixed; z-index: 1000;
  background: white; border: 1px solid #aaa; border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  min-width: 200px; padding: 4px 0;
  font-size: 13px;
}
.kp-menu-item {
  display: block; width: 100%; text-align: left;
  background: white; border: none; padding: 8px 12px;
  cursor: pointer; font-size: 13px;
}
.kp-menu-item:hover { background: #e8f4ea; }
.kp-menu-item .dot {
  display: inline-block; width: 10px; height: 10px;
  border-radius: 50%; vertical-align: middle; margin-right: 6px;
}
.kp-menu-item .dot-upper { background: #3399ff; }
.kp-menu-item .dot-pt    { background: #22dd22; }
.kp-menu-item .dot-lower { background: #ff8800; }
.kp-menu-sep { height: 1px; background: #ddd; margin: 4px 0; }
.kp-menu-delete { color: #aa3333; }
.kp-menu-delete:hover { background: #fdd; }
