:root {
    --app-sidebar-width: 304px;
    --app-bar-height: 64px;
    --app-bg: #f4f7f6;
    --surface: #ffffff;
    --surface-subtle: #f7f9f8;
    --surface-hover: #edf3f1;
    --border: #dfe7e4;
    --border-strong: #c8d5d1;
    --text: #1d2926;
    --text-muted: #65736f;
    --primary: #0f766e;
    --primary-hover: #0b5f59;
    --primary-soft: #e5f3f0;
    --warning: #a16207;
    --danger: #b42318;
    --danger-soft: #fff0ee;
    --focus: #0f766e;
    --shadow-dialog: 0 18px 50px rgba(24, 42, 37, 0.18);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    color-scheme: light;
    background: var(--app-bg);
    scrollbar-color: #a8b6b2 transparent;
}

body {
    min-height: 100vh;
    margin: 0;
    overflow-x: hidden;
    color: var(--text);
    background: var(--app-bg);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    font-size: 16px;
}

button,
input,
textarea {
    font: inherit;
    letter-spacing: 0;
}

button,
label[for] {
    -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
a:focus-visible,
label[for]:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

#body-container {
    min-height: 100vh;
    overflow-x: clip;
}

.hidden {
    display: none !important;
}

.icon-button {
    display: inline-flex;
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: 6px;
    color: var(--text-muted);
    background: transparent;
    cursor: pointer;
}

.icon-button:hover:not(:disabled) {
    color: var(--primary);
    background: var(--surface-hover);
}

.icon-button:disabled {
    opacity: 0.35;
    cursor: default;
}

.button {
    display: inline-flex;
    min-height: 40px;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 15px;
    border: 1px solid transparent;
    border-radius: 6px;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
}

.button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.button-primary {
    color: #ffffff;
    background: var(--primary);
}

.button-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.button-secondary {
    color: var(--text);
    border-color: var(--border-strong);
    background: var(--surface);
}

.button-secondary:hover:not(:disabled),
.button-quiet:hover:not(:disabled) {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-soft);
}

.button-quiet {
    color: var(--text);
    border-color: var(--border);
    background: var(--surface);
}

.button-danger {
    color: var(--danger);
    border-color: #f0b7b1;
    background: var(--danger-soft);
}

.button-danger:hover:not(:disabled) {
    border-color: var(--danger);
}

/* Sidebar */

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 300;
    display: flex;
    width: var(--app-sidebar-width);
    height: 100vh;
    flex-direction: column;
    overflow: hidden;
    transform: translateX(-100%);
    border-right: 1px solid var(--border);
    color: var(--text);
    background: var(--surface);
    transition: transform 180ms ease;
}

#sidebar-toggle-anchor:checked ~ .sidebar {
    z-index: 300;
    transform: translateX(0);
}

.sidebar-brand {
    display: flex;
    min-height: var(--app-bar-height);
    align-items: center;
    gap: 11px;
    padding: 10px 14px 10px 16px;
    border-bottom: 1px solid var(--border);
}

.brand-mark {
    display: flex;
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    align-items: center;
    justify-content: center;
    border-radius: 7px;
    color: #ffffff;
    background: var(--primary);
    font-size: 17px;
}

.brand-copy {
    display: flex;
    min-width: 0;
    flex: 1;
    flex-direction: column;
    line-height: 1.2;
}

.brand-copy strong {
    overflow: hidden;
    font-size: 15px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.brand-copy span {
    margin-top: 3px;
    color: var(--text-muted);
    font-size: 12px;
}

.sidebar-close {
    display: none;
}

.sidebar-controls {
    padding: 16px 14px 12px;
    border-bottom: 1px solid var(--border);
}

.field-caption {
    display: block;
    margin-bottom: 7px;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 700;
}

.catalog-heading {
    display: flex;
    min-height: 36px;
    align-items: center;
    justify-content: space-between;
    margin-top: 18px;
}

.catalog-heading > div:first-child {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.catalog-heading .field-caption {
    margin: 0;
    color: var(--text);
    font-size: 13px;
}

.catalog-heading small {
    color: var(--text-muted);
    font-size: 12px;
}

.catalog-actions {
    display: flex;
    gap: 2px;
}

.chapter-search {
    display: flex;
    height: 38px;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    padding: 0 8px 0 11px;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    background: var(--surface-subtle);
}

.chapter-search:focus-within,
.chapter-search.active {
    border-color: var(--primary);
    background: var(--surface);
}

.chapter-search input {
    min-width: 0;
    height: 100%;
    flex: 1;
    padding: 0;
    border: 0;
    outline: 0;
    color: var(--text);
    background: transparent;
    font-size: 13px;
}

.chapter-search .icon-button {
    width: 28px;
    height: 28px;
    flex-basis: 28px;
}

.menu-list-box {
    flex: 1;
    overflow-y: auto;
    padding: 10px 10px 24px;
    scrollbar-width: thin;
}

.menu-list-box::-webkit-scrollbar {
    width: 5px;
}

.menu-list-box::-webkit-scrollbar-thumb {
    border-radius: 4px;
    background: #b7c4c0;
}

.sidebar-empty {
    padding: 24px 12px;
    color: var(--text-muted);
    font-size: 13px;
    text-align: center;
}

/* Vue multiselect */

.sidebar .multiselect {
    min-height: 42px;
    color: var(--text);
    font-size: 13px;
}

.sidebar .multiselect__tags {
    min-height: 42px;
    padding: 10px 38px 8px 11px;
    border-color: var(--border-strong);
    border-radius: 6px;
    background: var(--surface);
}

.sidebar .multiselect__single,
.sidebar .multiselect__input {
    max-width: 100%;
    margin: 0;
    padding: 0;
    color: var(--text);
    background: transparent;
    font-size: 13px;
    line-height: 20px;
}

.sidebar .multiselect__placeholder {
    margin: 0;
    padding: 0;
    color: #87938f;
    line-height: 20px;
}

.sidebar .multiselect__select {
    width: 36px;
    height: 40px;
}

.sidebar .multiselect__content-wrapper {
    margin-top: 5px;
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 10px 28px rgba(24, 42, 37, 0.13);
}

.sidebar .multiselect__option {
    min-height: 38px;
    padding: 10px 12px;
    line-height: 18px;
}

.sidebar .multiselect__option--group {
    min-height: 32px;
    padding: 8px 12px;
    color: var(--text-muted);
    background: var(--surface-subtle);
    font-size: 12px;
    font-weight: 700;
}

.sidebar .multiselect__option--highlight,
.sidebar .multiselect__option--selected.multiselect__option--highlight {
    color: var(--text);
    background: var(--primary-soft);
}

.sidebar .multiselect__option--selected {
    color: var(--primary);
    background: var(--surface);
    font-weight: 600;
}

.sidebar .multiselect__option::after {
    display: none;
}

/* Chapter tree */

.chapter {
    width: 100%;
    margin: 0;
    padding: 0;
    list-style: none;
}

.chapter .chapter {
    padding-left: 14px;
}

.menu-list-box .chapter li:not(.expanded) + li > ol {
    display: block;
}

.menu-list-box .chapter-node {
    display: block;
    width: 100%;
    margin: 2px 0;
}

.menu-list-box .chapter-group,
.menu-list-box .chapter-link {
    display: flex;
    width: 100%;
    min-height: 36px;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 9px;
    border: 0;
    border-radius: 5px;
    color: var(--text);
    background: transparent;
    font-size: 13px;
    line-height: 19px;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.menu-list-box .chapter-group:hover,
.menu-list-box .chapter-link:hover {
    color: var(--text);
    background: var(--surface-hover);
}

.menu-list-box .chapter-link.active {
    color: var(--primary);
    background: var(--primary-soft);
    font-weight: 600;
}

.menu-list-box .chapter-label {
    display: -webkit-box;
    min-width: 0;
    overflow: hidden;
    overflow-wrap: anywhere;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.menu-list-box .chapter-chevron {
    width: 12px;
    flex: 0 0 12px;
    margin-top: 2px;
    color: var(--text-muted);
    text-align: center;
    transition: transform 150ms ease;
}

.menu-list-box .chapter-group.expanded .chapter-chevron {
    transform: rotate(90deg);
}

.menu-list-box .chapter-dot {
    width: 5px;
    height: 5px;
    flex: 0 0 5px;
    margin: 7px 4px 0 3px;
    border-radius: 50%;
    background: #aab6b2;
}

.menu-list-box .chapter-link.active .chapter-dot {
    background: var(--primary);
}

/* Application bar and reader */

.page-wrapper {
    min-height: 100vh;
    margin: 0;
    transform: none !important;
    background: var(--app-bg);
    transition: margin-left 180ms ease;
}

.app-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    height: var(--app-bar-height);
    align-items: center;
    gap: 10px;
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.96);
}

.menu-toggle {
    color: var(--text);
}

.page-context {
    display: flex;
    min-width: 0;
    flex: 1;
    align-items: center;
    gap: 8px;
    overflow: hidden;
    white-space: nowrap;
}

.context-column {
    max-width: 35%;
    overflow: hidden;
    color: var(--text-muted);
    font-size: 13px;
    text-overflow: ellipsis;
}

.context-separator {
    color: #a5b1ad;
    font-size: 12px;
}

.context-chapter {
    min-width: 0;
    overflow: hidden;
    font-size: 14px;
    font-weight: 650;
    text-overflow: ellipsis;
}

.app-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.progress-badge {
    display: inline-flex;
    height: 28px;
    align-items: center;
    padding: 0 9px;
    border: 1px solid var(--border);
    border-radius: 5px;
    color: var(--text-muted);
    background: var(--surface-subtle);
    font-size: 12px;
    white-space: nowrap;
}

.content {
    min-height: calc(100vh - var(--app-bar-height));
    overflow: visible;
    padding: 0;
    background: var(--surface);
}

.reader-shell {
    position: relative;
    min-height: calc(100vh - var(--app-bar-height));
    padding: 0 24px 72px;
}

.reading-surface {
    width: 100%;
    max-width: 860px !important;
    min-height: calc(100vh - var(--app-bar-height));
    margin: 0 auto;
    padding: 48px 0 40px;
    color: var(--text);
    background: var(--surface);
    font-size: 16px;
    line-height: 1.75;
}

.reading-surface > :first-child {
    margin-top: 0;
}

.reading-surface h1,
.reading-surface h2,
.reading-surface h3,
.reading-surface h4 {
    color: #15201d;
    line-height: 1.35;
}

.reading-surface h1 {
    font-size: 30px;
}

.reading-surface h2 {
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    font-size: 24px;
}

.reading-surface h3 {
    font-size: 20px;
}

.reading-surface a {
    color: var(--primary);
}

.reading-surface blockquote {
    padding: 12px 18px;
    border: 0;
    border-left: 3px solid var(--primary);
    color: #42504c;
    background: var(--primary-soft);
}

.reading-surface img {
    border-radius: 4px;
}

.iframe-surface {
    width: 100%;
    max-width: none !important;
    min-height: calc(100vh - var(--app-bar-height));
    margin: 0 auto;
    padding: 24px 0 0;
    background: #ffffff;
}

.iframe-surface iframe {
    display: block;
    width: 100%;
    min-height: calc(100vh - var(--app-bar-height) - 24px);
    border: 0;
    background: #ffffff;
}

.reader-loading .reading-surface,
.reader-loading .iframe-surface {
    visibility: hidden;
}

.content-loading {
    position: absolute;
    top: 54px;
    left: 50%;
    z-index: 2;
    display: flex;
    width: min(720px, calc(100% - 48px));
    transform: translateX(-50%);
    flex-direction: column;
    gap: 18px;
}

.loading-line {
    display: block;
    width: 82%;
    height: 14px;
    border-radius: 4px;
    background: #e7edeb;
    animation: loading-pulse 1.2s ease-in-out infinite alternate;
}

.loading-line-wide {
    width: 100%;
    height: 24px;
}

.loading-line-short {
    width: 58%;
}

@keyframes loading-pulse {
    from { opacity: 0.55; }
    to { opacity: 1; }
}

.state-panel {
    display: flex;
    min-height: calc(100vh - var(--app-bar-height));
    align-items: center;
    justify-content: center;
    flex-direction: column;
    padding: 48px 24px;
    color: var(--text);
    text-align: center;
}

.state-panel .state-icon {
    display: flex;
    width: 52px;
    height: 52px;
    align-items: center;
    justify-content: center;
    margin-bottom: 18px;
    border-radius: 8px;
    color: var(--primary);
    background: var(--primary-soft);
    font-size: 22px;
}

.state-panel.state-error .state-icon {
    color: var(--danger);
    background: var(--danger-soft);
}

.state-panel h1 {
    margin: 0;
    font-size: 22px;
    line-height: 1.35;
}

.state-panel p {
    max-width: 520px;
    margin: 10px 0 0;
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1.65;
}

.state-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-top: 22px;
}

.content-error {
    min-height: calc(100vh - var(--app-bar-height) - 72px);
}

.chapter-navigation {
    display: grid;
    width: 100%;
    max-width: 860px;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 12px;
    margin: 0 auto;
    padding-top: 28px;
    border-top: 1px solid var(--border);
}

.render-html .chapter-navigation,
.render-pdf .chapter-navigation {
    max-width: none;
}

.chapter-nav-item {
    display: flex;
    min-width: 0;
    min-height: 72px;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    background: var(--surface);
    text-align: left;
    cursor: pointer;
}

.chapter-nav-item:hover {
    border-color: var(--primary);
    background: var(--primary-soft);
}

.chapter-nav-item.next {
    justify-content: flex-end;
    text-align: right;
}

.chapter-nav-item i {
    color: var(--primary);
}

.chapter-nav-item span {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 5px;
}

.chapter-nav-item small {
    color: var(--text-muted);
    font-size: 12px;
}

.chapter-nav-item strong {
    overflow: hidden;
    font-size: 14px;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Settings */

.dialog-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(20, 31, 28, 0.52);
}

.dialog-container {
    position: relative;
    display: flex;
    width: min(560px, 100%);
    max-width: 560px;
    max-height: min(820px, calc(100vh - 48px));
    flex-direction: column;
    overflow: hidden;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    background: var(--surface);
    box-shadow: var(--shadow-dialog);
}

.dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 20px 22px 16px;
    border-bottom: 1px solid var(--border);
}

.dialog-kicker {
    display: block;
    margin-bottom: 4px;
    color: var(--primary);
    font-size: 11px;
    font-weight: 700;
}

.dialog-header h2 {
    margin: 0;
    font-size: 20px;
}

.dialog-content {
    overflow-y: auto;
    padding: 2px 22px 24px;
}

.settings-section {
    margin: 0;
    padding: 20px 0;
    border: 0;
    border-bottom: 1px solid var(--border);
}

.settings-section:last-child {
    border-bottom: 0;
}

.settings-section legend {
    width: 100%;
    margin: 0 0 14px;
    padding: 0;
    color: var(--text);
    font-size: 14px;
    font-weight: 700;
}

.form-field {
    display: flex;
    margin-top: 14px;
    flex-direction: column;
    gap: 7px;
}

.form-field:first-of-type {
    margin-top: 0;
}

.form-field > span {
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
}

.form-field input,
.form-field textarea {
    width: 100%;
    min-height: 40px;
    padding: 9px 11px;
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    outline: 0;
    color: var(--text);
    background: var(--surface);
    font-size: 14px;
}

.form-field textarea {
    min-height: 92px;
    resize: vertical;
    line-height: 1.5;
}

.form-field input:focus,
.form-field textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.11);
}

.form-field small,
.switch-row small,
.danger-zone small {
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1.45;
}

.form-field .field-error {
    color: var(--danger);
}

.input-with-action {
    position: relative;
}

.input-with-action input {
    padding-right: 44px;
}

.input-with-action .icon-button {
    position: absolute;
    top: 2px;
    right: 2px;
}

.switch-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    margin-top: 14px;
}

.switch-row > span {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.switch-row strong {
    font-size: 13px;
}

.switch-row input[type="checkbox"] {
    width: 42px;
    height: 24px;
    flex: 0 0 42px;
    margin: 0;
    appearance: none;
    border: 1px solid var(--border-strong);
    border-radius: 12px;
    background: #d6dfdc;
    cursor: pointer;
    transition: background 150ms ease;
}

.switch-row input[type="checkbox"]::before {
    display: block;
    width: 18px;
    height: 18px;
    margin: 2px;
    transform: translateX(0);
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 1px 3px rgba(20, 31, 28, 0.25);
    content: "";
    transition: transform 150ms ease;
}

.switch-row input[type="checkbox"]:checked {
    border-color: var(--primary);
    background: var(--primary);
}

.switch-row input[type="checkbox"]:checked::before {
    transform: translateX(18px);
}

.danger-zone {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-top: 20px;
    padding: 14px;
    border: 1px solid #f1c7c2;
    border-radius: 6px;
    background: #fffafa;
}

.danger-zone > div:first-child {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.danger-zone strong {
    font-size: 13px;
}

.danger-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.danger-actions .button {
    min-height: 34px;
    padding: 6px 10px;
    font-size: 12px;
}

.dialog-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 22px;
    border-top: 1px solid var(--border);
    background: var(--surface-subtle);
}

.toast-message {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 1200;
    max-width: min(360px, calc(100vw - 40px));
    padding: 11px 14px;
    border: 1px solid #bed8d2;
    border-radius: 6px;
    color: #ffffff;
    background: #21453f;
    box-shadow: 0 8px 22px rgba(24, 42, 37, 0.18);
    font-size: 13px;
}

.toast-enter-active,
.toast-leave-active {
    transition: opacity 150ms ease, transform 150ms ease;
}

.toast-enter,
.toast-leave-to {
    transform: translateY(8px);
    opacity: 0;
}

.sidebar-backdrop {
    display: none;
}

@media (min-width: 1025px) {
    #sidebar-toggle-anchor:checked ~ .page-wrapper {
        margin-left: var(--app-sidebar-width);
    }
}

@media (max-width: 1024px) {
    .sidebar {
        box-shadow: 12px 0 34px rgba(24, 42, 37, 0.16);
    }

    .sidebar-close {
        display: inline-flex;
    }

    #sidebar-toggle-anchor:checked + .sidebar-backdrop {
        position: fixed;
        inset: 0;
        z-index: 250;
        display: block;
        background: rgba(20, 31, 28, 0.4);
    }

    #sidebar-toggle-anchor:checked ~ .page-wrapper {
        margin-left: 0;
        transform: none;
    }
}

@media (max-width: 680px) {
    .app-bar {
        padding: 0 10px;
    }

    .context-column,
    .context-separator,
    .progress-badge {
        display: none;
    }

    .reader-shell {
        padding: 0 16px 48px;
    }

    .reading-surface {
        padding: 32px 0;
        font-size: 15px;
    }

    .reading-surface h1 {
        font-size: 26px;
    }

    .reading-surface h2 {
        font-size: 21px;
    }

    .iframe-surface {
        width: calc(100% + 32px);
        margin-right: 0;
        margin-left: -16px;
        padding-top: 0;
    }

    .content .iframe-surface {
        margin-right: 0;
        margin-left: -16px;
    }

    .chapter-navigation {
        grid-template-columns: 1fr;
    }

    .chapter-nav-spacer {
        display: none;
    }

    .chapter-nav-item.next {
        grid-row: 1;
    }

    .dialog-overlay {
        align-items: stretch;
        padding: 0;
    }

    .dialog-container {
        width: 100%;
        max-width: none;
        max-height: 100vh;
        border: 0;
        border-radius: 0;
    }

    .dialog-header,
    .dialog-content,
    .dialog-footer {
        padding-right: 16px;
        padding-left: 16px;
    }

    .danger-zone {
        flex-direction: column;
    }

    .danger-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .dialog-footer .button {
        flex: 1;
    }
}

@media (max-width: 360px) {
    :root {
        --app-sidebar-width: min(304px, 88vw);
    }

    .sidebar {
        width: min(304px, 88vw);
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
