/* ==========================================================================
   HAI ANH MINIMAL ADMIN & GOOGLE DOCS-STYLE FREE CANVAS EDITOR
   - Trước khi đăng nhập: Chỉ hiển thị duy nhất 1 nút nhỏ "Admin" ở góc trên bên phải.
   - Sau khi đăng nhập: Chỉ hiển thị 1 nút toggle "Công cụ" và 1 nút "Lưu" ở góc trên bên phải.
   - Khung chọn 8 điểm kiểu Google Docs: Nắm viền để kéo tự do, nắm 8 góc/cạnh để resize độc lập.
   - Không có nút "Kéo" / "Kéo cả ô"; chỉ hiện nút "Đổi ảnh" khi chọn hình ảnh.
   - Menu chuột phải (Context Menu) chuẩn Google Docs.
   ========================================================================== */

/* 1. ĐẢM BẢO ẢNH LUÔN HIỂN THỊ SẮC NÉT 100% */
img,
img.lazy-load,
img.lazyload,
img.rocket-lazyload,
img[data-lazy-src],
img[data-src],
.image-cover img,
.box-image img,
.has-format img,
.page-header-excerpt img {
  opacity: 1 !important;
  visibility: visible !important;
  transition: opacity 0.15s ease !important;
}

[data-placeholder]::before,
[data-empty="true"]::before {
  content: none !important;
  display: none !important;
}

/* 2. TRẠNG THÁI CHƯA ĐĂNG NHẬP: ẨN TUYỆT ĐỐI TOÀN BỘ CÔNG CỤ */
#ha-admin-controls,
#ha-gdocs-toolbar,
#ha-selection-box,
#ha-context-menu,
#ha-studio-topbar,
#ha-drag-handle-pill,
#ha-floating-toolbar,
#ha-breadcrumb-bar {
  display: none !important;
}

/* Nút "Admin" nhỏ gọn ở góc trên bên phải khi chưa đăng nhập */
#ha-stealth-trigger {
  position: fixed !important;
  top: 10px !important;
  right: 12px !important;
  z-index: 2147483645 !important;
  height: 28px !important;
  padding: 0 12px !important;
  border-radius: 4px !important;
  background: rgba(255, 255, 255, 0.92) !important;
  color: #3c4043 !important;
  border: 1px solid #dadce0 !important;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif !important;
  font-size: 12px !important;
  font-weight: 500 !important;
  line-height: 26px !important;
  cursor: pointer !important;
  opacity: 0.55 !important;
  box-shadow: 0 1px 2px rgba(60, 64, 67, 0.15) !important;
  transition: opacity 0.15s ease, background 0.15s ease !important;
  user-select: none !important;
}

#ha-stealth-trigger:hover {
  opacity: 1 !important;
  background: #ffffff !important;
  color: #1a73e8 !important;
  border-color: #1a73e8 !important;
}

html.ha-studio-active #ha-stealth-trigger {
  display: none !important;
}

/* Hộp nhập mật khẩu nhỏ gọn ngay dưới nút Admin */
#ha-login-popover {
  position: fixed !important;
  top: 44px !important;
  right: 12px !important;
  z-index: 2147483646 !important;
  background: #ffffff !important;
  border: 1px solid #dadce0 !important;
  border-radius: 6px !important;
  padding: 10px !important;
  box-shadow: 0 4px 12px rgba(60, 64, 67, 0.2) !important;
  display: none !important;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif !important;
}

#ha-login-popover.open {
  display: block !important;
}

#ha-login-popover form {
  display: flex !important;
  align-items: center !important;
  gap: 6px !important;
  margin: 0 !important;
}

#ha-login-pw {
  width: 150px !important;
  height: 30px !important;
  padding: 0 8px !important;
  border: 1px solid #dadce0 !important;
  border-radius: 4px !important;
  font-size: 13px !important;
  color: #202124 !important;
  background: #ffffff !important;
  outline: none !important;
  margin: 0 !important;
  box-shadow: none !important;
}

#ha-login-pw:focus {
  border-color: #1a73e8 !important;
}

#ha-login-submit {
  height: 30px !important;
  padding: 0 12px !important;
  border: none !important;
  border-radius: 4px !important;
  background: #1a73e8 !important;
  color: #ffffff !important;
  font-size: 12px !important;
  font-weight: 600 !important;
  cursor: pointer !important;
  margin: 0 !important;
}

#ha-login-submit:hover {
  background: #1557b0 !important;
}

#ha-login-err {
  color: #d93025 !important;
  font-size: 11px !important;
  margin-top: 6px !important;
  display: none;
}

/* 3. SAU KHI ĐĂNG NHẬP: CHỈ 1 NÚT TOGGLE "CÔNG CỤ" & 1 NÚT "LƯU" Ở GÓC PHẢI */
html.ha-studio-active #ha-admin-controls {
  position: fixed !important;
  top: 8px !important;
  right: 12px !important;
  z-index: 2147483646 !important;
  display: flex !important;
  align-items: center !important;
  gap: 6px !important;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif !important;
}

.ha-ctrl-btn {
  height: 30px !important;
  padding: 0 12px !important;
  border-radius: 4px !important;
  font-size: 12.5px !important;
  font-weight: 500 !important;
  cursor: pointer !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  margin: 0 !important;
  line-height: 1 !important;
  user-select: none !important;
  transition: background 0.12s ease, border-color 0.12s ease !important;
}

#ha-btn-toggle-tools {
  background: #ffffff !important;
  color: #3c4043 !important;
  border: 1px solid #dadce0 !important;
  box-shadow: 0 1px 3px rgba(60, 64, 67, 0.15) !important;
}

#ha-btn-toggle-tools:hover,
#ha-btn-toggle-tools.active {
  background: #e8f0fe !important;
  color: #1a73e8 !important;
  border-color: #1a73e8 !important;
}

#ha-btn-save {
  background: #1a73e8 !important;
  color: #ffffff !important;
  border: 1px solid #1a73e8 !important;
  font-weight: 600 !important;
  box-shadow: 0 1px 3px rgba(26, 115, 232, 0.25) !important;
}

#ha-btn-save:hover {
  background: #1557b0 !important;
  border-color: #1557b0 !important;
}

/* 4. THANH CÔNG CỤ KIỂU GOOGLE DOCS (CHỈ HIỆN KHI BẬT TOGGLE "CÔNG CỤ") */
html.ha-studio-active.ha-toolbar-open #ha-gdocs-toolbar {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  min-height: 42px !important;
  z-index: 2147483645 !important;
  background: #f9fbfd !important;
  border-bottom: 1px solid #dadce0 !important;
  display: flex !important;
  align-items: center !important;
  flex-wrap: wrap !important;
  gap: 3px !important;
  padding: 4px 160px 4px 12px !important;
  box-shadow: 0 1px 3px rgba(60, 64, 67, 0.08) !important;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif !important;
  user-select: none !important;
}

html.ha-studio-active.ha-toolbar-open body {
  padding-top: 42px !important;
}

.ha-gd-sep {
  width: 1px !important;
  height: 20px !important;
  background: #dadce0 !important;
  margin: 0 4px !important;
  flex-shrink: 0 !important;
}

.ha-gd-btn {
  min-width: 28px !important;
  height: 28px !important;
  padding: 0 7px !important;
  border: 1px solid transparent !important;
  border-radius: 4px !important;
  background: transparent !important;
  color: #444746 !important;
  font-size: 13px !important;
  font-weight: 500 !important;
  cursor: pointer !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  margin: 0 !important;
  line-height: 1 !important;
}

.ha-gd-btn:hover {
  background: #edf2fa !important;
  color: #1f1f1f !important;
}

.ha-gd-btn.active {
  background: #d3e3fd !important;
  color: #041e49 !important;
  font-weight: 600 !important;
}

.ha-gd-btn:disabled {
  opacity: 0.38 !important;
  cursor: default !important;
}

.ha-gd-btn.danger:hover {
  background: #fce8e6 !important;
  color: #c5221f !important;
}

.ha-gd-select {
  height: 28px !important;
  padding: 0 6px !important;
  border: 1px solid #dadce0 !important;
  border-radius: 4px !important;
  background: #ffffff !important;
  color: #1f1f1f !important;
  font-size: 12px !important;
  outline: none !important;
  margin: 0 !important;
  cursor: pointer !important;
}

#ha-page-switcher {
  width: 135px !important;
}

#ha-gd-blockstyle {
  width: 118px !important;
}

#ha-gd-font {
  width: 145px !important;
}

.ha-gd-size-input {
  width: 38px !important;
  height: 26px !important;
  padding: 0 2px !important;
  border: 1px solid #dadce0 !important;
  border-radius: 4px !important;
  background: #ffffff !important;
  color: #1f1f1f !important;
  font-size: 12px !important;
  text-align: center !important;
  margin: 0 !important;
}

/* Nút chọn màu chữ & màu nền kèm thanh hiển thị màu hiện tại chuẩn Google Docs */
.ha-gd-color-wrap {
  position: relative !important;
  display: inline-flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  width: 28px !important;
  height: 28px !important;
  border-radius: 4px !important;
  cursor: pointer !important;
}

.ha-gd-color-wrap:hover {
  background: #edf2fa !important;
}

.ha-gd-color-label {
  font-size: 12px !important;
  font-weight: 700 !important;
  color: #444746 !important;
  line-height: 1 !important;
  margin-bottom: 2px !important;
  pointer-events: none !important;
}

.ha-gd-color-bar {
  width: 16px !important;
  height: 3.5px !important;
  border-radius: 1px !important;
  border: 1px solid rgba(0, 0, 0, 0.15) !important;
  pointer-events: none !important;
}

.ha-gd-color-input {
  position: absolute !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
  opacity: 0 !important;
  cursor: pointer !important;
  margin: 0 !important;
  padding: 0 !important;
  border: none !important;
}

/* 5. SOẠN THẢO TRỰC TIẾP & KHUNG CHỌN 8 ĐIỂM RESIZE TỰ DO */
html.ha-studio-active [contenteditable="true"] {
  outline: none !important;
  cursor: text !important;
}

html.ha-studio-active .ha-hovered-el {
  outline: 1px dashed rgba(26, 115, 232, 0.45) !important;
  outline-offset: 1px !important;
}

html.ha-studio-active #ha-selection-box.active {
  position: fixed !important;
  z-index: 2147483640 !important;
  pointer-events: none !important;
  border: 1.5px solid #1a73e8 !important;
  box-sizing: border-box !important;
  display: block !important;
}

/* 4 Cạnh viền khung chọn: cho phép nắm kéo di chuyển tự do ở bất kỳ cạnh nào */
.ha-sel-edge {
  position: absolute !important;
  pointer-events: auto !important;
  cursor: move !important;
}

.ha-sel-edge.n {
  top: -5px !important;
  left: 6px !important;
  right: 6px !important;
  height: 10px !important;
}

.ha-sel-edge.s {
  bottom: -5px !important;
  left: 6px !important;
  right: 6px !important;
  height: 10px !important;
}

.ha-sel-edge.w {
  left: -5px !important;
  top: 6px !important;
  bottom: 6px !important;
  width: 10px !important;
}

.ha-sel-edge.e {
  right: -5px !important;
  top: 6px !important;
  bottom: 6px !important;
  width: 10px !important;
}

/* 8 Điểm vuông (Handles) kéo giãn kích thước kiểu Google Docs */
.ha-sel-handle {
  position: absolute !important;
  width: 9px !important;
  height: 9px !important;
  background: #1a73e8 !important;
  border: 1.5px solid #ffffff !important;
  box-sizing: border-box !important;
  pointer-events: auto !important;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25) !important;
}

.ha-sel-handle.nw { top: -5px !important; left: -5px !important; cursor: nwse-resize !important; }
.ha-sel-handle.n  { top: -5px !important; left: calc(50% - 4.5px) !important; cursor: ns-resize !important; }
.ha-sel-handle.ne { top: -5px !important; right: -5px !important; cursor: nesw-resize !important; }
.ha-sel-handle.e  { top: calc(50% - 4.5px) !important; right: -5px !important; cursor: ew-resize !important; }
.ha-sel-handle.se { bottom: -5px !important; right: -5px !important; cursor: nwse-resize !important; }
.ha-sel-handle.s  { bottom: -5px !important; left: calc(50% - 4.5px) !important; cursor: ns-resize !important; }
.ha-sel-handle.sw { bottom: -5px !important; left: -5px !important; cursor: nesw-resize !important; }
.ha-sel-handle.w  { top: calc(50% - 4.5px) !important; left: -5px !important; cursor: ew-resize !important; }

/* Nút nhỏ "Đổi ảnh" chỉ hiện duy nhất khi chọn Hình ảnh */
.ha-sel-bar {
  position: absolute !important;
  top: -26px !important;
  left: -1.5px !important;
  display: none;
  align-items: center !important;
  background: #1a73e8 !important;
  color: #ffffff !important;
  border-radius: 3px !important;
  padding: 1px 3px !important;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif !important;
  font-size: 11px !important;
  font-weight: 500 !important;
  line-height: 18px !important;
  pointer-events: auto !important;
  white-space: nowrap !important;
  user-select: none !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2) !important;
}

#ha-selection-box.flip-bottom .ha-sel-bar {
  top: auto !important;
  bottom: -26px !important;
}

.ha-sel-bar-act {
  padding: 0 7px !important;
  color: #ffffff !important;
  background: transparent !important;
  border: none !important;
  font-size: 11px !important;
  font-weight: 600 !important;
  cursor: pointer !important;
  height: 20px !important;
  line-height: 20px !important;
  margin: 0 !important;
}

.ha-sel-bar-act:hover {
  background: rgba(255, 255, 255, 0.2) !important;
  border-radius: 2px !important;
}

/* 6. MENU CHUỘT PHẢI (RIGHT-CLICK CONTEXT MENU) CHUẨN GOOGLE DOCS */
html.ha-studio-active #ha-context-menu.open {
  position: fixed !important;
  z-index: 2147483647 !important;
  display: block !important;
  background: #ffffff !important;
  border: 1px solid #dadce0 !important;
  border-radius: 8px !important;
  box-shadow: 0 4px 16px rgba(60, 64, 67, 0.22) !important;
  padding: 6px 0 !important;
  min-width: 256px !important;
  max-height: calc(100vh - 24px) !important;
  overflow-y: auto !important;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif !important;
  user-select: none !important;
}

.ha-ctx-item {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  width: 100% !important;
  padding: 6px 16px !important;
  border: none !important;
  background: transparent !important;
  color: #202124 !important;
  font-size: 13px !important;
  font-weight: 400 !important;
  text-align: left !important;
  cursor: pointer !important;
  margin: 0 !important;
  line-height: 18px !important;
  box-sizing: border-box !important;
}

.ha-ctx-item:hover:not(:disabled) {
  background: #f1f3f4 !important;
}

.ha-ctx-item:disabled {
  opacity: 0.42 !important;
  cursor: default !important;
}

.ha-ctx-item.danger {
  color: #c5221f !important;
}

.ha-ctx-item.danger:hover:not(:disabled) {
  background: #fce8e6 !important;
}

.ha-ctx-label {
  flex: 1 !important;
  padding-right: 16px !important;
}

.ha-ctx-shortcut {
  color: #5f6368 !important;
  font-size: 12px !important;
  font-weight: 400 !important;
  flex-shrink: 0 !important;
}

.ha-ctx-sep {
  height: 1px !important;
  background: #e8eaed !important;
  margin: 5px 0 !important;
}

/* 7. THÔNG BÁO NHỎ GÓC DƯỚI */
#ha-toast-notification {
  position: fixed !important;
  bottom: 16px !important;
  right: 16px !important;
  z-index: 2147483647 !important;
  background: #323232 !important;
  color: #ffffff !important;
  padding: 8px 14px !important;
  border-radius: 4px !important;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif !important;
  font-size: 12.5px !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25) !important;
  pointer-events: none !important;
  opacity: 0 !important;
  transform: translateY(8px) !important;
  transition: opacity 0.18s ease, transform 0.18s ease !important;
}

#ha-toast-notification.show {
  opacity: 1 !important;
  transform: translateY(0) !important;
}
