
html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

body {
    background: #f8f9fa;
    min-height: 100vh;
}

#appRoot {
    display: none;
}

.login-overlay {
    position: fixed;
    inset: 0;
    z-index: 12000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background:
        radial-gradient(circle at 15% 15%, rgba(32, 119, 190, 0.2), transparent 34%),
        radial-gradient(circle at 85% 85%, rgba(0, 91, 170, 0.2), transparent 34%),
        linear-gradient(135deg, #f4f8ff 0%, #eaf2ff 100%);
}

.login-card {
    width: min(460px, 100%);
    background: #ffffff;
    border: 1px solid #d9e6fb;
    border-radius: 16px;
    box-shadow: 0 28px 55px rgba(16, 41, 84, 0.2);
    padding: 24px 24px 20px;
}

.login-card-head h2 {
    margin: 0;
    font-size: 22px;
    color: #0f3b72;
    font-weight: 800;
}

.login-card-head p {
    margin: 8px 0 0;
    color: #5d7293;
    font-size: 13px;
}

.login-form {
    margin-top: 16px;
}

.login-form .form-label {
    font-size: 13px;
    color: #37557d;
    margin-bottom: 6px;
}

.login-submit-btn {
    margin-top: 4px;
    font-weight: 700;
    padding: 10px 14px;
    border-radius: 10px;
}

.login-error {
    background: #fff1f3;
    border: 1px solid #ffccd5;
    color: #b42345;
    border-radius: 10px;
    padding: 8px 10px;
    font-size: 12px;
    margin-bottom: 10px;
}

.login-help {
    border-top: 1px dashed #d8e4f7;
    padding-top: 10px;
    text-align: center;
    color: #6c7f9b;
}

.container-fluid {
    min-height: 100vh;
    padding: 0;
}

.main-row {
    min-height: 100vh;
}

.edit-col {
    background: #fff;
    border-right: 1px solid #e0e0e0;
    padding: 20px 30px;
    overflow-y: auto;
    max-height: 100vh;
}

.preview-col {
    background: #f4f4f4;
    padding: 30px 20px;
    overflow-y: auto;
    max-height: 100vh;
    display: flex;
    align-items: flex-start;
    justify-content: center;
}

.page-header {
    position: relative;
    margin-bottom: 30px;
    padding-bottom: 15px;
    border-bottom: 2px solid #005baa;
}

.page-title {
    font-weight: bold;
    font-size: 22px;
    color: #005baa;
    margin: 0;
}

.header-actions {
    position: absolute;
    top: 0;
    right: 0;
    display: flex;
    gap: 10px;
}

.btn-primary-custom {
    background: linear-gradient(90deg, #1976d2, #2196f3);
    color: #fff;
    border: none;
    padding: 8px 20px;
    border-radius: 6px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(33, 150, 243, 0.22);
    transition: all 0.2s;
}

.btn-primary-custom:hover {
    background: linear-gradient(90deg, #1565c0, #1976d2);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.3);
}

.btn-danger-custom {
    background: linear-gradient(90deg, #d32f2f, #f44336);
    color: #fff;
    border: none;
    padding: 8px 20px;
    border-radius: 6px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(244, 67, 54, 0.22);
    transition: all 0.2s;
}

.btn-danger-custom:hover {
    background: linear-gradient(90deg, #c62828, #d32f2f);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(244, 67, 54, 0.3);
}

.template-selector {
    margin-bottom: 30px;
}

.template-selector label {
    font-weight: 600;
    color: #333;
    margin-bottom: 8px;
}

.template-selector select {
    font-size: 15px;
    padding: 10px 15px;
    border-radius: 6px;
    border: 1px solid #ddd;
    transition: all 0.2s;
}

.template-selector select:focus {
    border-color: #1976d2;
    box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.1);
    outline: none;
}

.template-tools {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.stamp-signature-card {
    border: none;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
}

.stamp-signature-header {
    background: linear-gradient(120deg, #005baa, #2a7fd4);
    color: #fff;
    font-weight: 700;
    font-size: 15px;
    border: none;
}

.stamp-signature-toggle {
    width: 28px;
    height: 28px;
    padding: 0;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
}

.stamp-signature-toggle i {
    transition: transform 0.2s ease;
}

.stamp-signature-toggle[aria-expanded="false"] i {
    transform: rotate(180deg);
}

.control-block {
    border: 1px solid #e9eef5;
    border-radius: 10px;
    padding: 14px;
    background: #fafcff;
}

.control-title {
    color: #223047;
    font-weight: 700;
    font-size: 14px;
}

.generator-box {
    background: #f4f8ff;
    border: 1px dashed #b9d5ff;
    border-radius: 8px;
    padding: 10px;
}

.field-group-card {
    border: none;
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 25px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
}

.field-group-card:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

.field-group-header {
    padding: 16px 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    user-select: none;
    border: none;
}

.field-group-common {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.field-group-common:hover {
    background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
}

.field-group-specific {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
}

.field-group-specific:hover {
    background: linear-gradient(135deg, #e082ea 0%, #e4465a 100%);
}

.field-group-title {
    font-weight: 600;
    font-size: 16px;
    letter-spacing: 0.3px;
}

.field-group-subtitle {
    font-size: 13px;
    opacity: 0.9;
    font-weight: 400;
}

.field-group-icon {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 14px;
    display: inline-block;
    width: 16px;
    text-align: center;
}

.field-group-icon.collapsed {
    transform: rotate(-90deg);
}

.field-group-card .card-body {
    padding: 25px;
    background: #fff;
}

.field-group-card .badge {
    font-size: 12px;
    padding: 6px 12px;
    border-radius: 12px;
    font-weight: 500;
}

.form-label {
    font-weight: 600;
    color: #444;
    margin-bottom: 6px;
    font-size: 14px;
}

.form-control {
    padding: 10px 14px;
    border-radius: 6px;
    border: 1px solid #ddd;
    font-size: 14px;
    transition: all 0.2s;
}

.form-select {
    border-radius: 6px;
    border: 1px solid #ddd;
    transition: all 0.2s;
}

.form-select:focus {
    border-color: #1976d2;
    box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.1);
    outline: none;
}

.form-control:focus {
    border-color: #1976d2;
    box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.1);
    outline: none;
}

.form-control-sm {
    border-radius: 6px;
}

.field-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 6px;
    gap: 10px;
}

.field-visibility-toggle {
    font-size: 13px;
    line-height: 1;
    opacity: 0.55;
    transition: opacity 0.15s;
    flex-shrink: 0;
}
.field-visibility-toggle:hover {
    opacity: 1;
}

.field-hidden .form-control,
.field-hidden .input-group,
.field-hidden .image-field-stack,
.field-hidden textarea {
    opacity: 0.35;
    pointer-events: none;
}
.field-hidden > div:first-child label {
    color: #aaa;
    text-decoration: line-through;
}

.field-key {
    font-family: Consolas, 'Courier New', monospace;
    font-size: 11px;
    color: #8a97ab;
    background: #f3f6fb;
    border: 1px solid #e6ecf5;
    border-radius: 4px;
    padding: 1px 6px;
}

.field-tip {
    font-size: 11px;
    color: #6e7b8f;
    text-align: right;
}

.form-input-wrapper {
    position: relative;
}

.form-input-wrapper .input-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #7c8aa5;
    z-index: 3;
    pointer-events: none;
}

.form-input-wrapper .form-control {
    padding-left: 36px;
}

.form-input-wrapper textarea.form-control {
    padding-top: 10px;
    min-height: 92px;
}

.form-range {
    accent-color: #1976d2;
}

.form-check-input:checked {
    background-color: #1976d2;
    border-color: #1976d2;
}

.input-group-text {
    background: #f8f9fa;
    border: 1px solid #ddd;
    border-left: none;
    color: #666;
    font-size: 14px;
}

.preview-container {
    background: #fff;
    padding: 0;
    min-height: 400px;
    max-width: 900px;
    margin: 0 auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    overflow: hidden;
}

.preview-title {
    font-weight: bold;
    color: #1976d2;
    margin-bottom: 0;
    font-size: 1.1rem;
    padding: 20px 30px;
    background: #f8f9fa;
    border-bottom: 2px solid #e0e0e0;
}

.preview-content {
    padding: 30px;
    min-height: 400px;
    display: flex;
    justify-content: center;
}

.preview-content > .document,
.preview-content > .main-doc {
    display: block;
    width: min(900px, 100%);
    max-width: 900px;
}

#templatePreview .document,
#templatePreview .main-doc {
    width: 900px !important;
    max-width: 900px !important;
    box-sizing: border-box;
}

@media (max-width: 1200px) {
    #templatePreview .document,
    #templatePreview .main-doc {
        width: 100% !important;
        max-width: 900px !important;
    }
}

.preview-empty {
    text-align: center;
    padding: 80px 20px;
    color: #999;
}

.preview-empty i {
    font-size: 48px;
    margin-bottom: 20px;
    color: #ddd;
}

.action-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 25px;
}

.action-buttons .btn {
    min-width: 112px;
}

.action-buttons .btn-outline-secondary {
    border-color: #9aa7b8;
    color: #4c5a6a;
    font-weight: 600;
}

.action-buttons .btn-outline-secondary:hover {
    background: #4c5a6a;
    border-color: #4c5a6a;
    color: #fff;
}

.alert-info-custom {
    background: #e3f2fd;
    border: 1px solid #90caf9;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 25px;
    color: #1976d2;
}

.alert-info-custom strong {
    display: block;
    margin-bottom: 8px;
    font-size: 15px;
}

.alert-info-custom ul {
    margin: 8px 0 0 0;
    padding-left: 20px;
}

.alert-info-custom li {
    margin-bottom: 4px;
}

.img-link {
    font-family: 'Courier New', monospace;
    background: #f5f5f5;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 13px;
}

.user-guide-card .card-body {
    background: #fbfcff;
}

.user-guide-intro {
    background: linear-gradient(135deg, #eef5ff 0%, #f4f9ff 100%);
    border: 1px solid #d7e8ff;
    border-radius: 10px;
    padding: 10px 12px;
    color: #1f3d66;
    font-size: 13px;
}

.user-guide-heading {
    margin: 0 0 8px 0;
    font-size: 13px;
    color: #1d4f91;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.2px;
}

.user-guide-table {
    font-size: 12.5px;
    background: #fff;
    border: 1px solid #e3ebf8;
    border-radius: 10px;
    overflow: hidden;
}

.user-guide-table thead th {
    background: #edf3ff;
    color: #2a4f88;
    font-weight: 700;
    border-bottom: 1px solid #dae6fb;
    white-space: nowrap;
}

.user-guide-table th,
.user-guide-table td {
    padding: 8px 10px;
    vertical-align: top;
    border-color: #e8eef9;
}

.user-guide-table tbody tr:nth-child(even) {
    background: #fcfdff;
}

.user-guide-tips {
    margin: 0;
    padding-left: 18px;
    color: #425a77;
    font-size: 12.5px;
}

.user-guide-tips li {
    margin-bottom: 5px;
}

.user-guide-tips li:last-child {
    margin-bottom: 0;
}

.btn-copy-img {
    font-size: 11px;
    padding: 2px 8px;
}

.toastify.toast-shell {
    padding: 0 !important;
    border-radius: 14px !important;
    box-shadow: 0 14px 34px rgba(12, 22, 38, 0.24) !important;
    min-width: 320px;
    max-width: 420px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    backdrop-filter: blur(8px);
    overflow: hidden;
}

.toastify.toast-shell-success {
    background: linear-gradient(120deg, rgba(14, 116, 93, 0.96), rgba(6, 88, 73, 0.96)) !important;
}

.toastify.toast-shell-error {
    background: linear-gradient(120deg, rgba(190, 24, 64, 0.96), rgba(132, 0, 41, 0.96)) !important;
}

.toast-modern {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 12px 14px;
    color: #ffffff;
}

.toast-modern-icon {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.2);
    flex-shrink: 0;
    margin-top: 1px;
}

.toast-modern-icon i {
    font-size: 15px;
}

.toast-modern-body {
    flex: 1;
    min-width: 0;
}

.toast-modern-title {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.2px;
    margin-bottom: 2px;
}

.toast-modern-text {
    font-size: 13px;
    line-height: 1.4;
    opacity: 0.98;
    word-break: break-word;
}

.toastify.toast-shell .toast-close {
    color: rgba(255, 255, 255, 0.9);
    font-size: 15px;
    opacity: 0.9;
    padding-right: 8px;
    margin-top: 10px;
}

@media (max-width: 576px) {
    .toastify.toast-shell {
        min-width: calc(100vw - 24px);
        max-width: calc(100vw - 24px);
    }
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(255, 255, 255, 0.9);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.loading-overlay .spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #1976d2;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-overlay .loading-text {
    margin-top: 20px;
    font-size: 18px;
    color: #005baa;
    font-weight: 600;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@media (max-width: 991px) {
    .edit-col, .preview-col {
        max-height: none;
        border: none;
        padding: 20px 15px;
    }
    
    .field-group-header {
        padding: 14px 16px;
    }
    
    .field-group-title {
        font-size: 14px;
    }
    
    .field-group-subtitle {
        font-size: 12px;
    }
    
    .preview-container {
        max-width: 100%;
    }
}

@media (max-width: 576px) {
    .action-buttons {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    
    .action-buttons .btn {
        width: 100%;
        min-width: 0;
    }
    

@media (max-width: 576px) {
    .action-buttons {
        grid-template-columns: 1fr;
    }
}
    .template-tools {
        flex-direction: column;
    }
    
    .template-tools .btn {
        width: 100%;
    }
}

.signature-pad-modal {
    border-radius: 16px;
    overflow: hidden;
    border: none;
    box-shadow: 0 25px 60px rgba(0,0,0,0.25);
}

.signature-pad-header {
    background: linear-gradient(135deg, #1a237e 0%, #283593 100%);
    color: #fff;
    padding: 16px 20px;
    border: none;
}

.signature-pad-header .modal-title {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: 0.3px;
}

.sig-pad-toolbar {
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 12px 18px;
    background: #f5f7ff;
    border-bottom: 1px solid #e3e8f5;
    flex-wrap: wrap;
}

.sig-tool-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 100px;
}

.sig-tool-label {
    font-size: 11px;
    font-weight: 600;
    color: #5564a0;
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.sig-tool-label span {
    color: #1a237e;
    font-weight: 700;
}

.sig-color-swatches {
    display: flex;
    gap: 6px;
    align-items: center;
}

.sig-swatch {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
    padding: 0;
    outline: none;
}

.sig-swatch:hover {
    transform: scale(1.2);
}

.sig-swatch.active {
    border-color: #fff;
    box-shadow: 0 0 0 2px #1a237e, 0 2px 6px rgba(0,0,0,0.3);
    transform: scale(1.1);
}

.sig-color-custom {
    width: 28px;
    height: 26px;
    border-radius: 6px;
    border: 1.5px solid #d0d7f0;
    padding: 1px;
    cursor: pointer;
    background: none;
}

.sig-slider {
    -webkit-appearance: none;
    width: 110px;
    height: 5px;
    border-radius: 3px;
    background: #d0d7f0;
    outline: none;
    cursor: pointer;
}

.sig-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #1a237e;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.sig-tool-actions {
    display: flex;
    gap: 8px;
    margin-left: auto;
    align-items: flex-end;
    padding-bottom: 2px;
}

.sig-tool-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1.5px solid #d0d7f0;
    background: #fff;
    color: #384470;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.sig-tool-btn:hover {
    background: #eef2ff;
    border-color: #1a237e;
    color: #1a237e;
    transform: translateY(-1px);
}

.sig-tool-btn.danger:hover {
    background: #fff0f0;
    border-color: #d32f2f;
    color: #d32f2f;
}

.sig-pad-canvas-wrap {
    position: relative;
    background: #fff;
    border-bottom: 1px solid #e3e8f5;
    line-height: 0;
}

#signaturePadCanvas {
    display: block;
    width: 100%;
    cursor: crosshair;
    touch-action: none;
    background: #fff;
}

.sig-pad-hint {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 22px;
    color: #c8d0ec;
    pointer-events: none;
    user-select: none;
    font-weight: 400;
    white-space: nowrap;
    transition: opacity 0.3s;
}

.sig-pad-hint.hidden {
    opacity: 0;
}

.signature-pad-footer {
    background: #f5f7ff;
    border-top: 1px solid #e3e8f5;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.sig-pad-preview-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sig-preview-label {
    font-size: 12px;
    font-weight: 600;
    color: #5564a0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

#sigPreviewCanvas {
    border: 1.5px solid #d0d7f0;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.field-style-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.field-style-controls .field-bold-btn.active {
    background: #111;
    color: #fff;
    border-color: #111;
}

.field-style-controls .field-color-input {
    width: 34px;
    height: 30px;
    padding: 2px;
    min-width: 34px;
}