/**
 * OpenFields Repeater Styles
 *
 * Clean, modern styles that follow WordPress admin design patterns.
 * Uses CSS custom properties for theming.
 *
 * @package OpenFields
 * @since   1.0.0
 */

/* ==========================================================================
   CSS Custom Properties
   ========================================================================== */

.cofld-repeater {
	--of-border-color: #c3c4c7;
	--of-border-radius: 4px;
	--of-spacing-xs: 4px;
	--of-spacing-sm: 8px;
	--of-spacing-md: 12px;
	--of-spacing-lg: 16px;
	--of-row-bg: #fff;
	--of-handle-color: #787c82;
	--of-transition: 0.15s ease;
}

/* ==========================================================================
   Repeater Container
   ========================================================================== */

.cofld-repeater {
	box-sizing: border-box;
}

.cofld-repeater *,
.cofld-repeater *::before,
.cofld-repeater *::after {
	box-sizing: border-box;
}

/* ==========================================================================
   Rows Container
   ========================================================================== */

.cofld-repeater-rows {
	display: flex;
	flex-direction: column;
	gap: var(--of-spacing-sm);
}

/* ==========================================================================
   Single Row
   ========================================================================== */

.cofld-repeater-row {
	display: flex;
	align-items: stretch;
	background: var(--of-row-bg);
	border: 1px solid var(--of-border-color);
	border-radius: var(--of-border-radius);
	overflow: hidden;
	transition: box-shadow var(--of-transition), opacity var(--of-transition), transform var(--of-transition);
}

.cofld-repeater-row:hover {
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.cofld-repeater-row.is-dragging {
	opacity: 0.5;
}

/* ==========================================================================
   Row Handle
   ========================================================================== */

.cofld-repeater-row-handle {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 2px;
	padding: var(--of-spacing-sm);
	background: #f6f7f7;
	border-right: 1px solid var(--of-border-color);
	cursor: grab;
	min-width: 40px;
	color: var(--of-handle-color);
	user-select: none;
}

.cofld-repeater-row-handle:hover {
	background: #f0f0f1;
}

.cofld-repeater-row-handle:active {
	cursor: grabbing;
}

.cofld-repeater-row-handle .dashicons {
	font-size: 16px;
	width: 16px;
	height: 16px;
}

.cofld-repeater-row-index {
	font-size: 11px;
	font-weight: 500;
	color: #787c82;
}

/* ==========================================================================
   Row Content
   ========================================================================== */

.cofld-repeater-row-content {
	flex: 1;
	display: flex;
	flex-wrap: wrap;
	gap: var(--of-spacing-md);
	padding: var(--of-spacing-md);
	min-width: 0;
}

/* Collapsed state */
.cofld-repeater-row.is-collapsed .cofld-repeater-row-content {
	display: none;
}

/* ==========================================================================
   Row Actions
   ========================================================================== */

.cofld-repeater-row-actions {
	display: flex;
	flex-direction: column;
	gap: 2px;
	padding: var(--of-spacing-xs);
	border-left: 1px solid var(--of-border-color);
	background: #f6f7f7;
}

.cofld-repeater-row-actions button {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 28px;
	height: 28px;
	padding: 0;
	margin: 0;
	background: transparent;
	border: none;
	border-radius: 3px;
	cursor: pointer;
	color: #787c82;
	transition: background var(--of-transition), color var(--of-transition);
}

.cofld-repeater-row-actions button:hover {
	background: #dcdcde;
	color: #1d2327;
}

.cofld-repeater-row-actions button:disabled {
	opacity: 0.4;
	cursor: not-allowed;
}

.cofld-repeater-row-actions button .dashicons {
	font-size: 16px;
	width: 16px;
	height: 16px;
}

.cofld-repeater-row-remove:hover {
	color: #d63638 !important;
}

/* ==========================================================================
   Subfields
   ========================================================================== */

.cofld-repeater-subfield {
	display: flex;
	flex-direction: column;
	gap: var(--of-spacing-xs);
	min-width: 0;
	box-sizing: border-box;
	/* Flex: shrink=0 (don't shrink), grow=0 (don't grow), basis=width from custom property */
	flex: 0 0 calc(var(--of-field-width, 100%) - calc(var(--of-spacing-xs)*2));
	/* Width also set for IE fallback */
	width: var(--of-field-width, 100%);
}

.cofld-repeater-subfield-label {
	font-weight: 500;
	font-size: 13px;
	color: #1e1e1e;
}

.cofld-repeater-subfield-label .required {
	color: #d63638;
	margin-left: 2px;
}

.cofld-repeater-subfield .description {
	margin: 4px 0 0;
	font-size: 12px;
	color: #646970;
}

/* ==========================================================================
   Footer / Add Button
   ========================================================================== */

.cofld-repeater-footer {
	margin-top: var(--of-spacing-sm);
}

.cofld-repeater-add {
	display: inline-flex !important;
	align-items: center;
	gap: 4px;
}

.cofld-repeater-add .dashicons {
	font-size: 16px;
	width: 16px;
	height: 16px;
}

/* ==========================================================================
   Drag Placeholder
   ========================================================================== */

.cofld-repeater-placeholder {
	border: 2px dashed #c3c4c7;
	border-radius: var(--of-border-radius);
	background: #f6f7f7;
	transition: height var(--of-transition);
}

/* ==========================================================================
   Nested Repeaters
   ========================================================================== */

.cofld-repeater .cofld-repeater {
	margin-top: var(--of-spacing-xs);
	padding: var(--of-spacing-sm);
	background: #f9f9f9;
	border: 1px solid #e0e0e0;
	border-radius: var(--of-border-radius);
}

.cofld-repeater .cofld-repeater .cofld-repeater-row {
	background: #fff;
}

/* ==========================================================================
   Layout Variations
   ========================================================================== */

/* Table layout - respects width but no wrapping */
[data-layout="table"] .cofld-repeater-row-content {
	flex-wrap: nowrap;
	gap: 8px;
}

[data-layout="table"] .cofld-repeater-subfield {
	flex-shrink: 0;
}

[data-layout="table"] .cofld-repeater-subfield-label {
	font-size: 12px;
}

/* Row layout - inline, respects width */
[data-layout="row"] .cofld-repeater-row-content {
	flex-wrap: nowrap;
	align-items: flex-end;
	gap: 8px;
}

[data-layout="row"] .cofld-repeater-subfield {
	flex-shrink: 0;
}

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

@media screen and (max-width: 782px) {


	.cofld-repeater-subfield {
		flex: 0 0 100% !important;
		max-width: 100% !important;
	}
}

/* Switch field in repeater uses the same grid-based styling from fields.css
   No overrides needed - inherits from .cofld-switch-checkbox and .cofld-switch-container */

/* ==========================================================================
   Media Preview in Repeater
   ========================================================================== */

.cofld-repeater-subfield .cofld-media-preview {
	max-width: 80px;
	height: auto;
	margin-bottom: 8px;
	border-radius: 3px;
}
