/* Hikari UI - Base Design Tokens */

*, *::before, *::after {
  box-sizing: border-box;
}

:root {
  /* Neutral colors (cool-toned) */
  --hk-gray-50: #f7fafc;
  --hk-gray-100: #f0f2f4;
  --hk-gray-200: #e2e8f0;
  --hk-gray-300: #cbd5e0;
  --hk-gray-400: #a0aec0;
  --hk-gray-500: #718096;
  --hk-gray-600: #4a5568;
  --hk-gray-700: #2d3748;
  --hk-gray-800: #1a202c;
  --hk-gray-900: #212529;

  /* Semantic colors (default = CFL) */
  --hk-primary: #2c5282;
  --hk-primary-light: #428bb0;
  --hk-primary-dark: #1a365d;
  --hk-primary-rgb: 44, 82, 130;
  --hk-primary-50: #ebf8ff;
  --hk-primary-100: rgba(44, 82, 130, 0.1);
  --hk-primary-300: #90cdf4;
  --hk-primary-700: #2a4365;
  --hk-success: #38a169;
  --hk-success-rgb: 56, 161, 105;
  --hk-success-50: rgba(56, 161, 105, 0.06);
  --hk-success-100: rgba(56, 161, 105, 0.12);
  --hk-success-300: #68d391;
  --hk-success-700: #276749;
  --hk-warning: #c05621;
  --hk-warning-rgb: 192, 86, 33;
  --hk-warning-50: rgba(192, 86, 33, 0.06);
  --hk-warning-100: rgba(192, 86, 33, 0.12);
  --hk-warning-300: #ed8936;
  --hk-warning-700: #9c4221;
  --hk-danger: #e53e3e;
  --hk-danger-rgb: 229, 62, 62;
  --hk-danger-50: rgba(229, 62, 62, 0.06);
  --hk-danger-100: rgba(229, 62, 62, 0.12);
  --hk-danger-300: #fc8181;
  --hk-danger-700: #c53030;
  --hk-info: #3182ce;
  --hk-info-rgb: 49, 130, 206;
  --hk-info-50: rgba(49, 130, 206, 0.06);
  --hk-info-100: rgba(49, 130, 206, 0.12);
  --hk-info-300: #63b3ed;
  --hk-info-700: #2b6cb0;

  /* Typography */
  --hk-font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  --hk-mono-family: 'JetBrains Mono', 'Fira Code', 'Consolas', 'Menlo', monospace;
  --hk-font-size-xs: 0.75rem;
  --hk-font-size-sm: 0.875rem;
  --hk-font-size-md: 1rem;
  --hk-font-size-lg: 1.125rem;
  --hk-font-size-xl: 1.25rem;
  --hk-font-size-2xl: 1.5rem;
  --hk-font-size-3xl: 1.875rem;
  --hk-line-height: 1.5;
  --hk-font-weight-normal: 400;
  --hk-font-weight-medium: 500;
  --hk-font-weight-semibold: 600;
  --hk-font-weight-bold: 700;

  /* Spacing (4px grid) */
  --hk-space-xs: 4px;
  --hk-space-sm: 8px;
  --hk-space-md: 16px;
  --hk-space-lg: 24px;
  --hk-space-xl: 32px;
  --hk-space-2xl: 48px;

  /* Borders & Radius */
  --hk-radius-sm: 2px;
  --hk-radius-md: 4px;
  --hk-radius-lg: 6px;
  --hk-radius-full: 9999px;
  --hk-border-width: 1px;
  --hk-border-color: var(--hk-gray-300);

  /* Shadows */
  --hk-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --hk-shadow-md: 0 2px 4px rgba(0, 0, 0, 0.06);
  --hk-shadow-lg: 0 4px 6px rgba(0, 0, 0, 0.08);

  /* Input */
  --hk-input-height: 40px;
  --hk-input-height-sm: 32px;
  --hk-input-height-lg: 48px;
  --hk-input-padding-x: 12px;
  --hk-input-border-color: var(--hk-gray-300);
  --hk-input-focus-ring: 0 0 0 3px rgba(var(--hk-primary-rgb), 0.2);
  --hk-input-bg: #ffffff;
  --hk-input-disabled-bg: var(--hk-gray-100);

  /* Button */
  --hk-btn-height: 34px;
  --hk-btn-height-sm: 28px;
  --hk-btn-height-lg: 40px;
  --hk-btn-padding-y: 5px;
  --hk-btn-padding-x: 12px;
  --hk-btn-padding-y-sm: 2px;
  --hk-btn-padding-x-sm: 8px;
  --hk-btn-padding-y-lg: 6px;
  --hk-btn-padding-x-lg: 20px;

  /* AppBar */
  --hk-app-bar-height: 50px;
  --hk-app-bar-bg: var(--hk-primary);
  --hk-app-bar-color: #ffffff;

  /* Card / Panel */
  --hk-card-accent-width: 4px;
  --hk-card-bg: #ffffff;
  --hk-card-border-color: var(--hk-gray-200);

  /* Transitions */
  --hk-transition-fast: 150ms ease;
  --hk-transition-normal: 250ms ease;

  /* Z-index layers */
  --hk-z-dropdown: 1000;
  --hk-z-modal-backdrop: 1040;
  --hk-z-modal: 1050;
  --hk-z-tooltip: 1070;
}

.hk-root {
  font-family: var(--hk-font-family);
  font-size: var(--hk-font-size-md);
  line-height: var(--hk-line-height);
  color: var(--hk-gray-900);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Shared input styles ───────────────────── */

.hk-textbox {
  display: block;
  width: 100%;
  height: var(--hk-input-height);
  padding: var(--hk-space-sm) var(--hk-input-padding-x);
  font-family: var(--hk-font-family);
  font-size: var(--hk-font-size-sm);
  color: var(--hk-gray-900);
  background-color: var(--hk-input-bg);
  border: var(--hk-border-width) solid var(--hk-input-border-color);
  border-radius: var(--hk-radius-md);
  transition: border-color var(--hk-transition-fast), box-shadow var(--hk-transition-fast);
}

.hk-textbox:focus {
  outline: none;
  border-color: var(--hk-primary);
  box-shadow: var(--hk-input-focus-ring);
}

.hk-textbox::placeholder {
  color: var(--hk-gray-400);
}

.hk-textbox:disabled, .hk-textbox--disabled {
  background-color: var(--hk-input-disabled-bg);
  cursor: not-allowed;
  opacity: 0.7;
}

.hk-textbox:read-only, .hk-textbox--readonly {
  background-color: var(--hk-input-disabled-bg);
}

.hk-textarea {
  display: block;
  width: 100%;
  height: auto;
  min-height: 80px;
  padding: var(--hk-space-sm) var(--hk-input-padding-x);
  font-family: var(--hk-font-family);
  font-size: var(--hk-font-size-sm);
  color: var(--hk-gray-900);
  background-color: var(--hk-input-bg);
  border: var(--hk-border-width) solid var(--hk-input-border-color);
  border-radius: var(--hk-radius-md);
  resize: vertical;
  transition: border-color var(--hk-transition-fast), box-shadow var(--hk-transition-fast);
}

/* Auto-grow: textarea hugs its content (no inner scrollbar). field-sizing is
   native on Chromium; Firefox/Safari fall back to JS height (hk-textarea.js).
   min-height above stays as the floor. */
.hk-textarea--autogrow {
  field-sizing: content;
  resize: none;
  overflow: hidden;
}

.hk-textarea:focus {
  outline: none;
  border-color: var(--hk-primary);
  box-shadow: var(--hk-input-focus-ring);
}

.hk-textarea::placeholder {
  color: var(--hk-gray-400);
}

.hk-textarea:disabled {
  background-color: var(--hk-input-disabled-bg);
  cursor: not-allowed;
  opacity: 0.7;
}

.hk-textarea:read-only {
  background-color: var(--hk-input-disabled-bg);
}

/* ── Floating label ────────────────────────── */

.hk-floating-label {
  position: relative;
  display: block;
  width: 100%;
}

.hk-floating-label__text {
  position: absolute;
  top: 50%;
  left: var(--hk-input-padding-x);
  transform: translateY(-50%);
  font-size: var(--hk-font-size-sm);
  color: var(--hk-gray-500);
  pointer-events: none;
  transition: all var(--hk-transition-fast);
  transform-origin: left top;
  background: var(--hk-input-bg);
  padding: 0 4px;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: calc(100% - 2 * var(--hk-input-padding-x));
}

.hk-floating-label:focus-within .hk-floating-label__text,
.hk-floating-label--filled .hk-floating-label__text {
  top: 0;
  transform: translateY(-50%) scale(0.85);
  color: var(--hk-gray-600);
}

.hk-floating-label:focus-within .hk-floating-label__text {
  color: var(--hk-primary);
}

/* Hide native placeholder when floating label is in resting position */
.hk-floating-label:not(:focus-within):not(.hk-floating-label--filled) input::placeholder,
.hk-floating-label:not(:focus-within):not(.hk-floating-label--filled) textarea::placeholder {
  color: transparent;
}

/* Textarea: label starts near the top row, not vertically centered */
.hk-floating-label--textarea .hk-floating-label__text {
  top: 12px;
  transform: translateY(0);
}

.hk-floating-label--textarea:focus-within .hk-floating-label__text,
.hk-floating-label--textarea.hk-floating-label--filled .hk-floating-label__text {
  top: 0;
  transform: translateY(-50%) scale(0.85);
}

/* ── Masked input ────────────────────────── */

.hk-masked-input {
  position: relative;
  display: inline-block;
  width: 100%;
}

.hk-masked-input--has-clear .hk-masked-input__input {
  padding-right: calc(var(--hk-input-padding-x) + 24px);
}

.hk-masked-input__clear {
  position: absolute;
  top: 50%;
  right: var(--hk-space-xs);
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  border-radius: var(--hk-radius-sm);
  background: transparent;
  color: var(--hk-gray-400);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  transition: color var(--hk-transition-fast), background-color var(--hk-transition-fast);
}

.hk-masked-input__clear:hover {
  color: var(--hk-gray-600);
  background-color: var(--hk-gray-100);
}

/* ── Stack ──────────────────────────────────── */

.hk-stack {
  display: flex;
}

.hk-stack--column { flex-direction: column; }
.hk-stack--row { flex-direction: row; }
.hk-stack--wrap { flex-wrap: wrap; }

/* Gap */
.hk-stack--gap-none { gap: 0; }
.hk-stack--gap-xs { gap: var(--hk-space-xs); }
.hk-stack--gap-sm { gap: var(--hk-space-sm); }
.hk-stack--gap-md { gap: var(--hk-space-md); }
.hk-stack--gap-lg { gap: var(--hk-space-lg); }
.hk-stack--gap-xl { gap: var(--hk-space-xl); }
.hk-stack--gap-xxl { gap: var(--hk-space-2xl); }

/* Align items */
.hk-stack--items-start { align-items: flex-start; }
.hk-stack--items-center { align-items: center; }
.hk-stack--items-end { align-items: flex-end; }
.hk-stack--items-stretch { align-items: stretch; }
.hk-stack--items-baseline { align-items: baseline; }

/* Justify content */
.hk-stack--justify-start { justify-content: flex-start; }
.hk-stack--justify-center { justify-content: center; }
.hk-stack--justify-end { justify-content: flex-end; }
.hk-stack--justify-between { justify-content: space-between; }
.hk-stack--justify-around { justify-content: space-around; }
.hk-stack--justify-evenly { justify-content: space-evenly; }

/* Responsive */
@media (max-width: 640px) {
  .hk-stack {
    flex-direction: var(--hk-stack-dir-mobile, inherit);
    gap: var(--hk-stack-gap-mobile, inherit);
  }
}

/* ── Input Group ────────────────────────────── */

.hk-input-group {
  display: flex;
  flex-direction: column;
  width: 100%;
}

.hk-input-group__label {
  font-size: var(--hk-font-size-sm);
  font-weight: var(--hk-font-weight-semibold);
  color: var(--hk-gray-600);
  margin-bottom: var(--hk-space-xs);
}

/* ── Editor pagination ── */

.hk-editor--paginated {
  background: var(--hk-gray-200);
  border-color: var(--hk-gray-300);
}

.hk-editor--paginated .hk-editor__content {
  background: var(--hk-gray-200);
  display: flex;
  justify-content: center;
}

.hk-editor--paginated .tiptap {
  background: transparent;
  line-height: var(--hk-editor-line-spacing, 1.15);
  zoom: var(--hk-zoom);
}

/* Body content padding to avoid overlap with H/F dashed overlay regions */
.hk-editor--paginated [data-page-body] > div {
  padding-top: var(--hk-header-height, 0mm);
  padding-bottom: var(--hk-footer-height, 0mm);
}

.hk-editor__page-format-select {
  appearance: auto;
  border: 1px solid var(--hk-gray-300);
  border-radius: var(--hk-radius-sm);
  padding: 2px var(--hk-space-xs);
  font-size: var(--hk-font-size-sm);
  background: #fff;
  cursor: pointer;
  height: 28px;
}

.hk-editor__page-format-select:hover {
  border-color: var(--hk-gray-400);
}

.hk-editor__page-format-select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.hk-editor__zoom-group {
  align-items: center;
}

.hk-editor__zoom-label {
  font-size: var(--hk-font-size-xs);
  min-width: 36px;
  text-align: center;
  user-select: none;
}

.hk-editor__font-family-select {
  appearance: auto;
  border: 1px solid var(--hk-gray-300);
  border-radius: var(--hk-radius-sm);
  padding: 2px var(--hk-space-xs);
  font-size: var(--hk-font-size-sm);
  background: #fff;
  cursor: pointer;
  height: 28px;
  min-width: 120px;
  max-width: 180px;
}

.hk-editor__font-size-select {
  appearance: auto;
  border: 1px solid var(--hk-gray-300);
  border-radius: var(--hk-radius-sm);
  padding: 2px var(--hk-space-xs);
  font-size: var(--hk-font-size-sm);
  background: #fff;
  cursor: pointer;
  height: 28px;
  width: 64px;
}

.hk-editor__line-spacing-select {
  appearance: auto;
  border: 1px solid var(--hk-gray-300);
  border-radius: var(--hk-radius-sm);
  padding: 2px var(--hk-space-xs);
  font-size: var(--hk-font-size-sm);
  background: #fff;
  cursor: pointer;
  height: 28px;
  width: 80px;
}

.hk-editor__heading-select {
  appearance: auto;
  border: 1px solid var(--hk-gray-300);
  border-radius: var(--hk-radius-sm);
  padding: 2px var(--hk-space-xs);
  font-size: var(--hk-font-size-sm);
  background: #fff;
  cursor: pointer;
  height: 28px;
  min-width: 110px;
}

.hk-editor__heading-select:hover {
  border-color: var(--hk-gray-400);
}

.hk-editor__heading-select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── Positioned blocks ── */

.ak-positioned-block--editing {
  position: relative;
  z-index: 1;
  min-height: 10mm;
}

.ak-positioned-block--editing:hover .ak-positioned-block__handle,
.ak-positioned-block--editing:hover .ak-positioned-block__delete,
.ak-positioned-block--editing:focus-within .ak-positioned-block__handle,
.ak-positioned-block--editing:focus-within .ak-positioned-block__delete {
  opacity: 1;
}

.ak-positioned-block--editing:hover,
.ak-positioned-block--editing:focus-within {
  outline: 2px solid var(--hk-primary-300, #90cdf4);
}

.ak-positioned-block--dragging {
  opacity: 0.8;
  outline: 2px dashed var(--hk-primary) !important;
}

.ak-positioned-block__content {
  width: 100%;
  height: 100%;
  overflow: hidden;
  cursor: text;
}

.ak-positioned-block__drag-bar {
  position: absolute;
  top: -12px;
  left: 0;
  right: 0;
  height: 12px;
  cursor: move;
  background: var(--hk-primary);
  opacity: 0;
  border-radius: 2px 2px 0 0;
  transition: opacity var(--hk-transition-fast);
}

.ak-positioned-block--editing:hover .ak-positioned-block__drag-bar {
  opacity: 0.6;
}

.ak-positioned-block__drag-bar:hover {
  opacity: 1 !important;
}

.ak-positioned-block__delete {
  position: absolute;
  top: -12px;
  right: -12px;
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 50%;
  background: var(--hk-danger);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity var(--hk-transition-fast);
}

.ak-positioned-block__delete:hover {
  background: var(--hk-danger);
  transform: scale(1.1);
}

.ak-positioned-block__handle {
  position: absolute;
  width: 8px;
  height: 8px;
  background: var(--hk-primary);
  border: 1px solid #fff;
  border-radius: 50%;
  z-index: 2;
  opacity: 0;
  pointer-events: auto;
  transition: opacity var(--hk-transition-fast);
}

.ak-positioned-block__handle--nw { top: -4px; left: -4px; cursor: nw-resize; }
.ak-positioned-block__handle--ne { top: -4px; right: -4px; cursor: ne-resize; }
.ak-positioned-block__handle--sw { bottom: -4px; left: -4px; cursor: sw-resize; }
.ak-positioned-block__handle--se { bottom: -4px; right: -4px; cursor: se-resize; }
.ak-positioned-block__handle--n { top: -4px; left: 50%; margin-left: -4px; cursor: n-resize; }
.ak-positioned-block__handle--s { bottom: -4px; left: 50%; margin-left: -4px; cursor: s-resize; }
.ak-positioned-block__handle--e { top: 50%; right: -4px; margin-top: -4px; cursor: e-resize; }
.ak-positioned-block__handle--w { top: 50%; left: -4px; margin-top: -4px; cursor: w-resize; }

/* Block Properties Dialog */
.hk-block-props-dialog {
  position: fixed;
  top: 48px;
  right: 20px;
  z-index: 1000;
  width: 300px;
  background: var(--hk-surface, #fff);
  border: 1px solid var(--hk-gray-300, #e2e8f0);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  font-size: 13px;
}

.hk-block-props-dialog__titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--hk-gray-200, #edf2f7);
  cursor: move;
  user-select: none;
  font-weight: 600;
  font-size: 13px;
}

.hk-block-props-dialog__close {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--hk-gray-500, #a0aec0);
  padding: 0 4px;
  line-height: 1;
}

.hk-block-props-dialog__close:hover {
  color: var(--hk-gray-700, #4a5568);
}

.hk-block-props-dialog__body {
  padding: 12px;
}

.hk-block-props-dialog__section {
  margin-bottom: 12px;
}

.hk-block-props-dialog__section:last-child {
  margin-bottom: 0;
}

.hk-block-props-dialog__label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--hk-gray-500, #a0aec0);
  margin-bottom: 4px;
}

.hk-block-props-dialog__row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hk-block-props-dialog__select {
  font-size: 12px;
  padding: 4px 6px;
  border: 1px solid var(--hk-gray-300, #e2e8f0);
  border-radius: 4px;
  background: var(--hk-surface, #fff);
  flex: 1;
}

.hk-block-props-dialog__select--small {
  flex: 0;
  width: 60px;
}

.hk-block-props-dialog__color {
  width: 28px;
  height: 24px;
  border: 1px solid var(--hk-gray-300, #e2e8f0);
  border-radius: 4px;
  padding: 1px;
  cursor: pointer;
}

.hk-block-props-dialog__input-number {
  width: 60px;
  font-size: 12px;
  padding: 4px 6px;
  border: 1px solid var(--hk-gray-300, #e2e8f0);
  border-radius: 4px;
}

.hk-block-props-dialog__value {
  font-size: 12px;
  color: var(--hk-gray-600, #718096);
  min-width: 40px;
}

.hk-block-props-dialog__btn-reset {
  font-size: 11px;
  padding: 3px 8px;
  background: var(--hk-gray-100, #f7fafc);
  border: 1px solid var(--hk-gray-300, #e2e8f0);
  border-radius: 4px;
  cursor: pointer;
}

.hk-block-props-dialog__btn-reset:hover {
  background: var(--hk-gray-200, #edf2f7);
}

.hk-block-props-dialog__footer {
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px solid var(--hk-gray-200, #edf2f7);
}

.hk-block-props-dialog__btn-action {
  font-size: 12px;
  padding: 5px 12px;
  background: var(--hk-gray-100, #f7fafc);
  border: 1px solid var(--hk-gray-300, #e2e8f0);
  border-radius: 4px;
  cursor: pointer;
}

.hk-block-props-dialog__btn-action:hover {
  background: var(--hk-gray-200, #edf2f7);
}

/* ── Editor tables ── */

.hk-editor .tiptap .tableWrapper {
  overflow-x: auto;
  margin: var(--hk-space-sm) 0;
}

.hk-editor .tiptap table {
  border-collapse: initial;
  border-spacing: 0;
  width: 100%;
  table-layout: fixed;
  overflow: hidden;
}

.hk-editor .tiptap td,
.hk-editor .tiptap th {
  border: 1px solid #000;
  padding: var(--hk-space-xs) var(--hk-space-sm);
  vertical-align: top;
  min-width: 40px;
  position: relative;
}

/* Table border configuration via CSS custom properties (set by HkTableView) */
.hk-editor .tiptap table[style*="--hk-table-border"] td,
.hk-editor .tiptap table[style*="--hk-table-border"] th {
  border-color: var(--hk-table-border-color, #000);
  border-width: var(--hk-table-border-width, 1px);
  border-style: var(--hk-table-border-style, solid);
}

/* Editor-only: show dashed preview when borders are hidden */
.hk-editor .tiptap table[data-border-hidden] td,
.hk-editor .tiptap table[data-border-hidden] th {
  border: 1px dashed var(--hk-gray-300) !important;
}

.hk-editor .tiptap th {
  font-weight: var(--hk-font-weight-bold);
  background: var(--hk-gray-100);
}

.hk-editor .tiptap .selectedCell {
  background: var(--hk-primary-100, rgba(var(--hk-primary-rgb), 0.1));
}

.hk-editor .tiptap .column-resize-handle {
  position: absolute;
  right: -2px;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--hk-primary);
  pointer-events: none;
  z-index: 20;
}

.hk-editor .tiptap.resize-cursor {
  cursor: col-resize;
}

.hk-editor__table-context-menu {
  z-index: var(--hk-z-dropdown);
  background: #fff;
  border: 1px solid var(--hk-gray-200);
  border-radius: var(--hk-radius-md);
  box-shadow: var(--hk-shadow-lg);
  padding: var(--hk-space-xs) 0;
  min-width: 180px;
}

.hk-editor__table-context-item {
  display: block;
  width: 100%;
  padding: var(--hk-space-xs) var(--hk-space-md);
  border: none;
  background: none;
  text-align: left;
  font-size: var(--hk-font-size-sm);
  cursor: pointer;
  color: var(--hk-gray-700);
}

.hk-editor__table-context-item:hover {
  background: var(--hk-gray-100);
}

.hk-editor__table-context-item--danger {
  color: var(--hk-danger);
}

.hk-editor__table-context-item--danger:hover {
  background: rgba(var(--hk-danger-rgb), 0.08);
}

.hk-editor__table-context-sep {
  height: 1px;
  background: var(--hk-gray-200);
  margin: var(--hk-space-xs) 0;
}

.hk-editor__table-context-color-row,
.hk-editor__table-context-select-row {
  display: flex;
  align-items: center;
  gap: var(--hk-space-xs);
  padding: var(--hk-space-xs) var(--hk-space-md);
}

.hk-editor__table-context-label {
  font-size: var(--hk-font-size-sm);
  color: var(--hk-gray-700);
  flex: 1;
  white-space: nowrap;
}

.hk-editor__table-context-label--title {
  font-weight: var(--hk-font-weight-bold);
  padding: var(--hk-space-xs) var(--hk-space-md) 0;
}

.hk-editor__table-context-color-input {
  width: 28px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--hk-gray-300);
  border-radius: var(--hk-radius-sm);
  cursor: pointer;
  background: none;
  flex-shrink: 0;
}

.hk-editor__table-context-color-input::-webkit-color-swatch-wrapper {
  padding: 2px;
}

.hk-editor__table-context-color-input::-webkit-color-swatch {
  border: none;
  border-radius: 2px;
}

.hk-editor__table-context-clear-btn {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--hk-gray-300);
  border-radius: var(--hk-radius-sm);
  background: none;
  cursor: pointer;
  font-size: 12px;
  color: var(--hk-gray-500);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.hk-editor__table-context-clear-btn:hover {
  background: var(--hk-gray-100);
  color: var(--hk-gray-700);
}

.hk-editor__table-context-select {
  padding: 2px 4px;
  border: 1px solid var(--hk-gray-300);
  border-radius: var(--hk-radius-sm);
  font-size: var(--hk-font-size-sm);
  color: var(--hk-gray-700);
  background: #fff;
  cursor: pointer;
  flex-shrink: 0;
}

.hk-editor__table-context-border-section {
  padding: var(--hk-space-xs) 0;
}

/* Mini condition editor (TipTap instance) */
.hk-condition-editor {
  border: 1px solid var(--hk-gray-300);
  border-radius: var(--hk-radius-md);
  background: #fff;
  overflow: hidden;
}

.hk-condition-editor__label {
  display: block;
  padding: 4px 10px 2px;
  background: var(--hk-gray-50);
  border-bottom: 1px solid var(--hk-gray-200);
  font-size: 10px;
  line-height: 1;
  font-weight: var(--hk-font-weight-bold);
  color: var(--hk-gray-600);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.hk-condition-editor__input {
  border: 1px solid var(--hk-gray-300);
  border-radius: var(--hk-radius-sm);
  margin: 8px;
  padding: 10px 12px;
  min-height: 56px;
  background: #fff;
  font-size: var(--hk-font-size-sm);
  color: var(--hk-gray-900);
}

.hk-condition-editor__input:focus,
.hk-condition-editor__input:focus-within {
  outline: none;
  border-color: var(--hk-primary);
  box-shadow: 0 0 0 2px rgba(var(--hk-primary-rgb), 0.15);
}

.hk-condition-editor__tiptap {
  outline: none;
  min-height: 20px;
}

.hk-condition-editor__tiptap p {
  margin: 0;
}

/* Inline If Editor (dedicated editing space) */
.hk-inline-if-editor {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: #fff;
  border: 1px solid var(--hk-gray-200);
  border-radius: var(--hk-radius-md);
}

.hk-inline-if-editor__header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--hk-gray-800);
  color: #fff;
  font-family: var(--hk-mono-family);
  font-size: var(--hk-font-size-xs);
  border-bottom: 1px solid var(--hk-gray-200);
  border-radius: var(--hk-radius-md) var(--hk-radius-md) 0 0;
}

.hk-inline-if-editor__header-comment {
  opacity: 0.6;
}

.hk-inline-if-editor__title {
  color: var(--hk-success-300);
  flex: 1;
}

.hk-inline-if-editor__actions {
  display: flex;
  gap: var(--hk-space-xs);
  margin-left: auto;
}

.hk-inline-if-editor .hk-inline-if-editor__header .hk-btn--flat.hk-btn--neutral {
  background-color: var(--hk-gray-700);
  color: var(--hk-gray-300);
}

.hk-inline-if-editor .hk-inline-if-editor__header .hk-btn--flat.hk-btn--neutral:hover:not(:disabled) {
  background-color: var(--hk-gray-600);
  color: #fff;
}

.hk-inline-if-editor__body {
  flex: 1;
  overflow-y: auto;
  padding: 0 0 0 14px;
  border-left: 2px dashed var(--hk-primary-300);
}

/* Condition tree (shared between inline-if-editor and panel) */
.hk-condition-tree__node {
  padding: 4px 0;
}

.hk-condition-tree__header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--hk-font-size-sm);
}

/* IDE-style syntax-highlighted branch header */
.kw {
  font-family: var(--hk-mono-family);
  font-weight: 800;
  font-size: var(--hk-font-size-md);
}

.kw--if,
.kw--elseif,
.kw--else {
  color: #1976d2;
}

.path {
  font-family: var(--hk-mono-family);
  font-size: var(--hk-font-size-sm);
  color: var(--hk-success-700);
}

.op {
  font-family: var(--hk-mono-family);
  font-size: var(--hk-font-size-sm);
  color: var(--hk-gray-600);
  margin: 0 4px;
}

.val {
  font-family: var(--hk-mono-family);
  font-size: var(--hk-font-size-sm);
  color: var(--hk-info);
}

.val::before,
.val::after {
  content: '"';
  color: var(--hk-gray-400);
}

.hk-condition-tree__actions {
  display: flex;
  gap: 2px;
  margin-left: auto;
}

/* IDE-style condition config row */
.cond-config {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 8px 12px;
  background: var(--hk-gray-50);
  border: 1px solid var(--hk-gray-200);
  border-radius: var(--hk-radius-sm);
  margin-bottom: 8px;
}

.cond-config__field {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cond-config__field--grow {
  flex: 1;
  min-width: 0;
}

.cond-config__label {
  font-family: var(--hk-mono-family);
  font-size: 9px;
  color: var(--hk-gray-500);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.cond-config__field-chip {
  height: 26px;
  padding: 0 10px;
  font-family: var(--hk-mono-family);
  font-size: var(--hk-font-size-xs);
  color: var(--hk-success-700);
  background: #fff;
  border: 1px solid var(--hk-gray-300);
  border-radius: var(--hk-radius-sm);
  cursor: pointer;
  transition: all var(--hk-transition-fast);
}

.cond-config__field-chip:hover {
  border-color: var(--hk-primary-300);
  background: var(--hk-primary-50);
}

.cond-config__field-chip--active {
  border-color: var(--hk-primary);
  background: var(--hk-primary-50);
  box-shadow: 0 0 0 2px rgba(var(--hk-primary-rgb), 0.15);
}

.cond-config__select,
.cond-config__input {
  height: 26px;
  padding: 0 8px;
  font-size: var(--hk-font-size-xs);
  font-family: var(--hk-mono-family);
  border: 1px solid var(--hk-gray-300);
  border-radius: var(--hk-radius-sm);
  background: #fff;
  color: var(--hk-gray-800);
}

.cond-config__select:focus,
.cond-config__input:focus {
  outline: none;
  border-color: var(--hk-primary);
  box-shadow: 0 0 0 2px rgba(var(--hk-primary-rgb), 0.15);
}

.hk-condition-tree__actions button {
  border: none;
  background: none;
  font-size: 11px;
  color: var(--hk-gray-500);
  cursor: pointer;
  padding: 1px 4px;
}

.hk-condition-tree__actions button:hover {
  color: var(--hk-primary);
}

.hk-condition-tree__condition-config {
  margin-top: 2px;
  margin-bottom: 2px;
}

.hk-condition-tree__content {
  margin-top: 4px;
  margin-left: 12px;
}

/* Nested depth indent guides — dashed lines, color per depth, with subtle background tint */
.hk-condition-tree__node[data-depth="1"] {
  border-left: 2px dashed var(--hk-warning-300);
  padding-left: 14px;
  background: var(--hk-warning-50);
  border-radius: var(--hk-radius-sm);
}
.hk-condition-tree__node[data-depth="2"] {
  border-left: 2px dashed var(--hk-success-300);
  padding-left: 14px;
  background: var(--hk-success-100);
  border-radius: var(--hk-radius-sm);
}
.hk-condition-tree__node[data-depth="3"],
.hk-condition-tree__node[data-depth]:not([data-depth="0"]):not([data-depth="1"]):not([data-depth="2"]) {
  border-left: 2px dashed var(--hk-gray-400);
  padding-left: 14px;
  background: var(--hk-gray-100);
  border-radius: var(--hk-radius-sm);
}

.hk-condition-tree__add-group {
  padding: 2px 0;
}
.hk-condition-tree__add-group button {
  font-size: var(--hk-font-size-xs);
  color: var(--hk-primary-600);
  background: none;
  border: 1px dashed var(--hk-primary-300);
  border-radius: var(--hk-radius-sm);
  padding: 2px 8px;
  cursor: pointer;
}
.hk-condition-tree__add-group button:hover {
  background: var(--hk-primary-50);
}

/* Chip format popover (floating below chip in inline-if-editor) */
.hk-inline-if-editor__chip-popover {
  background: #fff;
  border: 1px solid var(--hk-gray-300);
  border-radius: var(--hk-radius-md);
  padding: var(--hk-spacing-md);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 100;
  min-width: 240px;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: var(--hk-spacing-xs);
}

.hk-inline-if-editor__chip-popover .hk-smart-panel__config-header {
  font-weight: var(--hk-font-weight-semibold);
  font-size: var(--hk-font-size-sm);
  margin-bottom: 4px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--hk-gray-200);
}

.hk-inline-if-editor__chip-popover .hk-smart-panel__config-label {
  margin-top: 4px;
}

.hk-inline-if-editor__chip-popover .hk-radio-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hk-inline-if-editor__chip-popover .hk-smart-panel__config-actions {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--hk-gray-200);
}

/* Inline conditional node */
.smart-if-inline {
  display: inline;
  border-bottom: 1.5px dashed var(--hk-primary-300);
  cursor: default;
  user-select: none;
  -webkit-user-modify: read-only;
}

.smart-if-inline--selected {
  background: var(--hk-primary-50);
  border-bottom-color: var(--hk-primary);
}

/* ── SmartDataForm (tree layout) ── */

.hk-smart-data-form {
  display: flex;
  flex-direction: column;
  font-family: var(--hk-font-family);
  font-size: var(--hk-font-size-sm);
}

.hk-smart-data-form__category {
  display: flex;
  flex-direction: column;
}

.hk-smart-data-form__category-title {
  font-size: var(--hk-font-size-xs);
  font-weight: var(--hk-font-weight-bold);
  text-transform: uppercase;
  color: var(--hk-gray-500);
  padding: var(--hk-space-sm) 0 var(--hk-space-2xs);
  border-bottom: 1px solid var(--hk-gray-200);
  margin-bottom: var(--hk-space-2xs);
}

.hk-smart-data-form__field {
  display: grid;
  grid-template-columns: 120px minmax(0, 160px) auto;
  align-items: center;
  gap: var(--hk-space-xs);
  padding: 3px 0;
  min-height: 28px;
}

.hk-smart-data-form__label {
  font-size: var(--hk-font-size-xs);
  color: var(--hk-gray-600);
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hk-smart-data-form__section {
  display: flex;
  flex-direction: column;
}

.hk-smart-data-form__section-toggle {
  display: flex;
  align-items: center;
  gap: var(--hk-space-2xs);
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  font-size: var(--hk-font-size-sm);
  font-weight: var(--hk-font-weight-semibold);
  color: var(--hk-primary);
  padding: 4px 0;
}

.hk-smart-data-form__section-toggle:hover {
  color: var(--hk-primary-700);
}

.hk-smart-data-form__chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  transition: transform 0.15s ease;
  flex-shrink: 0;
}

.hk-smart-data-form__chevron::before {
  content: '';
  display: block;
  width: 0;
  height: 0;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
}

.hk-smart-data-form__section-toggle--expanded .hk-smart-data-form__chevron {
  transform: rotate(90deg);
}

.hk-smart-data-form__section-content {
  margin-left: 6px;
  padding-left: 14px;
  border-left: 1px solid var(--hk-gray-300);
  display: flex;
  flex-direction: column;
}

.hk-smart-data-form__clear {
  background: none;
  border: 1px solid var(--hk-gray-300);
  border-radius: var(--hk-radius-sm);
  cursor: pointer;
  font-size: 11px;
  color: var(--hk-gray-500);
  padding: 1px 5px;
  flex-shrink: 0;
  line-height: 1.2;
  transition: all var(--hk-transition-fast);
}

.hk-smart-data-form__clear:hover {
  color: var(--hk-danger);
  border-color: var(--hk-danger);
}

.hk-smart-data-form__clear--null {
  background: var(--hk-gray-100);
  color: var(--hk-gray-400);
  font-style: italic;
}

/* ── Condition editor toolbar (JS-toggled, bypasses scoped CSS) ── */

.hk-condition-editor__toolbar {
  display: flex;
  align-items: center;
  gap: 1px;
  padding: 4px 8px;
  background: var(--hk-gray-50);
  border-bottom: 1px solid var(--hk-gray-200);
}

.hk-condition-editor__btn {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  border-radius: var(--hk-radius-sm);
  cursor: pointer;
  color: var(--hk-gray-700);
  font-size: 12px;
  line-height: 1;
  padding: 0;
  transition: background var(--hk-transition-fast);
}

.hk-condition-editor__btn:hover {
  background: var(--hk-gray-200);
}

.hk-condition-editor__btn--active {
  background: var(--hk-primary);
  color: #fff;
}

.hk-condition-editor__toolbar-sep {
  width: 1px;
  align-self: stretch;
  background: var(--hk-gray-300);
  margin: 4px 4px;
}

.hk-condition-editor__color {
  position: relative;
  width: 24px;
  height: 24px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--hk-gray-300);
  border-radius: var(--hk-radius-sm);
  background: #fff;
  cursor: pointer;
  padding: 0;
  gap: 1px;
}

.hk-condition-editor__color-icon {
  font-size: 10px;
  line-height: 1;
  color: var(--hk-gray-700);
}

.hk-condition-editor__color-bar {
  width: 12px;
  height: 3px;
  background: var(--hk-primary);
  border-radius: 1px;
}

.hk-condition-editor__color--highlight .hk-condition-editor__color-bar {
  background: #fde68a;
}

.hk-condition-editor__color-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  border: none;
  padding: 0;
}

.hk-condition-editor__select {
  height: 22px;
  padding: 0 6px;
  font-size: 11px;
  font-family: var(--hk-font-family);
  border: 1px solid var(--hk-gray-300);
  border-radius: var(--hk-radius-sm);
  background: #fff;
  color: var(--hk-gray-700);
  cursor: pointer;
}

/* ── Color palette (used in SmartField dialog + BlockSi chip popover) ── */

.hk-smart-field-edit__palette {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

.hk-smart-field-edit__swatch {
  width: 22px;
  height: 22px;
  min-width: 22px;
  min-height: 22px;
  border: 1px solid var(--hk-border);
  border-radius: 3px;
  cursor: pointer;
  padding: 0;
  box-sizing: border-box;
  display: inline-block;
}

.hk-smart-field-edit__swatch:hover {
  transform: scale(1.15);
}

.hk-smart-field-edit__swatch--selected {
  outline: 2px solid var(--hk-primary);
  outline-offset: 1px;
}

.hk-smart-field-edit__color-reset {
  width: 22px;
  height: 22px;
  min-width: 22px;
  min-height: 22px;
  border: 1px solid var(--hk-border);
  border-radius: 3px;
  cursor: pointer;
  padding: 0;
  background: var(--hk-bg);
  color: var(--hk-gray-500);
  font-size: 10px;
  line-height: 1;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.hk-smart-field-edit__custom-color {
  width: 22px;
  height: 22px;
  min-width: 22px;
  min-height: 22px;
  padding: 0;
  border: 1px solid var(--hk-border);
  border-radius: 3px;
  cursor: pointer;
  box-sizing: border-box;
}

/* ── SmartField chips (global — NodeViews bypass scoped CSS) ── */

.smart-field {
  display: inline-block;
  padding: 1px 8px;
  border-radius: var(--hk-radius-sm);
  font-size: inherit;
  font-weight: inherit;
  font-style: inherit;
  font-family: inherit;
  color: inherit;
  cursor: default;
  user-select: none;
  -webkit-user-modify: read-only;
  vertical-align: baseline;
}

.smart-field--selected {
  outline: 2px solid var(--hk-primary);
  outline-offset: 1px;
}

.smart-field--simple {
  background: var(--hk-primary-100);
  border: 1px solid var(--hk-primary-300);
}

.smart-field--object {
  background: var(--hk-warning-100);
  border: 1px solid var(--hk-warning-300);
}

.smart-field--list {
  background: var(--hk-danger-100);
  border: 1px solid var(--hk-danger-300);
}

/* Zero-width clickable "tail" appended inside SmartField / SmartIf NodeViews.
   Provides a mousedown target to place the cursor right after the chip,
   even when the chip is the last element in a paragraph. */
.smart-field-tail {
  display: inline-block;
  width: 6px;
  height: 1em;
  vertical-align: baseline;
  cursor: text;
}

/* Image NodeView — inline wrapper with corner resize handles */
.hk-image-nodeview {
  position: relative;
  display: inline-block;
  line-height: 0;
  max-width: 100%;
}

.hk-image-nodeview > img {
  display: block;
  max-width: 100%;
  height: auto;
}

.hk-image-nodeview.ProseMirror-selectednode > img {
  outline: 2px solid var(--hk-primary-500, #1e6fff);
  outline-offset: 2px;
}

.hk-image-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: var(--hk-primary-500, #1e6fff);
  border: 1px solid #fff;
  border-radius: 2px;
  display: none;
  z-index: 2;
}

.hk-image-nodeview.ProseMirror-selectednode .hk-image-handle {
  display: block;
}

.hk-image-handle--nw { top: -6px; left: -6px; cursor: nwse-resize; }
.hk-image-handle--ne { top: -6px; right: -6px; cursor: nesw-resize; }
.hk-image-handle--se { bottom: -6px; right: -6px; cursor: nwse-resize; }
.hk-image-handle--sw { bottom: -6px; left: -6px; cursor: nesw-resize; }

.hk-image-handle--delete {
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  background: var(--hk-danger-500, #d32f2f);
  color: #fff;
  border-radius: 50%;
  border: 1px solid #fff;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  line-height: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.hk-image-nodeview.ProseMirror-selectednode .hk-image-handle--delete {
  display: flex;
}

.hk-image-handle--delete:hover {
  background: #b71c1c;
}

