/* =====================================================
   Custom Fields Components
   ===================================================== */

/* Custom field help tooltip */
.custom-field-help {
    cursor: help;
    color: var(--text-muted);
    font-size: 0.85em;
    margin-left: 4px;
}

/* Toggle-style boolean field */
.custom-field-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 8px 0;
}

.custom-field-toggle input[type="checkbox"] {
    width: 16px;
    height: 16px;
}

.custom-field-toggle .toggle-label {
    font-weight: normal;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Multi-select checkbox group */
.custom-field-multi-select {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    padding: 8px 0;
}

.multi-select-option {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    color: var(--text-primary);
}

.multi-select-option input[type="checkbox"] {
    width: 14px;
    height: 14px;
}

/* Custom fields section in forms */
.custom-fields-section .form-section-title {
    color: var(--color-brand);
}

/* =====================================================
   Settings: Custom Fields Manager
   ===================================================== */

/* Tab bar for entity type switching */
.custom-fields-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border);
    margin-bottom: 20px;
}

.custom-fields-tab {
    padding: 10px 20px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.15s, border-color 0.15s;
}

.custom-fields-tab:hover {
    color: var(--text-primary);
}

.custom-fields-tab.active {
    color: var(--color-brand);
    border-bottom-color: var(--color-brand);
}

/* Section header in manager (legacy — kept for AI field cards) */
.custom-fields-manager-section {
    margin-bottom: 20px;
}

.custom-fields-section-header {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 8px 0;
    margin-bottom: 4px;
}

/* Field card — flat list style (used in AI generator modal) */
.custom-field-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-bottom: 6px;
    background: var(--surface);
    transition: box-shadow 0.15s;
}

.custom-field-card:hover {
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.custom-field-card-info {
    flex: 1;
    min-width: 0;
}

.custom-field-card-label {
    font-weight: 500;
    font-size: 0.95rem;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.custom-field-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.custom-field-card-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
    margin-left: 12px;
}

.custom-field-card-actions .btn-icon {
    padding: 6px;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--text-muted);
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
}

.custom-field-card-actions .btn-icon:hover {
    color: var(--text-primary);
    background: var(--surface-secondary);
}

/* =====================================================
   WYSIWYG Custom Fields Manager (form layout)
   ===================================================== */

.cfm-section {
    margin-bottom: 20px;
}

.cfm-section-common .cfm-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.cfm-section-header {
    font-weight: 600;
    font-size: 0.85rem;
    padding-bottom: 4px;
    margin-bottom: 10px;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
}

.cfm-section-collapsible {
    cursor: pointer;
    user-select: none;
}

.cfm-section-collapsible:hover {
    color: var(--color-brand);
}

.cfm-section-body {
    transition: none;
}

.cfm-collapsed .cfm-section-body {
    display: none;
}

.cfm-collapsed .cfm-chevron {
    transform: rotate(-90deg);
}

.cfm-collapsed .cfm-section-header {
    margin-bottom: 0;
    border-bottom-color: transparent;
}

.cfm-field-builtin {
    opacity: 0.55;
    pointer-events: none;
}

.cfm-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px 16px;
}

.cfm-field {
    display: flex;
    align-items: flex-start;
    gap: 6px;
}

.cfm-field-full {
    grid-column: 1 / -1;
}

.cfm-field-actions {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex-shrink: 0;
    align-self: flex-end;
    opacity: 0.4;
    transition: opacity 0.15s;
}

.cfm-field:hover .cfm-field-actions {
    opacity: 1;
}

.cfm-field-actions .btn-icon {
    padding: 3px;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--text-muted);
    border-radius: 3px;
    transition: color 0.15s, background 0.15s;
}

.cfm-field-actions .btn-icon:hover {
    color: var(--text-primary);
    background: var(--surface-secondary);
}

.cfm-field-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.cfm-field-label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

/* Field type badges */
.field-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 500;
}

.field-badge-type {
    background: var(--surface-secondary);
    color: var(--text-secondary);
}

.field-badge-required {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

.field-badge-source {
    background: rgba(15, 118, 110, 0.1);
    color: var(--color-brand);
}

.field-badge-options {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* =====================================================
   Add/Edit Field Modal
   ===================================================== */

.cf-option-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 6px;
}

.cf-option-input {
    flex: 1;
}

.cf-option-remove {
    padding: 4px;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--text-muted);
    border-radius: 4px;
}

.cf-option-remove:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}

/* Field key display */
.cf-field-key-display {
    font-family: var(--font-family-mono);
    font-size: 0.85rem;
    color: var(--text-muted);
    background: var(--surface-secondary);
    padding: 4px 8px;
    border-radius: 4px;
    margin-top: 4px;
}

/* Column picker styles moved to css/components/column-picker.css */

/* Custom field column cells in data tables */
td[data-cf-col],
th[data-cf-col] {
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Computed field (auto-calculated, read-only) */
.computed-field-value {
    display: inline-block;
    padding: 7px 10px;
    background: var(--surface-secondary, rgba(0, 0, 0, 0.03));
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.9rem;
    min-height: 36px;
    line-height: 1.4;
    flex: 1;
}

.computed-field-badge {
    display: inline-block;
    padding: 2px 6px;
    margin-left: 8px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-brand);
    background: rgba(15, 118, 110, 0.1);
    border-radius: 4px;
    vertical-align: middle;
}

/* =====================================================
   Bulk Edit Fields Table
   ===================================================== */

.bulk-edit-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.bulk-edit-table thead {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--bg-primary);
}

.bulk-edit-table th {
    padding: 10px 12px;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border);
    text-align: left;
    white-space: nowrap;
}

.bulk-edit-table td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.bulk-edit-table tr:hover {
    background: var(--surface-secondary, rgba(0, 0, 0, 0.02));
}

.be-input {
    width: 100%;
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.85rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    box-sizing: border-box;
}

.be-input:focus-visible {
    outline: none;
    border-color: var(--color-brand);
    box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.15);
}

.be-checkbox {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.be-field-key {
    display: block;
    font-family: var(--font-family-mono);
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 2px;
    padding-left: 2px;
}

/* Placeholder row for adding new fields */
.be-placeholder-row td {
    border-bottom: none;
}

.be-placeholder-row .be-input {
    border: 1px solid var(--border);
    color: var(--text-muted);
    background: transparent;
}

.be-placeholder-row .be-input:focus-visible {
    color: var(--text-primary);
}

/* Draggable rows */
.bulk-edit-table tr[draggable="true"] {
    cursor: grab;
    user-select: none;
}

.bulk-edit-table tr[draggable="true"]:active {
    cursor: grabbing;
}

/* Row being dragged */
.be-dragging {
    opacity: 0.4;
    background: var(--surface-secondary, rgba(0, 0, 0, 0.03));
}

/* Drop target indicator */
.be-drag-over td {
    border-bottom: 2px solid var(--color-brand);
}

/* New (promoted) row highlight */
.be-new-row {
    background: rgba(15, 118, 110, 0.04);
}

/* Pending delete row */
.be-pending-delete {
    opacity: 0.45;
    text-decoration: line-through;
    background: rgba(220, 38, 38, 0.04);
}

.be-pending-delete:hover {
    background: rgba(220, 38, 38, 0.06);
}

.be-undo-delete {
    display: block;
    font-size: 0.75rem;
    color: var(--color-brand);
    cursor: pointer;
    text-decoration: none;
    margin-top: 2px;
}

.be-undo-delete:hover {
    text-decoration: underline;
}

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

@media (max-width: 768px) {
    .custom-field-card {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .custom-field-card-actions {
        margin-left: 0;
        align-self: flex-end;
    }

    .custom-fields-tab {
        padding: 8px 14px;
        font-size: 0.9rem;
    }

    .cfm-grid {
        grid-template-columns: 1fr;
    }

    .cfm-field-full {
        grid-column: auto;
    }

    .cfm-field-actions {
        opacity: 1;
    }
}
