/* SaaS Design System - PDF Form Service */
:root {
    --bg: #f5f6fa;
    --card: #fff;
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --danger: #ef4444;
    --success: #48c78e;
    --warning: #f59e0b;
    --text: #1a1a2e;
    --text-muted: #64748b;
    --border: #e2e4e9;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font-sans); background: var(--bg); color: var(--text); line-height: 1.5; }

/* Layout */
header { background: var(--card); padding: 12px 24px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); box-shadow: var(--shadow); }
header h1 { font-size: 1.25rem; font-weight: 700; color: var(--primary); }
header nav { display: flex; gap: 12px; align-items: center; }
header .spacer { flex: 1; }
nav button { padding: 8px 16px; border: 1px solid var(--border); background: var(--card); border-radius: var(--radius); cursor: pointer; font-size: 0.9rem; transition: all 0.2s; }
nav button:hover { background: var(--bg); }
nav button.btn-secondary { color: var(--text-muted); }
nav button.btn-secondary:hover { border-color: var(--danger); color: var(--danger); }

main { max-width: 1400px; margin: 0 auto; padding: 24px; }
.view { animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.hidden { display: none !important; }

/* Cards */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; border: 1px solid var(--border); box-shadow: var(--shadow); }
.card-body strong { display: block; }
.card-body code { color: var(--primary); font-size: 0.9em; }
.badge { background: var(--bg); padding: 2px 8px; border-radius: 12px; font-size: 0.8em; color: var(--text-muted); }
.card-actions { display: flex; gap: 8px; }
.card-actions button { padding: 6px 12px; border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; background: var(--card); color: var(--text); font-size: 0.85em; }
.card-actions button.danger { color: var(--danger); border-color: var(--danger); }

/* Forms */
.form-group { margin: 12px 0; }
.form-group label { display: block; margin-bottom: 6px; font-size: 0.9rem; color: var(--text-muted); font-weight: 500; }
.form-group input { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 1rem; transition: border-color 0.2s; }
.form-group input:focus { outline: none; border-color: var(--primary); }
.form-group input:disabled { background: var(--bg); cursor: not-allowed; }

/* Buttons */
.btn { padding: 10px 20px; border: none; border-radius: var(--radius); cursor: pointer; font-size: 1rem; font-weight: 600; transition: all 0.2s; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { background: var(--card); color: var(--primary); border: 1px solid var(--primary); }
.btn-secondary:hover { background: rgba(59,130,246,0.05); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #3db580; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-large { width: 100%; padding: 16px; font-size: 1.1rem; margin-top: 12px; }
.btn-icon { display: flex; align-items: center; gap: 6px; }
.icon-btn { background: none; border: none; cursor: pointer; font-size: 1.2rem; padding: 8px; border-radius: 4px; }
.icon-btn:hover { background: var(--bg); }

/* Auth Pages */
.auth-card { max-width: 400px; margin: 80px auto; padding: 40px; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow-lg); text-align: center; }
.auth-card h2 { margin-bottom: 8px; }
.auth-card .subtitle { color: var(--text-muted); margin-bottom: 24px; }
.auth-card form { text-align: left; }
.auth-help { margin-top: 16px; color: var(--text-muted); font-size: 0.9rem; }
.auth-help a { color: var(--primary); }

/* Dashboard */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--card); padding: 24px; border-radius: var(--radius); text-align: center; border: 1px solid var(--border); }
.stat-number { display: block; font-size: 2.5rem; font-weight: 700; color: var(--primary); margin-bottom: 8px; }
.stat-label { color: var(--text-muted); font-size: 0.9rem; }
.recent-actions { margin-top: 32px; }
.action-buttons { display: flex; gap: 12px; margin-top: 16px; }

/* Template/Envelope Lists */
.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }

/* Signing Ceremony */
.signing-header { text-align: center; margin-bottom: 24px; }
.signing-header h2 { font-size: 1.5rem; margin-bottom: 12px; }
.signing-progress { display: flex; justify-content: center; gap: 24px; }
.step { color: var(--text-muted); font-size: 0.9rem; }
.step.active { color: var(--primary); font-weight: 700; }
.step::after { content: '→'; margin-left: 12px; color: var(--border); }
.step:last-child::after { content: ''; }

.signing-layout { display: grid; grid-template-columns: 280px 1fr; gap: 24px; }
.signing-sidebar { background: var(--card); padding: 16px; border-radius: var(--radius); border: 1px solid var(--border); }
.signing-sidebar h3 { margin-bottom: 12px; }
.from-label { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 8px; }
.envelope-message { background: var(--bg); padding: 12px; border-radius: var(--radius); font-size: 0.9rem; margin-bottom: 16px; }

.signing-main { display: flex; flex-direction: column; gap: 16px; }
#pdf-viewer { overflow: auto; background: #fff; border-radius: var(--radius); border: 1px solid var(--border); }
#pdf-canvas-wrapper { position: relative; display: inline-block; min-width: 100%; }
#pdf-page-img { display: block; width: 100%; }
#field-overlays { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
.signing-page-image { display: block; width: 100%; }
.signature-field { position: absolute; border: 2px dashed var(--primary); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.2s; }
.signature-field:hover { background: rgba(59,130,246,0.1); }
.signature-field.active { background: rgba(59,130,246,0.2); border-color: var(--primary-dark); }
.field-label { color: var(--text-muted); font-size: 0.8rem; }
.field-icon { position: absolute; right: 8px; }

.signature-pad-container { background: var(--card); padding: 16px; border-radius: var(--radius); border: 1px solid var(--border); text-align: center; }
.signature-canvas { border: 1px solid var(--border); border-radius: var(--radius); cursor: crosshair; touch-action: none; }
.signature-tools { display: flex; justify-content: center; gap: 12px; margin-top: 12px; }

.signing-controls { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }

/* Settings */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.settings-section { background: var(--card); padding: 20px; border-radius: var(--radius); border: 1px solid var(--border); }
.settings-section h3 { margin-bottom: 16px; }

.dropzone { border: 2px dashed var(--text-muted); border-radius: var(--radius); padding: 60px; text-align: center; cursor: pointer; margin: 16px 0; transition: border-color 0.2s; }
.dropzone:hover, .dropzone.drag-over { border-color: var(--primary); }
.muted { color: var(--text-muted); font-size: 0.9rem; }

/* Loading */
.loading-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.spinner { width: 48px; height: 48px; border: 4px solid rgba(255,255,255,0.3); border-radius: 50%; border-top-color: #fff; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay p { color: #fff; margin-top: 16px; font-size: 1.1rem; }

/* Completion Screen */
.completion-screen { text-align: center; padding: 60px 24px; background: var(--card); border-radius: var(--radius); max-width: 500px; margin: 60px auto; box-shadow: var(--shadow-lg); }
.completion-icon { width: 80px; height: 80px; background: var(--success); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 2.5rem; color: #fff; margin: 0 auto 24px; }

/* Toast Notifications */
.toast-container { position: fixed; top: 24px; right: 24px; z-index: 1000; }
.toast { background: var(--card); padding: 16px 24px; border-radius: var(--radius); margin-bottom: 12px; box-shadow: var(--shadow-lg); border-left: 4px solid var(--primary); animation: slideIn 0.3s ease; }
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Responsive */
@media (max-width: 1024px) {
    .signing-layout { grid-template-columns: 1fr; }
    .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    header { padding: 12px; flex-wrap: wrap; }
    header h1 { width: 100%; margin-bottom: 8px; }
    header nav { width: 100%; justify-content: space-between; flex-wrap: wrap; }
    header nav button { flex: 1; min-width: 80px; }
    main { padding: 12px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .signing-progress { gap: 12px; }
    .step { font-size: 0.8rem; }
    .step::after { margin-left: 6px; }
}

/* Utilities */
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }

/* Preformatted */
pre { background: #1a1a2e; color: #e2e4e9; padding: 16px; border-radius: var(--radius); overflow-x: auto; font-size: 0.85em; margin: 12px 0; }
pre code { font-family: 'SF Mono', 'Fira Code', monospace; }

/* Drag & Drop */
.drag-over { outline: 3px dashed var(--primary); outline-offset: 2px; }
.field-palette { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 16px; }
.field-palette h4 { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 8px; }
.field-palette-item { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px dashed var(--border); border-radius: var(--radius); cursor: grab; font-size: 0.9rem; background: var(--bg); transition: all 0.2s; }
.field-palette-item:hover { border-color: var(--primary); background: rgba(59,130,246,0.05); }
.field-palette-item:active { cursor: grabbing; opacity: 0.6; }
.palette-icon { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; background: var(--primary); color: #fff; border-radius: 4px; font-size: 0.75em; font-weight: bold; }
.field-overlay.positioned-text { border: 2px dashed var(--primary); background: rgba(59,130,246,0.15) !important; cursor: move; }
.field-overlay.positioned-text.selected { background: rgba(59,130,246,0.3) !important; }
.field-overlay.dragging { border: 3px dotted var(--danger); background: rgba(239,68,68,0.15) !important; z-index: 10; }

/* Config Layout (for template editor) */
.config-layout { display: grid; grid-template-columns: 120px 1fr 300px; gap: 16px; height: calc(100vh - 100px); }
#page-thumbnails { overflow-y: auto; }
.thumb { margin-bottom: 8px; cursor: pointer; border: 2px solid transparent; border-radius: 4px; overflow: hidden; }
.thumb.active { border-color: var(--primary); }
.thumb img { width: 100%; display: block; }
.thumb span { display: block; text-align: center; font-size: 0.8em; color: var(--text-muted); }

/* Field List & Editor */
#field-panel { overflow-y: auto; }
#field-panel h3 { margin-bottom: 8px; }
.field-item { padding: 8px 12px; border-radius: var(--radius); cursor: pointer; border: 1px solid var(--border); margin-bottom: 4px; background: var(--card); }
.field-item:hover { background: var(--bg); }
.field-item.active { border-color: var(--primary); background: rgba(59,130,246,0.08); }

#field-editor { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-top: 12px; }
#field-editor label { display: block; margin-bottom: 8px; font-size: 0.9rem; }
#field-editor input, #field-editor select { width: 100%; padding: 6px 10px; border: 1px solid var(--border); border-radius: 4px; margin-top: 2px; }
#field-editor button { margin-top: 8px; width: 100%; }

/* Error Banner */
.error-banner { position: fixed; top: 24px; left: 50%; transform: translateX(-50%); background: var(--danger); color: #fff; padding: 12px 24px; border-radius: var(--radius); z-index: 1000; box-shadow: var(--shadow-lg); }

/* Summary View */
#summary-content { max-width: 800px; margin: 0 auto; background: var(--card); padding: 24px; border-radius: var(--radius); border: 1px solid var(--border); }
#summary-content h3 { margin-bottom: 16px; color: var(--primary); }
#summary-content pre { margin-top: 16px; }
.h4 { margin-top: 24px; margin-bottom: 8px; font-size: 1rem; }
.code-block { background: #1a1a2e; color: #e2e4e9; padding: 16px; border-radius: var(--radius); overflow-x: auto; font-size: 0.85em; margin: 12px 0; }
.code-block code { font-family: 'SF Mono', 'Fira Code', monospace; }

/* Overlay Labels */
.overlay-label { font-size: 0.55em; color: #333; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none; }
.field-overlay { position: absolute; border: 1px solid rgba(0,0,0,0.3); cursor: pointer; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.field-overlay:hover { border: 2px solid var(--primary); }
.field-overlay.selected { border: 2px solid var(--primary); background: rgba(59,130,246,0.3) !important; }

/* No Signature Fields */
.no-signature-fields { text-align: center; color: var(--text-muted); padding: 40px; }

/* Back Button */
.btn-back { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 1rem; padding: 8px 16px; border-radius: var(--radius); }
.btn-back:hover { background: var(--bg); color: var(--text); }
