/* Admin CMS: form controls, dashboard/chapter lists, and the chapter editor.
 * The public pages had no form controls at all, so the field/radio/checkbox
 * primitives below are defined here for the first time — all colours come from
 * the base.css tokens so the CMS re-themes with everything else.
 */

/* Filtered out by the search box / status tabs, and the collapsed schedule row. */
.is-hidden { display: none; }

/* ---------- responsive shell ----------
 * Phone (default): the CMS is a stack of separate pages, matching the Mini App.
 * Desktop (>=900px): the dashboard and chapter list become one two-pane screen
 * with a persistent novel sidebar, per the "Админ · дашборд (ПК)" design. The
 * chapter editor stays full-width on both ("редактор вынесен").
 */

.admin-sidebar { display: none; }

@media (width >= 900px) {
    .admin-body { background: var(--surface); }

    .admin-shell {
        display: flex;
        min-height: 100vh;
        align-items: stretch;
    }

    .admin-sidebar {
        display: flex;
        flex: none;
        flex-direction: column;
        width: 238px;
        padding: 18px 14px;
        background: var(--surface);
        border-right: 1px solid var(--line);
    }

    .admin-pane {
        flex: 1;
        min-width: 0;
        max-width: none;
        padding: 24px 28px;
    }

    /* In the pane head the actions sit inline, not as full-width stacked blocks. */
    .admin-pane .admin-actions {
        margin: 0;
        flex: none;
    }

    .admin-pane .admin-actions .btn { flex: none; }

    /* The editor has no sidebar: writing is a focus mode, and the novel list is
     * navigation you don't need mid-chapter. The bar runs full window width;
     * only the meta/toolbar/prose column below it is capped and centred, per the
     * "Окно редактора (ПК)" design. Reuses the same desktop-container cap as
     * .catalog rather than inventing its own number. */
    .editor-page {
        max-width: none;
        width: 100%;
        padding: 0;
    }

    .editor-page .editor-bar {
        align-items: center;
        gap: 10px;
        padding: 14px 24px;
        margin-bottom: 0;
        border-bottom: 1px solid var(--line);
        background: var(--surface);
    }

    .editor-page > form {
        max-width: var(--measure-wide);
        margin: 0 auto;
        padding: 20px 24px 28px;
    }

    .editor-page .editor-meta > div:not(.editor-meta-title) { width: 6.5rem; }

    .editor-page .editor-publish { margin-top: 14px; }

    /* Toolbar + surface read as one slab: the toolbar is the dark lid, the paper
     * hangs beneath it. Both span the capped column, matching the fields above. */

    .editor-page .toolbar {
        justify-content: center;
        position: sticky;
        top: 0;
        z-index: 2;
        border-color: var(--toolbar-bg);
        background: var(--toolbar-bg);
    }

    .editor-page .toolbar .icon-btn {
        border-color: rgb(255 255 255 / 18%);
        color: var(--toolbar-ink);
    }

    .editor-page .toolbar .icon-btn:hover { background: rgb(255 255 255 / 12%); }

    .editor-page .toolbar .icon-btn.is-active {
        background: rgb(255 255 255 / 16%);
        color: var(--toolbar-ink);
    }

    .editor-page .toolbar-sep { background: rgb(255 255 255 / 20%); }

    /* The footnote popover sits on light --surface even on desktop, so its buttons
     * keep dark ink rather than the toolbar's light ink. */
    .editor-page .toolbar .toolbar-menu-list .icon-btn {
        border-color: var(--line);
        color: var(--ink);
    }

    .editor-page .editor-surface {
        min-height: 55vh;
        padding: 28px 40px;
        background: var(--surface);
        border: 1px solid var(--line);
        border-radius: 12px;
    }

}

/* ---------- form primitives ---------- */

.field {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    color: var(--ink);
    font: inherit;
}

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

textarea.field {
    resize: vertical;
    min-height: 96px;
}

.field-label {
    display: block;
    margin: 16px 0 6px;
    font-size: 13px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink-soft);
}

.field-hint {
    margin: 6px 0 0;
    font-size: 13px;
    color: var(--ink-soft);
}

.radio-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* The native control stays focusable but visually replaced by its pill. */
.radio-pill input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.radio-pill {
    position: relative;
    display: inline-flex;
}

.radio-pill span {
    display: inline-block;
    padding: 8px 14px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    color: var(--ink-soft);
    cursor: pointer;
    font-size: 14px;
}

.radio-pill input:checked + span {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
}

.radio-pill input:focus-visible + span {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 16px 0;
    color: var(--ink-soft);
    font-size: 15px;
    cursor: pointer;
}

/* Same trick as .radio-pill: native control stays focusable, the .checkbox-box
   sibling is what gets drawn. */
.checkbox-row input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.checkbox-box {
    position: relative;
    flex: none;
    width: 20px;
    height: 20px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface);
    transition: background 0.15s ease, border-color 0.15s ease;
}

/* Checkmark: two borders of an empty box, rotated into a tick. */
.checkbox-box::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 6px;
    width: 5px;
    height: 10px;
    border: solid var(--accent-ink);
    border-width: 0 2px 2px 0;
    border-radius: 1px;
    transform: rotate(45deg) scale(0.6);
    opacity: 0;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.checkbox-row input:checked + .checkbox-box {
    background: var(--accent);
    border-color: var(--accent);
}

.checkbox-row input:checked + .checkbox-box::after {
    opacity: 1;
    transform: rotate(45deg) scale(1);
}

.checkbox-row input:focus-visible + .checkbox-box {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.checkbox-row input:checked + .checkbox-box + span {
    color: var(--ink);
}

.admin > .admin-save {
    width: 100%;
    margin-top: 24px;
}

.btn-danger {
    background: transparent;
    border-color: var(--accent);
    color: var(--accent);
    width: 100%;
    margin-top: 24px;
}

.admin > .admin-save + form .btn-danger { margin-top: 12px; }

.admin-error {
    margin: 12px 0;
    padding: 10px 12px;
    border: 1px solid var(--accent);
    border-radius: 10px;
    color: var(--accent);
    background: var(--surface);
    font-size: 14px;
}

/* Save no longer navigates away, so this is the confirmation. Fades out via
 * .is-gone (editor.js) rather than vanishing, so the eye catches it leaving. */
.editor-toast {
    margin: 12px 0;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--ink);
    background: var(--surface);
    font-size: 14px;
    transition: opacity 0.4s ease;
}

.editor-toast.is-gone {
    opacity: 0;
}

/* ---------- dashboard / lists ---------- */

.admin-head,
.admin-form-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.admin-search { margin-bottom: 8px; }

.admin-section-head {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin: 20px 0 10px;
}

.admin-section-title {
    margin: 0;
    font-size: 20px;
}

.admin-count {
    color: var(--ink-soft);
    font-size: 14px;
}

.admin-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.admin-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
}

.admin-row-main {
    flex: 1;
    min-width: 0;
}

.admin-row-title {
    font-size: 16px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.admin-row-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 4px;
    color: var(--ink-soft);
    font-size: 13px;
}
.admin-row-chevron { color: var(--ink-soft); }

/* Chapter rows carry the same content on both form factors, only placed
 * differently — one DOM re-arranged by grid, not a markup fork. Phone: flags sit
 * under the title. Desktop: flags get their own column before the chevron.
 * Must follow the .admin-row-* rules above, whose placement it overrides. */
.admin-chapter-row {
    display: grid;
    grid-template-areas:
        "label title chevron"
        "label meta  chevron";
    grid-template-columns: auto 1fr auto;
    column-gap: 12px;
}

.admin-chapter-row .chapter-label { grid-area: label; }
.admin-chapter-row .admin-row-title { grid-area: title; }
.admin-chapter-row .admin-row-meta { grid-area: meta; }
.admin-chapter-row .admin-row-chevron { grid-area: chevron; }

@media (width >= 900px) {
    .admin-chapter-row {
        grid-template-areas: "label title meta chevron";
        grid-template-columns: auto 1fr auto auto;
        align-items: center;
    }

    .admin-chapter-row .admin-row-meta { margin-top: 0; }
}

.admin-queued { color: var(--olive); }

.admin-draft-flag,
.admin-hidden-flag { color: var(--accent); }

.admin-empty {
    color: var(--ink-soft);
    padding: 16px 0;
}

.admin-novel-title {
    margin: 0 0 6px;
    font-size: 24px;
}

.admin-actions {
    display: flex;
    gap: 8px;
    margin: 16px 0;
}
.admin-actions .btn { flex: 1; }

/* Full-width in the phone stack; the desktop pane un-stretches them above. */
.admin-add {
    width: 100%;
    margin-top: 16px;
}

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}

.tab {
    padding: 6px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: transparent;
    color: var(--ink-soft);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}

.tab.is-active {
    background: var(--tag-bg);
    color: var(--ink);
}

/* ---------- desktop sidebar ---------- */

/* The brand is a link back to the public site; keep it feeling clickable. */
.admin-home {
    margin-bottom: 14px;
    padding: 6px;
    margin-left: -6px;
    border-radius: 10px;
}
.admin-home:hover { background: var(--bg); }

.admin-sidebar .admin-search { margin-bottom: 12px; }

.admin-section-label {
    font-size: 11px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--ink-soft);
}

.admin-sidebar-list {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
    min-height: 0;
}

.admin-sidebar-row {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 8px;
    border-radius: 10px;
    border: 1px solid transparent;
}
.admin-sidebar-row:hover { background: var(--bg); }

.admin-sidebar-row.is-current {
    background: var(--tag-bg);
    border-color: var(--line);
}

.admin-sidebar-cover {
    flex: none;
    width: 30px;
    aspect-ratio: 2 / 3;
    border-radius: 4px;
    overflow: hidden;
    background: var(--tag-bg);
}

.admin-sidebar-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.admin-sidebar-main {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.admin-sidebar-title {
    font-size: 13.5px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.admin-sidebar-meta {
    font-size: 12px;
    color: var(--ink-soft);
}

.admin-sidebar-add {
    width: 100%;
    margin-top: 12px;
}

/* ---------- desktop content pane ---------- */

.admin-pane-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 16px;
}

.admin-toolbar-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.admin-sort {
    width: auto;
    padding: 6px 12px;
    font-size: 13px;
}

.admin-toolbar-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ---------- novel stats page ---------- */

.stat-tiles {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 24px;
}

/* Tiles hug their content and pack left rather than stretching across the pane:
 * four numbers spread over a 1200px desktop read as unrelated. */
.stat-tile {
    flex: 0 0 auto;
    min-width: 120px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
}

.stat-tile-value { font-size: 24px; }

.stat-tile-label {
    color: var(--ink-soft);
    font-size: 12px;
}

.stat-heading {
    margin: 0 0 10px;
    font-size: 15px;
}

/* The default thumb is the page background, i.e. invisible — give it contrast
 * so it's clear the table scrolls sideways. */
.stat-table-wrap {
    overflow-x: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--ink-soft) transparent;
}

.stat-table-wrap::-webkit-scrollbar { height: 8px; }
.stat-table-wrap::-webkit-scrollbar-track { background: transparent; }

.stat-table-wrap::-webkit-scrollbar-thumb {
    background: var(--ink-soft);
    border-radius: 4px;
}

/* Left-aligned and content-width: the numeric columns line up next to the
 * chapter they belong to instead of drifting to the far edge of a wide pane. */
.stat-table {
    width: auto;
    border-collapse: collapse;
    font-size: 14px;
    white-space: nowrap;
}

.stat-table th {
    color: var(--ink-soft);
    font-size: 12px;
    font-weight: 400;
}

.stat-table th,
.stat-table td {
    padding: 8px 24px 8px 0;
    text-align: left;
    border-bottom: 1px solid var(--line);
}

.stat-table td a { color: inherit; }

.stat-reactions {
    display: inline-flex;
    gap: 10px;
    color: var(--ink-soft);
}

.stat-reaction {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

/* ---------- novel form layout ----------
 * Two columns on wide screens (cover left, fields right), stacking to a single
 * column on phones — the "данные новеллы (ПК)" design, adapted responsively. */

.novel-form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px 32px;
}

@media (width >= 720px) {
    .novel-form-grid { grid-template-columns: 300px 1fr; }
}

/* Tags + status sit side by side on wide screens, stack on phones. */
.novel-form-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0 24px;
}

@media (width >= 560px) {
    .novel-form-row { grid-template-columns: 1fr 1fr; }
}

/* The whole 2:3 dashed box is the file picker (native input is hidden inside). */
.cover-drop {
    position: relative;
    display: block;
    aspect-ratio: 2 / 3;
    border: 2px dashed var(--line);
    border-radius: 14px;
    background: var(--tag-bg);
    cursor: pointer;
    overflow: hidden;
}

.cover-drop input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.cover-preview {
    position: absolute;
    inset: 0;
}

.cover-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Centred icon + label, hidden once an image fills the box. */
.cover-drop-prompt {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--ink-soft);
    text-align: center;
    pointer-events: none;
}

.cover-drop.has-image .cover-drop-prompt { display: none; }

.cover-drop-icon {
    width: 34px;
    height: 34px;
    fill: none;
    stroke: currentcolor;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.cover-drop-label { font-size: 15px; }

/* ---------- chapter editor ---------- */

/* How the chapter did: shown above the form for published chapters only. */
.editor-stats {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 14px;
}

.editor-stat {
    display: flex;
    flex-direction: column;
}
.editor-stat-value { font-size: 18px; }

.editor-stat-label {
    color: var(--ink-soft);
    font-size: 12px;
}

.editor-stat-reactions {
    display: flex;
    width: 100%;
    gap: 25px;
    color: var(--ink-soft);
    font-size: 13px;
}

.editor-stat-reaction {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Two columns sharing one row: the number is sized to its content, the title
 * takes the rest. Bottom alignment keeps the inputs on one line even if a
 * label wraps; min-width: 0 lets the title actually shrink and grow. */
.editor-meta {
    display: flex;
    align-items: flex-end;
    gap: 12px;
}

.editor-meta > div:not(.editor-meta-title) {
    flex: 0 0 auto;
    width: 5.5rem;
}

.editor-meta > .editor-meta-title {
    flex: 1 1 auto;
    min-width: 0;
}

.editor-publish {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
}

/* Inline in the publish row, so it loses the block .field-label margins. */
.editor-publish-label { margin: 0; }

.schedule-row {
    display: flex;
    align-items: center;
    gap: 8px;
}
.schedule-row .field { width: auto; }
.schedule-row.is-hidden { display: none; }

.editor-saved {
    flex: 1;
    text-align: right;
    color: var(--ink-soft);
    font-size: 13px;
}

.toolbar {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    padding: 8px;
    border: 1px solid var(--line);
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
    background: var(--surface);
}
.toolbar .icon-btn { min-width: 34px; }

/* Toolbar glyphs drawn as line art (Word-like), inheriting the button's ink so
 * the .is-active accent applies to them like it does to the text buttons. */
.tb-icon {
    width: 18px;
    height: 18px;
    display: block;
    fill: currentcolor;
}

.tb-icon .tb-rule {
    fill: none;
    stroke: currentcolor;
    stroke-width: 1.6;
    stroke-linecap: round;
}

.tb-icon .tb-num {
    font-size: 6px;
    font-family: inherit;
}

.toolbar .icon-btn.is-active {
    background: var(--tag-bg);
    color: var(--accent);
}

.toolbar-menu { position: relative; }

.toolbar-menu-list {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 6px 20px rgb(0 0 0 / 30%);
    white-space: nowrap;
}

/* .toolbar-menu-list wins the display cascade over the global .is-hidden (both
 * single-class, this rule comes later), so scope the hidden state to this menu. */
.toolbar-menu-list.is-hidden { display: none; }
.toolbar-menu-list .icon-btn { justify-content: flex-start; }

.toolbar-sep {
    width: 1px;
    align-self: stretch;
    background: var(--line);
    margin: 0 4px;
}

/* Inherits .reader-prose, so what admins type is styled as readers will see it.
 * Font is pinned to Charis SIL rather than following the reader's chosen face:
 * the editor should look the same whatever the admin reads in. */
.editor-surface {
    border: 1px solid var(--line);
    border-top: 0;
    border-bottom-left-radius: 10px;
    border-bottom-right-radius: 10px;
    background: var(--surface);
    padding: 16px;
    min-height: 320px;
    max-width: none;
    counter-reset: fn;
    font-family: "Charis SIL", georgia, serif;
}

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

/* Novel description: the same toolbar + surface pair as the chapter editor, but
 * short and marks-only, so it sits inline in the form instead of sticking. */
.desc-toolbar { position: static; }

.desc-surface {
    border: 1px solid var(--line);
    border-top: 0;
    border-bottom-left-radius: 10px;
    border-bottom-right-radius: 10px;
    background: var(--surface);
    padding: 12px;
    min-height: 96px;
    color: var(--ink);
    line-height: 1.6;
    font-family: "Charis SIL", georgia, serif;
}

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

.desc-surface p { margin: 0 0 0.6em; }
.desc-surface p:last-child { margin-bottom: 0; }

/* Modal footnotes are single inline markers in the editor (the note text lives
 * in data-note, edited on click). The [N] label is drawn by a CSS counter
 * (counter-reset on .editor-surface above) so it always reflects document order
 * without any renumbering code. */
.editor-surface sup.fn { counter-increment: fn; }
.editor-surface sup.fn::after { content: "[" counter(fn) "]"; }

/* Footnote note editor — a styled stand-in for the native prompt(). */
.fn-dialog-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgb(0 0 0 / 45%);
}

.fn-dialog-overlay.is-hidden { display: none; }

.fn-dialog {
    width: 100%;
    max-width: 420px;
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
}

.fn-dialog-title {
    margin: 0 0 8px;
    font-weight: 600;
}

.fn-dialog-field {
    width: 100%;
    padding: 8px 10px;
    font: inherit;
    color: inherit;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 8px;
    resize: vertical;
}

.fn-dialog-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 12px;
}
