/* E-sign templates + bulk send (public/esign-templates.js). Reuses the
   Settings › Workspace (wsa-*) components; tokens are re-declared here
   because those are scoped to #workspace-settings-view. */
#esign-templates-view {
    --wsa-ink: #0f172a;
    --wsa-text: #1e293b;
    --wsa-muted: #64748b;
    --wsa-line: #e2e8f0;
    --wsa-line-strong: #cbd5e1;
    --wsa-surface: #f8fafc;
    --wsa-accent: #2563eb;
    --wsa-accent-hover: #1d4ed8;
    --wsa-accent-soft: #eff6ff;
    --wsa-ok: #166534;
    --wsa-ok-bg: #dcfce7;
    --wsa-warn: #92400e;
    --wsa-warn-bg: #fef3c7;
    --wsa-danger: #b91c1c;
    --wsa-danger-bg: #fef2f2;
    font-family: 'Inter', sans-serif;
    color: var(--wsa-text);
    background: #f1f5f9;
}
#esign-templates-view .hidden { display: none !important; }
#esign-templates-view select, #esign-templates-view input[type="text"], #esign-templates-view input[type="email"],
#esign-templates-view input[type="number"], #esign-templates-view textarea {
    min-height: 40px; padding: 8px 12px; border: 1px solid var(--wsa-line-strong); border-radius: 8px;
    background: #fff; color: var(--wsa-text); font-size: 14px; font-family: inherit; max-width: 100%; box-sizing: border-box;
}
#esign-templates-view textarea { min-height: 72px; resize: vertical; line-height: 1.45; }
#esign-templates-view select:focus-visible, #esign-templates-view input:focus-visible, #esign-templates-view textarea:focus-visible,
#esign-templates-view button:focus-visible, #esign-templates-view [role="tabpanel"]:focus-visible, #esign-templates-view a:focus-visible {
    outline: 2px solid var(--wsa-accent); outline-offset: 2px;
}
#esign-templates-view label.est-label { font-size: 13px; font-weight: 500; color: #334155; }
.est-scope { margin-left: auto; display: flex; align-items: center; gap: 8px; min-width: 0; }
.est-scope select { max-width: 280px; }
.est-head-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.est-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.est-card { background: #fff; border: 1px solid var(--wsa-line); border-radius: 12px; padding: 18px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.est-card.est-archived { opacity: 0.75; background: var(--wsa-surface); }
.est-card-top { display: flex; gap: 12px; align-items: flex-start; }
.est-card-icon { width: 40px; height: 40px; flex-shrink: 0; border-radius: 10px; background: var(--wsa-accent-soft); color: var(--wsa-accent); display: flex; align-items: center; justify-content: center; font-size: 17px; }
.est-card-name { font-size: 15px; font-weight: 600; color: var(--wsa-ink); margin: 0; overflow-wrap: anywhere; }
.est-card-meta { font-size: 12.5px; color: var(--wsa-muted); margin-top: 2px; }
.est-card-desc { font-size: 13px; color: #475569; margin: 0; overflow-wrap: anywhere; }
.est-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.est-chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; background: #f1f5f9; color: #334155; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.est-chip-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.est-card-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: auto; padding-top: 6px; }
.est-empty { text-align: center; padding: 48px 20px; color: var(--wsa-muted); background: #fff; border: 1px dashed var(--wsa-line-strong); border-radius: 12px; }
.est-empty h3 { color: var(--wsa-ink); font-size: 16px; font-weight: 600; margin: 8px 0 6px; }
.est-empty i.est-empty-icon { font-size: 28px; color: #94a3b8; }
.est-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.est-usage { font-size: 13px; color: var(--wsa-muted); }
.est-status { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: #f1f5f9; color: #475569; }
.est-status[data-status="sent"], .est-status[data-status="queued"], .est-status[data-status="sending"] { background: #eff6ff; color: #1d4ed8; }
.est-status[data-status="viewed"] { background: #ede9fe; color: #5b21b6; }
.est-status[data-status="completed"], .est-status[data-status="signed"], .est-status[data-status="done"] { background: var(--wsa-ok-bg); color: var(--wsa-ok); }
.est-status[data-status="declined"], .est-status[data-status="bounced"], .est-status[data-status="failed"] { background: var(--wsa-danger-bg); color: var(--wsa-danger); }
.est-status[data-status="voided"], .est-status[data-status="expired"], .est-status[data-status="cancelled"] { background: #f1f5f9; color: #64748b; }
.est-status[data-status="waiting"] { background: var(--wsa-warn-bg); color: var(--wsa-warn); }
.est-table-wrap { background: #fff; border: 1px solid var(--wsa-line); border-radius: 12px; overflow: hidden; }
.est-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.est-table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--wsa-muted); background: var(--wsa-surface); padding: 10px 14px; border-bottom: 1px solid var(--wsa-line); white-space: nowrap; }
.est-table td { padding: 11px 14px; border-bottom: 1px solid var(--wsa-line); vertical-align: top; color: #1e293b; }
.est-table tr:last-child td { border-bottom: none; }
.est-table .est-sub { display: block; font-size: 12px; color: var(--wsa-muted); overflow-wrap: anywhere; }
.est-table .est-row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.est-table tr.est-row-error td { background: #fff7f7; }
.est-err-text { color: var(--wsa-danger); font-size: 12.5px; }
.est-foot { display: flex; justify-content: center; padding: 12px; }
.est-tiles { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
.est-tile { background: #fff; border: 1px solid var(--wsa-line); border-radius: 12px; padding: 14px 16px; min-width: 0; }
.est-tile-value { font-size: 24px; font-weight: 700; color: var(--wsa-ink); font-variant-numeric: tabular-nums; line-height: 1.15; }
.est-tile-label { font-size: 12.5px; color: var(--wsa-muted); margin-top: 2px; }
.est-tile[data-kind="completed"][data-nonzero] .est-tile-value { color: var(--wsa-ok); }
.est-tile[data-kind="declined"][data-nonzero] .est-tile-value, .est-tile[data-kind="bounced"][data-nonzero] .est-tile-value { color: var(--wsa-danger); }
.est-progress { height: 8px; background: #e2e8f0; border-radius: 999px; overflow: hidden; display: flex; }
.est-progress span { height: 100%; transition: width 0.3s; }
.est-progress .p-completed { background: #16a34a; }
.est-progress .p-pending { background: #3b82f6; }
.est-progress .p-problem { background: #dc2626; }
.est-progress .p-closed { background: #94a3b8; }
.est-dash-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.est-dash-title { font-size: 20px; font-weight: 700; color: var(--wsa-ink); margin: 0; overflow-wrap: anywhere; }
.est-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--wsa-muted); margin-top: 8px; }
.est-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.est-batch { cursor: pointer; text-align: left; font: inherit; width: 100%; }
.est-batch:hover { border-color: var(--wsa-line-strong); box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06); }
.est-batch-row { display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; }

/* ---- modals ---- */
.est-modal { position: fixed; inset: 0; z-index: 450; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(15, 23, 42, 0.45); }
.est-modal-card { background: #fff; border-radius: 14px; width: 560px; max-width: 100%; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 25px 50px rgba(15, 23, 42, 0.25); }
.est-modal-card.est-wide { width: 880px; }
.est-modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--wsa-line); }
.est-modal-head h2 { font-size: 18px; font-weight: 600; color: var(--wsa-ink); margin: 0; overflow-wrap: anywhere; }
.est-modal-body { padding: 18px 22px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.est-modal-foot { padding: 14px 22px; border-top: 1px solid var(--wsa-line); display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; align-items: center; }
.est-modal-foot .est-msg { margin-right: auto; flex: 1 1 200px; min-width: 0; }
.est-section-title { font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--wsa-muted); margin: 0 0 8px; }
.est-role-block { border: 1px solid var(--wsa-line); border-radius: 10px; padding: 12px 14px; }
.est-role-block-head { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; color: var(--wsa-ink); margin-bottom: 10px; }
.est-two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.est-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.est-field input, .est-field select, .est-field textarea { width: 100%; }
.est-msg { font-size: 13px; color: var(--wsa-muted); min-height: 1em; }
.est-msg.est-msg-error { color: var(--wsa-danger); }
.est-msg.est-msg-ok { color: var(--wsa-ok); }
.est-success { text-align: center; padding: 8px 0; }
.est-success-icon { width: 52px; height: 52px; border-radius: 50%; background: var(--wsa-ok-bg); color: var(--wsa-ok); display: flex; align-items: center; justify-content: center; margin: 0 auto 10px; font-size: 22px; }
.est-link-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; text-align: left; }
.est-link-list li { display: flex; align-items: center; gap: 10px; justify-content: space-between; border: 1px solid var(--wsa-line); border-radius: 10px; padding: 10px 12px; }
.est-seg { display: inline-flex; border: 1px solid var(--wsa-line-strong); border-radius: 8px; overflow: hidden; }
.est-seg button { border: none; background: #fff; padding: 8px 14px; font: inherit; font-size: 13.5px; cursor: pointer; color: #334155; }
.est-seg button[aria-pressed="true"] { background: var(--wsa-accent-soft); color: #1d4ed8; font-weight: 600; }
.est-drop { border: 1.5px dashed var(--wsa-line-strong); border-radius: 10px; padding: 18px; text-align: center; color: var(--wsa-muted); font-size: 13.5px; background: var(--wsa-surface); }
.est-drop.est-drop-over { border-color: var(--wsa-accent); background: var(--wsa-accent-soft); }
.est-summary { display: flex; gap: 8px; flex-wrap: wrap; }
.est-issues { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.est-issues li { padding: 8px 10px; border-radius: 8px; background: var(--wsa-danger-bg); color: var(--wsa-danger); }
.est-issues li.est-warn { background: var(--wsa-warn-bg); color: var(--wsa-warn); }
.est-preview-table { max-height: 280px; overflow: auto; border: 1px solid var(--wsa-line); border-radius: 10px; }
.est-upsell-modal .wsa-upsell { border: none; padding: 28px 24px; margin: 0; }

/* ---- template editor ---- */
.est-editor { position: fixed; inset: 0; z-index: 420; display: flex; flex-direction: column; background: #e2e8f0; }
.est-editor-bar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: #fff; border-bottom: 1px solid var(--wsa-line); flex-wrap: wrap; }
.est-editor-bar .est-name { flex: 1 1 220px; min-width: 0; font-weight: 600; font-size: 15px; }
.est-editor-bar .est-version { font-size: 12.5px; color: var(--wsa-muted); white-space: nowrap; }
.est-editor-body { flex: 1; display: flex; min-height: 0; }
.est-side { width: 320px; flex-shrink: 0; background: #fff; border-right: 1px solid var(--wsa-line); overflow-y: auto; padding: 14px 16px 24px; display: flex; flex-direction: column; gap: 18px; }
.est-side h3 { font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--wsa-muted); margin: 0 0 8px; }
.est-role-row { display: grid; grid-template-columns: 14px minmax(0, 1fr) 58px 36px; gap: 8px; align-items: center; margin-bottom: 8px; }
.est-role-row.est-parallel { grid-template-columns: 14px minmax(0, 1fr) 36px; }
.est-role-row input { min-height: 36px !important; padding: 6px 10px !important; }
.est-role-swatch { width: 14px; height: 14px; border-radius: 4px; }
.est-placing { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 13px; color: #334155; }
.est-placing select { flex: 1; min-height: 36px !important; padding: 6px 10px !important; }
.est-palette { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.est-tool { display: flex; align-items: center; gap: 8px; padding: 9px 10px; border: 1px solid var(--wsa-line-strong); border-radius: 8px; background: #fff; font: inherit; font-size: 13px; color: #1e293b; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; text-align: left; }
.est-tool i { width: 16px; text-align: center; color: var(--wsa-accent); }
.est-tool:hover { border-color: var(--wsa-accent); }
.est-tool[aria-pressed="true"] { border-color: var(--wsa-accent); background: var(--wsa-accent-soft); box-shadow: inset 0 0 0 1px var(--wsa-accent); }
.est-tool.est-tool-sender i { color: #b45309; }
.est-hint { font-size: 12.5px; color: var(--wsa-muted); line-height: 1.45; margin: 6px 0 0; }
.est-props { border: 1px solid var(--wsa-line); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 10px; background: var(--wsa-surface); }
.est-props .est-field input, .est-props .est-field select { min-height: 36px; padding: 6px 10px; }
.est-check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: #334155; }
.est-canvas { flex: 1; overflow: auto; padding: 24px; display: flex; flex-direction: column; align-items: center; gap: 20px; }
.est-page { position: relative; background: #fff; box-shadow: 0 1px 3px rgba(15, 23, 42, 0.15), 0 8px 24px rgba(15, 23, 42, 0.08); flex-shrink: 0; touch-action: pan-x pan-y; }
.est-page canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.est-page.est-armed { cursor: crosshair; outline: 2px dashed var(--wsa-accent); outline-offset: 4px; }
.est-page-label { position: absolute; top: -18px; left: 0; font-size: 11px; color: #475569; }
.est-fld { position: absolute; border: 1.5px solid; border-radius: 3px; display: flex; align-items: center; padding: 0 4px; font-size: 11px; font-weight: 600; overflow: hidden; white-space: nowrap; cursor: move; touch-action: none; user-select: none; -webkit-user-select: none; box-sizing: border-box; font-family: inherit; text-align: left; }
.est-fld.est-sel { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--wsa-ink); z-index: 3; }
.est-fld.est-readonly { cursor: default; }
.est-fld .est-req { margin-left: 2px; color: #b91c1c; }
.est-fld-handle { position: absolute; right: -1px; bottom: -1px; width: 12px; height: 12px; background: var(--wsa-ink); border: 2px solid #fff; border-radius: 3px; cursor: nwse-resize; touch-action: none; }
.est-ghost { position: fixed; z-index: 460; pointer-events: none; padding: 6px 10px; border-radius: 6px; background: var(--wsa-accent); color: #fff; font-size: 12px; font-weight: 600; box-shadow: 0 6px 16px rgba(15, 23, 42, 0.25); }
.est-loading { padding: 60px 20px; text-align: center; color: #475569; }
.est-editor-msg { font-size: 13px; color: var(--wsa-muted); min-width: 0; flex: 1 1 200px; overflow-wrap: anywhere; }
.est-editor-msg:empty { display: none; }
.est-editor-msg.est-msg-error { color: var(--wsa-danger); }
.est-readonly-note { font-size: 13px; padding: 10px 12px; border-radius: 8px; background: var(--wsa-accent-soft); color: #1e3a8a; }
.est-field-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.est-field-list li { display: flex; align-items: center; gap: 8px; }

/* The CSV picker's native button matches the app's secondary buttons. */
.est-drop input[type="file"] { font: inherit; font-size: 13px; color: var(--wsa-muted); max-width: 100%; }
.est-drop input[type="file"]::file-selector-button { font: inherit; font-weight: 600; font-size: 13px; color: var(--wsa-text); background: #fff; border: 1px solid var(--wsa-line); border-radius: 8px; padding: 6px 12px; margin-right: 10px; cursor: pointer; }
.est-drop input[type="file"]::file-selector-button:hover { border-color: var(--wsa-muted); }

@media (max-width: 900px) {
    .est-tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .est-editor-body { flex-direction: column; }
    .est-side { width: auto; max-height: 42vh; border-right: none; border-bottom: 1px solid var(--wsa-line); }
    .est-canvas { padding: 16px 10px; }
}
@media (max-width: 640px) {
    .est-scope select { max-width: 100%; width: 100%; }
    .est-scope { flex: 1; }
    .est-scope .est-label { display: none; }
    .est-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .est-two { grid-template-columns: 1fr; }
    .est-table thead { display: none; }
    .est-table, .est-table tbody, .est-table tr, .est-table td { display: block; width: 100%; box-sizing: border-box; }
    .est-table tr { border-bottom: 1px solid var(--wsa-line); padding: 8px 0; }
    .est-table tr:last-child { border-bottom: none; }
    .est-table td { border-bottom: none; padding: 4px 14px; }
    .est-table td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; font-weight: 600; color: var(--wsa-muted); text-transform: uppercase; letter-spacing: 0.04em; }
    .est-table .est-row-actions { justify-content: flex-start; }
    .est-modal { padding: 0; align-items: stretch; }
    .est-modal-card, .est-modal-card.est-wide { width: 100%; max-height: 100vh; border-radius: 0; }
    .est-editor-bar { padding: 8px 10px; gap: 8px; }
    .est-editor-bar .est-name { flex-basis: 100%; order: -1; }
    .est-side { max-height: 46vh; padding: 12px; }
    .est-dash-head .wsa-actions { width: 100%; }
    .est-modal-foot .est-msg { flex-basis: 100%; }
    .est-modal-foot .wsa-btn { flex: 1 1 auto; justify-content: center; }
}

/* The app toast is text-only: never let it swallow taps, whether idle
   (opacity 0) or showing over a dialog footer or the template page
   (tap-to-place on phones lands under it). */
#toast { pointer-events: none; }
