/* Hanhai Pro Image Annotator (Canvas & /studio/ Shared Standalone UI) */
.hhia-backdrop,
.hhia-backdrop * {
  box-sizing: border-box;
}

.hhia-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2147482000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(6, 7, 10, 0.78);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --hhia-bg: #141519;
  --hhia-bg-elev: #1b1d23;
  --hhia-stage: #0d0e11;
  --hhia-checker-a: #13151a;
  --hhia-checker-b: #191c22;
  --hhia-border: rgba(255, 255, 255, 0.11);
  --hhia-border-strong: rgba(255, 255, 255, 0.22);
  --hhia-ink: #f3f4f7;
  --hhia-muted: #9ca3af;
  --hhia-pill-bg: rgba(22, 23, 29, 0.88);
  --hhia-pill-border: rgba(255, 255, 255, 0.14);
  --hhia-pill-shadow: 0 14px 40px rgba(0, 0, 0, 0.55);
  --hhia-btn-hover: rgba(255, 255, 255, 0.1);
  --hhia-accent: #7357ff;
  --hhia-accent-2: #5b3df5;
  --hhia-accent-ink: #ffffff;
  --hhia-cta-bg: linear-gradient(135deg, #e5bf6e, #c99438);
  --hhia-cta-ink: #161108;
}

.hhia-backdrop[data-hhia-theme="day"],
html[data-hhv-appearance="day"] .hhia-backdrop,
html[data-hh-appearance="day"] .hhia-backdrop,
html.hhd4-day .hhia-backdrop {
  background: rgba(15, 23, 42, 0.42);
  --hhia-bg: #ffffff;
  --hhia-bg-elev: #f6f7fa;
  --hhia-stage: #eef0f5;
  --hhia-checker-a: #eaedf3;
  --hhia-checker-b: #f7f8fb;
  --hhia-border: rgba(17, 24, 39, 0.11);
  --hhia-border-strong: rgba(17, 24, 39, 0.22);
  --hhia-ink: #181a20;
  --hhia-muted: #5c6270;
  --hhia-pill-bg: rgba(255, 255, 255, 0.92);
  --hhia-pill-border: rgba(17, 24, 39, 0.12);
  --hhia-pill-shadow: 0 12px 34px rgba(15, 23, 42, 0.16);
  --hhia-btn-hover: rgba(17, 24, 39, 0.07);
  --hhia-accent: #5b46f6;
  --hhia-accent-2: #4834d4;
  --hhia-accent-ink: #ffffff;
  --hhia-cta-bg: linear-gradient(135deg, #d8a74a, #b88224);
  --hhia-cta-ink: #ffffff;
}

.hhia-dialog {
  width: min(1160px, 95vw);
  height: min(850px, 92vh);
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  overflow: hidden;
  background: var(--hhia-bg);
  color: var(--hhia-ink);
  border: 1px solid var(--hhia-border);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.55);
  outline: none;
}

.hhia-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 18px;
  background: var(--hhia-bg-elev);
  border-bottom: 1px solid var(--hhia-border);
}

.hhia-header-title {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.hhia-header-kicker {
  font-size: 11px;
  font-weight: 700;
  color: var(--hhia-accent);
  letter-spacing: 0.04em;
}

.hhia-header-title strong {
  font-size: 15px;
  font-weight: 700;
  color: var(--hhia-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hhia-close {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--hhia-border);
  background: transparent;
  color: var(--hhia-ink);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.hhia-close:hover {
  background: var(--hhia-btn-hover);
}

.hhia-body {
  flex: 1 1 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 268px;
}

.hhia-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
  padding: 46px 24px 130px;
  background-color: var(--hhia-stage);
  background-image:
    linear-gradient(45deg, var(--hhia-checker-a) 25%, transparent 25%),
    linear-gradient(-45deg, var(--hhia-checker-a) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--hhia-checker-a) 75%),
    linear-gradient(-45deg, transparent 75%, var(--hhia-checker-a) 75%);
  background-size: 22px 22px;
  background-position: 0 0, 0 11px, 11px -11px, -11px 0;
  user-select: none;
  -webkit-user-select: none;
}

.hhia-stage.is-panning,
.hhia-stage.is-panning canvas {
  cursor: grab !important;
}

.hhia-stage.is-panning-active,
.hhia-stage.is-panning-active canvas {
  cursor: grabbing !important;
}

.hhia-stage-transform {
  display: flex;
  align-items: center;
  justify-content: center;
  transform-origin: center center;
  will-change: transform;
}

.hhia-stage canvas {
  display: block;
  max-width: 100%;
  max-height: calc(92vh - 280px);
  width: auto;
  height: auto;
  box-shadow: 0 14px 48px rgba(0, 0, 0, 0.45);
  touch-action: none;
  cursor: crosshair;
  border-radius: 3px;
}

.hhia-stage.tool-text canvas {
  cursor: text;
}

.hhia-stage.tool-eraser canvas {
  cursor: none;
}

.hhia-status-badge,
.hhia-error-badge {
  position: absolute;
  z-index: 6;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  background: var(--hhia-pill-bg);
  border: 1px solid var(--hhia-pill-border);
  color: var(--hhia-ink);
  backdrop-filter: blur(12px);
}

.hhia-error-badge {
  color: #ff7b72;
  border-color: rgba(255, 107, 107, 0.45);
}

.hhia-dims {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 5;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  background: var(--hhia-pill-bg);
  border: 1px solid var(--hhia-pill-border);
  color: var(--hhia-muted);
  backdrop-filter: blur(10px);
  pointer-events: none;
}

.hhia-zoombar {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 7;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  border-radius: 999px;
  background: var(--hhia-pill-bg);
  border: 1px solid var(--hhia-pill-border);
  box-shadow: var(--hhia-pill-shadow);
  backdrop-filter: blur(14px);
}

.hhia-zoombar button {
  height: 26px;
  min-width: 28px;
  padding: 0 8px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--hhia-ink);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.hhia-zoombar button:hover {
  background: var(--hhia-btn-hover);
}

.hhia-cursor-ring {
  position: fixed;
  z-index: 2147482010;
  pointer-events: none;
  border-radius: 50%;
  border: 1.5px solid #ffffff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.65);
  transform: translate(-50%, -50%);
  display: none;
}

.hhia-text-pop {
  position: absolute;
  z-index: 15;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 240px;
  max-width: 320px;
  padding: 10px;
  border-radius: 12px;
  background: var(--hhia-pill-bg);
  border: 1px solid var(--hhia-border-strong);
  box-shadow: var(--hhia-pill-shadow);
  backdrop-filter: blur(16px);
}

.hhia-text-pop input[type="text"] {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--hhia-border-strong);
  background: var(--hhia-bg);
  color: var(--hhia-ink);
  font-size: 13px;
  outline: none;
}

.hhia-text-pop input[type="text"]:focus {
  border-color: var(--hhia-accent);
}

.hhia-text-pop-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.hhia-text-pop-actions label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--hhia-muted);
  cursor: pointer;
}

.hhia-text-pop-btns {
  display: inline-flex;
  gap: 6px;
}

.hhia-text-pop-btns button {
  height: 28px;
  padding: 0 10px;
  border-radius: 7px;
  border: 1px solid var(--hhia-border);
  background: transparent;
  color: var(--hhia-ink);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.hhia-text-pop-btns button.is-ok {
  border-color: transparent;
  background: var(--hhia-accent);
  color: #ffffff;
}

/* TapNow-style Floating Dual-Pill Bar */
.hhia-dock {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  z-index: 12;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  max-width: calc(100% - 20px);
  pointer-events: none;
}

.hhia-subpill,
.hhia-toolpill {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--hhia-pill-bg);
  border: 1px solid var(--hhia-pill-border);
  box-shadow: var(--hhia-pill-shadow);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}

.hhia-subpill::-webkit-scrollbar,
.hhia-toolpill::-webkit-scrollbar {
  display: none;
}

.hhia-sep {
  width: 1px;
  height: 18px;
  margin: 0 4px;
  background: var(--hhia-border-strong);
  flex: 0 0 auto;
}

.hhia-swatches {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex: 0 0 auto;
}

.hhia-swatch {
  width: 18px;
  height: 18px;
  padding: 0;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.35);
  background: var(--dot-color, #ff3b30);
  cursor: pointer;
  flex: 0 0 auto;
  transition: transform 0.12s, box-shadow 0.12s;
}

.hhia-backdrop[data-hhia-theme="day"] .hhia-swatch {
  border-color: rgba(15, 23, 42, 0.22);
}

.hhia-swatch:hover {
  transform: scale(1.14);
}

.hhia-swatch.is-active {
  transform: scale(1.18);
  box-shadow: 0 0 0 2px var(--hhia-bg), 0 0 0 3.5px var(--hhia-accent);
}

.hhia-color-custom {
  position: relative;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  overflow: hidden;
  border: 1.5px solid var(--hhia-border-strong);
  background: conic-gradient(#ff3b30, #ffd60a, #32d74b, #0a84ff, #bf5af2, #ff3b30);
  cursor: pointer;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.hhia-color-custom input[type="color"] {
  position: absolute;
  inset: -4px;
  width: 28px;
  height: 28px;
  opacity: 0;
  cursor: pointer;
}

.hhia-mini-btn {
  height: 26px;
  min-width: 28px;
  padding: 0 8px;
  border-radius: 999px;
  border: 0;
  background: transparent;
  color: var(--hhia-ink);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: background 0.12s, color 0.12s, opacity 0.12s;
}

.hhia-mini-btn:hover:not(:disabled) {
  background: var(--hhia-btn-hover);
}

.hhia-mini-btn.is-active {
  background: var(--hhia-accent);
  color: var(--hhia-accent-ink);
}

.hhia-mini-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.hhia-tool-btn {
  height: 34px;
  padding: 0 11px;
  border-radius: 999px;
  border: 0;
  background: transparent;
  color: var(--hhia-ink);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: background 0.14s, color 0.14s, transform 0.1s;
}

.hhia-tool-btn svg {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
}

.hhia-tool-btn:hover {
  background: var(--hhia-btn-hover);
}

.hhia-tool-btn.is-active {
  background: linear-gradient(135deg, var(--hhia-accent), var(--hhia-accent-2));
  color: var(--hhia-accent-ink);
  box-shadow: 0 4px 14px rgba(115, 87, 255, 0.38);
}

/* Right Sidebar Inspector */
.hhia-sidebar {
  border-left: 1px solid var(--hhia-border);
  background: var(--hhia-bg);
  padding: 16px 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.hhia-panel-card {
  padding: 12px;
  border-radius: 12px;
  background: var(--hhia-bg-elev);
  border: 1px solid var(--hhia-border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hhia-panel-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 700;
  color: var(--hhia-ink);
}

.hhia-panel-label small {
  color: var(--hhia-muted);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.hhia-slider {
  width: 100%;
  accent-color: var(--hhia-accent);
  cursor: pointer;
}

.hhia-check {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--hhia-ink);
  cursor: pointer;
}

.hhia-check input[type="checkbox"] {
  accent-color: var(--hhia-accent);
  width: 15px;
  height: 15px;
}

.hhia-shortcuts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  font-size: 11px;
  color: var(--hhia-muted);
}

.hhia-shortcuts span {
  display: flex;
  align-items: center;
  gap: 5px;
}

.hhia-shortcuts kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 18px;
  padding: 0 5px;
  border-radius: 5px;
  border: 1px solid var(--hhia-border-strong);
  background: var(--hhia-bg);
  color: var(--hhia-ink);
  font-family: ui-monospace, monospace;
  font-size: 10px;
  font-weight: 700;
}

.hhia-footer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  background: var(--hhia-bg-elev);
  border-top: 1px solid var(--hhia-border);
}

.hhia-footer-summary {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 12px;
  color: var(--hhia-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hhia-footer button {
  height: 36px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--hhia-border-strong);
  background: transparent;
  color: var(--hhia-ink);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.hhia-footer button:hover:not(:disabled) {
  background: var(--hhia-btn-hover);
}

.hhia-footer button.hhia-cta-save {
  border-color: transparent;
  background: var(--hhia-cta-bg);
  color: var(--hhia-cta-ink);
  font-weight: 700;
  padding: 0 18px;
}

.hhia-footer button:disabled {
  opacity: 0.45;
  cursor: wait;
}

/* /studio/ Reference Thumbnail Inject Button */
.hhsw-thumb,
.hhsw-frame-slot,
.hh-ref-chip,
html body #hhswApp .hhsw-composer .hhref-card {
  position: relative !important;
}

html body button.hhia-ref-annotate-btn[data-hh-annotate-btn="1"],
html body .hhsw-thumb > button.hhia-ref-annotate-btn[data-hh-annotate-btn="1"],
html body .hhsw-frame-slot > button.hhia-ref-annotate-btn[data-hh-annotate-btn="1"],
html body .hh-ref-chip > button.hhia-ref-annotate-btn[data-hh-annotate-btn="1"],
html body #hhswApp .hhsw-composer .hhref-card > button.hhia-ref-annotate-btn[data-hh-annotate-btn="1"] {
  position: absolute !important;
  left: 4px !important;
  bottom: 4px !important;
  top: auto !important;
  right: auto !important;
  z-index: 25 !important;
  width: auto !important;
  min-width: 24px !important;
  max-width: 74px !important;
  height: 22px !important;
  min-height: 22px !important;
  margin: 0 !important;
  padding: 0 7px !important;
  border-radius: 999px !important;
  border: 1px solid rgba(255, 255, 255, 0.28) !important;
  background: rgba(16, 18, 24, 0.88) !important;
  color: #f6e3b4 !important;
  -webkit-text-fill-color: #f6e3b4 !important;
  font-size: 11px !important;
  font-weight: 700 !important;
  line-height: 1 !important;
  cursor: pointer !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 3px !important;
  opacity: 0.92 !important;
  transition: opacity 0.15s ease, transform 0.12s ease !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35) !important;
  pointer-events: auto !important;
}

html body .hhsw-thumb:hover > button.hhia-ref-annotate-btn[data-hh-annotate-btn="1"],
html body .hhsw-thumb:focus-within > button.hhia-ref-annotate-btn[data-hh-annotate-btn="1"],
html body .hhsw-frame-slot:hover > button.hhia-ref-annotate-btn[data-hh-annotate-btn="1"],
html body .hhsw-frame-slot:focus-within > button.hhia-ref-annotate-btn[data-hh-annotate-btn="1"],
html body #hhswApp .hhsw-composer .hhref-card:hover > button.hhia-ref-annotate-btn[data-hh-annotate-btn="1"],
html body #hhswApp .hhsw-composer .hhref-card:focus-within > button.hhia-ref-annotate-btn[data-hh-annotate-btn="1"],
html body .hh-ref-chip:hover > button.hhia-ref-annotate-btn[data-hh-annotate-btn="1"],
html body .hh-ref-chip:focus-within > button.hhia-ref-annotate-btn[data-hh-annotate-btn="1"],
html body button.hhia-ref-annotate-btn[data-hh-annotate-btn="1"]:hover,
html body button.hhia-ref-annotate-btn[data-hh-annotate-btn="1"]:focus-visible {
  opacity: 1 !important;
}

html body .hhref-card > button.hhia-ref-annotate-btn[data-hh-annotate-btn="1"],
html body #hhswApp .hhsw-composer .hhref-card > button.hhia-ref-annotate-btn[data-hh-annotate-btn="1"] {
  top: 4px !important;
  left: 4px !important;
  bottom: auto !important;
  right: auto !important;
  min-width: 22px !important;
  height: 20px !important;
  min-height: 20px !important;
  padding: 0 6px !important;
}

html body .hhref-card:has(.hhref-role) > button.hhia-ref-annotate-btn[data-hh-annotate-btn="1"],
html body #hhswApp .hhsw-composer .hhref-card:has(.hhref-role) > button.hhia-ref-annotate-btn[data-hh-annotate-btn="1"] {
  top: 34px !important;
  left: 4px !important;
  bottom: auto !important;
}

html body #hhswApp .hhsw-composer .hhref-card > button.hhia-ref-annotate-btn[data-hh-annotate-btn="1"]:hover,
html body button.hhia-ref-annotate-btn[data-hh-annotate-btn="1"]:hover {
  background: #D6A64E !important;
  color: #ffffff !important;
  -webkit-text-fill-color: #ffffff !important;
  transform: translateY(-1px) !important;
}

@media (max-width: 880px) {
  .hhia-dialog {
    width: 98vw;
    height: 94vh;
  }
  .hhia-body {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
  }
  .hhia-sidebar {
    border-left: 0;
    border-top: 1px solid var(--hhia-border);
    max-height: 165px;
    padding: 10px 12px;
  }
  .hhia-stage {
    padding: 40px 12px 124px;
  }
  .hhia-tool-btn span {
    display: none;
  }
  .hhia-tool-btn {
    padding: 0 9px;
  }
}

/* 3D Relight & Camera quick pills on Studio reference cards */
html body button.hhia-ref-d3d-btn {
  position: absolute !important;
  bottom: 4px !important;
  z-index: 9 !important;
  width: 22px !important;
  min-width: 22px !important;
  height: 20px !important;
  min-height: 20px !important;
  padding: 0 !important;
  border-radius: 6px !important;
  border: 1px solid rgba(214, 166, 78, 0.45) !important;
  background: rgba(18, 19, 24, 0.84) !important;
  color: #F5D47E !important;
  font: 600 11px/1 system-ui, sans-serif !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  cursor: pointer !important;
  opacity: 0 !important;
  transition: opacity 0.14s ease, background 0.14s ease !important;
  pointer-events: auto !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35) !important;
}
html body button.hhia-ref-d3d-btn.is-relight3d { right: 29px !important; left: auto !important; }
html body button.hhia-ref-d3d-btn.is-camctrl3d { right: 4px !important; left: auto !important; }
html body .hhsw-thumb:hover > button.hhia-ref-d3d-btn,
html body .hhsw-frame-slot:hover > button.hhia-ref-d3d-btn,
html body .hhref-card:hover > button.hhia-ref-d3d-btn,
html body button.hhia-ref-d3d-btn:hover {
  opacity: 1 !important;
}
html body button.hhia-ref-d3d-btn:hover {
  background: #D6A64E !important;
  color: #141311 !important;
}
