:root {
    color-scheme: light;
    --ink: #172033;
    --muted: #687386;
    --line: #dfe4ec;
    --soft: #f5f7fa;
    --white: #fff;
    --blue: #2f66e8;
    --blue-dark: #1f4fc7;
    --blue-soft: #edf3ff;
    --green: #16805d;
    --red: #b93838;
    --shadow: 0 16px 45px rgba(23, 32, 51, .08);
    font-family: Inter, "Microsoft YaHei UI", "PingFang SC", system-ui, sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--ink);
    background: radial-gradient(circle at 85% 8%, #eaf1ff 0, transparent 26rem), #f7f8fb;
}

button,
input {
    font: inherit;
}

button {
    cursor: pointer;
}

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

.hidden {
    display: none !important;
}

.topbar {
    position: sticky;
    z-index: 20;
    top: 0;
    height: 68px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 max(24px, calc((100vw - 1180px) / 2));
    border-bottom: 1px solid rgba(223, 228, 236, .85);
    background: rgba(255, 255, 255, .86);
    backdrop-filter: blur(14px);
}

.brand {
    display: inline-flex;
    align-items: center;
}

.brand-logo {
    display: block;
    width: auto;
    height: 48px;
    object-fit: contain;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.language-button {
    width: 38px;
    height: 38px;
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--ink);
    background: var(--white);
    font-weight: 700;
}

.privacy-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border-radius: 999px;
    padding: 8px 12px;
    color: var(--green);
    background: #ecf8f3;
    font-size: 13px;
    font-weight: 600;
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #20a777;
    box-shadow: 0 0 0 4px rgba(32, 167, 119, .12);
}

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

.hero {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 28px;
    margin-bottom: 34px;
}

.eyebrow {
    margin: 0 0 12px;
    color: var(--blue);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .16em;
}

h1 {
    margin: 0;
    font-size: clamp(32px, 5vw, 56px);
    line-height: 1.06;
    letter-spacing: -.04em;
}

.hero-actions {
    display: grid;
    flex: 0 0 180px;
    gap: 10px;
    padding-top: 2px;
}

.summary-action-row {
    position: relative;
}

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

.hero-copy {
    max-width: 760px;
    margin: 18px 0 0;
    color: var(--muted);
    font-size: 17px;
    line-height: 1.75;
}

.hero-note {
    margin: 10px 0 0;
    color: #395a50;
    font-size: 13px;
    font-weight: 700;
}

.steps {
    list-style: none;
    display: flex;
    align-items: center;
    margin: 0 0 18px;
    padding: 0;
}

.steps li {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #98a1b1;
    font-size: 13px;
    font-weight: 700;
}

.steps li:not(:last-child)::after {
    width: 58px;
    height: 1px;
    margin: 0 14px;
    background: var(--line);
    content: "";
}

.steps b {
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #e8ebf0;
}

.steps li.active {
    color: var(--blue);
}

.steps li.active b {
    color: white;
    background: var(--blue);
}

.steps li.done b {
    color: white;
    background: var(--green);
}

.card {
    margin-top: 18px;
    border: 1px solid rgba(223, 228, 236, .9);
    border-radius: 20px;
    background: var(--white);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 22px;
    padding: 23px 26px;
    border-bottom: 1px solid var(--line);
}

.section-heading > div:first-child {
    display: flex;
    align-items: center;
    gap: 12px;
}

.section-heading h2,
.panel-heading h3 {
    margin: 0;
    font-size: 19px;
    letter-spacing: -.02em;
}

.section-heading p {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
    text-align: right;
}

.section-number {
    color: var(--blue);
    font-size: 11px;
    font-weight: 900;
    letter-spacing: .08em;
}

.dropzone {
    margin: 26px;
    min-height: 190px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 9px;
    border: 1.5px dashed #b8c3d6;
    border-radius: 16px;
    background: #fbfcfe;
    text-align: center;
    transition: .2s ease;
    cursor: pointer;
}

.dropzone:hover,
.dropzone.dragging {
    border-color: var(--blue);
    background: var(--blue-soft);
    transform: translateY(-1px);
}

.upload-icon {
    display: grid;
    place-items: center;
    width: 50px;
    height: 50px;
    border-radius: 14px;
    color: var(--blue);
    background: var(--blue-soft);
    font-size: 27px;
}

.dropzone strong {
    font-size: 16px;
}

.dropzone small,
.dropzone span {
    color: var(--muted);
}

.choose-file-chip {
    border-radius: 10px;
    padding: 9px 14px;
    color: white !important;
    background: var(--blue);
    font-size: 13px;
    font-weight: 700;
}

.error-stack {
    display: grid;
    gap: 8px;
    margin: 0 26px 26px;
}

.error-message {
    margin: 0;
    border: 1px solid #f0c5ca;
    border-radius: 10px;
    padding: 10px 13px;
    color: var(--red);
    background: #fff4f5;
    font-size: 13px;
}

.workbench-grid {
    display: grid;
    grid-template-columns: minmax(250px, .9fr) minmax(340px, 1.4fr) minmax(250px, .9fr);
    gap: 16px;
    padding: 18px 26px 26px;
}

.panel {
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--white);
}

.panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px;
    border-bottom: 1px solid var(--line);
}

.panel-heading span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.document-list {
    display: grid;
    gap: 9px;
    margin: 0;
    padding: 14px;
    list-style: none;
}

.document-card {
    display: grid;
    grid-template-columns: 24px minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    min-height: 70px;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 9px;
    background: #fbfcfe;
}

.document-number {
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border-radius: 8px;
    color: var(--blue);
    background: var(--blue-soft);
    font-size: 12px;
    font-weight: 800;
}

.document-details {
    min-width: 0;
}

.document-details strong {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
}

.document-details small {
    color: var(--muted);
    font-size: 11px;
}

.document-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.icon-button {
    min-width: 32px;
    min-height: 32px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    background: var(--white);
    font-size: 16px;
    line-height: 1;
}

.icon-button.danger {
    color: var(--red);
}

.preview-panel {
    min-width: 0;
}

.preview-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
}

.panel-button {
    min-height: 34px;
    margin-left: auto;
    padding: 0 12px;
    font-size: 12px;
}

.preview-stage {
    position: relative;
    min-height: 430px;
    display: grid;
    place-items: center;
    padding: 16px;
    background: #eef2f6;
}

#previewCanvas {
    display: block;
    max-width: 100%;
    max-height: 520px;
    border-radius: 8px;
    background: white;
    box-shadow: 0 10px 24px rgba(23, 32, 51, .14);
}

.signature-layer {
    position: absolute;
    pointer-events: auto;
}

.signature-item {
    position: absolute;
    display: grid;
    border: 1px dashed #687de6;
    border-radius: 4px;
    padding: 4px;
    background: rgba(238, 241, 255, .78);
    pointer-events: auto;
    touch-action: none;
    user-select: none;
    cursor: move;
}

.signature-item img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
}

.signature-remove {
    position: absolute;
    top: -11px;
    right: -11px;
    min-width: 20px;
    min-height: 20px;
    border: 1px solid #d0d8e7;
    border-radius: 50%;
    color: #23304a;
    background: white;
    font-size: 12px;
    line-height: 1;
}

.signature-resize {
    position: absolute;
    right: -7px;
    bottom: -7px;
    min-width: 16px;
    min-height: 16px;
    border: 0;
    color: var(--blue);
    background: transparent;
    font-size: 13px;
    cursor: nwse-resize;
}

.field-grid {
    display: grid;
    gap: 12px;
    padding: 16px;
}

.field {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.field input {
    min-height: 42px;
    border: 1px solid #cfd6e2;
    border-radius: 10px;
    padding: 0 12px;
    color: var(--ink);
    background: white;
}

.field input:focus-visible,
.icon-button:focus-visible,
.secondary-button:focus-visible,
.primary-button:focus-visible,
.language-button:focus-visible {
    outline: 0;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(47, 102, 232, .14);
}

.panel-actions {
    padding: 0 16px 16px;
}

.primary-button,
.secondary-button {
    min-height: 42px;
    border-radius: 10px;
    border: 1px solid transparent;
    padding: 0 17px;
    font-weight: 760;
}

.primary-button {
    width: 100%;
    color: white;
    background: var(--blue);
    box-shadow: 0 7px 16px rgba(47, 102, 232, .2);
}

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

.secondary-button {
    color: var(--ink);
    border-color: var(--line);
    background: var(--white);
}

.status-text {
    min-height: 20px;
    margin: 0;
    padding: 0 16px 16px;
    color: var(--muted);
    font-size: 13px;
}

.empty {
    margin: 0;
    padding: 22px 14px 20px;
    color: #98a1b1;
    text-align: center;
    font-size: 13px;
}

.busy-overlay {
    position: fixed;
    z-index: 60;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgba(23, 32, 51, .3);
}

.busy-card {
    width: min(360px, calc(100% - 32px));
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 20px;
    background: var(--white);
    box-shadow: 0 30px 70px rgba(23, 32, 51, .23);
}

.busy-card p {
    margin: 12px 0;
    font-size: 14px;
    font-weight: 700;
}

.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--blue-soft);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.progress-track {
    height: 8px;
    border-radius: 999px;
    background: #edf1f7;
    overflow: hidden;
}

.progress-value {
    width: 24%;
    height: 100%;
    background: var(--blue);
    transition: width .2s ease;
}

.toast-region {
    position: fixed;
    z-index: 70;
    right: 16px;
    bottom: 16px;
    display: grid;
    gap: 8px;
}

.toast {
    min-width: 220px;
    max-width: 320px;
    border-radius: 10px;
    padding: 11px 13px;
    color: white;
    background: #23304a;
    box-shadow: 0 12px 28px rgba(14, 22, 36, .24);
    font-size: 13px;
    line-height: 1.5;
}

.toast.success {
    background: #1f7658;
}

.toast.error {
    background: #a33644;
}

.signature-dialog-backdrop {
    position: fixed;
    z-index: 80;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(23, 32, 51, .34);
}

.signature-dialog {
    width: min(560px, 100%);
    border: 1px solid var(--line);
    border-radius: 18px;
    background: white;
    box-shadow: 0 24px 70px rgba(23, 32, 51, .22);
    padding: 18px;
}

.signature-dialog h3 {
    margin: 0 0 8px;
    font-size: 18px;
}

.signature-dialog p {
    margin: 0 0 10px;
    color: var(--muted);
    font-size: 13px;
}

#signatureCanvas {
    width: 100%;
    height: auto;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: white;
    touch-action: none;
}

.summary-help-button {
    position: absolute;
    top: 50%;
    left: -38px;
    width: 18px;
    height: 18px;
    transform: translateY(-50%);
    padding: 0;
    border: 1px solid #2f66e8;
    border-radius: 50%;
    color: var(--blue);
    background: var(--white);
    font-size: 11px;
    font-weight: 700;
    line-height: 16px;
    box-shadow: none;
    transition: border-color .2s ease, background-color .2s ease, color .2s ease;
}

.summary-help-button:hover,
.summary-help-button:focus-visible {
    border-color: var(--blue);
    background: #dce8ff;
}

.summary-help-text {
    white-space: pre-line;
    line-height: 1.8;
}

.summary-password-input {
    width: 100%;
    box-sizing: border-box;
    min-height: 42px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    outline: none;
}

.summary-password-input:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(47, 102, 232, .14);
}

.signature-dialog-actions {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    margin-top: 12px;
}

.dialog-primary {
    width: auto;
}

.saved-signatures {
    margin-top: 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fbfcfe;
    padding: 10px;
}

.saved-signatures strong {
    display: block;
    margin-bottom: 6px;
    font-size: 12px;
}

#savedSignatureList {
    display: grid;
    gap: 6px;
}

.saved-signature-row {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 12px;
}

.saved-signature-row button {
    min-height: 30px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0 10px;
    color: var(--ink);
    background: white;
    font-size: 12px;
}

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

@media (max-width: 850px) {
    .hero {
        flex-direction: column;
        margin-bottom: 24px;
    }

    .steps li:not(:last-child)::after {
        width: 30px;
    }

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

    .section-heading {
        flex-direction: column;
        align-items: flex-start;
    }

    .section-heading p {
        text-align: left;
    }
}

@media (max-width: 560px) {
    .topbar {
        padding-left: 10px;
        padding-right: 10px;
    }

    .brand-logo {
        height: 42px;
    }

    .privacy-pill {
        display: none;
    }

    .page-shell {
        width: calc(100% - 20px);
        padding-top: 32px;
    }

    .steps span {
        display: none;
    }

    .steps li:not(:last-child)::after {
        width: 16px;
        margin: 0 8px;
    }

    .dropzone,
    .error-stack {
        margin-left: 14px;
        margin-right: 14px;
    }

    .workbench-grid {
        padding: 14px;
    }

    .preview-stage {
        min-height: 320px;
    }

    .signature-dialog-actions {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}
