/* ═══════════════════════════════════════════════
   MODULE — IN-CHAT IMAGE ANNOTATION EDITOR
   Fullscreen modal, layered canvas, theme-matched.
   All classes prefixed .ie- to avoid collisions.
═══════════════════════════════════════════════ */

/* ── EDIT OVERLAY BUTTON ON CHAT IMAGES ──────── */
#page-messaging .mc-img-wrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
  line-height: 0;
}
#page-messaging .mc-img-edit {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: rgba(20,16,12,0.62);
  color: #F0E8D0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 12px;
  opacity: 0;
  transform: scale(0.85);
  transition: opacity 0.2s, transform 0.2s, background 0.2s;
  backdrop-filter: blur(4px);
  z-index: 2;
}
#page-messaging .mc-img-wrap:hover .mc-img-edit,
#page-messaging .mc-img-edit:focus-visible {
  opacity: 1;
  transform: scale(1);
}
#page-messaging .mc-img-edit:hover {
  background: var(--gold);
  color: #1A1205;
}
/* Touch devices — always show the affordance */
@media (hover: none) {
  #page-messaging .mc-img-edit { opacity: 1; transform: scale(1); }
}

/* ── EDITOR OVERLAY ──────────────────────────── */
.ie-overlay {
  position: fixed;
  inset: 0;
  z-index: 9500;
  display: none;
  flex-direction: column;
  background: rgba(8,6,4,0.82);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: ieFade 0.25s ease;
}
.ie-overlay.open { display: flex; }
@keyframes ieFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes iePop  { from { opacity: 0; transform: scale(0.97); } to { opacity: 1; transform: none; } }

/* ── HEADER BAR ──────────────────────────────── */
.ie-header {
  flex-shrink: 0;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  background: var(--surface);
  backdrop-filter: var(--blur);
  border-bottom: 1px solid var(--border);
}
.ie-header-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.ie-header-title i { color: var(--gold); }
.ie-header-actions { display: flex; align-items: center; gap: 10px; }

.ie-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: 'Lexend', sans-serif;
  font-size: 13px;
  font-weight: 500;
  padding: 9px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
}
.ie-btn:hover { background: var(--card); border-color: var(--gold); }
.ie-btn-primary {
  background: linear-gradient(135deg, var(--gold), #B8922A);
  color: #1A1205;
  border: none;
  box-shadow: 0 4px 14px var(--glow);
  font-weight: 600;
}
.ie-btn-primary:hover { filter: brightness(1.05); transform: translateY(-1px); }
.ie-btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.ie-icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 15px;
  transition: all 0.2s;
}
.ie-icon-btn:hover { background: var(--card); color: var(--text); border-color: var(--gold); }
.ie-icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* ── BODY (toolbar + stage) ──────────────────── */
.ie-body {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

/* ── TOOL RAIL (left / bottom dock on mobile) ── */
.ie-tools {
  flex-shrink: 0;
  width: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}
.ie-tool {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.18s;
  position: relative;
}
.ie-tool:hover { background: var(--surface2); color: var(--text); }
.ie-tool.active {
  background: rgba(201,168,76,0.18);
  border-color: rgba(201,168,76,0.4);
  color: var(--gold);
  box-shadow: 0 0 14px var(--glow);
}
.ie-tool-sep {
  width: 32px;
  height: 1px;
  background: var(--border);
  margin: 4px 0;
  flex-shrink: 0;
}

/* ── STAGE (canvas viewport) ─────────────────── */
.ie-stage {
  flex: 1;
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    repeating-conic-gradient(rgba(255,255,255,0.04) 0% 25%, transparent 0% 50%) 50% / 22px 22px;
}
.ie-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;          /* we handle gestures ourselves */
  cursor: crosshair;
}
.ie-canvas.ie-cursor-select { cursor: default; }
.ie-canvas.ie-cursor-move   { cursor: move; }
.ie-canvas.ie-cursor-erase  { cursor: cell; }

/* Floating text editing overlay */
.ie-text-input {
  position: absolute;
  z-index: 5;
  min-width: 40px;
  background: rgba(255,255,255,0.06);
  border: 1px dashed var(--gold);
  border-radius: 6px;
  outline: none;
  resize: none;
  overflow: hidden;
  padding: 2px 4px;
  font-family: 'Lexend', sans-serif;
  line-height: 1.2;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Loading state */
.ie-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text2);
  font-size: 13px;
  z-index: 6;
}
.ie-spinner {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--gold);
  animation: ieSpin 0.8s linear infinite;
}
@keyframes ieSpin { to { transform: rotate(360deg); } }

/* Zoom indicator */
.ie-zoom-pill {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 6px 10px;
  z-index: 7;
  backdrop-filter: var(--blur);
}
.ie-zoom-pill button {
  width: 26px; height: 26px;
  border: none; border-radius: 50%;
  background: var(--surface2); color: var(--text2);
  cursor: pointer; font-size: 12px;
  display: flex; align-items: center; justify-content: center;
}
.ie-zoom-pill button:hover { background: var(--card); color: var(--text); }
.ie-zoom-pill span { font-size: 12px; color: var(--text2); min-width: 42px; text-align: center; }

/* ── PROPERTIES PANEL (right) ────────────────── */
.ie-props {
  flex-shrink: 0;
  width: 230px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 18px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.ie-prop-group { display: flex; flex-direction: column; gap: 9px; }
.ie-prop-label {
  font-size: 10.5px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text3);
  font-weight: 600;
}
.ie-swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.ie-swatch {
  width: 26px; height: 26px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.15s, border-color 0.15s;
}
.ie-swatch:hover { transform: scale(1.12); }
.ie-swatch.active { border-color: var(--text); box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--gold); }
.ie-color-custom {
  width: 26px; height: 26px;
  padding: 0; border: 1px solid var(--border);
  border-radius: 50%; cursor: pointer; background: none;
  overflow: hidden;
}

.ie-sizes { display: flex; gap: 6px; flex-wrap: wrap; }
.ie-size-dot {
  width: 32px; height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.ie-size-dot .ie-size-vis {
  background: var(--text2);
  border-radius: 50%;
}
.ie-size-dot:hover { border-color: var(--gold); }
.ie-size-dot.active { background: rgba(201,168,76,0.18); border-color: var(--gold); }
.ie-size-dot.active .ie-size-vis { background: var(--gold); }

.ie-range { width: 100%; accent-color: var(--gold); cursor: pointer; }
.ie-range-row { display: flex; align-items: center; justify-content: space-between; }
.ie-range-val { font-size: 12px; color: var(--text2); }

.ie-toggle-row { display: flex; gap: 8px; }
.ie-chip {
  flex: 1;
  text-align: center;
  font-size: 12px;
  padding: 7px 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text2);
  cursor: pointer;
  transition: all 0.15s;
}
.ie-chip.active { background: rgba(201,168,76,0.18); border-color: var(--gold); color: var(--gold); }

.ie-hint {
  font-size: 11px;
  color: var(--text3);
  line-height: 1.5;
  border-top: 1px solid var(--border);
  padding-top: 14px;
  margin-top: auto;
}
.ie-hint kbd {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 10px;
  font-family: monospace;
}

/* ── CONFIRM DIALOG (Clear All) ──────────────── */
.ie-confirm {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(4px);
}
.ie-confirm.open { display: flex; }
.ie-confirm-box {
  width: 340px; max-width: 90%;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 22px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  animation: iePop 0.2s ease;
}
.ie-confirm-box h4 { margin: 0 0 6px; font-size: 15px; color: var(--text); }
.ie-confirm-box p { margin: 0 0 18px; font-size: 13px; color: var(--text3); line-height: 1.5; }
.ie-confirm-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ── RESPONSIVE ──────────────────────────────── */
@media (max-width: 760px) {
  .ie-props { display: none; }                 /* collapse into a sheet */
  .ie-props.ie-mobile-open {
    display: flex;
    position: absolute;
    right: 0; top: 0; bottom: 0;
    width: 220px;
    z-index: 12;
    box-shadow: -8px 0 30px rgba(0,0,0,0.4);
  }
  .ie-body { flex-direction: column-reverse; }  /* tools become a bottom dock */
  .ie-tools {
    width: 100%;
    flex-direction: row;
    justify-content: flex-start;
    border-right: none;
    border-top: 1px solid var(--border);
    padding: 8px 10px;
    gap: 4px;
    overflow-x: auto;
    overflow-y: hidden;
  }
  .ie-tool-sep { width: 1px; height: 28px; margin: 0 4px; }
  .ie-header { height: 52px; padding: 0 12px; }
  .ie-btn span.ie-btn-label { display: none; }
  .ie-btn-primary span.ie-btn-label { display: inline; }
}
