/* One PDF Editor - Professional Enterprise Styling */

/* ==================
   Bundled Fonts (Cross-Platform)
   These fonts are served from backend/fonts/ and work on both macOS and Linux VPS
   ================== */

/* Arimo - Metric-compatible with Arial/Helvetica */
@font-face {
    font-family: 'Arimo-Regular';
    src: url('/api/bundled-fonts/Arimo-Regular.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'Arimo-Bold';
    src: url('/api/bundled-fonts/Arimo-Bold.ttf') format('truetype');
    font-weight: bold;
    font-style: normal;
}

@font-face {
    font-family: 'Arimo-Italic';
    src: url('/api/bundled-fonts/Arimo-Italic.ttf') format('truetype');
    font-weight: normal;
    font-style: italic;
}

@font-face {
    font-family: 'Arimo-BoldItalic';
    src: url('/api/bundled-fonts/Arimo-BoldItalic.ttf') format('truetype');
    font-weight: bold;
    font-style: italic;
}

/* Tinos - Metric-compatible with Times New Roman */
@font-face {
    font-family: 'Tinos-Regular';
    src: url('/api/bundled-fonts/Tinos-Regular.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'Tinos-Bold';
    src: url('/api/bundled-fonts/Tinos-Bold.ttf') format('truetype');
    font-weight: bold;
    font-style: normal;
}

@font-face {
    font-family: 'Tinos-Italic';
    src: url('/api/bundled-fonts/Tinos-Italic.ttf') format('truetype');
    font-weight: normal;
    font-style: italic;
}

@font-face {
    font-family: 'Tinos-BoldItalic';
    src: url('/api/bundled-fonts/Tinos-BoldItalic.ttf') format('truetype');
    font-weight: bold;
    font-style: italic;
}

/* Cousine - Metric-compatible with Courier New */
@font-face {
    font-family: 'Cousine-Regular';
    src: url('/api/bundled-fonts/Cousine-Regular.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'Cousine-Bold';
    src: url('/api/bundled-fonts/Cousine-Bold.ttf') format('truetype');
    font-weight: bold;
    font-style: normal;
}

@font-face {
    font-family: 'Cousine-Italic';
    src: url('/api/bundled-fonts/Cousine-Italic.ttf') format('truetype');
    font-weight: normal;
    font-style: italic;
}

@font-face {
    font-family: 'Cousine-BoldItalic';
    src: url('/api/bundled-fonts/Cousine-BoldItalic.ttf') format('truetype');
    font-weight: bold;
    font-style: italic;
}

:root {
    /* Global Variables - Professional Blue/Orange Theme */
    /* Primary Colors - Blue */
    --primary: #2563eb;
    /* Professional Blue */
    --primary-hover: #1d4ed8;
    --primary-active: #1e40af;
    --primary-light: #dbeafe;

    /* Accent Colors - Orange */
    --accent: #f97316;
    /* Vibrant Orange for CTAs */
    --accent-hover: #ea580c;
    --accent-light: #ffedd5;

    /* Secondary */
    --secondary: #1e293b;
    /* Dark Slate for Headings */

    /* UI Colors */
    --bg-body: #f8fafc;
    /* Clean slate-tinted white */
    --bg-surface: #ffffff;
    --bg-toolbar: #ffffff;

    /* Text Colors */
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-light: #94a3b8;

    /* Borders & Shadows */
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-soft: 0 4px 6px rgba(0, 0, 0, 0.04);
    --shadow-card: 0 10px 25px rgba(0, 0, 0, 0.08);
    --shadow-float: 0 20px 40px rgba(0, 0, 0, 0.12);

    /* Spacing */
    --nav-height: 64px;
    --toolbar-height: 50px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Open Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--text-primary);
    background-color: var(--bg-body);
    line-height: 1.6;
    overflow-x: hidden;
}

/* ==================
   Rich Navigation Bar
   ================== */
.navbar {
    height: var(--nav-height);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 40px;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: var(--shadow-sm);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--secondary);
    text-decoration: none;
}

.brand-icon {
    font-size: 1.5rem;
    color: var(--primary);
}

.nav-menu {
    display: flex;
    gap: 32px;
}

.nav-link {
    text-decoration: none;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.95rem;
    padding: 4px 0;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.nav-link:hover {
    color: var(--text-primary);
}

.nav-link.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.btn-login {
    text-decoration: none;
    color: var(--text-secondary);
    font-weight: 600;
    padding: 8px 16px;
}

.btn-trial {
    background: var(--primary);
    color: white;
    text-decoration: none;
    font-weight: 600;
    padding: 8px 20px;
    border-radius: 4px;
    transition: background 0.2s;
}

.btn-trial:hover {
    background: var(--primary-hover);
}

/* ==================
   Pro Upload Section
   ================== */
.upload-container {
    margin-top: var(--nav-height);
    padding: 60px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: calc(100vh - var(--nav-height) - 60px);
    /* Minus footer */
    background: linear-gradient(180deg, #ffffff 0%, #f4f7f6 100%);
}

.upload-card-wrapper {
    width: 100%;
    max-width: 800px;
    text-align: center;
}

.hero-title {
    font-size: 2.5rem;
    color: var(--secondary);
    margin-bottom: 12px;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.hero-subtitle {
    font-size: 1.25rem;
    color: var(--text-secondary);
    margin-bottom: 40px;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

.upload-box {
    background: white;
    padding: 60px;
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.08);
    border: 2px dashed #cdd5dc;
    transition: all 0.2s ease;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.upload-box:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.12);
}

.upload-icon-circle {
    width: 80px;
    height: 80px;
    background: #f0fdf4;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 24px;
    color: var(--primary);
    font-size: 2rem;
}

.btn-upload-lg {
    background: var(--primary);
    color: white;
    font-size: 1.2rem;
    font-weight: 600;
    padding: 16px 40px;
    border-radius: 50px;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 156, 77, 0.3);
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 12px;
}

.btn-upload-lg:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(0, 156, 77, 0.4);
}

/* Feature Grid (Trust Signals) */
.features-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 40px;
    margin-top: 60px;
    max-width: 1000px;
    padding: 0 20px;
}

.feature-item {
    text-align: center;
}

.feature-icon {
    font-size: 1.5rem;
    color: var(--secondary);
    margin-bottom: 12px;
    background: white;
    width: 48px;
    height: 48px;
    border-radius: 12px;
    box-shadow: var(--shadow-card);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.feature-title {
    font-weight: 700;
    color: var(--secondary);
    margin-bottom: 8px;
}

.feature-desc {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* ==================
   App Footer
   ================== */
.app-footer {
    background: white;
    border-top: 1px solid var(--border);
    padding: 24px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: auto;
}

/* ==================
   Editor Workspace
   ================== */
/* Editor Workspace */
.editor-workspace {
    margin-top: var(--nav-height);
    height: calc(100vh - var(--nav-height));
    display: flex;
    flex-direction: column;
    background: #e5e7eb;
    /* Lighter clean gray instead of dark */
}

/* Robust Toolbar */
.toolbar {
    background: var(--bg-toolbar);
    height: var(--toolbar-height);
    border-bottom: 1px solid var(--border);
    display: flex;
    padding: 0 24px;
    justify-content: space-between;
    align-items: center;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 4px;
    padding-right: 12px;
    margin-right: 12px;
    border-right: 1px solid #dde1e6;
    height: 32px;
}

.toolbar-group:last-child {
    border-right: none;
}

.tool-btn {
    height: 36px;
    padding: 0 12px;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    color: #4a5568;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.1s;
}

.tool-btn:hover {
    background: #e9ecef;
    color: var(--text-primary);
}

.tool-btn.active {
    background: #e6f4ea;
    color: var(--primary);
    border-color: #bce3cd;
}

.tool-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: transparent;
    color: #a0aec0;
}

.tool-btn:disabled:hover {
    background: transparent;
    color: #a0aec0;
}

/* Editor Main (Canvas) */
.main-content {
    flex: 1;
    overflow: hidden;
    /* Canvas container handles scroll */
    position: relative;
}

.canvas-container {
    width: 100%;
    height: 100%;
    overflow: auto;
    padding: 40px;
    display: flex;
    justify-content: center;
    background-color: #f5f5f5 !important;
    /* Light gray background */
    background-image: none !important;
    /* Remove any pattern */
}

/* PDF Page Wrapper (Paper look) */
.pdf-page-wrapper {
    position: relative;
    background: white;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    /* Deep shadow */
    margin-bottom: 40px;
}

/* Floating Controls */
.page-controls {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: #2c3e50;
    backdrop-filter: blur(8px);
    padding: 8px 20px;
    border-radius: 50px;
    display: flex;
    align-items: center;
    gap: 16px;
    color: white;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    z-index: 500;
}

.page-controls button {
    background: none;
    border: none;
    color: #cbd5e0;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    font-size: 1rem;
}

.page-controls button:hover {
    color: white;
    background: rgba(255, 255, 255, 0.1);
}

.page-meta {
    font-variant-numeric: tabular-nums;
    font-size: 0.9rem;
    font-weight: 500;
}

/* Utility */
.hidden {
    display: none !important;
}

/* Action Buttons */
.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 8px 20px;
    border-radius: 4px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: all 0.2s;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-primary:disabled {
    background: #a0aec0;
    cursor: not-allowed;
    box-shadow: none;
}

/* Overlays */
.text-layer,
.edit-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* Allow clicks to pass through to canvas if needed, but text items capture them */
}

.text-item {
    position: absolute;
    cursor: text;
    border: 1px solid transparent;
    /* Highlight on hover */
    pointer-events: auto;
}

.text-item:hover {
    background: rgba(0, 156, 77, 0.05);
    border-color: rgba(0, 156, 77, 0.3);
}

.edit-input {
    position: absolute;
    /* Vital */
    border: 1px solid var(--accent);
    background: white;
    padding: 0;
    outline: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    pointer-events: auto;
}

/* Loading */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(0, 0, 0, 0.1);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s infinite linear;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* ===================
   Sejda-Style Inline Editing
   =================== */

/* Text Span - Seamless Inline Text */
.text-span {
    position: absolute;
    cursor: text;
    white-space: pre;
    outline: none;
    border: none;
    background: transparent;
    color: transparent;
    /* Hidden by default - overlays PDF canvas */
    transition: background 0.1s, box-shadow 0.1s;
    /* Zero padding ensures exact fit to maintain PDF layout fidelity */
    padding: 0;
    margin: 0;
    border-radius: 0;
    line-height: 1.0;
    pointer-events: auto;
    box-sizing: border-box;
    /* CRITICAL: Enable mouse interaction */
}

.text-span:hover {
    background: rgba(0, 156, 77, 0.08);
    box-shadow: 0 0 0 2px rgba(0, 156, 77, 0.15);
    color: transparent;
    /* Still hidden on hover */
}

.text-span.editing {
    /* Color is set by JavaScript from textRun.color */
    background-color: #ffffff;
    /* Opaque white background to completely hide PDF text underneath */
    box-shadow: 0 0 0 1px rgba(46, 129, 206, 0.5);
    /* Thinner focus ring */
    z-index: 100;
    padding: 0;
    margin: 0;
}

.text-span.edited {
    /* Color is set by JavaScript to preserve original text color */
    /* Background color set by JS to match PDF background */
    padding: 0;
    margin: 0;
}

/* Floating Toolbar - Sejda Style */
.floating-toolbar {
    position: absolute;
    background: linear-gradient(180deg, #4a5568 0%, #3d4654 100%);
    border-radius: 6px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25), 0 2px 6px rgba(0, 0, 0, 0.15);
    padding: 4px 6px;
    display: flex;
    align-items: center;
    gap: 2px;
    z-index: 2000;
    pointer-events: auto;
}

.floating-toolbar::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    border-width: 6px 6px 0 6px;
    border-style: solid;
    border-color: #3d4654 transparent transparent transparent;
}

.toolbar-item {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: #e2e8f0;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    transition: all 0.12s;
}

.toolbar-item:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

.toolbar-item.active {
    background: rgba(255, 255, 255, 0.25);
    color: #fff;
}

.toolbar-item.delete-btn:hover {
    background: rgba(231, 76, 60, 0.3);
    color: #e74c3c;
}

.toolbar-divider {
    width: 1px;
    height: 20px;
    background: rgba(255, 255, 255, 0.2);
    margin: 0 4px;
}

/* Remove old edit-input styles - replaced by inline editing */
.edit-input {
    display: none !important;
}

/* ==================
   Mobile Responsiveness & Touch Optimization
   ================== */

/* Mobile-First Breakpoints */
@media (max-width: 1024px) {
    .toolbar {
        flex-wrap: wrap;
        padding: 12px 16px;
    }

    .toolbar-group {
        flex-wrap: wrap;
    }

    .page-controls {
        width: 100%;
        justify-content: center;
        order: -1;
        margin-bottom: 12px;
    }
}

@media (max-width: 768px) {

    /* Navigation */
    .nav-menu {
        display: none;
        /* Hide menu on mobile, can add hamburger menu later */
    }

    .nav-actions {
        gap: 8px;
    }

    .btn-login,
    .btn-trial {
        padding: 6px 12px;
        font-size: 0.85rem;
    }

    /* Upload Container */
    .upload-container {
        padding: 40px 20px;
    }

    .upload-box h2 {
        font-size: 1.5rem;
    }

    /* Toolbar - Touch Friendly */
    .toolbar {
        padding: 12px;
        gap: 8px;
    }

    .tool-btn,
    .control-btn {
        min-width: 44px;
        min-height: 44px;
        padding: 10px 14px;
        font-size: 0.85rem;
    }

    .tool-btn i {
        font-size: 1.1rem;
    }

    /* Zoom controls - easier touch */
    .zoom-display {
        min-width: 70px;
        font-size: 0.9rem;
    }

    /* Editor Container */
    .editor-container {
        padding: 16px;
    }

    #canvasContainer {
        margin: 16px auto;
    }

    /* Text Layer - Better touch selection */
    .text-layer span {
        cursor: pointer;
        -webkit-tap-highlight-color: rgba(0, 156, 77, 0.2);
    }

    .text-layer span.editing {
        min-width: 100px;
        /* Ensure enough space for typing on mobile */
    }

    /* Floating Toolbar - Optimize for mobile */
    #floatingToolbar {
        flex-wrap: wrap;
        max-width: 95vw;
        padding: 8px;
        gap: 6px;
    }

    #floatingToolbar button {
        min-width: 40px;
        min-height: 40px;
        padding: 8px;
    }

    /* Font Dropdown */
    #fontFamilySelect {
        max-width: 140px;
        font-size: 0.85rem;
    }

    /* Page Navigation */
    .pagination-info {
        font-size: 0.9rem;
    }

    /* Apply Button - Sticky on mobile */
    .actions {
        position: sticky;
        bottom: 0;
        background: white;
        padding: 16px;
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
        z-index: 100;
    }

    .btn-apply {
        width: 100%;
        font-size: 1rem;
        padding: 14px;
    }
}

@media (max-width: 480px) {

    /* Extra small screens */
    .navbar {
        padding: 12px 16px;
    }

    .brand {
        font-size: 1.1rem;
    }

    .brand-icon {
        font-size: 1.3rem;
    }

    .nav-actions .btn-trial {
        display: none;
        /* Hide trial button on very small screens */
    }

    /* Upload */
    .upload-box {
        padding: 32px 16px;
    }

    .upload-box h2 {
        font-size: 1.25rem;
    }

    .upload-box p {
        font-size: 0.9rem;
    }

    .file-input-btn {
        font-size: 0.9rem;
        padding: 12px 24px;
    }

    /* Toolbar - Compact */
    .toolbar-group:not(:first-child) {
        display: none;
        /* Hide advanced tools on tiny screens */
    }

    .page-controls {
        gap: 8px;
    }

    .control-btn {
        min-width: 40px;
        padding: 8px;
    }

    /* Zoom */
    .zoom-display {
        min-width: 60px;
        padding: 6px;
        font-size: 0.85rem;
    }

    /* Canvas - Full width on mobile */
    #canvasContainer {
        max-width: 100%;
    }

    /* Floating Toolbar - Simplified */
    #floatingToolbar {
        padding: 6px;
        bottom: 80px;
        /* Account for sticky apply button */
    }

    #floatingToolbar button {
        min-width: 36px;
        min-height: 36px;
        padding: 6px;
    }
}

/* Touch-Specific Enhancements */
@media (hover: none) and (pointer: coarse) {
    /* Targeting touch devices specifically */

    .text-layer span:hover {
        background-color: rgba(0, 156, 77, 0.1);
        /* Less aggressive hover on touch */
    }

    .tool-btn:active,
    .control-btn:active {
        transform: scale(0.95);
        /* Visual feedback on tap */
    }

    /* Larger minimum touch targets */
    button,
    .tool-btn,
    .control-btn,
    .nav-link {
        min-width: 44px;
        min-height: 44px;
    }

    /* Prevent double-tap zoom on buttons */
    button,
    .tool-btn,
    .control-btn {
        touch-action: manipulation;
    }

    /* Better selection visibility on touch */
    .text-layer span.editing {
        outline: 3px solid var(--primary);
        outline-offset: 2px;
    }
}

/* Landscape Mobile Optimization */
@media (max-width: 896px) and (orientation: landscape) {
    .upload-container {
        padding: 24px 20px;
    }

    .toolbar {
        padding: 8px 12px;
    }

    .editor-container {
        padding: 12px;
    }

    /* Make better use of horizontal space */
    #canvasContainer {
        max-height: calc(100vh - 200px);
    }
}

/* High DPI / Retina Displays */
@media (-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {
    canvas {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}