/* =========================================================
   RichEditor — Standalone Rich Text Editor
   Usage: <link rel="stylesheet" href="/editor/rich-editor.css">
   ========================================================= */

.rich-editor-wrapper {
    display: flex;
    flex-direction: column;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    overflow: hidden;
    background: #fff;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* Dark mode */
.dark .rich-editor-wrapper {
    border-color: #374151;
    background: #1f2937;
}

/* ---- Toolbar ---- */
.rich-editor-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    padding: 6px 8px;
    border-bottom: 1px solid #e5e7eb;
    background: #f9fafb;
    user-select: none;
}

.dark .rich-editor-toolbar {
    border-bottom-color: #374151;
    background: #111827;
}

.re-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 8px;
    font-size: 13px;
    line-height: 1;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    background: #fff;
    color: #374151;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.1s, border-color 0.1s;
}

.re-btn:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}

.re-btn.re-active {
    background: #dbeafe;
    border-color: #3b82f6;
    color: #1d4ed8;
}

.dark .re-btn {
    background: #1f2937;
    border-color: #4b5563;
    color: #d1d5db;
}

.dark .re-btn:hover {
    background: #374151;
}

.dark .re-btn.re-active {
    background: #1e3a5f;
    border-color: #3b82f6;
    color: #93c5fd;
}

.re-select {
    padding: 4px 6px;
    font-size: 13px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    background: #fff;
    color: #374151;
    cursor: pointer;
}

.dark .re-select {
    background: #1f2937;
    border-color: #4b5563;
    color: #d1d5db;
}

.re-sep {
    width: 1px;
    height: 20px;
    background: #d1d5db;
    margin: 0 4px;
    flex-shrink: 0;
}

.dark .re-sep {
    background: #4b5563;
}

.re-color-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 6px;
    font-size: 12px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    background: #fff;
    color: #374151;
    cursor: pointer;
}

.dark .re-color-btn {
    background: #1f2937;
    border-color: #4b5563;
    color: #d1d5db;
}

.re-color-btn input[type="color"] {
    width: 20px;
    height: 20px;
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
    -webkit-appearance: none;
}

/* ---- Editor area ---- */
.rich-editor-body {
    min-height: 220px;
    max-height: 600px;
    overflow-y: auto;
    padding: 12px 16px;
    outline: none;
    font-size: 14px;
    line-height: 1.7;
    color: #111827;
    background: #fff;
}

.dark .rich-editor-body {
    color: #f3f4f6;
    background: #111827;
}

.rich-editor-body:focus {
    outline: none;
}

/* Content styling inside editor */
.rich-editor-body h1 { font-size: 2em;   font-weight: 700; margin: 0.5em 0; }
.rich-editor-body h2 { font-size: 1.5em; font-weight: 700; margin: 0.5em 0; }
.rich-editor-body h3 { font-size: 1.25em;font-weight: 600; margin: 0.5em 0; }
.rich-editor-body p  { margin: 0.4em 0; }
.rich-editor-body ul { list-style: disc;   padding-left: 1.5em; margin: 0.4em 0; }
.rich-editor-body ol { list-style: decimal; padding-left: 1.5em; margin: 0.4em 0; }
.rich-editor-body a  { color: #2563eb; text-decoration: underline; }
.rich-editor-body blockquote {
    border-left: 3px solid #d1d5db;
    padding-left: 12px;
    color: #6b7280;
    margin: 0.5em 0;
}

/* Tables */
.rich-editor-body table {
    border-collapse: collapse;
    width: 100%;
    margin: 8px 0;
}
.rich-editor-body td,
.rich-editor-body th {
    border: 1px solid #d1d5db;
    padding: 6px 10px;
    min-width: 40px;
}
.rich-editor-body th {
    background: #f3f4f6;
    font-weight: 600;
}
.dark .rich-editor-body td,
.dark .rich-editor-body th {
    border-color: #4b5563;
}
.dark .rich-editor-body th {
    background: #374151;
}

/* Images */
.rich-editor-body img {
    max-width: 100%;
    height: auto;
    display: inline-block;
    border-radius: 3px;
}

.rich-editor-body img.re-selected {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* ---- Status bar ---- */
.rich-editor-statusbar {
    padding: 3px 10px;
    font-size: 11px;
    color: #9ca3af;
    border-top: 1px solid #e5e7eb;
    background: #f9fafb;
    text-align: right;
}

.dark .rich-editor-statusbar {
    border-top-color: #374151;
    background: #111827;
}

/* ---- Modal overlay ---- */
.re-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.re-modal {
    background: #fff;
    border-radius: 8px;
    padding: 24px;
    min-width: 320px;
    max-width: 480px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}

.dark .re-modal {
    background: #1f2937;
    color: #f3f4f6;
}

.re-modal h3 {
    font-size: 16px;
    font-weight: 600;
    margin: 0 0 16px;
    color: #111827;
}

.dark .re-modal h3 {
    color: #f3f4f6;
}

.re-modal label {
    display: block;
    font-size: 13px;
    color: #6b7280;
    margin-bottom: 4px;
}

.re-modal input[type="text"],
.re-modal input[type="url"],
.re-modal input[type="number"] {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #d1d5db;
    border-radius: 5px;
    font-size: 14px;
    margin-bottom: 12px;
    box-sizing: border-box;
    background: #fff;
    color: #111827;
}

.dark .re-modal input[type="text"],
.dark .re-modal input[type="url"],
.dark .re-modal input[type="number"] {
    background: #374151;
    border-color: #4b5563;
    color: #f3f4f6;
}

.re-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 4px;
}

.re-modal-btn {
    padding: 8px 18px;
    border-radius: 5px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid #d1d5db;
    background: #fff;
    color: #374151;
}

.re-modal-btn.primary {
    background: #3b82f6;
    border-color: #3b82f6;
    color: #fff;
}

.re-modal-btn.primary:hover {
    background: #2563eb;
}

.re-modal-btn:hover {
    background: #f3f4f6;
}

.dark .re-modal-btn {
    background: #374151;
    border-color: #4b5563;
    color: #d1d5db;
}

/* ── Image Resize Overlay ─────────────────────────────────── */
.re-resize-overlay {
    position: absolute;
    z-index: 99999;
    box-sizing: border-box;
    outline: 2px solid #6366f1;
    pointer-events: none;
}

/* Selected image inside the editor body */
.rich-editor-body img.re-selected {
    outline: 2px solid #6366f1;
}

/* 8 drag handles */
.re-resize-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: #fff;
    border: 2px solid #6366f1;
    border-radius: 2px;
    pointer-events: all;
    box-sizing: border-box;
}
.re-resize-handle:hover { background: #818cf8; }

/* Corners */
.re-rh-nw { top:  -5px; left:  -5px;            cursor: nw-resize; }
.re-rh-ne { top:  -5px; right: -5px;            cursor: ne-resize; }
.re-rh-se { bottom: -5px; right: -5px;          cursor: se-resize; }
.re-rh-sw { bottom: -5px; left:  -5px;          cursor: sw-resize; }

/* Edges */
.re-rh-n  { top:  -5px; left: calc(50% - 5px); cursor: n-resize; }
.re-rh-e  { top: calc(50% - 5px); right: -5px; cursor: e-resize; }
.re-rh-s  { bottom: -5px; left: calc(50% - 5px); cursor: s-resize; }
.re-rh-w  { top: calc(50% - 5px); left:  -5px; cursor: w-resize; }

/* Dimensions tooltip */
.re-resize-size {
    position: absolute;
    bottom: calc(100% + 5px);
    left: 50%;
    transform: translateX(-50%);
    background: #312e81;
    color: #e0e7ff;
    font-size: 11px;
    padding: 2px 7px;
    border-radius: 3px;
    white-space: nowrap;
    pointer-events: none;
    font-family: monospace;
}
