/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
}

/* Navigation */
.navbar {
    background: #2c3e50;
    color: white;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.nav-brand h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

.nav-menu {
    display: flex;
    gap: 2rem;
}

.nav-link {
    color: white;
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    transition: background-color 0.3s;
}

.nav-link:hover,
.nav-link.active {
    background-color: #34495e;
}

/* Main Content */
.main-content {
    min-height: calc(100vh - 80px);
    padding: 2rem;
}

/* Pages */
.page {
    display: none;
}

.page.active {
    display: block;
}

/* Page Header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.page-header h2 {
    color: #2c3e50;
    font-size: 2rem;
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.3s;
}

.btn-primary {
    background-color: #3498db;
    color: white;
}

.btn-primary:hover {
    background-color: #2980b9;
}

.btn-secondary {
    background-color: #95a5a6;
    color: white;
}

.btn-secondary:hover {
    background-color: #7f8c8d;
}

.btn-danger {
    background-color: #e74c3c;
    color: white;
}

.btn-danger:hover {
    background-color: #c0392b;
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #2c3e50;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

/* Login Page */
.login-container {
    max-width: 400px;
    margin: 2rem auto;
    background: white;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.login-container h2 {
    text-align: center;
    margin-bottom: 2rem;
    color: #2c3e50;
}

/* Templates Grid */
.templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 2rem;
}

/* Users Grid */
.users-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 2rem;
}

.template-card {
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: transform 0.3s, box-shadow 0.3s;
}

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

.template-card h3 {
    color: #2c3e50;
    margin-bottom: 1rem;
}

.template-meta {
    color: #7f8c8d;
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.template-actions {
    display: flex;
    gap: 0.5rem;
}

.template-actions .btn {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
}

/* User Cards */
.user-card {
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: transform 0.3s, box-shadow 0.3s;
    text-align: center;
}

.user-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.user-avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3498db, #2980b9);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem auto;
    color: white;
    font-size: 1.5rem;
}

.user-card h3 {
    color: #2c3e50;
    margin-bottom: 1rem;
}

.user-meta {
    color: #7f8c8d;
    font-size: 0.9rem;
    margin-bottom: 1rem;
    text-align: left;
}

.user-meta div {
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.user-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: center;
}

.user-actions .btn {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
}

.text-success {
    color: #27ae60 !important;
}

.text-danger {
    color: #e74c3c !important;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
}

.modal-content {
    background-color: white;
    margin: 10% auto;
    padding: 2rem;
    border-radius: 8px;
    width: 80%;
    max-width: 500px;
    position: relative;
}

.close {
    position: absolute;
    right: 1rem;
    top: 1rem;
    font-size: 2rem;
    cursor: pointer;
    color: #7f8c8d;
}

.close:hover {
    color: #2c3e50;
}

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

.editor-sidebar {
    width: 300px;
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    overflow-y: auto;
}

.editor-sidebar h3 {
    color: #2c3e50;
    margin-bottom: 1rem;
}

.editor-canvas {
    flex: 1;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
}

.canvas-toolbar {
    padding: 1rem;
    border-bottom: 1px solid #ecf0f1;
    display: flex;
    gap: 1rem;
    align-items: center;
    justify-content: space-between;
}

.canvas-toolbar select {
    width: auto;
    max-width: 200px;
}

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

#page-counter {
    font-weight: 600;
    color: #2c3e50;
    padding: 0.5rem 1rem;
    background: #ecf0f1;
    border-radius: 4px;
    min-width: 120px;
    text-align: center;
}

#pdf-viewer {
    flex: 1;
    padding: 1rem;
    overflow: auto;
    position: relative;
}

/* Field List */
.field-item {
    background: #f8f9fa;
    border: 1px solid #ecf0f1;
    border-radius: 4px;
    padding: 1rem;
    margin-bottom: 1rem;
    position: relative;
}

.field-item h4 {
    color: #2c3e50;
    margin-bottom: 0.5rem;
}

.field-item .field-meta {
    color: #7f8c8d;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.field-item .field-actions {
    display: flex;
    gap: 0.5rem;
}

.field-item .field-actions .btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
}

/* Field Properties Panel */
.field-properties {
    margin-top: 2rem;
    padding: 1.5rem;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #ecf0f1;
}

.field-properties h3 {
    color: #2c3e50;
    margin-bottom: 1rem;
    border-bottom: 2px solid #3498db;
    padding-bottom: 0.5rem;
}

.field-properties h4 {
    color: #2c3e50;
    margin: 1.5rem 0 1rem 0;
    font-size: 1.1rem;
}

.field-properties .form-group {
    margin-bottom: 1rem;
}

.field-properties .form-group label {
    display: block;
    margin-bottom: 0.3rem;
    font-weight: 500;
    color: #2c3e50;
    font-size: 0.9rem;
}

.field-properties .form-group input,
.field-properties .form-group select {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
}

.field-properties .form-group input[type="checkbox"] {
    width: auto;
    margin-right: 0.5rem;
}

.field-properties .form-group input[type="color"] {
    width: 60px;
    height: 35px;
    padding: 2px;
    border-radius: 4px;
}

.field-properties .form-actions {
    margin-top: 1.5rem;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.field-properties .form-actions .btn {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
}

/* PDF Canvas */
.pdf-canvas {
    position: relative;
    margin: 0 auto;
    display: block;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.field-overlay {
    position: absolute;
    border: 2px dashed #3498db;
    background: rgba(52, 152, 219, 0.1);
    cursor: move;
    min-width: 20px;
    min-height: 20px;
    user-select: none;
    transition: all 0.2s ease;
}

.field-overlay:hover {
    border-color: #2980b9;
    background: rgba(52, 152, 219, 0.2);
}

.field-overlay.selected {
    border-color: #e74c3c;
    background: rgba(231, 76, 60, 0.1);
}

.field-overlay.dragging {
    opacity: 0.8;
    z-index: 1000;
    transform: rotate(1deg) scale(1.02);
    box-shadow: 0 8px 20px rgba(0,0,0,0.4);
    border-style: solid;
    border-color: #27ae60;
    background: rgba(39, 174, 96, 0.2);
    transition: none !important;
}

.field-overlay.resizing {
    opacity: 0.8;
    z-index: 1000;
    transform: scale(1.01);
    box-shadow: 0 6px 16px rgba(0,0,0,0.3);
    border-color: #f39c12;
    background: rgba(243, 156, 18, 0.2);
    transition: none !important;
}

.field-label {
    position: absolute;
    top: -20px;
    left: 0;
    background: #3498db;
    color: white;
    padding: 2px 6px;
    font-size: 10px;
    border-radius: 3px;
    white-space: nowrap;
    pointer-events: none;
}

.field-overlay.selected .field-label {
    background: #e74c3c;
}

.field-overlay.dragging .field-label {
    background: #27ae60;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.field-overlay.resizing .field-label {
    background: #f39c12;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.resize-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: #3498db;
    border: 1px solid white;
}

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

.field-overlay.selected .resize-handle {
    background: #e74c3c;
}

/* API Tester */
.api-tester-container {
    max-width: 800px;
    margin: 0 auto;
}

.api-section {
    background: white;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.api-section h3 {
    color: #2c3e50;
    margin-bottom: 1.5rem;
}

#field-values {
    font-family: 'Courier New', monospace;
    resize: vertical;
}

#api-result {
    margin-top: 2rem;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 4px;
    border-left: 4px solid #3498db;
    display: none;
}

#api-result.success {
    border-left-color: #27ae60;
    background: #d5f4e6;
}

#api-result.error {
    border-left-color: #e74c3c;
    background: #fadbd8;
}

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

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 2rem;
    right: 2rem;
    z-index: 10000;
}

.toast {
    background: white;
    border-left: 4px solid #3498db;
    padding: 1rem;
    margin-bottom: 0.5rem;
    border-radius: 4px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    min-width: 300px;
    opacity: 0;
    transform: translateX(100%);
    transition: all 0.3s ease;
}

.toast.show {
    opacity: 1;
    transform: translateX(0);
}

.toast.success {
    border-left-color: #27ae60;
}

.toast.error {
    border-left-color: #e74c3c;
}

.toast.info {
    border-left-color: #3498db;
}

.toast.warning {
    border-left-color: #f39c12;
}

/* Responsive Design */
@media (max-width: 768px) {
    .navbar {
        flex-direction: column;
        gap: 1rem;
    }
    
    .nav-menu {
        width: 100%;
        justify-content: center;
    }
    
    .main-content {
        padding: 1rem;
    }
    
    .templates-grid {
        grid-template-columns: 1fr;
    }
    
    .editor-container {
        flex-direction: column;
        height: auto;
    }
    
    .editor-sidebar {
        width: 100%;
    }
    
    .page-header {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }
    
    .template-actions {
        flex-wrap: wrap;
    }
    
    .modal-content {
        width: 95%;
        margin: 5% auto;
    }
}

@media (max-width: 480px) {
    .nav-menu {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .nav-link {
        text-align: center;
    }
    
    .canvas-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    
    .canvas-toolbar select {
        max-width: none;
    }
}