/* PDF Template Editor Styles */

.pdf-template-editor {
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
}

.editor-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: #f8f9fa;
}

.editor-toolbar {
    display: flex;
    align-items: center;
    gap: 2rem;
    padding: 0.75rem 1rem;
    background: white;
    border-bottom: 1px solid #dee2e6;
    flex-shrink: 0;
}

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

.editor-main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Field Palette */
.field-palette {
    width: 280px;
    background: white;
    border-right: 1px solid #dee2e6;
    overflow-y: auto;
    padding: 1rem;
    flex-shrink: 0;
    /* Contain layout recalculations */
    contain: layout style;
}

.palette-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: #495057;
    margin-bottom: 0.75rem;
}

.palette-items {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.palette-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.875rem;
}

.palette-item:hover {
    background: #e9ecef;
    border-color: #238DC1;
    transform: translateX(2px);
}

.palette-item i {
    font-size: 1.125rem;
    color: #238DC1;
}

/* Field List */
.field-list {
    max-height: 400px;
    overflow-y: auto;
}

.field-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.625rem;
    margin-bottom: 0.5rem;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.2s;
}

.field-list-item:hover {
    background: #e9ecef;
}

.field-list-item.selected {
    background: #DCE9F4;
    border-color: #238DC1;
}

.field-info {
    flex: 1;
}

.field-info strong {
    font-size: 0.875rem;
    display: block;
}

.field-info small {
    font-size: 0.75rem;
}

/* Canvas Area */
.canvas-container {
    flex: 1;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 2rem;
    background: #e9ecef;
    position: relative;
    overflow: auto;
}

.canvas-wrapper {
    position: relative;
    transform-origin: top center;
    transition: transform 0.2s;
    /* GPU acceleration for smoother transforms */
    will-change: transform;
    transform: translateZ(0);
}

canvas {
    display: block;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Cursor classes for canvas */
.cursor-crosshair {
    cursor: crosshair;
}

.cursor-default {
    cursor: default;
}

/* Field Overlays */
.field-overlays {
    width: 100%;
    height: 100%;
    /* GPU acceleration */
    will-change: contents;
}

.field-overlay {
    /* Use CSS custom properties for positioning - much faster than inline styles */
    position: absolute;
    left: var(--field-x, 0);
    top: var(--field-y, 0);
    width: var(--field-w, 100px);
    height: var(--field-h, 30px);
    pointer-events: all;
    border: 2px dashed #6c757d;
    background: rgba(108, 117, 125, 0.1);
    cursor: move;
    transition: border-color 0.1s, background 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 500;
    color: #495057;
    /* GPU acceleration for dragging */
    will-change: transform;
    transform: translateZ(0);
}

.field-overlay:hover {
    border-color: #238DC1;
    background: rgba(36, 142, 194, 0.1);
    z-index: 10;
}

.field-overlay.selected {
    border-color: #238DC1;
    border-style: solid;
    background: rgba(36, 142, 194, 0.15);
    z-index: 20;
}

.field-overlay.field-signature {
    border-color: #238DC1;
    background: rgba(36, 142, 194, 0.05);
}

.field-overlay.field-initials {
    border-color: #6610f2;
    background: rgba(102, 16, 242, 0.05);
}

.field-overlay.field-date {
    border-color: #198754;
    background: rgba(25, 135, 84, 0.05);
}

.field-overlay.field-text {
    border-color: #fd7e14;
    background: rgba(253, 126, 20, 0.05);
}

/* Staffing Specialist field styles */
.field-overlay.field-payrate {
    border-color: #20c997;
    background: rgba(32, 201, 151, 0.05);
}

.field-overlay.field-startdate {
    border-color: #0dcaf0;
    background: rgba(13, 202, 240, 0.05);
}

.field-overlay.field-jobtitle {
    border-color: #d63384;
    background: rgba(214, 51, 132, 0.05);
}

.field-overlay.field-department {
    border-color: #6c757d;
    background: rgba(108, 117, 125, 0.05);
}

.field-overlay.field-location {
    border-color: #dc3545;
    background: rgba(220, 53, 69, 0.05);
}

.field-overlay.field-benefits {
    border-color: #198754;
    background: rgba(25, 135, 84, 0.05);
}

.field-overlay.field-schedule {
    border-color: #ffc107;
    background: rgba(255, 193, 7, 0.05);
}

.field-overlay.field-reportsto {
    border-color: #238DC1;
    background: rgba(36, 142, 194, 0.05);
}

.field-overlay.field-currency {
    border-color: #20c997;
    background: rgba(32, 201, 151, 0.05);
}

.field-overlay.field-number {
    border-color: #6610f2;
    background: rgba(102, 16, 242, 0.05);
}

.field-label {
    padding: 0.25rem 0.5rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Resize Handle */
.resize-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: #238DC1;
    border: 1px solid white;
    border-radius: 2px;
    z-index: 30;
}

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

.resize-handle:hover {
    background: #0b5ed7;
}

/* Properties Panel */
.properties-panel {
    width: 300px;
    background: white;
    border-left: 1px solid #dee2e6;
    overflow-y: auto;
    padding: 1rem;
    flex-shrink: 0;
    /* Contain layout recalculations */
    contain: layout style;
}

.panel-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: #495057;
    margin-bottom: 1rem;
}

.property-group {
    margin-bottom: 1rem;
}

.property-group .form-label {
    margin-bottom: 0.25rem;
    color: #495057;
}

.property-group small {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.75rem;
}

/* Responsive adjustments */
@media (max-width: 1200px) {
    .field-palette {
        width: 240px;
    }
    
    .properties-panel {
        width: 260px;
    }
}

@media (max-width: 992px) {
    .editor-main {
        flex-direction: column;
    }
    
    .field-palette,
    .properties-panel {
        width: 100%;
        max-height: 250px;
    }
}

/* Scrollbar styling */
.field-palette::-webkit-scrollbar,
.properties-panel::-webkit-scrollbar,
.field-list::-webkit-scrollbar {
    width: 6px;
}

.field-palette::-webkit-scrollbar-track,
.properties-panel::-webkit-scrollbar-track,
.field-list::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.field-palette::-webkit-scrollbar-thumb,
.properties-panel::-webkit-scrollbar-thumb,
.field-list::-webkit-scrollbar-thumb {
    background: #adb5bd;
    border-radius: 3px;
}

.field-palette::-webkit-scrollbar-thumb:hover,
.properties-panel::-webkit-scrollbar-thumb:hover,
.field-list::-webkit-scrollbar-thumb:hover {
    background: #6c757d;
}

/* ── Dark mode ───────────────────────── */

[data-bs-theme="dark"] .editor-container {
    background: var(--dm-bg);
}

[data-bs-theme="dark"] .editor-toolbar {
    background: var(--dm-surface-raised);
    border-bottom-color: var(--dm-border);
}

[data-bs-theme="dark"] .field-palette,
[data-bs-theme="dark"] .properties-panel {
    background: var(--dm-surface);
    border-color: var(--dm-border);
}

[data-bs-theme="dark"] .palette-title,
[data-bs-theme="dark"] .panel-title {
    color: var(--dm-text);
}

[data-bs-theme="dark"] .palette-item {
    background: var(--dm-surface-raised);
    border-color: var(--dm-border);
    color: var(--dm-text);
}

[data-bs-theme="dark"] .palette-item:hover {
    background: rgba(36, 142, 194, 0.1);
    border-color: var(--brand-blue);
}

[data-bs-theme="dark"] .palette-item i {
    color: var(--brand-blue);
}

[data-bs-theme="dark"] .field-list-item {
    background: var(--dm-surface-raised);
    border-color: var(--dm-border);
    color: var(--dm-text);
}

[data-bs-theme="dark"] .field-list-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

[data-bs-theme="dark"] .field-list-item.selected {
    background: rgba(36, 142, 194, 0.12);
    border-color: var(--brand-blue);
}

[data-bs-theme="dark"] .canvas-container {
    background: #1a1e25;
}

/* PDF canvas itself stays light -- the white page
   becomes a natural focal point against dark chrome */
[data-bs-theme="dark"] canvas {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

[data-bs-theme="dark"] .field-overlay {
    color: #e0e3e8;
}

[data-bs-theme="dark"] .property-group .form-label {
    color: var(--dm-text-secondary);
}

[data-bs-theme="dark"] .field-palette hr {
    border-color: var(--dm-border);
}

/* Scrollbars */
[data-bs-theme="dark"] .field-palette::-webkit-scrollbar-track,
[data-bs-theme="dark"] .properties-panel::-webkit-scrollbar-track,
[data-bs-theme="dark"] .field-list::-webkit-scrollbar-track {
    background: transparent;
}

[data-bs-theme="dark"] .field-palette::-webkit-scrollbar-thumb,
[data-bs-theme="dark"] .properties-panel::-webkit-scrollbar-thumb,
[data-bs-theme="dark"] .field-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
}

[data-bs-theme="dark"] .field-palette::-webkit-scrollbar-thumb:hover,
[data-bs-theme="dark"] .properties-panel::-webkit-scrollbar-thumb:hover,
[data-bs-theme="dark"] .field-list::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}
