/* ===========================================
   Bot Setup (projects/content/edit.html, preview_partial.html): one content type per
   tab, its editor card and its version history; also the Community rules editor
   reached from Protection. Page head, tabs, cards, buttons, badges and menus are the
   global v6 pieces (primitives.css, page-tabs.css, cards.css, forms.css, badges.css);
   only the page's own layout lives here.
   =========================================== */

/* Two columns: the editor, and a 320px side column (version history). */
.bs-detail {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: var(--gap);
    align-items: start;
    margin-top: var(--gap);
}
.bs-col { display: flex; flex-direction: column; gap: var(--gap); min-width: 0; }

/* AI mark on a tab */
.bs-ai-ico { color: var(--ai); }

/* Community rules: "Protection › AI rules" above the title */
.bs-crumb { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 6px; font-size: 12px; color: var(--label-3); }
.bs-crumb a { color: var(--label-2); text-decoration: none; }
.bs-crumb a:hover { color: var(--label-1); }

/* ---- Editor card ---- */
.bs-editor { margin: 0; }
.ed-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.ed-head .card-name { display: flex; align-items: center; gap: 6px; }
.ed-tip { margin: 6px 0 0; font-size: 12px; line-height: 1.5; color: var(--label-3); }
/* Saved · date (or "Not written yet"); the footer says "Unsaved changes" instead while editing. */
.ed-state { flex-shrink: 0; margin-top: 2px; font-size: 12px; color: var(--label-3); white-space: nowrap; }
.ed-state-req { color: var(--amber); }
.bs-editor.dirty .ed-state { visibility: hidden; }

.ed-area,
.ed-area:is(:focus, [readonly]) {
    display: block;
    width: 100%;
    min-height: 420px;
    margin: 0;
    padding: 14px 16px;
    resize: vertical;
    border: 1px solid var(--hairline);
    border-radius: var(--r-md);
    background: var(--bg);
    color: var(--label-body);
    font: 400 13px/1.7 var(--font-mono);
    box-shadow: none;
}
.ed-area:focus { border-color: var(--accent); outline: none; }
.ed-area::placeholder { color: var(--label-3); }

/* "Start from" cards: one click loads a template; the one matching the text is checked. */
.bs-presets { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.bs-preset-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.bs-preset {
    position: relative;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 0;
    padding: 9px 12px;
    border: 1px solid var(--hairline);
    border-radius: var(--r-md);
    background: transparent;
    box-shadow: none;
    color: var(--label-2);
    font-size: 13px;
    text-align: left;
    transition: border-color 0.18s ease, background-color 0.18s ease;
}
.bs-preset:hover { border-color: var(--line-strong); background: transparent; }
.bs-preset:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.bs-preset b { font-weight: 500; color: var(--label-2); }
.bs-preset span { font-size: 12px; font-weight: 400; line-height: 1.35; color: var(--label-3); }
.bs-preset:hover b { color: var(--label-1); }
.bs-preset.is-on { padding-right: 36px; border-color: var(--sel-line); background: var(--sel-bg); }
.bs-preset.is-on b { font-weight: 600; color: var(--label-1); }
.bs-preset.is-on span { color: var(--label-2); }
.bs-preset.is-on::after {
    content: '✓';
    position: absolute; top: 50%; right: 10px; transform: translateY(-50%);
    display: grid; place-items: center; width: 18px; height: 18px; border-radius: 50%;
    background: var(--label-1); color: var(--bg); font-size: 11px; font-weight: 700;
}

/* Footer: Unsaved changes · length on the left, Discard + Save on the right. The one Save
   of the view (no floating bar); bindDirtyForm toggles .show while there are edits. */
.ed-foot { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 12px; color: var(--label-3); }
.ed-foot .btn { flex-shrink: 0; margin: 0; white-space: nowrap; }
.ed-foot .btn:disabled { opacity: 0.4; cursor: default; }
.ed-dirty { display: inline-flex; align-items: center; gap: 6px; color: var(--amber); font-weight: 500; white-space: nowrap; }
.ed-dirty::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--amber); }
.ed-dirty::after { content: '·'; margin-left: 2px; color: var(--label-3); font-weight: 400; }
.ed-foot:not(.show) .ed-dirty { display: none; }

/* ---- Version history ---- */
.ver-head { display: flex; align-items: center; gap: 8px; }
.ver-hint { margin: 8px 0 0; font-size: 12px; line-height: 1.55; color: var(--label-2); }
.ver-list { margin-top: 8px; }
.ver { position: relative; display: flex; align-items: flex-start; gap: 10px; margin: 0 -10px; padding: 10px; border-radius: var(--r-md); }
.ver + .ver { margin-top: 2px; }
.ver.is-loadable { cursor: pointer; }
.ver.is-on,
.ver.is-loadable:hover,
.ver:has(.popover.open) { background: var(--fill-1); }
.ver-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ver-main b { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; color: var(--label-1); }
.ver-main > span { font-size: 11.5px; color: var(--label-3); }
.ver > .btn,
.ver > .row-menu { flex-shrink: 0; }
.ver .row-menu > .popover { min-width: 290px; }
.ver .pop-item { white-space: nowrap; }
.ver form { display: contents; }

/* ---- Preview dialog ---- */
.bs-preview #preview-content { max-height: 60vh; overflow-y: auto; }
.ver-preview {
    margin: 0;
    padding: 14px 16px;
    border: 1px solid var(--hairline);
    border-radius: var(--r-md);
    background: var(--bg);
    color: var(--label-body);
    font: 400 13px/1.7 var(--font-mono);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

@media (max-width: 1000px) {
    .bs-detail { grid-template-columns: 1fr; }
    .ed-area { min-height: 300px; }
}

@media (max-width: 560px) {
    .ed-head { flex-wrap: wrap; }
    .ed-foot { flex-wrap: wrap; }
    .ed-foot .grow { flex-basis: 100%; height: 0; }
}
