:root {
    --bg: #f4f7fb;
    --card: #ffffff;
    --text: #14253d;
    --muted: #68778b;
    --line: #d8e2ee;
    --primary: #3164A3;
    --primary-dark: #244d80;
    --primary-soft: #eaf1f9;
    --accent: #FF0000;
    --accent-dark: #c90000;
    --accent-soft: #fff0f0;
    --danger: var(--accent-dark);
    --danger-soft: var(--accent-soft);
    --warning: #9b0000;
    --warning-soft: #fff4f4;
    --shadow: 0 8px 30px rgba(49, 100, 163, .10);
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input { font: inherit; }
h1, h2 { line-height: 1.2; margin-top: 0; }
h1 { font-size: clamp(1.55rem, 3vw, 2.15rem); margin-bottom: .4rem; }
h2 { font-size: 1.15rem; margin-bottom: 1rem; }
p { margin: .45rem 0 1rem; }

.topbar { min-height: 66px; padding: 0 max(20px, calc((100% - 1180px) / 2)); display: flex; align-items: center; justify-content: space-between; gap: 24px; background: #fff; border-top: 3px solid var(--accent); border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; }
.brand:hover { text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 11px; color: #fff; background: var(--primary); box-shadow: inset 0 -3px 0 var(--accent); font-size: .88rem; }
.official-logo { display: block; width: auto; height: 46px; object-fit: contain; }
.topnav { display: flex; align-items: center; gap: 22px; font-size: .94rem; }
.topnav form { margin: 0; }
.page-shell { width: min(1180px, calc(100% - 32px)); margin: 32px auto 60px; }
.footer { padding: 20px 16px 30px; text-align: center; color: var(--muted); font-size: .88rem; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 24px; }
.page-heading, .card-heading, .document-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.page-heading { margin-bottom: 22px; }
.muted { color: var(--muted); }
.eyebrow { color: var(--accent-dark); font-weight: 700; font-size: .78rem; text-transform: uppercase; letter-spacing: .07em; }

.button { display: inline-flex; min-height: 44px; align-items: center; justify-content: center; border: 1px solid transparent; border-radius: 10px; padding: 10px 17px; font-weight: 650; cursor: pointer; text-align: center; }
.button:hover { text-decoration: none; }
.button:disabled { cursor: wait; opacity: .62; }
.button-primary { color: #fff; background: var(--primary); }
.button-primary:hover { background: var(--primary-dark); }
.button-secondary { color: var(--text); background: #fff; border-color: var(--line); }
.button-secondary:hover { border-color: var(--primary); }
.button-danger { color: var(--danger); background: var(--danger-soft); border-color: #ffb8b8; }
.button-small { min-height: 38px; padding: 7px 12px; font-size: .88rem; }
.button-wide { width: 100%; }
.link-button { border: 0; padding: 0; color: var(--primary); background: transparent; cursor: pointer; }
.button-row { display: flex; gap: 12px; flex-wrap: wrap; }
.button-column { display: grid; gap: 10px; margin-top: 22px; }

.form-card { max-width: 850px; }
.form-stack { display: grid; gap: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.choice-group { margin: 0; padding: 16px; border: 1px solid var(--line); border-radius: 10px; }
.choice-group legend { padding: 0 6px; font-weight: 700; }
.choice-list { display: grid; gap: 12px; margin-top: 14px; }
.choice-detail { color: var(--muted); font-weight: 400; }
.document-upload-group { display: grid; gap: 14px; }
.document-upload-list { display: grid; gap: 12px; }
.document-upload-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 10px; background: #f8fafd; }
.document-upload-row input[type="file"] { background: #fff; }
.document-remove { margin-bottom: 1px; }
.add-document-button { justify-self: start; }
label { display: grid; gap: 7px; font-weight: 650; font-size: .92rem; }
input[type="text"], input[type="email"], input[type="password"], input[type="tel"] { width: 100%; min-height: 46px; border: 1px solid #bdcada; border-radius: 9px; padding: 10px 12px; color: var(--text); background: #fff; font-weight: 400; }
input::placeholder { color: #9aa8ba; font-weight: 400; opacity: 1; }
input:disabled { color: #8996a8; background: #f1f4f8; border-color: #d5dde7; cursor: not-allowed; }
.disabled-field small { margin-top: -2px; }
input:focus { outline: 3px solid rgba(49, 100, 163, .18); border-color: var(--primary); }
input[type="file"] { border: 1px dashed #9fb1c7; border-radius: 9px; padding: 16px; background: #f8fafd; }
small { color: var(--muted); font-weight: 400; }
.notice, .success-panel { padding: 14px 16px; border-radius: 10px; background: var(--warning-soft); color: #860000; }
.notice { border-left: 4px solid var(--accent); }
.success-panel { background: var(--primary-soft); color: var(--primary-dark); border-left: 4px solid var(--primary); }

.auth-card { width: min(440px, 100%); margin: 70px auto; }
.flash, .form-error { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: start; gap: 12px; margin: 0 0 16px; padding: 13px 14px 13px 16px; border-radius: 10px; border: 1px solid; }
.flash-success { color: var(--primary-dark); background: var(--primary-soft); border-color: #b8cee7; }
.flash-error { color: #8a0000; background: var(--danger-soft); border-color: #ffb8b8; }
.flash-demo { color: var(--warning); background: var(--warning-soft); border-color: #ffb8b8; font-weight: 700; }
.form-error { margin: 0; color: #8a0000; background: var(--danger-soft); border-color: #ffb8b8; }
.message-close { width: 28px; height: 28px; margin: -4px -4px -4px 0; border: 0; border-radius: 7px; color: currentColor; background: transparent; cursor: pointer; font-size: 1.35rem; line-height: 1; }
.message-close:hover { background: rgba(20, 37, 61, .08); }

.table-card { padding: 0; overflow: hidden; }
.table-card > h2, .table-card > p { margin: 22px 24px; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: 14px 16px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); background: #f8fafd; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:last-child td { border-bottom: 0; }
.empty-state { padding: 55px 24px; text-align: center; }
.contract-delete-column, .contract-delete-cell { width: 1%; padding-left: 6px; padding-right: 12px; text-align: center; }
.contract-delete-form { display: inline; margin: 0; }
.contract-delete-button { display: inline-grid; width: 32px; height: 32px; padding: 0; place-items: center; border: 1px solid #ffb8b8; border-radius: 8px; color: var(--danger); background: var(--danger-soft); cursor: pointer; font-size: 1.45rem; font-weight: 400; line-height: 1; }
.contract-delete-button:hover { color: #fff; background: var(--danger); border-color: var(--danger); }
.contract-delete-button:focus-visible { outline: 3px solid rgba(255, 0, 0, .18); outline-offset: 2px; }

.status { display: inline-flex; align-items: center; border-radius: 999px; padding: 5px 10px; background: #eef2f7; color: #4c5d73; font-size: .78rem; font-weight: 700; white-space: nowrap; }
.status-signed { background: var(--primary-soft); color: var(--primary-dark); }
.status-cancelled, .status-delivery_failed { background: var(--danger-soft); color: var(--danger); }
.status-opened, .status-otp_sent { background: var(--primary-soft); color: var(--primary); }

.detail-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(290px, .8fr); gap: 20px; margin-bottom: 20px; }
.details { display: grid; grid-template-columns: 150px 1fr; gap: 9px 14px; margin: 0; }
.details dt { color: var(--muted); }
.details dd { margin: 0; word-break: break-word; }
.details.compact { margin-top: 22px; }
.contract-documents { display: grid; gap: 10px; margin-top: 22px; }
.contract-documents h3 { margin: 0 0 2px; font-size: 1rem; }
.contract-document-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 14px; padding: 13px; border: 1px solid var(--line); border-radius: 10px; background: #f8fafd; }
.contract-document-info { display: grid; gap: 4px; min-width: 0; }
.contract-document-info strong { overflow-wrap: anywhere; }
.contract-document-info span, .bundle-hash span { color: var(--muted); font-size: .78rem; }
.contract-document-info code, .bundle-hash code { display: block; color: var(--muted); font-size: .68rem; overflow-wrap: anywhere; }
.bundle-hash { display: grid; gap: 4px; padding: 10px 13px; border-left: 3px solid var(--primary); background: var(--primary-soft); }
.action-form { display: grid; gap: 7px; margin-bottom: 18px; }
.integrity-card { margin: 20px 0; }
.integrity-card code, .timeline code { display: block; word-break: break-all; color: var(--muted); font-size: .72rem; }
.integrity-ok { border-left: 5px solid var(--primary); }
.integrity-bad { border-left: 5px solid var(--danger); }
.timeline-card { margin-top: 20px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; display: grid; gap: 4px; padding: 0 0 22px 24px; border-left: 2px solid #c9d8e9; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 3px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.timeline li:last-child { padding-bottom: 0; }
.timeline span { color: var(--muted); font-size: .84rem; }

.sign-body .page-shell { width: min(960px, calc(100% - 24px)); }
.sign-header { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; margin-bottom: 18px; }
.document-card { margin-bottom: 18px; }
.customer-document-list { display: grid; gap: 24px; margin-top: 18px; }
.customer-document { padding-top: 22px; border-top: 1px solid var(--line); }
.customer-document:first-child { padding-top: 0; border-top: 0; }
.document-item-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.document-item-heading h3 { margin: 0 0 5px; font-size: 1rem; }
.document-item-heading p { margin: 0; color: var(--muted); font-size: .88rem; overflow-wrap: anywhere; }
.pdf-viewer { width: 100%; min-height: 520px; margin-top: 14px; overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: #e8edf3; }
.pdf-viewer-status { padding: 24px; color: var(--muted); text-align: center; font-weight: 600; }
.pdf-pages { display: grid; gap: 16px; padding: 16px; background: #dfe5ec; }
.pdf-page { display: grid; width: 100%; max-width: 900px; min-height: 220px; margin: 0 auto; place-items: center; overflow: hidden; background: #fff; box-shadow: 0 2px 10px rgba(20, 37, 61, .16); }
.pdf-page canvas { display: block; max-width: 100%; height: auto; background: #fff; }
.pdf-page-loading, .pdf-page-error { padding: 24px; color: var(--muted); text-align: center; }
.pdf-page-error { color: var(--danger); }
.pdf-viewer-fallback { display: grid; min-height: 300px; place-content: center; justify-items: center; gap: 10px; padding: 24px; text-align: center; background: #f8fafd; }
.pdf-viewer-fallback span { color: var(--muted); }
.signing-card { max-width: 720px; margin: 0 auto; }
.signing-step-title { margin: 0 0 10px; font-size: 1.08rem; }
.consent-text { margin: 0 0 20px; padding: 16px; border-left: 4px solid var(--primary); border-radius: 10px; background: #f4f7fb; color: #2b405d; font-size: 1rem; line-height: 1.55; }
.check-label { display: grid; grid-template-columns: 22px 1fr; align-items: start; gap: 10px; line-height: 1.45; font-weight: 500; }
.check-label input { width: 19px; height: 19px; margin-top: 2px; accent-color: var(--primary); }
.customer-signing-form { gap: 21px; font-size: 1.02rem; }
.customer-signing-form label { font-size: 1rem; }
.customer-signing-form small { font-size: .9rem; line-height: 1.45; }
.signing-card .check-label { grid-template-columns: 27px 1fr; gap: 12px; font-size: 1rem; line-height: 1.55; }
.signing-card .check-label input { width: 23px; height: 23px; margin-top: 1px; }
.signing-card .button { font-size: 1rem; }
.signing-field input[type="email"] { min-height: 50px; font-size: 1rem; }
.otp-label { width: min(310px, 100%); margin: 0 auto; text-align: center; }
.otp-input { height: 62px !important; text-align: center; font-size: 1.75rem !important; letter-spacing: .28em; font-weight: 700; }
.resend-form { text-align: center; margin-top: 18px; }
.resend-form .link-button { font-size: 1rem; }
.signed-card, .centered-card { max-width: 700px; margin: 55px auto; text-align: center; }
.check-icon, .error-icon { display: grid; place-items: center; width: 64px; height: 64px; margin: 0 auto 18px; border-radius: 50%; color: #fff; background: var(--primary); box-shadow: 0 0 0 5px var(--primary-soft); font-size: 2rem; font-weight: 800; }
.error-icon { background: var(--danger); }
.centered-buttons { justify-content: center; }
.signed-document-links { display: grid; gap: 10px; max-width: 560px; margin: 22px auto 0; }
.signed-document-links .button { overflow-wrap: anywhere; }
.confirmation-link-row { margin-top: 12px; }

@media (max-width: 760px) {
    .topbar { min-height: 58px; padding: 8px 14px; }
    .brand span:last-child { display: none; }
    .official-logo { height: 42px; }
    .topnav { gap: 13px; font-size: .84rem; }
    .page-shell { margin-top: 20px; }
    .card { border-radius: 12px; padding: 18px; }
    .page-heading, .document-heading { align-items: stretch; flex-direction: column; }
    .page-heading .button { width: 100%; }
    .form-grid, .detail-grid { grid-template-columns: 1fr; }
    .document-upload-row, .contract-document-row { grid-template-columns: 1fr; align-items: stretch; }
    .document-remove { width: 100%; }
    .details { grid-template-columns: 115px 1fr; }
    .button-row { display: grid; }
    .pdf-viewer { min-height: 420px; }
    .pdf-pages { gap: 10px; padding: 8px; }
    .document-item-heading { flex-direction: column; }
    .document-item-heading .button { width: 100%; }
    .sign-header { align-items: flex-start; }
    .sign-header .status { margin-top: 3px; }
}
