/**
 * Btmh ContentBlocks Admin Styles
 *
 * Custom styling for content blocks admin UI components:
 * - Repeater fields
 * - Entity picker
 * - Range slider
 * - Responsive tabs
 * - Block type selector
 */

/* ==========================================================================
   Repeater Field Styles
   ========================================================================== */

.btmh-repeater-container {
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 15px;
    background: #fafafa;
}

.btmh-repeater-records {
    margin-bottom: 15px;
}

.btmh-repeater-record {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-bottom: 10px;
    transition: box-shadow 0.2s ease;
}

.btmh-repeater-record:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.btmh-repeater-record--dragging {
    opacity: 0.5;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btmh-repeater-record-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 15px;
    gap:10px;
    background: #f5f5f5;
    border-bottom: 1px solid #ddd;
    border-radius: 4px 4px 0 0;
    font-weight: 700;
}

.btmh-repeater-record-header .btmh-repeater-record-fields {
    padding: 10px;
}

.btmh-repeater-drag-handle {
    cursor: grab;
    padding: 5px;
    margin-right: 10px;
    color: #999;
}

.btmh-repeater-drag-handle:hover {
    color: #666;
}

.btmh-repeater-record-number {
    flex: 1;
    font-weight: 600;
    color: #666;
    font-size: 14px;
}

.btmh-repeater-delete-btn {
    background: none;
    border: 1px solid #e22626;
    color: #e22626;
    cursor: pointer;
    padding: 5px 12px;
    border-radius: 3px;
    font-size: 12px;
    transition: background 0.2s, color 0.2s;
}

.btmh-repeater-delete-btn:hover {
    background: #e22626;
    color: #fff;
}

.btmh-repeater-record-fields {
    padding: 15px;
}

.btmh-repeater-record-fields .admin__field {
    margin-bottom: 12px;
}

.btmh-repeater-record-fields .admin__field:last-child {
    margin-bottom: 0;
}

.btmh-repeater-add-btn {
    min-width: 120px;
    margin-top: 10px;
}

.btmh-repeater-empty {
    text-align: center;
    padding: 30px;
    color: #999;
    font-style: italic;
}

/* ==========================================================================
   Entity Picker Styles
   ========================================================================== */

.btmh-entity-picker-container {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.btmh-entity-picker-selected {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.btmh-entity-tag {
    display: inline-flex;
    align-items: center;
    background: #e8f4fc;
    border: 1px solid #b8d4e8;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 13px;
}

.btmh-entity-tag-label {
    margin-right: 6px;
}

.btmh-entity-tag-remove {
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0 2px;
}

.btmh-entity-tag-remove:hover {
    color: #e22626;
}

.btmh-entity-picker-btn {
    white-space: nowrap;
}

/* Entity picker modal */
.btmh-entity-picker-modal {
    padding: 20px;
}

.btmh-entity-picker-modal input[type="text"] {
    width: 100%;
    margin-bottom: 15px;
}

.btmh-entity-list {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-bottom: 15px;
}

.btmh-entity-id-input {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: #f5f5f5;
    border-radius: 4px;
}

.btmh-entity-id-input input {
    flex: 1;
}

/* ==========================================================================
   Range Slider Styles
   ========================================================================== */

.btmh-range-slider-container {
    display: flex;
    align-items: center;
    gap: 15px;
}

.btmh-range-slider-input {
    flex: 1;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: #ddd;
    border-radius: 3px;
    outline: none;
}

.btmh-range-slider-input::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: #1979c3;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s ease;
}

.btmh-range-slider-input::-webkit-slider-thumb:hover {
    background: #006bb4;
}

.btmh-range-slider-input::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: #1979c3;
    border: none;
    border-radius: 50%;
    cursor: pointer;
}

.btmh-range-slider-value {
    min-width: 40px;
    text-align: center;
    font-weight: 600;
    color: #333;
    background: #f0f0f0;
    padding: 4px 8px;
    border-radius: 4px;
}

/* ==========================================================================
   Responsive Tabs Styles
   ========================================================================== */

.btmh-responsive-tabs-field {
    margin-bottom: 20px;
}

.btmh-responsive-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 10px;
}

.btmh-responsive-tab {
    padding: 8px 16px;
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-bottom: none;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.2s ease;
}

.btmh-responsive-tab:first-child {
    border-radius: 4px 0 0 0;
}

.btmh-responsive-tab:last-child {
    border-radius: 0 4px 0 0;
}

.btmh-responsive-tab:hover {
    background: #e8e8e8;
}

.btmh-responsive-tab--active {
    background: #fff;
    border-bottom: 1px solid #fff;
    margin-bottom: -1px;
    font-weight: 600;
}

.btmh-responsive-content {
    border: 1px solid #ddd;
    border-radius: 0 4px 4px 4px;
    padding: 15px;
    background: #fff;
}

.btmh-responsive-badge {
    display: inline-block;
    background: #eb5202;
    color: #fff;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 10px;
    margin-left: 8px;
    vertical-align: middle;
}

.btmh-responsive-inherit-toggle,
.btmh-responsive-visibility-toggle {
    margin-bottom: 10px;
}

/* Span-based checkbox for responsive toggles (native checkbox unreliable in admin) */
.btmh-checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 13px;
    color: #333;
    user-select: none;
}

.btmh-checkbox-box {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    min-width: 18px;
    border: 2px solid #adadad;
    border-radius: 3px;
    background: #fff;
    flex-shrink: 0;
    transition: background-color 0.15s, border-color 0.15s;
}

.btmh-checkbox-label:hover .btmh-checkbox-box {
    border-color: #858585;
}

.btmh-checkbox-box.btmh-checkbox-checked {
    background-color: #006bb4;
    border-color: #006bb4;
}

.btmh-checkbox-tick {
    display: none;
    width: 5px;
    height: 10px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
    margin-bottom: 2px;
}

.btmh-checkbox-checked .btmh-checkbox-tick {
    display: block;
}

.btmh-responsive-mobile-input {
    margin-top: 10px;
}

.btmh-responsive-inherited {
    padding: 10px;
    background: #f9f9f9;
    border-radius: 4px;
    color: #666;
}

.btmh-responsive-inherited-value {
    font-weight: 500;
}

.btmh-responsive-inherited-label {
    font-size: 12px;
    color: #999;
    margin-left: 8px;
}

/* ==========================================================================
   Block Type Selector Styles
   ========================================================================== */

.btmh-block-type-selector {
    position: relative;
}

.btmh-block-type-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 15px;
    padding: 15px;
}

.btmh-block-type-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 15px;
    background: #fff;
    border: 2px solid #ddd;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btmh-block-type-item:hover {
    border-color: #1979c3;
    box-shadow: 0 2px 8px rgba(25, 121, 195, 0.2);
}

.btmh-block-type-item--selected {
    border-color: #1979c3;
    background: #e8f4fc;
}

.btmh-block-type-icon {
    font-size: 32px;
    margin-bottom: 10px;
    color: #666;
}

.btmh-block-type-label {
    font-weight: 600;
    text-align: center;
    margin-bottom: 5px;
}

.btmh-block-type-description {
    font-size: 12px;
    color: #999;
    text-align: center;
}

/* ==========================================================================
   General Admin Form Enhancements
   ========================================================================== */

/* Dynamic fieldset loading state */
.btmh-fieldset-loading {
    position: relative;
    min-height: 100px;
}

.btmh-fieldset-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 30px;
    height: 30px;
    margin: -15px 0 0 -15px;
    border: 3px solid #ddd;
    border-top-color: #1979c3;
    border-radius: 50%;
    animation: btmh-spin 0.8s linear infinite;
}

@keyframes btmh-spin {
    to {
        transform: rotate(360deg);
    }
}

/* Field groups */
.btmh-field-group {
    background: #fafafa;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 15px;
    margin-bottom: 15px;
}

.btmh-field-group-title {
    font-weight: 600;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid #e0e0e0;
}

/* Conditional field animation */
.btmh-conditional-field {
    transition: opacity 0.3s ease, max-height 0.3s ease;
    overflow: hidden;
}

.btmh-conditional-field--hidden {
    opacity: 0;
    max-height: 0;
    margin: 0;
    padding: 0;
}

/* ==========================================================================
   Query Builder Styles
   ========================================================================== */

.btmh-query-builder-container {
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 20px;
    background: #fafafa;
}

.btmh-query-builder-section {
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #e0e0e0;
}

.btmh-query-builder-section:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.btmh-query-builder-section > .admin__field-label {
    font-weight: 600;
    margin-bottom: 10px;
    display: block;
}

.btmh-query-builder-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.btmh-query-builder-section-header .admin__field-label {
    margin-bottom: 0;
}

.btmh-query-builder-filter-logic {
    display: flex;
    gap: 20px;
}

.btmh-query-builder-filter-logic label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 13px;
}

.btmh-query-builder-filter-list {
    margin-bottom: 15px;
}

.btmh-query-builder-filter-row {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
    padding: 10px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.btmh-filter-attribute {
    flex: 1;
    min-width: 150px;
}

.btmh-filter-operator {
    width: 160px;
}

.btmh-filter-value {
    flex: 2;
    min-width: 150px;
}

.btmh-filter-remove {
    background: none;
    border: none;
    color: #e22626;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    padding: 5px 10px;
}

.btmh-filter-remove:hover {
    color: #c00;
}

.btmh-query-builder-filter-actions {
    display: flex;
    gap: 10px;
}

.btmh-query-builder-sort-row {
    display: flex;
    gap: 15px;
}

.btmh-sort-attribute {
    flex: 1;
    max-width: 300px;
}

.btmh-sort-direction {
    width: 150px;
}

.btmh-query-builder-pagination input {
    width: 100px;
}

.btmh-query-builder-pagination .admin__field-note {
    display: block;
    margin-top: 5px;
    font-size: 12px;
    color: #999;
}

/* Locked filter row (category auto-injected filter) */
.btmh-filter-row--locked {
    opacity: 0.6;
    pointer-events: none;
    background: #f5f5f5;
    border-radius: 3px;
    padding: 4px;
}

/* Pinned products section */
.btmh-pinned-search {
    position: relative;
    margin-top: 8px;
}

.btmh-pinned-dropdown {
    position: absolute;
    background: #fff;
    border: 1px solid #ccc;
    z-index: 100;
    max-height: 200px;
    overflow-y: auto;
    list-style: none;
    margin: 0;
    padding: 0;
    width: 100%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.btmh-pinned-dropdown li {
    padding: 6px 12px;
    cursor: pointer;
}

.btmh-pinned-dropdown li:hover {
    background: #f5f5f5;
}

.btmh-pinned-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.btmh-pinned-chip {
    background: #e8f0fe;
    border-radius: 4px;
    padding: 2px 8px;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
}

.btmh-pinned-chip-remove {
    background: none;
    border: none;
    cursor: pointer;
    color: #666;
    font-size: 14px;
    line-height: 1;
    padding: 0 2px;
}

.btmh-pinned-chip-remove:hover {
    color: #333;
}

.btmh-query-builder-preview-results {
    margin-top: 15px;
    padding: 15px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.btmh-preview-summary {
    margin-bottom: 10px;
    font-size: 14px;
}

.btmh-preview-items {
    max-height: 250px;
    overflow-y: auto;
}

.btmh-preview-items table {
    width: 100%;
}

.btmh-preview-items th,
.btmh-preview-items td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid #eee;
}

.btmh-preview-items th {
    background: #f5f5f5;
    font-weight: 600;
}

.btmh-preview-more {
    padding: 10px;
    text-align: center;
    color: #666;
    font-style: italic;
}

/* ========== Group Tabs for Dynamic Fieldset ========== */
.btmh-group-tabs {
    display: flex;
    flex-direction: row;
    gap: 0;
    border-bottom: 2px solid #e0e0e0;
    margin-bottom: 20px;
    padding: 0;
    flex-wrap: wrap;
    width: 100%;
    clear: both;
}

.btmh-group-tab {
    padding: 10px 20px;
    border: 1px solid transparent;
    border-bottom: none;
    background: #f5f5f5;
    color: #555;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    position: relative;
    bottom: -2px;
    border-radius: 4px 4px 0 0;
    transition: background 0.2s, color 0.2s;
    margin-right: 2px;
    text-transform: capitalize;
    float: none;
    display: inline-block;
}

.btmh-group-tab:hover {
    background: #eaeaea;
    color: #333;
}

.btmh-group-tab--active {
    background: #fff;
    color: #1979c3;
    border-color: #e0e0e0;
    border-bottom: 2px solid #fff;
}

/* Loading/Error states */
.dynamic-fieldset-loading,
.dynamic-fieldset-error {
    padding: 15px;
    text-align: center;
}

.dynamic-fieldset-error .error-message {
    color: #e22626;
}

.dynamic-fieldset-empty .empty-message {
    color: #999;
    font-style: italic;
    padding: 15px;
}

/* ========== Accordion Legend ========== */
.btmh-accordion-legend {
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 15px;
    background: #f8f8f8;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    margin-bottom: 0;
    user-select: none;
}

.btmh-accordion-legend:hover {
    background: #f0f0f0;
}

.btmh-accordion-arrow {
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid #555;
    transition: transform 0.2s;
}

.btmh-accordion-arrow--open {
    transform: rotate(180deg);
}

.btmh-accordion-content {
    padding-top: 15px;
}

.btmh-dynamic-fieldset--collapsed .btmh-accordion-legend {
    margin-bottom: 15px;
}

/* ==========================================================================
   Typography Field Styles
   ========================================================================== */

.btmh-typography-field-container {
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 15px;
    background: #fafafa;
}

.btmh-typography-controls-row {
    display: flex;
    gap: 20px;
    align-items: flex-end;
    margin-bottom: 15px;
}

.btmh-typography-tag-field {
    flex: 0 0 160px;
}

.btmh-typography-tag-field .admin__field-label,
.btmh-typography-alignment-field .admin__field-label,
.btmh-typography-text-field .admin__field-label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    font-size: 13px;
}

.btmh-typography-alignment-field {
    flex: 0 0 auto;
}

.btmh-alignment-group {
    display: inline-flex;
    gap: 0;
    border: 1px solid #ccc;
    border-radius: 4px;
    overflow: hidden;
}

.btmh-alignment-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    background: #fff;
    border: none;
    border-right: 1px solid #ccc;
    cursor: pointer;
    color: #666;
    transition: background 0.15s, color 0.15s;
}

.btmh-alignment-btn:last-child {
    border-right: none;
}

.btmh-alignment-btn:hover {
    background: #f0f0f0;
    color: #333;
}

.btmh-alignment-btn.active {
    background: #1979c3;
    color: #fff;
}

.btmh-typography-text-field .admin__control-text,
.btmh-typography-text-field .admin__control-textarea {
    width: 100%;
}

/* ==========================================================================
   Sort Order Column (grid inline reorder)
   ========================================================================== */

.btmh-sort-order-cell {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.btmh-sort-order-input {
    width: 60px;
    padding: 4px 6px;
    border: 1px solid #ccc;
    border-radius: 3px;
    text-align: center;
    font-size: 13px;
    -moz-appearance: textfield;
}

.btmh-sort-order-input::-webkit-inner-spin-button,
.btmh-sort-order-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
}

.btmh-sort-order-input:focus {
    border-color: #1979c3;
    outline: none;
}

.btmh-sort-arrow {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    background: #f5f5f5;
    border: 1px solid #ccc;
    border-radius: 3px;
    cursor: pointer;
    font-size: 10px;
    color: #555;
    line-height: 1;
    transition: background 0.15s, color 0.15s;
}

.btmh-sort-arrow:hover:not([disabled]) {
    background: #1979c3;
    border-color: #1979c3;
    color: #fff;
}

.btmh-sort-arrow[disabled] {
    opacity: 0.3;
    cursor: default;
}

/* ==========================================================================
   View-Only Mode (query blocks on category page)
   ========================================================================== */

.btmh-view-only-notice {
    background: #fff8e5;
    border: 1px solid #f0c36d;
    border-radius: 4px;
    padding: 10px 15px;
    margin-bottom: 15px;
    color: #6f4400;
    font-size: 13px;
}

.btmh-dynamic-fieldset--view-only .dynamic-fields-container {
    pointer-events: none;
    opacity: 0.7;
}

.btmh-dynamic-fieldset--view-only .btmh-group-tabs {
    pointer-events: auto;
    opacity: 1;
}

