/* ============================================================
   EDIT-MODE.CSS  —  regulasiku.id
   Admin-only "Mode Edit" toggle + per-leaf pencil/editor UI.
   Reuses the site's existing visual language (account.css's pill
   button and form card, perubahan.css's small rounded toolbar
   buttons) rather than inventing a new one.
   ============================================================ */

#edit-mode-toggle {
    background: none;
    border: 1px solid #cbd5e1;
    border-radius: 999px;
    padding: 0.4rem 1rem;
    font-size: 0.85rem;
    color: #334155;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

#edit-mode-toggle:hover {
    background-color: #f1f5f9;
    border-color: #94a3b8;
}

#edit-mode-toggle.is-active {
    background-color: #357d90;
    border-color: #357d90;
    color: #ffffff;
}

/* On mobile the header row has no spare width at all (it already sits
   flush at 100% without this button), so the pill can't just shrink —
   it has to leave the header row. Pulled out to a fixed circular FAB
   matching the site's existing #toc-hamburger mobile pattern
   (daftar-isi.css), stacked directly above it. */
@media screen and (max-width: 600px) {
    #edit-mode-toggle {
        position: fixed;
        right: 20px;
        bottom: 90px;
        z-index: 8000;

        display: flex;
        align-items: center;
        justify-content: center;
        width: 48px;
        height: 48px;
        padding: 0;
        border-radius: 50%;
        border: 3px solid #f8fafc;
        background-color: #357d90;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);

        font-size: 0; /* hide the "Mode Edit" text; icon comes from ::before */
        color: transparent;
    }

    #edit-mode-toggle::before {
        /* Plain pencil glyph (no U+FE0F emoji variation selector) so it
           renders as a monochrome text symbol everywhere, instead of
           depending on a color-emoji font being present. Explicit color
           needed since the button itself sets color:transparent to hide
           its "Mode Edit" text content. */
        content: "\270F";
        color: #ffffff;
        font-size: 22px;
        line-height: 1;
    }

    #edit-mode-toggle.is-active {
        background-color: #b91c1c;
        border-color: #f8fafc;
    }

    #edit-mode-toggle.is-active::before {
        content: "✕";
        color: #ffffff;
        font-size: 22px;
        font-weight: 700;
    }
}

/* Small round "?" right next to EVERY pencil (see edit-mode.js's
   attachPencils()) — one per editable leaf, not one shared button up at
   the Mode Edit toggle (that was the first version; moved here on
   request so help is reachable right where an admin is about to use
   it). Same show/hide-with-edit-mode rule as .edit-pencil-btn itself,
   just below — no reason for the help icon to be visible when there's
   nothing yet to edit. */
.edit-help-btn-inline {
    display: none;
    width: 1.3rem;
    height: 1.3rem;
    margin-left: 2px;
    padding: 0;
    border: 1px solid #cbd5e1;
    border-radius: 50%;
    background: none;
    color: #334155;
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    vertical-align: middle;
    opacity: 0.7;
    transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.edit-help-btn-inline:hover {
    background-color: #f1f5f9;
    border-color: #94a3b8;
    opacity: 1;
}

body.edit-mode-active .edit-help-btn-inline {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Modal: hidden by default, centered card over a dimmed backdrop. Uses
   the same show/hide-via-class pattern as .riwayat-perubahan's
   versi-lama pill and auth.js's #upgrade-nudge, rather than <dialog>,
   to stay consistent with the rest of the codebase. */
#format-help-modal {
    display: none;
}

#format-help-modal.is-open {
    display: block;
}

.format-help-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 9000;
}

.format-help-card {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 9001;
    width: min(560px, 92vw);
    max-height: 85vh;
    overflow-y: auto;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
    padding: 1.5rem;
    font-size: 0.9rem;
    line-height: 1.5;
    color: #1e293b;
}

.format-help-card h3 {
    margin: 0 0 0.5rem;
    font-size: 1.1rem;
}

.format-help-card h4 {
    margin: 1.1rem 0 0.3rem;
    font-size: 0.95rem;
    color: #357d90;
}

.format-help-card p {
    margin: 0.4rem 0;
}

.format-help-card ul {
    margin: 0.3rem 0;
    padding-left: 1.3rem;
}

.format-help-card li {
    margin-bottom: 0.25rem;
}

.format-help-card code {
    background: #f1f5f9;
    border-radius: 4px;
    padding: 0.1rem 0.35rem;
    font-size: 0.85em;
}

.format-help-card pre {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 0.6rem 0.8rem;
    margin: 0.4rem 0;
    font-size: 0.8rem;
    white-space: pre-wrap;
    overflow-wrap: break-word;
}

.format-help-close {
    position: absolute;
    top: 0.8rem;
    right: 0.8rem;
    background: none;
    border: none;
    font-size: 1rem;
    color: #64748b;
    cursor: pointer;
    padding: 0.2rem;
}

.format-help-close:hover {
    color: #1e293b;
}

/* Pencils are always in the DOM (attached once, reused on toggle) but
   hidden until edit mode is switched on. */
.edit-pencil-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0 4px;
    vertical-align: middle;
    opacity: 0.7;
}

.edit-pencil-btn:hover {
    opacity: 1;
}

body.edit-mode-active .edit-pencil-btn {
    display: inline;
}

body.edit-mode-active .editable-content:hover {
    outline: 1px dashed #357d90;
    outline-offset: 2px;
    cursor: text;
}

.edit-mode-editor {
    display: block;
    margin: 0.4rem 0;
    padding: 0.75rem;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.edit-mode-editor textarea {
    display: block;
    width: 100%;
    box-sizing: border-box;
    font-size: 0.9rem;
    font-family: inherit;
    padding: 0.5rem 0.7rem;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    outline: none;
    resize: vertical;
}

.edit-mode-editor textarea:focus {
    border-color: #357d90;
}

.edit-mode-toolbar {
    display: flex;
    gap: 0.4rem;
    margin-top: 0.5rem;
}

.edit-mode-toolbar-btn {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    font-size: 0.75rem;
    font-weight: 600;
    font-family: sans-serif;
    border-radius: 999px;
    border: 1px solid currentColor;
    background: rgba(255, 255, 255, 0.5);
    color: #357d90;
    cursor: pointer;
}

.edit-mode-toolbar-btn:hover {
    background: rgba(53, 125, 144, 0.1);
}

.edit-mode-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 0.6rem;
}

.edit-mode-save-btn {
    background-color: #357d90;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 0.4rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.edit-mode-save-btn:hover {
    background-color: #2a6474;
}

.edit-mode-save-btn:disabled,
.edit-mode-cancel-btn:disabled,
.edit-mode-toolbar-btn:disabled {
    opacity: 0.5;
    cursor: default;
}

.edit-mode-cancel-btn {
    background: none;
    border: none;
    color: #64748b;
    font-size: 0.85rem;
    cursor: pointer;
}

.edit-mode-error {
    margin: 0.4rem 0 0;
    color: #b91c1c;
    font-size: 0.8rem;
}
