/* ============================================
   Design Tokens
   ============================================ */
:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    --bg: #f8fafc;
    --surface: #ffffff;
    --text: #1e293b;
    --text-light: #64748b;
    --border: #e2e8f0;
    --error: #ef4444;
    --error-light: #fef2f2;
    --success: #22c55e;
    --success-light: #f0fdf4;
    --info-bg: #e0f2fe;
    --info-text: #0369a1;
    --info-border: #bae6fd;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --transition: 0.2s ease;
    --page-area-bg: #94a3b8;
    --tooltip-bg: #1e293b;
    --tooltip-text: #f1f5f9;
    --success-border: #bbf7d0;
    --error-border: #fecaca;
    --note-bg: #fef9c3;
    --note-border: #eab308;
    --note-header: #92400e;
}

/* ============================================
   Dark Theme Overrides
   ============================================ */
[data-theme="dark"] {
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-light: #1e3a5f;
    --bg: #0f172a;
    --surface: #1e293b;
    --text: #f1f5f9;
    --text-light: #94a3b8;
    --border: #334155;
    --error: #f87171;
    --error-light: #451a1a;
    --success: #4ade80;
    --success-light: #14532d;
    --info-bg: #0c4a6e;
    --info-text: #7dd3fc;
    --info-border: #075985;
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
    --page-area-bg: #475569;
    --tooltip-bg: #f1f5f9;
    --tooltip-text: #1e293b;
    --success-border: #166534;
    --error-border: #991b1b;
    --note-bg: #854d0e;
    --note-border: #a16207;
    --note-header: #fef9c3;
}

[data-theme-transitioning] * {
    transition: background-color 0.3s, color 0.3s, border-color 0.3s !important;
}

/* ============================================
   Reset & Base
   ============================================ */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    margin: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

h2 { font-size: 1.25rem; margin-bottom: 1rem; }
p  { line-height: 1.6; color: var(--text-light); }

/* ============================================
   Layout
   ============================================ */
main {
    flex: 1;
    padding: 1rem;
    width: 100%;
}

.card {
    background: var(--surface);
    padding: 1rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

/* ============================================
   Shared Components
   ============================================ */
.hidden { display: none !important; }

.btn {
    background-color: var(--primary);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
    transition: background-color var(--transition), transform var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

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

.btn:disabled {
    background-color: var(--border);
    cursor: not-allowed;
    opacity: 0.7;
    transform: none;
}

.btn-outline {
    background-color: transparent;
    border: 2px solid var(--primary);
    color: var(--primary);
}

.btn-outline:hover { background-color: var(--primary-light); }


input[type="text"],
input[type="number"] {
    padding: 0.6rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 1rem;
    width: 100%;
    background: var(--surface);
    color: var(--text);
    transition: border-color var(--transition);
}

input[type="text"]:focus,
input[type="number"]:focus {
    outline: none;
    border-color: var(--primary);
}

/* ============================================
   PDF Editor
   ============================================ */

.color-circle {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform var(--transition), box-shadow var(--transition);
}

.color-circle:hover { transform: scale(1.15); }

[data-theme="dark"] .color-circle {
    border-color: rgba(241, 245, 249, 0.25);
}

.color-circle.selected {
    transform: scale(1.15);
    box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--primary);
}

.page-wrapper {
    position: relative;
    box-shadow: var(--shadow-lg);
    border-radius: 4px;
    overflow: hidden;
    background: var(--page-area-bg);
    margin-bottom: 20px;
}

.draw-layer {
    position: absolute;
    top: 0;
    left: 0;
    cursor: crosshair;
    touch-action: none;
    z-index: 10;
}

#pdf-text-input {
    position: absolute;
    z-index: 20;
    border: 2px solid var(--primary);
    background: var(--surface);
    padding: 4px 8px;
    font-family: Helvetica, Arial, sans-serif;
    font-size: 16px;
    outline: none;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
    border-radius: 4px;
    min-width: 50px;
    white-space: nowrap;
}

.pdf-empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-light);
}

.pdf-empty-state svg {
    display: block;
    margin: 0 auto 1rem;
    color: #cbd5e1;
}

[data-theme="dark"] .pdf-empty-state svg { color: #475569; }

.pdf-drop-zone {
    cursor: pointer;
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    margin: 2rem;
    transition: border-color var(--transition), background var(--transition);
}

.pdf-drop-zone:hover {
    border-color: var(--primary);
    background: color-mix(in srgb, var(--primary) 4%, transparent);
}

.pdf-drop-zone.drag-active {
    border-color: var(--primary);
    background: color-mix(in srgb, var(--primary) 8%, transparent);
}


.context-separator {
    width: 1px;
    height: 24px;
    background: var(--border);
    margin: 0 2px;
}

.color-swatch-black  { background-color: #000; }
.color-swatch-blue   { background-color: #2563eb; }
.color-swatch-red    { background-color: #ef4444; }
.color-swatch-green  { background-color: #22c55e; }
.color-swatch-white  { background-color: #fff; border: 1px solid var(--border); }

.color-swatch-yellow  { background-color: #ffff00; }
.color-swatch-fuchsia { background-color: #ff66cc; }
.color-swatch-cyan    { background-color: #00e5ff; }
.color-swatch-lime    { background-color: #99ff00; }
.color-swatch-orange  { background-color: #ffa600; }

.color-control {
    gap: 8px;
    flex-wrap: nowrap;
}

.color-presets {
    display: flex;
    gap: 5px;
    align-items: center;
}

.color-picker-input {
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    background: none;
}

.color-picker-input::-webkit-color-swatch-wrapper { padding: 2px; }
.color-picker-input::-webkit-color-swatch { border: none; border-radius: 2px; }

.color-hex-input {
    width: 70px;
    padding: 3px 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.75rem;
    font-family: monospace;
    text-transform: uppercase;
}


.font-size-input {
    width: 52px;
    padding: 3px 4px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.8rem;
    text-align: center;
}

.font-family-select {
    padding: 3px 4px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.8rem;
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
    height: 26px;
}

.font-size-input,
.font-family-select,
.color-hex-input,
.color-picker-input {
    height: 26px;
    box-sizing: border-box;
}

.theme-toggle-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px;
    cursor: pointer;
    color: var(--text-light);
    transition: color var(--transition), border-color var(--transition), transform 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle-btn:hover {
    color: var(--text);
    border-color: var(--text-light);
}

.theme-toggle-btn .theme-icon {
    transition: opacity 0.2s ease;
}

.ml-auto { margin-left: auto; }

.drop-zone-title {
    font-size: 1.1rem;
    font-weight: 500;
}

.drop-zone-subtitle {
    font-size: 0.85rem;
    margin-top: 0.25rem;
}

.modal-description {
    color: var(--text-light);
    font-size: 0.9rem;
}

.mt-sm { margin-top: 0.5rem; }

/* ============================================
   PDF Editor — 3-Column Layout
   ============================================ */
.pdf-editor-layout {
    display: flex;
    height: calc(100vh - 4rem - 2rem);
    gap: 0;
    position: relative;
}

/* Left Tool Sidebar */
.pdf-left-sidebar {
    width: 56px;
    flex-shrink: 0;
    background: var(--bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 8px 4px;
    gap: 2px;
    overflow-y: auto;
}

.pdf-left-sidebar .sidebar-group-label {
    font-size: 0.6rem;
    color: var(--text-light);
    text-align: center;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    margin: 4px 0 2px;
}

.pdf-left-sidebar .sidebar-separator {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

.pdf-left-sidebar .sidebar-spacer { flex: 1; }

.sidebar-tool-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    padding: 6px 2px;
    border: 1px solid transparent;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text);
    font-size: 0.6rem;
    transition: background-color var(--transition), color var(--transition), border-color var(--transition);
    width: 100%;
}

.sidebar-tool-btn:hover { background: var(--border); }

.sidebar-tool-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.sidebar-tool-btn.delete-btn {
    color: var(--error);
}

.sidebar-tool-btn.delete-btn:hover { background: var(--error-light); }

.sidebar-tool-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.sidebar-tool-btn svg { flex-shrink: 0; }

/* Center Area */
.pdf-center-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

/* Context-Sensitive Top Bar */
.pdf-context-bar {
    padding: 6px 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    min-height: 44px;
}

.context-control {
    display: flex;
    gap: 6px;
    align-items: center;
    background: var(--bg);
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-light);
    white-space: nowrap;
}

.context-control label { font-size: 0.8rem; }

.context-control input[type="range"] {
    width: 60px;
    accent-color: var(--primary);
    padding: 0;
    border: none;
}

.context-control .value-label {
    font-weight: 600;
    color: var(--text);
    min-width: 32px;
    text-align: right;
}

/* Pages scroll area */
.pdf-pages-scroll {
    flex: 1;
    overflow-y: auto;
    background: var(--page-area-bg);
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Right Page Sidebar */
.pdf-right-sidebar {
    width: 150px;
    flex-shrink: 0;
    background: var(--bg);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: width var(--transition);
    overflow: hidden;
}

.pdf-right-sidebar.collapsed { width: 0; border-left: none; }

.expand-sidebar-btn {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-right: none;
    border-radius: 6px 0 0 6px;
    padding: 12px 4px;
    cursor: pointer;
    color: var(--text-light);
    font-size: 0.7rem;
    z-index: 10;
    transition: color var(--transition);
}

.expand-sidebar-btn:hover { color: var(--primary); }

.right-sidebar-header {
    padding: 8px;
    border-bottom: 1px solid var(--border);
}

.right-sidebar-header .header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.right-sidebar-header .header-row span {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text);
}

.right-sidebar-header .header-actions {
    display: flex;
    gap: 4px;
}

.right-sidebar-header .header-actions button {
    font-size: 0.65rem;
    padding: 3px 6px;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    transition: background-color var(--transition), color var(--transition), border-color var(--transition);
}

.right-sidebar-header .header-actions button:hover {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary);
}

.collapse-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.7rem;
    color: var(--text-light);
    padding: 2px;
}

.thumbnail-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.thumbnail-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px;
    cursor: grab;
    transition: border-color var(--transition), transform 200ms ease;
}

.thumbnail-card:hover { border-color: var(--primary); }

.thumbnail-card.active { border: 2px solid var(--primary); }

.thumbnail-card.dragging { opacity: 0.5; }

.thumbnail-card.drag-over {
    border-color: var(--primary);
    border-style: dashed;
}

.thumbnail-canvas {
    width: 100%;
    border-radius: 3px;
    background: var(--bg);
    margin-bottom: 4px;
}

.thumbnail-label {
    text-align: center;
    font-size: 0.65rem;
    color: var(--text-light);
    margin-bottom: 4px;
}

.thumbnail-actions {
    display: flex;
    justify-content: center;
    gap: 3px;
}

.thumbnail-actions button {
    font-size: 0.65rem;
    background: var(--bg);
    padding: 2px 5px;
    border-radius: 3px;
    cursor: pointer;
    border: none;
    color: var(--text);
    transition: background-color var(--transition), color var(--transition);
}

.thumbnail-actions button:hover { background: var(--border); }

.thumbnail-actions .del-page-btn {
    color: var(--error);
    background: var(--error-light);
}

.thumbnail-actions .del-page-btn:hover { background: var(--error); color: white; }

.thumbnail-actions button:disabled { opacity: 0.3; cursor: not-allowed; }

/* Split modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active { display: flex; }

.modal-content {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    max-width: 480px;
    width: 90%;
    box-shadow: var(--shadow-lg);
}

.modal-content h2 { margin-top: 0; }

.modal-content .modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 16px;
}

.modal-content .range-preview {
    background: var(--bg);
    padding: 12px;
    border-radius: var(--radius);
    margin-top: 8px;
    font-size: 0.85rem;
    color: var(--text-light);
    min-height: 40px;
}

.modal-content .range-error {
    color: var(--error);
    font-size: 0.8rem;
    margin-top: 4px;
}

/* ============================================
   Focus & Accessibility
   ============================================ */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

:focus:not(:focus-visible) {
    outline: none;
}

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

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 900px) {
    .pdf-right-sidebar { width: 0; border-left: none; }
}

@media (max-width: 600px) {
    /* Remove excess outer padding */
    main { padding: 0; }
    .card {
        padding: 0;
        border-radius: 0;
        box-shadow: none;
    }

    /* Full-height layout */
    .pdf-editor-layout {
        flex-direction: column;
        height: 100vh;
        height: 100dvh; /* accounts for mobile browser chrome */
    }

    /* Right sidebar — explicitly remove from layout */
    .pdf-right-sidebar { display: none; }

    /* Horizontal toolbar */
    .pdf-left-sidebar {
        width: auto;
        flex-direction: row;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 4px 6px;
        overflow-x: auto;
        overflow-y: hidden;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .pdf-left-sidebar::-webkit-scrollbar { display: none; }

    .pdf-left-sidebar .sidebar-group-label { display: none; }

    .pdf-left-sidebar .sidebar-separator {
        width: 1px;
        height: 24px;
        margin: 0 2px;
        flex-shrink: 0;
    }

    .pdf-left-sidebar .sidebar-spacer { display: none; }

    .sidebar-tool-btn {
        flex-direction: row;
        padding: 10px;
        font-size: 0;
        min-width: 44px;
        min-height: 44px;
        flex-shrink: 0;
    }

    /* Compact context bar — horizontal scroll instead of wrapping */
    .pdf-context-bar {
        padding: 4px 8px;
        gap: 6px;
        flex-wrap: nowrap;
        overflow-x: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        min-height: 38px;
    }
    .pdf-context-bar::-webkit-scrollbar { display: none; }

    .context-control {
        padding: 3px 6px;
        font-size: 0.75rem;
        flex-shrink: 0;
    }

    /* Visually hide labels but keep accessible to screen readers */
    .context-control > span:first-child:not(.value-label) {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }

    /* Hide hex input on mobile — too tiny to use */
    .color-hex-input { display: none; }

    /* Narrower range inputs */
    .context-control input[type="range"] { width: 48px; }

    /* Hide stroke preview on mobile */
    .stroke-preview { display: none; }

    /* Compact context separator */
    .context-separator { margin: 0; height: 20px; }

    /* Compact download button — icon only */
    #pdf-btn-download {
        padding: 8px 12px;
        font-size: 0;
        min-width: 40px;
    }
    #pdf-btn-download::before {
        content: '';
        display: block;
        width: 18px;
        height: 18px;
        background: currentColor;
        -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4'/%3E%3Cpolyline points='7 10 12 15 17 10'/%3E%3Cline x1='12' y1='15' x2='12' y2='3'/%3E%3C/svg%3E") center/contain no-repeat;
        mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4'/%3E%3Cpolyline points='7 10 12 15 17 10'/%3E%3Cline x1='12' y1='15' x2='12' y2='3'/%3E%3C/svg%3E") center/contain no-repeat;
    }

    /* Zoom controls tight */
    .zoom-controls { margin-left: 0; gap: 2px; flex-shrink: 0; }
    .zoom-label { min-width: 34px; font-size: 11px; }

    /* Pages scroll fills remaining space */
    .pdf-pages-scroll {
        flex: 1;
        min-height: 0;
        padding: 12px 8px;
    }

    /* Compact empty state */
    .pdf-empty-state { padding: 2rem 1rem; }
    .pdf-empty-state svg { width: 48px; height: 48px; }

    /* Signature modal fits on mobile */
    .signature-modal { padding: 16px; max-width: 95%; }
    #signature-canvas { height: 160px; }

    /* Shortcut panel — single column on mobile */
    .shortcut-columns {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    .shortcut-panel { padding: 16px; }

    /* Full-width toasts on mobile — slide down instead of from right */
    .toast-container { left: 8px; right: 8px; }
    .toast {
        max-width: 100%;
        animation-name: toastInMobile;
    }
    .toast.removing {
        animation-name: toastOutMobile;
    }

    /* Find bar compact */
    .find-bar { padding: 4px 8px; gap: 4px; }
    .find-bar input { max-width: none; }
    .find-count { min-width: 40px; font-size: 0.7rem; }

    /* Crop toolbar */
    .crop-toolbar { bottom: 24px; }

    /* Page indicator closer to bottom */
    .page-indicator { bottom: 8px; font-size: 12px; }

    /* Compact modals */
    .confirm-modal { padding: 16px; }
    .stamp-modal { padding: 16px; }
    .sticky-note-popup { max-width: calc(100vw - 32px); }

    /* Drop zone uniform spacing */
    .pdf-drop-zone { margin: 0.5rem; }
}

/* Mobile toast animations — outside media query for keyframes compatibility */
@keyframes toastInMobile {
    from { transform: translateY(-100%); opacity: 0; }
    to   { transform: translateY(0);     opacity: 1; }
}
@keyframes toastOutMobile {
    from { transform: translateY(0);     opacity: 1; }
    to   { transform: translateY(-100%); opacity: 0; }
}

/* ============================================
   Loading Overlay
   ============================================ */
.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    background: rgba(248, 250, 252, 0.8);
    backdrop-filter: blur(4px);
}

[data-theme="dark"] .loading-overlay {
    background: rgba(15, 23, 42, 0.85);
}

.loading-spinner {
    width: 40px;
    height: 40px;
    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); }
}

.loading-label {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text);
}

/* ============================================
   Confirmation Modal
   ============================================ */
#confirm-modal-overlay {
    display: flex;
}

.confirm-modal {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    max-width: 400px;
    width: 90%;
    box-shadow: var(--shadow-lg);
}

.confirm-modal-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.confirm-modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text);
}

.confirm-modal-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--error-light);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.confirm-modal-icon::after {
    content: '!';
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--error);
}

.confirm-modal p {
    margin: 0 0 20px;
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--text-light);
}

.confirm-modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.btn-destructive {
    background-color: var(--error);
    color: white;
}

.btn-destructive:hover {
    filter: brightness(0.85);
    transform: translateY(-1px);
}

/* ============================================
   Toast System
   ============================================ */
.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 500;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    pointer-events: auto;
    box-shadow: var(--shadow-md);
    animation: toastIn 250ms ease forwards;
    max-width: 360px;
}

.toast.removing {
    animation: toastOut 250ms ease forwards;
}

.toast-success {
    background: var(--success-light);
    color: var(--success);
    border: 1px solid var(--success-border);
}

.toast-error {
    background: var(--error-light);
    color: var(--error);
    border: 1px solid var(--error-border);
}

.toast-info {
    background: var(--info-bg);
    color: var(--info-text);
    border: 1px solid var(--info-border);
}

.toast-undo {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 14px;
    font-weight: 600;
    text-decoration: underline;
    cursor: pointer;
    padding: 0 4px;
    margin-left: auto;
}

.toast-undo:hover {
    opacity: 0.8;
}

.toast-undo:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

@keyframes toastIn {
    from { transform: translateX(100%); opacity: 0; }
    to   { transform: translateX(0);    opacity: 1; }
}

@keyframes toastOut {
    from { transform: translateX(0);    opacity: 1; }
    to   { transform: translateX(100%); opacity: 0; }
}

/* ============================================
   Context Bar Transitions (Task 10)
   ============================================ */
.context-control {
    transition: opacity 150ms ease, transform 150ms ease;
}

.ctx-exit {
    opacity: 0;
    transform: translateY(-4px);
    pointer-events: none;
}

.sidebar-tool-btn.active {
    animation: toolPulse 150ms ease;
}

@keyframes toolPulse {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.05); }
    100% { transform: scale(1); }
}

/* ============================================
   Tooltip System (Task 11)
   ============================================ */
.tooltip {
    position: fixed;
    z-index: 100;
    background: var(--tooltip-bg);
    color: var(--tooltip-text);
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 6px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 100ms ease;
    white-space: nowrap;
}
.tooltip.visible { opacity: 1; }
.tooltip kbd {
    display: inline-block;
    background: rgba(255, 255, 255, 0.15);
    padding: 1px 5px;
    border-radius: 3px;
    font-family: inherit;
    font-size: 11px;
    margin-left: 6px;
}
[data-theme="dark"] .tooltip kbd { background: rgba(0, 0, 0, 0.15); }

/* ============================================
   Keyboard Shortcut Panel (Task 13)
   ============================================ */
.shortcut-panel {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 24px 32px;
    max-width: 600px;
    width: 90%;
}
.shortcut-panel h3 { margin: 0 0 16px; font-size: 16px; }
.shortcut-columns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; }
.shortcut-group h4 {
    font-size: 12px; text-transform: uppercase; color: var(--text-light);
    margin: 0 0 8px; letter-spacing: 0.05em;
}
.shortcut-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 4px 0; font-size: 13px;
}
.shortcut-row kbd {
    background: var(--bg); border: 1px solid var(--border);
    padding: 2px 6px; border-radius: 4px; font-family: inherit;
    font-size: 12px; min-width: 24px; text-align: center;
}

/* ============================================
   Improved Empty State (Task 14)
   ============================================ */
.drop-zone-formats {
    font-size: 0.75rem;
    color: var(--text-light);
    margin-top: 0.5rem;
    opacity: 0.7;
}
.pdf-drop-zone:hover > svg {
    animation: bounce 0.6s ease;
}
@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    40% { transform: translateY(-6px); }
    60% { transform: translateY(-3px); }
}
.pdf-drop-zone.drag-active > svg {
    transform: scale(1.1);
    transition: transform 200ms ease;
}

/* ============================================
   Zoom Controls (Task 16)
   ============================================ */
.zoom-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
}
.zoom-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px;
    cursor: pointer;
    color: var(--text-light);
    display: flex;
    align-items: center;
    transition: color var(--transition), border-color var(--transition);
}
.zoom-btn:hover { color: var(--text); border-color: var(--text-light); }
.zoom-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.zoom-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    min-width: 40px;
    text-align: center;
}

/* ============================================
   Page Indicator (Task 17)
   ============================================ */
.page-indicator {
    position: sticky;
    bottom: 12px;
    z-index: 50;
    background: rgba(30, 41, 59, 0.75);
    color: #f1f5f9; /* Always light text on dark pill — matches dark theme --text */
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 13px;
    backdrop-filter: blur(4px);
    text-align: center;
    width: fit-content;
    margin: 0 auto;
    pointer-events: auto;
}
[data-theme="dark"] .page-indicator {
    background: rgba(241, 245, 249, 0.15);
}
.page-indicator-num {
    cursor: pointer;
    font-weight: 600;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.4);
}
.page-indicator-num:hover { border-bottom-color: white; }
.page-indicator-input {
    width: 32px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    color: white;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    padding: 0 2px;
}

/* ============================================
   Stroke Width Preview (Task 18)
   ============================================ */
.stroke-preview { color: var(--text); flex-shrink: 0; }

/* ============================================
   Signature Modal
   ============================================ */
.signature-modal {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 24px;
    max-width: 560px;
    width: 90%;
}

.signature-modal h3 {
    margin: 0 0 16px;
    font-size: 16px;
}

#signature-canvas {
    width: 100%;
    height: 200px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: crosshair;
    background: white;
}

.signature-modal-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    align-items: center;
}

.signature-spacer { flex: 1; }

.signature-save-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--text-light);
    margin-top: 8px;
}

/* ============================================
   Stamp Modal
   ============================================ */
.stamp-modal {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 24px;
    max-width: 400px;
    width: 90%;
}
.stamp-modal h3 { margin: 0 0 16px; font-size: 16px; }
.stamp-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}
.stamp-preset-btn {
    padding: 8px 16px;
    border: 2px solid var(--error);
    border-radius: 4px;
    background: transparent;
    color: var(--error);
    font-weight: 700;
    font-size: 0.85rem;
    letter-spacing: 0.1em;
    cursor: pointer;
    transition: background-color var(--transition), color var(--transition);
}
.stamp-preset-btn:hover {
    background: var(--error);
    color: white;
}
.stamp-custom {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}
.stamp-custom input {
    flex: 1;
}
.stamp-modal-footer {
    display: flex;
    justify-content: flex-end;
}

/* ============================================
   Sticky Notes
   ============================================ */
.sticky-note-popup {
    position: absolute;
    z-index: 25;
    width: 200px;
    background: var(--note-bg);
    border: 1px solid var(--note-border);
    border-radius: 6px;
    box-shadow: var(--shadow-md);
    font-size: 12px;
}

.sticky-note-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 8px;
    border-bottom: 1px solid var(--note-border);
    font-weight: 600;
    font-size: 11px;
    color: var(--note-header);
    cursor: move;
}

.sticky-note-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    color: inherit;
    padding: 0 2px;
    line-height: 1;
}

.sticky-note-body {
    padding: 6px 8px;
}

.sticky-note-body textarea {
    width: 100%;
    height: 80px;
    border: none;
    background: transparent;
    resize: vertical;
    font-size: 12px;
    font-family: inherit;
    color: inherit;
    outline: none;
}

/* ============================================
   Find Bar
   ============================================ */
.find-bar {
    padding: 6px 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 8px;
    align-items: center;
}

.find-bar input {
    flex: 1;
    max-width: 300px;
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.85rem;
    background: var(--surface);
    color: var(--text);
}

.find-bar input:focus {
    outline: none;
    border-color: var(--primary);
}

.find-count {
    font-size: 0.8rem;
    color: var(--text-light);
    min-width: 60px;
}

.find-nav-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px;
    cursor: pointer;
    color: var(--text-light);
    display: flex;
    align-items: center;
    transition: color var(--transition), border-color var(--transition);
}

.find-nav-btn:hover:not(:disabled) {
    color: var(--text);
    border-color: var(--text-light);
}

.find-nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.find-close-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    color: var(--text-light);
    padding: 2px 6px;
    line-height: 1;
}

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

/* ============================================
   Form Field Overlays
   ============================================ */
.form-field-overlay {
    position: absolute;
    z-index: 15;
    border: 1px solid color-mix(in srgb, var(--primary) 40%, transparent);
    background: color-mix(in srgb, var(--primary) 5%, transparent);
    padding: 2px 4px;
    font-size: 12px;
    font-family: inherit;
    color: var(--text);
    box-sizing: border-box;
}

.form-field-overlay:focus {
    border-color: var(--primary);
    background: color-mix(in srgb, var(--primary) 10%, transparent);
    outline: none;
}

.form-checkbox-overlay {
    padding: 0;
    cursor: pointer;
}

.form-field-overlay option {
    background: var(--surface);
    color: var(--text);
}

/* ============================================
   Crop Toolbar
   ============================================ */
.crop-toolbar {
    position: fixed;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 50;
    display: flex;
    gap: 8px;
    background: var(--surface);
    padding: 8px 16px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
}
