/* Settings > Data fields (B-063): tabs, the field lists and the Add / Edit field modal. */
.fields-page { max-width: 880px; }
.fields-page .settings-title { margin-bottom: var(--sp-4); font-size: var(--fs-title); line-height: 32px; }
.fields-count {
  display: inline-flex; align-items: center; height: 24px; padding: 0 var(--sp-4); border-radius: var(--r-pill);
  background: var(--bg-hover); font-size: var(--fs-sm); color: var(--text);
}
.fields-count:empty { display: none; }
.fields-intro { margin: var(--sp-5) 0 var(--sp-6); max-width: 640px; color: var(--text); line-height: var(--lh-md); }

.fields-tabs { display: flex; gap: var(--sp-6); border-bottom: 1px solid var(--border); margin-bottom: var(--sp-6); }
.fields-tab {
  position: relative; display: inline-flex; align-items: center; gap: var(--sp-2); height: 40px; padding: 0 var(--sp-2);
  color: var(--text-2); text-decoration: none; font-weight: var(--fw-semibold);
  transition: color var(--t-fast) var(--ease);
}
.fields-tab .ic, .fields-tab svg { width: 16px; height: 16px; display: block; }
.fields-tab:hover { color: var(--text); }
.fields-tab.is-active { color: var(--link); }
.fields-tab.is-active::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; border-radius: 2px 2px 0 0; background: var(--link);
}
.fields-tab:focus-visible { outline: 2px solid var(--border-focus); outline-offset: -2px; border-radius: var(--r-sm); }

.fields-toolbar { display: flex; align-items: center; gap: var(--sp-4); min-height: var(--control-h); margin-bottom: var(--sp-6); }
.fields-add .ic, .fields-add svg { width: 14px; height: 14px; }
.fields-add { gap: var(--sp-2); }

.fields-card { border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--bg-surface); margin-bottom: var(--sp-6); overflow: hidden; }
.fields-card-head {
  display: flex; align-items: center; gap: var(--sp-4); width: 100%; height: 48px; padding: 0 var(--sp-6);
  border: 0; border-bottom: 1px solid var(--border); background: none; color: var(--text); font: inherit;
  font-size: var(--fs-md); font-weight: var(--fw-semibold); text-align: left; cursor: pointer;
}
.fields-card-head:hover { background: var(--bg-hover); }
.fields-card-head:focus-visible { outline: 2px solid var(--border-focus); outline-offset: -2px; }
.fields-card-caret { width: 16px; height: 16px; color: var(--text-2); transition: transform var(--t-med) var(--ease); }
.fields-card-caret svg { width: 16px; height: 16px; display: block; }
.fields-card.is-collapsed .fields-card-caret { transform: rotate(180deg); }
.fields-card.is-collapsed .fields-card-head { border-bottom: 0; }
.fields-card.is-collapsed .fdef-colhead, .fields-card.is-collapsed .fields-card-body { display: none; }
.fdef-colhead {
  display: grid; grid-template-columns: 24px 32px minmax(0, 1fr) 72px 32px; gap: var(--sp-4); align-items: center;
  height: 44px; padding: 0 var(--sp-5); border-bottom: 1px solid var(--border); font-weight: var(--fw-semibold);
}
.fdef-colhead > span:first-child { grid-column: 3; }
.fdef-colhead-shown { grid-column: 4; text-align: center; font-size: var(--fs-sm); color: var(--text-2); font-weight: var(--fw-regular); }
.fields-card-body { min-height: 48px; }
.fields-card-body .skeleton { padding: var(--sp-5) var(--sp-6); }

.fdef-rows { display: flex; flex-direction: column; }
.fdef-row {
  display: grid; grid-template-columns: 24px 32px minmax(0, 1fr) 72px 32px; gap: var(--sp-4); align-items: center;
  min-height: 53px; padding: 0 var(--sp-5); border-bottom: 1px solid var(--border); background: var(--bg-surface);
  transition: background var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.fdef-row:last-child { border-bottom: 0; }
.fdef-row:hover { background: var(--bg-hover); }
.fdef-row.is-dragging { position: relative; z-index: 1; background: var(--bg-surface); box-shadow: var(--shadow-popover, 0 4px 16px rgba(0, 0, 0, .16)); }
.fdef-rows.is-reordering { cursor: grabbing; user-select: none; }
.fdef-rows.is-reordering .fdef-row:hover:not(.is-dragging) { background: var(--bg-surface); }
.fdef-tile {
  display: grid; place-items: center; width: 32px; height: 32px; border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--bg-app); color: var(--text-2);
}
.fdef-tile .ic, .fdef-tile svg { width: 22px; height: 22px; display: block; }
.fdef-tile.is-blank { border-style: dashed; }
.fdef-text { display: flex; flex-direction: column; min-width: 0; padding: var(--sp-3) 0; }
.fdef-name { font-size: var(--fs-md); line-height: var(--lh-md); color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fdef-type { font-size: var(--fs-sm); line-height: var(--lh-sm); color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fdef-flag { margin-left: var(--sp-2); color: var(--red); font-weight: var(--fw-semibold); }
.fdef-flag.is-important { color: var(--yellow-icon); }
.fdef-drag, .fdef-more {
  display: grid; place-items: center; width: 24px; height: 28px; padding: 0; border: 0; border-radius: var(--r-sm);
  background: none; color: var(--text-muted); cursor: grab; opacity: 0; transition: opacity var(--t-fast) var(--ease);
}
.fdef-more { width: 32px; cursor: pointer; }
.fdef-drag .ic, .fdef-drag svg, .fdef-more .ic, .fdef-more svg { width: 16px; height: 16px; display: block; }
.fdef-row:hover .fdef-drag, .fdef-row:hover .fdef-more, .fdef-drag:focus-visible, .fdef-more:focus-visible,
.fdef-more[aria-expanded="true"], .fdef-row.is-dragging .fdef-drag { opacity: 1; }
.fdef-more:hover, .fdef-more[aria-expanded="true"] { background: var(--bg-surface); color: var(--text); box-shadow: inset 0 0 0 1px var(--border); }
.fdef-drag:hover { color: var(--text); }
.fdef-drag:focus-visible, .fdef-more:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 1px; }
.fdef-shown {
  justify-self: center; display: grid; place-items: center; width: 24px; height: 24px; padding: 0; border: 0;
  border-radius: var(--r-sm); background: none; color: var(--text);
}
.fdef-shown .ic, .fdef-shown svg { width: 16px; height: 16px; display: block; }
button.fdef-shown { cursor: pointer; }
button.fdef-shown:hover { background: var(--bg-surface); box-shadow: inset 0 0 0 1px var(--border); }
button.fdef-shown:not(.is-on):hover::after { content: ''; width: 12px; height: 12px; border: 1px dashed var(--border-strong); border-radius: 3px; }
button.fdef-shown:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 1px; }
.fdef-row.is-builtin:hover { background: none; }

.fields-empty { padding: var(--sp-7) var(--sp-6); display: flex; flex-direction: column; gap: var(--sp-2); }
.fields-empty-title { font-size: var(--fs-xl); line-height: 28px; font-weight: var(--fw-semibold); }
.fields-empty-text { color: var(--text-2); line-height: var(--lh-md); }
.fields-default-none { padding: var(--sp-5) var(--sp-6); }

/* Add / Edit field modal (~815px, two columns) */
.fdef-modal .modal-body { padding: 0; display: block; }
.fdef-form { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); min-height: 380px; }
.fdef-col { display: flex; flex-direction: column; gap: var(--sp-6); padding: var(--sp-6); min-width: 0; }
.fdef-col-right { border-left: 1px solid var(--border); gap: var(--sp-4); }
.fdef-intro { margin: 0; line-height: var(--lh-md); color: var(--text); }
.fdef-field { display: flex; flex-direction: column; gap: var(--sp-2); max-width: 346px; }
.fdef-label { font-size: var(--fs-md); line-height: var(--lh-md); color: var(--text); }
.fdef-req { color: var(--text-2); }
.fdef-field > .input, .fdef-field > .select-trigger { width: 100%; }
.fdef-field.is-invalid .input { border-color: var(--red); }
.fdef-type-trigger { height: 40px; gap: var(--sp-4); }
.fdef-type-trigger .select-label { flex: 1; text-align: left; }
.fdef-type-tile .fdef-tile { width: 28px; height: 28px; }
.fdef-type-tile .fdef-tile svg { width: 18px; height: 18px; }
.fdef-side-title { margin-top: var(--sp-2); font-weight: var(--fw-semibold); }
.fdef-side-card { padding: var(--sp-4) var(--sp-5); border-radius: var(--r-md); background: var(--bg-app); }
.fdef-switch-row { display: flex; align-items: flex-start; gap: var(--sp-4); cursor: pointer; }
.fdef-switch-row .switch { margin-top: 2px; }
.fdef-switch-text { display: flex; flex-direction: column; line-height: var(--lh-md); }
.fdef-switch-hint { font-size: var(--fs-sm); line-height: var(--lh-sm); color: var(--text-2); }
/* BUG-123: 'Show in add view' locked on while the field is required. */
.fdef-switch-row.is-locked { cursor: default; }
.fdef-switch-row.is-locked .switch { opacity: .6; cursor: not-allowed; }
.fdef-switch-note { margin-top: var(--sp-1); font-size: var(--fs-sm); line-height: var(--lh-sm); color: var(--text-2); font-style: italic; }
.fdef-switch-note[hidden] { display: none; }

.fdef-options-list { display: flex; flex-direction: column; gap: var(--sp-3); max-height: 220px; overflow-y: auto; padding: 2px; }
.fdef-option { display: grid; grid-template-columns: minmax(0, 1fr) 28px; gap: var(--sp-3); align-items: center; }
.fdef-option-remove {
  display: grid; place-items: center; width: 28px; height: 28px; padding: 0; border: 0; border-radius: var(--r-sm);
  background: none; color: var(--text-2); cursor: pointer;
}
.fdef-option-remove .ic, .fdef-option-remove svg { width: 14px; height: 14px; display: block; }
.fdef-option-remove:hover:not(:disabled) { background: var(--bg-hover); color: var(--text); }
.fdef-option-remove:disabled { opacity: .35; cursor: default; }
.fdef-option-add { margin-top: var(--sp-2); }
.fdef-option-add .ic, .fdef-option-add svg { width: 14px; height: 14px; }
.fdef-options.is-invalid .input { border-color: var(--red); }

/* Field type list (popover on body: tokens from :root) */
.fdef-type-popover { padding: var(--sp-3) 0; max-width: calc(100vw - 32px); }
.fdef-type-searchbox {
  display: flex; align-items: center; gap: var(--sp-3); margin: 0 var(--sp-3) var(--sp-3); padding: 0 var(--sp-4);
  height: var(--control-h); border: 1px solid var(--border-focus); border-radius: var(--r-md); background: var(--bg-surface);
}
.fdef-type-searchbox .ic, .fdef-type-searchbox svg { width: 16px; height: 16px; color: var(--text-2); display: block; }
.fdef-type-search.input { flex: 1; height: 30px; padding: 0; border: 0; background: none; }
.fdef-type-list { list-style: none; margin: 0; padding: 0 var(--sp-2); max-height: 340px; overflow-y: auto; }
.fdef-type-opt {
  display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: var(--sp-4); align-items: center; padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md); cursor: pointer;
}
.fdef-type-opt.is-active { background: var(--bg-hover); }
.fdef-type-opt.is-selected { background: var(--blue-bright); color: var(--text-inverse); }
.fdef-type-opt.is-selected .fdef-type-desc { color: var(--text-inverse); }
.fdef-type-opt.is-selected .fdef-tile { background: var(--bg-surface); }
.fdef-type-text { display: flex; flex-direction: column; min-width: 0; }
.fdef-type-name { font-weight: var(--fw-semibold); line-height: var(--lh-md); }
.fdef-type-desc { font-size: var(--fs-sm); line-height: var(--lh-sm); color: var(--text-2); }
.fdef-type-none { padding: var(--sp-4); color: var(--text-2); }

@media (max-width: 720px) {
  .fdef-form { grid-template-columns: minmax(0, 1fr); }
  .fdef-col-right { border-left: 0; border-top: 1px solid var(--border); }
}
@media (prefers-reduced-motion: reduce) { .fields-card-caret, .fdef-row { transition: none; } }
