body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f4f7f9;
    color: #333;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100vh;
    overflow: hidden;
}

header {
    width: 100%;
    background-color: #fff;
    border-bottom: 1px solid #dde3e8;
    padding: 20px 0;
    text-align: center;
}

header h1 {
    margin: 0;
    font-size: 1.8rem;
    color: #007bff;
}

header p {
    margin: 5px 0 0;
    color: #666;
}

main {
    width: 95%;
    max-width: 1200px;
    margin: 20px 0;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    padding: 20px;
    box-sizing: border-box;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    padding: 15px 20px;
    background: #f8f9fa;
    border-bottom: 2px solid #e0e0e0;
    margin-bottom: 0;
}

.controls-group {
    display: flex;
    gap: 8px;
    align-items: center;
}

.controls-divider {
    width: 1px;
    height: 36px;
    background-color: #cbd5e0;
    margin: 0 4px;
}

#image-tools-group,
#history-group {
    display: none;
}

#file-input {
    display: none;
}

.button,
#save-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    font-size: 0.95rem;
    font-weight: 500;
    color: #fff;
    background-color: #007bff;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
    white-space: nowrap;
}

.button:hover,
#save-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.button:active,
#save-button:active {
    transform: translateY(0);
}

/* Button Color Variants */
.btn-primary {
    background-color: #007bff;
}

.btn-primary:hover {
    background-color: #0056b3;
    box-shadow: 0 2px 6px rgba(0, 123, 255, 0.4);
}

.btn-success {
    background-color: #28a745;
}

.btn-success:hover {
    background-color: #218838;
    box-shadow: 0 2px 6px rgba(40, 167, 69, 0.4);
}

.btn-edit {
    background-color: #17a2b8;
}

.btn-edit:hover {
    background-color: #138496;
    box-shadow: 0 2px 6px rgba(23, 162, 184, 0.4);
}

.btn-danger {
    background-color: #dc3545;
    display: none;
}

.btn-danger:hover {
    background-color: #c82333;
    box-shadow: 0 2px 6px rgba(220, 53, 69, 0.4);
}

.btn-secondary {
    background-color: #6c757d;
}

.btn-secondary:hover {
    background-color: #5a6268;
    box-shadow: 0 2px 6px rgba(108, 117, 125, 0.4);
}

.btn-icon-only {
    padding: 10px 12px;
    font-size: 1rem;
    position: relative;
}

/* Tooltip styling */
.button[title]:hover::after,
label[title]:hover::after {
    content: attr(title);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 0.85rem;
    white-space: nowrap;
    z-index: 1000;
    pointer-events: none;
    animation: tooltipFadeIn 0.2s ease;
}

.button[title]:hover::before,
label[title]:hover::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    pointer-events: none;
}

@keyframes tooltipFadeIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(4px);
    }

    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

#delete-page-button,
#delete-all-button {
    display: none;
}

/* Workspace Layout */
#workspace {
    display: flex;
    flex: 1;
    border: 1px solid #dde3e8;
    border-radius: 5px;
    overflow: hidden;
}

#thumbnails-panel {
    width: 250px;
    background-color: #f4f7f9;
    border-right: 1px solid #dde3e8;
    overflow-y: auto;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex-shrink: 0;
}

#viewer-panel {
    flex: 1;
    background-color: #e9ecef;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
    min-width: 0;
}

#scroll-wrapper {
    flex: 1;
    overflow: auto;
    display: flex;
    padding: 20px;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    /* cursor: grab; Removed to allow text selection in editor mode */
}

#large-view-container {
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
    background-color: white;
    transform-origin: top left;
    height: fit-content;
    margin: auto;
    flex-shrink: 0;
    position: relative;
}

#editor-toolbar {
    display: none;
    /* Deprecated */
}

/* Zoom Controls */
.zoom-controls {
    margin-left: auto;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay.non-blocking {
    background: transparent;
    pointer-events: none;
}

.modal-content {
    background: white;
    padding: 20px;
    border-radius: 8px;
    width: 300px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    pointer-events: auto;
    /* Ensure content is clickable */
}

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

.modal-body {
    margin-bottom: 20px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.button.secondary {
    background-color: #6c757d;
}

.button.secondary:hover {
    background-color: #5a6268;
}

.control-group {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.slider-container {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.filter-option {
    margin-bottom: 15px;
}

.filter-option label {
    display: block;
    margin-bottom: 5px;
}

.filter-option select,
.filter-option input {
    width: 100%;
}

/* Info Modal Styles */
.info-grid {
    display: grid;
    gap: 20px;
    margin: 20px 0;
}

.info-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid #007bff;
}

.info-item:hover {
    box-shadow: 0 2px 8px rgba(0, 123, 255, 0.15);
}

.info-icon-label {
    font-size: 1.5rem;
    color: #007bff;
    min-width: 30px;
    text-align: center;
}

.info-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.info-label {
    font-size: 0.85rem;
    color: #6c757d;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.info-value {
    font-size: 1.1rem;
    color: #212529;
    font-weight: 600;
}

#info-modal {
    width: auto;
    min-width: 400px;
    max-width: 90%;
}

#info-modal .modal-footer {
    display: flex;
    justify-content: center;
}

.input-group {
    margin-bottom: 10px;
}

.input-group label {
    display: block;
    margin-bottom: 5px;
}

.input-group input {
    width: 100%;
    padding: 5px;
    box-sizing: border-box;
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 5px;
}

/* Crop Overlay */
.crop-overlay {
    position: absolute;
    border: 2px dashed #00ff00;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
    cursor: move;
}

.crop-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: #00ff00;
    border: 1px solid white;
}

.crop-handle.tl {
    top: -5px;
    left: -5px;
    cursor: nw-resize;
}

.crop-handle.tr {
    top: -5px;
    right: -5px;
    cursor: ne-resize;
}

.crop-handle.bl {
    bottom: -5px;
    left: -5px;
    cursor: sw-resize;
}

.crop-handle.br {
    bottom: -5px;
    right: -5px;
    cursor: se-resize;
}

/* Info Icon */
.info-icon {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 30px;
    height: 30px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-weight: bold;
    font-family: sans-serif;
    z-index: 500;
    transition: background 0.3s;
    pointer-events: auto;
}

.info-icon:hover {
    background: rgba(0, 0, 0, 0.8);
    transform: scale(1.1);
}

/* Thumbnail Styles */
.thumbnail {
    width: 100%;
    height: 260px;
    min-height: 260px;
    border: 2px solid transparent;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    transition: border-color 0.2s;
    background-color: white;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    padding: 5px;
    flex-shrink: 0;
}

.thumbnail.active {
    border-color: #007bff;
}

.thumbnail img {
    width: 100%;
    flex: 1;
    object-fit: contain;
    display: block;
    min-height: 0;
}

.thumbnail-number {
    text-align: center;
    font-size: 12px;
    color: #666;
    margin-top: 2px;
}

/* Thumbnail dragging styles */
.thumbnail {
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.thumbnail.dragging {
    opacity: 0.5;
    border: 2px dashed #007bff;
}

.thumbnail.drag-over {
    border-top: 2px solid #007bff;
}

/* Zoom Controls */
.zoom-controls {
    margin-left: auto;
}

#hidden-container {
    position: absolute;
    left: -9999px;
    top: 0;
}

/* File Drag & Drop Overlay */
.drop-zone-active {
    position: relative;
}

#viewer-panel.drop-zone-active::after {
    content: 'Drop files here';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 123, 255, 0.1);
    outline: 3px dashed #007bff;
    outline-offset: -3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: #007bff;
    z-index: 1000;
    pointer-events: none;
    margin: 0;
}

@media print {
    body {
        background-color: #fff;
    }

    header,
    #controls,
    #editor-toolbar {
        display: none;
    }

    main {
        box-shadow: none;
        margin: 0;
        padding: 0;
        width: 100%;
        max-width: none;
    }

    .docx-editor {
        width: 100%;
        margin: 0;
        padding: 0;
        box-shadow: none;
    }

    .page-break {
        border: none;
    }

    .crop-dimensions {
        position: absolute;
        top: -25px;
        left: 50%;
        transform: translateX(-50%);
        background: rgba(0, 0, 0, 0.7);
        color: white;
        padding: 2px 5px;
        border-radius: 3px;
        font-size: 12px;
        pointer-events: none;
        white-space: nowrap;
    }

    /* Loading Overlay */
    #loading-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.7);
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 2000;
    }

    .loading-content {
        text-align: center;
        color: white;
    }

    .loading-content i {
        margin-bottom: 15px;
    }