/* =========================================================
   PDF Redactor — Modern UI
   No external fonts, no CDN. CSP: style-src 'self'
   ========================================================= */

/* ----- Reset ----- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    /* Brand */
    --brand-50:  #eff6ff;
    --brand-100: #dbeafe;
    --brand-200: #bfdbfe;
    --brand-500: #3b82f6;
    --brand-600: #2563eb;
    --brand-700: #1d4ed8;
    --brand-900: #1e3a8a;

    /* Neutrals */
    --gray-50:  #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;

    /* Semantic */
    --color-success:        #16a34a;
    --color-success-bg:     #f0fdf4;
    --color-success-border: #bbf7d0;
    --color-error:          #dc2626;
    --color-error-bg:       #fef2f2;
    --color-error-border:   #fecaca;

    /* Surface */
    --surface: #ffffff;
    --bg:      #f1f5f9;

    /* Radius */
    --r-sm:   6px;
    --r-md:   10px;
    --r-lg:   16px;
    --r-xl:   20px;
    --r-full: 9999px;

    /* Shadow */
    --shadow-xs: 0 1px 2px rgba(0,0,0,.05);
    --shadow-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.05);
    --shadow-lg: 0 10px 30px rgba(0,0,0,.1), 0 4px 8px rgba(0,0,0,.06);

    /* Transition */
    --ease:   cubic-bezier(.4,0,.2,1);
    --t-fast: 120ms;
    --t-base: 200ms;
}

[hidden] {
    display: none !important;
}

html { font-size: 17px; -webkit-text-size-adjust: 100%; }

@media (max-width: 700px) {
    html { font-size: 16px; }
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 "Inter", Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--gray-800);
    line-height: 1.55;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

.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;
}

/* =========================================================
   NAVBAR
   ========================================================= */
.navbar {
    background: var(--gray-900);
    padding: 0 2.25rem;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 0 rgba(255,255,255,.06);
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: .6rem;
}

.navbar-home-btn {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 12px;
    padding: .22rem .35rem;
    cursor: pointer;
    transition: background var(--t-fast) var(--ease),
                border-color var(--t-fast) var(--ease),
                box-shadow var(--t-fast) var(--ease);
}

.navbar-home-btn:hover {
    background: rgba(255,255,255,.06);
    border-color: rgba(255,255,255,.14);
}

.navbar-home-btn:focus-visible {
    outline: none;
    border-color: rgba(147,197,253,.55);
    box-shadow: 0 0 0 3px rgba(59,130,246,.25);
}

.navbar-logo {
    width: 44px; height: 44px;
    background:
        radial-gradient(100% 100% at 24% 18%, rgba(255,255,255,.4) 0%, transparent 48%),
        linear-gradient(155deg, #5ea2ff 0%, #2f70ea 55%, #1d4ed8 100%);
    border-radius: 11px;
    border: 1px solid rgba(255,255,255,.18);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 8px 18px rgba(23,71,176,.42), inset 0 1px 0 rgba(255,255,255,.35);
}

.navbar-logo svg {
    width: 30px;
    height: 30px;
    filter: drop-shadow(0 1px 1px rgba(15,23,42,.1));
}

.navbar-name {
    font-size: 1rem;
    font-weight: 650;
    color: #fff;
    letter-spacing: -.01em;
}

.navbar-badge {
    font-size: .72rem;
    font-weight: 600;
    color: var(--brand-200);
    background: rgba(59,130,246,.2);
    border: 1px solid rgba(59,130,246,.3);
    padding: .15rem .5rem;
    border-radius: var(--r-full);
    text-transform: uppercase;
    letter-spacing: .04em;
}

/* =========================================================
   HERO
   ========================================================= */
.hero {
    background: linear-gradient(160deg, var(--gray-900) 0%, #1e3058 100%);
    padding: 3.6rem 2rem 4.1rem;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.hero::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse 60% 60% at 50% 120%,
                rgba(59,130,246,.18) 0%, transparent 70%);
    pointer-events: none;
}

.hero-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    font-size: .8rem;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--brand-200);
    background: rgba(59,130,246,.12);
    border: 1px solid rgba(59,130,246,.25);
    padding: .38rem 1rem;
    border-radius: var(--r-full);
    margin-bottom: 1.25rem;
}

.hero-eyebrow-dot {
    width: 6px; height: 6px;
    background: #60a5fa;
    border-radius: 50%;
    animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: .5; transform: scale(.8); }
}

.hero-title {
    font-size: clamp(2.1rem, 4.2vw, 3.25rem);
    font-weight: 700;
    color: #fff;
    letter-spacing: -.02em;
    line-height: 1.2;
    margin-bottom: .75rem;
    text-wrap: balance;
}

.hero-emphasis {
    color: #c8dcff;
    text-shadow: 0 0 12px rgba(147,197,253,.24);
    border-bottom: 2px solid rgba(147,197,253,.38);
    padding-bottom: .02em;
}

.hero-sub {
    font-size: 1.12rem;
    color: rgba(255,255,255,.55);
    max-width: 680px;
    margin: 0 auto 2.25rem;
}

.hero-features {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: .5rem 1.5rem;
}

.hero-feat {
    display: flex;
    align-items: center;
    gap: .35rem;
    font-size: .92rem;
    color: rgba(255,255,255,.5);
}

.hero-feat svg {
    width: 13px; height: 13px;
    color: #60a5fa;
    flex-shrink: 0;
}

/* =========================================================
   MAIN CONTENT
   ========================================================= */
main {
    max-width: 1280px;
    margin: -1.5rem auto 0;
    padding: 0 1.5rem 5rem;
    position: relative;
    z-index: 1;
}

.feature-tiles {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.25rem;
}

.feature-tiles.upload-focused {
    grid-template-columns: 1fr;
}

.feature-tiles.sign-focused {
    grid-template-columns: 1fr;
}

.feature-tiles .step-card {
    margin-bottom: 0;
    height: 100%;
}

/* =========================================================
   DISCLAIMER
   ========================================================= */
.disclaimer-card {
    background: var(--surface);
    border: 1px solid var(--gray-200);
    border-radius: var(--r-xl);
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.disclaimer-summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    padding: 1rem 1.25rem;
    color: var(--gray-900);
    font-size: 1.02rem;
    font-weight: 700;
}

.disclaimer-summary::-webkit-details-marker { display: none; }

.disclaimer-hint {
    font-size: .8rem;
    font-weight: 600;
    color: var(--gray-400);
    text-transform: uppercase;
    letter-spacing: .05em;
}

.disclaimer-card[open] .disclaimer-summary {
    border-bottom: 1px solid var(--gray-100);
}

.disclaimer-body {
    padding: 1rem 1.25rem 1.2rem;
    color: var(--gray-600);
    font-size: .95rem;
    line-height: 1.65;
}

.disclaimer-body p + p {
    margin-top: .75rem;
}

/* =========================================================
   FEEDBACK
   ========================================================= */
.feedback-card {
    margin-bottom: 0;
}

.feedback-form {
    display: flex;
    flex-direction: column;
    gap: .8rem;
}

.feedback-intro {
    font-size: .98rem;
    color: var(--gray-500);
    margin-top: -.15rem;
}

.rating-row {
    display: flex;
    gap: .45rem;
    flex-wrap: wrap;
}

.rating-btn {
    min-width: 42px;
    padding: .52rem .92rem;
    border-radius: var(--r-md);
    border: 1px solid var(--gray-200);
    background: var(--surface);
    color: var(--gray-700);
    font-size: .93rem;
    font-weight: 700;
    cursor: pointer;
    transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast), color var(--t-fast);
}

.rating-btn:hover {
    border-color: var(--brand-500);
    color: var(--brand-700);
}

.rating-btn.is-active {
    border-color: var(--brand-600);
    background: var(--brand-50);
    color: var(--brand-700);
    box-shadow: 0 0 0 2px rgba(59,130,246,.12);
}

.rating-scale {
    font-size: .84rem;
    color: var(--gray-400);
    margin-top: -.25rem;
}

.feedback-label {
    display: block;
    font-size: .8rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--gray-400);
    margin-bottom: .35rem;
}

.feedback-textarea {
    width: 100%;
    border: 1px solid var(--gray-200);
    border-radius: var(--r-md);
    padding: .65rem .8rem;
    font-size: .95rem;
    color: var(--gray-800);
    background: var(--surface);
}

.feedback-textarea {
    resize: vertical;
    min-height: 108px;
    line-height: 1.5;
}

.feedback-textarea:focus {
    outline: none;
    border-color: var(--brand-500);
    box-shadow: 0 0 0 3px rgba(59,130,246,.12);
}

.feedback-meta {
    display: flex;
    justify-content: flex-end;
}

.feedback-counter {
    font-size: .8rem;
    color: var(--gray-400);
}

.feedback-actions {
    display: flex;
    align-items: center;
    gap: .7rem;
    flex-wrap: wrap;
}

.feedback-status {
    font-size: .9rem;
    color: var(--gray-500);
}

.feedback-status.success {
    color: var(--color-success);
}

.feedback-status.error {
    color: var(--color-error);
}

/* =========================================================
   STEP CARD
   ========================================================= */
.step-card {
    background: var(--surface);
    border: 1px solid var(--gray-200);
    border-radius: var(--r-xl);
    padding: 2.2rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-md);
}

.step-header {
    display: flex;
    align-items: center;
    gap: .85rem;
    margin-bottom: 1.45rem;
}

.step-badge {
    width: 32px; height: 32px;
    border-radius: var(--r-md);
    background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
    color: #fff;
    font-weight: 700;
    font-size: .85rem;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(37,99,235,.35);
}

.step-title {
    font-size: 1.42rem;
    font-weight: 700;
    color: var(--gray-900);
    letter-spacing: -.02em;
}

.step-subtitle {
    font-size: .96rem;
    color: var(--gray-500);
    margin-top: .1rem;
}

/* =========================================================
   SIGNATURE FEATURE PREVIEW
   ========================================================= */
.signature-feature-card {
    border-color: var(--gray-200);
    background: var(--surface);
}

.signature-feature-header {
    align-items: center;
}

.signature-preview-shell {
    border: 2px dashed var(--gray-200);
    border-radius: var(--r-lg);
    background: var(--gray-50);
    padding: 1.25rem;
}

.signature-flow-controls {
    display: flex;
    gap: .65rem;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: .8rem;
}

.sign-upload-row {
    display: flex;
    align-items: center;
    gap: .65rem;
    flex-wrap: wrap;
    margin-bottom: .9rem;
}

.sign-upload-status {
    font-size: .92rem;
    color: #64748b;
}

.signature-workspace {
    border: 1px solid #dbe7f4;
    border-radius: var(--r-md);
    padding: 1.05rem;
    background: #ffffff;
}

.signature-step {
    border: 1px solid #dbe6f5;
    border-radius: var(--r-md);
    background: #fcfdff;
    padding: 1rem;
}

.signature-step + .signature-step {
    margin-top: .85rem;
}

.signature-step-title {
    font-size: 1.06rem;
    font-weight: 700;
    color: #1e293b;
}

.signature-step-subtitle {
    margin-top: .2rem;
    margin-bottom: .6rem;
    font-size: .9rem;
    color: #64748b;
}

.signature-step-actions {
    margin-top: .75rem;
}

.signature-mode-row {
    display: flex;
    gap: .6rem;
    flex-wrap: wrap;
    margin-bottom: .75rem;
}

.signature-mode-btn {
    border: 1px solid #cddcf2;
    border-radius: var(--r-full);
    padding: .48rem 1rem;
    background: #ffffff;
    color: #475569;
    font-size: .92rem;
    font-weight: 600;
    cursor: pointer;
}

.signature-mode-btn.is-active {
    color: #1d4ed8;
    border-color: #8cb9fb;
    background: #e9f1ff;
}

.signature-draw-panel {
    background: #ffffff;
    border: 1px solid #d7e3f5;
    border-radius: var(--r-md);
    padding: .8rem;
}

.signature-pad-canvas {
    width: 100%;
    min-height: 172px;
    height: 190px;
    border-radius: var(--r-sm);
    border: 1px solid #d4def0;
    background: #ffffff;
    cursor: crosshair;
    touch-action: none;
    display: block;
}

.signature-pad-toolbar {
    margin-top: .6rem;
    display: flex;
    gap: .65rem;
    align-items: center;
    flex-wrap: wrap;
}

.signature-pad-toolbar span {
    font-size: .87rem;
    color: #64748b;
    line-height: 1.4;
}

.signature-text-panel {
    margin-top: .3rem;
    padding: .2rem 0;
}

.signature-text-input {
    width: 100%;
    border: 1px solid #d6e2f3;
    border-radius: var(--r-md);
    background: #ffffff;
    color: #0f172a;
    font-size: 1rem;
    padding: .7rem .82rem;
}

.signature-text-input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59,130,246,.12);
}

.signature-text-help {
    margin: .45rem 0 0;
    font-size: .86rem;
    color: #64748b;
    line-height: 1.45;
}

.signature-placement-note {
    margin-top: .75rem;
    font-size: .87rem;
    color: #64748b;
    line-height: 1.45;
}

.signature-size-control {
    margin-top: .6rem;
    display: flex;
    align-items: center;
    gap: .65rem;
    flex-wrap: wrap;
}

.signature-size-control label {
    font-size: .9rem;
    color: #475569;
    font-weight: 600;
}

.signature-size-control input[type="range"] {
    width: min(280px, 65vw);
}

.signature-size-control span {
    font-size: .9rem;
    color: #334155;
    font-weight: 700;
    min-width: 3.2rem;
}

.signature-page-nav {
    display: flex;
    align-items: center;
    gap: .55rem;
    margin-bottom: .65rem;
}

.signature-page-selector {
    display: flex;
    align-items: center;
    gap: .55rem;
    flex-wrap: wrap;
    margin-bottom: .7rem;
}

.signature-page-checkbox {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    font-size: .9rem;
    color: #334155;
    font-weight: 600;
}

.signature-page-checkbox input[type="checkbox"] {
    width: 16px;
    height: 16px;
}

.sign-selected-pages-label {
    font-size: .86rem;
    color: #64748b;
    margin-right: .3rem;
}

.sign-page-stage {
    position: relative;
    border: 1px solid #d7e3f5;
    border-radius: var(--r-md);
    background: #ffffff;
    overflow: hidden;
    min-height: 220px;
}

.sign-page-image {
    width: 100%;
    height: auto;
    display: block;
    user-select: none;
    -webkit-user-drag: none;
    pointer-events: none;
}

.sign-placement-stamp {
    position: absolute;
    border: 2px solid #2563eb;
    border-radius: .45rem;
    background: rgba(37,99,235,.12);
    box-shadow: 0 8px 22px rgba(37,99,235,.18);
    cursor: grab;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: .22rem .35rem;
    touch-action: none;
}

.sign-placement-stamp.is-dragging {
    cursor: grabbing;
}

.sign-placement-stamp-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.sign-placement-stamp-text {
    color: #111111;
    font-weight: 500;
    font-style: italic;
    font-family: "Brush Script MT", "Segoe Script", "Lucida Handwriting", "Snell Roundhand", cursive;
    font-size: 1.2rem;
    white-space: nowrap;
    line-height: 1;
}

.signature-preview-actions {
    margin-top: .9rem;
    display: flex;
    gap: .65rem;
    align-items: center;
    flex-wrap: wrap;
}

.sign-action-status {
    font-size: .9rem;
    color: #64748b;
    min-height: 1.2em;
}

.sign-action-status.success {
    color: var(--color-success);
}

.sign-action-status.error {
    color: var(--color-error);
}

.signature-preview-actions span {
    font-size: .9rem;
    color: #64748b;
    line-height: 1.45;
}

@media (max-width: 700px) {
    main {
        padding: 0 1rem 4rem;
    }

    .feature-tiles {
        grid-template-columns: 1fr;
        justify-items: center;
        gap: 1rem;
    }

    #upload-section,
    #signature-feature-section {
        width: 100%;
        max-width: 430px;
    }

    .signature-pad-canvas {
        min-height: 140px;
        height: 150px;
    }
    .signature-page-nav {
        flex-wrap: wrap;
    }
}

/* =========================================================
   DROP ZONE
   ========================================================= */
.drop-zone {
    position: relative;
    border: 2px dashed var(--gray-200);
    border-radius: var(--r-lg);
    padding: 4rem 2.25rem;
    text-align: center;
    cursor: pointer;
    transition: border-color var(--t-base) var(--ease),
                background   var(--t-base) var(--ease),
                transform    var(--t-fast) var(--ease);
    background: var(--gray-50);
}

.drop-zone:hover {
    border-color: var(--brand-500);
    background: var(--brand-50);
}

.drop-zone:focus-visible {
    outline: none;
    border-color: var(--brand-500);
    box-shadow: 0 0 0 4px rgba(59,130,246,.15);
}

.drop-zone.drag-over {
    border-color: var(--brand-500);
    background: var(--brand-50);
    transform: scale(1.005);
    box-shadow: 0 0 0 4px rgba(59,130,246,.12);
}

.drop-zone input[type="file"] {
    position: absolute; inset: 0;
    opacity: 0; cursor: pointer;
    width: 100%; height: 100%;
    pointer-events: none;
}

.dz-icon-wrap {
    width: 72px; height: 72px;
    border-radius: var(--r-lg);
    background: linear-gradient(135deg, var(--brand-50), var(--brand-100));
    border: 1px solid var(--brand-200);
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 1.25rem;
    transition: transform var(--t-base) var(--ease);
}

.drop-zone:hover .dz-icon-wrap { transform: translateY(-2px); }

.dz-icon-wrap svg {
    width: 32px; height: 32px;
    color: var(--brand-600);
}

.dz-title {
    font-size: 1.28rem;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: .35rem;
}

.dz-title span { color: var(--brand-600); }

.dz-hint {
    font-size: .92rem;
    color: var(--gray-400);
}

.dz-formats {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    margin-top: 1.25rem;
}

.dz-chip {
    font-size: .78rem;
    font-weight: 600;
    letter-spacing: .04em;
    color: var(--gray-500);
    background: var(--gray-100);
    border: 1px solid var(--gray-200);
    padding: .26rem .72rem;
    border-radius: var(--r-full);
}

.status-message {
    margin-top: 1rem;
    font-size: .92rem;
    color: var(--gray-400);
    text-align: center;
    min-height: 1.4em;
}

.upload-assist {
    margin-top: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .65rem;
    flex-wrap: wrap;
}

.upload-assist span {
    font-size: .9rem;
    color: var(--gray-500);
}

/* =========================================================
   REDACT LAYOUT
   ========================================================= */
.redact-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 1.5rem;
    align-items: start;
}

@media (max-width: 700px) {
    .redact-layout { grid-template-columns: 1fr; }
}

.panel-label {
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--gray-400);
    margin-bottom: .6rem;
}

.panel-desc {
    font-size: .9rem;
    color: var(--gray-500);
    margin-bottom: .85rem;
    line-height: 1.5;
}

/* ----- Patterns panel ----- */
.patterns-panel {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--r-lg);
    padding: 1.25rem;
}

.pattern-textarea {
    width: 100%;
    border: 1px solid var(--gray-200);
    border-radius: var(--r-md);
    padding: .7rem .9rem;
    font-family: "Menlo", "Consolas", "SF Mono", monospace;
    font-size: .88rem;
    resize: vertical;
    background: var(--surface);
    color: var(--gray-800);
    transition: border-color var(--t-base) var(--ease),
                box-shadow   var(--t-base) var(--ease);
    line-height: 1.6;
}

.pattern-textarea:focus {
    outline: none;
    border-color: var(--brand-500);
    box-shadow: 0 0 0 3px rgba(59,130,246,.12);
}

.pattern-textarea::placeholder { color: var(--gray-400); }

.pattern-count {
    font-size: .78rem;
    color: var(--gray-400);
    text-align: right;
    margin-top: .35rem;
}

/* ----- Canvas panel ----- */
.canvas-panel {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--r-lg);
    padding: 1.25rem;
}

.canvas-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: .75rem;
}

.page-nav {
    display: flex;
    align-items: center;
    gap: .5rem;
    background: var(--surface);
    border: 1px solid var(--gray-200);
    border-radius: var(--r-md);
    padding: .2rem .35rem;
}

.page-nav-btn {
    background: none;
    border: none;
    cursor: pointer;
    width: 28px; height: 28px;
    border-radius: var(--r-sm);
    color: var(--gray-600);
    font-size: .9rem;
    display: flex; align-items: center; justify-content: center;
    transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}

.page-nav-btn:hover:not(:disabled) {
    background: var(--gray-100);
    color: var(--gray-900);
}

.page-nav-btn:disabled { opacity: .35; cursor: not-allowed; }

.page-indicator {
    font-size: .84rem;
    font-weight: 600;
    color: var(--gray-600);
    min-width: 72px;
    text-align: center;
    user-select: none;
}

/* Canvas */
.canvas-wrapper {
    position: relative;
    display: block;
    border: 1px solid var(--gray-200);
    border-radius: var(--r-md);
    overflow: hidden;
    cursor: crosshair;
    background: var(--gray-300);
    box-shadow: var(--shadow-xs);
}

#pdf-canvas { display: block; max-width: 100%; }

#selection-overlay {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
}

.selection-box {
    position: absolute;
    background: rgba(239,68,68,.15);
    border: 2px solid #ef4444;
    border-radius: 3px;
    pointer-events: none;
}

#active-selection {
    position: absolute;
    background: rgba(59,130,246,.15);
    border: 2px dashed var(--brand-500);
    border-radius: 3px;
    pointer-events: none;
    display: none;
}

/* Regions list */
.regions-list {
    margin-top: .85rem;
    display: flex;
    flex-direction: column;
    gap: .35rem;
    max-height: 130px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--gray-300) transparent;
}

.regions-list:empty::after {
    content: 'No regions selected yet — drag on the page above';
    display: block;
    font-size: .84rem;
    color: var(--gray-400);
    text-align: center;
    padding: .5rem 0;
}

.region-item {
    display: flex;
    align-items: center;
    gap: .5rem;
    background: var(--surface);
    border: 1px solid var(--gray-200);
    border-radius: var(--r-sm);
    padding: .3rem .5rem .3rem .75rem;
    font-size: .84rem;
    color: var(--gray-600);
}

.region-dot {
    width: 8px; height: 8px;
    background: #ef4444;
    border-radius: 50%;
    flex-shrink: 0;
}

.region-label { flex: 1; }

.region-remove {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--gray-400);
    font-size: 1rem;
    line-height: 1;
    padding: .1rem .3rem;
    border-radius: var(--r-sm);
    transition: background var(--t-fast), color var(--t-fast);
}

.region-remove:hover {
    background: var(--color-error-bg);
    color: var(--color-error);
}

/* =========================================================
   ACTION BAR
   ========================================================= */
.action-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 1.75rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--gray-100);
    flex-wrap: wrap;
}

.action-bar-left {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .9rem;
    color: var(--gray-400);
}

.action-bar-left svg { width: 14px; height: 14px; color: var(--color-success); }

/* =========================================================
   DOWNLOAD SECTION
   ========================================================= */
.download-card {
    text-align: center;
    padding: 1rem 0 .5rem;
}

.success-circle {
    width: 72px; height: 72px;
    border-radius: 50%;
    background: var(--color-success-bg);
    border: 2px solid var(--color-success-border);
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 1.25rem;
    animation: pop-in .4s var(--ease) both;
}

@keyframes pop-in {
    from { transform: scale(.7); opacity: 0; }
    to   { transform: scale(1);  opacity: 1; }
}

.success-circle svg {
    width: 32px; height: 32px;
    color: var(--color-success);
}

.download-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--gray-900);
    margin-bottom: .4rem;
    letter-spacing: -.02em;
}

.download-sub {
    font-size: .95rem;
    color: var(--gray-500);
    margin-bottom: .5rem;
}

.download-note {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    font-size: .82rem;
    color: var(--gray-400);
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--r-full);
    padding: .25rem .85rem;
    margin-bottom: 2rem;
}

.download-note svg { width: 12px; height: 12px; }

.download-actions {
    display: flex;
    gap: .85rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* =========================================================
   BUTTONS
   ========================================================= */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .45rem;
    padding: .68rem 1.35rem;
    border-radius: var(--r-md);
    font-size: .95rem;
    font-weight: 650;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background var(--t-fast) var(--ease),
                color var(--t-fast) var(--ease),
                border-color var(--t-fast) var(--ease),
                box-shadow var(--t-fast) var(--ease),
                transform var(--t-fast) var(--ease);
    white-space: nowrap;
    letter-spacing: -.01em;
    user-select: none;
}

.btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(59,130,246,.3);
}

.btn:active:not(:disabled) { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; }

/* Primary */
.btn-primary {
    background: linear-gradient(160deg, var(--brand-500), var(--brand-700));
    color: #fff;
    box-shadow: 0 2px 8px rgba(37,99,235,.35), 0 1px 2px rgba(37,99,235,.2);
}

.btn-primary:hover:not(:disabled) {
    background: linear-gradient(160deg, var(--brand-600), #1e40af);
    box-shadow: 0 4px 14px rgba(37,99,235,.45), 0 1px 3px rgba(37,99,235,.25);
    transform: translateY(-1px);
}

/* Ghost */
.btn-ghost {
    background: transparent;
    color: var(--gray-600);
    border-color: var(--gray-200);
}

.btn-ghost:hover:not(:disabled) {
    background: var(--gray-50);
    color: var(--gray-800);
    border-color: var(--gray-300);
}

/* Sizes */
.btn-lg {
    padding: .82rem 1.95rem;
    font-size: 1.02rem;
    border-radius: var(--r-lg);
}

.btn-sm {
    padding: .46rem .95rem;
    font-size: .88rem;
}

/* =========================================================
   ERROR BANNER
   ========================================================= */
.error-banner {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    max-width: 520px;
    width: calc(100% - 2rem);
    background: var(--surface);
    border: 1px solid var(--color-error-border);
    border-left: 4px solid var(--color-error);
    color: var(--gray-700);
    border-radius: var(--r-lg);
    padding: .85rem 1rem .85rem 1.25rem;
    display: flex;
    align-items: flex-start;
    gap: .85rem;
    box-shadow: var(--shadow-lg);
    font-size: .875rem;
    z-index: 1000;
    animation: slide-up .2s var(--ease) both;
}

.error-banner[hidden] { display: none; }

@keyframes slide-up {
    from { transform: translateX(-50%) translateY(1rem); opacity: 0; }
    to   { transform: translateX(-50%) translateY(0);    opacity: 1; }
}

.error-icon {
    width: 18px; height: 18px;
    color: var(--color-error);
    flex-shrink: 0;
    margin-top: .1rem;
}

.error-body { flex: 1; }
.error-title { font-weight: 600; color: var(--gray-900); margin-bottom: .15rem; }
.error-msg   { color: var(--gray-500); font-size: .8rem; }

.error-close {
    background: none; border: none; cursor: pointer;
    color: var(--gray-400); font-size: 1.1rem; line-height: 1;
    padding: .1rem .3rem; border-radius: var(--r-sm); flex-shrink: 0;
    transition: color var(--t-fast);
}

.error-close:hover { color: var(--gray-700); }

/* =========================================================
   LOADING OVERLAY
   ========================================================= */
.loading-overlay {
    position: fixed; inset: 0;
    background: rgba(249,250,251,.85);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.25rem;
    z-index: 900;
    animation: fade-in .15s var(--ease);
}

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

@keyframes fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.loading-card {
    background: var(--surface);
    border: 1px solid var(--gray-200);
    border-radius: var(--r-xl);
    padding: 2rem 2.5rem;
    text-align: center;
    box-shadow: var(--shadow-lg);
    min-width: 200px;
}

.spinner {
    width: 36px; height: 36px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--brand-600);
    border-radius: 50%;
    animation: spin .65s linear infinite;
    margin: 0 auto 1rem;
}

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

.loading-text {
    font-size: .875rem;
    font-weight: 600;
    color: var(--gray-700);
}

.loading-sub {
    font-size: .75rem;
    color: var(--gray-400);
    margin-top: .25rem;
}

/* =========================================================
   RESOURCES
   ========================================================= */
.resources-card {
    margin-bottom: 0;
}

.resources-head h2 {
    font-size: 1.1rem;
    color: var(--gray-900);
    letter-spacing: -.02em;
    margin-bottom: .35rem;
}

.resources-head p {
    color: var(--gray-500);
    font-size: .86rem;
}

.resources-grid {
    margin-top: 1rem;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: .6rem;
}

.resource-link {
    display: block;
    border: 1px solid var(--gray-200);
    background: var(--gray-50);
    border-radius: var(--r-md);
    padding: .65rem .8rem;
    color: var(--gray-700);
    font-size: .84rem;
    font-weight: 600;
    text-decoration: none;
    transition: border-color var(--t-fast), background var(--t-fast), color var(--t-fast), transform var(--t-fast);
}

.resource-link:hover {
    border-color: var(--brand-500);
    background: var(--brand-50);
    color: var(--brand-700);
    transform: translateY(-1px);
}
