/* static/css/style.css */
:root {
    --primary-color: #0d6efd;
    --secondary-color: #6c757d;
    --background-color: #f8f9fa;
    --surface-color: #ffffff;
    --text-color: #212529;
    --border-color: #dee2e6;
    --error-color: #dc3545;
    --success-color: #198754;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
body {
    font-family: var(--font-family);
    background-color: var(--background-color);
    color: var(--text-color);
    margin: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}
nav {
    background-color: var(--surface-color);
    padding: 1rem 2rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}
nav .brand {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-color);
    text-decoration: none;
}
nav .nav-links a {
    color: var(--secondary-color);
    text-decoration: none;
    margin-left: 1.5rem;
    font-weight: 500;
    transition: color 0.2s;
}
nav .nav-links a:hover { color: var(--primary-color); }

.container {
    flex: 1;
    width: 100%;
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 2rem;
}
footer {
    text-align: center;
    padding: 1.5rem;
    background-color: var(--surface-color);
    border-top: 1px solid var(--border-color);
    margin-top: auto;
    color: var(--secondary-color);
}
.template-title-display { color: var(--primary-color); }

/* Forms & Buttons */
.button {
    display: inline-block;
    padding: 0.6rem 1.2rem;
    border: 1px solid var(--border-color);
    border-radius: 0.3rem;
    text-decoration: none;
    cursor: pointer;
    font-weight: 500;
    background-color: var(--surface-color);
    color: var(--text-color);
    transition: background-color 0.2s, border-color 0.2s;
}
.button.primary {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}
.button.danger {
    background-color: var(--error-color);
    color: white;
    border-color: var(--error-color);
}
.button:hover { background-color: #e9ecef; }
.button.primary:hover { background-color: #0b5ed7; border-color: #0a58ca; }
.button.danger:hover { background-color: #bb2d3b; border-color: #b02a37; }
.button:disabled { background-color: #e9ecef; cursor: not-allowed; opacity: 0.7; }

.form-container {
    background: var(--surface-color);
    padding: 2rem;
    border-radius: 0.5rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    max-width: 600px;
    margin: 2rem auto;
}
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.5rem; font-weight: 500; }
.form-group input[type="text"],
.form-group input[type="file"],
.form-group select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 0.3rem;
    box-sizing: border-box;
}
input:invalid { border-color: var(--error-color); }

/* PDF Viewer */
#pdf-viewer {
    border: 1px solid var(--border-color);
    background: #e9ecef;
    padding: 1rem;
}
.pdf-page {
    position: relative;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    margin: 0 auto 1.5rem auto;
    max-width: 850px;
    user-select: none; /* Prevent text selection during drag */
}
.pdf-page img {
    display: block;
    width: 100%;
    height: auto;
}

/* Template Editor Fields */
.field-overlay {
    position: absolute;
    border: 2px dashed var(--primary-color);
    box-sizing: border-box;
    cursor: move;
    background-color: rgba(13, 110, 253, 0.2);
}
.field-overlay.selected {
    border-style: solid;
    z-index: 10;
}
.field-overlay .field-label {
    position: absolute;
    top: -22px;
    left: -2px;
    background-color: var(--primary-color);
    color: white;
    padding: 2px 6px;
    font-size: 11px;
    border-radius: 3px;
    font-weight: 500;
    white-space: nowrap;
}
.field-overlay .delete-handle {
    position: absolute;
    top: -10px;
    right: -10px;
    width: 20px;
    height: 20px;
    background: var(--error-color);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    line-height: 20px;
    display: none; /* Hidden by default */
}
.field-overlay.selected .delete-handle {
    display: flex;
}
.field-overlay .resize-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: var(--primary-color);
    border: 1px solid white;
    border-radius: 50%;
    display: none; /* Hidden by default */
}
.field-overlay.selected .resize-handle {
    display: block;
}
.resize-handle.br {
    bottom: -5px;
    right: -5px;
    cursor: nwse-resize;
}

/* Document Filler Fields */
.filler-field {
    position: absolute;
    box-sizing: border-box;
    background-color: rgba(255, 255, 0, 0.2);
    border: 1px solid #cccc00;
    transition: background-color 0.2s;
}
.filler-field:hover { background-color: rgba(255, 255, 0, 0.3); }
.filler-field .filler-label {
    position: absolute;
    top: -18px;
    left: 0;
    font-size: 11px;
    color: var(--secondary-color);
}
.filler-field input[type="text"] {
    width: 100%; height: 100%; border: none;
    padding: 4px; background: transparent; font-size: 14px;
}
.filler-field input[type="checkbox"] { transform: scale(1.5); margin: 4px; }
.filler-field .sig-placeholder {
    width: 100%; height: 100%; display: flex;
    align-items: center; justify-content: center;
    color: var(--secondary-color); font-style: italic; cursor: pointer;
    background-color: rgba(0,0,0,0.02);
}
.filler-field img { width: 100%; height: 100%; object-fit: contain; cursor: pointer; }

/* Modal */
.modal {
    position: fixed; z-index: 1000; left: 0; top: 0;
    width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.5);
    display: flex; align-items: center; justify-content: center;
}
.modal-content {
    background-color: var(--surface-color); padding: 2rem;
    border-radius: 5px; width: 90%; max-width: 500px; position: relative;
}
.close-button {
    position: absolute; top: 10px; right: 15px;
    font-size: 28px; font-weight: bold; cursor: pointer;
}

/* Signature Pad */
#sig-canvas { border: 1px solid var(--border-color); cursor: crosshair; background: #fff; }
.sig-tabs { border-bottom: 1px solid var(--border-color); margin-bottom: 1rem; }
.sig-tabs .tab-link { background: none; border: none; padding: 10px 15px; cursor: pointer; font-weight: 500; color: var(--secondary-color); }
.sig-tabs .tab-link.active { color: var(--primary-color); border-bottom: 2px solid var(--primary-color); }
.tab-content { display: none; padding-top: 10px; }
.tab-content.active { display: block; }
#sig-text-render {
    border: 1px solid var(--border-color); min-height: 150px; padding: 10px;
    font-family: 'Cedarville Cursive', cursive; font-size: 2.5rem;
}
.modal-actions { margin-top: 1.5rem; text-align: right; }

/* Flash Messages */
.flash { padding: 1rem; margin: 0 auto 1rem auto; border-radius: 0.25rem; max-width: 1200px; }
.flash.success { background-color: #d1e7dd; color: #0f5132; }
.flash.error { background-color: #f8d7da; color: #842029; }

/* Template List */
.template-list ul { list-style: none; padding: 0; }
.template-list li {
    display: flex; justify-content: space-between; align-items: center;
    padding: 1.2rem; background: var(--surface-color);
    margin-bottom: 0.5rem; border-radius: 0.3rem;
    border: 1px solid var(--border-color);
}
.template-list li a {
    display: flex; justify-content: space-between; align-items: center;
    text-decoration: none; color: var(--text-color);
    flex-grow: 1; transition: transform 0.2s;
}
.template-list li a:hover { transform: translateX(5px); }
.template-list .template-name { font-weight: 500; }
.template-list .template-date { color: var(--secondary-color); font-size: 0.9rem; margin-left: 1rem; }
#manage-template-list .template-info { flex-grow: 1; }
