/* ==========================================================================
   LibreKey Global & Root Styles
   ========================================================================== */
:root {
    --lk-primary-color: #2563eb;
    --lk-primary-hover: #1d4ed8;
    --lk-text-dark: #1f2937;
    --lk-text-light: #6b7280;
    --lk-border-color: #e5e7eb;
    --lk-bg-light: #f9fafb;
    --lk-bg-white: #ffffff;
    --lk-success-bg: #f0fdf4;
    --lk-success-border: #4ade80;
    --lk-error-bg: #fef2f2;
    --lk-error-border: #f87171;
    --lk-error-text: #dc2626;
    --lk-secondary-bg: #f3f4f6;
    --lk-secondary-hover: #e5e7eb;
    --lk-secondary-text: #374151;
}
.librekey-dashboard, .librekey-lead-form {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    color: var(--lk-text-dark);
}
.librekey-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    background-color: var(--lk-primary-color);
    color: #fff;
    text-decoration: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: background-color 0.2s ease-in-out;
}
.librekey-button:hover {
    background-color: var(--lk-primary-hover);
    color: #fff;
}
.librekey-notice { padding: 1em; margin-bottom: 1em; border-left: 4px solid; border-radius: 4px; }
.librekey-notice-success { background-color: var(--lk-success-bg); border-left-color: var(--lk-success-border); color: #16a34a; }
.librekey-notice-error { background-color: var(--lk-error-bg); border-left-color: var(--lk-error-border); color: var(--lk-error-text); }

/* ==========================================================================
   Dashboard Layout & Cards
   ========================================================================== */
.librekey-dashboard { max-width: 1100px; margin: 2em auto; padding: 0 15px; }
.librekey-dashboard h2 { font-size: 28px; font-weight: 600; margin-bottom: 1.5em; }
.dashboard-section.card {
    background: var(--lk-bg-white);
    border: 1px solid var(--lk-border-color);
    border-radius: 8px;
    margin-bottom: 2.5em;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.dashboard-section-header { display: flex; justify-content: space-between; align-items: center; padding: 20px 24px; border-bottom: 1px solid var(--lk-border-color); }
.dashboard-section-header h3 { margin: 0; font-size: 18px; font-weight: 600; }
.lk-listings-table-wrap, .lk-leads-table-wrap { overflow-x: auto; }
.lk-empty-state { text-align: center; padding: 48px 24px; color: var(--lk-text-light); }
.lk-empty-state .dashicons { font-size: 48px; width: 48px; height: 48px; margin-bottom: 12px; }

/* ==========================================================================
   Tables & Status Pills
   ========================================================================== */
.librekey-table { width: 100%; border-collapse: collapse; }
.librekey-table th, .librekey-table td { padding: 16px; text-align: left; border-bottom: 1px solid var(--lk-border-color); white-space: nowrap; }
.librekey-table th { font-size: 12px; font-weight: 500; color: var(--lk-text-light); text-transform: uppercase; letter-spacing: 0.05em; }
.librekey-table tr:last-child td { border-bottom: none; }
.librekey-table td.actions-cell { text-align: right; }
.action-link { background: none; border: none; cursor: pointer; padding: 4px; }
.action-link .dashicons { color: var(--lk-text-light); transition: color 0.2s; font-size: 20px; }
.action-link:hover .dashicons { color: var(--lk-primary-color); }
.action-link.delete:hover .dashicons { color: var(--lk-error-text); }
.status-pill { padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 500; }
.status-pill.status-approved, .status-pill.status-publish { background-color: #dcfce7; color: #166534; }
.status-pill.status-draft { background-color: #f3f4f6; color: #4b5563; }

/* ==========================================================================
   Lead Capture Form & Modal Forms
   ========================================================================== */
.librekey-lead-form, .lk-modal-content form { max-width: 600px; margin: 0 auto; }
.librekey-lead-form { background: var(--lk-bg-white); border: 1px solid var(--lk-border-color); padding: 2em; border-radius: 8px; }
.form-row { margin-bottom: 1.5em; }
label { display: block; margin-bottom: 0.5em; font-weight: 500; font-size: 14px; }
.required { color: var(--lk-error-text); }
input[type="text"], input[type="email"], input[type="tel"], input[type="number"], textarea, select {
    width: 100%; padding: 10px 12px; border: 1px solid var(--lk-border-color); border-radius: 6px; box-sizing: border-box; background-color: var(--lk-bg-light); transition: border-color 0.2s, box-shadow 0.2s; }
input:focus, textarea:focus, select:focus { border-color: var(--lk-primary-color); background-color: var(--lk-bg-white); outline: none; box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2); }
.form-row.has-error input, .form-row.has-error textarea { border-color: var(--lk-error-text); }
.form-error { color: var(--lk-error-text); font-size: 12px; display: block; margin-top: 5px; }

/* ==========================================================================
   AJAX Modal - FINAL VERSION
   ========================================================================== */
#lk-add-listing-modal, #lk-edit-listing-modal,
#lk-add-lead-modal, #lk-edit-lead-modal,
#lk-documents-modal, #lk-trust-add-entry-modal {
    position: fixed; z-index: 99999; inset: 0; width: 100%; height: 100%;
    background-color: rgba(17, 24, 39, 0.8); display: none; align-items: center;
    justify-content: center; padding: 1rem; opacity: 0; transition: opacity 0.2s ease-in-out; }
#lk-add-listing-modal.is-visible, #lk-edit-listing-modal.is-visible,
#lk-add-lead-modal.is-visible, #lk-edit-lead-modal.is-visible,
#lk-documents-modal.is-visible, #lk-trust-add-entry-modal.is-visible {
    display: flex; opacity: 1; }
.lk-modal-content {
    background-color: var(--lk-bg-white); width: 100%; max-width: 640px; border-radius: 8px;
    position: relative; box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1); transform: scale(0.95);
    transition: transform 0.2s ease-in-out; display: flex; flex-direction: column; max-height: 90vh; }
.lk-modal-overlay.is-visible .lk-modal-content { transform: scale(1); }
.lk-modal-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 24px; border-bottom: 1px solid var(--lk-border-color); flex-shrink: 0; }
.lk-modal-header h3 { margin: 0; font-size: 18px; font-weight: 600; }
.lk-modal-content form, #lk-documents-modal .lk-modal-body { padding: 24px; overflow-y: auto; }
.lk-modal-close { color: var(--lk-text-light); font-size: 28px; border: none; background: none; cursor: pointer; line-height: 1; padding: 0; transition: color 0.2s; }
.lk-modal-close:hover { color: var(--lk-text-dark); }
.form-row-split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-footer { margin-top: 24px; padding-top: 24px; border-top: 1px solid var(--lk-border-color); display:flex; justify-content: flex-end; }
.lk-modal-feedback { text-align: left; flex-grow: 1; }

/* Spinner for AJAX Button */
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid rgba(255,255,255,0.3); border-radius: 50%; border-top-color: #fff; animation: spin 1s ease-in-out infinite; -webkit-animation: spin 1s ease-in-out infinite; display: none; }
.librekey-button.is-loading { position: relative; }
.librekey-button.is-loading .spinner { display: block; }
.librekey-button.is-loading .button-text { visibility: hidden; }
.spinner { position: absolute; left: 50%; top: 50%; margin-top: -8px; margin-left: -8px; }
@keyframes spin { to { transform: rotate(360deg); } }
@-webkit-keyframes spin { to { -webkit-transform: rotate(360deg); } }

/* ==========================================================================
   Modal Tabs
   ========================================================================== */
.lk-tabs-nav { display: flex; border-bottom: 1px solid var(--lk-border-color); padding: 0 24px; flex-shrink: 0; }
.lk-tab-link { padding: 12px 16px; border-bottom: 2px solid transparent; margin-bottom: -1px; text-decoration: none; color: var(--lk-text-light); font-weight: 500; }
.lk-tab-link.active { color: var(--lk-primary-color); border-bottom-color: var(--lk-primary-color); }
.lk-modal-body { overflow-y: auto; }
.lk-tab-content { display: none; }
.lk-tab-content.active { display: block; }
#lk-activity-panel-frontend { padding: 24px; }
#lk-activity-form-wrap-frontend textarea { width: 100%; min-height: 80px; margin-bottom: 10px; }
#lk-activity-form-wrap-frontend .lk-activity-actions { display: flex; gap: 10px; align-items: center; }
.lk-activity-stream-frontend { margin-top: 24px; border-top: 1px solid var(--lk-border-color); }

/* ==========================================================================
   Activity Stream & Edit Form Styles
   ========================================================================== */
.lk-activity-item { display: flex; gap: 15px; padding: 15px 0; border-bottom: 1px solid #eee; }
.lk-activity-item:last-child { border-bottom: none; }
.lk-activity-icon .dashicons { background: #e0e0e0; border-radius: 50%; width: 36px; height: 36px; font-size: 20px; line-height: 36px; text-align: center; color: #555; }
.lk-activity-content { word-wrap: break-word; overflow-wrap: break-word; word-break: break-word; white-space: pre-wrap; }
.lk-activity-content p { margin: 0 0 10px 0; }
.lk-activity-meta { font-size: 12px; color: #777; }
.lk-activity-meta a { text-decoration: none; font-weight: 500; color: var(--lk-primary-color); }
.lk-activity-meta a:hover { text-decoration: underline; }
.lk-activity-reminder-info { background-color: #fff8e1; border-left: 3px solid #ffc107; padding: 5px 10px; margin-bottom: 10px; font-size: 12px; }
.lk-no-activity { text-align: center; color: #888; padding: 20px; }
.lk-modal-content .lk-activity-edit-textarea {
    width: 100%; min-height: 120px; padding: 10px 12px; border: 1px solid var(--lk-border-color);
    border-radius: 6px; box-sizing: border-box; background-color: var(--lk-bg-light);
    transition: border-color 0.2s, box-shadow 0.2s; margin-bottom: 10px; }
.lk-modal-content .lk-activity-edit-textarea:focus {
    border-color: var(--lk-primary-color); background-color: var(--lk-bg-white);
    outline: none; box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2); }
.lk-activity-edit-actions .button {
    font-size: 13px; padding: 6px 12px; border-radius: 4px; border: 1px solid var(--lk-border-color);
    cursor: pointer; text-decoration: none; }
.lk-activity-edit-actions .button.button-primary {
    background: var(--lk-primary-color); border-color: var(--lk-primary-color); color: #fff; }
.lk-activity-edit-actions .button.button-primary:hover {
    background: var(--lk-primary-hover); border-color: var(--lk-primary-hover); }
.lk-activity-edit-actions .button.button-secondary {
    background: var(--lk-secondary-bg); color: var(--lk-secondary-text); }
.lk-activity-edit-actions .button.button-secondary:hover {
    background: var(--lk-secondary-hover); }
    
    .lk-activity-meta a.delete:hover {
    color: var(--lk-error-text);
    text-decoration: underline;
}

/* Document List Styles */
.lk-document-list {
    list-style: none;
    margin: 0;
    padding: 0;
}
.lk-document-list li {
    padding: 12px 0;
    border-bottom: 1px solid var(--lk-border-color);
}
.lk-document-list li:last-child {
    border-bottom: none;
}
.lk-document-list a {
    text-decoration: none;
    font-weight: 500;
    color: var(--lk-primary-color);
    display: flex;
    align-items: center;
    gap: 10px;
}
.lk-document-list a .dashicons {
    font-size: 22px;
}
.lk-document-list .timestamp {
    font-size: 12px;
    color: var(--lk-text-light);
    margin-left: auto;
}

/* Document Management Modal */
#lk-documents-modal .lk-modal-body {
    padding: 24px;
}
.lk-doc-section {
    margin-bottom: 24px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--lk-border-color);
}
.lk-doc-section:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}
.lk-doc-section h4 {
    margin-top: 0;
    margin-bottom: 16px;
    font-size: 16px;
    font-weight: 500;
}
.lk-doc-generate-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}
.librekey-button.secondary {
    background-color: var(--lk-secondary-bg);
    color: var(--lk-secondary-text);
}
.librekey-button.secondary:hover {
    background-color: var(--lk-secondary-hover);
}

/* Quick Link Buttons in Tables */
.lk-quick-link {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    color: var(--lk-primary-color);
    cursor: pointer;
    text-align: left;
}
.lk-quick-link:hover {
    text-decoration: underline;
    color: var(--lk-primary-hover);
}

/* Source Pill Styles */
.source-pill {
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    background-color: #eef2ff;
    color: #4338ca;
}
.source-pill.source-manual {
    background-color: #f1f5f9;
    color: #475569;
}

/* ==========================================================================
   Trust Account Dashboard
   ========================================================================== */
.lk-trust-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5em;
}
.lk-trust-mode-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
}
.mode-label {
    font-size: 14px;
    font-weight: 500;
    color: var(--lk-text-light);
}
.mode-pill {
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    line-height: 1;
}
.mode-pill.mode-live {
    background-color: var(--lk-success-bg);
    color: #166534;
    border: 1px solid var(--lk-success-border);
}
.mode-pill.mode-test {
    background-color: #fffbeb;
    color: #b45309;
    border: 1px solid #fbbF74;
}
#lk-trust-dashboard .lk-tabs-nav {
    padding: 0;
    border-bottom: 2px solid var(--lk-border-color);
}
#lk-trust-dashboard .lk-tab-content {
    padding: 1.5em 0;
}
.lk-compliance-list {
    list-style: none;
    padding: 0;
    margin-top: 1em;
}
.lk-compliance-list li {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 0.5em;
    font-size: 15px;
}
.lk-compliance-list .dashicons {
    color: #16a34a;
}
.header-actions {
    display: flex;
    align-items: center;
    gap: 1.5em;
}
.running-balance {
    font-size: 14px;
    color: var(--lk-text-light);
}
.running-balance strong {
    color: var(--lk-text-dark);
    font-weight: 600;
}
#lk-trust-ledger-table-wrap {
    min-height: 200px;
    position: relative;
}
.lk-table-loader {
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    font-size: 16px;
    gap: 1em;
    color: var(--lk-text-light);
}
.lk-table-loader .spinner {
    display: block;
    position: static;
    border-color: rgba(0,0,0,0.2);
    border-top-color: var(--lk-primary-color);
    width: 24px;
    height: 24px;
    margin: 0;
}
.librekey-table .trust-receipt td:nth-child(5)::before { content: '+ '; color: #16a34a; }
.librekey-table .trust-disbursement td:nth-child(5)::before { content: '- '; color: var(--lk-error-text); }
.librekey-table .trust-receipt td:nth-child(5) { color: #166534; font-weight: 500; }
.librekey-table .trust-disbursement td:nth-child(5) { color: #991b1b; font-weight: 500; }

/* Reconciliation Styles */
.lk-recon-controls {
    padding: 24px;
    background-color: var(--lk-bg-light);
    border-bottom: 1px solid var(--lk-border-color);
    display: flex;
    align-items: center;
    gap: 1em;
}
#lk-recon-results {
    padding: 24px;
}
.lk-recon-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5em;
    margin-bottom: 2em;
}
.summary-box {
    background: var(--lk-bg-light);
    padding: 1em;
    border-radius: 8px;
    border: 1px solid var(--lk-border-color);
}
.summary-box .label {
    font-size: 14px;
    color: var(--lk-text-light);
    margin: 0 0 0.5em 0;
}
.summary-box .value {
    font-size: 24px;
    font-weight: 600;
    margin: 0;
}
.lk-recon-actions {
    margin-top: 2em;
    padding-top: 2em;
    border-top: 1px solid var(--lk-border-color);
    display: flex;
    justify-content: flex-end;
    gap: 1em;
}
.librekey-button.secondary {
    background-color: var(--lk-secondary-bg);
    color: var(--lk-secondary-text);
}
.librekey-button.secondary:hover {
    background-color: var(--lk-secondary-hover);
}
.recon-details h4 {
    font-size: 18px;
    margin-bottom: 1em;
}
.recon-flags .flag-item {
    padding: 0.75em 1em;
    border-radius: 6px;
    margin-bottom: 0.5em;
}
.flag-item.flag-warning {
    background-color: #fffbeb;
    border: 1px solid #fbbF74;
    color: #b45309;
}

/* Ledger Filters */
.lk-ledger-filters {
    padding: 16px 24px;
    background-color: var(--lk-bg-light);
    border-bottom: 1px solid var(--lk-border-color);
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 16px;
}
.filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.filter-group label {
    font-size: 12px;
    font-weight: 500;
    color: var(--lk-text-light);
}
.filter-group input,
.filter-group select {
    padding: 8px 10px;
    font-size: 14px;
}
.filter-group-search {
    flex-grow: 1;
}
#lk_filter_apply_btn {
    padding: 8px 16px;
}

/* Pagination */
.lk-pagination-controls {
    text-align: center;
    padding: 24px;
}

/* Annual Report Table */
#lk-annual-results .librekey-table th,
#lk-annual-results .librekey-table td {
    font-size: 13px;
}

/* Disabled/Audit Mode Styles */
.audit-mode .librekey-button,
.audit-mode button {
    cursor: not-allowed !important;
    opacity: 0.6;
}
.audit-mode .header-actions .librekey-button {
    display: none;
}

/* Unreconciled Transactions List in Reconciliation View */
.unreconciled-list-wrapper {
    margin-top: 2em;
    padding: 1.5em;
    background-color: #fef2f2; /* Light red background to draw attention */
    border: 1px solid #f87171;
    border-radius: 8px;
}
.unreconciled-list-wrapper h5 {
    margin-top: 0;
    margin-bottom: 1em;
    font-size: 16px;
    color: #991b1b; /* Dark red text */
}
.unreconciled-list-wrapper .librekey-table {
    background-color: var(--lk-bg-white);
}
.unreconciled-list-wrapper .librekey-table td,
.unreconciled-list-wrapper .librekey-table th {
    padding: 12px;
}
.reconcile-now-btn {
    padding: 6px 12px !important;
    font-size: 13px !important;
}
.reconcile-now-btn.is-success {
    background-color: #16a34a;
    color: white;
    cursor: default;
}

/* Read-only / Disabled field styles for Trust Officer view */
.lk-modal-content form input:disabled,
.lk-modal-content form select:disabled,
.lk-modal-content form textarea:disabled {
    background-color: #f3f4f6; /* A slightly different grey */
    color: #6b7280;
    cursor: not-allowed;
    opacity: 0.8;
}