/* ========================================
   UI.CSS - Giao diện người dùng
   ======================================== */

/* === LAYOUT === */
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;
}

.container-fluid {
    min-height: 100vh;
    padding: 0;
}

.main-row {
    min-height: 100vh;
}

/* === COLUMNS === */
.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;
}

/* === HEADER === */
.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;
}

/* === BUTTONS === */
.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 === */
.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 PANEL === */
.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 GROUPS === */
.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 FIELDS === */
.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 ẩn/hiện toggle */
.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 === */
.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;
}

/* Hard lock template width so all templates render same scale in preview */
#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 === */
.action-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 25px;
}

.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;
}

/* === ALERTS === */
.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;
}

.btn-copy-img {
    font-size: 11px;
    padding: 2px 8px;
}

/* === LOADING OVERLAY === */
.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); }
}

/* === RESPONSIVE === */
@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 {
        flex-direction: column;
    }
    
    .action-buttons .btn {
        width: 100%;
    }
    
    .template-tools {
        flex-direction: column;
    }
    
    .template-tools .btn {
        width: 100%;
    }
}

/* ==========================================
   SIGNATURE DRAW PAD MODAL
   ========================================== */
.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;
}

/* Toolbar */
.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;
}

/* Canvas area */
.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;
}

/* Footer */
.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);
}