/**
 * PAP Afiliados Pro - Template Builder CSS
 *
 * Estilos para a página de Aparência (Template Builder).
 * Dependência CSS: papafpro-frontend-css (para preview do card).
 *
 * @package PAP_Afiliados_Pro
 * @since   2.0.0
 */

/* ==========================================================================
   LAYOUT GERAL
   ========================================================================== */

.papafpro-builder-wrap {
	display: flex;
	gap: 24px;
	flex-wrap: nowrap;
	margin-top: 20px;
}

.papafpro-builder-controls {
	flex: 1 1 0%;
	max-width: 65%;
	min-width: 500px;
}

.papafpro-builder-preview {
	flex: 0 0 35%;
	max-width: 35%;
	min-width: 280px;
	position: sticky;
	top: 32px;
	align-self: flex-start;
}

/* ==========================================================================
   ABAS
   ========================================================================== */

.papafpro-tabs {
	display: flex;
	border-bottom: 2px solid #ddd;
	margin-bottom: 16px;
	flex-wrap: wrap;
	gap: 4px 0;
}

.papafpro-tab {
	padding: 8px 14px;
	cursor: pointer;
	border-bottom: 2px solid transparent;
	margin-bottom: -2px;
	text-decoration: none;
	color: #555;
	font-size: 13px;
	transition: color 0.2s, border-color 0.2s;
	white-space: nowrap;
	flex-shrink: 0;
}

.papafpro-tab:hover {
	color: #0073aa;
}

.papafpro-tab.active {
	border-bottom-color: #0073aa;
	color: #0073aa;
	font-weight: 600;
}

.papafpro-tab-content {
	display: none;
}

.papafpro-tab-content.active {
	display: block;
}

/* ==========================================================================
   CAMPOS DE CONTROLE
   ========================================================================== */

.papafpro-control-group {
	margin-bottom: 16px;
}

.papafpro-control-group label {
	display: block;
	font-weight: 600;
	margin-bottom: 4px;
	font-size: 13px;
}

.papafpro-control-group select,
.papafpro-control-group input[type="number"],
.papafpro-control-group input[type="text"]:not(.wp-color-picker) {
	width: 100%;
}

.papafpro-control-group textarea {
	width: 100%;
	min-height: 100px;
	font-family: monospace;
	font-size: 12px;
}

.papafpro-control-group .description {
	color: #666;
	font-size: 12px;
	margin-top: 2px;
}

.papafpro-control-group-inline {
	display: flex;
	align-items: center;
	gap: 8px;
}

.papafpro-control-group-inline label {
	display: inline;
	font-weight: normal;
	margin-bottom: 0;
}

/* ==========================================================================
   PREVIEW
   ========================================================================== */

.papafpro-preview-container {
	padding: 20px;
	background: #f5f5f5;
	border: 1px solid #ddd;
	border-radius: 8px;
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: auto;
	max-height: none;
	overflow: visible;
}

.papafpro-preview-container .papafpro-single-card {
	width: 100%;
	max-width: 280px;
	margin: 0 auto;
}

.papafpro-preview-container .papafpro-single-card .papafpro-card {
	/* box-shadow delegada para card_style classes do frontend CSS */
}

.papafpro-preview-container .papafpro-single-card.papafpro-layout-list,
.papafpro-preview-container .papafpro-single-card:has(.papafpro-template-horizontal) {
	max-width: 100%;
}

.papafpro-preview-container .papafpro-single-card:has(.papafpro-template-minimal) {
	max-width: 100%;
}

.papafpro-preview-container .papafpro-card__content {
	padding: 16px;
	background: var(--papafpro-card-bg, #ffffff);
	border-radius: 0 0 8px 8px;
}

.papafpro-preview-container .papafpro-card__title {
	font-size: var(--papafpro-title-size, 16px);
	/* Use the same var as the frontend so the Title Font Weight control
	   reflects in the preview. This preview-scoped selector (specificity
	   0,0,2,0) was shadowing the frontend rule with a hardcoded weight. */
	font-weight: var(--papafpro-title-weight, 600);
	margin: 0 0 8px 0;
	color: var(--papafpro-primary-color, #333);
}

.papafpro-preview-container .papafpro-card__description {
	font-size: var(--papafpro-desc-size, 14px);
	margin: 0 0 12px 0;
	color: var(--papafpro-text-color, #666);
	line-height: 1.4;
}

.papafpro-preview-container .papafpro-card__price {
	font-size: var(--papafpro-price-size, 20px);
	/* Use the same var as the frontend so the Price Font Weight control
	   reflects in the preview (was hardcoded, shadowing the variable). */
	font-weight: var(--papafpro-price-weight, 700);
	margin: 0 0 12px 0;
	color: var(--papafpro-price-color, #e74c3c);
}

.papafpro-preview-container .papafpro-card__button {
	width: 100%;
	padding: 12px 16px;
	font-size: 14px;
	font-weight: 600;
	/* border delegada para button_style classes do frontend CSS (outline usa border) */
	cursor: pointer;
	text-align: center;
	transition: all 0.3s ease;
	box-sizing: border-box;
}

/* Minimal preview: restore compact horizontal strip from frontend.
   Overrides generic preview rules (button width, content padding,
   title/price sizes) that style Minimal as a vertical card. */
.papafpro-preview-container .papafpro-template-minimal .papafpro-card__content {
	padding: 12px 16px;
}

.papafpro-preview-container .papafpro-template-minimal .papafpro-card__image-area {
	flex: 0 0 auto;
	aspect-ratio: 1 / 1;
	min-width: 80px;
	max-width: 180px;
	height: auto;
}

.papafpro-preview-container .papafpro-template-minimal > .papafpro-card__button {
	width: auto;
	padding: 8px 16px;
}

.papafpro-preview-container .papafpro-template-minimal .papafpro-card__title {
	font-size: var(--papafpro-title-size, 15px);
	margin: 0;
}

.papafpro-preview-container .papafpro-template-minimal .papafpro-card__price {
	font-size: var(--papafpro-price-size, 13px);
	margin: 0;
}

.papafpro-preview-title {
	font-size: 14px;
	color: #666;
	margin-bottom: 12px;
}

/* Loading state do preview */
.papafpro-preview-container.papafpro-loading {
	opacity: 0.6;
	pointer-events: none;
	position: relative;
}

.papafpro-preview-container.papafpro-loading::after {
	content: '';
	position: absolute;
	top: 50%;
	left: 50%;
	width: 40px;
	height: 40px;
	margin: -20px 0 0 -20px;
	border: 4px solid #f3f3f3;
	border-top: 4px solid #3498db;
	border-radius: 50%;
	animation: papafpro-spin 1s linear infinite;
}

@keyframes papafpro-spin {
	0% { transform: rotate(0deg); }
	100% { transform: rotate(360deg); }
}

/* ==========================================================================
   PRESETS
   ========================================================================== */

.papafpro-presets-section {
	margin-top: 24px;
	border-top: 1px solid #ddd;
	padding-top: 16px;
}

/* =============================================
   Preset List Table
   ============================================= */

.papafpro-preset-list {
	border-collapse: collapse;
	width: 100%;
	margin-top: 8px;
}

/* ----- Header ----- */

.papafpro-preset-list thead th {
	background-color: #f1f1f1;
	border-bottom: 2px solid #ddd;
	font-weight: 600;
	font-size: 12px;
	color: #555;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	padding: 8px 12px;
	text-align: left;
}

.papafpro-preset-list thead th.papafpro-col-check {
	width: 30px;
	padding: 8px;
	text-align: center;
}

.papafpro-preset-list thead th.papafpro-col-id {
	width: 60px;
	text-align: center;
}

.papafpro-preset-list thead th.papafpro-col-shortcode {
	width: 220px;
	text-align: left;
}

.papafpro-preset-list thead th.papafpro-col-actions {
	width: 220px;
	text-align: center;
}

/* ----- Body rows ----- */

.papafpro-preset-list tbody td {
	padding: 8px 12px;
	border-bottom: 1px solid #eee;
	vertical-align: middle;
}

.papafpro-preset-list tbody td.papafpro-col-check {
	width: 30px;
	padding: 8px;
	text-align: center;
}

.papafpro-preset-list tbody td.papafpro-col-id {
	text-align: center;
}

.papafpro-preset-list tbody td.papafpro-col-shortcode {
	white-space: nowrap;
}

.papafpro-preset-list tbody td.papafpro-col-shortcode code {
	font-family: Consolas, Monaco, monospace;
	font-size: 12px;
	background: #f0f0f1;
	padding: 2px 6px;
	border-radius: 3px;
	user-select: all;
}

.papafpro-preset-list .papafpro-copy-btn {
	background: none;
	border: none;
	cursor: pointer;
	padding: 2px 4px;
	margin-left: 4px;
	color: #2271b1;
	vertical-align: middle;
	line-height: 1;
}

.papafpro-preset-list .papafpro-copy-btn:hover {
	color: #135e96;
}

.papafpro-preset-list .papafpro-copy-btn .dashicons {
	font-size: 16px;
	width: 16px;
	height: 16px;
}

.papafpro-preset-list .papafpro-copy-feedback {
	display: none;
	margin-left: 6px;
	color: #00a32a;
	font-size: 12px;
	vertical-align: middle;
}

.papafpro-preset-list tbody td.papafpro-col-actions {
	text-align: center;
}

/* ----- Zebra striping ----- */

.papafpro-preset-list tbody tr:nth-child(even) {
	background-color: #f9f9f9;
}

/* ----- Hover ----- */

.papafpro-preset-list tbody tr:hover {
	background-color: #e8f4fd;
}

/* ----- Name column ----- */

.papafpro-preset-list td.papafpro-col-name label {
	display: block;
	cursor: default;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	max-width: 400px;
}

/* ----- ID badge ----- */

.papafpro-preset-id {
	display: inline-block;
	font-size: 11px;
	color: #888;
	background: #f0f0f0;
	padding: 2px 6px;
	border-radius: 3px;
	font-family: monospace;
	white-space: nowrap;
	cursor: default;
}

/* ----- Action buttons ----- */

.papafpro-preset-actions {
	display: flex;
	gap: 6px;
	justify-content: center;
}

.papafpro-preset-actions .button {
	padding: 0 8px;
	min-height: 28px;
	line-height: 26px;
	font-size: 12px;
}

/* ==========================================================================
   BOTÕES
   ========================================================================== */

.papafpro-builder-actions {
	margin-top: 16px;
	display: flex;
	gap: 8px;
	flex-wrap: wrap;
}

.papafpro-btn-danger {
	background: #dc3545;
	color: #fff;
	border-color: #dc3545;
}

.papafpro-btn-danger:hover {
	background: #c82333;
	border-color: #bd2130;
	color: #fff;
}

/* ==========================================================================
   FEEDBACK
   ========================================================================== */

.papafpro-notice {
	padding: 8px 12px;
	border-left: 4px solid;
	margin-bottom: 12px;
	background: #fff;
}

.papafpro-notice--success {
	border-color: #46b450;
	background: #ecf7ed;
}

.papafpro-notice--error {
	border-color: #dc3232;
	background: #fbeaea;
}

/* ==========================================================================
   SECTION CARDS - Agrupamento de campos
   ========================================================================== */

.papafpro-section-grid {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 20px;
	margin-bottom: 20px;
}

.papafpro-section-card {
	background: #fff;
	border: 1px solid #e0e0e0;
	border-radius: 8px;
	padding: 0;
	overflow: hidden;
}

.papafpro-section-title {
	display: flex;
	align-items: center;
	gap: 8px;
	margin: 0;
	padding: 12px 16px;
	font-size: 14px;
	font-weight: 600;
	color: #1d2327;
	border-bottom: 1px solid #e0e0e0;
	background: #f9f9f9;
}

.papafpro-section-title .dashicons {
	color: #2271b1;
	font-size: 18px;
	width: 18px;
	height: 18px;
}

.papafpro-section-content {
	padding: 16px;
}

.papafpro-section-content .papafpro-control-group:last-child {
	margin-bottom: 0;
}

/* ==========================================================================
   ACCORDIONS — native <details>/<summary> (v2.6.0 F5)
   ========================================================================== */

.papafpro-accordion {
	background: #fff;
	border: 1px solid #e0e0e0;
	border-radius: 8px;
	margin-bottom: 12px;
	overflow: hidden;
}

.papafpro-accordion[open] {
	border-color: #c0d2e8;
}

.papafpro-accordion__header {
	display: flex;
	align-items: center;
	gap: 8px;
	margin: 0;
	padding: 12px 16px;
	font-size: 14px;
	font-weight: 600;
	color: #1d2327;
	background: #f9f9f9;
	cursor: pointer;
	list-style: none;
	user-select: none;
}

.papafpro-accordion[open] > .papafpro-accordion__header {
	border-bottom: 1px solid #e0e0e0;
	background: #f0f5fb;
}

.papafpro-accordion__header::-webkit-details-marker {
	display: none;
}

.papafpro-accordion__header::after {
	content: '\f140';
	font-family: dashicons;
	font-size: 18px;
	line-height: 1;
	color: #2271b1;
	margin-left: auto;
	transition: transform 0.2s ease;
}

.papafpro-accordion[open] > .papafpro-accordion__header::after {
	transform: rotate(180deg);
}

.papafpro-accordion__icon {
	color: #2271b1;
	font-size: 18px;
	width: 18px;
	height: 18px;
	flex-shrink: 0;
}

.papafpro-accordion__body {
	padding: 16px;
}

.papafpro-accordion__body .papafpro-control-group:last-child {
	margin-bottom: 0;
}

/* ==========================================================================
   CONDITIONAL FIELDS — v2.5.0
   ========================================================================== */

.papafpro-conditional-field {
	display: none;
}

.papafpro-conditional-field.is-visible {
	display: block;
}

/* ==========================================================================
   Disabled conditional fields — template availability (CT1 v2)
   ========================================================================== */

.papafpro-field--disabled {
	opacity: 0.45;
	position: relative;
	cursor: not-allowed;
	transition: opacity 0.2s ease;
}

.papafpro-field--disabled input,
.papafpro-field--disabled select,
.papafpro-field--disabled textarea {
	pointer-events: none;
	cursor: not-allowed;
}

.papafpro-field-notice {
	display: block;
	font-size: 12px;
	color: #646970;
	font-style: italic;
	margin-top: 4px;
	line-height: 1.4;
}

/* ==========================================================================
   TYPOGRAPHY TAB — v2.5.0
   ========================================================================== */

.papafpro-control-group input[type="range"] {
	width: 100%;
	max-width: 300px;
	vertical-align: middle;
}

.papafpro-range-value {
	display: inline-block;
	min-width: 48px;
	text-align: right;
	font-weight: 600;
	color: #1d2327;
	margin-left: 8px;
}

/* ==========================================================================
   RESPONSIVO
   ========================================================================== */

/* ==========================================================================
   PRESET EDITING CONTEXT BAR
   ========================================================================== */

.papafpro-preset-editing-bar {
	background: #fff3cd;
	border: 1px solid #ffc107;
	border-radius: 4px;
	padding: 10px 16px;
	margin-bottom: 16px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
}

.papafpro-preset-editing-label {
	font-size: 14px;
	color: #664d03;
}

.papafpro-back-to-global {
	white-space: nowrap;
}

/* Tablet: empilhar verticalmente */
@media (max-width: 1024px) {
	.papafpro-builder-wrap {
		flex-direction: column;
	}

	.papafpro-builder-controls {
		flex: 1 1 100%;
		max-width: 100%;
		min-width: auto;
	}

	.papafpro-builder-preview {
		flex: 1 1 100%;
		max-width: 100%;
		position: static;
	}

	.papafpro-section-grid {
		grid-template-columns: 1fr;
	}
}

/* ==========================================================================
   Preset Preview Modal
   ========================================================================== */

.papafpro-preset-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 100000; /* acima do admin bar (99999) */
    display: none; /* hidden by default; toggled via --active modifier */
    align-items: center;
    justify-content: center;
}

.papafpro-preset-modal.papafpro-preset-modal--active {
    display: flex;
}

.papafpro-preset-modal__backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
}

.papafpro-preset-modal__dialog {
    position: relative;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    max-width: 480px;
    width: 90%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.papafpro-preset-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #dcdcde;
    flex-shrink: 0;
}

.papafpro-preset-modal__title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #1d2327;
}

.papafpro-preset-modal__title span {
    font-weight: 400;
}

.papafpro-preset-modal__close {
    background: none;
    border: none;
    cursor: pointer;
    color: #50575e;
    padding: 4px;
    line-height: 1;
    border-radius: 4px;
    transition: background-color 0.15s ease;
}

.papafpro-preset-modal__close:hover {
    background: #f0f0f1;
    color: #1d2327;
}

.papafpro-preset-modal__body {
    padding: 20px;
    overflow-y: auto;
    flex-grow: 1;
}

.papafpro-preset-modal__loading {
    text-align: center;
    padding: 40px 0;
}

.papafpro-preset-modal__loading .spinner {
    float: none;
    margin: 0 auto;
}

.papafpro-preset-modal__footer {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding: 16px 20px;
    border-top: 1px solid #dcdcde;
    flex-shrink: 0;
}

/* Card dentro do modal — reset de width para caber */
.papafpro-preset-modal__body .papafpro-card {
    max-width: 100%;
    margin: 0 auto;
}

.papafpro-preset-modal__body .papafpro-card img {
    max-width: 100%;
    height: auto;
}

/* Responsivo */
@media (max-width: 600px) {
    .papafpro-preset-modal__dialog {
        width: 95%;
        max-height: 95vh;
    }

    .papafpro-preset-modal__footer {
        flex-direction: column;
    }

    .papafpro-preset-modal__footer .button {
        width: 100%;
        text-align: center;
    }
}
