/*
 * Help Manual viewer theme. All rules are scoped under .cw-help so the library never bleeds into the
 * host app's styles. Hosts re-theme by overriding the --help-* custom properties on .cw-help.
 */
.cw-help {
    --help-font: inherit;
    --help-fg: #1f2933;
    --help-muted: #6b7785;
    --help-bg: #ffffff;
    --help-sidebar-bg: #f7f9fb;
    --help-border: #e1e6eb;
    --help-accent: #2563eb;
    --help-accent-fg: #ffffff;
    --help-active-bg: #e8effd;
    --help-radius: 6px;
    --help-tag-bg: #eef1f4;
    --help-deprecated-bg: #fff7e6;
    --help-deprecated-fg: #8a5a00;
    --help-gap: 1rem;

    color: var(--help-fg);
    font-family: var(--help-font);
}

.cw-help-layout {
    display: flex;
    gap: 0;
    align-items: flex-start;
}

.cw-help-sidebar {
    flex: 0 0 18rem;
    min-width: 160px;
    max-width: 55vw;
    background: var(--help-sidebar-bg);
    border: 1px solid var(--help-border);
    border-radius: var(--help-radius);
    padding: 0.75rem;
    max-height: 80vh;
    overflow: auto;
}

.cw-help-resize-handle {
    flex: 0 0 10px;
    align-self: stretch;
    cursor: col-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 1;
}

.cw-help-resize-handle::after {
    content: '';
    display: block;
    width: 3px;
    height: 100%;
    min-height: 2rem;
    background: var(--help-border);
    border-radius: 2px;
    transition: background 0.15s, width 0.15s;
}

.cw-help-resize-handle:hover::after,
.cw-help-resize-handle:active::after {
    width: 4px;
    background: var(--help-accent);
}

.cw-help-content {
    flex: 1 1 auto;
    min-width: 0;
    margin-left: var(--help-gap);
}

.cw-help-search {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 0.75rem;
}

.cw-help-search-input {
    flex: 1 1 auto;
    border: 1px solid var(--help-border);
    border-radius: var(--help-radius);
    padding: 0.35rem 0.5rem;
}

.cw-help-tree,
.cw-help-articles,
.cw-help-subfolders,
.cw-help-search-results ul {
    list-style: none;
    margin: 0;
    padding-left: 0.75rem;
}

.cw-help-tree { padding-left: 0; }

.cw-help-folder-title {
    font-weight: 600;
    margin: 0.5rem 0 0.25rem;
}

/* collapsible authoring tree */
.cw-help-folder-row { display: flex; align-items: center; gap: 0.25rem; }
.cw-help-folder-toggle {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    padding: 0.25rem 0.3rem;
    border-radius: var(--help-radius);
    color: var(--help-fg);
    font-weight: 600;
}
.cw-help-folder-toggle:hover { background: var(--help-active-bg); }
.cw-help-folder-toggle > .fa-chevron-right,
.cw-help-folder-toggle > .fa-chevron-down { width: 0.8em; color: var(--help-muted); }
.cw-help-chevron-leaf { width: 0.8em; color: var(--help-muted); opacity: 0.6; }
.cw-help-folder-name { flex: 1 1 auto; }
.cw-help-folder-add { flex: 0 0 auto; }

.cw-help-article-link {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    border-radius: var(--help-radius);
    padding: 0.3rem 0.5rem;
    color: var(--help-fg);
    cursor: pointer;
}

.cw-help-article-link:hover { background: var(--help-active-bg); }
.cw-help-article-link.active { background: var(--help-active-bg); color: var(--help-accent); font-weight: 600; }

.cw-help-result-title { display: block; font-weight: 600; }
.cw-help-result-snippet { display: block; font-size: 0.85em; color: var(--help-muted); }

.cw-help-search-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85em;
    color: var(--help-muted);
    margin-bottom: 0.25rem;
}

.cw-help-btn {
    border: 1px solid var(--help-border);
    background: var(--help-bg);
    border-radius: var(--help-radius);
    padding: 0.35rem 0.6rem;
    cursor: pointer;
}

.cw-help-btn:hover { background: var(--help-active-bg); }

.cw-help-link {
    background: none;
    border: none;
    color: var(--help-accent);
    cursor: pointer;
    padding: 0;
}

.cw-help-article-title { margin: 0 0 0.25rem; }
.cw-help-article-meta { color: var(--help-muted); font-size: 0.85em; margin-bottom: 0.75rem; }

.cw-help-tags { margin-bottom: 0.75rem; }
.cw-help-tag {
    display: inline-block;
    background: var(--help-tag-bg);
    border-radius: 999px;
    padding: 0.1rem 0.6rem;
    font-size: 0.8em;
    margin-right: 0.25rem;
}

.cw-help-article-body img,
.cw-help-editor-surface img { max-width: 100%; height: auto; }

/* image preset sizes (set via the editor's S/M/L/Full buttons; sanitizer-safe class, not inline style) */
.cw-help img.cw-help-img-sm { width: 25%; height: auto; }
.cw-help img.cw-help-img-md { width: 50%; height: auto; }
.cw-help img.cw-help-img-lg { width: 75%; height: auto; }
.cw-help-article-body table { border-collapse: collapse; }
.cw-help-article-body th,
.cw-help-article-body td { border: 1px solid var(--help-border); padding: 0.4rem 0.6rem; }

.cw-help-banner {
    border-radius: var(--help-radius);
    padding: 0.6rem 0.8rem;
    margin-bottom: 0.75rem;
}
.cw-help-banner-deprecated { background: var(--help-deprecated-bg); color: var(--help-deprecated-fg); }
.cw-help-banner-recovery { background: #eef4ff; color: #1f3a8a; display: flex; gap: 0.5rem; align-items: center; }

.cw-help-feedback {
    margin-top: 1.5rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--help-border);
    display: flex;
    gap: 0.5rem;
    align-items: center;
}
.cw-help-feedback-prompt { color: var(--help-muted); }

.cw-help-loading,
.cw-help-empty { color: var(--help-muted); padding: 1rem; }

/* busy overlay (CmpBusySection) */
.cw-help-busy-host { position: relative; }
.cw-help-busy-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.6);
    z-index: 20;
    min-height: 3rem;
}
.cw-help-busy-box {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 1rem;
    background: var(--help-bg);
    color: var(--help-fg);
    border: 1px solid var(--help-border);
    border-radius: var(--help-radius);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    font-size: 0.95rem;
}
.cw-help-busy-box .fa-spinner { color: var(--help-accent); }

/* sidebar toolbar (reorder toggle, expand/collapse all, add root folder) */
.cw-help-toolbar { display: inline-flex; gap: 0.25rem; }
.cw-help-toolbar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2rem;
    height: 2rem;
    padding: 0 0.5rem;
    border: 1px solid var(--help-border);
    border-radius: var(--help-radius);
    background: var(--help-bg);
    cursor: pointer;
}
.cw-help-toolbar-btn:hover { background: var(--help-active-bg); }
.cw-help-toolbar-btn.active { color: var(--help-accent); border-color: var(--help-accent); }

/* reorder arrows (only shown in reorder mode), stacked before the title */
.cw-help-reorder { display: inline-flex; flex-direction: column; line-height: 0.8; margin-right: 0.35rem; }
.cw-help-reorder-btn { padding: 0 0.15rem; font-size: 0.72rem; }
.cw-help-reorder-btn[disabled] { opacity: 0.3; cursor: default; }
.cw-help-article-row { display: flex; align-items: center; }

/* context menu (kebab / right-click) */
.cw-help-menu-anchor { position: relative; display: inline-flex; }
.cw-help-kebab { padding: 0 0.4rem; }
.cw-help-menu {
    position: fixed;
    z-index: 1010;
    min-width: 12rem;
    background: var(--help-bg);
    border: 1px solid var(--help-border);
    border-radius: var(--help-radius);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
    padding: 0.25rem;
    display: flex;
    flex-direction: column;
}
.cw-help-menu-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    padding: 0.4rem 0.6rem;
    border-radius: var(--help-radius);
    color: var(--help-fg);
    text-decoration: none;
    cursor: pointer;
    font-size: 0.9rem;
}
.cw-help-menu-item:hover { background: var(--help-active-bg); }
.cw-help-menu-danger { color: #b42318; }
.cw-help-menu-sep { height: 1px; background: var(--help-border); margin: 0.25rem 0; }
.cw-help-menu-backdrop { position: fixed; inset: 0; z-index: 1005; background: transparent; }

/* modal (import / delete dialogs) */
.cw-help-modal-backdrop {
    position: fixed; inset: 0; z-index: 1000;
    background: rgba(0, 0, 0, 0.4);
    display: flex; align-items: center; justify-content: center;
}
.cw-help-modal {
    background: var(--help-bg); color: var(--help-fg);
    border-radius: var(--help-radius);
    padding: 1.25rem; max-width: 28rem; width: 90%;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
}
.cw-help-modal-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-top: 1rem; }
.cw-help-muted { color: var(--help-muted); }
.cw-help-alert-danger { background: #fef3f2; color: #b42318; border: 1px solid #fecdca; border-radius: var(--help-radius); padding: 0.5rem 0.75rem; margin: 0.5rem 0; }
.cw-help-btn-danger { background: #b42318; color: #fff; border-color: #b42318; }

/* contextual help */
.cw-help-context { position: relative; display: inline-block; }
.cw-help-context-btn {
    background: none;
    border: none;
    color: var(--help-accent);
    cursor: pointer;
}
.cw-help-context-panel {
    position: absolute;
    z-index: 1050;
    top: 1.5rem;
    right: 0;
    width: 24rem;
    max-width: 90vw;
    max-height: 70vh;
    overflow: auto;
    background: var(--help-bg);
    border: 1px solid var(--help-border);
    border-radius: var(--help-radius);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    padding: 0.75rem;
}
.cw-help-context-panel-head { display: flex; justify-content: flex-end; }

/* modal (audit & publish) */
.cw-help-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 6vh;
    z-index: 1100;
}
.cw-help-modal {
    background: var(--help-bg);
    border-radius: var(--help-radius);
    width: 42rem;
    max-width: 92vw;
    max-height: 85vh;
    overflow: auto;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
.cw-help-modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--help-border);
}
.cw-help-modal-head h2 { margin: 0; font-size: 1.1rem; }
.cw-help-modal-body { padding: 1rem; }

/* editor */
.cw-help-editor {
    border: 1px solid var(--help-border);
    border-radius: var(--help-radius);
    overflow: hidden;
}
.cw-help-editor-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.2rem;
    align-items: center;
    padding: 0.35rem;
    background: var(--help-sidebar-bg);
    border-bottom: 1px solid var(--help-border);
}
.cw-help-editor-toolbar .cw-help-btn { padding: 0.25rem 0.5rem; min-width: 2rem; }
.cw-help-toolbar-sep { width: 1px; align-self: stretch; background: var(--help-border); margin: 0 0.25rem; }
.cw-help-toolbar-label { font-size: 0.8em; color: var(--help-muted); padding: 0 0.15rem; }
.cw-help-editor-surface { padding: 0.75rem; min-height: 12rem; }
.cw-help-editor-surface .ProseMirror { outline: none; min-height: 11rem; }
.cw-help-editor-surface div[data-callout] {
    border-left: 4px solid var(--help-accent);
    background: var(--help-active-bg);
    padding: 0.5rem 0.75rem;
    border-radius: var(--help-radius);
    margin: 0.5rem 0;
}
.cw-help-editor-surface div[data-callout="warning"] { border-left-color: var(--help-deprecated-fg); background: var(--help-deprecated-bg); }

/* authoring badges + forms */
.cw-help-badge {
    display: inline-block;
    font-size: 0.7em;
    padding: 0.05rem 0.4rem;
    border-radius: 999px;
    margin-left: 0.35rem;
    background: var(--help-tag-bg);
    color: var(--help-muted);
    vertical-align: middle;
}
.cw-help-badge-published { background: #e3f5e8; color: #1b7a3d; }
.cw-help-badge-draft { background: #eef1f4; color: #6b7785; }
.cw-help-badge-hidden { background: #f0e6f5; color: #6a3d8a; }
.cw-help-badge-deprecated { background: var(--help-deprecated-bg); color: var(--help-deprecated-fg); }
.cw-help-badge-review { background: #fdf0e3; color: #9a5a00; }
.cw-help-badge-scope { background: var(--help-active-bg); color: var(--help-accent); }

.cw-help-sidebar-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.cw-help-inline-form { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; margin: 0.5rem 0; }
.cw-help-edit-head { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.5rem; }
.cw-help-title-input { flex: 1 1 auto; font-size: 1.25rem; font-weight: 600; border: 1px solid var(--help-border); border-radius: var(--help-radius); padding: 0.35rem 0.5rem; }
.cw-help-edit-actions { display: flex; justify-content: space-between; align-items: center; gap: 0.6rem; flex-wrap: wrap; margin: 0.5rem 0; }
.cw-help-actions-left { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; }
.cw-help-actions-right { display: flex; gap: 0.5rem; align-items: center; margin-left: auto; }
.cw-help-btn-primary { background: var(--help-accent); color: var(--help-accent-fg); border-color: var(--help-accent); }
.cw-help-btn-primary:hover { background: var(--help-accent); filter: brightness(0.93); }
.cw-help-save-msg { color: var(--help-muted); }
.cw-help-dirty { color: #b32424; font-size: 0.85em; font-weight: 600; }
.cw-help-publish-panel { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--help-border); }

/* tags (left) + help keys (right) share one row, stacking to two rows when too narrow */
.cw-help-meta-row { display: flex; flex-wrap: wrap; gap: 0.4rem 1.5rem; align-items: flex-start; margin: 0.5rem 0; }
.cw-help-meta-row > .cw-help-tags-edit { flex: 1 1 280px; min-width: 0; margin: 0; }

.cw-help-tags-edit { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; margin: 0.5rem 0; }
.cw-help-tags-label { color: var(--help-muted); font-size: 0.9em; }
.cw-help-tag-remove {
    background: none; border: none; cursor: pointer; color: var(--help-muted);
    padding: 0 0 0 0.25rem; font-weight: 700; line-height: 1;
}
.cw-help-tag-remove:hover { color: #b32424; }
.cw-help-tag-input { border: 1px solid var(--help-border); border-radius: var(--help-radius); padding: 0.2rem 0.45rem; min-width: 9rem; }
.cw-help-audit-blockers { color: #b32424; }
.cw-help-audit-warnings { color: var(--help-deprecated-fg); }
.cw-help-audit-ok { color: #1b7a3d; }
