/* ═══════════════════════════════════════════════════════════════
   NM Article Editor — Custom Rich Text Editor Styles
   ═══════════════════════════════════════════════════════════════ */

/* ── Container ──────────────────────────────────────────────── */
.nm-editor {
    position: relative;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: #fff;
    font-family: 'Inter', -apple-system, system-ui, sans-serif;
}
.nm-editor.nm-fullscreen {
    position: fixed;
    inset: 0;
    z-index: 9999;
    border-radius: 0;
    display: flex;
    flex-direction: column;
}

/* ── Toolbar ─────────────────────────────────────────────────── */
.nm-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1px;
    padding: 5px 8px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    border-radius: 8px 8px 0 0;
    user-select: none;
    min-height: 38px;
}
.nm-editor.nm-fullscreen .nm-toolbar { border-radius: 0; }
.nm-toolbar-sep {
    width: 1px; height: 22px;
    background: #cbd5e1;
    margin: 0 3px;
    flex-shrink: 0;
}
.nm-toolbar-break { width: 100%; height: 0; margin: 2px 0; }

/* ── Buttons ─────────────────────────────────────────────────── */
.nm-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 3px 6px;
    min-width: 28px;
    height: 26px;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    color: #334155;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    line-height: 1;
    transition: all 0.1s;
    white-space: nowrap;
    flex-shrink: 0;
}
.nm-btn:hover { background: #f1f5f9; border-color: #e2e8f0; }
.nm-btn.nm-active { background: #e0e7ff; border-color: #a5b4fc; color: #4338ca; }
.nm-btn svg { pointer-events: none; flex-shrink: 0; }

/* ── Selects ─────────────────────────────────────────────────── */
.nm-sel {
    height: 26px;
    padding: 2px 4px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    background: #fff;
    color: #334155;
    font-size: 12px;
    cursor: pointer;
    outline: none;
}
.nm-sel:hover { border-color: #94a3b8; }
.nm-sel-block { max-width: 116px; }
.nm-sel-font  { max-width: 110px; }
.nm-sel-size  { max-width: 58px; }

/* ── Color button ────────────────────────────────────────────── */
.nm-color-wrap { position: relative; }
.nm-color-bar {
    display: block;
    height: 3px;
    border-radius: 1px;
    width: 14px;
    margin-top: 1px;
    background: #000;
    pointer-events: none;
}
.nm-color-panel {
    position: absolute;
    top: 30px; left: 0;
    z-index: 2000;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    width: 196px;
    display: none;
}
.nm-color-panel.nm-open { display: block; }
.nm-color-grid {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 3px;
    margin-bottom: 8px;
}
.nm-swatch {
    width: 18px; height: 18px;
    border-radius: 3px;
    cursor: pointer;
    border: 1px solid rgba(0,0,0,0.12);
    transition: transform 0.1s;
}
.nm-swatch:hover { transform: scale(1.3); z-index: 1; position: relative; }
.nm-color-custom {
    display: flex; align-items: center; gap: 6px;
    padding-top: 6px;
    border-top: 1px solid #f1f5f9;
}
.nm-color-custom label { font-size: 11px; color: #64748b; }
.nm-color-custom input[type="color"] {
    width: 28px; height: 22px;
    border: 1px solid #d1d5db;
    border-radius: 3px;
    padding: 1px; cursor: pointer;
}

/* ── Table picker ────────────────────────────────────────────── */
.nm-tp-wrap { position: relative; }
.nm-tp-panel {
    position: absolute;
    top: 30px; left: 0;
    z-index: 2000;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    display: none;
}
.nm-tp-panel.nm-open { display: block; }
.nm-tp-grid {
    display: grid;
    grid-template-columns: repeat(10, 20px);
    gap: 3px;
}
.nm-tp-cell {
    width: 20px; height: 20px;
    border: 1px solid #e2e8f0;
    border-radius: 2px;
    cursor: pointer;
    background: #fff;
}
.nm-tp-cell.nm-hi { background: #dbeafe; border-color: #93c5fd; }
.nm-tp-label {
    margin-top: 6px;
    font-size: 11px; color: #64748b;
    text-align: center;
}

/* ── Editable area ───────────────────────────────────────────── */
.nm-editable {
    min-height: 420px;
    padding: 18px 22px;
    outline: none;
    overflow-y: auto;
    font-size: 15px;
    line-height: 1.75;
    color: #1e293b;
    caret-color: #4f46e5;
}
.nm-editor.nm-fullscreen .nm-editable {
    flex: 1;
    max-height: none;
    overflow-y: auto;
}
.nm-editable:empty::before {
    content: attr(data-placeholder);
    color: #94a3b8;
    pointer-events: none;
}
/* Content typography */
.nm-editable h1 { font-size: 2em; font-weight: 700; margin: .6em 0 .4em; line-height: 1.25; }
.nm-editable h2 { font-size: 1.5em; font-weight: 700; margin: .8em 0 .4em; line-height: 1.3; }
.nm-editable h3 { font-size: 1.25em; font-weight: 600; margin: .8em 0 .4em; }
.nm-editable h4 { font-size: 1.1em; font-weight: 600; margin: .8em 0 .3em; }
.nm-editable h5 { font-size: 1em; font-weight: 600; margin: .6em 0 .3em; }
.nm-editable h6 { font-size: .9em; font-weight: 600; color: #475569; margin: .6em 0 .3em; }
.nm-editable p  { margin: 0 0 .75em; }
.nm-editable ul { margin: .5em 0; padding-left: 1.8em; list-style-type: disc; }
.nm-editable ol { margin: .5em 0; padding-left: 1.8em; list-style-type: decimal; }
.nm-editable ul ul { list-style-type: circle; }
.nm-editable ul ul ul { list-style-type: square; }
.nm-editable li { margin: .2em 0; display: list-item; }
.nm-editable blockquote {
    margin: 1em 0; padding: .75em 1em .75em 1.1em;
    border-left: 4px solid #6366f1;
    background: #eef2ff; color: #374151;
    border-radius: 0 6px 6px 0;
    font-style: italic;
}
.nm-editable pre {
    background: #0f172a; color: #e2e8f0;
    padding: 1em 1.25em; border-radius: 8px;
    overflow-x: auto;
    font-family: 'Courier New', monospace;
    font-size: 13px; line-height: 1.6;
    margin: .8em 0;
}
.nm-editable code {
    background: #f1f5f9; color: #e11d48;
    padding: .15em .4em; border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: .875em;
}
.nm-editable pre code { background: none; color: inherit; padding: 0; }
.nm-editable table {
    border-collapse: collapse;
    width: 100%; margin: 0; font-size: 14px;
    max-width: 100%;
}
/* figure.nm-figure wraps the table; width + alignment are applied here */
.nm-editable figure.nm-figure table { width: 100%; margin: 0; }
.nm-editable table td, .nm-editable table th {
    border: 1px solid #cbd5e1;
    padding: 7px 12px; text-align: left;
}
.nm-editable table th { background: #f8fafc; font-weight: 600; }
.nm-editable table tr:hover td { background: #f8fafc; }
.nm-editable a { color: #4f46e5; text-decoration: underline; }
.nm-editable img { max-width: 100%; height: auto; border-radius: 6px; display: inline-block; }
.nm-editable figure.nm-figure {
    margin: 1em 0;
    display: block;
}
.nm-editable figure.nm-figure img {
    display: block;
    margin: 0 auto;
    border-radius: 6px;
    max-width: 100%;
    height: auto;
}
.nm-editable figure.nm-figure table { margin: 0; width: 100%; }
.nm-editable figcaption {
    font-size: 13px;
    color: #64748b;
    font-style: italic;
    text-align: center;
    margin-top: 6px;
    padding: 3px 8px;
    min-height: 1.4em;
    border-radius: 4px;
    transition: background .1s;
    outline: none;
}
.nm-editable figcaption:focus { background: #f8fafc; }
.nm-editable figcaption:empty::before {
    content: 'Nhấn để nhập chú thích...';
    color: #cbd5e1;
    pointer-events: none;
    font-style: italic;
}
.nm-editable hr { border: none; border-top: 2px solid #e2e8f0; margin: 1.5em 0; }
.nm-editable .nm-media {
    position: relative; padding-bottom: 56.25%; height: 0;
    overflow: hidden; margin: 1em 0; border-radius: 8px; background: #000;
}
.nm-editable .nm-media iframe {
    position: absolute; top: 0; left: 0;
    width: 100%; height: 100%; border: none;
}

/* ── Source textarea ─────────────────────────────────────────── */
.nm-source {
    display: none;
    width: 100%;
    min-height: 420px;
    padding: 18px 22px;
    border: none; outline: none;
    resize: vertical;
    font-family: 'Courier New', monospace;
    font-size: 13px; line-height: 1.6;
    color: #0f172a; background: #f8fafc;
    box-sizing: border-box;
}
.nm-editor.nm-fullscreen .nm-source { flex: 1; min-height: 0; }

/* ── Status bar ──────────────────────────────────────────────── */
.nm-status {
    display: flex; align-items: center;
    justify-content: space-between;
    padding: 4px 14px;
    border-top: 1px solid #e2e8f0;
    background: #f8fafc;
    border-radius: 0 0 8px 8px;
    font-size: 11px; color: #94a3b8;
}
.nm-editor.nm-fullscreen .nm-status { border-radius: 0; }

/* ── Dialog overlay ──────────────────────────────────────────── */
.nm-overlay {
    position: absolute; inset: 0;
    background: rgba(15,23,42,.45);
    display: none;
    align-items: center; justify-content: center;
    z-index: 3000;
    border-radius: 8px;
}
.nm-overlay.nm-open { display: flex; }
.nm-editor.nm-fullscreen .nm-overlay { border-radius: 0; }
.nm-dialog {
    background: #fff; border-radius: 10px;
    box-shadow: 0 12px 40px rgba(0,0,0,.22);
    width: min(460px, 94%);
    max-height: 86vh;
    display: flex; flex-direction: column;
    overflow: hidden;
}
.nm-dialog-hd {
    display: flex; align-items: center;
    justify-content: space-between;
    padding: 13px 16px;
    border-bottom: 1px solid #f1f5f9;
    font-weight: 600; font-size: 14px; color: #0f172a;
    flex-shrink: 0;
}
.nm-dialog-x {
    background: none; border: none;
    font-size: 18px; cursor: pointer;
    color: #94a3b8; padding: 0; line-height: 1;
}
.nm-dialog-x:hover { color: #334155; }
.nm-dialog-bd {
    padding: 16px; overflow-y: auto; flex: 1;
}
.nm-dialog-ft {
    padding: 11px 16px;
    border-top: 1px solid #f1f5f9;
    display: flex; justify-content: flex-end; gap: 8px;
    background: #f8fafc; flex-shrink: 0;
}
.nm-f { margin-bottom: 12px; }
.nm-f:last-child { margin-bottom: 0; }
.nm-f label {
    display: block; font-size: 12px;
    font-weight: 500; color: #475569; margin-bottom: 4px;
}
.nm-f input, .nm-f select, .nm-f textarea {
    width: 100%; padding: 7px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px; font-size: 13px;
    outline: none; color: #1e293b;
    box-sizing: border-box;
    font-family: inherit;
}
.nm-f input:focus, .nm-f select:focus, .nm-f textarea:focus {
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}
.nm-f-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.nm-f-check { display: flex; align-items: center; gap: 7px; font-size: 13px; color: #374151; cursor: pointer; }
.nm-f-check input { width: auto; margin: 0; }
.nm-f-hint { font-size: 11px; color: #94a3b8; margin-top: 3px; }
.nm-dbtn {
    padding: 7px 16px; border-radius: 6px;
    font-size: 13px; font-weight: 500;
    cursor: pointer; border: 1px solid transparent;
    font-family: inherit;
}
.nm-dbtn-cancel { background:#fff; border-color:#d1d5db; color:#374151; }
.nm-dbtn-cancel:hover { background: #f1f5f9; }
.nm-dbtn-ok { background:#4f46e5; color:#fff; }
.nm-dbtn-ok:hover { background:#4338ca; }
.nm-dbtn-danger { background:#ef4444; color:#fff; }
.nm-dbtn-danger:hover { background:#dc2626; }

/* ── Special characters ──────────────────────────────────────── */
.nm-special-grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 4px;
}
.nm-special-btn {
    padding: 6px 4px; border: 1px solid #e2e8f0;
    border-radius: 4px; background: #fff;
    cursor: pointer; font-size: 15px; text-align: center;
    transition: all .1s;
}
.nm-special-btn:hover { background: #eef2ff; border-color: #a5b4fc; }

/* ── List type picker ────────────────────────────────────────── */
.nm-list-wrap { position: relative; display: inline-flex; }
.nm-list-panel {
    position: absolute;
    top: 30px; left: 0;
    z-index: 2000;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 6px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    min-width: 180px;
    display: none;
}
.nm-list-panel.nm-open { display: block; }
.nm-list-grid { display: flex; flex-direction: column; gap: 1px; }
.nm-list-item {
    display: flex; align-items: center; gap: 10px;
    padding: 6px 8px;
    border-radius: 5px;
    cursor: pointer;
    transition: background .1s;
    user-select: none;
}
.nm-list-item:hover { background: #f1f5f9; }
.nm-list-item.nm-active { background: #e0e7ff; }
.nm-list-preview {
    font-size: 11px; color: #1e293b;
    width: 62px; flex-shrink: 0;
    font-family: 'Courier New', monospace;
    line-height: 1.4;
}
.nm-list-label { font-size: 12px; color: #64748b; }
.nm-btn .nm-arr { font-size: 8px; margin-left: 1px; opacity: .7; }

/* ── Image Editor (Crop + Resize) ───────────────────────────── */
.nm-ie-stage {
    overflow: auto;
    max-height: 370px;
    display: flex;
    justify-content: center;
    background: repeating-conic-gradient(#cbd5e1 0% 25%, #f8fafc 0% 50%) 0 0 / 14px 14px;
    border-radius: 6px;
    padding: 8px;
    border: 1px solid #e2e8f0;
}
.nm-ie-canvas-wrap { position: relative; flex-shrink: 0; }
.nm-ie-bg { display: block; }
.nm-ie-ol { position: absolute; top: 0; left: 0; cursor: crosshair; }
.nm-ie-panel { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.nm-ie-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.nm-ie-lbl { font-size: 12px; color: #64748b; white-space: nowrap; }
.nm-ie-num {
    width: 68px; padding: 4px 6px;
    border: 1px solid #d1d5db; border-radius: 4px;
    font-size: 13px; text-align: center; outline: none;
}
.nm-ie-num:focus { border-color: #6366f1; box-shadow: 0 0 0 2px rgba(99,102,241,.12); }
.nm-ie-sel {
    height: 26px; padding: 2px 6px;
    border: 1px solid #d1d5db; border-radius: 4px;
    font-size: 12px; outline: none; background: #fff; cursor: pointer;
}
.nm-ie-chk-lbl {
    display: flex; align-items: center; gap: 4px;
    font-size: 12px; color: #374151; cursor: pointer; white-space: nowrap;
}
.nm-ie-hint { font-size: 11px; color: #94a3b8; font-style: italic; }
.nm-ie-warn {
    font-size: 12px; color: #b45309;
    background: #fffbeb; border: 1px solid #fde68a;
    border-radius: 5px; padding: 6px 10px; margin-bottom: 8px;
}

/* ── Image Resizer ───────────────────────────────────────────── */
.nm-img-sel {
    position: fixed;
    pointer-events: none;
    z-index: 9990;
    box-sizing: border-box;
    outline: 2px solid #6366f1;
    outline-offset: 1px;
}
.nm-img-h {
    position: absolute;
    width: 10px; height: 10px;
    background: #fff;
    border: 2px solid #6366f1;
    border-radius: 2px;
    pointer-events: all;
}
.nm-h-nw { top: -5px; left: -5px; cursor: nw-resize; }
.nm-h-ne { top: -5px; right: -5px; cursor: ne-resize; }
.nm-h-sw { bottom: -5px; left: -5px; cursor: sw-resize; }
.nm-h-se { bottom: -5px; right: -5px; cursor: se-resize; }
.nm-img-bar {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 2px;
    background: #1e293b;
    border-radius: 6px;
    padding: 4px 6px;
    pointer-events: all;
    white-space: nowrap;
    box-shadow: 0 4px 14px rgba(0,0,0,.35);
}
.nm-img-bar.nm-bar-below {
    bottom: auto;
    top: calc(100% + 8px);
}
.nm-ib {
    background: transparent;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: inherit;
    line-height: 1.4;
}
.nm-ib:hover { background: #334155; color: #e2e8f0; }
.nm-ib-del:hover { color: #f87171 !important; }
.nm-ib-crop:hover { color: #86efac !important; }
.nm-ib-sep {
    width: 1px; height: 14px;
    background: #334155;
    flex-shrink: 0;
    margin: 0 2px;
}
.nm-ib-lbl { font-size: 11px; color: #475569; padding: 0 2px; }
.nm-isz-w {
    width: 48px; padding: 2px 4px;
    border: 1px solid #475569;
    border-radius: 3px;
    background: #0f172a;
    color: #e2e8f0;
    font-size: 11px;
    text-align: center;
    outline: none;
}
.nm-isz-w:focus { border-color: #818cf8; }

/* ── Table Selector ──────────────────────────────────────────── */
.nm-tbl-sel {
    position: fixed;
    pointer-events: none;
    z-index: 9990;
    box-sizing: border-box;
    outline: 2px solid #6366f1;
    outline-offset: 1px;
}
.nm-tbl-bar {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 2px;
    background: #1e293b;
    border-radius: 6px;
    padding: 4px 6px;
    pointer-events: all;
    white-space: nowrap;
    box-shadow: 0 4px 14px rgba(0,0,0,.35);
}
.nm-tbl-bar.nm-bar-below {
    bottom: auto;
    top: calc(100% + 8px);
}
.nm-ib-grp {
    font-size: 9px !important;
    color: #475569 !important;
    letter-spacing: .5px;
    text-transform: uppercase;
    padding: 0 2px;
}
.nm-tb-del:hover { color: #f87171 !important; }
.nm-tbl-rh {
    position: absolute;
    right: -5px; top: 50%;
    transform: translateY(-50%);
    width: 10px; height: 32px;
    background: #6366f1;
    border-radius: 3px;
    cursor: col-resize;
    pointer-events: all;
    opacity: .85;
}
.nm-tbl-rh:hover { opacity: 1; background: #4f46e5; }

/* ── Upload progress ─────────────────────────────────────────── */
.nm-upload-area {
    border: 2px dashed #cbd5e1;
    border-radius: 8px; padding: 20px;
    text-align: center; cursor: pointer;
    transition: all .2s;
    background: #f8fafc;
}
.nm-upload-area:hover, .nm-upload-area.nm-drag { border-color: #6366f1; background: #eef2ff; }
.nm-upload-area p { margin: 6px 0 0; font-size: 12px; color: #64748b; }
.nm-progress {
    height: 4px; background: #e2e8f0;
    border-radius: 2px; margin-top: 8px;
    overflow: hidden; display: none;
}
.nm-progress-bar {
    height: 100%; background: #6366f1;
    transition: width .2s; width: 0;
}
