/* =========================================
   1. VARIABLES & THEME SETUP
   ========================================= */
:root {
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --hue-primary: 240; /* Indigo */
    --hue-secondary: 280; /* Magenta/Purple */
    --hue-danger: 350;  /* Red */
    --transition: 0.3s ease;

    /* Dimensions */
    --header-height: auto;
    --header-min-height: 65px;
    --sidebar-width: 240px;

    /* Light Mode Colors */
    --bg-main: #f8f9fc;
    --bg-glass: rgba(255, 255, 255, 0.5);
    --bg-card: #ffffff;
    --bg-subtle: #f1f3f8;
    --border: rgba(0, 0, 0, 0.08);
    --text-primary: #1a202c;
    --text-secondary: #5a677d;
    --shadow-color: 220, 40%, 50%;
    
    --primary: hsl(var(--hue-primary), 90%, 65%);
    --primary-dark: hsl(var(--hue-primary), 90%, 55%);
    --danger: hsl(var(--hue-danger), 80%, 55%);
    --success: #16a34a;
    --warning: #f59e0b;

    --grad-1: hsl(var(--hue-primary), 100%, 85%);
    --grad-2: hsl(var(--hue-secondary), 100%, 90%);
}

.dark-mode {
    /* Dark Mode Colors */
    --bg-main: #131824;
    --bg-glass: rgba(28, 35, 51, 0.5);
    --bg-card: #1c2333;
    --bg-subtle: #2a3346;
    --border: rgba(255, 255, 255, 0.1);
    --text-primary: #f0f4f9;
    --text-secondary: #a0aec0;
    --shadow-color: 220, 40%, 0%;

    --primary: hsl(var(--hue-primary), 80%, 70%);
    --primary-dark: hsl(var(--hue-primary), 80%, 80%);
    --danger: hsl(var(--hue-danger), 70%, 60%);
    --success: #22c55e;
    --warning: #fbbf24;

    --grad-1: hsl(var(--hue-primary), 80%, 20%);
    --grad-2: hsl(var(--hue-secondary), 80%, 25%);
}

/* =========================================
   2. GLOBAL RESET & BASE STYLES
   ========================================= */
* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
    font-family: var(--font-family);
    background-color: var(--bg-main);
    color: var(--text-primary);
    transition: background-color var(--transition), color var(--transition);
    font-size: 16px;
    line-height: 1.6;
    overflow-x: hidden; /* Prevent horizontal scroll */
    position: relative;
    -webkit-tap-highlight-color: transparent;
}

body.no-scroll { overflow: hidden; }

/* Aurora Background Effect */
body::before, body::after {
    content: ''; position: fixed; z-index: -1;
    border-radius: 50%; filter: blur(150px);
    transition: background-color 0.5s;
}
body::before { width: 500px; height: 500px; background: var(--grad-1); top: -20%; left: -10%; animation: pulse 15s infinite alternate; }
body::after { width: 600px; height: 600px; background: var(--grad-2); bottom: -25%; right: -15%; animation: pulse 20s infinite alternate-reverse; }
@keyframes pulse { from { transform: scale(0.8); } to { transform: scale(1.2); } }

/* Global Utilities */
.container { max-width: 1200px; width: 100%; margin: 0 auto; padding: 0 20px; }
.hidden { display: none !important; }
a { text-decoration: none; color: var(--primary); transition: color var(--transition); }
a:hover { color: var(--primary-dark); }

/* Typography */
h1, h2, h3 { font-weight: 700; line-height: 1.2; color: var(--text-primary); margin-bottom: 1rem; }
p { margin-bottom: 1rem; color: var(--text-secondary); }
h2.section-title { font-size: 2.5rem; text-align: center; margin-bottom: 4rem; }

/* =========================================
   3. UI COMPONENTS (Buttons, Pills)
   ========================================= */
.btn-primary {
    display: inline-flex; 
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 28px; border-radius: 50px;
    font-weight: 600; background-color: var(--primary); color: white !important;
    border: none; box-shadow: 0 4px 15px rgba(var(--shadow-color), 0.2);
    transition: all var(--transition); text-align: center; cursor: pointer;
}
.btn-primary:hover { transform: translateY(-3px); background-color: var(--primary-dark); box-shadow: 0 6px 20px rgba(var(--shadow-color), 0.3); }

.btn-primary i {
    color: rgba(255, 255, 255, 0.75) !important;
    transition: color var(--transition);
}
.btn-primary:hover i {
    color: rgba(255, 255, 255, 1) !important;
}

.btn-secondary {
    display: inline-block; padding: 12px 24px; border-radius: 50px;
    font-weight: 600; background-color: transparent; color: var(--primary);
    border: 2px solid var(--primary); transition: all var(--transition);
    cursor: pointer; text-align: center;
}
.btn-secondary:hover { background-color: var(--primary); color: white; transform: translateY(-3px); }

.btn-danger {
    display: inline-block; padding: 12px 24px; border-radius: 50px;
    font-weight: 600; background-color: transparent; color: var(--danger);
    border: 1px solid var(--danger); transition: all var(--transition);
    cursor: pointer; text-align: center; font-size: 0.9rem;
}
.btn-danger:hover { background-color: var(--danger); color: white; }

.btn-full { width: 100%; }
.btn-sm { padding: 8px 16px; font-size: 0.9rem; }

.pill {
    display: inline-flex; align-items: center; padding: 4px 12px;
    border-radius: 999px; font-size: 0.75rem; font-weight: 600;
    letter-spacing: 0.04em; text-transform: uppercase;
}
.pill-success { background: rgba(22, 163, 74, 0.1); color: var(--success); }
.pill-info { background: rgba(59, 130, 246, 0.1); color: var(--primary); }

/* =========================================
   4. LANDING PAGE STYLES (Optional if using editor-only)
   ========================================= */

/* Main Header (Website Navigation) */
.header {
    background-color: var(--bg-glass); backdrop-filter: blur(20px) saturate(180%);
    position: fixed; top: 0; left: 0; width: 100%; z-index: 1000;
    border-bottom: 1px solid var(--border); padding: 10px 0;
    transition: padding var(--transition), background-color var(--transition), box-shadow var(--transition);
}
.header.scrolled { box-shadow: 0 2px 10px rgba(var(--shadow-color), 0.05); }
.header .container { display: flex; justify-content: space-between; align-items: center; }

.logo { display: flex; align-items: center; gap: 12px; }
.logo-img { height: 40px; }
.logo-text h1 { font-size: 1.3rem; margin-bottom: 0; color: var(--text-primary); }
.logo-text p { font-size: 0.75rem; color: var(--text-secondary); margin: 0; line-height: 1; }

.navbar ul { display: flex; list-style: none; gap: 25px; align-items: center; }
.navbar ul li a { color: var(--text-primary); font-weight: 500; }
.nav-link-btn { border: none; background: transparent; font: inherit; color: var(--text-primary); cursor: pointer; }
.nav-link-btn-primary { padding: 8px 16px; border-radius: 999px; border: 1px solid var(--primary); color: var(--primary); }
.nav-link-btn-primary:hover { background: var(--primary); color: #fff; }

.header-actions { display: flex; align-items: center; gap: 20px; }
.mobile-menu-btn { display: none; font-size: 1.5rem; cursor: pointer; color: var(--text-primary); }

/* Theme Switcher */
.theme-switcher { display: flex; align-items: center; gap: 8px; color: var(--text-secondary); }
.switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--bg-subtle); transition: var(--transition); border-radius: 24px; border: 1px solid var(--border); }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 2px; bottom: 2px; background-color: white; transition: var(--transition); border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
.dark-mode .slider:before { background-color: var(--bg-main); }
input:checked + .slider { background-color: var(--primary); }
input:checked + .slider:before { transform: translateX(20px); }

/* Landing Page Hero */
.hero { padding: 130px 0 60px; text-align: center; }
.centered-hero .container { display: flex; flex-direction: column; align-items: center; gap: 40px; }
.hero-content h1 { font-size: 3.5rem; margin: 0 auto 1.5rem; line-height: 1.1; max-width: 900px; background: linear-gradient(135deg, var(--text-primary) 0%, var(--primary) 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.hero-content p { font-size: 1.25rem; max-width: 600px; margin: 0 auto 2rem; }
.hero-badges { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin-bottom: 1.5rem; }
.hero-cta-row { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-bottom: 2.5rem; }
.hero-cta-note { font-size: 0.9rem; color: var(--text-secondary); margin-top: 1rem; }
.hero-meta-row { display: flex; flex-wrap: wrap; gap: 20px; margin-top: 1.75rem; font-size: 0.85rem; justify-content: center; }
.hero-meta-row span { display: inline-flex; align-items: center; gap: 6px; }
.hero-meta-row i { color: var(--success); }
.hero-image-container { width: 100%; display: flex; justify-content: center; }
.hero-image { position: relative; width: 100%; max-width: 800px; aspect-ratio: 16 / 9; border-radius: 18px; box-shadow: 0 20px 50px rgba(var(--shadow-color), 0.2); overflow: hidden; background-color: var(--bg-subtle); border: 1px solid var(--border); }
.hero-image img { width: 100%; height: 100%; object-fit: cover; }
.hero-floating-card { position: absolute; bottom: 20px; left: 20px; background: rgba(15, 23, 42, 0.9); color: #fff; padding: 12px 16px; border-radius: 12px; font-size: 0.9rem; display: inline-flex; flex-direction: column; gap: 4px; text-align: left; }
.hero-floating-card span { color: #e5e7eb; }

/* Footer */
.footer { background-color: var(--bg-card); color: var(--text-primary); padding: 60px 0 0; border-top: 1px solid var(--border); }
.footer-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 40px; margin-bottom: 40px; }
.footer-col h3 { margin-bottom: 1.5rem; font-size: 1.2rem; }
.footer-col ul { list-style: none; }
.footer-col ul li { margin-bottom: 10px; }
.footer-col ul li a { color: var(--text-secondary); }
.social-links { display: flex; gap: 15px; margin-top: 1.5rem; }
.social-links a { width: 40px; height: 40px; background: var(--bg-subtle); border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--text-secondary); }
.social-links a:hover { background-color: var(--primary); color: #fff; }
.footer-bottom { text-align: center; padding: 20px 0; border-top: 1px solid var(--border); color: var(--text-secondary); font-size: 0.9rem; }

/* =========================================
   5. APP LAYOUT & EDITOR STYLES
   ========================================= */
.app-layout { display: flex; height: 100vh; }

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-glass);
    backdrop-filter: blur(30px) saturate(180%);
    border-right: 1px solid var(--border);
    flex-shrink: 0;
    display: flex; flex-direction: column; height: 100vh;
    box-shadow: inset -1px 0 0 var(--border);
    transition: width 0.3s ease, transform 0.3s ease;
    z-index: 20;
}
.sidebar-content { overflow-y: auto; padding: 1.5rem; display: flex; flex-direction: column; flex-grow: 1; }
.sidebar-header { margin-bottom: 2rem; }
.sidebar h1 { font-size: 1.3rem; font-weight: 600; }
.action-section { margin-bottom: 2rem; }
.action-section h2 { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 1px; color: var(--text-secondary); margin-bottom: 0.75rem; font-weight: 600; }
.sidebar-btn { display: flex; align-items: center; gap: 0.75rem; width: 100%; padding: 0.75rem; margin-bottom: 0.5rem; font-size: 0.95rem; font-weight: 500; text-align: left; border: 1px solid transparent; border-radius: 8px; background-color: rgba(128,128,128,0.1); color: var(--text-primary); cursor: pointer; transition: all 0.2s; }
.sidebar-btn:hover { border-color: var(--primary); color: var(--primary); background-color: var(--bg-subtle); transform: translateY(-2px); box-shadow: 0 4px 10px rgba(var(--shadow-color), 0.1); }
.sidebar-btn:disabled { opacity: 0.6; cursor: not-allowed; background-color: transparent; border-color: var(--border); color: var(--text-secondary); transform: none; box-shadow: none; }
.sidebar-btn.primary { background-color: var(--primary); color: white; border-color: var(--primary); }
.sidebar-btn.primary:hover { background-color: var(--primary-dark); border-color: var(--primary-dark); }
.sidebar-btn i { font-size: 1.1rem; width: 20px; text-align: center; }
a.sidebar-btn { text-decoration: none; }
.sidebar-footer { padding: 1rem; border-top: 1px solid var(--border); }

/* Main Content Area */
.main-content {
    flex: 1; display: flex; flex-direction: column;
    height: 100vh; position: relative; min-width: 0;
}
.main-header {
    height: var(--header-height); min-height: var(--header-min-height);
    padding: 1rem 1.5rem; border-bottom: 1px solid var(--border);
    display: flex; align-items: center;
    flex-shrink: 0; background-color: var(--bg-glass);
    backdrop-filter: blur(30px) saturate(180%);
    box-shadow: inset 0 -1px 0 var(--border);
    position: fixed; top: 0; left: var(--sidebar-width); right: 0;
    z-index: 10; flex-wrap: wrap; gap: 1rem;
}
.header-right { display: flex; align-items: center; gap: 1rem; margin-left: auto; }
#history-controls { display: flex; align-items: center; gap: 0.5rem; }
.pages-grid-container { flex-grow: 1; overflow: auto; padding: 1.5rem; padding-top: calc(var(--header-min-height) + 1.5rem); }

/* --- Universal Minimalist Scrollbar --- */
.sidebar-content::-webkit-scrollbar,
.pages-grid-container::-webkit-scrollbar,
#layers-list::-webkit-scrollbar,
.signature-modal-layout::-webkit-scrollbar,
.custom-select-options::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
.sidebar-content::-webkit-scrollbar-track,
.pages-grid-container::-webkit-scrollbar-track,
#layers-list::-webkit-scrollbar-track,
.signature-modal-layout::-webkit-scrollbar-track,
.custom-select-options::-webkit-scrollbar-track {
    background: transparent;
}
.sidebar-content::-webkit-scrollbar-thumb,
.pages-grid-container::-webkit-scrollbar-thumb,
#layers-list::-webkit-scrollbar-thumb,
.signature-modal-layout::-webkit-scrollbar-thumb,
.custom-select-options::-webkit-scrollbar-thumb {
    background-color: rgba(128, 128, 128, 0.3);
    border-radius: 8px;
    border: 2px solid transparent;
    background-clip: content-box;
}
.sidebar-content::-webkit-scrollbar-thumb:hover,
.pages-grid-container::-webkit-scrollbar-thumb:hover,
#layers-list::-webkit-scrollbar-thumb:hover,
.signature-modal-layout::-webkit-scrollbar-thumb:hover,
.custom-select-options::-webkit-scrollbar-thumb:hover {
    background-color: rgba(128, 128, 128, 0.6);
}


/* Editor Placeholder */
#initial-placeholder { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: var(--text-secondary); text-align: center; padding: 2rem; user-select: none; gap: 1rem; }
#initial-placeholder i { font-size: 4rem; color: var(--primary); }
#initial-placeholder h2 { font-size: 1.5rem; margin-bottom: 0; color: var(--text-primary); }
#initial-placeholder p { margin-bottom: 0.5rem; }
#placeholder-load-btn { padding: 12px 24px; font-size: 1rem; }

/* Tool Palette */
.tool-palette { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 0.5rem; }
.tool-btn { background: var(--bg-subtle); border: 1px solid var(--border); color: var(--text-secondary); width: 100%; height: 40px; border-radius: 8px; cursor: pointer; font-size: 1rem; transition: all 0.2s; position: relative; }
.tool-btn:hover { background-color: var(--primary); color: white; border-color: var(--primary); transform: translateY(-2px); }
.tool-btn.active { background-color: var(--primary); color: white; border-color: var(--primary); box-shadow: 0 0 10px rgba(var(--shadow-color), 0.2); }

/* Contextual Tool Bar */
#contextual-tools-wrapper { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.context-options { display: flex; align-items: center; gap: 0.5rem; }
.context-options span, .context-options label { font-size: 0.9rem; color: var(--text-secondary); white-space: nowrap; }
.context-options select, .context-options input, .tool-option-btn { height: 36px; border-radius: 6px; border: 1px solid var(--border); background-color: var(--bg-card); color: var(--text-primary); font-family: var(--font-family); font-size: 0.9rem; padding: 0 0.5rem; }
#font-size-input, #shape-stroke-width, #table-stroke-width { width: 70px; }
.context-options input[type="color"] { padding: 2px; width: 36px; }
.context-options input[type="range"] { padding: 0; width: 100px; }
.tool-option-btn { cursor: pointer; transition: all 0.2s; padding: 0 0.75rem; }
.tool-option-btn:hover { border-color: var(--primary); color: var(--primary); }
.tool-option-btn.active { background-color: var(--primary); color: white; border-color: var(--primary); }
.tool-option-btn.danger:hover { background-color: var(--danger); color: white; border-color: var(--danger); }
.separator { color: var(--border); font-size: 1.5rem; }
.tool-option-group { display: flex; background-color: var(--bg-subtle); border-radius: 6px; padding: 2px; }
.tool-option-group .tool-option-btn { background: none; border: none; height: 32px; padding: 0 8px; }
.tool-option-group .tool-option-btn.active { background-color: var(--bg-card); color: var(--primary); box-shadow: 0 1px 3px rgba(0,0,0,0.1); }

/* Custom Font Select */
.custom-select-container { position: relative; width: 180px; }
.custom-select-value { width: 100%; height: 36px; border-radius: 6px; border: 1px solid var(--border); background-color: var(--bg-card); color: var(--text-primary); font-size: 0.9rem; padding: 0 0.75rem; text-align: left; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; }
.custom-select-options { position: absolute; top: 100%; left: 0; right: 0; background-color: var(--bg-card); border: 1px solid var(--border); border-radius: 6px; margin-top: 4px; z-index: 100; max-height: 250px; overflow-y: auto; box-shadow: 0 4px 15px rgba(var(--shadow-color), 0.1); }
.custom-select-group { padding: 8px 12px; font-size: 0.75rem; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; }
.custom-select-option { padding: 8px 12px; font-size: 0.9rem; cursor: pointer; transition: background-color 0.2s; }
.custom-select-option:hover { background-color: var(--bg-subtle); color: var(--primary); }

/* PDF Viewer Canvas Area */
#pdf-viewer-container { padding: 20px; width: fit-content; margin: 0 auto; }
#pdf-viewer { position: relative; box-shadow: 0 10px 30px rgba(var(--shadow-color), 0.1); transform-origin: top left; }
#pdf-viewer.brush-tool-active, #pdf-viewer.clone-tool-active, #pdf-viewer.eraser-tool-active, #pdf-viewer.image-eraser-active { cursor: none; }
#pdf-viewer.text-tool-active { cursor: text; }
#pdf-viewer.shape-tool-active, #pdf-viewer.table-tool-active { cursor: crosshair; }
#pdf-viewer.clone-tool-alt-active { cursor: crosshair; }
#pdf-viewer.bg-fill-tool-active { cursor: crosshair; } /* Background Fill Cursor */
#pdf-viewer.eyedropper-active, #pdf-viewer.eyedropper-active .object-wrapper, #pdf-viewer.eyedropper-active .object-wrapper img { cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M16.27 7.73L6.5 17.5l-4-4L12.27 3.73a2.12 2.12 0 0 1 3 3zM8.5 14.5L5 11"/></svg>') 4 19, crosshair !important; }

#pdf-canvas, #background-canvas, #drawing-canvas, #text-layer, #shape-canvas { position: absolute; top: 0; left: 0; }
#pdf-canvas { z-index: 1; }
#background-canvas { z-index: 2; pointer-events: none; }
#shape-canvas { z-index: 3; pointer-events: none; }
#drawing-canvas { z-index: 4; pointer-events: none; }
#text-layer { z-index: 5; pointer-events: auto; }

/* Interactive Objects (Text, Image) */
.object-wrapper {
    position: absolute;
    cursor: move;
    border: 1px solid transparent;
    user-select: none;
    transition: opacity 0.2s;
    /* --- FIX FOR BLUR & BLACK EDGE EXPORT ISSUES --- */
    /* This promotes the element to its own GPU layer, ensuring cleaner rendering for canvas capture */
    transform: translateZ(0);
}
.object-wrapper.no-pointer-events { pointer-events: none; }
.object-wrapper:hover, .object-wrapper.selected { border: 1px dashed var(--primary); }
.object-wrapper:hover .resizer, .object-wrapper:hover .rotater, .object-wrapper.selected .resizer, .object-wrapper.selected .rotater { display: block; }
.text-box { padding: 2px; white-space: pre-wrap; word-break: break-word; min-width: 20px; min-height: 20px; box-sizing: border-box; outline: none; user-select: text; line-height: 1.2; }
.text-box.underlined { text-decoration: underline; }
.image-box { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.resizer, .rotater { position: absolute; width: 10px; height: 10px; background-color: white; border: 1px solid var(--primary); border-radius: 50%; display: none; z-index: 10; }
.resizer.top-left { top: -5px; left: -5px; cursor: nwse-resize; }
.resizer.top-right { top: -5px; right: -5px; cursor: nesw-resize; }
.resizer.bottom-left { bottom: -5px; left: -5px; cursor: nesw-resize; }
.resizer.bottom-right { bottom: -5px; right: -5px; cursor: nwse-resize; }
.rotater { top: -20px; left: 50%; transform: translateX(-50%); cursor: grabbing; }
.resizer.top { top: -5px; left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.resizer.bottom { bottom: -5px; left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.resizer.left { left: -5px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }
.resizer.right { right: -5px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }

/* --- Text cursor on hover for select tool --- */
#pdf-viewer.select-tool-active .object-wrapper:hover .text-box,
#pdf-viewer.select-tool-active .object-wrapper:hover .table-cell {
    cursor: text;
}

/* Table Objects */
.table-container { display: grid; width: 100%; height: 100%; border-top: var(--table-border-width, 1px) solid var(--table-border-color, var(--border)); border-left: var(--table-border-width, 1px) solid var(--table-border-color, var(--border)); position: relative; }
.table-cell { border-right: var(--table-border-width, 1px) solid var(--table-border-color, var(--border)); border-bottom: var(--table-border-width, 1px) solid var(--table-border-color, var(--border)); padding: 4px; min-width: 30px; outline: none; user-select: text; white-space: pre-wrap; word-break: break-word; font-size: inherit; color: inherit; }
.table-cell:focus { background-color: hsla(var(--hue-primary), 90%, 65%, 0.1); outline: 1px solid var(--primary); z-index: 1; position: relative; }
.table-col-resizer, .table-row-resizer { position: absolute; background-color: transparent; z-index: 5; transition: background-color 0.2s; }
.table-col-resizer { top: 0; height: 100%; width: 10px; cursor: col-resize; transform: translateX(-5px); }
.table-row-resizer { left: 0; width: 100%; height: 10px; cursor: row-resize; transform: translateY(-5px); }

/* Tool Cursors & Indicators */
#ocr-selection-box { position: absolute; border: 2px dashed var(--primary); background-color: hsla(var(--hue-primary), 90%, 65%, 0.2); z-index: 5; pointer-events: none; display: none; }
#brush-cursor { position: absolute; border: 1px solid #333; border-radius: 50%; transform: translate(-50%, -50%); pointer-events: none; display: none; z-index: 100; }
#clone-source-indicator { position: absolute; width: 10px; height: 10px; border: 1px solid black; background: white; border-radius: 50%; transform: translate(-50%, -50%); pointer-events: none; display: none; z-index: 101; }
#bg-fill-selection-box { position: absolute; border: 2px dashed var(--success); background-color: rgba(34, 197, 94, 0.2); z-index: 5; pointer-events: none; display: none; }
#auto-select-bg-box { position: absolute; border: 2px dashed var(--warning); background-color: rgba(245, 158, 11, 0.2); z-index: 6; pointer-events: none; display: none; }

/* --- BG Fill Tool Options --- */
.bg-fill-color-section {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.5rem;
    background-color: var(--bg-subtle);
    border-radius: 6px;
}
.bg-fill-color-section h4 {
    font-size: 0.75rem;
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}
.bg-fill-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}
#bg-fill-target-colors,
#bg-fill-fill-colors {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}
.tool-option-color-input {
    width: 36px;
    height: 36px;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background-color: var(--bg-card);
    cursor: pointer;
}
.bg-fill-swatch {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--bg-card);
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    position: relative;
    cursor: pointer;
}
.bg-fill-swatch .delete-swatch {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 16px;
    height: 16px;
    background-color: var(--danger);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    line-height: 1;
    font-weight: bold;
    opacity: 0;
    transition: opacity 0.2s;
    border: none;
    cursor: pointer;
}
.bg-fill-swatch:hover .delete-swatch {
    opacity: 1;
}

/* Crop UI */
#crop-box-container { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 50; }
.crop-box-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); }
.crop-box { position: absolute; border: 2px dashed #fff; cursor: move; }
.crop-handle { position: absolute; width: 12px; height: 12px; background: #fff; border: 1px solid #333; border-radius: 50%; }
.crop-handle.top-left { top: -6px; left: -6px; cursor: nwse-resize; }
.crop-handle.top-right { top: -6px; right: -6px; cursor: nesw-resize; }
.crop-handle.bottom-left { bottom: -6px; left: -6px; cursor: nesw-resize; }
.crop-handle.bottom-right { bottom: -6px; right: -6px; cursor: nwse-resize; }
.crop-actions { position: absolute; bottom: -45px; left: 50%; transform: translateX(-50%); display: flex; gap: 10px; }
.crop-actions button { width: 36px; height: 36px; border-radius: 50%; border: none; cursor: pointer; font-size: 1rem; color: white; transition: all 0.2s; }
#confirm-crop-btn, #confirm-sig-crop-btn { background-color: var(--primary); }
#confirm-crop-btn:hover, #confirm-sig-crop-btn:hover { background-color: var(--primary-dark); }
#cancel-crop-btn, #cancel-sig-crop-btn { background-color: var(--danger); }
#cancel-crop-btn:hover, #cancel-sig-crop-btn:hover { background-color: hsl(var(--hue-danger), 70%, 45%); }

/* Layers Panel */
#layers-panel { position: fixed; top: calc(var(--header-min-height) + 20px); right: 20px; width: 250px; max-height: 400px; background-color: var(--bg-card); box-shadow: 0 8px 25px rgba(var(--shadow-color), 0.15); border-radius: 12px; z-index: 15; display: flex; flex-direction: column; border: 1px solid var(--border); }
.layers-panel-header { display: flex; justify-content: space-between; align-items: center; padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); }
.layers-panel-header h3 { font-size: 1rem; margin: 0; }
#close-layers-btn { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-secondary); padding: 0 5px; }
#layers-list { overflow-y: auto; flex-grow: 1; padding: 0.5rem; }
.layer-item { padding: 0.5rem 0.75rem; font-size: 0.9rem; border-radius: 6px; cursor: grab; user-select: none; background-color: transparent; transition: background-color 0.2s; display: flex; flex-direction: column; gap: 8px; }
.layer-item:hover { background-color: var(--bg-subtle); }
.layer-item.dragging { opacity: 0.5; background-color: var(--primary); color: white; }
.layer-info { display: flex; justify-content: space-between; align-items: center; width: 100%; }
.layer-name { flex-grow: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.layer-controls { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.layer-visibility-toggle, .layer-delete-btn { cursor: pointer; color: var(--text-secondary); }
.layer-visibility-toggle:hover { color: var(--primary); }
.layer-delete-btn:hover { color: var(--danger); }
.layer-item.hidden-layer .layer-name { opacity: 0.6; text-decoration: line-through; }
.layer-item.hidden-layer .layer-visibility-toggle { color: var(--border); }
.layer-opacity-slider { width: 100%; margin-top: 4px; }
input[type="range"].layer-opacity-slider { -webkit-appearance: none; appearance: none; width: 100%; height: 5px; background: var(--bg-subtle); outline: none; border-radius: 5px; }
input[type="range"].layer-opacity-slider::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 15px; height: 15px; background: var(--primary); cursor: pointer; border-radius: 50%; }

/* Page Controls in Editor */
#page-controls, #zoom-controls { display: flex; align-items: center; background-color: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; padding: 4px; }
#page-controls button, #zoom-controls button { background: none; border: none; color: var(--text-secondary); width: 28px; height: 28px; border-radius: 6px; cursor: pointer; transition: all 0.2s; }
#page-controls button:hover, #zoom-controls button:hover { background-color: var(--bg-subtle); color: var(--primary); }
#page-indicator, #zoom-level { padding: 0 0.75rem; font-size: 0.9rem; font-weight: 500; color: var(--text-primary); }

/* =========================================
   6. MODALS & UTILITIES
   ========================================= */

/* Generic Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px) saturate(150%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1100;
}
.modal-content {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    max-width: 600px;
    width: 90%;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    padding-bottom: 1rem;
    margin-bottom: 1rem;
}
.modal-header h3 {
    margin: 0;
    font-size: 1.2rem;
}
.modal-header button {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
}

/* Signature Modal Specifics */
.signature-modal-content {
    max-width: 900px;
    width: 95%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}
.signature-modal-layout {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 1.5rem;
    min-height: 450px;
    overflow-y: auto;
    padding-right: 10px;
}
.signature-panel-left {
    border-right: 1px solid var(--border);
    padding-right: 1.5rem;
    display: flex;
    flex-direction: column;
}
.signature-panel-left h4, .signature-panel-right h4 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--text-secondary);
}
#saved-signatures-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
    flex-grow: 1;
    overflow-y: auto;
    padding: 0.5rem;
    align-content: flex-start;
}
.saved-signature-item {
    position: relative;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
    background-color: var(--bg-subtle);
}
.saved-signature-item:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
}
.saved-signature-item img {
    width: 100%;
    height: auto;
    object-fit: contain;
}
.delete-signature-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background-color: var(--danger);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    opacity: 0;
    transition: opacity 0.2s;
}
.saved-signature-item:hover .delete-signature-btn {
    opacity: 1;
}
#add-new-signature-area {
    border-top: 1px solid var(--border);
    padding-top: 1rem;
}
.signature-panel-right {
    display: flex;
    flex-direction: column;
}
#signature-placeholder {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    border: 2px dashed var(--border);
    border-radius: 8px;
}
#signature-placeholder i {
    font-size: 3rem;
    margin-bottom: 1rem;
}
#signature-preview-area {
    display: flex;
    flex-direction: column;
    height: 100%;
}
#signature-picker-instruction {
    font-size: 0.9rem;
    text-align: center;
    color: var(--primary);
    margin-bottom: 0.5rem;
}
#signature-preview-canvas-wrapper {
    width: 100%;
    flex-grow: 1;
    margin: 0 auto 1rem;
    border: 1px dashed var(--border);
    background-color: var(--bg-subtle);
    padding: 0.5rem;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}
#signature-preview-canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}
#signature-preview-canvas.picking-color {
    cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M16.27 7.73L6.5 17.5l-4-4L12.27 3.73a2.12 2.12 0 0 1 3 3zM8.5 14.5L5 11"/></svg>') 4 19, crosshair;
}
.signature-preview-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}
.signature-preview-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: auto;
}

/* --- NEW: Modern Signature Crop UI --- */
#sig-crop-box-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
}
.sig-crop-overlay {
    position: absolute;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1;
}
#sig-crop-box-container .crop-box {
    position: absolute;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
    border: 1px solid #fff;
    z-index: 2;
    cursor: move;
}
.sig-crop-grid-line {
    position: absolute;
    background-color: rgba(255, 255, 255, 0.5);
    pointer-events: none;
}
.sig-crop-grid-line.vertical { width: 1px; height: 100%; }
.sig-crop-grid-line.horizontal { height: 1px; width: 100%; }
.sig-crop-handle {
    position: absolute;
    background-color: #fff;
    z-index: 3;
}
.sig-crop-handle.corner { width: 10px; height: 10px; border-radius: 50%; }
.sig-crop-handle.top-left { top: -5px; left: -5px; cursor: nwse-resize; }
.sig-crop-handle.top-right { top: -5px; right: -5px; cursor: nesw-resize; }
.sig-crop-handle.bottom-left { bottom: -5px; left: -5px; cursor: nesw-resize; }
.sig-crop-handle.bottom-right { bottom: -5px; right: -5px; cursor: nwse-resize; }
.sig-crop-handle.side { background-color: rgba(255, 255, 255, 0.8); }
.sig-crop-handle.top, .sig-crop-handle.bottom {
    left: 25%; width: 50%; height: 6px;
    cursor: ns-resize;
}
.sig-crop-handle.top { top: -3px; }
.sig-crop-handle.bottom { bottom: -3px; }
.sig-crop-handle.left, .sig-crop-handle.right {
    top: 25%; height: 50%; width: 6px;
    cursor: ew-resize;
}
.sig-crop-handle.left { left: -3px; }
.sig-crop-handle.right { right: -3px; }


/* Picked Color Swatches */
#picked-colors-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 1rem;
    padding: 8px;
    background-color: var(--bg-subtle);
    border-radius: 6px;
    min-height: 40px;
}
.picked-color-swatch {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--bg-card);
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    position: relative;
    cursor: pointer;
}
.picked-color-swatch span {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 16px;
    height: 16px;
    background-color: var(--danger);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    line-height: 1;
    font-weight: bold;
    opacity: 0;
    transition: opacity 0.2s;
}
.picked-color-swatch:hover span {
    opacity: 1;
}

/* Loader */
#loader-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.3); backdrop-filter: blur(10px) saturate(150%); display: flex; align-items: center; justify-content: center; z-index: 1100; }
.loader-content { background: var(--bg-card); padding: 2rem 3rem; border-radius: 12px; text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,0.2); }
.loader-content i { font-size: 3rem; color: var(--primary); margin-bottom: 1rem; }
.loader-content p { font-size: 1.1rem; font-weight: 500; color: var(--text-primary); }

/* PWA Install Banner */
#install-prompt { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background-color: var(--bg-card); color: var(--text-primary); padding: 1rem 1.5rem; border-radius: 12px; box-shadow: 0 10px 30px rgba(var(--shadow-color), 0.2); z-index: 3000; display: flex; align-items: center; gap: 1rem; transition: opacity 0.3s, transform 0.3s; }
#install-prompt.hidden { opacity: 0; transform: translate(-50%, 100px); pointer-events: none; }
#install-prompt p { margin: 0; font-weight: 500; }
#install-prompt-btn.primary { padding: 0.5rem 1rem; border-radius: 8px; border: none; background-color: var(--primary); color: white; font-weight: 600; cursor: pointer; }
#install-dismiss-btn { background: none; border: none; color: var(--text-secondary); font-size: 1.5rem; cursor: pointer; }

/* Password Overlay */
#password-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.3); backdrop-filter: blur(10px) saturate(150%); display: flex; align-items: center; justify-content: center; z-index: 1200; }
.password-prompt { background: var(--bg-card); padding: 2rem; border-radius: 12px; text-align: center; box-shadow: 0 10px 30px rgba(var(--shadow-color), 0.2); max-width: 400px; width: 90%; position: relative; }
.password-prompt h3 { font-size: 1.5rem; color: var(--text-primary); margin-bottom: 1rem; }
#unlock-now-btn { display: inline-block; padding: 0.75rem 1.5rem; background-color: var(--primary); color: white; border-radius: 8px; text-decoration: none; font-weight: 600; }
#close-password-prompt-btn { position: absolute; top: 10px; right: 10px; background: none; border: none; font-size: 1.75rem; cursor: pointer; color: var(--text-secondary); }

/* Unsupported Mobile Overlay */
#mobile-unsupported-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: var(--bg-main); z-index: 5000; display: none; align-items: center; justify-content: center; text-align: center; padding: 2rem; }
.mobile-unsupported-content { max-width: 400px; }

/* Auth Modal (Global) */
.auth-modal-overlay { position: fixed; }