/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    overflow: hidden;
}

/* Keep file inputs programmatically clickable across browsers */
.input-file-hidden {
    position: fixed;
    left: -9999px;
    top: 0;
    width: 1px;
    height: 1px;
    opacity: 0;
    border: 0;
    padding: 0;
}

/* App layout */
.app-container {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.header {
    background: white;
    border-bottom: 1px solid #e0e0e0;
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 20px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

h1 {
    font-size: 20px;
    font-weight: 600;
    color: #2c3e50;
}

.file-controls {
    display: flex;
    gap: 10px;
}

.zoom-controls,
.page-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Hide legacy page controls in continuous mode */
.page-controls {
    display: none;
}

/* Buttons */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Dropdown */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-content {
    display: none;
    position: absolute;
    right: 0;
    background-color: white;
    min-width: 180px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-radius: 6px;
    border: 1px solid #e0e0e0;
    z-index: 1000;
    top: calc(100% + 4px);
}

/* Invisible bridge to maintain hover when moving from button to dropdown */
.dropdown-content::before {
    content: '';
    position: absolute;
    top: -20px;
    /* Overlap the button significantly */
    left: 0;
    right: 0;
    height: 30px;
    /* Cover the gap and part of button */
    background: transparent;
    /* Ensure it catches mouse events */
}

.dropdown:hover .dropdown-content,
.dropdown:focus-within .dropdown-content {
    display: block;
}

.dropdown-item {
    width: 100%;
    padding: 10px 16px;
    border: none;
    background: none;
    text-align: left;
    cursor: pointer;
    font-size: 14px;
    color: #2c3e50;
    transition: background-color 0.2s ease;
    border-radius: 0;
}

.dropdown-item:hover {
    background-color: #f8f9fa;
}

.dropdown-item:first-child {
    border-radius: 6px 6px 0 0;
}

/* Compact select for export mode */
.select-compact {
    height: 32px;
    font-size: 13px;
    padding: 0 8px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    background: #fff;
}

.file-controls .select-compact {
    margin-left: 6px;
}

.dropdown-item:last-child {
    border-radius: 0 0 6px 6px;
}

.btn-primary {
    background: #3498db;
    color: white;
}

.btn-primary:hover {
    background: #2980b9;
}

.btn-secondary {
    background: #95a5a6;
    color: white;
}

.btn-secondary:hover {
    background: #7f8c8d;
}

.btn-secondary:disabled {
    background: #bdc3c7;
    cursor: not-allowed;
}

/* New button variants for clarity in properties panel */
.btn-danger {
    background: #e74c3c;
    color: #fff;
}

.btn-danger:hover {
    background: #c0392b;
}

.btn-sm {
    padding: 6px 10px;
    font-size: 13px;
}

.btn-icon {
    padding: 8px 12px;
    background: #ecf0f1;
    color: #34495e;
    font-size: 16px;
    font-weight: bold;
}

.btn-icon:hover {
    background: #d5dbdb;
}

.btn-icon:disabled {
    background: #ecf0f1;
    color: #bdc3c7;
    cursor: not-allowed;
}

.btn-tool {
    padding: 12px;
    background: #ecf0f1;
    color: #34495e;
    font-size: 18px;
    border-radius: 8px;
    width: 48px;
    height: 48px;
}

.btn-tool.active {
    background: #3498db;
    color: white;
}

.btn-tool:hover {
    background: #d5dbdb;
}

.btn-tool.active:hover {
    background: #2980b9;
}

/* Main content */
.main-content {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.sidebar {
    width: 280px;
    background: white;
    border-right: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.sidebar-section {
    padding: 20px;
    border-bottom: 1px solid #f0f0f0;
}

.sidebar-section h3 {
    font-size: 14px;
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tool-buttons {
    display: flex;
    gap: 8px;
}

/* Properties panel */
.properties-panel {
    font-size: 14px;
}

.no-selection {
    color: #7f8c8d;
    font-style: italic;
}

.property-group {
    margin-bottom: 16px;
}

.property-label {
    display: block;
    margin-bottom: 4px;
    font-weight: 500;
    color: #2c3e50;
}

.property-input {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.property-select {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    background: white;
}

/* Thumbnails */
.thumbnails-container {
    max-height: 400px;
    overflow-y: auto;
}

.thumbnail {
    width: 100%;
    margin-bottom: 8px;
    border: 2px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    transition: border-color 0.2s ease;
}

.thumbnail:hover {
    border-color: #3498db;
}

.thumbnail.active {
    border-color: #e74c3c;
}

.no-content {
    text-align: center;
    color: #7f8c8d;
    padding: 20px;
}

/* PDF Viewer */
.viewer-container {
    flex: 1;
    overflow: auto;
    background: #f8f9fa;
    position: relative;
}

.pdf-viewer {
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100%;
}

/* Landing (no-PDF) readability on large screens */
.pdf-viewer .no-content {
    max-width: 960px;
    margin: 0 auto;
}

.pdf-page {
    margin-bottom: 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-radius: 4px;
    position: relative;
    background: white;
}

.pdf-page canvas {
    display: block;
    border-radius: 4px;
}

/* Reflowed page styles */
.pdf-page.reflowed {
    position: relative;
}

.content-segment {
    position: absolute;
    left: 0;
}

.content-segment canvas {
    display: block;
    border-radius: 0;
}

/* Page break preview */
.page-break-line {
    position: absolute;
    left: 0;
    right: 0;
    height: 0;
    border-top: 2px dashed rgba(231, 76, 60, 0.8);
    pointer-events: none;
}

.page-break-label {
    position: absolute;
    right: 8px;
    top: -10px;
    background: rgba(255, 255, 255, 0.9);
    color: #e74c3c;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 3px;
    border: 1px solid rgba(231, 76, 60, 0.5);
}

/* Loading and no content states */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #7f8c8d;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #ecf0f1;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.no-content-icon {
    font-size: 64px;
    margin-bottom: 20px;
    opacity: 0.5;
}

.no-content h2 {
    font-size: 24px;
    margin-bottom: 12px;
    color: #2c3e50;
}

.no-content p {
    font-size: 16px;
    margin-bottom: 24px;
    color: #7f8c8d;
}

/* Spacer styles */
.spacer {
    position: absolute;
    left: 0;
    right: 0;
    background: white;
    border: 2px dashed #3498db;
    cursor: move;
    transition: all 0.2s ease;
}

.spacer:hover {
    border-color: #e74c3c;
    background: rgba(231, 76, 60, 0.1);
}

.spacer.selected {
    border-color: #e74c3c;
    background: rgba(231, 76, 60, 0.1);
    border-style: solid;
}

.spacer-ghost {
    position: absolute;
    left: 0;
    right: 0;
    background: rgba(52, 152, 219, 0.28);
    border: 2px dashed rgba(52, 152, 219, 0.95);
    pointer-events: none;
    z-index: 1100;
}

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

.btn-icon.small {
    width: 28px;
    height: 28px;
    font-size: 14px;
    padding: 0;
    background: #f3f4f6;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
}

.btn-icon.small:hover {
    background: #e9ecef;
}

.spacer.plain {
    background: white;
}

.spacer.ruled {
    background:
        repeating-linear-gradient(to bottom,
            transparent,
            transparent calc(var(--rule-spacing) - 1px),
            #ddd var(--rule-spacing));
}

.spacer.dot-grid {
    background:
        radial-gradient(circle, #ddd 1px, transparent 1px);
    background-size: var(--dot-pitch) var(--dot-pitch);
}

.spacer.squared {
    background:
        linear-gradient(to right, #ddd 1px, transparent 1px),
        linear-gradient(to bottom, #ddd 1px, transparent 1px);
    background-size: var(--grid-size) var(--grid-size);
}

.spacer-handle {
    position: absolute;
    bottom: -6px;
    right: 50%;
    transform: translateX(50%);
    width: 12px;
    height: 12px;
    background: #e74c3c;
    border: 2px solid white;
    border-radius: 50%;
    cursor: ns-resize;
    display: none;
}

.spacer.selected .spacer-handle {
    display: block;
}

.spacer-label {
    position: absolute;
    top: -20px;
    left: 0;
    font-size: 12px;
    color: #3498db;
    font-weight: 500;
    background: white;
    padding: 2px 6px;
    border-radius: 3px;
    border: 1px solid #3498db;
}

/* Spacer preview */
.spacer-preview {
    position: absolute;
    background: rgba(52, 152, 219, 0.2);
    border: 2px dashed #3498db;
    pointer-events: none;
    z-index: 1000;
}

/* placement guide removed */

/* Context menu */
.context-menu {
    position: absolute;
    background: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 2000;
    min-width: 120px;
}

.context-item {
    padding: 10px 16px;
    cursor: pointer;
    font-size: 14px;
    color: #2c3e50;
    transition: background-color 0.2s ease;
}

.context-item:hover {
    background-color: #f8f9fa;
}

.context-item:first-child {
    border-radius: 6px 6px 0 0;
}

.context-item:last-child {
    border-radius: 0 0 6px 6px;
}

/* Responsive design */
@media (max-width: 768px) {
    .sidebar {
        width: 240px;
    }

    .header {
        flex-direction: column;
        gap: 12px;
        padding: 12px;
    }

    .header-left,
    .header-right {
        flex-direction: column;
        gap: 12px;
    }
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Progress indicator */
.progress-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
}

.progress-content {
    background: white;
    padding: 30px;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.progress-bar {
    width: 300px;
    height: 8px;
    background: #ecf0f1;
    border-radius: 4px;
    overflow: hidden;
    margin: 16px 0;
}

.progress-fill {
    height: 100%;
    background: #3498db;
    transition: width 0.3s ease;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.45);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 4000;
}

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

.modal-content {
    background: #fff;
    padding: 20px;
    border-radius: 12px;
    min-width: 380px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.25);
}

/* Modern export dialog */
.modal-content.modern {
    padding: 0;
    overflow: hidden;
}

.modal-content.modern .modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    border-bottom: 1px solid #eef1f4;
}

.modal-content.modern .modal-header h3 {
    margin: 0;
    color: #2c3e50;
    font-size: 16px;
}

.modal-content.modern .modal-body {
    padding: 16px 18px;
}

.modal-content.modern .modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding: 12px 18px;
    border-top: 1px solid #eef1f4;
}

.form-row {
    display: grid;
    grid-template-columns: 140px 1fr;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.field-label {
    color: #5b6b7b;
    font-size: 13px;
}

.help-text {
    color: #95a5a6;
    font-size: 12px;
    margin-top: 4px;
}

/* Segmented control */
.segmented {
    display: inline-flex;
    background: #f3f4f6;
    border: 1px solid #e3e7ee;
    border-radius: 8px;
    padding: 4px;
}

.segment {
    position: relative;
}

.segment input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.segment span {
    display: inline-block;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    color: #2c3e50;
    cursor: pointer;
}

.segment input:checked+span {
    background: #3498db;
    color: #fff;
    box-shadow: 0 1px 3px rgba(52, 152, 219, 0.3);
    font-weight: 500;
}

/* Social Feedback Links */
.feedback-links {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid #e3e7ee;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    color: #64748b;
}

.feedback-label {
    font-weight: 500;
}

.social-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #f1f5f9;
    color: #475569;
    transition: all 0.2s ease;
}

.social-icon svg {
    width: 14px;
    height: 14px;
}

.social-icon:hover {
    background: #e2e8f0;
    color: #1e293b;
    transform: translateY(-1px);
}

.social-icon.twitter:hover {
    color: #000;
    background: #e2e8f0;
}

.social-icon.email:hover {
    color: #ea4335;
    background: #fee2e2;
}

.feedback-email {
    color: #64748b;
    text-decoration: none;
    font-size: 13px;
    margin-left: 4px;
    transition: color 0.2s;
}

.feedback-email:hover {
    color: #3498db;
    text-decoration: underline;
}

.social-icon svg {
    width: 16px !important;
    height: 16px !important;
}