/* PDF2Database – Mobile-first styles */

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

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #ef4444;
    --success: #10b981;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-500: #6b7280;
    --gray-700: #374151;
    --gray-900: #111827;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-50);
    color: var(--gray-900);
    line-height: 1.5;
}

/* Layout */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
}

header {
    background: white;
    border-bottom: 1px solid var(--gray-200);
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

header h1 {
    font-size: 1.25rem;
    font-weight: 700;
}

header a {
    color: var(--gray-500);
    text-decoration: none;
    font-size: 0.875rem;
}

header a:hover {
    color: var(--primary);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
    text-decoration: none;
}

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

.btn-danger {
    background: var(--danger);
    color: white;
}
.btn-danger:hover {
    background: #dc2626;
}

.btn-success {
    background: var(--success);
    color: white;
}
.btn-success:hover {
    background: #059669;
}

.btn-outline {
    background: white;
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
}
.btn-outline:hover {
    background: var(--gray-100);
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

/* Cards */
.card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem;
}

/* Document list */
.doc-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.doc-card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.doc-card h3 {
    font-size: 1rem;
    font-weight: 600;
}

.doc-card .meta {
    font-size: 0.8125rem;
    color: var(--gray-500);
}

.doc-card .actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: auto;
}

/* Upload area */
.upload-area {
    border: 2px dashed var(--gray-300);
    border-radius: var(--radius);
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s;
}

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

/* PDF viewer */
.pdf-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding: 1rem 0;
}

.pdf-page-wrapper {
    position: relative;
    box-shadow: 0 2px 8px rgba(0,0,0,.15);
    background: white;
}

.pdf-page-wrapper canvas {
    display: block;
}

/* Editor-specific */
.editor-layout {
    display: flex;
    gap: 1rem;
    min-height: calc(100vh - 60px);
}

.editor-sidebar {
    width: 280px;
    flex-shrink: 0;
    background: white;
    border-left: 1px solid var(--gray-200);
    padding: 1rem;
    overflow-y: auto;
    position: sticky;
    top: 52px;
    max-height: calc(100vh - 52px);
}

.editor-main {
    flex: 1;
    overflow: auto;
}

.field-list-item {
    padding: 0.5rem;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    font-size: 0.8125rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}

.field-list-item:hover {
    background: var(--gray-50);
}

.field-list-item .field-type-badge {
    font-size: 0.75rem;
    padding: 0.125rem 0.375rem;
    border-radius: 4px;
    color: white;
    font-weight: 500;
}

/* Runtime fields overlay */
.runtime-field {
    position: absolute;
    z-index: 10;
    border: 2px solid transparent;
    border-radius: 4px;
    transition: border-color 0.15s;
}

.runtime-field:focus-within {
    border-color: var(--primary);
}

.runtime-field input[type="text"],
.runtime-field input[type="date"] {
    width: 100%;
    height: 100%;
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    padding: 0.25rem 0.5rem;
    font-size: 14px;
    background: rgba(255, 255, 255, 0.9);
}

.runtime-field input[type="checkbox"] {
    width: 24px;
    height: 24px;
    cursor: pointer;
}

.runtime-field .photo-upload {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.9);
    border: 1px dashed var(--gray-300);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.75rem;
    color: var(--gray-500);
    overflow: hidden;
}

.runtime-field .photo-upload img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.runtime-field .signature-pad-container {
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    position: relative;
}

.runtime-field .signature-pad-container canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.runtime-field .sig-clear {
    position: absolute;
    top: 2px;
    right: 2px;
    font-size: 0.625rem;
    padding: 1px 4px;
    background: var(--gray-200);
    border: none;
    border-radius: 3px;
    cursor: pointer;
    z-index: 5;
}

/* Modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal {
    background: white;
    border-radius: var(--radius);
    padding: 1.5rem;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,.2);
}

.modal h2 {
    font-size: 1.125rem;
    margin-bottom: 1rem;
}

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

.form-group label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
    color: var(--gray-700);
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.875rem;
}

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

/* Toolbar */
.toolbar {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
    padding: 0.5rem 0;
}

.toolbar .spacer {
    flex: 1;
}

/* Toast notifications */
.toast {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius);
    color: white;
    font-size: 0.875rem;
    z-index: 9999;
    animation: slideIn 0.3s ease;
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }

@keyframes slideIn {
    from { transform: translateY(1rem); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* Responsive */
@media (max-width: 768px) {
    .editor-layout {
        flex-direction: column;
    }

    .editor-sidebar {
        width: 100%;
        position: static;
        max-height: none;
        order: -1;
    }

    .doc-grid {
        grid-template-columns: 1fr;
    }
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--gray-500);
}

.empty-state svg {
    width: 64px;
    height: 64px;
    margin-bottom: 1rem;
    opacity: 0.5;
}
