/* Text editor — only active with body.is-text-editing */

/* Phase 7A login overlay */
.text-editor-login {
  position: fixed;
  inset: 0;
  z-index: 10050;
  display: grid;
  place-items: center;
  background: rgba(20, 16, 12, 0.45);
  backdrop-filter: blur(2px);
}
.text-editor-login__card {
  width: min(360px, calc(100vw - 32px));
  padding: 22px 20px 18px;
  border-radius: 14px;
  background: var(--text-editor-paper-card, #faf7f2);
  border: 1px solid var(--text-editor-line, rgba(30, 26, 22, 0.14));
  box-shadow: 0 18px 48px rgba(20, 16, 12, 0.18);
  display: grid;
  gap: 12px;
}
.text-editor-login__title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
}
.text-editor-login__hint,
.text-editor-login__error {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-editor-ink-soft, #625f5a);
}
.text-editor-login__error {
  color: var(--text-editor-wine, #9f1738);
}
.text-editor-login__label {
  display: grid;
  gap: 6px;
  font-size: 0.8rem;
}
.text-editor-login__input {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--text-editor-line, rgba(30, 26, 22, 0.2));
  font: inherit;
}
.text-editor-login__submit {
  margin-top: 4px;
  padding: 9px 12px;
  border: 0;
  border-radius: 999px;
  background: var(--text-editor-wine, #9f1738);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

/* Server-mode normal hydration: avoid flashing private local draft */
html.rrf-server-mode.rrf-hydrating body {
  visibility: hidden;
}

/* Conflict resolution panel (Phase 7A correction) */
.text-editor-conflict {
  position: fixed;
  inset: 0;
  z-index: 10060;
  display: grid;
  place-items: center;
  background: rgba(20, 16, 12, 0.5);
  backdrop-filter: blur(2px);
}
.text-editor-conflict__card {
  width: min(440px, calc(100vw - 32px));
  padding: 20px 18px 16px;
  border-radius: 14px;
  background: var(--text-editor-paper-card, #faf7f2);
  border: 1px solid var(--text-editor-line, rgba(30, 26, 22, 0.14));
  box-shadow: 0 18px 48px rgba(20, 16, 12, 0.18);
  display: grid;
  gap: 12px;
}
.text-editor-conflict__title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}
.text-editor-conflict__text {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text-editor-ink-soft, #625f5a);
}
.text-editor-conflict__actions {
  display: grid;
  gap: 8px;
}
.text-editor-bar__status.is-saving {
  color: var(--text-editor-wine-dark, #781127);
}

:root {
  --text-editor-bar-height: 0px;
  --text-editor-wine: #9f1738;
  --text-editor-wine-dark: #781127;
  --text-editor-ink: #171716;
  --text-editor-ink-soft: #625f5a;
  --text-editor-paper: #f5f0e8;
  --text-editor-paper-card: #faf7f2;
  --text-editor-paper-soft: #eee6dc;
  --text-editor-line: rgba(30, 26, 22, 0.14);
  --text-editor-graphite: #141414;
}

body.is-text-editing {
  padding-top: var(--text-editor-bar-height);
}

body.is-text-editing.is-text-editor-preview,
body.is-text-editing.is-text-editor-collapsed {
  /* collapsed uses capsule height via --text-editor-bar-height */
}

body.is-text-editing.is-text-editor-preview {
  padding-top: 0;
}

body.is-text-editing.is-text-editor-preview.is-text-editor-collapsed {
  padding-top: 0;
}

.text-editor-bar__scope {
  flex: 0 0 auto;
  margin: 0 4px 0 0;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(159, 23, 56, 0.08);
  color: var(--text-editor-wine-dark);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.text-editor-capsule {
  position: fixed;
  z-index: 10000;
  top: 10px;
  right: 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  max-width: calc(100vw - 24px);
  padding: 0 14px;
  border: 1px solid var(--text-editor-line);
  border-radius: 999px;
  background: var(--text-editor-paper-card);
  color: var(--text-editor-ink);
  font-family: Onest, "Segoe UI", Arial, sans-serif;
  font-size: 0.82rem;
  font-weight: 700;
  box-shadow: 0 10px 28px rgba(42, 31, 22, 0.12);
  cursor: pointer;
}

.text-editor-capsule[hidden] {
  display: none !important;
}

/* Critical: flex display would otherwise override the hidden attribute */
.text-editor-bar[hidden] {
  display: none !important;
}

::highlight(editor-selection) {
  background-color: rgba(159, 23, 56, 0.28);
  color: inherit;
}

[data-editor-section-id].is-section-selected {
  outline: 2px solid rgba(159, 23, 56, 0.45);
  outline-offset: 4px;
}

[data-editor-section-id].is-editor-section-deleted,
[data-editor-section-id][data-editor-section-deleted],
[data-editor-section-id].is-editor-section-deleted[hidden] {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
  height: 0 !important;
  max-height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
  border: 0 !important;
}

/* Soft hide only inside active edit UI (not preview). */
body.is-text-editing:not(.is-text-editor-preview)
  [data-editor-section-id].is-editor-section-hidden:not(.is-editor-section-deleted) {
  opacity: 0.42;
  outline: 1px dashed rgba(98, 95, 90, 0.55);
  outline-offset: 3px;
}

/* Preview + public page: hidden sections are fully removed from layout. */
body.is-text-editor-preview [data-editor-section-id].is-editor-section-hidden:not(.is-editor-section-deleted),
body:not(.is-text-editing) [data-editor-section-id].is-editor-section-hidden:not(.is-editor-section-deleted) {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
  height: 0 !important;
  max-height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
  border: 0 !important;
  opacity: 0 !important;
}

.text-editor-section-toolbar {
  position: absolute;
  z-index: 9990;
  display: none;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border: 1px solid var(--text-editor-line);
  border-radius: 999px;
  background: var(--text-editor-paper-card);
  box-shadow: 0 8px 22px rgba(42, 31, 22, 0.12);
  font-family: Onest, "Segoe UI", Arial, sans-serif;
  font-size: 12px;
}

.text-editor-section-toolbar.is-open {
  display: inline-flex;
}

.text-editor-section-toolbar__badge {
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(159, 23, 56, 0.1);
  color: var(--text-editor-wine-dark);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.text-editor-section-toolbar__label {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-editor-ink-soft);
  font-weight: 600;
}

.text-editor-section-toolbar__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-editor-ink);
  cursor: pointer;
}

.text-editor-section-toolbar__btn:hover:not(:disabled) {
  background: rgba(159, 23, 56, 0.08);
}

.text-editor-section-toolbar__btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.text-editor-section-toolbar__btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.text-editor-structure {
  position: fixed;
  z-index: 10020;
  top: 72px;
  right: 16px;
  width: min(320px, calc(100vw - 24px));
  max-height: min(70vh, 520px);
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--text-editor-line);
  border-radius: 14px;
  background: var(--text-editor-paper-card);
  box-shadow: 0 16px 40px rgba(42, 31, 22, 0.16);
  font-family: Onest, "Segoe UI", Arial, sans-serif;
}

.text-editor-structure[hidden] {
  display: none !important;
}

.text-editor-structure__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.text-editor-structure__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(30, 26, 22, 0.08);
}

.text-editor-structure__name {
  border: 0;
  background: transparent;
  color: var(--text-editor-ink);
  font: inherit;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.text-editor-structure__state {
  color: var(--text-editor-ink-soft);
  font-size: 0.75rem;
}

.text-editor-structure__row.is-deleted .text-editor-structure__name {
  color: var(--text-editor-wine-dark);
  text-decoration: line-through;
}

.text-editor-capsule:hover {
  border-color: rgba(159, 23, 56, 0.35);
}

.text-editor-capsule:focus-visible {
  outline: 3px solid rgba(159, 23, 56, 0.45);
  outline-offset: 2px;
}

.text-editor-capsule__dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #2f6b3a;
}

.text-editor-capsule__dot.is-dirty {
  background: var(--text-editor-wine);
}

.text-editor-capsule__dot.is-saved {
  background: #2f6b3a;
}

@media (prefers-reduced-motion: no-preference) {
  .text-editor-bar,
  .text-editor-capsule {
    transition: opacity 0.18s ease, transform 0.18s ease;
  }
}

/* —— Top bar —— */

.text-editor-bar {
  position: fixed;
  z-index: 10000;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 100%;
  padding: 8px 12px 10px;
  border-bottom: 1px solid var(--text-editor-line);
  background: var(--text-editor-paper-card);
  color: var(--text-editor-ink);
  font-family: Onest, "Segoe UI", Arial, sans-serif;
  font-size: 13px;
  line-height: 1.3;
  box-shadow: 0 8px 28px rgba(42, 31, 22, 0.08);
}

body.is-text-editor-preview .text-editor-bar {
  display: none;
}

.text-editor-bar__row {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

/* P1-03: primary as grid so right zone cannot overlay center hitboxes */
.text-editor-bar__row--primary {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

/* 6-6B.1 P1-04: wrap secondary format controls instead of hiding them in a long scroll strip */
.text-editor-bar__row--secondary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  row-gap: 6px;
  min-width: 0;
  overflow-x: visible;
  overflow-y: visible;
  scrollbar-width: thin;
}

.text-editor-bar__row--secondary::-webkit-scrollbar {
  height: 4px;
}

.text-editor-bar__row--secondary::-webkit-scrollbar-thumb {
  border-radius: 4px;
  background: rgba(30, 26, 22, 0.2);
}

/* Primary toolbar zones (phase-6-5) */
.text-editor-bar__zone {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.text-editor-bar__zone--left {
  flex: 0 1 auto;
  max-width: none;
}

.text-editor-bar__zone--center,
.text-editor-bar__zone--primary-center {
  flex: 1 1 auto;
  min-width: 0;
  border-left: 1px solid var(--text-editor-line);
  border-right: 1px solid var(--text-editor-line);
  padding-inline: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  /* No stacking above siblings — scroll stays in this cell only */
  position: relative;
  z-index: 0;
}

.text-editor-bar__zone--center .text-editor-bar__group:first-child,
.text-editor-bar__zone--primary-center .text-editor-bar__group:first-child {
  border-left: 0;
  padding-left: 0;
}

.text-editor-bar__zone--right {
  flex: 0 0 auto;
  flex-shrink: 0;
  /* sticky overlay caused hit-test failures on ≤1024 — stay in grid cell */
  position: relative;
  z-index: 1;
  margin-left: 0;
  padding-left: 6px;
  background: var(--text-editor-paper-card);
}

@media (min-width: 1280px) {
  .text-editor-bar__row--secondary {
    overflow-x: visible;
    flex-wrap: nowrap;
  }

  .text-editor-bar__zone--primary-center {
    overflow-x: visible;
  }

  .text-editor-bar__row--secondary .text-editor-bar__group {
    flex: 0 0 auto;
  }
}

/* ≤1279: two-row primary — left+right on top, center full width below.
   Prevents right-zone status/buttons from covering LH/Tracking/Align hitboxes. */
@media (max-width: 1279px) {
  .text-editor-bar__row--primary {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "left right"
      "center center";
    align-items: center;
    gap: 6px 8px;
  }

  .text-editor-bar__zone--left {
    grid-area: left;
    max-width: none;
  }

  .text-editor-bar__zone--right {
    grid-area: right;
    position: relative;
    z-index: 1;
  }

  .text-editor-bar__zone--center,
  .text-editor-bar__zone--primary-center {
    grid-area: center;
    border-left: 0;
    border-right: 0;
    border-top: 1px solid var(--text-editor-line);
    padding-inline: 0;
    padding-top: 6px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    z-index: 0;
  }

  .text-editor-bar__status {
    max-width: 5.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.text-editor-bar__brand {
  flex: 0 0 auto;
  margin: 0;
  padding-right: 4px;
  color: var(--text-editor-ink-soft);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
}

.text-editor-bar__selection {
  flex: 0 1 auto;
  min-width: 7rem;
  max-width: 16rem;
  margin: 0;
  overflow: hidden;
  color: var(--text-editor-ink);
  font-size: 0.8rem;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.text-editor-bar__selection.is-empty {
  color: var(--text-editor-ink-soft);
  font-weight: 500;
}

.text-editor-bar__group {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 4px;
  padding-inline: 6px;
  border-left: 1px solid var(--text-editor-line);
}

.text-editor-bar__row > .text-editor-bar__group:first-of-type {
  border-left: 0;
  padding-left: 0;
}

.text-editor-bar__spacer {
  flex: 1 1 auto;
  min-width: 8px;
}

.text-editor-bar button,
.text-editor-bar select,
.text-editor-bar input[type="text"],
.text-editor-bar input[type="number"],
.text-editor-bar input[type="color"] {
  font: inherit;
  color: inherit;
}

/* Phase 7B-2.3 — shared editor action + icon system (desktop compact / mobile tiles) */
.te-icon {
  display: block;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  pointer-events: none;
}

.te-action {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.te-action__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}

.te-action__label {
  display: inline;
  font-size: inherit;
  font-weight: inherit;
  line-height: 1.1;
  white-space: nowrap;
}

.te-action-group {
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 4px;
}

.te-format-tile__icon,
.te-format-tile__caption {
  display: none;
}

.text-editor-bar__btn {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--text-editor-line);
  border-radius: 10px;
  background: var(--text-editor-paper);
  color: var(--text-editor-ink);
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.text-editor-bar__btn:focus-visible {
  outline: 2px solid rgba(159, 23, 56, 0.5);
  outline-offset: 2px;
}

/* Desktop: icon-first compact utility (labels on save/publish/preview/more stay) */
.text-editor-bar:not(.is-mobile-chrome) .te-action--icon .te-action__label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.text-editor-bar:not(.is-mobile-chrome) .te-action--icon {
  width: 34px;
  min-width: 34px;
  min-height: 34px;
  padding: 0;
}

/* Save: light shell + dark floppy (never white icon on light paper). */
.text-editor-bar:not(.is-mobile-chrome) [data-editor-save],
.text-editor-bar:not(.is-mobile-chrome) .te-action--save {
  background: #fff;
  border-color: var(--text-editor-line);
  color: #1c1c1a;
}

.text-editor-bar:not(.is-mobile-chrome) [data-editor-save] .te-action__icon,
.text-editor-bar:not(.is-mobile-chrome) [data-editor-save] .te-icon,
.text-editor-bar:not(.is-mobile-chrome) .te-action--save .te-icon {
  color: #1c1c1a;
}

/* Publish label must read fully on desktop */
.text-editor-bar:not(.is-mobile-chrome) [data-editor-publish],
.text-editor-bar:not(.is-mobile-chrome) .te-action--publish {
  min-width: 8.5rem;
  padding-inline: 12px;
}

.text-editor-bar:not(.is-mobile-chrome) [data-editor-publish] .te-action__label {
  overflow: visible;
  text-overflow: clip;
  max-width: none;
}

/* Desktop «Авто» size control — full word, no clipping */
.text-editor-bar:not(.is-mobile-chrome) [data-editor-size-auto],
.text-editor-bar:not(.is-mobile-chrome) .text-editor-bar__size-auto {
  min-width: 3.25rem;
  padding-inline: 10px;
  overflow: visible;
  text-overflow: clip;
  white-space: nowrap;
  flex: 0 0 auto;
}

.text-editor-bar:not(.is-mobile-chrome) .text-editor-bar__size-combo .text-editor-bar__input--px {
  width: 4.5rem;
  min-width: 4.5rem;
}

.text-editor-bar:not(.is-mobile-chrome) .te-action-group--utility .te-action {
  min-height: 34px;
}

/* Phase 7A: [hidden] must win over display:inline-flex on toolbar buttons */
.text-editor-bar__btn[hidden],
.text-editor-bar [hidden] {
  display: none !important;
}

.text-editor-bar__btn:hover:not(:disabled) {
  border-color: rgba(159, 23, 56, 0.35);
  background: #fff;
}

.text-editor-bar__btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.text-editor-bar__btn.is-active {
  border-color: rgba(159, 23, 56, 0.45);
  background: rgba(159, 23, 56, 0.08);
  color: var(--text-editor-wine-dark);
}

.text-editor-bar__btn--icon {
  width: 32px;
  min-width: 32px;
  padding: 0;
  font-size: 0.9rem;
  font-weight: 700;
}

/* 6-6B.3 UX-01: striped align icons (inline SVG) */
.text-editor-align-icon {
  display: block;
  width: 16px;
  height: 16px;
  margin: 0 auto;
  pointer-events: none;
  flex-shrink: 0;
}

.text-editor-bar__btn--icon[data-editor-align] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Higher specificity than `.text-editor-bar button { color: inherit }` */
.text-editor-bar .text-editor-bar__btn--primary,
.text-editor-bar .text-editor-bar__btn--primary:hover:not(:disabled),
.text-editor-bar .text-editor-bar__btn--primary:focus-visible,
.text-editor-bar .text-editor-bar__btn--primary:active {
  border-color: var(--text-editor-wine);
  background: var(--text-editor-wine);
  color: #fff;
}

.text-editor-bar .text-editor-bar__btn--primary:hover:not(:disabled),
.text-editor-bar .text-editor-bar__btn--primary:active {
  border-color: var(--text-editor-wine-dark);
  background: var(--text-editor-wine-dark);
  color: #fff;
}

.text-editor-bar .text-editor-bar__btn--primary:focus-visible {
  outline: 3px solid rgba(159, 23, 56, 0.45);
  outline-offset: 2px;
  color: #fff;
}

.text-editor-bar .text-editor-bar__btn--primary svg {
  color: #fff;
  fill: none;
  stroke: currentColor;
}

.text-editor-bar__btn--ghost {
  border-color: transparent;
  background: transparent;
}

.text-editor-bar__label {
  flex: 0 0 auto;
  color: var(--text-editor-ink-soft);
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}

.text-editor-bar__select,
.text-editor-bar__input {
  min-height: 32px;
  padding: 0 8px;
  border: 1px solid var(--text-editor-line);
  border-radius: 8px;
  background: #fff;
  font-size: 0.78rem;
}

.text-editor-bar__select {
  max-width: 11rem;
}

.text-editor-bar__input--px {
  width: 4.2rem;
  text-align: center;
}

/* Font-size combobox (no datalist) */
.text-editor-bar__group--size {
  gap: 4px;
}

.text-editor-bar__size-combo {
  display: inline-flex;
  align-items: stretch;
  flex: 0 0 auto;
  border: 1px solid var(--text-editor-line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.text-editor-bar__size-combo .text-editor-bar__input--px {
  width: 3.6rem;
  border: 0;
  border-radius: 0;
  min-height: 30px;
}

.text-editor-bar__size-combo .text-editor-bar__size-toggle {
  width: 28px;
  min-width: 28px;
  min-height: 30px;
  border: 0;
  border-left: 1px solid var(--text-editor-line);
  border-radius: 0;
  background: var(--text-editor-paper);
  font-size: 0.7rem;
  line-height: 1;
}

.text-editor-bar__size-combo .text-editor-bar__size-toggle:hover:not(:disabled) {
  background: #fff;
}

.text-editor-size-listbox {
  position: fixed;
  z-index: 10005;
  top: 0;
  left: 0;
  display: none;
  flex-direction: column;
  gap: 0;
  max-height: min(50vh, 320px);
  overflow: auto;
  padding: 4px;
  border: 1px solid var(--text-editor-line);
  border-radius: 10px;
  background: var(--text-editor-paper-card);
  box-shadow: 0 14px 40px rgba(42, 31, 22, 0.14);
  font-family: Onest, "Segoe UI", Arial, sans-serif;
  scrollbar-width: thin;
}

.text-editor-size-listbox.is-open,
.text-editor-size-listbox:not([hidden]) {
  display: flex;
}

.text-editor-size-listbox[hidden] {
  display: none !important;
}

.text-editor-size-listbox__option {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  padding: 4px 8px;
  border-radius: 6px;
  color: var(--text-editor-ink);
  font-size: 0.8rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  user-select: none;
}

.text-editor-size-listbox__option:hover,
.text-editor-size-listbox__option.is-active {
  background: var(--text-editor-paper-soft);
}

.text-editor-size-listbox__option.is-selected {
  color: var(--text-editor-wine-dark);
}

.text-editor-size-listbox__check {
  display: inline-flex;
  flex: 0 0 12px;
  width: 12px;
  height: 12px;
  align-items: center;
  justify-content: center;
  color: var(--text-editor-wine);
  font-size: 0.75rem;
  line-height: 1;
}

.text-editor-size-listbox__option.is-selected .text-editor-size-listbox__check::before {
  content: "✓";
}

.text-editor-size-listbox__label {
  flex: 1 1 auto;
}

.text-editor-bar__input--hex {
  width: 5.6rem;
  font-variant-numeric: tabular-nums;
  text-transform: uppercase;
}

.text-editor-bar__input--num {
  width: 3.6rem;
  text-align: center;
}

.text-editor-bar__color {
  width: 32px;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--text-editor-line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

.text-editor-bar__swatches {
  display: flex;
  flex: 0 0 auto;
  gap: 4px;
}

.text-editor-bar__swatch {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid rgba(30, 26, 22, 0.2);
  border-radius: 999px;
  cursor: pointer;
}

.text-editor-bar__swatch:hover {
  outline: 2px solid var(--text-editor-wine);
  outline-offset: 1px;
}

.text-editor-bar__status {
  flex: 0 0 auto;
  min-width: 8.5rem;
  margin: 0;
  color: var(--text-editor-ink-soft);
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}

.text-editor-bar__status.is-saved {
  color: #2f6b3a;
}

.text-editor-bar__status.is-dirty {
  color: var(--text-editor-wine-dark);
}

/* —— More menu —— */

.text-editor-bar__menu {
  position: relative;
  flex: 0 0 auto;
}

.text-editor-bar__menu-panel,
.text-editor-bar__menu-panel--portal {
  z-index: 10001;
  min-width: 15rem;
  max-height: min(70vh, 420px);
  overflow: auto;
  padding: 6px;
  border: 1px solid var(--text-editor-line);
  border-radius: 12px;
  background: var(--text-editor-paper-card);
  box-shadow: 0 14px 40px rgba(42, 31, 22, 0.12);
}

.text-editor-bar__menu-panel--portal {
  position: fixed;
  top: 0;
  left: 0;
  display: none;
  flex-direction: column;
  gap: 2px;
}

.text-editor-bar__menu-panel--portal.is-open {
  display: flex;
}

.text-editor-bar__menu-item {
  display: block;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-editor-ink);
  font-size: 0.8rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.text-editor-bar__menu-item:hover {
  background: var(--text-editor-paper-soft);
}

.text-editor-bar__menu-item--danger {
  color: var(--text-editor-wine-dark);
}

.text-editor-bar__menu-sep {
  height: 1px;
  margin: 4px 6px;
  background: var(--text-editor-line);
}

.text-editor-bar__file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* —— Preview return chip —— */

.text-editor-preview-chip {
  position: fixed;
  z-index: 10000;
  top: 12px;
  right: 12px;
  display: none;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--text-editor-line);
  border-radius: 999px;
  background: var(--text-editor-paper-card);
  color: var(--text-editor-ink);
  font-family: Onest, "Segoe UI", Arial, sans-serif;
  font-size: 0.82rem;
  font-weight: 700;
  box-shadow: 0 10px 30px rgba(42, 31, 22, 0.12);
  cursor: pointer;
}

body.is-text-editing.is-text-editor-preview .text-editor-preview-chip {
  display: inline-flex;
}

.text-editor-preview-chip:hover {
  border-color: rgba(159, 23, 56, 0.4);
}

/* —— Editable text highlights —— */

body.is-text-editing:not(.is-text-editor-preview) [data-edit-id] {
  cursor: text;
  outline: 1px dashed transparent;
  outline-offset: 3px;
  transition: outline-color 0.12s ease;
  border-radius: 2px;
}

body.is-text-editing:not(.is-text-editor-preview) [data-edit-id]:hover {
  outline-color: rgba(159, 23, 56, 0.55);
}

body.is-text-editing:not(.is-text-editor-preview) [data-edit-id].is-edit-selected {
  outline: 2px solid var(--text-editor-wine);
  outline-offset: 3px;
}

body.is-text-editing:not(.is-text-editor-preview) [data-edit-id][contenteditable="true"] {
  caret-color: var(--text-editor-wine);
}

body.is-text-editing:not(.is-text-editor-preview) a[data-edit-id],
body.is-text-editing:not(.is-text-editor-preview) a:has(> [data-edit-id]),
body.is-text-editing:not(.is-text-editor-preview) button:has(> [data-edit-id]),
body.is-text-editing:not(.is-text-editor-preview) .faq-question:has(> [data-edit-id]) {
  cursor: text;
}

/* —— Block structure chrome (edit mode only) —— */

body.is-text-editing:not(.is-text-editor-preview) [data-editor-block-id] {
  position: relative;
  outline: 1px dashed transparent;
  outline-offset: 4px;
  transition: outline-color 0.12s ease, opacity 0.15s ease;
}

body.is-text-editing:not(.is-text-editor-preview) [data-editor-block-id]:hover {
  outline-color: rgba(159, 23, 56, 0.35);
}

body.is-text-editing:not(.is-text-editor-preview) [data-editor-block-id].is-block-selected {
  outline: 2px solid var(--text-editor-wine);
  outline-offset: 4px;
}

body.is-text-editing:not(.is-text-editor-preview) [data-editor-block-id].is-editor-block-hidden {
  opacity: 0.48;
}

body.is-text-editing:not(.is-text-editor-preview) [data-editor-block-id].is-editor-block-hidden::after {
  position: absolute;
  z-index: 2;
  top: 8px;
  right: 8px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--text-editor-graphite);
  color: #fff;
  content: "Скрыт";
  font-family: Onest, "Segoe UI", Arial, sans-serif;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  pointer-events: none;
}

/* Hidden blocks leave layout in normal/preview */
body:not(.is-text-editing) [data-editor-block-id][data-editor-hidden="true"],
body.is-text-editor-preview [data-editor-block-id][data-editor-hidden="true"] {
  display: none !important;
}

/* Block floating toolbar portal */
.text-editor-block-toolbar {
  position: fixed;
  z-index: 10002;
  display: none;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--text-editor-line);
  border-radius: 12px;
  background: var(--text-editor-paper-card);
  box-shadow: 0 12px 36px rgba(42, 31, 22, 0.14);
  font-family: Onest, "Segoe UI", Arial, sans-serif;
}

.text-editor-block-toolbar.is-open {
  display: flex;
}

body.is-text-editor-preview .text-editor-block-toolbar,
body:not(.is-text-editing) .text-editor-block-toolbar {
  display: none !important;
}

.text-editor-block-toolbar__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-editor-ink);
  cursor: pointer;
}

.text-editor-block-toolbar__btn:hover:not(:disabled) {
  border-color: var(--text-editor-line);
  background: var(--text-editor-paper-soft);
}

.text-editor-block-toolbar__btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.text-editor-block-toolbar__btn.is-active {
  border-color: rgba(159, 23, 56, 0.4);
  background: rgba(159, 23, 56, 0.08);
  color: var(--text-editor-wine-dark);
}

.text-editor-block-toolbar__btn:focus-visible {
  outline: 3px solid rgba(159, 23, 56, 0.45);
  outline-offset: 1px;
}

.text-editor-block-toolbar__btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.text-editor-block-toolbar__handle {
  cursor: grab;
}

.text-editor-block-toolbar__handle:active {
  cursor: grabbing;
}

.text-editor-block-toolbar__menu {
  position: relative;
}

.text-editor-block-toolbar__menu-panel {
  position: absolute;
  z-index: 2;
  top: calc(100% + 4px);
  right: 0;
  display: none;
  min-width: 12rem;
  padding: 4px;
  border: 1px solid var(--text-editor-line);
  border-radius: 10px;
  background: var(--text-editor-paper-card);
  box-shadow: 0 10px 28px rgba(42, 31, 22, 0.12);
}

.text-editor-block-toolbar__menu.is-open .text-editor-block-toolbar__menu-panel {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.text-editor-block-toolbar__menu-item {
  display: block;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-editor-ink);
  font-size: 0.78rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.text-editor-block-toolbar__menu-item:hover {
  background: var(--text-editor-paper-soft);
}

/* Drag chrome */
.text-editor-block-ghost {
  position: fixed;
  z-index: 10003;
  left: 0;
  top: 0;
  pointer-events: none;
  opacity: 0.55;
  box-shadow: 0 16px 40px rgba(42, 31, 22, 0.18);
  will-change: transform;
  box-sizing: border-box;
  overflow: hidden;
}

/* Legacy placeholder kept for compatibility; phase-6-2 uses body overlay indicator */
.text-editor-block-placeholder {
  box-sizing: border-box;
  min-height: 48px;
  margin: 8px 0;
  border: 2px dashed var(--text-editor-wine);
  border-radius: 12px;
  background: rgba(159, 23, 56, 0.06);
  pointer-events: none;
}

.text-editor-block-drop-indicator {
  position: fixed;
  z-index: 10003;
  pointer-events: none;
  border-radius: 2px;
  background: var(--text-editor-wine);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.65);
  opacity: 0.95;
}

.text-editor-block-drop-indicator.is-stack {
  height: 3px;
}

.text-editor-block-drop-indicator.is-grid {
  width: 3px;
}

body.is-block-dragging {
  cursor: grabbing;
  user-select: none;
}

body.is-block-dragging [data-editor-block-id].is-block-dragging-source {
  opacity: 0.25;
}

/* Toast */
.text-editor-toast {
  position: fixed;
  z-index: 10004;
  right: 16px;
  bottom: 16px;
  display: none;
  align-items: center;
  gap: 12px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 14px;
  border: 1px solid var(--text-editor-line);
  border-radius: 12px;
  background: var(--text-editor-paper-card);
  color: var(--text-editor-ink);
  font-family: Onest, "Segoe UI", Arial, sans-serif;
  font-size: 0.86rem;
  font-weight: 600;
  box-shadow: 0 14px 40px rgba(42, 31, 22, 0.16);
}

.text-editor-toast.is-open {
  display: flex;
}

.text-editor-toast__action {
  flex: 0 0 auto;
  padding: 6px 10px;
  border: 1px solid var(--text-editor-wine);
  border-radius: 8px;
  background: transparent;
  color: var(--text-editor-wine-dark);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

/* Narrow legacy fallback (non-mobile-chrome) */
@media (max-width: 900px) {
  .text-editor-bar:not(.is-mobile-chrome) {
    padding: 8px 10px 9px;
    gap: 6px;
  }

  .text-editor-bar:not(.is-mobile-chrome) .text-editor-bar__row--primary {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }

  .text-editor-bar:not(.is-mobile-chrome) .text-editor-bar__zone--left,
  .text-editor-bar:not(.is-mobile-chrome) .text-editor-bar__zone--center,
  .text-editor-bar:not(.is-mobile-chrome) .text-editor-bar__zone--primary-center,
  .text-editor-bar:not(.is-mobile-chrome) .text-editor-bar__zone--right {
    width: 100%;
    max-width: 100%;
    border-left: 0;
    border-right: 0;
    padding-inline: 0;
    position: relative;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .text-editor-bar:not(.is-mobile-chrome) .text-editor-bar__zone--right .text-editor-bar__status {
    display: none;
  }
}

/* Phase 7B-2.3 — mobile two equal rows of labeled SVG tiles
   reference: a_clean_mobile_app_editor_ui_screenshot_portrait_1.png */
@media (max-width: 900px) {
  .text-editor-bar.is-mobile-chrome {
    padding: 8px 10px 10px;
    gap: 8px;
    box-sizing: border-box;
    background: #f7f4ef;
    border-bottom: 1px solid rgba(23, 23, 22, 0.08);
  }

  .text-editor-bar.is-mobile-chrome .text-editor-bar__brand,
  .text-editor-bar.is-mobile-chrome .text-editor-bar__selection,
  .text-editor-bar.is-mobile-chrome .text-editor-bar__scope,
  .text-editor-bar.is-mobile-chrome .text-editor-bar__status,
  .text-editor-bar.is-mobile-chrome .text-editor-bar__label {
    display: none !important;
  }

  .text-editor-bar.is-mobile-chrome .text-editor-bar__zone--center,
  .text-editor-bar.is-mobile-chrome .text-editor-bar__zone--primary-center {
    display: none !important;
  }

  .text-editor-bar.is-mobile-chrome .text-editor-bar__row--primary,
  .text-editor-bar.is-mobile-chrome .text-editor-bar__row--secondary {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: stretch;
    gap: 8px;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
    min-height: 0;
    padding-bottom: 2px;
    scrollbar-width: thin;
  }

  .text-editor-bar.is-mobile-chrome .text-editor-bar__zone--left,
  .text-editor-bar.is-mobile-chrome .text-editor-bar__zone--right {
    display: contents;
  }

  .text-editor-bar.is-mobile-chrome .te-action-group,
  .text-editor-bar.is-mobile-chrome .te-action-group--utility,
  .text-editor-bar.is-mobile-chrome .text-editor-bar__menu {
    display: contents;
  }

  /* Phase 7B-2.3.1: readable equal tiles 72×64, captions ≥11px, no ellipsis on primary labels */
  .text-editor-bar.is-mobile-chrome .te-action,
  .text-editor-bar.is-mobile-chrome .te-format-tile {
    box-sizing: border-box;
    display: inline-flex !important;
    flex-direction: column !important;
    align-items: center;
    justify-content: center;
    gap: 5px;
    flex: 0 0 auto;
    width: 72px;
    min-width: 72px;
    max-width: 72px;
    height: 64px;
    min-height: 64px;
    max-height: 64px;
    padding: 5px 1px 4px !important;
    margin: 0;
    border: 1px solid rgba(23, 23, 22, 0.12) !important;
    border-radius: 12px !important;
    background: #fff !important;
    color: #1c1c1a !important;
    box-shadow: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    position: relative;
  }

  .text-editor-bar.is-mobile-chrome .te-action__icon {
    width: 24px;
    height: 24px;
  }

  .text-editor-bar.is-mobile-chrome .te-icon {
    width: 22px;
    height: 22px;
  }

  .text-editor-bar.is-mobile-chrome .te-action__label {
    display: block !important;
    position: static !important;
    width: auto !important;
    max-width: 70px !important;
    height: auto !important;
    margin: 0 !important;
    clip: auto !important;
    overflow: visible !important;
    font-size: 11px !important;
    font-weight: 600 !important;
    line-height: 1.15 !important;
    letter-spacing: -0.02em;
    color: inherit;
    white-space: nowrap;
    text-overflow: clip;
    text-align: center;
  }

  /* One alignment control on mobile; three direct buttons remain on desktop */
  .text-editor-bar.is-mobile-chrome .te-align-desktop {
    display: none !important;
  }

  /* Save: light tile + dark floppy disk (readable, not white-on-light). */
  .text-editor-bar.is-mobile-chrome .te-action--save,
  .text-editor-bar.is-mobile-chrome [data-editor-save] {
    background: #fff !important;
    border-color: rgba(23, 23, 22, 0.12) !important;
    color: #1c1c1a !important;
  }

  .text-editor-bar.is-mobile-chrome .te-action--save .te-icon,
  .text-editor-bar.is-mobile-chrome [data-editor-save] .te-icon {
    color: #1c1c1a !important;
  }

  /* Publish: full «Опубликовать» — allow wider tile than 72px equal grid */
  .text-editor-bar.is-mobile-chrome [data-editor-publish],
  .text-editor-bar.is-mobile-chrome .te-action--publish {
    width: auto !important;
    min-width: 88px !important;
    max-width: none !important;
    padding-inline: 6px !important;
  }

  .text-editor-bar.is-mobile-chrome [data-editor-publish] .te-action__label {
    max-width: none !important;
    overflow: visible !important;
    text-overflow: clip !important;
    white-space: nowrap !important;
  }

  .text-editor-bar.is-mobile-chrome .te-action.is-active {
    border-color: rgba(159, 23, 56, 0.45) !important;
    background: rgba(159, 23, 56, 0.08) !important;
    color: var(--text-editor-wine-dark, #7a122c) !important;
  }

  .text-editor-bar.is-mobile-chrome .te-action:focus-visible {
    outline: 2px solid rgba(159, 23, 56, 0.5);
    outline-offset: 2px;
  }

  .text-editor-bar.is-mobile-chrome .te-format-tile {
    gap: 0;
  }

  /* Phase 7B-2.4: real tile button (not native overlay). Icon+caption always visible. */
  .text-editor-bar.is-mobile-chrome .te-format-tile__hit {
    box-sizing: border-box;
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 5px 1px 4px;
    border: 0 !important;
    border-radius: inherit;
    background: transparent !important;
    color: #1c1c1a !important;
    cursor: pointer;
    z-index: 3;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  .text-editor-bar.is-mobile-chrome .te-format-tile__icon {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    pointer-events: none;
    position: relative;
    z-index: 1;
  }

  .text-editor-bar.is-mobile-chrome .te-format-tile__caption {
    display: block !important;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.15;
    letter-spacing: -0.02em;
    color: #1c1c1a;
    pointer-events: none;
    white-space: nowrap;
    overflow: visible;
    text-overflow: clip;
    max-width: 70px;
    position: relative;
    z-index: 1;
  }

  /* Hide desktop-only form chrome on mobile — ban transparent full-tile native overlays. */
  .text-editor-bar.is-mobile-chrome .te-format-tile .text-editor-bar__label,
  .text-editor-bar.is-mobile-chrome .te-format-tile .text-editor-bar__swatches,
  .text-editor-bar.is-mobile-chrome .te-format-tile .text-editor-bar__input--hex,
  .text-editor-bar.is-mobile-chrome .te-format-tile .text-editor-bar__size-toggle,
  .text-editor-bar.is-mobile-chrome .te-format-tile [data-editor-size-auto],
  .text-editor-bar.is-mobile-chrome .te-format-tile .text-editor-bar__select,
  .text-editor-bar.is-mobile-chrome .te-format-tile .text-editor-bar__input--px,
  .text-editor-bar.is-mobile-chrome .te-format-tile .text-editor-bar__input--num,
  .text-editor-bar.is-mobile-chrome .te-format-tile .text-editor-bar__color,
  .text-editor-bar.is-mobile-chrome .te-format-tile .text-editor-bar__size-combo {
    display: none !important;
    pointer-events: none !important;
    opacity: 0 !important;
    position: static !important;
    width: 0 !important;
    height: 0 !important;
    min-width: 0 !important;
    min-height: 0 !important;
    overflow: hidden !important;
  }

  .text-editor-bar.is-mobile-chrome .text-editor-bar__group {
    border-left: 0;
    padding-inline: 0;
    gap: 8px;
  }

  .text-editor-bar.is-mobile-chrome .text-editor-bar__row--secondary .text-editor-bar__group {
    flex: 0 0 auto;
  }

  /* Must win over .te-action { display:inline-flex !important } */
  .text-editor-bar.is-mobile-chrome .te-action.te-action--desktop-only,
  .text-editor-bar.is-mobile-chrome button.te-action--desktop-only {
    display: none !important;
  }
}

/* Desktop keeps three align buttons; mobile single control is in te-align-mobile */
.text-editor-bar:not(.is-mobile-chrome) .te-align-mobile {
  display: none !important;
}

/* Desktop: hide mobile tile hit buttons (icon+caption only on mobile) */
.text-editor-bar:not(.is-mobile-chrome) .te-format-tile__hit {
  display: none !important;
}

/* Phase 7B-2.4 mobile sheets (editor-owned, Tilda-inspired UX, HEX only, no alpha) */
.text-editor-color-sheet,
.text-editor-size-sheet,
.text-editor-font-sheet,
.text-editor-interval-sheet {
  position: fixed;
  inset: 0;
  z-index: 10060;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.text-editor-color-sheet[hidden],
.text-editor-size-sheet[hidden],
.text-editor-font-sheet[hidden],
.text-editor-interval-sheet[hidden] {
  display: none !important;
}

.text-editor-color-sheet__backdrop,
.text-editor-size-sheet__backdrop,
.text-editor-font-sheet__backdrop,
.text-editor-interval-sheet__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(23, 23, 22, 0.35);
}

.text-editor-color-sheet__panel,
.text-editor-size-sheet__panel,
.text-editor-font-sheet__panel,
.text-editor-interval-sheet__panel {
  position: relative;
  z-index: 1;
  width: min(100%, 420px);
  max-height: min(88vh, 720px);
  max-height: min(88dvh, 720px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 14px calc(18px + env(safe-area-inset-bottom, 0px));
  border-radius: 16px 16px 0 0;
  background: #fff;
  box-shadow: 0 -8px 32px rgba(23, 23, 22, 0.16);
  font-family: Onest, "Segoe UI", Arial, sans-serif;
  color: #1c1c1a;
}

.text-editor-color-sheet__head,
.text-editor-size-sheet__head,
.text-editor-font-sheet__head,
.text-editor-interval-sheet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  font-weight: 700;
  font-size: 1rem;
}

.text-editor-color-sheet__close,
.text-editor-size-sheet__close,
.text-editor-font-sheet__head button,
.text-editor-interval-sheet__head button {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  color: #1c1c1a;
  flex: 0 0 auto;
}

.text-editor-color-sheet__sv {
  position: relative;
  width: 100%;
  height: 180px;
  border-radius: 12px;
  overflow: hidden;
  touch-action: none;
  margin-bottom: 12px;
  border: 1px solid rgba(23, 23, 22, 0.08);
}

.text-editor-color-sheet__sv canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.text-editor-color-sheet__sv-knob {
  position: absolute;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.text-editor-color-sheet__hue-wrap {
  display: block;
  margin-bottom: 12px;
}

.text-editor-color-sheet__hue {
  width: 100%;
  min-height: 28px;
  height: 28px;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  border-radius: 999px;
  background: linear-gradient(
    90deg,
    #f00 0%,
    #ff0 17%,
    #0f0 33%,
    #0ff 50%,
    #00f 67%,
    #f0f 83%,
    #f00 100%
  );
  outline: none;
}

.text-editor-color-sheet__hue::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid rgba(23, 23, 22, 0.35);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  cursor: pointer;
}

.text-editor-color-sheet__hue::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid rgba(23, 23, 22, 0.35);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  cursor: pointer;
}

.text-editor-color-sheet__hex-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.text-editor-color-sheet__hex-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: #625f5a;
}

.text-editor-color-sheet__hex {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid rgba(23, 23, 22, 0.14);
  border-radius: 10px;
  font: inherit;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.text-editor-color-sheet__hex.is-invalid,
.text-editor-size-sheet__custom-input.is-invalid {
  border-color: #b42318;
  box-shadow: 0 0 0 2px rgba(180, 35, 24, 0.12);
}

.text-editor-color-sheet__hex-error,
.text-editor-size-sheet__error {
  flex: 1 0 100%;
  margin: 4px 0 0;
  font-size: 0.75rem;
  font-weight: 600;
  color: #b42318;
}

.text-editor-color-sheet__chosen {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(23, 23, 22, 0.04);
}

.text-editor-color-sheet__chosen-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: #625f5a;
  flex: 1 1 auto;
}

.text-editor-color-sheet__preview {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid rgba(23, 23, 22, 0.14);
  flex: 0 0 auto;
  background-image:
    linear-gradient(45deg, #ddd 25%, transparent 25%),
    linear-gradient(-45deg, #ddd 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #ddd 75%),
    linear-gradient(-45deg, transparent 75%, #ddd 75%);
  background-size: 10px 10px;
  background-position: 0 0, 0 5px, 5px -5px, -5px 0;
}

.text-editor-color-sheet__chosen-hex {
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
  min-width: 5.5em;
  text-align: right;
}

.text-editor-color-sheet__section-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: #625f5a;
  margin-bottom: 8px;
}

.text-editor-color-sheet__swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.text-editor-color-sheet__swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
  flex: 0 0 auto;
}

.text-editor-color-sheet__swatch.is-active {
  border-color: var(--text-editor-wine, #9f1738);
  box-shadow: 0 0 0 2px rgba(159, 23, 56, 0.25);
}

/* 3 actions: Cancel | Reset | Apply */
.text-editor-color-sheet__actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  position: sticky;
  bottom: 0;
  padding-top: 4px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, #fff 28%);
}

.text-editor-color-sheet__btn,
.text-editor-size-sheet__btn {
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid rgba(23, 23, 22, 0.14);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  padding: 0 8px;
}

.text-editor-color-sheet__btn--ghost,
.text-editor-size-sheet__btn--ghost {
  background: #fff;
  color: #1c1c1a;
}

.text-editor-color-sheet__btn--primary,
.text-editor-size-sheet__btn--primary {
  background: var(--text-editor-wine, #9f1738);
  border-color: var(--text-editor-wine, #9f1738);
  color: #fff;
}

/* Size sheet */
.text-editor-size-sheet__presets {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.text-editor-size-sheet__preset {
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid rgba(23, 23, 22, 0.12);
  background: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  color: #1c1c1a;
}

.text-editor-size-sheet__preset.is-active {
  border-color: var(--text-editor-wine, #9f1738);
  background: rgba(159, 23, 56, 0.1);
  color: var(--text-editor-wine-dark, #7a122c);
}

.text-editor-size-sheet__custom {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.text-editor-size-sheet__custom-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: #625f5a;
}

.text-editor-size-sheet__custom-input {
  min-height: 48px;
  padding: 0 12px;
  border: 1px solid rgba(23, 23, 22, 0.14);
  border-radius: 12px;
  font: inherit;
  font-weight: 600;
  font-size: 1rem;
}

.text-editor-size-sheet__actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.text-editor-font-sheet__list,
.text-editor-interval-sheet__list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.text-editor-font-sheet__item,
.text-editor-interval-sheet__item {
  min-height: 48px;
  padding: 10px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.text-editor-font-sheet__item.is-active,
.text-editor-interval-sheet__item.is-active {
  background: rgba(159, 23, 56, 0.1);
  color: var(--text-editor-wine-dark, #7a122c);
}

@media (max-width: 360px) {
  .text-editor-color-sheet__actions {
    grid-template-columns: 1fr;
  }

  .text-editor-size-sheet__presets {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Mobile alignment popover (7B-2.3.1) */
.text-editor-align-menu {
  position: fixed;
  z-index: 10050;
  min-width: 220px;
  padding: 6px;
  border: 1px solid rgba(23, 23, 22, 0.12);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 10px 28px rgba(23, 23, 22, 0.14);
}

.text-editor-align-menu[hidden] {
  display: none !important;
}

.text-editor-align-menu__item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #1c1c1a;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.text-editor-align-menu__item:hover,
.text-editor-align-menu__item:focus-visible {
  background: rgba(159, 23, 56, 0.08);
  outline: none;
}

.text-editor-align-menu__item.is-active,
.text-editor-align-menu__item[aria-checked="true"] {
  background: rgba(159, 23, 56, 0.1);
  color: var(--text-editor-wine-dark, #7a122c);
}

.text-editor-align-menu__item .te-icon {
  width: 20px;
  height: 20px;
}

/* 6-6B.2 P2: 360px — keep align-right fully inside viewport (was right=363.19) */
@media (max-width: 380px) {
  .text-editor-bar:not(.is-mobile-chrome) {
    padding: 6px 6px 8px;
    gap: 5px;
    box-sizing: border-box;
  }

  .text-editor-bar:not(.is-mobile-chrome) .text-editor-bar__row--primary,
  .text-editor-bar:not(.is-mobile-chrome) .text-editor-bar__row--secondary {
    max-width: 100%;
    gap: 4px;
    row-gap: 4px;
  }

  .text-editor-bar:not(.is-mobile-chrome) .text-editor-bar__zone--center,
  .text-editor-bar:not(.is-mobile-chrome) .text-editor-bar__zone--primary-center {
    gap: 4px;
    flex-wrap: wrap;
    overflow-x: visible;
    overflow-y: visible;
  }

  .text-editor-bar:not(.is-mobile-chrome) .text-editor-bar__btn {
    padding-inline: 6px;
  }

  .text-editor-bar:not(.is-mobile-chrome) .text-editor-bar__btn--icon {
    min-width: 1.85rem;
    padding-inline: 4px;
  }

  .text-editor-bar:not(.is-mobile-chrome) .text-editor-bar__group {
    gap: 3px;
  }

  .text-editor-bar:not(.is-mobile-chrome) .text-editor-bar__selection {
    max-width: 7.5rem;
    min-width: 0;
  }
}

/* Explicit wrap breakpoint for secondary format row (6-6B.1 P1-04) — desktop/tablet only */
@media (max-width: 1279px) {
  .text-editor-bar:not(.is-mobile-chrome) .text-editor-bar__row--secondary {
    flex-wrap: wrap;
    overflow-x: visible;
    overflow-y: visible;
    row-gap: 6px;
  }

  .text-editor-bar:not(.is-mobile-chrome) .text-editor-bar__row--secondary .text-editor-bar__swatches {
    flex-wrap: wrap;
  }
}

@media (max-width: 640px) {
  .text-editor-bar__brand {
    display: none;
  }

  .text-editor-preview-chip {
    top: auto;
    bottom: 16px;
    right: 12px;
    left: 12px;
    justify-content: center;
  }

  .text-editor-toast {
    right: 12px;
    left: 12px;
    bottom: 72px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .text-editor-bar__btn,
  body.is-text-editing [data-edit-id],
  body.is-text-editing [data-editor-block-id] {
    transition: none;
  }

  .text-editor-block-ghost {
    transition: none;
  }
}
