:root {
    --bg: #f5ecdf;
    --panel: #fffaf2;
    --card: rgba(255, 255, 255, 0.82);
    --line: #e7d4b2;
    --ink: #1e293b;
    --muted: #6b7280;
    --accent: #9a3412;
    --accent-strong: #7c2d12;
    --success: #166534;
    --danger: #b91c1c;
    --shadow: 0 22px 50px rgba(86, 52, 15, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    color: var(--ink);
    background:
        radial-gradient(circle at top left, rgba(154, 52, 18, 0.12), transparent 28%),
        linear-gradient(135deg, #f7efe3 0%, #f2e6d5 50%, #efe5d7 100%);
}

body.sheet-open {
    overflow: hidden;
}

a {
    color: inherit;
}

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

.admin-header,
.panel,
.card {
    background: rgba(255, 250, 242, 0.94);
    border: 1px solid var(--line);
    border-radius: 24px;
    box-shadow: var(--shadow);
}

.admin-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 20px 24px;
    margin-bottom: 24px;
}

.admin-title h1,
.page-title h1 {
    margin: 0;
    font-size: 28px;
}

.admin-title p,
.page-title p,
.muted {
    margin: 8px 0 0;
    color: var(--muted);
}

.admin-actions,
.row-actions,
.button-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.button,
button,
input[type="submit"] {
    appearance: none;
    border: 0;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: #fff;
    padding: 12px 18px;
    font-size: 14px;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.button.secondary,
button.secondary {
    background: rgba(154, 52, 18, 0.08);
    color: var(--accent-strong);
}

.button.danger,
button.danger {
    background: #b91c1c;
}

.button.ghost,
button.ghost {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--line);
}

.grid {
    display: grid;
    gap: 24px;
}

.grid.two {
    grid-template-columns: 1.5fr 1fr;
}

.panel {
    padding: 24px;
}

.template-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 20px;
}

.template-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 22px;
    overflow: hidden;
}

.template-card img {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 10;
    object-fit: cover;
    background: #f8f3eb;
}

.template-card .body {
    padding: 18px;
}

.template-card h3 {
    margin: 0 0 8px;
    font-size: 19px;
}

.meta-list {
    display: grid;
    gap: 8px;
    color: var(--muted);
    font-size: 14px;
}

.status {
    display: inline-flex;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
}

.status.active {
    background: rgba(22, 101, 52, 0.12);
    color: var(--success);
}

.status.inactive {
    background: rgba(185, 28, 28, 0.12);
    color: var(--danger);
}

.notice {
    padding: 14px 16px;
    border-radius: 16px;
    margin-bottom: 18px;
    font-size: 14px;
}

.notice.success {
    background: rgba(22, 101, 52, 0.12);
    color: var(--success);
}

.notice.error {
    background: rgba(185, 28, 28, 0.12);
    color: var(--danger);
}

.form-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid.one {
    grid-template-columns: 1fr;
}

.template-editor {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
    gap: 24px;
    align-items: start;
}

.template-editor-preview,
.template-editor-form {
    min-width: 0;
}

.editor-canvas {
    position: relative;
    width: 100%;
    margin-top: 18px;
    border-radius: 24px;
    overflow: hidden;
    background: #fff;
    border: 1px solid var(--line);
    box-shadow: 0 18px 48px rgba(58, 45, 27, 0.12);
}

.editor-canvas img {
    display: block;
    width: 100%;
    height: auto;
}

.editor-name-box {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 22px 10px 14px;
    border: 3px solid #ef4444;
    background: rgba(255, 255, 255, 0.42);
    color: #111111;
    cursor: move;
    user-select: none;
    touch-action: none;
    text-align: center;
    backdrop-filter: blur(1px);
    box-shadow:
        0 10px 22px rgba(239, 68, 68, 0.18),
        inset 0 0 0 1px rgba(255, 255, 255, 0.86);
}

.editor-name-box span {
    display: block;
    width: 100%;
    pointer-events: none;
}

.editor-name-tag {
    position: absolute;
    left: 10px;
    top: -13px;
    width: auto !important;
    padding: 3px 10px;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.02em;
    box-shadow: 0 8px 16px rgba(239, 68, 68, 0.24);
}

.editor-resize-handle {
    position: absolute;
    right: -11px;
    top: 50%;
    width: 22px;
    height: 22px;
    padding: 0;
    border-radius: 999px;
    border: 3px solid #fff;
    background: #ef4444;
    transform: translateY(-50%);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.16);
    cursor: ew-resize;
}

.editor-meta {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 16px;
    color: var(--muted);
    font-size: 14px;
}

.template-editor-actions {
    grid-column: 1 / -1;
}

label {
    display: grid;
    gap: 8px;
    font-size: 14px;
    color: var(--muted);
}

input,
select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px 14px;
    font-size: 15px;
    background: rgba(255, 255, 255, 0.9);
}

table {
    width: 100%;
    border-collapse: collapse;
}

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

.admin-table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.admin-table {
    min-width: 820px;
}

.admin-table td form {
    margin: 0;
}

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-card,
.public-shell,
.message-card {
    width: min(520px, 100%);
    background: rgba(255, 250, 242, 0.95);
    border: 1px solid var(--line);
    border-radius: 28px;
    box-shadow: var(--shadow);
    padding: 28px;
}

.message-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.public-shell {
    width: min(780px, calc(100% - 24px));
    margin: 20px auto;
}

.certificate-preview {
    position: relative;
    width: 100%;
    border-radius: 24px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 18px 48px rgba(58, 45, 27, 0.16);
}

.certificate-preview img {
    display: block;
    width: 100%;
    height: auto;
}

.certificate-preview-guarded {
    isolation: isolate;
}

.guarded-preview-image {
    filter: blur(2.8px) saturate(0.92);
    transform: scale(1.01);
    transform-origin: center center;
}

.certificate-preview-guarded::after {
    content: "";
    position: absolute;
    inset: 0;
    background:
        linear-gradient(135deg, rgba(255, 255, 255, 0.18), rgba(154, 52, 18, 0.06)),
        repeating-linear-gradient(
            -24deg,
            rgba(154, 52, 18, 0.08) 0,
            rgba(154, 52, 18, 0.08) 14px,
            rgba(255, 255, 255, 0.02) 14px,
            rgba(255, 255, 255, 0.02) 28px
        );
    pointer-events: none;
    z-index: 1;
}

.name-overlay {
    position: absolute;
    transform-origin: left top;
    white-space: nowrap;
    color: #111111;
    text-shadow:
        0 1px 0 rgba(255, 255, 255, 0.95),
        0 2px 10px rgba(255, 255, 255, 0.5);
    z-index: 2;
}

.preview-guard-mark {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    gap: 6px;
    text-align: center;
    pointer-events: none;
    z-index: 2;
}

.preview-guard-mark span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 7px 16px;
    border-radius: 999px;
    background: rgba(255, 250, 242, 0.72);
    border: 1px solid rgba(154, 52, 18, 0.16);
    color: rgba(124, 45, 18, 0.9);
    font-weight: 700;
    letter-spacing: 0.08em;
    backdrop-filter: blur(6px);
}

.preview-guard-mark-elegant {
    align-content: end;
    justify-items: center;
    gap: 12px;
    padding: 20px 20px 22px;
}

.preview-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 9px 20px;
    border-radius: 999px;
    box-shadow:
        0 10px 22px rgba(124, 45, 18, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.preview-pill-accent {
    background: rgba(255, 245, 240, 0.92);
    color: var(--accent-strong);
    border: 1px solid rgba(154, 52, 18, 0.18);
    font-size: 16px;
    font-weight: 800;
    letter-spacing: 0.08em;
}

.preview-pill-soft {
    background: rgba(255, 250, 242, 0.88);
    color: #6b3f22;
    border: 1px solid rgba(154, 52, 18, 0.12);
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.public-copy h1 {
    margin: 0 0 10px;
    font-size: 28px;
}

.landing-title {
    width: 100%;
    margin: 0 auto 10px;
    text-align: center;
    white-space: nowrap;
    font-size: clamp(14px, 3.35vw, 24px);
    letter-spacing: -0.06em;
    line-height: 1.1;
}

.public-copy p {
    margin: 0;
    color: var(--muted);
    line-height: 1.7;
}

.public-form {
    display: grid;
    gap: 16px;
    margin-top: 22px;
}

.loading-box {
    padding: 16px 18px;
    border-radius: 16px;
    background: rgba(154, 52, 18, 0.08);
    color: var(--accent-strong);
    font-size: 14px;
}

.confirm-sheet {
    position: fixed;
    inset: 0;
    z-index: 40;
}

.confirm-sheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(30, 41, 59, 0.28);
    backdrop-filter: blur(6px);
}

.confirm-sheet-panel {
    position: absolute;
    left: 50%;
    bottom: max(18px, env(safe-area-inset-bottom));
    transform: translateX(-50%);
    width: min(520px, calc(100% - 24px));
    padding: 22px;
    border-radius: 28px;
    border: 1px solid rgba(231, 212, 178, 0.92);
    background: rgba(255, 250, 242, 0.98);
    box-shadow: 0 24px 60px rgba(30, 41, 59, 0.18);
}

.confirm-sheet-tag {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    padding: 0 12px;
    border-radius: 999px;
    background: rgba(154, 52, 18, 0.1);
    color: var(--accent-strong);
    font-size: 13px;
    font-weight: 700;
}

.confirm-sheet-panel h2 {
    margin: 14px 0 8px;
    font-size: 26px;
    line-height: 1.2;
}

.confirm-sheet-copy {
    margin: 0;
    color: var(--muted);
    line-height: 1.7;
}

.confirm-sheet-name {
    margin-top: 16px;
    padding: 18px 20px;
    border-radius: 20px;
    background: linear-gradient(135deg, #fff8ef, #fff4e8);
    border: 1px solid rgba(154, 52, 18, 0.14);
    color: var(--accent-strong);
    font-size: 30px;
    font-weight: 800;
    text-align: center;
    letter-spacing: 0.04em;
}

.confirm-sheet-actions {
    margin-top: 18px;
    justify-content: stretch;
}

.confirm-sheet-actions .button {
    flex: 1 1 0;
}

.result-image {
    width: 100%;
    border-radius: 20px;
    display: block;
    border: 1px solid var(--line);
}

.result-tip-card {
    display: grid;
    gap: 8px;
    margin-top: 18px;
    padding: 18px 20px;
    border-radius: 18px;
    border: 1px solid rgba(154, 52, 18, 0.14);
    background: rgba(255, 247, 237, 0.92);
    color: var(--accent-strong);
}

.qr-box {
    margin-top: 14px;
    padding: 14px;
    background: #fff;
    border: 1px dashed var(--line);
    border-radius: 18px;
    display: inline-block;
}

.qr-box canvas,
.qr-box img {
    display: block;
}

.small {
    font-size: 13px;
}

.qr-share-card {
    margin-top: 18px;
    padding: 18px;
    border-radius: 24px;
    border: 1px solid rgba(154, 52, 18, 0.16);
    background:
        radial-gradient(circle at top left, rgba(154, 52, 18, 0.08), transparent 32%),
        linear-gradient(145deg, #fff8ef 0%, #fff4e6 55%, #f8e7d2 100%);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.qr-share-card-head,
.qr-share-card-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.qr-share-badge,
.qr-share-status {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 8px 14px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
}

.qr-share-badge {
    background: rgba(154, 52, 18, 0.12);
    color: var(--accent-strong);
}

.qr-share-status {
    background: rgba(22, 101, 52, 0.12);
    color: var(--success);
}

.qr-share-card-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 220px;
    gap: 20px;
    align-items: center;
    margin-top: 16px;
    margin-bottom: 16px;
}

.qr-share-copy h4 {
    margin: 14px 0 0;
    font-size: 24px;
    line-height: 1.2;
    color: var(--accent-strong);
}

.qr-share-copy p {
    margin: 12px 0 0;
    color: var(--ink);
    font-size: 16px;
    line-height: 1.65;
}

.qr-share-template-name {
    margin: 0;
    color: var(--ink);
    font-size: 30px;
    font-weight: 700;
    line-height: 1.25;
    letter-spacing: -0.03em;
}

.qr-share-valid {
    margin-top: 14px;
    color: var(--accent-strong);
    font-size: 14px;
    font-weight: 600;
}

.qr-share-code {
    margin-top: 10px;
    color: #334155;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.04em;
    font-family: Consolas, "Courier New", monospace;
    word-break: break-all;
}

.qr-share-tip {
    margin-top: 12px;
    color: var(--muted);
    line-height: 1.7;
    font-size: 14px;
}

.qr-share-qrcode {
    display: grid;
    place-items: center;
}

.qr-share-qrcode .qr-render {
    padding: 16px;
    border-radius: 28px;
    background: #fff;
    box-shadow:
        0 18px 40px rgba(22, 59, 99, 0.12),
        inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.qr-share-card-foot {
    padding-top: 14px;
    border-top: 1px dashed rgba(124, 45, 18, 0.18);
    color: var(--muted);
    font-size: 13px;
}

.qr-share-actions {
    margin-top: 16px;
}

.qr-self-check-result {
    min-height: 20px;
    margin-top: 10px;
    color: var(--muted);
}

.qr-self-check-result.success {
    color: var(--success);
    font-weight: 600;
}

.qr-self-check-result.error {
    color: var(--danger);
    font-weight: 600;
}

.qr-self-check-result.warn {
    color: var(--accent-strong);
    font-weight: 600;
}

@media (max-width: 900px) {
    .grid.two,
    .form-grid,
    .template-editor {
        grid-template-columns: 1fr;
    }

    .qr-share-card-body {
        grid-template-columns: 1fr;
    }

    .admin-header {
        align-items: flex-start;
        flex-direction: column;
    }
}

@media (max-width: 760px) {
    .shell {
        width: min(100%, calc(100% - 16px));
        margin: 16px auto;
    }

    .admin-header,
    .panel,
    .card {
        border-radius: 20px;
    }

    .admin-header,
    .panel {
        padding: 18px;
    }

    .admin-title h1,
    .page-title h1 {
        font-size: 24px;
    }

    .admin-actions,
    .button-row {
        width: 100%;
    }

    .admin-actions .button,
    .button-row .button,
    .button-row button,
    .button-row a {
        flex: 1 1 0;
    }

    .admin-table {
        min-width: 0;
    }

    .admin-records-table thead {
        display: none;
    }

    .admin-records-table,
    .admin-records-table tbody,
    .admin-records-table tr,
    .admin-records-table td {
        display: block;
        width: 100%;
    }

    .admin-records-table tr {
        padding: 14px 0;
        border-bottom: 1px solid var(--line);
    }

    .admin-records-table td {
        display: grid;
        grid-template-columns: 72px minmax(0, 1fr);
        gap: 8px;
        align-items: start;
        padding: 8px 0;
        border-bottom: 0;
        word-break: break-word;
        font-size: 13px;
        line-height: 1.6;
    }

    .admin-records-table td::before {
        content: attr(data-label);
        color: var(--muted);
        font-weight: 700;
        font-size: 12px;
    }

    .admin-records-table td[data-label="操作"] form,
    .admin-records-table td[data-label="操作"] .button {
        width: 100%;
    }

    .template-list {
        grid-template-columns: 1fr;
    }

    .template-card .body {
        padding: 16px;
    }

    .row-actions {
        width: 100%;
    }

    .row-actions .button,
    .row-actions button,
    .row-actions a {
        flex: 1 1 calc(50% - 10px);
    }

    .qr-share-card {
        padding: 16px;
    }

    .qr-share-template-name {
        font-size: 24px;
    }

    .qr-share-copy h4 {
        font-size: 20px;
    }

    .qr-share-valid,
    .qr-share-code,
    .small {
        font-size: 13px;
    }
}
