:root {
    --bg: #f5f7f8;
    --surface: #ffffff;
    --line: #d9e0e3;
    --text: #1d2529;
    --muted: #637177;
    --accent: #176d63;
    --accent-dark: #0f514a;
    --warning: #a66100;
    --danger: #a32929;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 15px;
    line-height: 1.55;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    min-height: 64px;
    padding: 0 32px;
    background: #162023;
    color: #ffffff;
    border-bottom: 4px solid #d9b46b;
}

.brand {
    color: #ffffff;
    font-size: 20px;
    font-weight: 700;
}

.brand:hover {
    text-decoration: none;
}

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

.nav a {
    min-height: 36px;
    padding: 7px 12px;
    color: #f9fbfb;
    border-radius: 4px;
}

.nav a:hover,
.nav-form button:hover {
    background: rgba(255, 255, 255, 0.12);
    text-decoration: none;
}

.nav-form {
    margin: 0;
}

.nav-form button {
    min-height: 36px;
    padding: 7px 12px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: #f9fbfb;
    font: inherit;
    cursor: pointer;
}

.page {
    width: min(1180px, calc(100% - 32px));
    margin: 28px auto 48px;
}

.section {
    margin-bottom: 24px;
    padding: 24px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.section.narrow {
    max-width: 720px;
}

.section-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.section-heading.compact {
    margin-bottom: 14px;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 0;
    font-size: 26px;
    line-height: 1.25;
}

h2 {
    margin-bottom: 0;
    font-size: 20px;
    line-height: 1.35;
}

h3 {
    margin-bottom: 6px;
    font-size: 17px;
}

.lead,
.document-row p {
    margin-bottom: 0;
    color: var(--muted);
}

.count-label,
.status {
    flex: 0 0 auto;
    min-height: 30px;
    padding: 4px 10px;
    border-radius: 4px;
    background: #edf3f2;
    color: var(--accent-dark);
    font-size: 13px;
    font-weight: 700;
}

.status-draft,
.status-review {
    background: #fff3dd;
    color: var(--warning);
}

.status-published {
    background: #e5f4ec;
    color: #16613a;
}

.status-failed {
    background: #fdeaea;
    color: var(--danger);
}

.search-form,
.upload-form,
.login-form {
    display: grid;
    grid-template-columns: minmax(280px, 2fr) repeat(4, minmax(120px, 1fr));
    gap: 14px;
    align-items: end;
}

.upload-form,
.login-form {
    grid-template-columns: 1fr;
}

label {
    display: grid;
    gap: 6px;
    min-width: 0;
}

label span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

input[type="search"],
input[type="text"],
input[type="password"],
input[type="number"],
input[type="file"],
select {
    width: 100%;
    min-height: 42px;
    padding: 8px 10px;
    border: 1px solid #c8d1d5;
    border-radius: 6px;
    background: #ffffff;
    color: var(--text);
    font: inherit;
}

select {
    cursor: pointer;
}

.form-actions,
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.primary-button,
.secondary-button,
.publish-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    min-width: 112px;
    padding: 9px 14px;
    border: 1px solid transparent;
    border-radius: 6px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

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

.primary-button:hover,
.publish-button:hover {
    text-decoration: none;
}

.secondary-button {
    background: #ffffff;
    color: var(--accent-dark);
    border-color: #b8c7ca;
}

.publish-button {
    background: #b34f14;
    color: #ffffff;
}

.inline-form {
    margin: 0;
}

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

.back-button {
    margin-top: 10px;
}

.preview-section {
    padding-bottom: 18px;
}

.preview-section.is-loading .pdf-page-preview {
    opacity: 0.45;
}

.preview-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

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

.page-jump-form {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin: 0;
}

.compact-button {
    min-width: 84px;
}

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

.page-jump {
    display: inline-flex;
    grid-template-columns: none;
    align-items: center;
    gap: 8px;
    min-height: 42px;
    padding: 7px 10px;
    border: 1px solid #c8d1d5;
    border-radius: 6px;
    background: #ffffff;
}

.page-jump span,
.page-jump strong {
    color: var(--muted);
    font-size: 13px;
}

.page-jump input {
    width: 76px;
    min-height: 28px;
    padding: 3px 6px;
    border: 1px solid #c8d1d5;
    border-radius: 4px;
    font: inherit;
}

.pdf-image-stage {
    overflow: auto;
    max-height: 78vh;
    min-height: 520px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #161616;
    text-align: center;
}

.pdf-page-preview {
    display: block;
    width: min(50%, 460px);
    height: auto;
    margin: 0 auto;
    background: #ffffff;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.32);
    transition: opacity 0.12s ease;
}

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
}

table {
    width: 100%;
    min-width: 860px;
    border-collapse: collapse;
    background: #ffffff;
}

th,
td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

th {
    background: #edf1f2;
    color: #344247;
    font-size: 13px;
}

td small {
    display: block;
    margin-top: 4px;
    color: var(--muted);
}

tr:last-child td {
    border-bottom: 0;
}

.table-link {
    font-weight: 700;
}

.code-link {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 2px 8px;
    border: 1px solid #b8c7ca;
    border-radius: 4px;
    background: #f7fbfa;
    color: var(--accent-dark);
    font-weight: 700;
}

.code-link:hover {
    border-color: var(--accent);
    text-decoration: none;
}

.document-grid {
    display: grid;
    gap: 12px;
}

.pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 18px;
}

.page-numbers {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
}

.page-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    min-height: 36px;
    padding: 6px 10px;
    border: 1px solid #b8c7ca;
    border-radius: 6px;
    background: #ffffff;
    color: var(--accent-dark);
    font-weight: 700;
}

.page-number:hover {
    border-color: var(--accent);
    text-decoration: none;
}

.page-number.current {
    border-color: var(--accent);
    background: var(--accent);
    color: #ffffff;
}

.page-number.ellipsis {
    min-width: 28px;
    border-color: transparent;
    background: transparent;
    color: var(--muted);
}

.document-row {
    display: grid;
    grid-template-columns: 108px minmax(0, 1fr) auto;
    gap: 16px;
    align-items: center;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfc;
}

.document-thumb,
.detail-thumb {
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #edf1f2;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.document-thumb {
    width: 108px;
    height: 148px;
}

.document-thumb:hover {
    border-color: var(--accent);
    text-decoration: none;
}

.document-thumb img,
.detail-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top right;
}

.detail-header {
    display: grid;
    grid-template-columns: 156px minmax(0, 1fr);
    gap: 20px;
    align-items: start;
}

.detail-thumb {
    width: 156px;
    height: 216px;
}

.detail-summary {
    min-width: 0;
}

.meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.meta-grid div {
    min-height: 78px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fbfcfc;
}

.meta-grid span {
    display: block;
    color: var(--muted);
    font-size: 13px;
}

.meta-grid strong {
    display: block;
    margin-top: 4px;
    font-size: 17px;
}

.messages {
    display: grid;
    gap: 8px;
    margin-bottom: 18px;
}

.auth-section {
    margin-inline: auto;
}

.message {
    padding: 12px 14px;
    border-radius: 6px;
    border: 1px solid var(--line);
    background: #ffffff;
}

.message-success {
    border-color: #99c9b2;
    background: #edf9f2;
}

.message-error {
    border-color: #e5a6a6;
    background: #fff0f0;
}

.empty {
    margin-bottom: 0;
    color: var(--muted);
}

.log-list {
    display: grid;
    gap: 8px;
}

.log-row {
    display: grid;
    grid-template-columns: 150px 72px minmax(0, 1fr);
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fbfcfc;
}

.log-row p {
    margin-bottom: 0;
}

.errorlist {
    margin: 0;
    padding-left: 20px;
    color: var(--danger);
}

@media (max-width: 900px) {
    .topbar,
    .section-heading,
    .document-row {
        align-items: stretch;
        flex-direction: column;
    }

    .topbar {
        padding: 14px 18px;
    }

    .search-form,
    .meta-grid {
        grid-template-columns: 1fr 1fr;
    }

    .document-row {
        grid-template-columns: 1fr;
    }

    .document-thumb {
        width: 132px;
        height: 180px;
    }

    .detail-header {
        grid-template-columns: 1fr;
    }

    .row-actions {
        justify-content: flex-start;
    }
}

@media (max-width: 560px) {
    .page {
        width: min(100% - 20px, 1180px);
        margin-top: 18px;
    }

    .section {
        padding: 18px;
    }

    .search-form,
    .meta-grid,
    .log-row {
        grid-template-columns: 1fr;
    }

    .primary-button,
    .secondary-button,
    .publish-button {
        width: 100%;
    }

    .preview-toolbar,
    .page-jump,
    .page-jump-form {
        width: 100%;
    }

    .page-jump,
    .page-jump-form {
        justify-content: center;
    }

    .pdf-image-stage {
        max-height: 68vh;
        min-height: 420px;
        padding: 8px;
    }

    .pdf-page-preview {
        width: min(100%, 920px);
    }
}
