/**
 * Forum Markdown Editor
 *
 * Tabbed editor component with Write/Preview toggle, formatting toolbar,
 * monospace textarea for markdown input, and a live preview pane that
 * renders formatted markdown output.
 *
 * @package PC_Kompas_Forum
 */

/* ============================================================================
   EDITOR CONTAINER
   ============================================================================ */

.forum-editor {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--bg-primary);
}

/* ============================================================================
   TABS — Write / Preview toggle
   ============================================================================ */

.forum-editor__tabs {
    display: flex;
    align-items: stretch;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
}

.forum-editor__tab {
    position: relative;
    padding: clamp(0.5rem, 1.2vw, 0.625rem) clamp(0.875rem, 2vw, 1.25rem);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    font-family: var(--font-display);
    font-size: clamp(0.8125rem, 1vw + 0.2rem, 0.875rem);
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.forum-editor__tab:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.forum-editor__tab--active {
    color: var(--text-primary);
    font-weight: 600;
    border-bottom-color: var(--accent);
    background: var(--bg-primary);
}

.forum-editor__tab:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

/* ============================================================================
   TOOLBAR — Formatting buttons
   ============================================================================ */

.forum-editor__toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 2px;
    padding: clamp(0.25rem, 0.8vw, 0.375rem) clamp(0.5rem, 1vw, 0.75rem);
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
}

.forum-editor__tool {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.15s ease, background-color 0.15s ease;
}

.forum-editor__tool:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.forum-editor__tool:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.forum-editor__tool svg {
    width: 16px;
    height: 16px;
}

/* Vertical separator between tool groups */
.forum-editor__separator {
    width: 1px;
    height: 18px;
    margin: 0 clamp(0.25rem, 0.5vw, 0.375rem);
    background: var(--border);
    flex-shrink: 0;
}

/* ============================================================================
   TEXTAREA — Markdown input
   ============================================================================ */

.forum-editor__textarea {
    display: block;
    width: 100%;
    min-height: clamp(180px, 25vw, 280px);
    padding: clamp(0.75rem, 2vw, 1rem);
    background: var(--bg-primary);
    border: none;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: clamp(0.8125rem, 0.9vw + 0.25rem, 0.9375rem);
    line-height: 1.6;
    resize: vertical;
    transition: box-shadow 0.15s ease;
}

.forum-editor__textarea::placeholder {
    color: var(--text-muted);
}

.forum-editor__textarea:focus {
    outline: none;
    box-shadow: inset 0 0 0 2px var(--accent-light);
}

/* ============================================================================
   FOOTER — Markdown hint
   ============================================================================ */

.forum-editor__footer {
    display: flex;
    align-items: center;
    padding: clamp(0.375rem, 0.8vw, 0.5rem) clamp(0.75rem, 1.5vw, 1rem);
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
}

.forum-editor__hint {
    font-size: clamp(0.6875rem, 0.8vw + 0.2rem, 0.75rem);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.35em;
}

.forum-editor__hint svg {
    width: 14px;
    height: 14px;
    opacity: 0.6;
}

/* ============================================================================
   PREVIEW PANE — Rendered markdown output
   ============================================================================ */

.forum-editor__preview {
    min-height: clamp(180px, 25vw, 280px);
    padding: clamp(0.75rem, 2vw, 1rem);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: clamp(0.9375rem, 1vw + 0.25rem, 1rem);
    line-height: 1.7;
    word-break: break-word;
    overflow-wrap: anywhere;
}

/* Empty preview placeholder */
.forum-editor__preview-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: clamp(180px, 25vw, 280px);
    color: var(--text-muted);
    font-size: clamp(0.8125rem, 1vw + 0.2rem, 0.875rem);
    font-style: italic;
}

/* ============================================================================
   PREVIEW — Markdown rendered content
   ============================================================================ */

.forum-editor__preview p {
    margin: 0.75em 0;
}

.forum-editor__preview > :first-child {
    margin-top: 0;
}

.forum-editor__preview > :last-child {
    margin-bottom: 0;
}

.forum-editor__preview h2,
.forum-editor__preview h3,
.forum-editor__preview h4 {
    margin: 1.5em 0 0.5em;
    color: var(--text-primary);
    line-height: 1.3;
}

.forum-editor__preview h2 {
    font-size: 1.25rem;
}

.forum-editor__preview h3 {
    font-size: 1.125rem;
}

.forum-editor__preview h4 {
    font-size: 1rem;
}

/* Code blocks */
.forum-editor__preview pre {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: clamp(0.75rem, 2vw, 1rem);
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: clamp(0.8125rem, 0.9vw + 0.2rem, 0.875rem);
    line-height: 1.6;
    margin: 1em 0;
}

.forum-editor__preview pre code {
    padding: 0;
    background: transparent;
    border-radius: 0;
    font-size: inherit;
}

/* Inline code */
.forum-editor__preview code {
    font-family: var(--font-mono);
    font-size: 0.875em;
}

.forum-editor__preview :not(pre) > code {
    background: var(--bg-secondary);
    padding: 0.15em 0.4em;
    border-radius: var(--radius-sm);
    font-size: 0.875em;
}

/* Blockquotes */
.forum-editor__preview blockquote {
    border-left: 3px solid var(--accent);
    margin: 1em 0;
    padding: 0.5em 1em;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* Lists */
.forum-editor__preview ul,
.forum-editor__preview ol {
    padding-left: 1.5em;
    margin: 0.75em 0;
}

.forum-editor__preview li {
    margin: 0.25em 0;
}

/* Links */
.forum-editor__preview a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: color 0.15s ease;
}

.forum-editor__preview a:hover {
    color: var(--accent-hover);
}

/* Images */
.forum-editor__preview img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-sm);
}
