:root {
    --navy: #1a2332;
    --navy-light: #243044;
    --slate: #64748b;
    --slate-light: #94a3b8;
    --border: #e2e5ea;
    --bg: #f8f9fb;
    --bg-card: #ffffff;
    --text: #1a2332;
    --text-secondary: #64748b;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --green: #059669;
    --green-bg: #ecfdf5;
    --green-border: #a7f3d0;
    --amber: #d97706;
    --amber-bg: #fffbeb;
    --amber-border: #fde68a;
    --red: #dc2626;
    --red-bg: #fef2f2;
    --seal: #b8860b;
    --seal-light: #daa520;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
    --radius: 8px;
    --radius-lg: 12px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'DM Sans', -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

.hidden { display: none !important; }
.mono { font-family: 'JetBrains Mono', monospace; }

/* ============ HEADER ============ */
.header {
    background: var(--navy);
    color: white;
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}
.header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 15px;
    cursor: pointer;
}
.header-brand svg { opacity: 0.9; }
.header-sep { opacity: 0.4; font-weight: 400; font-size: 13px; }
.header-actions { display: flex; align-items: center; gap: 12px; }
.header-wallet {
    display: flex;
    align-items: center;
    gap: 10px;
}
.wallet-addr {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    opacity: 0.7;
}
.btn-disconnect {
    background: none;
    border: none;
    color: white;
    opacity: 0.5;
    cursor: pointer;
    padding: 4px;
}
.btn-disconnect:hover { opacity: 1; }

/* ============ BUTTONS ============ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--navy); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--navy-light); }
.btn-secondary { background: white; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--bg); }
.btn-connect { background: rgba(255,255,255,0.15); color: white; font-size: 13px; padding: 8px 16px; }
.btn-connect:hover { background: rgba(255,255,255,0.25); }
.btn-full { width: 100%; justify-content: center; }
.btn-lg { padding: 14px 32px; font-size: 15px; }
.btn-sm { padding: 6px 14px; font-size: 12px; }

/* ============ MAIN CONTAINER ============ */
.main {
    max-width: 640px;
    margin: 0 auto;
    padding: 32px 20px 64px;
}

.screen-back {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--slate);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    margin-bottom: 20px;
}
.screen-back:hover { color: var(--text); }

.screen-sub {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 24px;
}

/* ============ LANDING ============ */
.landing-card {
    text-align: center;
    padding: 80px 20px;
}
.landing-icon {
    color: var(--navy);
    margin-bottom: 24px;
}
.landing-card h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
}
.landing-sub {
    color: var(--text-secondary);
    font-size: 16px;
    margin-bottom: 32px;
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
}
.landing-hint {
    color: var(--slate-light);
    font-size: 12px;
    margin-top: 16px;
}

/* ============ DASHBOARD ============ */
.dash-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}
.dash-header h2 { font-size: 20px; font-weight: 700; }

.dash-list { display: flex; flex-direction: column; gap: 8px; }

.dash-empty {
    text-align: center;
    padding: 48px 20px;
    color: var(--slate);
}
.dash-empty svg { margin-bottom: 12px; opacity: 0.4; }
.dash-empty .small { font-size: 13px; color: var(--slate-light); margin-top: 4px; }

.dash-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 20px;
    cursor: pointer;
    transition: border-color 0.15s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.dash-item:hover { border-color: var(--slate-light); }
.dash-item-left { flex: 1; min-width: 0; }
.dash-item-title { font-weight: 600; font-size: 14px; margin-bottom: 2px; }
.dash-item-meta { font-size: 12px; color: var(--slate-light); }

.status-pill {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 20px;
    white-space: nowrap;
}
.status-pill.draft { background: var(--bg); color: var(--slate); border: 1px solid var(--border); }
.status-pill.paid { background: #eff6ff; color: #2563eb; border: 1px solid #bfdbfe; }
.status-pill.pending_cosign { background: var(--amber-bg); color: var(--amber); border: 1px solid var(--amber-border); }
.status-pill.pending_finalization { background: var(--amber-bg); color: var(--amber); border: 1px solid var(--amber-border); }
.status-pill.notarized { background: var(--green-bg); color: var(--green); border: 1px solid var(--green-border); }
.status-pill.cancelled { background: var(--red-bg); color: var(--red); border: 1px solid #fecaca; }

/* ============ FORMS ============ */
.form-group { margin-bottom: 20px; }
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text);
}
.form-group .optional { font-weight: 400; color: var(--slate-light); }
.form-group .hint { font-size: 12px; color: var(--slate-light); margin-top: 6px; }

input[type="text"],
input[type="email"],
textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 14px;
    color: var(--text);
    background: white;
    transition: border-color 0.15s;
}
input:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
textarea { resize: vertical; }

/* Upload zone */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 32px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    color: var(--slate);
}
.upload-zone:hover { border-color: var(--slate-light); background: white; }
.upload-zone.drag-over { border-color: var(--accent); background: #eff6ff; }
.upload-zone p { font-size: 14px; margin-top: 8px; }
.upload-zone .formats { font-size: 12px; color: var(--slate-light); margin-top: 4px; }

.file-preview {
    display: flex;
    align-items: center;
    gap: 12px;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
}
.file-icon {
    background: #dc2626;
    color: white;
    font-size: 10px;
    font-weight: 700;
    padding: 6px 8px;
    border-radius: 4px;
}
.file-info { flex: 1; min-width: 0; }
.file-info .name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-info .meta { font-size: 11px; color: var(--slate-light); font-family: 'JetBrains Mono', monospace; }
.file-remove {
    background: none;
    border: none;
    color: var(--slate-light);
    cursor: pointer;
    padding: 4px;
}
.file-remove:hover { color: var(--red); }

/* Cost estimate */
.cost-estimate {
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 20px;
}
.cost-estimate h4 { font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.cost-row {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    padding: 4px 0;
}
.cost-value { font-family: 'JetBrains Mono', monospace; font-weight: 500; }
.cost-note { font-size: 11px; color: var(--slate-light); margin-top: 8px; }

/* ============ STATUS BANNER ============ */
.status-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    border-radius: var(--radius);
    margin-bottom: 24px;
    font-size: 14px;
    font-weight: 500;
}
.status-banner.draft { background: var(--bg); border: 1px solid var(--border); color: var(--slate); }
.status-banner.paid { background: #eff6ff; border: 1px solid #bfdbfe; color: #2563eb; }
.status-banner.pending { background: var(--amber-bg); border: 1px solid var(--amber-border); color: var(--amber); }
.status-banner.confirmed { background: var(--green-bg); border: 1px solid var(--green-border); color: var(--green); }

/* ============ DOCUMENT CARD ============ */
.document-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
}
.document-card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.document-card-header h3 { font-size: 14px; font-weight: 600; }
.doc-hash { font-size: 11px; color: var(--slate-light); cursor: pointer; }
.doc-hash:hover { color: var(--accent); }

.document-body { padding: 0; background: #f1f3f5; max-height: 600px; overflow-y: auto; display: block; }
.pdf-viewer { width: 100%; }
.pdf-viewer canvas { width: 100%; height: auto; display: block; }

.document-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    color: var(--slate-light);
}

/* ============ AGREEMENT HEADER ============ */
.agreement-header { margin-bottom: 24px; }
.agreement-header h1 { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.agreement-meta { font-size: 12px; color: var(--slate-light); }

/* ============ SIGNATURES ============ */
.signatures-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
}
.signatures-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.signatures-header h3 { font-size: 14px; font-weight: 600; }

.signature-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
}
.signature-row:last-child { border-bottom: none; }

.sig-indicator {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.sig-indicator.signed { background: var(--green-bg); color: var(--green); border: 1px solid var(--green-border); }
.sig-indicator.pending { background: var(--amber-bg); color: var(--amber); border: 1px solid var(--amber-border); }
.sig-indicator.waiting { background: var(--bg); color: var(--slate-light); border: 1px solid var(--border); }

.sig-info { flex: 1; min-width: 0; }
.sig-label { font-size: 13px; font-weight: 600; }
.sig-address { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--slate-light); }
.sig-time { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }

/* ============ SIGN ACTION ============ */
.sign-action {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
}
.sign-action h3 { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.sign-action > p { font-size: 13px; color: var(--text-secondary); margin-bottom: 14px; }

.invite-action, .finalize-action {
    margin-bottom: 24px;
}

/* ============ CHAIN PROOF ============ */
.chain-proof {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
}
.chain-proof-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.chain-proof-header h3 { font-size: 14px; font-weight: 600; }
.verified-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    font-weight: 600;
    color: var(--green);
    background: var(--green-bg);
    border: 1px solid var(--green-border);
    padding: 3px 10px;
    border-radius: 20px;
}
.proof-rows { padding: 16px 20px; }
.proof-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 8px 0;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}
.proof-row:last-child { border-bottom: none; }
.proof-label { color: var(--text-secondary); white-space: nowrap; margin-right: 16px; }
.proof-value { font-family: 'JetBrains Mono', monospace; font-size: 12px; text-align: right; word-break: break-all; }
.proof-value a { color: var(--accent); text-decoration: none; }
.proof-value a:hover { text-decoration: underline; }

/* ============ NOTARY SEAL ============ */
.notary-seal {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    margin-bottom: 24px;
}
.seal {
    width: 140px;
    height: 140px;
    border-radius: 50%;
    border: 3px double var(--seal);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, rgba(184,134,11,0.04), rgba(218,165,32,0.08));
    position: relative;
}
.seal::before {
    content: '';
    position: absolute;
    inset: 6px;
    border: 1px solid var(--seal-light);
    border-radius: 50%;
    opacity: 0.5;
}
.seal .seal-text {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--seal);
    margin-bottom: 4px;
}
.seal svg { color: var(--seal); margin-bottom: 4px; }
.seal .seal-date {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    color: var(--seal-light);
}

/* ============ DOWNLOAD ============ */
.download-section { margin-bottom: 24px; }

/* ============ LOADING ============ */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(248,249,251,0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 200;
}
.loading-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--navy);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay p { font-size: 14px; color: var(--slate); }

/* ============ TOAST ============ */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    z-index: 300;
    box-shadow: var(--shadow-md);
    transition: opacity 0.3s;
}
.toast.success { background: var(--green); color: white; }
.toast.error { background: var(--red); color: white; }
.toast.info { background: var(--navy); color: white; }

/* ============ SIGNATURE FIELD PLACEMENT ============ */
.sig-placement {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 24px;
}
.sig-placement h3 { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.sig-placement > p { font-size: 13px; color: var(--text-secondary); margin-bottom: 14px; }
.sig-fields-list { margin-bottom: 12px; }
.sig-field-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--bg);
    border-radius: var(--radius);
    margin-bottom: 6px;
    font-size: 13px;
}
.sig-field-item select {
    font-family: inherit;
    font-size: 12px;
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: white;
}
.sig-field-remove {
    background: none;
    border: none;
    color: var(--slate-light);
    cursor: pointer;
    margin-left: auto;
    padding: 2px;
}
.sig-field-remove:hover { color: var(--red); }

/* ============ RESPONSIVE ============ */
@media (max-width: 640px) {
    .main { padding: 20px 16px 48px; }
    .header { padding: 0 16px; }
    .landing-card { padding: 48px 16px; }
    .landing-card h1 { font-size: 24px; }
}
