/**
 * Meta Ledger Admin Styles
 *
 * Clean, neutral, modern styling.
 *
 * @package Meta_Ledger
 * @since   1.0.0
 */

/* ========================================
   Container & Base
   ======================================== */

.meta-ledger-container {
	margin: -6px -12px -12px;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
	background: #fff;
}

/* ========================================
   Tabs - Clean Design
   ======================================== */

.meta-ledger-tabs {
	display: flex;
	border-bottom: 1px solid #e5e7eb;
	background: #fafafa;
	margin: 0;
	padding: 0;
}

.meta-ledger-tab {
	padding: 14px 24px;
	border: none;
	background: transparent;
	cursor: pointer;
	font-size: 13px;
	font-weight: 500;
	color: #6b7280;
	border-bottom: 2px solid transparent;
	margin-bottom: -1px;
	transition: all 0.2s ease;
	display: flex;
	align-items: center;
	gap: 10px;
}

.meta-ledger-tab:hover {
	color: #2563eb;
	background: #f9fafb;
}

.meta-ledger-tab.active {
	color: #2563eb;
	background: #fff;
	border-bottom-color: #2563eb;
	font-weight: 600;
}

.meta-ledger-count {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 20px;
	height: 20px;
	background: #2563eb;
	color: #fff;
	font-size: 11px;
	font-weight: 600;
	padding: 0 6px;
	border-radius: 10px;
}

/* ========================================
   Panels
   ======================================== */

.meta-ledger-panel {
	display: none;
	padding: 20px;
	background: #fff;
}

.meta-ledger-panel.active {
	display: block;
}

/* Loading */
.meta-ledger-loading {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 12px;
	padding: 60px 20px;
	color: #6b7280;
	font-size: 14px;
}

.meta-ledger-loading .spinner {
	float: none;
	margin: 0;
}

/* History Toolbar */
.meta-ledger-history-toolbar {
	display: flex;
	justify-content: flex-end;
	gap: 12px;
	margin-bottom: 16px;
	padding: 0;
}

.meta-ledger-refresh-btn {
	display: inline-flex !important;
	align-items: center;
	gap: 6px;
	font-size: 13px !important;
	padding: 6px 14px !important;
	height: auto;
	line-height: 1.5;
	border-radius: 6px !important;
	font-weight: 500 !important;
	transition: all 0.2s ease !important;
	background: #2563eb !important;
	border: none !important;
	color: #fff !important;
}

.meta-ledger-refresh-btn .dashicons {
	font-size: 16px;
	width: 16px;
	height: 16px;
	line-height: 1;
}

.meta-ledger-refresh-btn:hover:not(:disabled) {
	background: #1d4ed8 !important;
	transform: translateY(-1px);
	box-shadow: 0 4px 6px rgba(37, 99, 235, 0.2) !important;
}

.meta-ledger-refresh-btn:disabled {
	opacity: 0.6;
	cursor: not-allowed;
	transform: none !important;
}

.meta-ledger-refresh-btn .dashicons-update {
	animation: none;
	transition: transform 0.3s ease;
}

.meta-ledger-refresh-btn:not(:disabled):hover .dashicons-update {
	transform: rotate(180deg);
}

.meta-ledger-refresh-btn:disabled .dashicons-update {
	animation: meta-ledger-spin 1s linear infinite;
}

@keyframes meta-ledger-spin {
	from {
		transform: rotate(0deg);
	}
	to {
		transform: rotate(360deg);
	}
}

/* Empty & Error States */
.meta-ledger-empty,
.meta-ledger-error {
	padding: 50px 20px;
	text-align: center;
	color: #6b7280;
	font-size: 14px;
	border-radius: 6px;
}

.meta-ledger-error {
	color: #dc2626;
	background: #fef2f2;
	border: 1px solid #fecaca;
}

/* ========================================
   Meta Values Tab
   ======================================== */

.meta-ledger-values-toolbar {
	display: flex;
	gap: 12px;
	margin-bottom: 20px;
	align-items: center;
	padding: 14px 16px;
	background: #f9fafb;
	border-radius: 8px;
	border: 1px solid #e5e7eb;
}

.meta-ledger-search {
	flex: 1;
	max-width: 320px;
	padding: 10px 14px;
	border: 1px solid #d1d5db;
	border-radius: 6px;
	font-size: 13px;
	background: #fff;
	transition: all 0.2s ease;
}

.meta-ledger-search:focus {
	border-color: #2563eb;
	box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
	outline: none;
}

.meta-ledger-add-btn {
	padding: 2px 18px !important;
	font-weight: 500 !important;
	background: #2563eb !important;
	border: none !important;
	border-radius: 6px !important;
	color: #fff !important;
	transition: all 0.2s ease !important;
	display: inline-flex !important;
	align-items: center !important;
	gap: 6px !important;
}

.meta-ledger-add-btn .dashicons {
	font-size: 16px;
	width: 16px;
	height: 16px;
	line-height: 1;
}

.meta-ledger-add-btn:hover {
	background: #1d4ed8 !important;
	transform: translateY(-1px);
	box-shadow: 0 4px 6px rgba(37, 99, 235, 0.2) !important;
}

/* Values Table */
.meta-ledger-values-table {
	width: 100%;
	border-collapse: separate;
	border-spacing: 0;
	font-size: 13px;
	border: 1px solid #e5e7eb;
	border-radius: 8px;
	overflow: hidden;
}

.meta-ledger-values-table th {
	text-align: left;
	padding: 12px 16px;
	background: #f9fafb;
	border-bottom: 1px solid #e5e7eb;
	font-weight: 600;
	color: #374151;
	font-size: 11px;
	text-transform: uppercase;
	letter-spacing: 0.5px;
}

.meta-ledger-values-table td {
	padding: 12px 16px;
	border-bottom: 1px solid #f3f4f6;
	vertical-align: middle;
}

.meta-ledger-values-table tr:last-child td {
	border-bottom: none;
}

.meta-ledger-values-table tr:hover td {
	background: #f9fafb;
}

.meta-ledger-col-key {
	width: 28%;
}

.meta-ledger-col-key code {
	display: inline-block;
	background: transparent;
	color: #2563eb;
	padding: 0;
	font-size: 11px;
	border-radius: 0;
	font-weight: 500;
}

.meta-ledger-col-value {
	width: 58%;
}

.meta-ledger-col-actions {
	width: 14%;
	white-space: nowrap;
	text-align: right;
	vertical-align: middle;
}

.meta-ledger-value-input {
	width: 100%;
	min-height: 40px;
	font-family: 'SF Mono', Consolas, 'Liberation Mono', Menlo, monospace;
	font-size: 12px;
	padding: 10px 12px;
	border: 1px solid #d1d5db;
	border-radius: 6px;
	resize: vertical;
	transition: all 0.2s ease;
	background: #fff;
}

.meta-ledger-value-input:focus {
	border-color: #2563eb;
	box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
	outline: none;
}

.meta-ledger-value-input[readonly] {
	background: #f9fafb;
	color: #6b7280;
	border-color: #e5e7eb;
}

.meta-ledger-serialized-note {
	display: block;
	color: #6b7280;
	font-size: 11px;
	margin-top: 6px;
	font-style: italic;
}

.meta-ledger-value-row.meta-ledger-saved td {
	background: #f0fdf4 !important;
	transition: background 0.3s ease;
}

/* Add New Meta Form */
#meta-ledger-new-meta-row {
	margin-bottom: 20px;
}

.meta-ledger-add-form {
	background: #fff;
	border: 1px solid #e5e7eb;
	border-radius: 8px;
	overflow: hidden;
	box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.meta-ledger-add-form-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 14px 18px;
	background: #f9fafb;
	border-bottom: 1px solid #e5e7eb;
}

.meta-ledger-add-form-header h3 {
	margin: 0;
	font-size: 14px;
	font-weight: 600;
	color: #111827;
}

.meta-ledger-close-add-form {
	background: none;
	border: none;
	padding: 4px;
	cursor: pointer;
	color: #6b7280;
	border-radius: 4px;
	transition: all 0.2s ease;
	display: flex;
	align-items: center;
	justify-content: center;
}

.meta-ledger-close-add-form:hover {
	background: #f3f4f6;
	color: #111827;
}

.meta-ledger-close-add-form .dashicons {
	font-size: 18px;
	width: 18px;
	height: 18px;
}

.meta-ledger-add-form-body {
	padding: 18px;
}

.meta-ledger-add-form-field {
	margin-bottom: 16px;
}

.meta-ledger-add-form-field:last-of-type {
	margin-bottom: 20px;
}

.meta-ledger-add-form-field label {
	display: block;
	margin-bottom: 6px;
	font-size: 12px;
	font-weight: 600;
	color: #374151;
	text-transform: uppercase;
	letter-spacing: 0.3px;
}

.meta-ledger-new-key,
.meta-ledger-new-value {
	width: 100%;
	font-family: 'SF Mono', Consolas, monospace;
	padding: 10px 12px;
	border: 1px solid #d1d5db;
	border-radius: 6px;
	background: #fff;
	font-size: 12px;
	transition: all 0.2s ease;
}

.meta-ledger-new-key:focus,
.meta-ledger-new-value:focus {
	border-color: #2563eb;
	box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
	outline: none;
}

.meta-ledger-new-value {
	resize: vertical;
	min-height: 80px;
}

.meta-ledger-add-form-actions {
	display: flex;
	gap: 10px;
	align-items: center;
}

.meta-ledger-add-form-actions .button {
	display: inline-flex;
	align-items: center;
	gap: 6px;
}

.meta-ledger-add-form-actions .dashicons {
	font-size: 16px;
	width: 16px;
	height: 16px;
}

/* Action buttons */
.meta-ledger-col-actions .button {
	padding: 0 10px;
	min-height: 32px;
	line-height: 30px;
	margin-left: 6px;
	border-radius: 6px;
	transition: all 0.2s ease;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	vertical-align: middle;
}

.meta-ledger-col-actions .button:first-child {
	margin-left: 0;
}

.meta-ledger-col-actions .button:hover {
	transform: translateY(-1px);
	box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.meta-ledger-col-actions .dashicons {
	font-size: 16px;
	width: 16px;
	height: 16px;
	line-height: 1;
}

/* ========================================
   History Tab
   ======================================== */

.meta-ledger-history {
	display: flex;
	flex-direction: column;
	gap: 12px;
}

/* History Groups */
.meta-ledger-group {
	border: 1px solid #e5e7eb;
	border-radius: 8px;
	background: #fff;
	overflow: hidden;
	transition: all 0.2s ease;
}

.meta-ledger-group:hover {
	box-shadow: 0 2px 8px rgba(0,0,0,0.06);
	border-color: #d1d5db;
}

.meta-ledger-group-header {
	display: flex;
	align-items: center;
	gap: 14px;
	padding: 14px 18px;
	cursor: pointer;
	background: #f9fafb;
	transition: all 0.2s ease;
	flex-wrap: wrap;
}

.meta-ledger-group-header:hover {
	background: #f3f4f6;
}

.meta-ledger-group.open .meta-ledger-group-header {
	border-bottom: 1px solid #e5e7eb;
}

.meta-ledger-group-toggle {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 22px;
	height: 22px;
	font-size: 10px;
	color: #6b7280;
	background: transparent;
	border: none;
	border-radius: 4px;
	transition: all 0.2s ease;
	font-weight: 600;
}

.meta-ledger-group.open .meta-ledger-group-toggle {
	transform: rotate(90deg);
	background: transparent;
	border-color: transparent;
	color: #2563eb;
}

.meta-ledger-group-key {
	display: inline-block;
	background: transparent;
	color: #2563eb;
	padding: 0;
	border-radius: 0;
	font-size: 12px;
	font-weight: 600;
	font-family: 'SF Mono', Consolas, monospace;
}

.meta-ledger-group-latest {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	font-size: 11px;
	color: #374151;
	margin-left: 12px;
	font-family: 'SF Mono', Consolas, monospace;
	flex: 1;
	min-width: 0;
}

.meta-ledger-latest-value {
	color: #2563eb;
	font-weight: 600;
	max-width: 120px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	display: inline-block;
}

.meta-ledger-latest-arrow {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: auto;
	height: auto;
	background: transparent;
	border-radius: 0;
	color: #9ca3af;
	font-weight: 400;
	font-size: 14px;
	flex-shrink: 0;
	padding: 0 4px;
}

.meta-ledger-group-count {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	font-size: 12px;
	color: #6b7280;
	background: #f3f4f6;
	padding: 4px 10px;
	border-radius: 12px;
	font-weight: 500;
	margin-left: auto;
	flex-shrink: 0;
}

.meta-ledger-group-date {
	font-size: 11px;
	color: #9ca3af;
	margin-left: 12px;
}

/* Group Content */
.meta-ledger-group-content {
	display: none;
	background: #fff;
}

.meta-ledger-group.open .meta-ledger-group-content {
	display: block;
}

/* Entries Table */
.meta-ledger-entries-table {
	width: 100%;
	border-collapse: separate;
	border-spacing: 0;
	font-size: 12px;
}

.meta-ledger-entries-table th {
	text-align: left;
	padding: 12px 14px;
	background: #fafafa;
	border-bottom: 1px solid #e5e7eb;
	font-weight: 600;
	color: #374151;
	font-size: 10px;
	text-transform: uppercase;
	letter-spacing: 0.5px;
}

.meta-ledger-entries-table td {
	padding: 12px 14px;
	border-bottom: 1px solid #f3f4f6;
	vertical-align: middle;
}

.meta-ledger-entries-table tr:last-child td {
	border-bottom: none;
}

.meta-ledger-entries-table tr:hover td {
	background: #f9fafb;
}

/* Entry Columns */
.meta-ledger-entry-date {
	white-space: nowrap;
	color: #374151;
	font-size: 11px;
	font-weight: 500;
}

.meta-ledger-entry-action span {
	display: inline-block;
	padding: 4px 10px;
	border-radius: 4px;
	font-size: 10px;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.3px;
}

.meta-ledger-action-add {
	background: #d1fae5;
	color: #065f46;
}

.meta-ledger-action-update {
	background: #dbeafe;
	color: #1e40af;
}

.meta-ledger-action-delete {
	background: #fee2e2;
	color: #991b1b;
}

.meta-ledger-entry-old,
.meta-ledger-entry-new {
	max-width: 200px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	font-family: 'SF Mono', Consolas, monospace;
	font-size: 11px;
	color: #374151;
	font-weight: 500;
}

.meta-ledger-entry-old em,
.meta-ledger-entry-new em {
	color: #9ca3af;
	font-style: normal;
}

.meta-ledger-entry-user {
	color: #374151;
	font-size: 11px;
	font-weight: 500;
}

/* Source Button */
.meta-ledger-source-btn {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 5px 10px;
	background: #eff6ff;
	border: 1px solid #bfdbfe;
	border-radius: 4px;
	font-size: 10px;
	font-family: 'SF Mono', Consolas, monospace;
	color: #2563eb;
	cursor: pointer;
	transition: all 0.2s ease;
	max-width: 160px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	font-weight: 500;
}

.meta-ledger-source-btn:hover {
	background: #eff6ff;
	border-color: #2563eb;
	color: #2563eb;
}

.meta-ledger-source-btn svg {
	flex-shrink: 0;
	opacity: 0.7;
}

.meta-ledger-entry-actions {
	white-space: nowrap;
}

.meta-ledger-restore-btn {
	font-size: 11px !important;
	padding: 6px 14px !important;
	border-radius: 4px !important;
	font-weight: 500 !important;
	transition: all 0.2s ease !important;
}

.meta-ledger-restore-btn:hover {
	background: #f3f4f6 !important;
}

/* ========================================
   Source Popover
   ======================================== */

.meta-ledger-popover {
	position: absolute;
	z-index: 100001;
	background: #fff;
	border: 1px solid #e5e7eb;
	border-radius: 8px;
	box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
	width: 450px;
	max-width: calc(100vw - 40px);
	max-height: 350px;
	display: flex;
	flex-direction: column;
	font-size: 12px;
	overflow: hidden;
}

.meta-ledger-popover-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 14px 18px;
	background: #f9fafb;
	border-bottom: 1px solid #e5e7eb;
	font-weight: 600;
	color: #374151;
	font-size: 13px;
}

.meta-ledger-popover-close {
	background: none;
	border: none;
	font-size: 20px;
	color: #6b7280;
	cursor: pointer;
	padding: 0;
	line-height: 1;
	width: 28px;
	height: 28px;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 4px;
	transition: all 0.2s ease;
}

.meta-ledger-popover-close:hover {
	background: #f3f4f6;
	color: #2563eb;
}

.meta-ledger-popover-body {
	padding: 18px;
	overflow-y: auto;
	flex: 1;
}

.meta-ledger-popover-file {
	margin-bottom: 14px;
}

.meta-ledger-popover-file code {
	display: block;
	background: #2563eb;
	color: #fff;
	padding: 12px 14px;
	border-radius: 6px;
	font-size: 11px;
	word-break: break-all;
	font-family: 'SF Mono', Consolas, monospace;
	line-height: 1.6;
}

.meta-ledger-popover-function {
	margin-top: 12px;
	font-size: 11px;
	color: #374151;
}

.meta-ledger-popover-label {
	font-weight: 600;
	color: #6b7280;
	margin-right: 8px;
	text-transform: uppercase;
	font-size: 10px;
	letter-spacing: 0.5px;
}

.meta-ledger-popover-function code {
	background: #eff6ff;
	color: #2563eb;
	padding: 5px 10px;
	border-radius: 4px;
	font-size: 10px;
	font-family: 'SF Mono', Consolas, monospace;
	font-weight: 500;
}

.meta-ledger-popover-stack-header {
	font-weight: 600;
	color: #374151;
	margin-bottom: 10px;
	font-size: 10px;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	margin-top: 16px;
}

.meta-ledger-popover-stack pre {
	background: #f9fafb;
	border: 1px solid #e5e7eb;
	border-radius: 6px;
	padding: 12px 14px;
	font-size: 10px;
	font-family: 'SF Mono', Consolas, monospace;
	color: #374151;
	white-space: pre-wrap;
	word-break: break-all;
	margin: 0;
	max-height: 180px;
	overflow-y: auto;
	line-height: 1.6;
}

/* Value trigger (clickable truncated value in history) */
.meta-ledger-value-trigger {
	display: inline;
	background: none;
	border: none;
	padding: 0;
	margin: 0;
	font: inherit;
	color: #2563eb;
	cursor: pointer;
	text-decoration: none;
	text-align: left;
	max-width: 100%;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	vertical-align: baseline;
}

.meta-ledger-value-trigger:hover {
	text-decoration: underline;
	color: #1d4ed8;
}

/* Value popover: side-by-side diff */
.meta-ledger-value-popover {
	width: 720px;
	max-width: calc(100vw - 40px);
}

.meta-ledger-diff-body {
	display: flex;
	gap: 0;
	padding: 0;
	overflow: hidden;
	min-height: 120px;
}

.meta-ledger-diff-col {
	flex: 1;
	display: flex;
	flex-direction: column;
	min-width: 0;
	border-right: 1px solid #e5e7eb;
}

.meta-ledger-diff-col:last-child {
	border-right: none;
}

.meta-ledger-diff-col-label {
	flex-shrink: 0;
	padding: 10px 14px;
	font-size: 10px;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	color: #6b7280;
	border-bottom: 1px solid #e5e7eb;
}

.meta-ledger-diff-old .meta-ledger-diff-col-label {
	background: #fef2f2;
	color: #991b1b;
}

.meta-ledger-diff-new .meta-ledger-diff-col-label {
	background: #f0fdf4;
	color: #166534;
}

.meta-ledger-diff-col pre {
	flex: 1;
	background: #f9fafb;
	border: none;
	border-radius: 0;
	padding: 12px 14px;
	font-size: 11px;
	font-family: 'SF Mono', Consolas, monospace;
	color: #374151;
	white-space: pre-wrap;
	word-break: break-all;
	margin: 0;
	max-height: 280px;
	overflow-y: auto;
	line-height: 1.6;
}

.meta-ledger-diff-old pre {
	background: #fef2f2;
}

.meta-ledger-diff-new pre {
	background: #f0fdf4;
}

/* ========================================
   Responsive
   ======================================== */

@media screen and (max-width: 782px) {
	.meta-ledger-tabs {
		flex-direction: column;
	}

	.meta-ledger-tab {
		border-bottom: none;
		border-left: 3px solid transparent;
		padding: 12px 16px;
	}

	.meta-ledger-tab.active {
		border-left-color: #2563eb;
		border-bottom-color: transparent;
	}

	.meta-ledger-values-toolbar {
		flex-direction: column;
	}

	.meta-ledger-search {
		max-width: none;
		width: 100%;
	}

	.meta-ledger-col-key,
	.meta-ledger-col-value,
	.meta-ledger-col-actions {
		width: auto;
	}

	.meta-ledger-entries-table {
		display: block;
		overflow-x: auto;
	}

	.meta-ledger-popover {
		width: calc(100vw - 40px);
		left: 20px !important;
		right: 20px !important;
	}
}
