/* PDF Form Fill Advanced Mode Styles */

/* Advanced Editor */
.advanced-editor {
    margin-top: 2rem;
}

.editor-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--color-white);
    border: 1px solid var(--color-border);
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.toolbar-btn {
    padding: 0.5rem 1rem;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: 0.25rem;
    cursor: pointer;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: background 0.3s ease;
}

.toolbar-btn:hover {
    background: var(--color-primary-dark, #c02a35);
}

.toolbar-label {
    margin: 0;
    font-weight: 500;
    color: var(--color-text);
}

.toolbar-select {
    padding: 0.5rem;
    border: 1px solid var(--color-border);
    border-radius: 0.25rem;
    background: var(--color-white);
    font-size: 0.9rem;
}

.editor-container {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.pdf-preview-container {
    position: relative;
    border: 1px solid var(--color-border);
    border-radius: 0.5rem;
    background: #f5f5f5;
    overflow: auto;
    max-height: 800px;
}

.pdf-preview {
    position: relative;
    display: inline-block;
    min-width: 100%;
}

#pdfCanvas {
    display: block;
    max-width: 100%;
    height: auto;
    background: white;
}

.elements-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* Grid Overlay */
.grid-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
    background-size: 20px 20px;
    background-image:
        linear-gradient(to right, rgba(200, 200, 200, 0.3) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(200, 200, 200, 0.3) 1px, transparent 1px);
}

.grid-overlay.grid-10 {
    background-size: 10px 10px;
}

.grid-overlay.grid-20 {
    background-size: 20px 20px;
}

.grid-overlay.grid-30 {
    background-size: 30px 30px;
}

.grid-overlay.grid-50 {
    background-size: 50px 50px;
}

/* Grid Toolbar Options */
.toolbar-grid-options {
    border-left: 1px solid var(--color-border);
    padding-left: 1rem;
}

.toolbar-grid-options .toolbar-label {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    transition: background 0.2s;
}

.toolbar-grid-options .toolbar-label:hover {
    background: rgba(0, 0, 0, 0.05);
}

.toolbar-grid-options input[type="checkbox"] {
    margin-right: 0.25rem;
}

.toolbar-select-small {
    width: auto;
    min-width: 70px;
}

.element-item {
    position: absolute;
    pointer-events: all;
    cursor: move;
    border: 2px dashed var(--color-primary);
    background: rgba(230, 57, 70, 0.05);
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    min-width: 50px;
    min-height: 20px;
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    font-size: 0.85rem;
    color: var(--color-text);
    z-index: 10;
    box-sizing: border-box;
    touch-action: none;
    /* Allow remove button to be outside */
    overflow: visible;
    line-height: 1.2;
}

.element-item.text-element {
    /* Explicit text box styling */
    text-align: left;
    vertical-align: top;
}

/* Text content span - ensures text stays within box */
.element-text-content {
    display: block;
    width: 100%;
    height: 100%;
    overflow: hidden;
    word-wrap: break-word;
    word-break: break-word;
    white-space: pre-wrap;
    text-overflow: ellipsis;
}


.element-item.selected {
    border-color: var(--color-primary);
    background: rgba(230, 57, 70, 0.2);
    z-index: 20;
}

.element-item.signature-element {
    border-color: #28a745;
    background: rgba(40, 167, 69, 0.1);
}

/* Remove button - positioned outside the element */
.element-item .element-remove {
    position: absolute;
    top: -12px;
    right: -12px;
    width: 24px;
    height: 24px;
    background: var(--color-primary);
    color: white;
    border: 2px solid white;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    z-index: 100;
    opacity: 0.95;
    transition: all 0.2s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.element-item .element-remove:hover {
    background: var(--color-primary-dark, #c02a35);
    opacity: 1;
    transform: scale(1.1);
}

.elements-panel {
    background: var(--color-white);
    border: 1px solid var(--color-border);
    border-radius: 0.5rem;
    padding: 1rem;
    max-height: 800px;
    overflow-y: auto;
}

.panel-title {
    margin: 0 0 1rem 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--color-text);
}

.elements-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.element-list-item {
    padding: 0.75rem;
    background: #f8f9fa;
    border: 1px solid var(--color-border);
    border-radius: 0.25rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.element-list-item:hover {
    background: #e9ecef;
    border-color: var(--color-primary);
}

.element-list-item.selected {
    background: rgba(230, 57, 70, 0.1);
    border-color: var(--color-primary);
}

.element-list-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.element-list-item-type {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--color-text);
}

.element-list-item-actions {
    display: flex;
    gap: 0.25rem;
}

.element-list-item-btn {
    padding: 0.25rem 0.5rem;
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: 0.25rem;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--color-text);
}

.element-list-item-btn:hover {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

.element-list-item-content {
    font-size: 0.85rem;
    color: var(--color-gray);
    word-break: break-word;
}

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

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

.modal-content {
    background: var(--color-white);
    border-radius: 0.5rem;
    width: 90%;
    max-width: 700px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

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

.modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

.modal-close {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    color: var(--color-gray);
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    color: var(--color-text);
}

.modal-body {
    padding: 1.5rem;
}

#signatureCanvas {
    border: 2px solid var(--color-border);
    border-radius: 0.25rem;
    cursor: crosshair;
    display: block;
    width: 100%;
    max-width: 100%;
    background: white;
    touch-action: none;
    /* Prevent scrolling while drawing */
}

.signature-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
    justify-content: flex-end;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
    justify-content: flex-end;
}

.modal-actions .btn-secondary {
    background-color: #6c757d;
    border-color: #6c757d;
    color: white;
}

.modal-actions .btn-secondary:hover {
    background-color: #5a6268;
    border-color: #545b62;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.form-row .form-group {
    margin-bottom: 0;
}

/* Responsive */
@media (max-width: 768px) {
    .editor-container {
        grid-template-columns: 1fr;
    }

    .elements-panel {
        max-height: 400px;
    }

    .editor-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .toolbar-group {
        justify-content: space-between;
    }
}

/* Mobile Controls */
.mobile-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: white;
    border-top: 1px solid var(--color-border);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    padding: 1rem;
    display: none;
    /* Hidden by default, toggled by JS */
}

.mobile-controls-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.mobile-controls-header h4 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.mobile-controls-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0 0.5rem;
}

.mobile-controls-grid {
    display: flex;
    justify-content: space-around;
    align-items: flex-start;
    gap: 1rem;
}

.control-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.control-group label {
    font-size: 0.8rem;
    color: var(--color-gray);
    font-weight: 500;
}

.d-pad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 0.25rem;
    width: 100px;
}

.d-pad-btn {
    width: 30px;
    height: 30px;
    border: 1px solid var(--color-border);
    background: #f8f9fa;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

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

.d-pad-btn.up {
    grid-column: 2;
    grid-row: 1;
}

.d-pad-btn.left {
    grid-column: 1;
    grid-row: 2;
}

.d-pad-btn.right {
    grid-column: 3;
    grid-row: 2;
}

.d-pad-btn.down {
    grid-column: 2;
    grid-row: 2;
}

.size-controls {
    display: flex;
    gap: 0.5rem;
}

.control-btn {
    width: 40px;
    height: 40px;
    border: 1px solid var(--color-border);
    background: #f8f9fa;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1rem;
}

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

.control-btn.delete-btn {
    color: #dc3545;
    border-color: #dc3545;
}

.control-btn.delete-btn:active {
    background: #dc3545;
    color: white;
}

/* Responsive adjustments */
@media (min-width: 769px) {
    .mobile-controls {
        display: none !important;
        /* Never show on desktop */
    }
}

@media (max-width: 768px) {
    .editor-container {
        grid-template-columns: 1fr;
        margin-bottom: 200px;
        /* Space for mobile controls */
    }

    .elements-panel {
        max-height: 400px;
    }

    .editor-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .toolbar-group {
        justify-content: space-between;
    }
}