/* Add any CSS rules for Angular module "crmRevisionist" */

/*
 * The history dialog is opened either via crm-dialog-popup (SearchKit admin
 * listing) or a SearchKit "task" uiDialog (FormBuilder admin table) - neither
 * call site lets us pass custom jQuery-UI-dialog width/height options, so the
 * default (a fixed 40%-of-window height) applies. Overriding it here with
 * :has() scopes the override to *this* dialog's content only, leaving every
 * other search-task/popup dialog in CiviCRM untouched. vw/vh units make it
 * naturally responsive to window resizing without any JS.
 *
 * :not(.revisionist-user-resized) lets this default step aside once the
 * user drags a resize handle (added via the dialog's own
 * "dialogresizestart" event) - otherwise this !important permanently
 * blocks jQuery UI's own inline resize updates, so dragging would look
 * possible but do nothing.
 */
.ui-dialog:has(.revisionist-history-panel):not(.revisionist-user-resized) {
  width: 92vw !important;
  max-width: 1200px !important;
  height: 85vh !important;
}

/*
 * jQuery UI stacks title bar + content + button pane in normal flow, with
 * the button pane pinned via position:absolute. Its own default height
 * already leaves room for that, but the taller default size above needs
 * content's height recomputed too - a fixed "leave 3em free" guess only
 * accounted for the button pane, not the title bar, so content could still
 * overlap it. Flexbox distributes the actual space correctly at any size,
 * including through an interactive resize. The .ui-dialog-buttonpane rule
 * below un-absolutizes it so it participates in this flex column instead
 * of overlapping the content before it.
 */
.ui-dialog:has(.revisionist-history-panel) {
  display: flex !important;
  flex-direction: column !important;
}

/*
 * jQuery UI gives its bottom-right resize handle (the only one of the 8
 * with a .ui-icon class) an explicit ~12px size, but CiviCRM's global
 * `.crm-container .ui-icon { width: inherit }` rule (for its icon-font
 * system) also matches it, making it inherit the dialog's own width and
 * swallow clicks meant for content below. Restoring an explicit size here,
 * scoped to this dialog, undoes the collision without touching CiviCRM's
 * global rule.
 */
.ui-dialog:has(.revisionist-history-panel) .ui-resizable-se {
  width: 12px !important;
  height: 12px !important;
}

.ui-dialog:has(.revisionist-history-panel) > .ui-dialog-titlebar {
  flex: 0 0 auto !important;
}

.ui-dialog:has(.revisionist-history-panel) > .ui-dialog-content {
  flex: 1 1 auto !important;
  height: auto !important;
  max-height: none !important;
  min-height: 0 !important;
  /*
   * jQuery UI's theme gives .ui-dialog-content a bottom margin sized for
   * the button pane - redundant now that flexbox reserves that space
   * itself, and left in place it doubles up, leaving a large gap above the
   * button pane.
   */
  margin: 0 !important;
}

.ui-dialog:has(.revisionist-history-panel) > .ui-dialog-buttonpane {
  position: static !important;
  flex: 0 0 auto !important;
}

.revisionist-history-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.revisionist-body {
  display: flex;
  flex: 1 1 auto;
  gap: 16px;
  /* Lets the flex children scroll internally instead of growing past the
     dialog and pushing the Close button off-screen. */
  min-height: 0;
}

.revisionist-sidebar {
  flex: 0 0 260px;
  overflow-y: auto;
}

.revisionist-current-marker {
  padding: 6px 10px;
  margin-bottom: 8px;
  border-left: 3px solid #5bc0de;
  background-color: rgba(91, 192, 222, 0.12);
  cursor: pointer;
}

.revisionist-current-marker.active {
  border-left-color: #2777a4;
  background-color: rgba(91, 192, 222, 0.28);
}

.revisionist-pinned-filter {
  /* Scaled down like .revisionist-pin-toggle below - the default
     crm-form-toggle is sized for a standalone form row. */
  transform: scale(0.85);
  transform-origin: left center;
  color: #767676;
  font-size: 0.9em;
  margin-bottom: 8px;
  cursor: pointer;
}

.revisionist-history-list > li {
  cursor: pointer;
  position: relative;
}

.revisionist-pin-toggle {
  float: right;
  padding: 1px 6px;
}

.revisionist-description {
  margin: 4px 0 8px 0;
}

/* Click-to-edit affordance matching SearchKit's own inline-edit convention
   (see #bootstrap-theme.crm-search .crm-editable-enabled in search_kit's
   crmSearchAdmin.css) - invisible border normally, dashed on hover, so it
   doesn't look like a permanent input box until the user actually wants to
   edit it. display:block (not inline-block) so a short/empty description
   doesn't leave room on the same line for whatever follows (e.g. the
   Restore button) to render alongside it instead of on its own line.
   width:fit-content keeps the hover border snug around the text rather
   than stretching the full row width. */
.revisionist-description-display {
  display: block;
  width: fit-content;
  max-width: 100%;
  margin: 4px 0 8px 0;
  padding: 1px 4px;
  border: 1px dashed transparent;
  border-radius: 2px;
  cursor: text;
  min-width: 40px;
}

.revisionist-description-display:hover {
  border-color: #999;
}

.revisionist-description-edit {
  position: relative;
  margin: 4px 0 8px 0;
}

.revisionist-description-edit .revisionist-description {
  margin: 0;
  padding-right: 22px;
}

.revisionist-description-clear {
  position: absolute;
  top: 50%;
  right: 4px;
  transform: translateY(-50%);
  border: 0;
  background: none;
  padding: 2px 4px;
  color: #999;
  cursor: pointer;
}

.revisionist-description-clear:hover {
  color: #333;
}

.revisionist-detail {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.revisionist-display-restore {
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px solid rgba(128, 128, 128, 0.2);
}

.revisionist-detail-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.revisionist-compare-row {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

/*
 * flex:1 1 auto here is only meant to apply inside .revisionist-compare-row's
 * horizontal layout, so this note takes the remaining width next to the
 * compare-toggle buttons. But the same element/class is also used standalone
 * (not inside .revisionist-compare-row) for the "Current version" note,
 * where it's a direct child of .revisionist-detail-inner's *column* flex
 * layout instead - there flex:1 1 auto grows it vertically to fill leftover
 * space, pushing the tab bar down. Scope the growth to the row context only;
 * the standalone case gets a plain, non-growing block below.
 */
.revisionist-compare-row .revisionist-compare-note {
  flex: 1 1 auto;
}

.revisionist-compare-note {
  flex: 0 0 auto;
  margin-bottom: 6px;
}

.revisionist-compare-toggle {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.revisionist-tabs {
  flex: 0 0 auto;
  margin-bottom: 0;
}

.revisionist-tab-content {
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
  border: 1px solid #ddd;
  border-top: 0;
  padding: 8px;
}

/*
 * Angular ng-if adds/removes this element from the DOM entirely rather than
 * toggling Bootstrap's .open class, so it needs its own display rule instead
 * of relying on ".open > .dropdown-menu". Scoped to this list only.
 */
.revisionist-history-list .dropdown-menu {
  display: block;
}

.revisionist-field-row {
  padding: 6px 8px;
  margin-bottom: 4px;
}

/* An inline row (key: value on one line) needs much less padding than a
   multi-line JSON/text block - :has() scopes the tighter padding to just
   those rows without a separate modifier class on the parent. */
.revisionist-field-row:has(.revisionist-field-inline) {
  padding: 3px 8px;
}

.revisionist-field-inline .revisionist-diff-marker {
  width: auto;
  margin-right: 0.2em;
}

.revisionist-field-name {
  font-weight: bold;
  margin-bottom: 2px;
}

/* Plain (non-diff) field=>value listing used for "Current version" - no
   status coloring, just a light separator between rows. */
.revisionist-field-row-plain {
  padding: 3px 8px;
  border-bottom: 1px solid rgba(128, 128, 128, 0.2);
}

.revisionist-field-row-plain:last-child {
  border-bottom: 0;
}

/*
 * Applied to a whole field-row, which can contain a mix of removed (red) and
 * added (green) lines for a "changed" field - so only a border-left accent
 * here, not a background, to avoid layering a third color behind the
 * per-line backgrounds below.
 */
.revisionist-diff-added,
.revisionist-diff-removed,
.revisionist-diff-changed {
  border-left: 3px solid transparent;
}

.revisionist-diff-added {
  border-left-color: #2ea043;
}

.revisionist-diff-removed {
  border-left-color: #d9534f;
}

.revisionist-diff-changed {
  border-left-color: #f0ad4e;
}

/*
 * Semi-transparent rgba() overlays rather than solid pastel hex backgrounds,
 * so these blend correctly with whatever the surrounding theme's background
 * is - light or dark - instead of punching a bright light-mode-only patch
 * into a dark dialog.
 */

.revisionist-diff-lines {
  font-family: monospace;
  white-space: pre-wrap;
}

.revisionist-diff-line-added {
  background-color: rgba(46, 160, 67, 0.18);
}

.revisionist-diff-line-removed {
  background-color: rgba(217, 83, 79, 0.18);
}

/* Word-level diff for a changed scalar string field (see diffWords() in
   crmRevisionDiff.component.js) - unchanged words render as plain text so
   only the actual edit stands out against its surrounding context. */
.revisionist-diff-words {
  white-space: pre-wrap;
}

.revisionist-diff-word-added {
  background-color: rgba(46, 160, 67, 0.35);
}

.revisionist-diff-word-removed {
  background-color: rgba(217, 83, 79, 0.35);
  text-decoration: line-through;
}

/* A "changed" line within a multi-line diff (pairLineChanges()) - word
   highlights already carry the signal, so this is just a faint neutral
   tint rather than a full added/removed background that would clash. */
.revisionist-diff-line-changed {
  background-color: rgba(240, 173, 78, 0.12);
}

.revisionist-diff-line-changed .revisionist-diff-marker {
  color: #f0ad4e;
}

.revisionist-diff-marker {
  display: inline-block;
  width: 1.2em;
  font-weight: bold;
}

/* Marks where a run of unchanged lines was collapsed - see collapseContext()
   in crmRevisionDiff.component.js. Kept visually quiet since it's a gap
   marker, not content. */
.revisionist-diff-context {
  color: #767676;
  font-style: italic;
  padding-left: 1.2em;
}
