/* ─── Reset & Base ─── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0A0A0A;
  --surface: #141414;
  --surface-2: #1E1E1E;
  --border: #2A2A2A;
  --text: #E5E5E5;
  --text-dim: #888;
  --accent: #FF3B30;
  --accent-blue: #007AFF;
  --radius: 8px;
  --toolbar-h: 48px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'SF Pro', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  cursor: default;
  -webkit-font-smoothing: antialiased;
}

/* ─── Toolbar ─── */
#toolbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--toolbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  z-index: 100;
  user-select: none;
}

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

.logo {
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-right: 12px;
}

.tool-group {
  display: flex;
  gap: 2px;
  background: var(--surface-2);
  border-radius: 6px;
  padding: 2px;
}

.tool-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.tool-btn:hover { color: var(--text); background: var(--border); }
.tool-btn.active { color: var(--text); background: var(--border); }

.color-group {
  display: flex;
  gap: 4px;
  margin-left: 8px;
}

.color-swatch {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
}

.color-swatch:hover { transform: scale(1.2); }
.color-swatch.active { border-color: var(--text); }

.separator {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 4px;
}

.action-btn {
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.action-btn:hover { background: var(--border); }
.action-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.action-btn.primary:hover { opacity: 0.85; }

#zoom-display {
  font-size: 11px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  min-width: 36px;
  text-align: right;
}

/* ─── Canvas ─── */
#canvas-container {
  position: fixed;
  top: var(--toolbar-h);
  left: 0; right: 0; bottom: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 50%, #111 0%, var(--bg) 100%);
}

/* Dot grid */
#canvas-container::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle, #222 1px, transparent 1px);
  background-size: 24px 24px;
  pointer-events: none;
  opacity: 0.5;
}

.canvas-container canvas {
  position: absolute;
  top: 0;
  left: 0;
}

/* ─── Drop overlay ─── */
#drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 122, 255, 0.08);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

#drop-overlay.hidden { display: none; }

.drop-content {
  text-align: center;
  padding: 48px;
  border: 2px dashed var(--accent-blue);
  border-radius: 16px;
  background: rgba(0, 122, 255, 0.05);
}

.drop-icon { font-size: 48px; margin-bottom: 12px; }
.drop-text { font-size: 18px; font-weight: 600; }
.drop-subtext { font-size: 13px; color: var(--text-dim); margin-top: 6px; }

/* ─── Empty state ─── */
#empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 10;
}

#empty-state.hidden { display: none !important; }

.empty-icon { font-size: 36px; margin-bottom: 16px; opacity: 0.3; }
.empty-title { font-size: 16px; font-weight: 600; opacity: 0.4; }
.empty-sub { font-size: 13px; color: var(--text-dim); opacity: 0.4; text-align: center; line-height: 1.6; margin-top: 8px; }

/* ─── Comment Panel ─── */
#comment-panel {
  position: fixed;
  z-index: 150;
  width: 280px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

#comment-panel.hidden { display: none; }

.comment-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.comment-number {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
}

.comment-close {
  width: 20px;
  height: 20px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.comment-close:hover { background: var(--border); color: var(--text); }

#comment-input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
  min-height: 60px;
  outline: none;
}

#comment-input:focus { border-color: var(--accent-blue); }

.comment-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.comment-save, .comment-delete {
  flex: 1;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
}

.comment-save {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: #fff;
}

.comment-delete {
  background: transparent;
  color: var(--text-dim);
}

.comment-save:hover { opacity: 0.85; }
.comment-delete:hover { background: var(--border); color: var(--text); }

/* ─── Toast ─── */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  z-index: 300;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  transition: opacity 0.3s;
}

#toast.hidden { opacity: 0; pointer-events: none; }

/* ─── Annotation badge (numbered markers) ─── */
.annotation-badge {
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  pointer-events: none;
  z-index: 50;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

/* ─── Sidebar ─── */
#sidebar {
  position: fixed;
  top: var(--toolbar-h);
  right: 0;
  bottom: 0;
  width: 280px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 90;
  transform: translateX(100%);
  transition: transform 0.2s ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#sidebar.open { transform: translateX(0); }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
}

.sidebar-count-badge {
  background: var(--border);
  color: var(--text-dim);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
}

#sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.sidebar-empty {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  padding: 32px 16px;
}

.sidebar-item {
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 4px;
}

.sidebar-item:hover { background: var(--surface-2); }

.sidebar-item-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.sidebar-badge {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-type {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sidebar-image {
  font-size: 11px;
  color: var(--text-dim);
  margin-left: auto;
  opacity: 0.6;
}

.sidebar-delete {
  width: 18px;
  height: 18px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 11px;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
}

.sidebar-item:hover .sidebar-delete { opacity: 1; }
.sidebar-delete:hover { background: var(--accent); color: #fff; }

.sidebar-comment {
  font-size: 12px;
  color: var(--text);
  line-height: 1.4;
  padding-left: 26px;
}

.sidebar-comment .no-comment {
  color: var(--text-dim);
  font-style: italic;
}

/* cursor overrides */
body.tool-rect { cursor: crosshair; }
body.tool-arrow { cursor: crosshair; }
body.tool-freehand { cursor: crosshair; }
body.tool-comment { cursor: crosshair; }
body.panning { cursor: grabbing !important; }
