.rte-container {
    --rte-font-family: inherit;
    --rte-font-size: 1rem;
    --rte-text-color: #1a1a1a;
    --rte-bg-color: #fff;
    --rte-border-color: #d1d5db;
    --rte-border-radius: 8px;
    --rte-toolbar-bg: #fafafa;
    --rte-toolbar-border: #e5e7eb;
    --rte-btn-hover-bg: #f3f4f6;
    --rte-btn-active-bg: #e5e7eb;
    --rte-btn-active-color: #1a1a1a;
    --rte-focus-ring: #8B6914;
    --rte-placeholder-color: #9ca3af;

    border: 1px solid var(--rte-border-color);
    border-radius: var(--rte-border-radius);
    overflow: hidden;
    background: var(--rte-bg-color);
    font-family: var(--rte-font-family);
    font-size: var(--rte-font-size);
    color: var(--rte-text-color);
    position: relative;
    max-width: 100%;
    min-width: 0;
}

.rte-container:focus-within {
    border-color: var(--rte-focus-ring);
    box-shadow: 0 0 0 1px var(--rte-focus-ring);
}

/* Toolbar */
.rte-toolbar {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 2px;
    padding: 4px 6px;
    background: var(--rte-toolbar-bg);
    border-bottom: 1px solid var(--rte-toolbar-border);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.rte-toolbar-sep {
    width: 1px;
    height: 18px;
    background: var(--rte-toolbar-border);
    margin: 0 2px;
    flex-shrink: 0;
}

.rte-toolbar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--rte-text-color);
    cursor: pointer;
    flex-shrink: 0;
}

.rte-toolbar-btn:hover {
    background: var(--rte-btn-hover-bg);
}

.rte-toolbar-btn.active {
    background: var(--rte-btn-active-bg);
    color: var(--rte-btn-active-color);
}

.rte-toolbar-btn svg {
    width: 20px;
    height: 20px;
    display: block;
    overflow: visible;
}

.rte-toolbar-btn svg.rte-icon-lg {
    width: 24px;
    height: 24px;
}

.rte-toolbar-btn svg.rte-icon-xl {
    width: 28px;
    height: 28px;
}

.rte-toolbar-btn svg.rte-icon-sm {
    width: 16px;
    height: 16px;
}


/* Content area */
.rte-content {
    padding: 12px 16px;
    min-height: 120px;
    outline: none;
    line-height: 1.6;
    word-wrap: break-word;
    overflow-wrap: break-word;
    position: relative;
}

/* Placeholder */
.rte-content.rte-empty[data-placeholder]:not(:focus)::before {
    content: attr(data-placeholder);
    color: var(--rte-placeholder-color);
    pointer-events: none;
    position: absolute;
}

/* Restore styles stripped by global reset (all: unset) */
.rte-content b,
.rte-content strong {
    font-weight: 700;
}

.rte-content i,
.rte-content em {
    font-style: italic;
}

.rte-content u {
    text-decoration: underline;
}

.rte-content s,
.rte-content strike {
    text-decoration: line-through;
}

.rte-content ul {
    list-style-type: disc;
}

.rte-content ol {
    list-style-type: decimal;
}

.rte-content li {
    display: list-item;
}

/* Nested list styles */
.rte-content ul ul {
    list-style-type: circle;
}

.rte-content ul ul ul {
    list-style-type: square;
}

.rte-content ol ol {
    list-style-type: lower-alpha;
}

.rte-content ol ol ol {
    list-style-type: lower-roman;
}


/* Content defaults */
.rte-content h1 {
    font-size: 1.75em;
    font-weight: 700;
    margin: 0.4em 0;
    line-height: 1.2;
}

.rte-content h2 {
    font-size: 1.4em;
    font-weight: 700;
    margin: 0.35em 0;
    line-height: 1.3;
}

.rte-content h3 {
    font-size: 1.15em;
    font-weight: 700;
    margin: 0.3em 0;
    line-height: 1.4;
}

.rte-content blockquote {
    border-left: 3px solid var(--rte-border-color);
    padding: 4px 12px;
    margin: 8px 0;
    font-style: italic;
    color: #6b7280;
}

.rte-content ul,
.rte-content ol {
    padding-left: 24px;
    margin: 4px 0;
}

.rte-content li {
    margin: 2px 0;
}

.rte-content a {
    color: #2563eb;
    text-decoration: underline;
}

.rte-content img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    cursor: pointer;
}

.rte-content img.rte-img-selected {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

/* Hide blue text-selection highlight on images (selection is kept for alignment to work) */
.rte-content img::selection {
    background: transparent;
}

.rte-content .rte-img-resize-wrapper::selection,
.rte-content .rte-img-resize-wrapper *::selection {
    background: transparent;
}

/* Image resize wrapper */
.rte-img-resize-wrapper {
    position: relative;
    display: inline-block;
    max-width: 100%;
    overflow: visible;
}

.rte-img-resize-handle {
    position: absolute;
    width: 22px;
    height: 22px;
    background: #2563eb;
    border: 2px solid #fff;
    border-radius: 0;
    cursor: nwse-resize;
    z-index: 10;
}

.rte-img-resize-handle-br {
    bottom: -6px;
    right: -13px;
}

.rte-img-resize-handle-bl {
    bottom: -6px;
    left: -13px;
    cursor: nesw-resize;
}

.rte-img-resize-handle-tr {
    top: -14px;
    right: -14px;
    cursor: nesw-resize;
}

.rte-img-resize-handle-tl {
    top: -14px;
    left: -14px;
    cursor: nwse-resize;
}

/* Image toolbar (delete, etc.) — centered above image */
.rte-img-toolbar {
    position: absolute;
    top: -40px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 4px;
    padding: 4px;
    background: #fff;
    border: 1px solid var(--rte-border-color);
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    z-index: 20;
    white-space: nowrap;
}

.rte-img-toolbar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: #dc2626;
    cursor: pointer;
}

.rte-img-toolbar-btn:hover {
    background: #fef2f2;
}

.rte-img-toolbar-btn-default {
    color: #374151;
}

.rte-img-toolbar-btn-default:hover {
    background: #f3f4f6;
}

/* Link toolbar — floating above clicked link */
.rte-link-toolbar {
    display: flex;
    gap: 2px;
    padding: 4px;
    background: #fff;
    border: 1px solid var(--rte-border-color);
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    z-index: 20;
    white-space: nowrap;
}

.rte-link-toolbar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 10px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--rte-text-color);
    cursor: pointer;
    font-size: 0.8rem;
    font-family: inherit;
}

.rte-link-toolbar-btn:hover {
    background: var(--rte-btn-hover-bg);
}

.rte-link-toolbar-btn-danger {
    color: #dc2626;
}

.rte-link-toolbar-btn-danger:hover {
    background: #fef2f2;
}

.rte-link-toolbar-url {
    font-size: 0.75rem;
    color: #6b7280;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0 4px;
    line-height: 28px;
}

.rte-content p {
    margin: 0 0 0.4em;
}

.rte-content > div {
    margin: 0;
}

/* Link popover — positioned relative to .rte-container */
.rte-link-popover {
    position: absolute;
    top: 37px;
    left: 4px;
    right: 4px;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 8px;
    background: #fff;
    border: 1px solid var(--rte-border-color);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.rte-link-text-input,
.rte-link-input {
    border: 1px solid var(--rte-border-color);
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 0.85rem;
    outline: none;
    min-width: 120px;
    flex: 1;
    font-family: inherit;
}

.rte-link-text-input::placeholder,
.rte-link-input::placeholder {
    color: var(--gray-5);
}

.rte-link-text-input:focus,
.rte-link-input:focus {
    border-color: var(--rte-focus-ring);
}

.rte-link-btn {
    border: none;
    border-radius: 4px;
    padding: 4px 10px;
    font-size: 0.8rem;
    cursor: pointer;
    background: var(--rte-btn-active-bg);
    color: var(--rte-text-color);
    white-space: nowrap;
    font-family: inherit;
}

.rte-link-btn:hover {
    background: #d1d5db;
}

.rte-link-btn-remove {
    color: #dc2626;
}

/* Color picker — positioned relative to .rte-container */
.rte-color-picker {
    position: absolute;
    top: 37px;
    right: 4px;
    z-index: 1000;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    padding: 8px;
    background: #fff;
    border: 1px solid var(--rte-border-color);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.rte-color-swatch {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.rte-color-swatch:hover {
    border-color: #93c5fd;
}

.rte-color-swatch.rte-color-selected {
    outline: 2px solid #2563eb;
    outline-offset: -1px;
}

.rte-color-reset {
    background: #fff;
    border: 2px solid var(--rte-border-color);
    color: #9ca3af;
}

/* Emoji picker — positioned relative to .rte-container */
.rte-emoji-picker {
    position: absolute;
    top: 37px;
    right: 4px;
    z-index: 1000;
    width: 280px;
    max-width: calc(100% - 8px);
    background: #fff;
    border: 1px solid var(--rte-border-color);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    overflow: hidden;
}

.rte-emoji-search {
    width: 100%;
    border: none;
    border-bottom: 1px solid var(--rte-toolbar-border);
    padding: 8px 10px;
    font-size: 0.85rem;
    outline: none;
    font-family: inherit;
    box-sizing: border-box;
}

.rte-emoji-search:focus {
    border-bottom-color: var(--rte-focus-ring);
}

.rte-emoji-categories {
    display: flex;
    border-bottom: 1px solid var(--rte-toolbar-border);
    padding: 2px 4px;
    gap: 1px;
    overflow-x: auto;
}

.rte-emoji-cat-btn {
    flex: 1;
    min-width: 28px;
    height: 28px;
    border: none;
    border-radius: 4px;
    background: transparent;
    cursor: pointer;
    font-size: 14px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.rte-emoji-cat-btn:hover {
    background: var(--rte-btn-hover-bg);
}

.rte-emoji-cat-btn.active {
    background: var(--rte-btn-active-bg);
}

.rte-emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 1px;
    padding: 4px;
    max-height: 200px;
    overflow-y: auto;
}

.rte-emoji-item {
    width: 100%;
    aspect-ratio: 1;
    border: none;
    border-radius: 4px;
    background: transparent;
    cursor: pointer;
    font-size: 18px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.rte-emoji-item:hover {
    background: var(--rte-btn-hover-bg);
}

/* Read-only state */
.rte-readonly .rte-toolbar {
    display: none;
}

.rte-readonly {
    border-color: transparent;
    box-shadow: none;
}

.rte-readonly .rte-content {
    padding: 0;
    min-height: 0;
}
