/* ==========================================================================
   Markdown Editor - Stilark
   Bruker CSS-variabler fra style.css for dark/light mode
   ========================================================================== */

/* Editor wrapper */
.md-editor {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--card2);
}

/* When inside a modal the textarea already has border/radius – remove it */
.md-editor .md-editor__textarea {
    border: none;
    border-radius: 0;
    outline: none;
}

.md-editor .md-editor__textarea:focus {
    border: none;
    box-shadow: none;
}

/* Focus ring on wrapper instead */
.md-editor:focus-within {
    border-color: var(--accent);
}

/* Toolbar */
.md-editor__toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    padding: var(--space-xs) var(--space-sm);
    background: var(--card);
    border-bottom: 1px solid var(--line);
    user-select: none;
}

.md-editor__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 var(--space-sm);
    font-size: var(--font-size-sm);
    font-family: inherit;
    font-weight: 600;
    color: var(--muted);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-xs);
    cursor: pointer;
    transition: all var(--transition-fast);
    line-height: 1;
}

.md-editor__btn:hover {
    color: var(--text);
    background: var(--card2);
    border-color: var(--line);
}

.md-editor__btn--active {
    color: var(--accent);
    background: rgba(var(--accent-rgb, 99, 102, 241), 0.12);
    border-color: var(--accent);
}

.md-editor__sep {
    width: 1px;
    height: 20px;
    background: var(--line);
    margin: 0 var(--space-xs);
    flex-shrink: 0;
}

/* Preview pane */
.md-editor__preview {
    padding: var(--space-md);
    min-height: 120px;
    max-height: 400px;
    overflow-y: auto;
    font-size: var(--font-size-base);
    line-height: 1.7;
    color: var(--text-secondary, var(--muted));
    background: var(--card2);
}

.md-editor__preview h1,
.md-editor__preview h2,
.md-editor__preview h3,
.md-editor__preview h4 {
    color: var(--text);
    margin: var(--space-md) 0 var(--space-sm);
}

.md-editor__preview h1 { font-size: var(--font-size-2xl); }
.md-editor__preview h2 { font-size: var(--font-size-xl); }
.md-editor__preview h3 { font-size: var(--font-size-lg); }
.md-editor__preview h4 { font-size: var(--font-size-base); font-weight: 700; }

.md-editor__preview p {
    margin: 0 0 var(--space-md);
}

.md-editor__preview p:last-child {
    margin-bottom: 0;
}

.md-editor__preview strong {
    color: var(--text);
    font-weight: 700;
}

.md-editor__preview a {
    color: var(--accent);
    text-decoration: underline;
}

.md-editor__preview blockquote {
    margin: var(--space-md) 0;
    padding: var(--space-sm) var(--space-md);
    border-left: 3px solid var(--accent);
    color: var(--muted);
    background: rgba(var(--accent-rgb, 99, 102, 241), 0.05);
    border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
}

.md-editor__preview ul,
.md-editor__preview ol {
    margin: var(--space-sm) 0;
    padding-left: var(--space-xl);
}

.md-editor__preview li {
    margin-bottom: var(--space-xs);
}

.md-editor__preview code {
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.9em;
    padding: 2px 6px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius-xs);
}

/* Post-modal rendered content (for article/concert edit modals) */
.post-modal-body .md-editor {
    margin-top: 0;
}

/* ==========================================================================
   Post Modal - Shared modal styles for edit modals
   (Duplicated from medlemmer.css for pages that don't include it)
   ========================================================================== */
.post-modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 1000;
    padding: var(--space-md);
}

.post-modal[hidden] {
    display: none !important;
}

.post-modal-content {
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: postModalSlideIn 0.2s ease-out;
}

@keyframes postModalSlideIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.post-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
}

.post-modal-header h3 {
    font-size: var(--font-size-lg);
    font-weight: 700;
    color: var(--text);
    margin: 0;
}

.post-modal-close {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--muted);
    transition: all var(--transition-fast);
}

.post-modal-close:hover {
    background: var(--card2);
    color: var(--text);
}

.post-modal-body {
    padding: var(--space-lg);
    overflow-y: auto;
    flex: 1;
}

.post-modal-body .form-group {
    margin-bottom: var(--space-lg);
}

.post-modal-body .form-group:last-child {
    margin-bottom: 0;
}

.post-modal-body label {
    display: block;
    font-weight: 600;
    color: var(--text);
    margin-bottom: var(--space-sm);
    font-size: var(--font-size-sm);
}

.post-modal-body input[type="text"],
.post-modal-body select {
    width: 100%;
    padding: var(--space-md);
    font-size: var(--font-size-base);
    font-family: inherit;
    color: var(--text);
    background: var(--card2);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color var(--transition-fast);
}

.post-modal-body input[type="text"]:focus,
.post-modal-body select:focus {
    border-color: var(--accent);
}

.post-modal-body input[type="text"]::placeholder {
    color: var(--muted);
}

.post-modal-body textarea {
    width: 100%;
    min-height: 120px;
    padding: var(--space-md);
    font-size: var(--font-size-base);
    font-family: inherit;
    color: var(--text);
    background: var(--card2);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    resize: vertical;
    outline: none;
    transition: border-color var(--transition-fast);
}

.post-modal-body textarea:focus {
    border-color: var(--accent);
}

.post-modal-body textarea::placeholder {
    color: var(--muted);
}

.post-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    border-top: 1px solid var(--line);
    flex-shrink: 0;
}

.post-submit-btn {
    padding: var(--space-sm) var(--space-lg);
    font-size: var(--font-size-base);
    font-weight: 600;
    font-family: inherit;
    color: var(--bg);
    background: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.post-submit-btn:hover {
    background: var(--accent-hover);
}

.post-submit-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.post-cancel-btn {
    padding: var(--space-sm) var(--space-lg);
    font-size: var(--font-size-base);
    font-weight: 600;
    font-family: inherit;
    color: var(--muted);
    background: transparent;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.post-cancel-btn:hover {
    color: var(--text);
    border-color: var(--text);
}

/* Edit button shown on cards */
.edit-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-md);
    font-size: var(--font-size-sm);
    font-weight: 600;
    font-family: inherit;
    color: var(--muted);
    background: transparent;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.edit-btn:hover {
    color: var(--text);
    border-color: var(--accent);
}

/* Delete button variant */
.delete-btn {
    color: var(--muted);
    border-color: var(--line);
}

.delete-btn:hover {
    color: #dc2626;
    border-color: #dc2626;
    background: rgba(220, 38, 38, 0.08);
}

/* Delete button in modal footer - left-aligned */
.post-modal-footer .post-delete-btn {
    margin-right: auto;
    padding: var(--space-sm) var(--space-lg);
    font-size: var(--font-size-base);
    font-weight: 600;
    font-family: inherit;
    color: #dc2626;
    background: transparent;
    border: 1px solid #dc2626;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.post-modal-footer .post-delete-btn:hover {
    background: rgba(220, 38, 38, 0.1);
}

/* Admin actions row on cards */
.melding-admin-actions,
.event-card__admin-actions {
    display: flex;
    gap: var(--space-sm);
    padding: 0 0 var(--space-sm);
}

/* Responsive toolbar */
@media (max-width: 480px) {
    .md-editor__toolbar {
        gap: 1px;
        padding: var(--space-xs);
    }

    .md-editor__btn {
        min-width: 28px;
        height: 28px;
        padding: 0 4px;
        font-size: var(--font-size-xs);
    }

    .md-editor__sep {
        height: 16px;
        margin: 0 2px;
    }
}
