/* =========================================================
   Library Bibliography — design tokens & shared primitives
   ========================================================= */
:root {
    --ink: #172825;
    --ink-2: #2a3b37;
    --ink-3: #41524d;
    --teal: #123f3b;
    --teal-2: #1d5a52;
    --teal-3: #2f776a;
    --sage: #dce8df;
    --sage-2: #eef3ec;
    --cream: #f7f2e7;
    --cream-2: #f1eadc;
    --paper: #fffdf8;
    --sand: #e6dac4;
    --sand-2: #d8c8ad;
    --rust: #b45f3f;
    --rust-2: #8f4932;
    --gold: #c09a56;
    --muted: #737b73;
    --muted-2: #8c938b;
    --line: #e3dccd;
    --line-strong: #cfc5b1;
    --danger: #a84437;
    --danger-bg: #fbefec;
    --success: #2e6b4f;
    --success-bg: #edf6ef;
    --warning: #946a2a;
    --warning-bg: #fbf3e2;
    --info: #2f5e72;
    --info-bg: #edf3f6;
    --shadow-sm: 0 1px 2px rgba(23, 40, 37, .04), 0 4px 12px rgba(23, 40, 37, .04);
    --shadow-md: 0 2px 4px rgba(23, 40, 37, .04), 0 18px 40px -20px rgba(23, 40, 37, .25);
    --shadow-lg: 0 30px 70px -30px rgba(18, 63, 59, .38);
    --radius-sm: 8px;
    --radius: 14px;
    --radius-lg: 22px;
    --radius-pill: 999px;
    --serif: "Noto Serif CJK SC", "Noto Serif CJK", "Source Han Serif SC", "Source Han Serif CN", "Noto Serif SC", "Songti SC", "STSong", "SimSun", "Noto Sans CJK SC", Georgia, "Times New Roman", serif;
    --sans: "Noto Sans CJK SC", "Noto Sans CJK", "Source Han Sans SC", "Source Han Sans CN", "Noto Sans SC", "Microsoft YaHei", "PingFang SC", system-ui, -apple-system, "Segoe UI", sans-serif;
    --mono: "JetBrains Mono", "Cascadia Code", "SFMono-Regular", Consolas, "Liberation Mono", "Noto Sans Mono CJK SC", monospace;
    --ease: cubic-bezier(.22, 1, .36, 1);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    font-family: var(--sans);
    font-size: 16px;
    line-height: 1.65;
    color: var(--ink);
    background: var(--cream);
    -webkit-font-smoothing: auto;
    text-rendering: optimizeLegibility;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    opacity: .35;
    background-image:
        radial-gradient(circle at 12% 8%, rgba(192, 154, 86, .10), transparent 28rem),
        radial-gradient(circle at 88% 22%, rgba(47, 119, 106, .08), transparent 30rem);
}

h1, h2, h3, h4, h5 {
    margin: 0;
    font-family: var(--serif);
    font-weight: 600;
    color: var(--ink);
    line-height: 1.25;
    letter-spacing: -.02em;
}

p {
    margin: 0;
}

a {
    color: inherit;
    text-decoration: none;
}

img, svg {
    display: block;
    max-width: 100%;
}

button, input, select, textarea {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
}

ul, ol, dl, dd {
    margin: 0;
    padding: 0;
}

li {
    list-style: none;
}

::selection {
    background: var(--teal);
    color: var(--cream);
}

:focus-visible {
    outline: 2px solid var(--rust);
    outline-offset: 3px;
    border-radius: 3px;
}

.icon-sprite {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

.icon {
    flex: 0 0 auto;
    display: inline-block;
    vertical-align: middle;
}

.container {
    width: min(1240px, calc(100% - 64px));
    margin-inline: auto;
}

.site-main {
    min-height: 60vh;
}

.mono {
    font-family: var(--mono);
    font-size: .9em;
    letter-spacing: -.02em;
}

.muted {
    color: var(--muted);
}

.nowrap {
    white-space: nowrap;
}

.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-muted { color: var(--muted); }
.text-warning { color: var(--warning); }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: fixed;
    top: -100px;
    left: 16px;
    z-index: 200;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    background: var(--teal);
    color: #fff;
    transition: top .2s;
}

.skip-link:focus {
    top: 12px;
}

/* ---------- Brand ---------- */
.brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    flex: 0 0 auto;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    flex: 0 0 auto;
    border-radius: 11px;
    color: var(--teal);
    background: linear-gradient(145deg, #eef2e9, #e2eadf);
    border: 1px solid #d6e0d5;
}

.brand-mark svg {
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
}

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

.brand-copy strong {
    font-family: var(--serif);
    font-size: 19px;
    font-weight: 700;
    letter-spacing: .01em;
    color: var(--ink);
}

.brand-copy small {
    margin-top: 2px;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: .14em;
    color: var(--muted);
}

/* ---------- Typographic bits ---------- */
.eyebrow {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    font-family: var(--sans);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .17em;
    color: var(--teal-2);
    text-transform: uppercase;
}

.eyebrow-mark {
    width: 22px;
    height: 1px;
    background: var(--rust);
    display: inline-block;
}

.eyebrow--light {
    color: rgba(255, 253, 248, .65);
}

.eyebrow--light .eyebrow-mark {
    background: var(--gold);
}

.lead {
    font-size: 18px;
    color: var(--ink-3);
}

.text-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--teal-2);
    font-size: 14px;
    font-weight: 600;
    border-bottom: 1px solid transparent;
    transition: color .2s, border-color .2s;
}

.text-link:hover {
    color: var(--rust);
    border-color: currentColor;
}

.text-link .icon {
    transition: transform .2s var(--ease);
}

.text-link:hover .icon {
    transform: translateX(2px);
}

/* ---------- Animated public statistics ---------- */
.live-stat {
    display: inline-block;
    min-width: 5.4ch;
    font-variant-numeric: tabular-nums;
    transform-origin: left bottom;
}

.live-stat.is-bumped {
    animation: live-stat-bump .58s var(--ease);
}

@keyframes live-stat-bump {
    0% { transform: translateY(0) scale(1); }
    32% { transform: translateY(-5px) scale(1.055); color: var(--rust); }
    100% { transform: translateY(0) scale(1); }
}

/* ---------- Buttons ---------- */
.btn {
    --btn-bg: transparent;
    --btn-color: var(--ink);
    --btn-border: transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 10px 20px;
    border: 1px solid var(--btn-border);
    border-radius: var(--radius-pill);
    background: var(--btn-bg);
    color: var(--btn-color);
    font-size: 14px;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    transition: transform .2s var(--ease), background .2s, border-color .2s, color .2s, box-shadow .2s;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

.btn--primary {
    --btn-bg: var(--teal);
    --btn-color: var(--cream);
    --btn-border: var(--teal);
    box-shadow: 0 10px 22px -14px rgba(18, 63, 59, .8);
}

.btn--primary:hover {
    --btn-bg: var(--teal-2);
    --btn-border: var(--teal-2);
}

.btn--dark {
    --btn-bg: var(--ink);
    --btn-color: var(--cream);
    --btn-border: var(--ink);
}

.btn--dark:hover {
    --btn-bg: var(--teal);
    --btn-border: var(--teal);
}

.btn--light {
    --btn-bg: var(--cream);
    --btn-color: var(--teal);
    --btn-border: var(--cream);
}

.btn--light:hover {
    --btn-bg: #fff;
}

.btn--outline {
    --btn-bg: transparent;
    --btn-color: var(--teal);
    --btn-border: var(--line-strong);
}

.btn--outline:hover {
    --btn-border: var(--teal);
    --btn-bg: var(--sage-2);
}

.btn--ghost {
    --btn-bg: transparent;
    --btn-color: var(--ink-3);
    --btn-border: transparent;
    padding-inline: 12px;
}

.btn--ghost:hover {
    --btn-bg: rgba(18, 63, 59, .06);
    --btn-color: var(--teal);
}

.btn--ghost-light {
    --btn-bg: transparent;
    --btn-color: rgba(255, 253, 248, .8);
    --btn-border: rgba(255, 253, 248, .22);
}

.btn--ghost-light:hover {
    --btn-bg: rgba(255, 255, 255, .08);
    --btn-color: #fff;
}

.btn--danger-outline {
    --btn-bg: transparent;
    --btn-color: var(--danger);
    --btn-border: #d9b4ad;
}

.btn--danger-outline:hover {
    --btn-bg: var(--danger-bg);
    --btn-border: var(--danger);
}

.btn--sm {
    min-height: 36px;
    padding: 7px 13px;
    font-size: 13px;
}

.btn--lg {
    min-height: 50px;
    padding: 13px 24px;
    font-size: 15px;
}

.btn--full {
    width: 100%;
}

.btn:disabled,
.btn.is-disabled {
    opacity: .5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn--ghost-light .icon,
.btn--light .icon {
    opacity: .9;
}

/* ---------- Forms ---------- */
.field {
    display: flex;
    flex-direction: column;
    gap: 7px;
    min-width: 0;
}

.field label {
    font-size: 13px;
    font-weight: 600;
    color: var(--ink-2);
}

.field .required {
    color: var(--rust);
}

.field input,
.field textarea,
.field select {
    width: 100%;
    min-height: 46px;
    padding: 10px 14px;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    background: var(--paper);
    font-size: 14px;
    color: var(--ink);
    transition: border-color .2s, box-shadow .2s, background .2s;
}

.field textarea {
    min-height: 110px;
    resize: vertical;
    line-height: 1.6;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
    outline: none;
    border-color: var(--teal-3);
    box-shadow: 0 0 0 3px rgba(47, 119, 106, .13);
    background: #fff;
}

.field input::placeholder,
.field textarea::placeholder {
    color: #a6a99f;
}

.field select {
    appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position: calc(100% - 18px) 20px, calc(100% - 13px) 20px;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    padding-right: 34px;
}

.field-hint {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.5;
}

.alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 13px 16px;
    border: 1px solid transparent;
    border-radius: 10px;
    font-size: 14px;
    margin-bottom: 18px;
}

.alert ul {
    margin-top: 4px;
    list-style: disc;
    padding-left: 18px;
}

.alert li {
    list-style: disc;
}

.alert--danger {
    background: var(--danger-bg);
    border-color: #ecd0ca;
    color: #84362a;
}

.alert--success {
    background: var(--success-bg);
    border-color: #cfe5d6;
    color: var(--success);
}

.alert--warning {
    background: var(--warning-bg);
    border-color: #eeddba;
    color: var(--warning);
}

.alert--info {
    background: var(--info-bg);
    border-color: #cfe0e7;
    color: var(--info);
}

.inline-alert {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 12px 14px;
    border: 1px solid #ecd0ca;
    border-radius: 9px;
    background: var(--danger-bg);
    color: #84362a;
    font-size: 13px;
}

/* ---------- Badges / pills ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    border-radius: var(--radius-pill);
    border: 1px solid transparent;
    font-family: var(--sans);
    font-size: 11px;
    font-weight: 600;
    line-height: 1.6;
    white-space: nowrap;
}

.badge--soft {
    background: var(--cream-2);
    border-color: var(--line);
    color: var(--ink-3);
}

.badge--marc {
    background: #eef2ee;
    border-color: #cfddd1;
    color: var(--teal-2);
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: .02em;
}

.badge--success {
    background: var(--success-bg);
    border-color: #cfe5d6;
    color: var(--success);
}

.badge--warning {
    background: var(--warning-bg);
    border-color: #eeddba;
    color: var(--warning);
}

.badge--danger {
    background: var(--danger-bg);
    border-color: #ecd0ca;
    color: var(--danger);
}

.badge--info {
    background: var(--info-bg);
    border-color: #cfe0e7;
    color: var(--info);
}

.badge--muted {
    background: #f0eee8;
    border-color: #ddd8cb;
    color: var(--muted);
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 4px 10px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--line);
    background: var(--paper);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .02em;
    color: var(--ink-3);
    white-space: nowrap;
}

.dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--muted-2);
    flex: 0 0 auto;
}

.dot.is-online,
.is-online .dot {
    background: #42a36d;
    box-shadow: 0 0 0 3px rgba(66, 163, 109, .13);
}

.dot.is-offline,
.is-offline .dot {
    background: var(--rust);
    box-shadow: 0 0 0 3px rgba(180, 95, 63, .12);
}

.status-pill.is-online {
    border-color: #cfe5d6;
    background: var(--success-bg);
    color: var(--success);
}

.status-pill.is-offline {
    border-color: #ecd0ca;
    background: var(--danger-bg);
    color: var(--danger);
}

/* ---------- Flash ---------- */
.flash-wrap {
    position: relative;
    z-index: 20;
}

.flash-wrap .container {
    padding-top: 16px;
}

.flash {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 44px 12px 16px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--paper);
    box-shadow: var(--shadow-sm);
    font-size: 14px;
    animation: flash-in .35s var(--ease);
    transition: opacity .24s var(--ease), transform .24s var(--ease);
}

.flash.is-dismissing {
    opacity: 0;
    transform: translateY(-5px);
    pointer-events: none;
}

.flash--success {
    border-color: #cfe5d6;
    background: var(--success-bg);
    color: var(--success);
}

.flash--danger {
    border-color: #ecd0ca;
    background: var(--danger-bg);
    color: var(--danger);
}

.flash--warning {
    border-color: #eeddba;
    background: var(--warning-bg);
    color: var(--warning);
}

.flash--info {
    border-color: #cfe0e7;
    background: var(--info-bg);
    color: var(--info);
}

.flash-close {
    position: absolute;
    right: 9px;
    top: 50%;
    transform: translateY(-50%);
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: currentColor;
    opacity: .6;
}

.flash-close:hover {
    opacity: 1;
    background: rgba(0, 0, 0, .05);
}

@keyframes flash-in {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---------- Panels / empty / pagination ---------- */
.panel {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.empty-panel,
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 58px 24px;
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius);
    background: rgba(255, 253, 248, .55);
}

.empty-icon {
    display: grid;
    place-items: center;
    width: 58px;
    height: 58px;
    margin-bottom: 16px;
    border-radius: 50%;
    background: var(--sage-2);
    color: var(--teal-2);
}

.empty-panel h3,
.empty-state h3 {
    font-size: 21px;
    margin-bottom: 6px;
}

.empty-panel p,
.empty-state p {
    color: var(--muted);
    font-size: 14px;
    max-width: 460px;
    margin-bottom: 18px;
}

.pagination {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.page-btn {
    display: grid;
    place-items: center;
    min-width: 34px;
    height: 34px;
    padding: 0 7px;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--ink-3);
    font-size: 13px;
    font-weight: 500;
    transition: background .15s, border-color .15s, color .15s;
}

.page-btn:hover {
    background: var(--sage-2);
    border-color: var(--line);
    color: var(--teal);
}

.page-btn.is-current {
    background: var(--teal);
    border-color: var(--teal);
    color: var(--cream);
    font-weight: 600;
}

.page-btn.is-disabled {
    opacity: .35;
    cursor: default;
}

.page-ellipsis {
    color: var(--muted-2);
    font-size: 12px;
    padding: 0 2px;
}

/* ---------- Spinner ---------- */
.spinner {
    display: inline-block;
    width: 15px;
    height: 15px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin .7s linear infinite;
    vertical-align: -2px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ---------- Tables (shared) ---------- */
.table-card {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.table-scroll {
    overflow-x: auto;
    scrollbar-width: thin;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}

.data-table thead th {
    padding: 12px 15px;
    text-align: left;
    font-family: var(--sans);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--muted);
    background: #f8f5ed;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

.data-table tbody td {
    padding: 13px 15px;
    border-bottom: 1px solid #eee8dc;
    vertical-align: middle;
    color: var(--ink-2);
}

.data-table tbody tr:last-child td {
    border-bottom: 0;
}

.data-table tbody tr {
    transition: background .15s;
}

.data-table tbody tr:hover {
    background: #fbf8f1;
}

.table-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    padding: 14px 16px;
    border-top: 1px solid var(--line);
    background: #fcfaf5;
}

.table-range {
    font-size: 12px;
    color: var(--muted);
}

.table-link {
    color: var(--teal-2);
    font-weight: 600;
}

.table-link:hover {
    color: var(--rust);
}

/* ---------- Cover tones (shared) ---------- */
.cover-tone-0 { --cover-bg: #1b514b; --cover-ink: #f8f1df; --cover-accent: #d2ac66; }
.cover-tone-1 { --cover-bg: #e6d6ba; --cover-ink: #43372a; --cover-accent: #a85b3c; }
.cover-tone-2 { --cover-bg: #8e4d37; --cover-ink: #fbf1e1; --cover-accent: #e7c78e; }
.cover-tone-3 { --cover-bg: #2f4358; --cover-ink: #f1ebdf; --cover-accent: #b9a173; }
.cover-tone-4 { --cover-bg: #dce5d8; --cover-ink: #294039; --cover-accent: #8d5a3f; }
.cover-tone-5 { --cover-bg: #5d6049; --cover-ink: #f7f0dd; --cover-accent: #d8ba85; }

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