/*
 * E-signature screens (WS6, spec §7.2, §7.7, §8.1, §8.2, §9.3).
 * One stylesheet for every host and shell: the main app, the Sign app (and
 * its desktop embedded shell), the guest signer page, tvarka.pro and
 * tvarka.eu. Plain CSS with an "es-" prefix, so it needs no Tailwind build
 * and cannot clash with a host page. Phone width: 16 px gutter, no
 * horizontal scroll.
 */

/* The handwriting font of the typed signature. The same file draws the mark
   in the PDF (signing/esign/marks.py), so what the signer sees is what lands
   on the page. Allura, SIL Open Font License, self-hosted (CSP font-src 'self'). */
@font-face {
    font-family: 'Tvarka Signature';
    src: url("../fonts/allura-regular.ec47de04a5f2.ttf") format('truetype');
    font-display: swap;
}

.es-root, .es-root * { box-sizing: border-box; }
.es-root {
    --es-primary: #2a8775;
    --es-primary-dark: #1f6457;
    --es-primary-50: #eaf5f2;
    --es-text: #0f181d;
    --es-muted: #5a6b6f;
    --es-border: #d9e3e0;
    --es-bg: #f8faf9;
    --es-danger: #b42318;
    --es-danger-50: #fef3f2;
    --es-warn: #b54708;
    --es-warn-50: #fffaeb;
    --es-ok: #067647;
    --es-ok-50: #ecfdf3;
    color: var(--es-text);
    font-size: 1rem;
    line-height: 1.5;
}
.es-hidden { display: none !important; }
.es-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;
}

/* ── Overlay and sheet ─────────────────────────────────────────────── */
.es-overlay {
    position: fixed; inset: 0; z-index: 90;
    background: rgba(15, 24, 29, 0.45);
    display: flex; align-items: center; justify-content: center;
    padding: 16px;
}
.es-sheet {
    position: relative;
    width: 100%; max-width: 520px;
    max-height: calc(100vh - 32px);
    overflow-y: auto; overscroll-behavior: contain;
    background: #fff; border-radius: 16px;
    box-shadow: 0 20px 50px rgba(15, 24, 29, 0.25);
    padding: 22px 22px 20px;
}
.es-sheet-wide { max-width: 680px; }
@media (max-width: 640px) {
    .es-overlay { align-items: flex-end; padding: 0; }
    .es-sheet {
        max-width: none; border-radius: 16px 16px 0 0;
        max-height: calc(100vh - 24px); padding: 18px 16px 16px;
    }
}
.es-sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.es-close {
    flex: none; border: 0; background: transparent; color: var(--es-muted);
    font-size: 1.5rem; line-height: 1; padding: 2px 6px; cursor: pointer; border-radius: 8px;
}
.es-close:hover, .es-close:focus-visible { color: var(--es-text); background: var(--es-bg); }
.es-title { font-size: 1.25rem; font-weight: 700; margin: 0; line-height: 1.3; }
.es-sub { color: var(--es-muted); margin: 4px 0 0; font-size: 0.95rem; overflow-wrap: anywhere; }

/* ── Fields ────────────────────────────────────────────────────────── */
.es-field { margin-top: 16px; }
.es-label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 6px; }
.es-help { color: var(--es-muted); font-size: 0.85rem; margin: 6px 0 0; }
/* Links in running text look like links on every host (the tvarka.eu base
   resets anchors): the sign-up acceptance line, "Already have an account?". */
.es-help a, .es-lead a, .es-sub a {
    color: var(--es-primary-dark); text-decoration: underline; text-underline-offset: 2px;
}
.es-help a:hover, .es-lead a:hover, .es-sub a:hover { color: var(--es-primary); }
.es-help a:focus-visible, .es-lead a:focus-visible, .es-sub a:focus-visible {
    outline: 2px solid var(--es-primary); outline-offset: 2px; border-radius: 2px;
}
.es-input, .es-select, .es-textarea {
    width: 100%; font: inherit; color: var(--es-text);
    border: 1px solid var(--es-border); border-radius: 10px;
    padding: 10px 12px; background: #fff; min-height: 44px;
}
.es-textarea { min-height: 88px; resize: vertical; }
.es-input:focus, .es-select:focus, .es-textarea:focus {
    outline: 2px solid var(--es-primary); outline-offset: 1px; border-color: var(--es-primary);
}
.es-input[readonly] { background: var(--es-bg); color: var(--es-muted); }
.es-input-code { letter-spacing: 0.3em; font-size: 1.25rem; text-align: center; font-variant-numeric: tabular-nums; }
.es-error { color: var(--es-danger); font-size: 0.9rem; margin: 8px 0 0; }
.es-error:empty { display: none; }

/* ── Signature tabs, typed preview, drawing pad ────────────────────── */
.es-tabs { display: flex; gap: 4px; background: var(--es-bg); border-radius: 10px; padding: 4px; }
.es-tab {
    flex: 1; border: 0; background: transparent; font: inherit; font-weight: 600;
    color: var(--es-muted); padding: 8px 10px; border-radius: 8px; cursor: pointer; min-height: 40px;
}
.es-tab[aria-selected="true"] { background: #fff; color: var(--es-text); box-shadow: 0 1px 3px rgba(15, 24, 29, 0.12); }
.es-tab:focus-visible { outline: 2px solid var(--es-primary); }
.es-typed {
    margin-top: 10px; border: 1px dashed var(--es-border); border-radius: 12px;
    min-height: 96px; display: flex; align-items: center; justify-content: center;
    padding: 8px 12px; background: #fff; overflow: hidden;
}
.es-typed-text {
    font-family: 'Tvarka Signature', 'Segoe Script', 'Brush Script MT', cursive;
    font-size: 2.6rem; line-height: 1.2; color: #1d2a6b; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
.es-pad { margin-top: 10px; position: relative; }
.es-pad canvas {
    display: block; width: 100%; height: 170px; touch-action: none;
    border: 1px dashed var(--es-border); border-radius: 12px; background: #fff; cursor: crosshair;
}
.es-pad-hint {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    color: var(--es-muted); pointer-events: none; font-size: 0.95rem; padding: 0 16px; text-align: center;
}
.es-pad-actions { display: flex; justify-content: flex-end; margin-top: 6px; }

/* ── Consent ───────────────────────────────────────────────────────── */
.es-check { display: flex; gap: 10px; align-items: flex-start; margin-top: 18px; cursor: pointer; }
.es-check input { width: 20px; height: 20px; margin: 2px 0 0; flex: none; accent-color: var(--es-primary); }
.es-check-text { font-weight: 600; }
.es-check-note { display: block; color: var(--es-muted); font-weight: 400; font-size: 0.85rem; margin-top: 2px; }

/* ── Buttons ───────────────────────────────────────────────────────── */
.es-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.es-actions-stack { flex-direction: column; align-items: stretch; }
.es-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    font: inherit; font-weight: 600; border-radius: 10px; padding: 10px 18px;
    min-height: 44px; cursor: pointer; border: 1px solid transparent; text-decoration: none;
}
.es-btn:focus-visible { outline: 2px solid var(--es-primary); outline-offset: 2px; }
.es-btn-primary { background: var(--es-primary); color: #fff; }
.es-btn-primary:hover { background: var(--es-primary-dark); color: #fff; }
.es-btn-primary[disabled] { background: #a9c9c1; cursor: not-allowed; }
.es-btn-secondary { background: #fff; color: var(--es-text); border-color: var(--es-border); }
.es-btn-secondary:hover { background: var(--es-bg); }
.es-btn-secondary[disabled] { color: var(--es-muted); cursor: not-allowed; }
.es-btn-block { width: 100%; }
.es-link {
    border: 0; background: none; font: inherit; color: var(--es-primary-dark);
    text-decoration: underline; cursor: pointer; padding: 4px 0;
}
.es-link-muted { color: var(--es-muted); }
.es-spinner {
    width: 16px; height: 16px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.5);
    border-top-color: #fff; animation: es-spin 0.8s linear infinite;
}
@keyframes es-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .es-spinner { animation: none; } }

/* ── Notices ───────────────────────────────────────────────────────── */
.es-notice { border-radius: 12px; padding: 14px 16px; margin-top: 16px; border: 1px solid; }
.es-notice h2, .es-notice h3 { margin: 0 0 4px; font-size: 1.05rem; font-weight: 700; }
.es-notice p { margin: 0; }
.es-notice-ok { background: var(--es-ok-50); border-color: #abefc6; color: #054f31; }
.es-notice-bad { background: var(--es-danger-50); border-color: #fecdca; color: #7a271a; }
.es-notice-warn { background: var(--es-warn-50); border-color: #fedf89; color: #7a2e0e; }
.es-notice-info { background: var(--es-bg); border-color: var(--es-border); color: var(--es-text); }

/* ── Pages (/v/, signer page, account screens) ─────────────────────── */
.es-page { max-width: 720px; margin: 0 auto; padding: 32px 16px 48px; }
.es-page-narrow { max-width: 460px; }
.es-page h1 { font-size: 1.75rem; line-height: 1.25; font-weight: 700; margin: 0 0 10px; }
.es-lead { color: var(--es-muted); font-size: 1.05rem; margin: 0 0 20px; }
.es-card {
    background: #fff; border: 1px solid var(--es-border); border-radius: 16px;
    padding: 20px; margin-top: 16px;
}
@media (max-width: 640px) { .es-card { padding: 16px; } .es-page h1 { font-size: 1.5rem; } }
.es-drop {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
    border: 2px dashed var(--es-border); border-radius: 14px; padding: 28px 16px;
    text-align: center; cursor: pointer; background: var(--es-bg); min-height: 140px;
}
.es-drop:hover, .es-drop:focus-within, .es-drop.es-drop-active { border-color: var(--es-primary); background: var(--es-primary-50); }
.es-drop-name { font-weight: 600; overflow-wrap: anywhere; }
.es-details { margin: 12px 0 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.es-details div { display: grid; grid-template-columns: minmax(120px, 34%) minmax(0, 1fr); gap: 12px; }
.es-details dt { color: var(--es-muted); }
.es-details dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
@media (max-width: 480px) { .es-details div { grid-template-columns: minmax(0, 1fr); gap: 2px; } }
.es-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.es-row > .es-grow { flex: 1 1 200px; min-width: 0; }

/* ── Invite dialog ─────────────────────────────────────────────────── */
.es-levels { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
@media (min-width: 560px) { .es-levels { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.es-level {
    display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--es-border);
    border-radius: 12px; padding: 12px; cursor: pointer; background: #fff;
}
.es-level input { margin-top: 3px; accent-color: var(--es-primary); width: 18px; height: 18px; flex: none; }
.es-level:has(input:checked) { border-color: var(--es-primary); background: var(--es-primary-50); }
.es-level-title { font-weight: 700; display: block; }
.es-level-desc { color: var(--es-muted); font-size: 0.85rem; display: block; margin-top: 2px; }
.es-signers { display: grid; gap: 12px; margin-top: 8px; }
.es-signer {
    border: 1px solid var(--es-border); border-radius: 12px; padding: 12px;
    display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr);
}
@media (min-width: 640px) {
    .es-signer-main { display: grid; gap: 10px; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1.4fr) minmax(0, 0.9fr); }
}
.es-signer-main { display: grid; gap: 10px; }
.es-signer-extras { display: grid; gap: 10px; }
.es-signer-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.es-signer-num { font-weight: 700; color: var(--es-muted); font-size: 0.85rem; }
.es-switch { display: flex; gap: 10px; align-items: center; cursor: pointer; }
.es-switch input { width: 20px; height: 20px; accent-color: var(--es-primary); flex: none; margin: 0; }
.es-price { color: var(--es-muted); font-size: 0.85rem; }
.es-radio-row { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.es-radio-row label { display: inline-flex; gap: 8px; align-items: center; cursor: pointer; }
.es-radio-row input { accent-color: var(--es-primary); width: 18px; height: 18px; margin: 0; }

/* ── Signer page ───────────────────────────────────────────────────── */
.es-viewer {
    margin-top: 16px; border: 1px solid var(--es-border); border-radius: 14px;
    overflow: hidden; background: var(--es-bg);
}
.es-viewer iframe { display: block; width: 100%; height: 62vh; min-height: 360px; border: 0; background: #fff; }
@media (max-width: 640px) { .es-viewer iframe { height: 55vh; min-height: 300px; } }
.es-sticky-actions {
    position: sticky; bottom: 0; background: #fff; border-top: 1px solid var(--es-border);
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); margin: 16px -16px 0;
    display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between;
}
@media (min-width: 641px) { .es-sticky-actions { margin: 16px 0 0; border: 1px solid var(--es-border); border-radius: 14px; } }
.es-countdown { color: var(--es-muted); font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.es-big-icon {
    width: 56px; height: 56px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
    margin: 0 0 12px; font-size: 1.6rem; font-weight: 700;
}
.es-big-icon-ok { background: var(--es-ok-50); color: var(--es-ok); }
.es-big-icon-info { background: var(--es-bg); color: var(--es-muted); }

/* ── Settings section in the Sign app ──────────────────────────────── */
.es-settings { display: grid; gap: 14px; margin-top: 12px; }

/* ── Passkeys and the remembered browser (account screens) ─────────── */
.es-root [hidden] { display: none !important; }
.es-or { display: flex; align-items: center; gap: 12px; margin: 18px 0; color: var(--es-muted); font-size: 0.85rem; }
.es-or::before, .es-or::after { content: ""; flex: 1; border-top: 1px solid var(--es-border); }
.es-passkeys { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.es-passkeys li { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px;
    border: 1px solid var(--es-border); border-radius: 10px; padding: 10px 12px; }
.es-passkeys form { margin: 0; }

/* ── The qualified guest page: beauty pass (UX round of 2026-11-12) ────
   Scoped to the page of the protected qualified ceremony. The button ink
   reaches 4.8 to 1 (it was 4.4). On a phone the frame gives the 16 px
   gutter, so the page adds none, and the main button spans the width. */
[data-qualified-guest] { --es-primary: #267f6e; }
@media (max-width: 640px) {
    [data-qualified-guest].es-page { padding: 8px 0 32px; }
    [data-qualified-guest] [data-q-sign] .es-btn-primary { width: 100%; margin-top: 8px; }
    [data-qualified-guest] .es-actions .es-btn { flex: 1 1 auto; }
}
