/* SignPDF v2 — design system */

:root {
    --primary: #4361ee;
    --primary-strong: #3a53d4;
    --success: #0d9f6e;
    --danger: #dc2f45;
    --warning: #d97706;
    --info: #0284c7;
    --stamp: #7c3aed;

    --bg: #f2f4fb;
    --bg-card: #ffffff;
    --bg-muted: #f7f8fd;
    --border: #e3e7f2;
    --text: #1c2333;
    --text-muted: #626b84;
    --shadow: 0 8px 30px rgba(28, 35, 51, 0.08);
    --shadow-soft: 0 2px 10px rgba(28, 35, 51, 0.06);
    --radius: 14px;
    --radius-sm: 9px;
    --hero-grad: linear-gradient(130deg, #3f37c9 0%, #4361ee 55%, #4895ef 100%);
}

[data-theme="dark"] {
    --bg: #10141f;
    --bg-card: #1a2030;
    --bg-muted: #151b29;
    --border: #2a3247;
    --text: #e8ecf6;
    --text-muted: #9aa4bd;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
    --shadow-soft: 0 2px 10px rgba(0, 0, 0, 0.35);
    --hero-grad: linear-gradient(130deg, #272066 0%, #2b3fae 55%, #2d68b8 100%);
}

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

html { scroll-behavior: smooth; }

body {
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    transition: background 0.25s ease, color 0.25s ease;
}

/* ---------------------------------------------------------------- topbar */

.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    background: color-mix(in srgb, var(--bg-card) 82%, transparent);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}

.topbar-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 10px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--text);
    font-weight: 700;
    font-size: 1.1rem;
}

.brand-mark { font-size: 1.35rem; }

.brand-badge {
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--primary);
    background: color-mix(in srgb, var(--primary) 12%, transparent);
    border: 1px solid color-mix(in srgb, var(--primary) 30%, transparent);
    padding: 1px 7px;
    border-radius: 999px;
}

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

.privacy-pill {
    font-size: 0.78rem;
    color: var(--success);
    background: color-mix(in srgb, var(--success) 10%, transparent);
    border: 1px solid color-mix(in srgb, var(--success) 28%, transparent);
    padding: 3px 11px;
    border-radius: 999px;
    white-space: nowrap;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 34px;
    padding: 0 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: border-color 0.15s ease, transform 0.1s ease;
}

.icon-btn:hover { border-color: var(--primary); }
.icon-btn:active { transform: scale(0.95); }

/* ------------------------------------------------------------------ hero */

.hero-section {
    background: var(--hero-grad);
    color: #fff;
    text-align: center;
    padding: 56px 20px 64px;
}

.hero-title {
    font-size: clamp(1.7rem, 4vw, 2.6rem);
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-bottom: 12px;
}

.hero-subtitle {
    max-width: 720px;
    margin: 0 auto;
    font-size: 1.02rem;
    opacity: 0.92;
}

/* ------------------------------------------------------------- structure */

.container {
    max-width: 1200px;
    margin: -32px auto 40px;
    padding: 0 20px;
}

.app-container { display: flex; flex-direction: column; gap: 24px; }

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 26px;
}

.step-title {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.step-title h2 { font-size: 1.25rem; font-weight: 700; }

.number {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
}

.step-hint { color: var(--text-muted); font-size: 0.92rem; margin-bottom: 14px; }

/* ------------------------------------------------------------------ tabs */

.signature-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 2px solid var(--border);
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.signature-tab {
    appearance: none;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    padding: 10px 18px;
    font: inherit;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease;
}

.signature-tab:hover { color: var(--text); }
.signature-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.signature-tab-content { display: none; }
.signature-tab-content.active { display: block; }

/* --------------------------------------------------------------- options */

.signature-options { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }

.option-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.option-btn:hover { border-color: var(--primary); }

.option-btn.active {
    border-color: var(--primary);
    background: color-mix(in srgb, var(--primary) 10%, transparent);
    color: var(--primary);
}

/* -------------------------------------------------------------- dropzone */

.dropzone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    background: var(--bg-muted);
    padding: 34px 20px;
    text-align: center;
    color: var(--text-muted);
    transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone.active {
    border-color: var(--primary);
    background: color-mix(in srgb, var(--primary) 7%, var(--bg-muted));
}

.dropzone-or { margin: 6px 0; font-size: 0.85rem; }

.upload-btn {
    margin-top: 6px;
    padding: 9px 22px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--primary);
    color: #fff;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
}

.upload-btn:hover { background: var(--primary-strong); }
.upload-btn:active { transform: scale(0.97); }

.preview-container { margin-top: 14px; text-align: center; }

.preview-container img {
    display: none;
    max-width: 260px;
    max-height: 110px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background:
        repeating-conic-gradient(color-mix(in srgb, var(--border) 45%, transparent) 0% 25%, transparent 0% 50%)
        0 0 / 16px 16px;
}

.preview-container img.visible { display: inline-block; }

/* ------------------------------------------------ upload editor (bg removal) */

.sig-editor { margin-top: 16px; display: flex; flex-direction: column; gap: 12px; }
.sig-editor[hidden] { display: none; }

.sig-edit-frame {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 120px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background:
        repeating-conic-gradient(color-mix(in srgb, var(--border) 45%, transparent) 0% 25%, transparent 0% 50%)
        0 0 / 16px 16px,
        var(--bg-muted);
}

.sig-edit-frame canvas { max-width: 100%; max-height: 170px; width: auto; height: auto; }

.sig-editor-controls {
    display: flex;
    align-items: flex-end;
    gap: 18px;
    flex-wrap: wrap;
}

.sig-editor-controls .range-label { flex: 1; min-width: 170px; }

/* ------------------------------------------------------------------ pads */

.signature-pad-container[hidden] { display: none !important; }

.signature-pad-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.pen-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

#signaturePad, #parafPad {
    width: 100%;
    height: 210px;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    background: var(--bg-muted);
    cursor: crosshair;
    touch-action: none;
}

#parafPad { height: 150px; }

.signature-pad-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* -------------------------------------------------------------- controls */

.swatches { display: flex; gap: 8px; }

.swatch {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--sw);
    cursor: pointer;
    transition: transform 0.1s ease, box-shadow 0.15s ease;
}

.swatch:hover { transform: scale(1.12); }

.swatch.active {
    border-color: var(--bg-card);
    box-shadow: 0 0 0 2.5px var(--primary);
}

.range-label {
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
}

.range-label input[type="range"] { accent-color: var(--primary); }

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    cursor: pointer;
    user-select: none;
}

.checkbox-label input { accent-color: var(--primary); width: 16px; height: 16px; }

/* --------------------------------------------------------- stamp designer */

.stamp-intro { color: var(--text-muted); font-size: 0.92rem; margin-bottom: 18px; }

.stamp-designer {
    display: grid;
    grid-template-columns: minmax(300px, 1fr) minmax(300px, 1fr);
    gap: 26px;
    align-items: start;
}

.stamp-form { display: flex; flex-direction: column; gap: 14px; }

.field-group { display: flex; flex-direction: column; gap: 5px; flex: 1; }

.field-label { font-size: 0.83rem; font-weight: 600; color: var(--text-muted); }

.field-row { display: flex; gap: 14px; flex-wrap: wrap; }

.check-row { display: flex; gap: 20px; flex-wrap: wrap; }

.stamp-form input[type="text"],
.stamp-form textarea,
.stamp-form select {
    font: inherit;
    font-size: 0.92rem;
    color: var(--text);
    background: var(--bg-muted);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    transition: border-color 0.15s ease;
}

.stamp-form input:focus,
.stamp-form textarea:focus,
.stamp-form select:focus {
    outline: none;
    border-color: var(--primary);
}

.stamp-form textarea { resize: vertical; min-height: 84px; }

.segmented { display: flex; border: 1.5px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }

.seg-btn {
    flex: 1;
    padding: 8px 10px;
    border: none;
    background: var(--bg-card);
    color: var(--text-muted);
    font: inherit;
    font-size: 0.87rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.seg-btn + .seg-btn { border-left: 1.5px solid var(--border); }

.seg-btn.active { background: var(--primary); color: #fff; }

.stamp-preview-panel {
    display: flex;
    flex-direction: column;
    gap: 14px;
    align-items: center;
    position: sticky;
    top: 76px;
}

.stamp-preview-frame {
    width: 100%;
    min-height: 280px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px;
    background:
        repeating-conic-gradient(color-mix(in srgb, var(--border) 40%, transparent) 0% 25%, transparent 0% 50%)
        0 0 / 18px 18px,
        var(--bg-muted);
}

#stampPreview { max-width: 100%; height: auto; }

.stamp-preview-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

.fine-print { font-size: 0.76rem; color: var(--text-muted); text-align: center; max-width: 340px; }

/* -------------------------------------------------------- document viewer */

.loading { display: flex; justify-content: center; padding: 36px 0; }
.loading[hidden] { display: none; }

.spinner {
    width: 42px;
    height: 42px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.document-preview { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.document-preview[hidden] { display: none; }

.doc-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
}

.page-indicator { color: var(--text-muted); font-size: 0.9rem; }

.pagination { display: flex; gap: 5px; flex-wrap: wrap; }

.page-btn {
    min-width: 34px;
    height: 34px;
    padding: 0 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.page-btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.page-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.page-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.zoom-controls { display: flex; align-items: center; gap: 8px; }
.zoom-level { font-size: 0.85rem; color: var(--text-muted); min-width: 44px; text-align: center; }

.canvas-container {
    overflow: auto;
    max-height: 78vh;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-muted);
    padding: 14px;
}

/* fabric.js wraps the canvas in its own .canvas-container — neutralize it */
.canvas-container .canvas-container {
    border: none;
    padding: 0;
    background: none;
    overflow: visible;
    max-height: none;
    margin: 0 auto;
    box-shadow: var(--shadow-soft);
}

/* --------------------------------------------------------------- actions */

.options-row { display: flex; gap: 22px; flex-wrap: wrap; margin-bottom: 16px; }

.document-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 10px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text);
    font: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.action-btn:hover { border-color: var(--primary); transform: translateY(-1px); }
.action-btn:active { transform: translateY(0) scale(0.98); }

.primary-btn { background: var(--primary); border-color: var(--primary); color: #fff; }
.primary-btn:hover { background: var(--primary-strong); border-color: var(--primary-strong); }

.info-btn { background: var(--info); border-color: var(--info); color: #fff; }
.warning-btn { background: var(--warning); border-color: var(--warning); color: #fff; }
.stamp-btn { background: var(--stamp); border-color: var(--stamp); color: #fff; }
.success-btn { background: var(--success); border-color: var(--success); color: #fff; }
.danger-btn { background: var(--danger); border-color: var(--danger); color: #fff; }

.info-btn:hover, .warning-btn:hover, .stamp-btn:hover,
.success-btn:hover, .danger-btn:hover { filter: brightness(1.08); }

.clear-btn { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.save-btn { background: var(--success); border-color: var(--success); color: #fff; }

/* -------------------------------------------------------------- progress */

.progress-bar {
    margin-top: 18px;
    height: 8px;
    border-radius: 999px;
    background: var(--bg-muted);
    border: 1px solid var(--border);
    overflow: hidden;
}

.progress-bar[hidden] { display: none; }

.progress {
    height: 100%;
    width: 0;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--primary), var(--success));
    transition: width 0.25s ease;
}

/* ---------------------------------------------------------------- toasts */

.toast-stack {
    position: fixed;
    top: 68px;
    right: 20px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: min(360px, calc(100vw - 40px));
}

.toast {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-left: 4px solid var(--info);
    box-shadow: var(--shadow);
    font-size: 0.9rem;
    animation: toast-in 0.25s ease;
}

.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--danger); }

.toast-out { opacity: 0; transform: translateX(12px); transition: all 0.4s ease; }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---------------------------------------------------------------- footer */

.footer {
    border-top: 1px solid var(--border);
    background: var(--bg-card);
    padding: 22px 20px 28px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.footer-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
}

.made-with-love { color: var(--text); font-weight: 600; text-decoration: none; }
.made-with-love:hover { color: var(--primary); }

.footer-privacy { margin: 0; }

.footer-links { display: flex; align-items: center; gap: 8px; }

.footer-cta {
    padding: 7px 14px;
    border: 1.5px solid var(--border);
    border-radius: 999px;
    background: var(--bg-card);
    color: var(--text);
    font: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.15s ease;
}

.footer-cta:hover { border-color: var(--primary); color: var(--primary); }

.social-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 1px solid var(--border);
    border-radius: 50%;
    color: var(--text-muted);
    transition: all 0.15s ease;
}

.social-btn:hover { color: var(--primary); border-color: var(--primary); transform: translateY(-1px); }

/* --------------------------------------------------------- support modal */

.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(10, 14, 25, 0.6);
    backdrop-filter: blur(4px);
    animation: toast-in 0.2s ease;
}

.modal-overlay[hidden] { display: none; }

.modal-card {
    position: relative;
    width: min(460px, 100%);
    max-height: 90vh;
    overflow-y: auto;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 30px 26px 20px;
    text-align: center;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 50%;
    background: var(--bg-muted);
    color: var(--text-muted);
    font-size: 0.9rem;
    cursor: pointer;
}

.modal-close:hover { color: var(--text); }

.modal-emoji { font-size: 2.4rem; margin-bottom: 6px; }

.modal-card h2 { font-size: 1.3rem; margin-bottom: 8px; }

.modal-sub { color: var(--text-muted); font-size: 0.92rem; margin-bottom: 18px; }

.support-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 18px;
}

.support-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 10px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.86rem;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.15s ease;
}

.support-btn:hover { border-color: var(--primary); color: var(--primary); transform: translateY(-1px); }

.support-btn.star {
    background: linear-gradient(120deg, #f59e0b, #f97316);
    border-color: transparent;
    color: #fff;
}

.support-btn.star:hover { color: #fff; filter: brightness(1.07); }

.modal-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin: 4px 0 14px;
}

.modal-divider::before,
.modal-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.share-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}

.share-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding: 10px 4px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.15s ease;
}

.share-btn:hover { color: var(--primary); border-color: var(--primary); }

.share-copy-row { display: flex; gap: 8px; margin-bottom: 16px; }

.share-copy-input {
    flex: 1;
    min-width: 0;
    padding: 9px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-muted);
    color: var(--text-muted);
    font: inherit;
    font-size: 0.83rem;
}

.share-copy-btn {
    padding: 9px 16px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--primary);
    color: #fff;
    font: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
}

.share-copy-btn:hover { background: var(--primary-strong); }

.modal-later {
    border: none;
    background: none;
    color: var(--text-muted);
    font: inherit;
    font-size: 0.84rem;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.modal-later:hover { color: var(--text); }

@media (max-width: 480px) {
    .support-grid { grid-template-columns: 1fr; }
    .share-grid { grid-template-columns: repeat(2, 1fr); }
    .footer-inner { justify-content: center; text-align: center; }
}

/* ------------------------------------------------------------ responsive */

@media (max-width: 860px) {
    .stamp-designer { grid-template-columns: 1fr; }
    .stamp-preview-panel { position: static; }
    .privacy-pill { display: none; }
    .card { padding: 18px; }
    .hero-section { padding: 40px 16px 52px; }
}

@media (max-width: 520px) {
    .document-actions .action-btn { flex: 1 1 46%; justify-content: center; }
    .doc-toolbar { justify-content: center; }
}

/* ------------------------------------------------------------- a11y bits */

:focus-visible { outline: 2.5px solid var(--primary); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
    html { scroll-behavior: auto; }
}
