/* Drawing box style during rectangle drag */
.annotation-box.drawing {
  border: 2px dashed #2196f3;
  background-color: rgba(33, 150, 243, 0.1);
  pointer-events: none;
}

/* Redaction Box */
.redaction-box {
  position: absolute;
  background-color: var(--redaction-color);
  cursor: move;
  pointer-events: auto;
  border: 2px solid transparent;
  transition: border-color 0.2s ease;
}

.redaction-box:hover,
.redaction-box.selected {
  border-color: var(--primary-color);
}

.redaction-box.drawing {
  border: 2px dashed var(--primary-color);
  background-color: rgba(0, 0, 0, 0.7);
}

/* Resize Handles — all 8 handles are uniform 6×6 circles (matches editor-v1) */
.resize-handle {
  position: absolute;
  width: calc(6px * var(--annotation-scale, 1));
  height: calc(6px * var(--annotation-scale, 1));
  background-color: #fbfbfb;
  border: 1px solid #0288d1;
  border-radius: 50%;
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 10;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.annotation-box.selected .resize-handle {
  opacity: 1;
}

/* Corner handles */
.resize-nw {
  top: calc(-3px * var(--annotation-scale, 1));
  left: calc(-3px * var(--annotation-scale, 1));
  cursor: nw-resize;
}
.resize-ne {
  top: calc(-3px * var(--annotation-scale, 1));
  right: calc(-3px * var(--annotation-scale, 1));
  cursor: ne-resize;
}
.resize-sw {
  bottom: calc(-3px * var(--annotation-scale, 1));
  left: calc(-3px * var(--annotation-scale, 1));
  cursor: sw-resize;
}
.resize-se {
  bottom: calc(-3px * var(--annotation-scale, 1));
  right: calc(-3px * var(--annotation-scale, 1));
  cursor: se-resize;
}

/* Edge handles — circles at midpoints */
.resize-n {
  top: calc(-3px * var(--annotation-scale, 1));
  left: 50%;
  transform: translateX(-50%);
  cursor: n-resize;
}
.resize-s {
  bottom: calc(-3px * var(--annotation-scale, 1));
  left: 50%;
  transform: translateX(-50%);
  cursor: s-resize;
}
.resize-e {
  right: calc(-3px * var(--annotation-scale, 1));
  top: 50%;
  transform: translateY(-50%);
  cursor: e-resize;
}
.resize-w {
  left: calc(-3px * var(--annotation-scale, 1));
  top: 50%;
  transform: translateY(-50%);
  cursor: w-resize;
}

/* Highlight */
.highlight-box {
  position: absolute;
  background-color: var(--highlight-color);
  pointer-events: auto;
  border-radius: 2px;
  border: 2px solid transparent;
  transition: border-color 0.2s ease;
}

.highlight-box:hover,
.highlight-box.selected {
  border-color: rgba(255, 193, 7, 0.8);
}

/* Annotation Box */
.annotation-box {
  --annotation-scale: 1;
  position: absolute;
  background-color: rgba(0, 255, 0, 0.4);
  border: 1px solid rgba(0, 175, 0, 0.85);
  pointer-events: auto;
  cursor: move;
  border-radius: 0;
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease,
    box-shadow 0.15s ease;
  box-sizing: border-box;
  z-index: 4;
  will-change: left, top, width, height;
}

.annotation-box:hover {
  background-color: rgba(0, 255, 0, 0.48);
}

.annotation-box.dragging,
.annotation-box.resizing {
  transition: none;
}

.annotation-box.dragging {
  cursor: grabbing;
}

.annotation-box.selected {
  background-color: rgba(0, 255, 0, 0.52);
  border-color: #0288d1;
  box-shadow:
    0 0 0 1px rgba(2, 136, 209, 0.35),
    0 2px 6px rgba(0, 160, 0, 0.25);
}

.annotation-box.drawing {
  border: 1px dashed #2196f3;
  background-color: rgba(33, 150, 243, 0.1);
}

/* Server-returned annotation (LLM-detected entities) */
.annotation-box.server-annotation {
  background-color: rgba(0, 255, 0, 0.4);
  border: 1px solid rgba(0, 175, 0, 0.85);
}

.annotation-box.server-annotation:hover {
  background-color: rgba(0, 255, 0, 0.48);
}

.annotation-box.server-annotation.selected {
  background-color: rgba(0, 255, 0, 0.52);
  border-color: #0288d1;
  box-shadow:
    0 0 0 1px rgba(2, 136, 209, 0.35),
    0 2px 6px rgba(0, 160, 0, 0.25);
}

/* Suggestions match editor-v1: subtle body with a green underline instead of a box. */
.annotation-box.suggestion-annotation,
.annotation-box.server-annotation.suggestion-annotation {
  background-color: rgba(242, 242, 242, 0.18);
  border: 0;
  border-bottom: calc(2px * var(--annotation-scale, 1)) solid
    rgba(0, 255, 0, 0.75);
}

.annotation-box.suggestion-annotation:hover,
.annotation-box.server-annotation.suggestion-annotation:hover {
  background-color: rgba(242, 242, 242, 0.26);
  border-bottom-color: rgba(0, 220, 0, 0.9);
}

.annotation-box.suggestion-annotation.selected,
.annotation-box.server-annotation.suggestion-annotation.selected {
  background-color: rgba(242, 242, 242, 0.32);
  border-bottom-color: #0288d1;
  box-shadow:
    0 1px 0 rgba(2, 136, 209, 0.5),
    0 2px 5px rgba(0, 0, 0, 0.12);
}

.annotation-box.persistence-error {
  border-color: #c62828;
  box-shadow: 0 0 0 2px rgba(198, 40, 40, 0.35);
}

body.annotation-interacting,
body.annotation-interacting * {
  user-select: none !important;
}

/* Annotation Sidebar */
.annotation-sidebar {
  width: 320px;
  min-width: 320px;
  background-color: var(--surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sidebar-inner {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

/* Empty state */
.sidebar-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 60px 24px;
  gap: 8px;
  flex: 1;
}

.sidebar-empty-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 8px;
}

.sidebar-empty-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* Sidebar when annotation is selected */
.sidebar-details {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.sidebar-selection-section {
  padding: 20px 20px 0;
}

.sidebar-section-body {
  padding: 16px 20px 0;
}

.sidebar-heading {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 14px;
}

.sidebar-select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background-color: var(--surface);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  box-sizing: border-box;
  margin-bottom: 10px;
  outline: none;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}

.sidebar-select:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(0, 102, 204, 0.08);
}

.sidebar-description {
  font-size: 13px;
  color: #79859a;
  line-height: 1.5;
  margin-bottom: 16px;
  word-break: break-word;
}

.sidebar-apply-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  margin-bottom: 4px;
}

.sidebar-action-btn {
  padding: 10px 16px;
  border-radius: 8px;
  border: none;
  background-color: #0d6efd;
  color: #ffffff;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition:
    background-color 0.15s ease,
    transform 0.15s ease;
}

.sidebar-action-btn:hover {
  background-color: #0b5ed7;
}

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

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

.sidebar-suggestion-section {
  display: flex;
  flex-direction: column;
}

.sidebar-suggestion-text {
  font-size: 15px;
  line-height: 1.45;
  color: var(--text-primary);
  margin-bottom: 4px;
  word-break: break-word;
}

.sidebar-suggestion-note {
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

/* Comments section */
.sidebar-comments-section {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 16px 20px 20px;
  gap: 12px;
  overflow: hidden;
}

.sidebar-comments-heading {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.sidebar-comments-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 80px;
}

.sidebar-comments-list-content {
  width: 100%;
}

.sidebar-no-comments {
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
}

.sidebar-comment-item {
  font-size: 13px;
  color: var(--text-primary);
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  line-height: 1.5;
  word-break: break-word;
}

.sidebar-delete-link {
  font-size: 12px;
  color: #f44336;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  text-decoration: underline;
}

.sidebar-delete-link:hover {
  color: #d32f2f;
}

.sidebar-comment-entry {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: auto;
}

.sidebar-comment-input {
  width: 100%;
  min-height: 72px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text-primary);
  background-color: var(--background);
  resize: vertical;
  box-sizing: border-box;
  outline: none;
  transition: border-color 0.15s ease;
}

.sidebar-comment-input:focus {
  border-color: var(--primary-color);
}

.sidebar-comment-input::placeholder {
  color: var(--border);
}

.sidebar-add-btn {
  align-self: flex-end;
  padding: 8px 20px;
  background-color: var(--primary-color);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.sidebar-add-btn:hover {
  background-color: var(--primary-hover);
}
