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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #f5f7fa;
    color: #333;
    line-height: 1.6;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

header {
    background: #fff;
    padding: 20px 30px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    margin-bottom: 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header h1 {
    color: #2563eb;
    font-size: 24px;
}

nav a {
    color: #666;
    text-decoration: none;
    padding: 8px 16px;
    border-radius: 6px;
    margin-left: 10px;
    transition: all 0.3s;
}

nav a:hover {
    background: #f0f0f0;
}

nav a.active {
    background: #2563eb;
    color: #fff;
}

.upload-section {
    background: #fff;
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    text-align: center;
}

.upload-section h2 {
    margin-bottom: 10px;
}

.hint {
    color: #666;
    margin-bottom: 30px;
}

.upload-area {
    border: 2px dashed #cbd5e1;
    border-radius: 12px;
    padding: 60px 40px;
    cursor: pointer;
    transition: all 0.3s;
}

.upload-area:hover {
    border-color: #2563eb;
    background: #f8fafc;
}

.upload-area.dragover {
    border-color: #2563eb;
    background: #eff6ff;
}

.upload-icon {
    width: 64px;
    height: 64px;
    margin-bottom: 20px;
    color: #94a3b8;
}

.upload-content p {
    font-size: 18px;
    color: #334155;
    margin-bottom: 8px;
}

.upload-hint {
    font-size: 14px;
    color: #94a3b8;
}

.status-message {
    margin-top: 20px;
    padding: 12px 20px;
    border-radius: 8px;
}

.status-message.success {
    background: #dcfce7;
    color: #166534;
}

.status-message.error {
    background: #fee2e2;
    color: #991b1b;
}

.status-message.info {
    background: #dbeafe;
    color: #1e40af;
}

/* Editor Styles */
.editor-container {
    display: flex;
    gap: 20px;
    height: calc(100vh - 150px);
}

.pdf-viewer {
    flex: 1;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    overflow: auto;
    position: relative;
}

.pdf-canvas-container {
    position: relative;
    display: inline-block;
    margin: 20px;
}

#pdfCanvas {
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

#fieldOverlay {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: auto;
}

.sidebar {
    width: 320px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    padding: 20px;
    overflow-y: auto;
}

.sidebar h3 {
    margin-bottom: 20px;
    color: #1e293b;
    font-size: 18px;
}

.tool-section {
    margin-bottom: 25px;
}

.tool-section h4 {
    font-size: 14px;
    color: #64748b;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s;
    text-decoration: none;
}

.btn-primary {
    background: #2563eb;
    color: #fff;
}

.btn-primary:hover {
    background: #1d4ed8;
}

.btn-secondary {
    background: #e2e8f0;
    color: #475569;
}

.btn-secondary:hover {
    background: #cbd5e1;
}

.btn-danger {
    background: #fee2e2;
    color: #991b1b;
}

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

.btn-success {
    background: #dcfce7;
    color: #166534;
}

.btn-success:hover {
    background: #bbf7d0;
}

.btn-block {
    width: 100%;
}

.btn + .btn {
    margin-top: 10px;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    font-size: 14px;
    color: #475569;
    margin-bottom: 6px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.3s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #2563eb;
}

.color-picker-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
}

.color-picker {
    width: 50px;
    height: 40px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

.color-value {
    font-size: 14px;
    color: #64748b;
    font-family: monospace;
}

.field-item {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 10px;
}

.field-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.field-item-name {
    font-weight: 500;
    color: #1e293b;
}

.field-item-actions {
    display: flex;
    gap: 8px;
}

.field-item-actions button {
    padding: 4px 8px;
    font-size: 12px;
}

.field-item-info {
    font-size: 12px;
    color: #94a3b8;
}

.empty-fields {
    text-align: center;
    padding: 40px 20px;
    color: #94a3b8;
}

.empty-fields svg {
    width: 48px;
    height: 48px;
    margin-bottom: 12px;
    opacity: 0.5;
}

/* Text Field Element */
.text-field {
    position: absolute;
    border: 2px solid #2563eb;
    background: rgba(37, 99, 235, 0.1);
    border-radius: 4px;
    cursor: move;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
}

.text-field.selected {
    border-color: #dc2626;
    background: rgba(220, 38, 38, 0.1);
}

.text-field-content {
    pointer-events: none;
    font-size: 14px;
    color: #333;
    padding: 4px 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: left;
    width: 100%;
    display: flex;
    align-items: center;
}

.text-field-resize {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    background: #2563eb;
    cursor: nwse-resize;
    border-radius: 0 0 4px 0;
}

.text-field-delete {
    position: absolute;
    top: -10px;
    right: -10px;
    width: 20px;
    height: 20px;
    background: #dc2626;
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Resize handles */
.resize-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: #fff;
    border: 2px solid #dc2626;
    border-radius: 2px;
    z-index: 10;
}

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

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

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

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

.text-field.selected .text-field-resize {
    background: #dc2626;
}

/* Modal Styles */
.modal-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: 1000;
}

.modal {
    background: #fff;
    border-radius: 12px;
    padding: 30px;
    min-width: 500px;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
}

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

.modal-header h2 {
    font-size: 20px;
    color: #1e293b;
}

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

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

/* Templates List */
.templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

.template-card {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    overflow: hidden;
    transition: transform 0.3s, box-shadow 0.3s;
}

.template-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}

.template-card-preview {
    height: 160px;
    background: #f1f5f9;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid #e2e8f0;
}

.template-card-preview svg {
    width: 64px;
    height: 64px;
    color: #cbd5e1;
}

.template-card-info {
    padding: 20px;
}

.template-card-info h3 {
    font-size: 16px;
    color: #1e293b;
    margin-bottom: 8px;
}

.template-card-info p {
    font-size: 13px;
    color: #94a3b8;
    margin-bottom: 15px;
}

.template-card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.template-card-actions .btn {
    flex: 1;
    min-width: 60px;
    font-size: 12px;
    padding: 6px 8px;
    white-space: nowrap;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #94a3b8;
}

.empty-state svg {
    width: 80px;
    height: 80px;
    margin-bottom: 20px;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 18px;
    color: #475569;
    margin-bottom: 10px;
}

/* Fill Form Modal */
.form-fields-list {
    max-height: 60vh;
    overflow-y: auto;
}

.form-field-item {
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 1px solid #e2e8f0;
}

.form-field-item:last-child {
    border-bottom: none;
}

.form-field-item label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: #1e293b;
    margin-bottom: 6px;
}

.form-field-item input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 14px;
}

.form-field-item input:focus {
    outline: none;
    border-color: #2563eb;
}

/* Loading */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: #64748b;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid #e2e8f0;
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 12px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Import Modal Styles */
#importModal .modal {
    min-width: 600px;
    max-width: 800px;
}

#importModal .templates-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}

#importModal .template-card {
    transition: all 0.2s;
}

#importModal .template-card:hover {
    border-color: #2563eb;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.15);
}
@media (max-width: 768px) {
    .editor-container {
        flex-direction: column;
        height: auto;
    }

    .sidebar {
        width: 100%;
    }

    .modal {
        min-width: auto;
        width: 90%;
        padding: 20px;
    }
}
