:root {
    --primary-color: #D32F2F;
    /* Red */
    --primary-hover: #b71c1c;
    --bg-color: #f8f9fa;
    --surface-color: #ffffff;
    --text-color: #333333;
    --text-light: #666666;
    --border-color: #e0e0e0;
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
    --border-radius: 8px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.5;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header Navbar */
.navbar {
    background-color: var(--surface-color);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-sm);
    z-index: 10;
    border-bottom: 2px solid var(--primary-color);
    position: relative;
}

.logo {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-color);
}

.logo span {
    color: var(--primary-color);
}

.actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.instruction-text {
    font-size: 0.9rem;
    color: var(--text-light);
    margin-right: 1rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--border-radius);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Inter', sans-serif;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

.btn.primary:hover:not(:disabled) {
    background-color: var(--primary-hover);
}

.btn.secondary {
    background-color: var(--surface-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

.btn.secondary:hover:not(:disabled) {
    background-color: var(--bg-color);
    border-color: #ccc;
}

/* Main Content */
main {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

/* Upload Area */
.upload-area {
    width: 100%;
    max-width: 600px;
    margin: auto;
    border: 2px dashed var(--border-color);
    border-radius: 12px;
    background-color: var(--surface-color);
    padding: 3rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.upload-area:hover,
.upload-area.dragover {
    border-color: var(--primary-color);
    background-color: #fff9f9;
}

.icon-circle {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background-color: #fff0f0;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.5rem;
}

.upload-content h2 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.upload-content p {
    color: var(--text-light);
    margin-bottom: 1rem;
}

.upload-content .subtext {
    font-size: 0.8rem;
    color: #888;
}

/* PDF Container */
.pdf-container {
    width: 100%;
    max-width: 900px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
    padding-bottom: 4rem;
}

.pdf-page-wrapper {
    position: relative;
    background: var(--surface-color);
    box-shadow: var(--shadow-md);
    border-radius: 4px;
    overflow: hidden;
    /* To keep text inside */
}

@keyframes spawnPop {
    0% {
        transform: scale(0.8);
        box-shadow: 0 0 0 rgba(211, 47, 47, 0);
        opacity: 0;
    }

    50% {
        transform: scale(1.15);
        box-shadow: 0 0 20px rgba(211, 47, 47, 0.8);
        border-color: var(--primary-color);
        background: rgba(255, 255, 255, 0.9);
        opacity: 1;
    }

    100% {
        transform: scale(1);
        box-shadow: 0 0 0 rgba(211, 47, 47, 0);
        opacity: 1;
    }
}

/* Draggable Text */
.draggable-text {
    position: absolute;
    min-width: 50px;
    min-height: 20px;
    font-size: 14px;
    font-family: Arial, sans-serif;
    color: black;
    cursor: move;
    border: 2px dashed transparent;
    padding: 4px;
    background: transparent;
    user-select: none;
    z-index: 100;
    animation: spawnPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.draggable-text:hover,
.draggable-text.active {
    border: 2px dashed var(--primary-color);
    background: rgba(255, 255, 255, 0.7);
    box-shadow: var(--shadow-sm);
}

.draggable-text:focus {
    outline: none;
    border: 2px dashed var(--primary-color);
    background: rgba(255, 255, 255, 0.9);
    cursor: text;
    box-shadow: var(--shadow-md);
}

.text-delete-btn {
    position: absolute;
    top: -10px;
    right: -10px;
    width: 20px;
    height: 20px;
    background: var(--primary-color);
    color: white;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
}

.draggable-text.active .text-delete-btn {
    display: flex;
}

/* Draggable Signature */
.draggable-signature {
    position: absolute;
    cursor: move;
    border: 2px dashed transparent;
    padding: 4px;
    z-index: 100;
    animation: spawnPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.draggable-signature:hover,
.draggable-signature.active {
    border: 2px dashed var(--primary-color);
    background: rgba(255, 255, 255, 0.5);
    box-shadow: var(--shadow-sm);
}

.draggable-signature img {
    max-width: 100%;
    pointer-events: none;
    /* Let the wrapper handle dragging */
}

.draggable-signature .text-delete-btn {
    display: none;
}

.draggable-signature.active .text-delete-btn {
    display: flex;
}

.img-resizer {
    position: absolute;
    right: -6px;
    bottom: -6px;
    width: 14px;
    height: 14px;
    background: var(--primary-color);
    border: 2px solid white;
    border-radius: 50%;
    cursor: se-resize;
    display: none;
    z-index: 10;
    box-shadow: var(--shadow-sm);
}

.draggable-signature.active .img-resizer {
    display: block;
}


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

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--surface-color);
    border-radius: var(--border-radius);
    width: 90%;
    max-width: 450px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.modal-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-light);
}

.modal-body {
    padding: 1rem;
    display: flex;
    justify-content: center;
    background: #f0f0f0;
}

#signatureCanvas {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: crosshair;
}

.modal-footer {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

/* Color Swatches */
.color-swatch {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid var(--border-color);
    cursor: pointer;
    padding: 0;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    flex-shrink: 0;
}

.color-swatch:hover {
    transform: scale(1.2);
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.3);
}

.color-swatch.active-swatch {
    box-shadow: 0 0 0 2px var(--surface-color), 0 0 0 4px var(--primary-color);
}

/* White swatch needs a visible border */
.color-swatch[data-color="#FFFFFF"] {
    border-color: #bbb;
}

/* Collapsible Color Dropdown */
.color-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 0.25rem;
    padding: 0.5rem;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    z-index: 1000;
    animation: dropdownSlide 0.15s ease-out;
}

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

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

/* Highlight Annotation */
.draggable-highlight {
    position: absolute;
    cursor: move;
    border: 2px dashed transparent;
    user-select: none;
    z-index: 50;
    mix-blend-mode: multiply;
    border-radius: 2px;
    animation: spawnPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.draggable-highlight:hover,
.draggable-highlight.active {
    border: 2px dashed rgba(0, 0, 0, 0.3);
}

.draggable-highlight.active .text-delete-btn {
    display: flex;
}

.draggable-highlight .highlight-resizer {
    position: absolute;
    right: -6px;
    bottom: -6px;
    width: 14px;
    height: 14px;
    background: var(--primary-color);
    border: 2px solid white;
    border-radius: 50%;
    cursor: se-resize;
    display: none;
    z-index: 10;
    box-shadow: var(--shadow-sm);
}

.draggable-highlight.active .highlight-resizer {
    display: block;
}

/* Highlight draw mode cursor */
.pdf-page-wrapper.highlight-mode {
    cursor: crosshair;
}

/* Active state for the highlight button */
#highlightBtn.highlighting-active {
    background-color: #FFEB3B;
    color: #333;
    border-color: #FBC02D;
}

/* Undo/Redo disabled state */
#undoBtn:disabled,
#redoBtn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.draggable-textbox {
    position: absolute;
    font-size: 14px;
    font-family: Arial, sans-serif;
    color: black;
    cursor: move;
    border: 2px dashed transparent;
    padding: 4px;
    background: transparent;
    user-select: none;
    z-index: 100;
    overflow: hidden;
    animation: spawnPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.draggable-textbox:hover,
.draggable-textbox.active {
    border: 2px dashed var(--primary-color);
    background: rgba(255, 255, 255, 0.7);
    box-shadow: var(--shadow-sm);
}

.draggable-textbox .text-content {
    width: 100%;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    word-wrap: break-word;
    white-space: pre-wrap;
    line-height: 1.2;
    outline: none;
}

.draggable-textbox.active .text-delete-btn {
    display: flex;
}

.draggable-textbox .textbox-resizer {
    position: absolute;
    right: -6px;
    bottom: -6px;
    width: 14px;
    height: 14px;
    background: var(--primary-color);
    border: 2px solid white;
    border-radius: 50%;
    cursor: se-resize;
    display: none;
    z-index: 10;
    box-shadow: var(--shadow-sm);
}

.draggable-textbox.active .textbox-resizer {
    display: block;
}

/* Draw mode cursor */
.pdf-page-wrapper.draw-mode {
    cursor: crosshair;
}

/* Active state for the draw button */
#drawTextBoxBtn.drawing-active {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.hidden {
    display: none !important;
}

/* Tablet/Intermediate Responsiveness */
@media (max-width: 1100px) {
    .instruction-text {
        display: none !important;
    }
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .navbar {
        padding: 1rem;
    }

    .mobile-menu-btn {
        display: inline-flex !important;
        margin-left: auto;
    }

    .instruction-text {
        display: none !important;
    }

    .actions {
        display: none;
        flex-direction: column;
        position: absolute;
        top: 100%;
        right: 0;
        background: var(--surface-color);
        padding: 1rem;
        box-shadow: var(--shadow-md);
        border: 1px solid var(--border-color);
        border-radius: 0 0 0 var(--border-radius);
        width: auto;
        min-width: 250px;
        z-index: 1000;
        align-items: stretch;
    }

    .actions.show {
        display: flex;
    }

    .actions>button,
    .actions>div {
        margin-bottom: 0.5rem;
        justify-content: center;
        width: 100%;
    }
}