/**
 * Customize WP Emails - Admin Styles
 * Aligned with Email Logs / Options Page Builder / shared PageHero screens.
 *
 * @package CustomWpEmails
 * @since 1.1.0
 */

.wpps-cwe-wrap {
	--wpps-cwe-accent: var(--wpps-accent, var(--wp-admin-theme-color, #2271b1));
	--wpps-cwe-accent-hover: var(--wpps-accent-hover, var(--wp-admin-theme-color-darker-10, #135e96));
	--wpps-cwe-accent-bg: color-mix(in srgb, var(--wpps-cwe-accent) 12%, #fff);
	--wpps-cwe-black: #1d2327;
	--wpps-cwe-gray: #646970;
	--wpps-cwe-border: #c3c4c7;
	--wpps-cwe-divider: #dcdcde;
	--wpps-cwe-bg: #f6f7f7;
	--wpps-cwe-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

/* Modals and floating panels sit outside .wpps-cwe-wrap — share the same tokens. */
.wpps-cwe-modal,
.wpps-cwe-smartcode-panel {
	--wpps-cwe-accent: var(--wpps-accent, var(--wp-admin-theme-color, #2271b1));
	--wpps-cwe-accent-hover: var(--wpps-accent-hover, var(--wp-admin-theme-color-darker-10, #135e96));
	--wpps-cwe-accent-bg: color-mix(in srgb, var(--wpps-cwe-accent) 12%, #fff);
	--wpps-cwe-black: #1d2327;
	--wpps-cwe-gray: #646970;
	--wpps-cwe-border: #c3c4c7;
	--wpps-cwe-divider: #dcdcde;
	--wpps-cwe-bg: #f6f7f7;
	--wpps-cwe-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.wrap.wpps-cwe-wrap {
	margin: 20px 20px 20px 0;
}

.wrap.wpps-cwe-wrap .wpps-page-hero__meta .button {
	margin: 0;
}

/* Panels */
.wpps-cwe-wrap .wpps-cwe-panel {
	background: #fff;
	border: 1px solid var(--wpps-cwe-border);
	box-shadow: var(--wpps-cwe-shadow);
	padding: 20px 24px;
	margin: 0 0 24px;
}

.wpps-cwe-wrap .wpps-cwe-panel:last-child {
	margin-bottom: 0;
}

.wpps-cwe-wrap .wpps-cwe-section-title {
	margin: 0 0 16px;
	padding: 0 0 12px;
	border-bottom: 1px solid var(--wpps-cwe-divider);
	font-size: 16px;
	font-weight: 600;
	color: var(--wpps-cwe-black);
}

/* Status badge */
.wpps-cwe-wrap .wpps-cwe-status-badge {
	display: inline-block;
	padding: 4px 10px;
	background: var(--wpps-cwe-bg);
	border-radius: 4px;
	font-size: 12px;
	font-weight: 500;
	color: var(--wpps-cwe-gray);
}

.wpps-cwe-wrap .wpps-cwe-status-badge.wpps-cwe-status-customized {
	background: var(--wpps-cwe-accent-bg);
	color: var(--wpps-cwe-accent-hover);
}

/* Tables */
.wpps-cwe-wrap .wpps-cwe-table {
	width: 100%;
	border-collapse: collapse;
	margin-top: 4px;
}

.wpps-cwe-wrap .wpps-cwe-table th,
.wpps-cwe-wrap .wpps-cwe-table td {
	padding: 12px 16px;
	text-align: left;
	border-bottom: 1px solid var(--wpps-cwe-divider);
	vertical-align: top;
}

.wpps-cwe-wrap .wpps-cwe-table thead th {
	background: var(--wpps-cwe-bg);
	font-weight: 600;
	font-size: 13px;
	color: var(--wpps-cwe-black);
}

.wpps-cwe-wrap .wpps-cwe-table tbody tr:hover {
	background: #fafafa;
}

.wpps-cwe-wrap .wpps-cwe-table .description {
	color: var(--wpps-cwe-gray);
}

/* Logo upload */
.wpps-cwe-wrap .wpps-cwe-logo-wrap {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 12px;
}

.wpps-cwe-wrap .wpps-cwe-logo-preview img {
	border: 1px solid var(--wpps-cwe-border);
	border-radius: 4px;
}

.wpps-cwe-wrap .wpps-cwe-logo-font-row {
	display: flex;
	flex-wrap: wrap;
	gap: 24px 32px;
}

.wpps-cwe-wrap .wpps-cwe-field-cell {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.wpps-cwe-wrap .wpps-cwe-field-cell .wpps-cwe-color-label {
	margin-bottom: 0;
}

/* Email Sender */
.wpps-cwe-wrap .wpps-cwe-sender-grid {
	display: grid;
	grid-template-columns: repeat(2, 1fr);
	gap: 20px 32px;
}

.wpps-cwe-wrap .wpps-cwe-sender-cell {
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.wpps-cwe-wrap .wpps-cwe-sender-label,
.wpps-cwe-wrap .wpps-cwe-color-label {
	font-weight: 600;
	font-size: 13px;
	color: var(--wpps-cwe-black);
}

.wpps-cwe-wrap .wpps-cwe-sender-cell .wpps-cwe-input {
	width: 100%;
	max-width: 100%;
}

/* Color grid */
.wpps-cwe-wrap .wpps-cwe-color-grid {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 20px 24px;
	margin-top: 8px;
}

.wpps-cwe-wrap .wpps-cwe-color-cell {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.wpps-cwe-wrap .wpps-cwe-panel .wpps-color-field-row {
	display: inline-flex;
	align-items: center;
	gap: 10px;
	flex-wrap: nowrap;
}

.wpps-cwe-wrap .wpps-cwe-panel .wpps-color-picker-circle {
	width: 40px !important;
	height: 40px !important;
	min-width: 40px;
	min-height: 40px;
	flex-shrink: 0;
	border-radius: 50% !important;
	border: 2px solid #ddd !important;
	padding: 0 !important;
	cursor: pointer;
	-webkit-appearance: none !important;
	-moz-appearance: none !important;
	appearance: none !important;
	overflow: hidden;
}

.wpps-cwe-wrap .wpps-cwe-panel .wpps-color-picker-circle::-webkit-color-swatch-wrapper {
	padding: 0 !important;
	margin: 0 !important;
	border: none !important;
	border-radius: 50% !important;
}

.wpps-cwe-wrap .wpps-cwe-panel .wpps-color-picker-circle::-webkit-color-swatch {
	border: none !important;
	border-radius: 50% !important;
	width: 100% !important;
	height: 100% !important;
}

.wpps-cwe-wrap .wpps-cwe-panel .wpps-color-picker-circle::-moz-color-swatch {
	border: none !important;
	border-radius: 50% !important;
	width: 100% !important;
	height: 100% !important;
}

.wpps-cwe-wrap .wpps-cwe-panel .wpps-color-code-wrap {
	display: inline-block;
	position: relative;
	margin: 0;
	flex-shrink: 0;
}

.wpps-cwe-wrap .wpps-cwe-panel .wpps-color-code-wrap .wpps-color-reset {
	position: absolute;
	right: 5px;
	top: 50%;
	transform: translateY(-50%);
	padding: 0;
	margin: 0;
	background: none;
	border: none;
	cursor: pointer;
	color: var(--wpps-cwe-gray);
}

.wpps-cwe-wrap .wpps-cwe-panel .wpps-color-code-wrap .wpps-color-reset:hover {
	color: var(--wpps-cwe-accent);
}

.wpps-cwe-wrap .wpps-cwe-panel .wpps-color-code-wrap .wpps-color-reset .dashicons {
	font-size: 16px;
	width: 16px;
	height: 16px;
}

.wpps-cwe-wrap .wpps-cwe-panel .wpps-color-code-wrap .wpps-color-code-input {
	box-sizing: border-box;
	padding: 8px 28px 8px 10px;
	border: 1px solid var(--wpps-cwe-border);
	border-radius: 4px;
	font-size: 13px;
}

/* Form inputs */
.wpps-cwe-wrap .wpps-cwe-input {
	box-sizing: border-box;
	width: 100%;
	min-width: 0;
	padding: 8px 12px;
	border: 1px solid var(--wpps-cwe-border);
	border-radius: 4px;
	font-size: 13px;
}

.wpps-cwe-wrap .wpps-cwe-input:focus {
	outline: none;
	border-color: var(--wpps-cwe-accent);
	box-shadow: 0 0 0 1px var(--wpps-cwe-accent);
}

/* Actions row */
.wpps-cwe-wrap .wpps-cwe-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	align-items: center;
	justify-content: space-between;
	margin-top: 20px;
	padding-top: 20px;
	border-top: 1px solid var(--wpps-cwe-divider);
}

.wpps-cwe-wrap .wpps-cwe-actions .wpps-cwe-actions-left {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	align-items: center;
}

.wpps-cwe-wrap .wpps-cwe-preview-toolbar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	margin-bottom: 16px;
}

.wpps-cwe-wrap .wpps-cwe-preview-toolbar .wpps-cwe-section-title {
	margin: 0;
	padding: 0;
	border: none;
}

.wpps-cwe-wrap .wpps-cwe-preview-toolbar-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
}

/* Preview */
.wpps-cwe-wrap .wpps-preview-container {
	margin-top: 0;
}

.wpps-cwe-wrap .wpps-cwe-preview-frame,
.wpps-cwe-modal .wpps-cwe-preview-frame {
	display: block;
	width: 100%;
	height: 450px;
	min-height: 400px;
	max-height: 500px;
	border: 1px solid var(--wpps-cwe-border);
	background: #fff;
	border-radius: 2px;
	box-sizing: border-box;
}

/* Modals */
.wpps-cwe-modal {
	display: none;
	position: fixed;
	inset: 0;
	z-index: 100000;
	align-items: center;
	justify-content: center;
	padding: 20px;
}

.wpps-cwe-modal.is-open {
	display: flex;
}

.wpps-cwe-modal-backdrop {
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, 0.5);
	cursor: pointer;
}

.wpps-cwe-modal-content {
	position: relative;
	z-index: 1;
	background: #fff;
	max-width: 700px;
	width: 100%;
	max-height: 90vh;
	overflow: auto;
	padding: 24px;
	border-radius: 2px;
	box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.wpps-cwe-modal-content h3 {
	margin: 0 0 16px;
	font-size: 1.125rem;
	font-weight: 600;
	color: var(--wpps-cwe-black);
}

/* Preview email modal — markup lives outside .wpps-cwe-wrap */
#wpps-preview-modal .wpps-cwe-modal-content {
	display: flex;
	flex-direction: column;
	max-width: 700px;
	max-height: 90vh;
	overflow: hidden;
}

#wpps-preview-modal .wpps-cwe-preview-frame {
	flex: 1 1 auto;
	width: 100%;
	height: 450px;
	min-height: 400px;
	max-height: calc(90vh - 140px);
	margin: 0;
	padding: 0;
}

#wpps-preview-modal .wpps-cwe-modal-actions {
	flex-shrink: 0;
	margin: 16px 0 0;
}

.wpps-cwe-modal .wpps-cwe-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	padding: 0 16px;
	min-height: 40px;
	line-height: 1;
	border-radius: 2px;
	font-size: 13px;
	font-weight: 500;
	cursor: pointer;
	border: none;
	text-decoration: none;
	transition: background 0.2s, color 0.2s, border-color 0.2s;
	box-sizing: border-box;
}

.wpps-cwe-modal .wpps-cwe-btn-secondary {
	background: #fff;
	border: 1px solid var(--wpps-cwe-border);
	color: var(--wpps-cwe-black);
}

.wpps-cwe-modal .wpps-cwe-btn-secondary:hover {
	background: rgba(34, 113, 177, 0.04);
	border-color: var(--wpps-cwe-accent);
	color: var(--wpps-cwe-accent-hover);
}

/* SmartCode panel */
.wpps-cwe-smartcode-panel {
	display: none;
	position: fixed;
	background: #fff;
	border: 1px solid var(--wpps-cwe-border);
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
	z-index: 100001;
	max-height: 280px;
	overflow: hidden;
	flex-direction: column;
}

.wpps-cwe-smartcode-panel.is-open {
	display: flex;
}

.wpps-cwe-smartcode-panel-tabs {
	display: flex;
	border-bottom: 1px solid var(--wpps-cwe-divider);
	flex-shrink: 0;
}

.wpps-cwe-smartcode-tab {
	flex: 1;
	padding: 10px 14px;
	border: none;
	background: none;
	cursor: pointer;
	font-size: 13px;
	font-weight: 500;
	color: var(--wpps-cwe-gray);
	transition: color 0.15s, background 0.15s;
}

.wpps-cwe-smartcode-tab:hover {
	color: var(--wpps-cwe-black);
}

.wpps-cwe-smartcode-tab.is-active {
	color: var(--wpps-cwe-accent);
	background: var(--wpps-cwe-accent-bg);
	font-weight: 600;
}

.wpps-cwe-smartcode-panel-content {
	flex: 1;
	overflow-y: auto;
	padding: 8px 0;
}

.wpps-cwe-smartcode-tab-pane {
	display: none;
	padding: 0 8px;
}

.wpps-cwe-smartcode-tab-pane.is-active {
	display: block;
}

.wpps-cwe-smartcode-item {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	width: 100%;
	text-align: left;
	padding: 8px 12px;
	border: none;
	background: none;
	cursor: pointer;
	font-size: 13px;
	color: var(--wpps-cwe-black);
	transition: background 0.15s;
}

.wpps-cwe-smartcode-item:hover {
	background: var(--wpps-cwe-accent-bg);
	color: var(--wpps-cwe-accent-hover);
}

.wpps-cwe-smartcode-label {
	font-weight: 500;
	margin-bottom: 2px;
}

.wpps-cwe-smartcode-code {
	font-size: 12px;
	color: var(--wpps-cwe-gray);
	font-family: monospace;
	background: var(--wpps-cwe-bg);
	padding: 2px 6px;
	border-radius: 4px;
}

.wpps-smartcode-media-btn {
	margin-left: 4px;
}

/* Notice / info box */
.wpps-cwe-wrap .wpps-cwe-notice-box {
	padding: 12px 16px;
	background: #fcf9e8;
	border-left: 4px solid #dba617;
	margin: 12px 0;
	font-size: 13px;
}

@media (max-width: 782px) {
	.wpps-cwe-wrap .wpps-cwe-sender-grid,
	.wpps-cwe-wrap .wpps-cwe-color-grid {
		grid-template-columns: 1fr;
	}

	.wpps-cwe-wrap .wpps-cwe-actions {
		flex-direction: column;
		align-items: stretch;
	}

	.wpps-cwe-wrap .wpps-cwe-actions .wpps-cwe-actions-left {
		width: 100%;
	}
}
