/* ============================================================
   SECTIONS
   ============================================================ */

.section-block {
    margin-bottom: 2px;
    position: relative;
    border-radius: var(--radius);
    transition: background var(--dur);
}


.section-inner {
    padding: 12px 20px;
    border-radius: var(--radius);
    transition: background var(--dur);
}
.section-inner:hover { background: var(--doc-hover-subtle); }

.section-header {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 4px;
    margin-bottom: 10px;
}

/* Section header tool buttons (+ insert, ⋯ meta) */
.section-header .insert-fig-header-btn,
.section-header .meta-toggle-btn {
    flex-shrink: 0;
    opacity: 0;
    transition: opacity var(--dur);
    margin-top: 3px;
}
.section-block:hover .insert-fig-header-btn,
.section-block:hover .meta-toggle-btn { opacity: 1; }
.section-block.meta-open .meta-toggle-btn { opacity: 1; }

.section-tool-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px; height: 28px;
    border-radius: var(--radius-xs);
    border: none;
    background: none;
    color: var(--td3);
    cursor: pointer;
    font-size: 10px;
    transition: background var(--dur), color var(--dur);
}
.section-tool-btn:hover { background: var(--doc-hover); color: var(--td1); }

/* Section metadata panel */
.section-meta-panel {
    padding: 4px 0 0;
    margin: 0 0 4px;
    max-height: 200px;
    opacity: 1;
    overflow: hidden;
    transition: max-height 150ms var(--ease), opacity 150ms var(--ease), padding 150ms var(--ease), margin 150ms var(--ease);
}
.section-meta-panel.collapsed {
    max-height: 0;
    opacity: 0;
    padding: 0;
    margin: 0;
    pointer-events: none;
}
.meta-divider {
    height: 2px;
    background: var(--doc-ochre-dim);
    margin-top: 10px;
    margin-bottom: 4px;
}

/* Summary — styled like body text */
.meta-summary-input {
    width: 100%;
    resize: none;
    overflow: hidden;
    border: none;
    background: transparent;
    color: var(--td3);
    font: 14px/1.7 var(--serif);
    font-style: italic;
    padding: 0;
    outline: none;
    box-sizing: border-box;
    min-height: 48px;
    caret-color: var(--accent);
}
.meta-summary-input::placeholder { color: var(--td3); opacity: 0.35; font-style: italic; }
.meta-summary-input:focus { color: var(--td2); }

/* Meta controls row (level picker + reorder + delete) */
.meta-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 8px;
}
.meta-controls-right {
    display: flex;
    align-items: center;
    gap: 2px;
}

/* Level picker — dropdown style */
.meta-level-picker {
    position: relative;
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    transition: background var(--dur);
}
.meta-level-picker:hover { background: var(--doc-hover); }
.meta-level-label {
    font: 12px var(--sans);
    color: var(--td3);
}
.meta-level-picker svg { color: var(--td3); flex-shrink: 0; }
.meta-level-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 150px;
}
.meta-level-menu .dropdown-item.active { background: var(--chrome-hover); color: var(--t1); }
.meta-toggle-btn { font-size: 18px !important; letter-spacing: 2px; }

.section-number {
    position: absolute;
    left: 0;
    top: 0;
    font-family: var(--serif);
    color: var(--doc-ochre);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.section-number[data-level="1"] { font-size: 26px; font-weight: 300; line-height: 1.25; }
.section-number[data-level="2"] { font-size: 23px; font-weight: 300; line-height: 1.3; }
.section-number[data-level="3"] { font-size: 20px; font-weight: 300; line-height: 1.35; }

.section-title-input {
    font-family: var(--serif);
    color: var(--td1);
    flex: 1;
    min-width: 0;
    border: none;
    background: none;
    outline: none;
    padding: 0;
    caret-color: var(--accent);
    resize: none;
    overflow: hidden;
}
.section-title-input::placeholder { color: var(--td3); opacity: 0.5; }
.section-title-input:focus { color: var(--td1); }

.section-title-input[data-level="1"] { font-size: 26px; font-weight: 300; line-height: 1.25; letter-spacing: -0.3px; text-indent: 36px; }
.section-title-input[data-level="2"] { font-size: 23px; font-weight: 300; line-height: 1.3; color: var(--td1); text-indent: 48px; }
.section-title-input[data-level="3"] { font-size: 20px; font-weight: 300; line-height: 1.35; color: var(--td1); text-indent: 56px; }

.section-body-input {
    font: 16px/1.82 var(--serif);
    color: var(--td2b);
    background: none;
    border: none;
    outline: none;
    width: 100%;
    padding: 0;
    white-space: pre-wrap;
    word-wrap: break-word;
    caret-color: var(--accent);
    resize: none;
    overflow: hidden;
    min-height: 28px;
}
.section-body-input::placeholder { color: var(--td3); opacity: 0.4; font-style: italic; }
.section-body-input:focus { color: var(--td2); }

/* Read-only body (for rendered content with citations) */
.section-body {
    font: 16px/1.82 var(--serif);
    color: var(--td2b);
    white-space: pre-wrap;
    word-wrap: break-word;
    cursor: text;
}
.section-body p { margin-bottom: 16px; }
.section-body p:last-child { margin-bottom: 0; }
.section-body.editing { outline: none; caret-color: var(--accent); }
.section-body:empty::before {
    content: 'Start writing...';
    color: var(--td3);
    opacity: 0.4;
    font-style: italic;
}


/* ---- Add section buttons ---- */
.add-row {
    position: relative;
    height: 22px;
    margin: 0;
    z-index: var(--z-section);
}
.previewing .add-row { visibility: hidden; }
.preview-section-spacer { height: 28px; }
.add-row.first-visible {
    height: auto;
    margin: 0 0 12px;
}

.add-line { display: none; }

/* buttons float over the gap, hidden until hover */
.add-row .add-btns {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    gap: 6px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 150ms;
}
.add-row:hover .add-btns {
    opacity: 1;
    pointer-events: auto;
}

/* first-visible row is always shown, static layout */
.add-row.first-visible .add-btns {
    position: static;
    transform: none;
    opacity: 1;
    pointer-events: auto;
    justify-content: center;
    padding: 0;
}

.add-section-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: 1px solid var(--td3);
    color: var(--td3);
    font: 500 12px var(--sans);
    padding: 5px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--dur) var(--ease);
    white-space: nowrap;
}
.add-section-btn:hover {
    border-color: var(--doc-ochre);
    color: var(--doc-ochre);
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.add-row.first-visible .add-section-btn {
    padding: 8px 18px;
    font-size: var(--fs-base);
    font-weight: 600;
    gap: 7px;
}
.add-row.first-visible .add-section-btn:hover {
    border-color: var(--doc-ochre);
    color: var(--doc-ochre);
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

/* ---- Delete section confirm ---- */
.section-delete-confirm {
    position: absolute;
    top: 0; right: 0;
    background: var(--chrome-bg2);
    border: 1px solid var(--chrome-border);
    border-radius: var(--radius);
    padding: 10px 14px;
    z-index: var(--z-sticky);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: var(--fs-sm);
    color: var(--t2);
}
