* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #1c1c1e;
  color: #f5f5f7;
  height: 100vh;
  overflow: hidden;
}

#topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background: #2c2c2e;
  border-bottom: 1px solid #3a3a3c;
  height: 48px;
}

#topbar .left, #topbar .right { display: flex; align-items: center; gap: 12px; }

#topbar select, #topbar input {
  background: #1c1c1e;
  color: #f5f5f7;
  border: 1px solid #48484a;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 14px;
}

#topbar select { min-width: 180px; }

#page-jump { width: 56px; }

#page-label { font-variant-numeric: tabular-nums; min-width: 90px; text-align: center; }

#edit-status {
  font-size: 18px;
  color: #30d158;
  margin-left: 8px;
}
#edit-status.dirty { color: #ff9500; }

#tune-indicator,
#export-indicator {
  margin-left: 8px;
  padding: 2px 8px;
  background: #003a72;
  border: 1px solid #0a84ff;
  border-radius: 4px;
  font-size: 11px;
  color: #79b8ff;
  animation: spin-pulse 1.4s ease-in-out infinite;
}
@keyframes spin-pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

button {
  background: #3a3a3c;
  color: #f5f5f7;
  border: 1px solid #48484a;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}
button:hover { background: #48484a; }
button:active { background: #2c2c2e; }
button.active { background: #0a84ff; border-color: #0a84ff; }

#btn-process-mayar { background: #5e3a8c; border-color: #7b4fad; }
#btn-process-mayar:hover { background: #7b4fad; }

#source-toggle {
  background: #1c1c1e;
  color: #f5f5f7;
  border: 1px solid #48484a;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 13px;
}

#toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: #232325;
  border-bottom: 1px solid #3a3a3c;
  height: 40px;
}

.tool-btn { min-width: 80px; }

.toolbar-check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #d0d0d5;
  cursor: pointer;
  user-select: none;
}
.toolbar-check input[type="checkbox"] {
  accent-color: #0a84ff;
  width: 14px;
  height: 14px;
  cursor: pointer;
}

.separator {
  width: 1px;
  height: 24px;
  background: #48484a;
}

main {
  display: flex;
  height: calc(100vh - 88px);
  overflow: hidden;
}

#canvas-container {
  flex: 1;
  background: #000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow: auto;
  position: relative;
  padding: 16px;
}

#image-wrap {
  position: relative;
  display: inline-block;
  /* width and height are set in JS to match the displayed image */
}

#page-img {
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
  background: #fff;
}

#box-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none; /* let the boxes inside catch events */
}

.ann-box {
  position: absolute;
  box-sizing: border-box;
  border: 2px solid #ff453a;
  background: rgba(255, 69, 58, 0.06);
  cursor: move;
  pointer-events: auto;
  touch-action: none;
}
.ann-box:hover {
  border-color: #ff6b61;
  background: rgba(255, 69, 58, 0.12);
}
.ann-box.selected {
  border: 3px solid #0a84ff;
  background: rgba(10, 132, 255, 0.12);
  z-index: 100;
}

.ann-label {
  position: absolute;
  top: 2px;
  left: 4px;
  font: bold 12px ui-monospace, monospace;
  color: #ff453a;
  background: rgba(0, 0, 0, 0.6);
  padding: 1px 4px;
  border-radius: 3px;
  pointer-events: none;
}
.ann-box.selected .ann-label {
  color: #0a84ff;
}

#draw-preview {
  position: absolute;
  border: 2px dashed #0a84ff;
  background: rgba(10, 132, 255, 0.08);
  pointer-events: none;
  z-index: 200;
  display: none;
}

#canvas-container.draw-mode #image-wrap { cursor: crosshair; }
#canvas-container.draw-mode #box-overlay { pointer-events: auto; }

#sidebar {
  width: 280px;
  background: #2c2c2e;
  border-left: 1px solid #3a3a3c;
  overflow-y: auto;
  padding: 12px;
}

#sidebar h3 {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 600;
  color: #98989f;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#page-list-section { margin-bottom: 16px; }

#page-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

#page-list li {
  width: 36px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1c1c1e;
  border: 1px solid #3a3a3c;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  color: #f5f5f7;
}
#page-list li:hover { background: #3a3a3c; }
#page-list li.active { background: #0a84ff; border-color: #0a84ff; font-weight: 700; }

#box-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

#box-list li {
  padding: 8px;
  margin-bottom: 4px;
  background: #1c1c1e;
  border-radius: 6px;
  font-size: 12px;
  font-family: ui-monospace, monospace;
  cursor: pointer;
  border: 1px solid transparent;
}
#box-list li:hover { background: #232325; }
#box-list li.selected {
  background: #003a72;
  border-color: #0a84ff;
}

#box-list .box-num { color: #ff453a; font-weight: 700; margin-right: 6px; }
#box-list .box-coords { color: #98989f; }

#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #2c2c2e;
  color: #f5f5f7;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  border: 1px solid #48484a;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 1000;
}
#toast.visible { opacity: 1; }
#toast.error { background: #5a1d1d; border-color: #ff453a; }
#toast.success { background: #1d3a1d; border-color: #30d158; }

/* Upload modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: #2c2c2e;
  border: 1px solid #48484a;
  border-radius: 12px;
  padding: 20px;
  width: 480px;
  max-width: 92vw;
}
.modal h3 {
  margin: 0 0 16px;
  font-size: 16px;
  color: #f5f5f7;
}
#upload-drop {
  border: 2px dashed #48484a;
  border-radius: 8px;
  padding: 32px;
  text-align: center;
  color: #98989f;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
#upload-drop.dragover {
  border-color: #0a84ff;
  background: rgba(10, 132, 255, 0.08);
  color: #f5f5f7;
}
#upload-list {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  max-height: 180px;
  overflow-y: auto;
}
#upload-list li {
  padding: 6px 8px;
  background: #1c1c1e;
  border-radius: 4px;
  margin-bottom: 4px;
  font-size: 12px;
  font-family: ui-monospace, monospace;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#upload-list .remove-btn {
  background: transparent;
  border: none;
  color: #ff453a;
  cursor: pointer;
  padding: 0 4px;
  font-size: 16px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}
.modal-actions button.primary {
  background: #0a84ff;
  border-color: #0a84ff;
}
.modal-actions button.primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
