/**
 * Admin Styles for PDF Template Manager
 */

.psf-templates-wrap {
    margin: 20px;
}

.templates-list table {
    margin-top: 20px;
}

.upload-template {
    max-width: 800px;
    background: #fff;
    padding: 30px;
    margin-top: 20px;
    border: 1px solid #ccc;
    border-radius: 4px;
}

.upload-template h2 {
    margin-top: 0;
}

#pdf-preview-container {
    max-height: 700px;
    overflow: auto;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

/* Preview Field Overlay */
#preview-field-overlay {
    position: absolute;
    pointer-events: none;
}

.preview-field-marker {
    position: absolute;
    border: 2px dashed #0073aa;
    background: rgba(0, 115, 170, 0.1);
    box-sizing: border-box;
    pointer-events: none;
}

.preview-field-marker.active {
    border: 3px solid #ff6600;
    background: rgba(255, 102, 0, 0.15);
    box-shadow: 0 0 15px rgba(255, 102, 0, 0.7);
}

.preview-field-label {
    position: absolute;
    top: -22px;
    left: 0;
    background: #ff6600;
    color: #fff;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 11px;
    white-space: nowrap;
}

/* Field Configuration Modal */
#field-config-modal .modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 999998;
}

#field-config-modal .modal-content {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 8px;
    max-width: 800px;
    width: 90%;
    max-height: 90vh;
    overflow: hidden;
    z-index: 999999;
    box-shadow: 0 5px 30px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
}

#field-config-modal .modal-header {
    padding: 20px 30px;
    border-bottom: 1px solid #ddd;
    position: relative;
}

#field-config-modal .modal-header h2 {
    margin: 0;
}

#field-config-modal .close-modal {
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 28px;
    font-weight: bold;
    color: #aaa;
    cursor: pointer;
    line-height: 1;
}

#field-config-modal .close-modal:hover {
    color: #000;
}

#field-config-modal .modal-body {
    padding: 30px;
    overflow-y: auto;
    flex: 1;
}

#field-config-modal .modal-footer {
    padding: 20px 30px;
    border-top: 1px solid #ddd;
    text-align: right;
}

#field-config-modal .modal-footer .button {
    margin-left: 10px;
}

.instructions {
    background: #f0f6fc;
    padding: 15px;
    border-left: 4px solid #0073aa;
    margin-bottom: 25px;
}

.quick-add-fields {
    margin-bottom: 30px;
}

.quick-add-fields h3 {
    margin-top: 0;
    margin-bottom: 15px;
}

.quick-add-fields .button {
    margin: 0 5px 5px 0;
}

.fields-list {
    margin-bottom: 20px;
}

.fields-list h3 {
    margin-bottom: 15px;
}

#fields-container {
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 15px;
    background: #fafafa;
    min-height: 100px;
}

.field-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-bottom: 10px;
}

.field-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

.field-info strong {
    min-width: 150px;
}

.field-info code {
    background: #f0f0f0;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 12px;
}

.required-badge {
    background: #dc3232;
    color: white;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 600;
}

.field-actions {
    display: flex;
    gap: 5px;
}

#upload-message {
    margin-top: 20px;
}

/* Responsive */
@media (max-width: 768px) {
    #field-config-modal .modal-content {
        width: 95%;
        max-height: 95vh;
    }
    
    .field-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .field-actions {
        width: 100%;
        justify-content: flex-end;
    }
}

/* ==============================================
   Field Mapping UX Polish (v1.5.1)
   ============================================== */

/* Stats Notice */
.psf-field-stats {
    border-left-width: 4px;
}

.psf-stat {
    padding: 2px 8px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 3px;
    font-size: 13px;
}

/* Bulk Toolbar */
.psf-bulk-toolbar {
    background: #f0f0f1;
    border: 1px solid #c3c4c7;
}

.psf-bulk-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* Table Wrapper with Sticky Header */
.psf-table-wrapper {
    border: 1px solid #c3c4c7;
    border-radius: 4px;
}

.psf-field-table {
    border: none !important;
}

.psf-field-table thead th {
    background: #f6f7f7 !important;
    border-bottom: 1px solid #c3c4c7;
    font-weight: 600;
    font-size: 12px;
    padding: 10px 8px;
}

.psf-field-table tbody td {
    padding: 8px;
    vertical-align: middle;
}

/* Saved As Column */
.psf-saved-as-cell {
    color: #50575e;
}

.psf-saved-as-cell code {
    background: #f0f0f1;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 10px;
}

.psf-unmapped {
    color: #787c82;
    font-style: italic;
}

/* Status Badges */
.psf-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 500;
    white-space: nowrap;
}

.psf-badge-warning {
    background: #fcf0e3;
    color: #9d6c00;
    border: 1px solid #f0c33c;
}

.psf-badge-error {
    background: #fcebea;
    color: #8a2a21;
    border: 1px solid #f0c8c5;
}

.psf-badge-success {
    background: #edf7ed;
    color: #1e4620;
    border: 1px solid #8bc88c;
}

/* Type Mismatch Warning */
.psf-type-warning {
    display: block;
    margin-top: 4px;
    padding: 3px 6px;
    background: #fcf0e3;
    color: #9d6c00;
    font-size: 10px;
    border-radius: 3px;
}

/* Duplicate Mapping Warning */
.psf-duplicate-warning {
    display: block;
    margin-top: 4px;
    padding: 3px 6px;
    background: #fcebea;
    color: #8a2a21;
    font-size: 10px;
    border-radius: 3px;
}

/* Row with duplicate mapping - highlight entire row */
.psf-row-duplicate {
    background-color: #fcebea !important;
}

.psf-row-duplicate td {
    border-color: #f0c8c5 !important;
}

/* Server-side duplicate warning */
.psf-server-duplicate {
    font-weight: 600;
}

/* Dirty State Badge */
.psf-dirty-badge {
    display: inline-block;
    padding: 4px 10px;
    background: #fcf0e3;
    color: #9d6c00;
    font-size: 12px;
    font-weight: 500;
    border-radius: 3px;
    margin-right: 10px;
    animation: psf-pulse 2s infinite;
}

@keyframes psf-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Column Preview Box */
.psf-column-preview {
    background: #f0f6fc;
    border: 1px solid #c3d9ed;
}

.psf-column-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.psf-column-item {
    background: #fff;
    padding: 8px 10px;
    border-radius: 4px;
    border: 1px solid #e0e0e0;
}

.psf-column-value {
    font-weight: 500;
}

/* Presets Section */
.psf-presets {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* Auto-Label Button */
#psf-auto-label {
    white-space: nowrap;
}

/* Filter Input */
#psf-field-filter {
    border-radius: 4px;
}

#psf-field-filter:focus {
    border-color: #2271b1;
    box-shadow: 0 0 0 1px #2271b1;
    outline: none;
}

/* Save Feedback */
.psf-save-feedback {
    border-radius: 4px;
}

.psf-save-feedback p {
    font-size: 13px;
}

/* Spinner in button - support both canonical and legacy selectors */
#psf-save-mappings .spinner,
#save-edited-labels .spinner {
    visibility: visible;
    vertical-align: middle;
    margin-top: -2px;
}

/* =====================================================
   CANONICAL SELECTORS (v1.6.0)
   These match the specification for future compatibility
   ===================================================== */

/* Main containers */
#psf-field-mapping-table {
    /* Canonical: main mapping table */
}

#psf-mapping-banner {
    /* Canonical: stats banner at top */
}

#psf-column-preview {
    /* Canonical: live column preview box - styled above */
}

#psf-save-mappings {
    /* Canonical: Save button */
}

#psf-unsaved-indicator {
    /* Canonical: unsaved changes badge - styled as .psf-dirty-badge */
    display: inline-block;
    padding: 4px 10px;
    background: #fcf0e3;
    color: #9d6c00;
    font-size: 12px;
    font-weight: 500;
    border-radius: 3px;
    margin-right: 10px;
    animation: psf-pulse 2s infinite;
}

/* Mapping rows */
tr.psf-mapping-row {
    /* Canonical: each mapping row */
}

/* Per-row inputs - canonical class names */
.psf-map-core-select {
    /* Canonical: core column select */
}

.psf-map-meta-input {
    /* Canonical: meta_key input */
}

.psf-field-label-input {
    /* Canonical: label input */
}

/* Per-row indicators */
.psf-row-warning {
    /* Canonical: inline warning container */
}

.psf-type-warning {
    /* Already styled above */
}

.psf-optional-warning {
    /* Canonical: optional-but-mapped warning */
    display: inline-block;
    padding: 2px 6px;
    background: #fcf0e3;
    color: #9d6c00;
    font-size: 10px;
    border-radius: 3px;
}

/* Preset button */
#psf-preset-basic-contact {
    /* Canonical: Basic Contact preset trigger */
}

/* Row hover highlight */
.psf-field-table tbody tr:hover,
#psf-field-mapping-table tbody tr.psf-mapping-row:hover {
    background-color: #f0f6fc;
}

/* Responsive adjustments for Field Mapping */
@media (max-width: 1200px) {
    .psf-bulk-toolbar {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .psf-field-search {
        margin-left: 0 !important;
        width: 100%;
    }
    
    #psf-field-filter {
        width: 100% !important;
    }
    
    .psf-presets {
        width: 100%;
    }
    
    .psf-column-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 600px) {
    .psf-column-grid {
        grid-template-columns: 1fr;
    }
}

/* ========================================
   Admin Page - Agreement Details Modal
   ======================================== */

.agreement-details-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 999998;
}

.agreement-details-content {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 30px;
    border-radius: 8px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    z-index: 999999;
    box-shadow: 0 5px 30px rgba(0, 0, 0, 0.3);
}

.close-modal {
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 28px;
    font-weight: bold;
    color: #aaa;
    cursor: pointer;
}

.close-modal:hover {
    color: #000;
}

#agreement-details-body {
    margin-top: 20px;
}

#agreement-details-body p {
    margin: 8px 0;
    padding: 8px 12px;
    background: #f9f9f9;
    border-radius: 4px;
}

#agreement-details-body strong {
    display: inline-block;
    min-width: 120px;
    color: #23282d;
}

.audit-trail-section {
    border-top: 2px solid #0073aa;
    margin-top: 15px;
    padding-top: 15px;
}

.audit-trail-section h3 {
    margin: 0 0 10px 0;
    color: #0073aa;
    font-size: 14px;
}

.audit-badge {
    display: inline-block;
    background: #00a32a;
    color: white;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 3px;
    margin-left: 10px;
}

.captured-fields-section {
    max-height: 400px;
    overflow-y: auto;
}

.captured-fields-section p {
    margin: 6px 0 !important;
    padding: 8px 12px !important;
    background: #f9f9f9 !important;
    border-radius: 4px !important;
    font-size: 13px;
    word-break: break-word;
}

.captured-fields-section p strong {
    color: #1d4ed8;
    min-width: 150px;
    display: inline-block;
}

/* ========================================
   Templates Page - Field Row Selection
   ======================================== */

#fields-tbody tr.psf-row-selected {
    background-color: #fff8e5 !important;
    outline: 2px solid #f39c12;
}

#fields-tbody tr:hover {
    background-color: #f8f8f8;
    cursor: pointer;
}

/* ========================================
   Settings Page Styles
   ======================================== */

.psf-settings-wrap {
    max-width: 960px;
    margin: 30px 30px 30px 0;
    padding-right: 20px;
}
.psf-settings-wrap h1 {
    font-size: 28px;
    font-weight: 400;
    margin: 0 0 30px 0;
    padding: 0;
}
.psf-section {
    background: #fff;
    border: 1px solid #dcdcde;
    border-radius: 8px;
    margin-bottom: 40px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}
.psf-section-header {
    padding: 24px 28px;
    border-bottom: 1px solid #e5e7eb;
    background: #f9fafb;
}
.psf-section-header h2 {
    margin: 0 0 8px 0;
    padding: 0;
    font-size: 18px;
    font-weight: 600;
    color: #1e1e1e;
}
.psf-section-header p {
    margin: 0;
    font-size: 14px;
    color: #646970;
    line-height: 1.6;
}
.psf-section-body {
    padding: 28px;
}
.psf-field-row {
    display: flex;
    align-items: flex-start;
    padding: 20px 0;
    border-bottom: 1px solid #f0f0f1;
}
.psf-field-row:last-child {
    border-bottom: none;
    padding-bottom: 0;
}
.psf-field-row:first-child {
    padding-top: 0;
}
.psf-field-label {
    width: 220px;
    flex-shrink: 0;
    font-weight: 500;
    font-size: 14px;
    color: #1e1e1e;
    padding-top: 10px;
    line-height: 1.5;
}
.psf-field-input {
    flex: 1;
}
.psf-field-input input[type="text"],
.psf-field-input input[type="email"],
.psf-field-input input[type="url"],
.psf-field-input input[type="number"],
.psf-field-input textarea {
    width: 100%;
    max-width: 420px;
    padding: 10px 14px;
    font-size: 14px;
    border: 1px solid #8c8f94;
    border-radius: 4px;
}
.psf-field-input input[type="text"]:focus,
.psf-field-input input[type="email"]:focus,
.psf-field-input input[type="url"]:focus,
.psf-field-input input[type="number"]:focus,
.psf-field-input textarea:focus {
    border-color: #2271b1;
    box-shadow: 0 0 0 1px #2271b1;
    outline: none;
}
.psf-field-input textarea {
    max-width: 100%;
    min-height: 120px;
    line-height: 1.6;
}
.psf-field-input .description {
    margin-top: 10px;
    font-size: 13px;
    color: #646970;
    line-height: 1.6;
}
.psf-checkbox-group label {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
    font-size: 14px;
    line-height: 1.5;
}
.psf-checkbox-group label:last-child {
    margin-bottom: 0;
}
.psf-checkbox-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin: 0;
}
.psf-toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 28px;
    background: #f8fafc;
    border-bottom: 1px solid #e5e7eb;
}
.psf-toggle-row label {
    display: flex;
    align-items: center;
    gap: 14px;
    font-weight: 500;
    font-size: 15px;
    cursor: pointer;
}
.psf-toggle-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin: 0;
}
.psf-toggle-row .psf-toggle-desc {
    font-size: 13px;
    color: #646970;
    font-weight: 400;
}
.psf-collapsible {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}
.psf-collapsible.is-open {
    max-height: 3000px;
}
.psf-collapsible-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 28px;
    background: #fff;
    border: none;
    border-bottom: 1px solid #e5e7eb;
    width: 100%;
    text-align: left;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    color: #2271b1;
}
.psf-collapsible-trigger:hover {
    background: #f0f6fc;
}
.psf-collapsible-trigger .dashicons {
    transition: transform 0.2s;
}
.psf-collapsible-trigger.is-open .dashicons {
    transform: rotate(180deg);
}
.psf-variables-list {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 14px;
}
.psf-variables-list code {
    background: #f0f0f1;
    padding: 8px 14px;
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s;
}
.psf-variables-list code:hover {
    background: #e0e0e0;
}
.psf-save-bar {
    position: sticky;
    bottom: 0;
    background: #fff;
    border: 1px solid #dcdcde;
    border-radius: 8px;
    padding: 20px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 -4px 12px rgba(0,0,0,0.08);
    z-index: 10;
    margin-top: 10px;
}
.psf-save-bar .button-primary {
    padding: 10px 32px;
    height: auto;
    font-size: 14px;
}
.psf-notice {
    padding: 16px 20px;
    border-radius: 6px;
    margin-bottom: 28px;
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 14px;
}
.psf-notice-success {
    background: #edfcf2;
    border: 1px solid #b8e6c8;
    color: #0a5c36;
}
.psf-inline-fields {
    display: flex;
    gap: 16px;
    align-items: center;
}
.psf-inline-fields input[type="number"] {
    width: 90px;
}

/* ========================================
   License Page Styles
   ======================================== */

.psf-license-wrap {
    max-width: 800px;
}
.psf-license-card {
    background: #fff;
    border: 1px solid #c3c4c7;
    border-radius: 4px;
}
.psf-license-header {
    padding: 15px 20px;
    border-bottom: 1px solid #c3c4c7;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f6f7f7;
}
.psf-license-header h2 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
}
.psf-status-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}
.psf-status-badge.active {
    background: #d1fae5;
    color: #065f46;
}
.psf-status-badge.none {
    background: #e5e7eb;
    color: #6b7280;
}
.psf-license-body {
    padding: 10px 20px 20px;
}
.psf-license-body .form-table th {
    padding: 15px 10px 15px 0;
    width: 180px;
}
.psf-license-body .form-table td {
    padding: 15px 10px;
}
.psf-status-table td {
    vertical-align: middle;
}
.psf-status-ok {
    color: #065f46;
    font-weight: 500;
}
.psf-status-ok .dashicons {
    color: #10b981;
}
.psf-status-disabled {
    color: #6b7280;
}
.psf-status-disabled .dashicons {
    color: #9ca3af;
}
.psf-diagnostics-details summary {
    list-style: none;
}
.psf-diagnostics-details summary::-webkit-details-marker {
    display: none;
}
.psf-diagnostics-details[open] summary .dashicons {
    transform: rotate(180deg);
}
.psf-diagnostics-details summary .dashicons {
    transition: transform 0.2s ease;
}
#psf-debug-info {
    font-family: monospace;
    font-size: 12px;
    background: #f6f7f7;
}