/* ============================================================
   MACHINE 28 - RICH EDITOR STYLES
   ============================================================ */

/* ===== TWO-COLUMN LAYOUT ===== */
.editor-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    align-items: start;
}

@media (max-width: 1100px) {
    .editor-layout {
        grid-template-columns: 1fr;
    }
}

.editor-column { min-width: 0; }
.preview-column { min-width: 0; }

/* ===== TEMPLATE GRID ===== */
.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
}

.template-btn {
    background: rgba(255,255,255,0.02);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 10px;
    cursor: pointer;
    transition: all 0.3s;
    text-align: center;
    color: var(--text);
    font-family: inherit;
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: center;
}

.template-btn:hover {
    border-color: var(--purple);
    background: rgba(167,139,250,0.05);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(167,139,250,0.1);
}

.template-btn.active {
    border-color: var(--gold);
    background: rgba(245,158,11,0.08);
}

.template-btn .icon { font-size: 24px; }
.template-btn .name { font-size: 13px; font-weight: 700; }
.template-btn .desc { font-size: 11px; color: var(--text-muted); }

/* ===== TOOLBAR ===== */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
    padding: 12px 14px;
    background: rgba(0,0,0,0.4);
    border-bottom: 1px solid var(--border);
    align-items: center;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 4px;
    padding-right: 12px;
    border-right: 1px solid var(--border);
}

.toolbar-group:last-child {
    border-right: none;
    padding-right: 0;
}

.toolbar-label {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    padding-right: 6px;
    font-weight: 700;
}

.toolbar button {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--text-muted);
    padding: 6px 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 13px;
    font-family: inherit;
    min-width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

.toolbar button:hover {
    background: rgba(167,139,250,0.1);
    border-color: var(--purple);
    color: var(--text);
}

.toolbar button:active {
    transform: scale(0.95);
}

.toolbar select {
    background: rgba(0,0,0,0.5);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: 6px 8px;
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    height: 32px;
}

.toolbar select:focus {
    outline: none;
    border-color: var(--purple);
}

/* ===== EDITOR AREA ===== */
.editor-content {
    min-height: 400px;
    max-height: 700px;
    overflow-y: auto;
    padding: 24px;
    background: rgba(0,0,0,0.3);
    color: var(--text);
    font-size: 15px;
    line-height: 1.7;
    outline: none;
    font-family: 'Inter', 'Segoe UI', sans-serif;
}

.editor-content:empty::before {
    content: attr(placeholder);
    color: var(--text-muted);
}

/* Editor content: all HTML tags render exactly */
.editor-content h1 {
    font-family: 'Orbitron', monospace;
    font-size: 28px;
    font-weight: 700;
    color: var(--gold);
    margin: 16px 0 10px 0;
    letter-spacing: 1px;
}
.editor-content h2 {
    font-family: 'Orbitron', monospace;
    font-size: 22px;
    font-weight: 700;
    color: var(--purple);
    margin: 14px 0 8px 0;
}
.editor-content h3 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    margin: 12px 0 6px 0;
}
.editor-content p { margin: 8px 0; }
.editor-content ul, .editor-content ol { padding-left: 24px; margin: 8px 0; }
.editor-content li { margin: 4px 0; }
.editor-content blockquote {
    border-left: 3px solid var(--gold);
    padding: 8px 16px;
    margin: 12px 0;
    background: rgba(245,158,11,0.05);
    border-radius: 0 6px 6px 0;
    color: var(--text-muted);
    font-style: italic;
}
.editor-content pre, .editor-content code {
    font-family: 'JetBrains Mono', monospace;
    background: rgba(0,0,0,0.5);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 2px 6px;
    font-size: 0.9em;
    color: var(--success);
}
.editor-content pre {
    padding: 12px 16px;
    overflow-x: auto;
    display: block;
    margin: 12px 0;
}
.editor-content a { color: var(--purple); text-decoration: underline; }
.editor-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 12px 0;
    border: 1px solid var(--border);
    display: block;
}
.editor-content hr {
    border: none;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--purple), transparent);
    margin: 20px 0;
}

/* Image alignment classes */
.editor-content img.img-top,
.preview-content img.img-top {
    display: block;
    margin: 16px auto;
    width: 100%;
    max-width: 100%;
}

.editor-content img.img-left,
.preview-content img.img-left {
    float: left;
    max-width: 40%;
    margin: 8px 16px 8px 0;
}

.editor-content img.img-right,
.preview-content img.img-right {
    float: right;
    max-width: 40%;
    margin: 8px 0 8px 16px;
}

.editor-content img.img-inline,
.preview-content img.img-inline {
    display: inline-block;
    max-width: 100%;
    margin: 8px 4px;
    vertical-align: middle;
}

/* Clear floats after paragraphs containing images */
.editor-content p::after,
.preview-content p::after {
    content: "";
    display: table;
    clear: both;
}

/* ===== EDITOR FOOTER ===== */
.editor-footer {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    background: rgba(0,0,0,0.4);
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-muted);
}

/* ===== LIVE PREVIEW ===== */
.preview-content {
    min-height: 400px;
    max-height: 700px;
    overflow-y: auto;
    padding: 20px;
    background: rgba(0,0,0,0.2);
    border-radius: 10px;
    border: 1px solid var(--border);
    font-family: 'Inter', 'Segoe UI', sans-serif;
    font-size: 15px;
    line-height: 1.7;
    color: var(--text);
    word-wrap: break-word;
}

.preview-content h1 {
    font-family: 'Orbitron', monospace;
    font-size: 26px;
    font-weight: 700;
    color: var(--gold);
    margin: 14px 0 8px 0;
}
.preview-content h2 {
    font-family: 'Orbitron', monospace;
    font-size: 20px;
    font-weight: 700;
    color: var(--purple);
    margin: 12px 0 6px 0;
}
.preview-content h3 {
    font-size: 17px;
    font-weight: 700;
    color: var(--text);
    margin: 10px 0 4px 0;
}
.preview-content p { margin: 8px 0; }
.preview-content ul, .preview-content ol { padding-left: 24px; margin: 8px 0; }
.preview-content blockquote {
    border-left: 3px solid var(--gold);
    padding: 8px 16px;
    margin: 12px 0;
    background: rgba(245,158,11,0.05);
    border-radius: 0 6px 6px 0;
    color: var(--text-muted);
    font-style: italic;
}
.preview-content pre, .preview-content code {
    font-family: 'JetBrains Mono', monospace;
    background: rgba(0,0,0,0.5);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 2px 6px;
    font-size: 0.9em;
    color: var(--success);
}
.preview-content pre {
    padding: 12px 16px;
    overflow-x: auto;
    display: block;
    margin: 12px 0;
}
.preview-content a { color: var(--purple); text-decoration: underline; }
.preview-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 12px 0;
    border: 1px solid var(--border);
}
.preview-content hr {
    border: none;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--purple), transparent);
    margin: 20px 0;
}

/* ===== PREVIEW MODAL ===== */
.preview-modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.9);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.3s ease;
}

.preview-modal.show {
    display: flex;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.preview-modal-box {
    background: linear-gradient(135deg, #0a0a1a, #0d1520);
    border: 1px solid var(--purple);
    border-radius: 16px;
    padding: 32px;
    max-width: 800px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 25px 60px rgba(0,0,0,0.8);
}

.preview-close {
    position: absolute;
    top: 16px;
    right: 20px;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 22px;
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}

.preview-close:hover {
    border-color: var(--gold);
    color: var(--gold);
    transform: rotate(90deg);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .toolbar {
        padding: 8px 10px;
        gap: 3px 8px;
    }
    .toolbar-group {
        padding-right: 8px;
        border-right: none;
    }
    .toolbar-label { display: none; }
    .toolbar button { min-width: 28px; height: 28px; font-size: 11px; padding: 4px 6px; }
    .toolbar select { font-size: 11px; padding: 4px 6px; height: 28px; }
    .editor-content { min-height: 300px; padding: 16px; font-size: 14px; }
    .editor-content h1 { font-size: 22px; }
    .editor-content h2 { font-size: 18px; }
    .editor-content h3 { font-size: 16px; }
    .template-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
    .toolbar button { min-width: 26px; height: 26px; font-size: 10px; padding: 3px 5px; }
    .template-grid { grid-template-columns: 1fr; }
}
