/**
 * @file
 * Styling for AI Context module.
 */

/* Add custom icon to toolbar menu item using mask-image */
:is(.toolbar-icon-ai-context-main-menu-link, .toolbar-button--icon--ai-context-main-menu-link, .toolbar-link--ai-context-main-menu-link)::before {
  background-color: currentColor;
  mask-image: url('data:image/svg+xml,%3Csvg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"%3E%3Cg fill="none" stroke="currentColor" stroke-width="2.25" stroke-linecap="round" stroke-linejoin="round"%3E%3Cpath fill="currentColor" fill-opacity=".15" d="M12.928 1.4861C12.3468 1.18165 11.6532 1.18165 11.072 1.4861L1.5 6.5L11.072 11.5139C11.6532 11.8183 12.3468 11.8183 12.928 11.5139L22.5 6.5L12.928 1.4861Z"/%3E%3Cpath d="M1.5 12L11.072 17.0139C11.6532 17.3183 12.3468 17.3183 12.928 17.0139L22.5 12"/%3E%3Cpath d="M1.5 17.5L11.072 22.5139C11.6532 22.8183 12.3468 22.8183 12.928 22.5139L22.5 17.5"/%3E%3C/g%3E%3C/svg%3E');
  mask-size: 85%;
  mask-repeat: no-repeat;
  mask-position: center;
}

/* Override `.toolbar .toolbar-icon::before { background-color: transparent; }`.
 * Same class count as core (0,2,1) loses when core aggregates later; use a
 * type or ID so our rule wins regardless of order. */
#toolbar-link-ai_context-context_redirect.toolbar-icon::before,
.toolbar a.toolbar-icon-ai-context-main-menu-link::before,
.toolbar button.toolbar-icon-ai-context-main-menu-link::before,
.toolbar a.toolbar-link--ai-context-main-menu-link::before,
.toolbar button.toolbar-link--ai-context-main-menu-link::before {
  background-color: currentColor;
}

.action-link.action-link--icon-trash {
  padding-block: calc(var(--gin-spacing-xs) - var(--gin-spacing-xxxs)) !important;
}

/* Tighten AI provider configuration spacing on the general settings form. */
#ai-context-settings-form .form-item--provider-config-provider-model {
  margin-block-end: 0;
}

/* Truncated description - indicate that hovering reveals full text */
.description-truncate {
  display: inline;
  cursor: help;
  color: var(--gin-color-text, currentColor);
  border-bottom: 1px dotted var(--gin-color-text-light, #6c7985);
}

/* Subtle inline links for debug/explore actions */
.ai-context-inline-link {
  color: var(--color-gray-800, #55565b);
  font-size: 0.9em;
}

.ai-context-inline-link:hover {
  color: var(--color-gray, #232429);
}

/* AI Context Usage view - compact exposed filters */
.view-ai-context-usage .views-exposed-form .form--inline {
  flex-wrap: wrap;
  gap: 1rem 1.5rem;
}

.view-ai-context-usage .views-exposed-form .form-item {
  margin-block: 0;
}

.view-ai-context-usage .views-exposed-form .form-item input[type="text"],
.view-ai-context-usage .views-exposed-form .form-item input[type="number"] {
  width: 20ch;
  min-width: 10ch;
}

.view-ai-context-usage .views-exposed-form .form-item-target-entity-id input {
  width: 6ch;
}

/* Preserve whitespace in target entity lists */
.ai-context-target {
  white-space: normal;
}

/* Tags display - each tag on its own line */
.ai-context-tag,
.ai-context-tags {
  display: block;
}

/* Scope display in agent form table - each scope type on its own line */
.ai-context-scope-cell {
  display: block;
}

/**
 * Diff visual inline layout accessibility improvements.
 *
 * Scoped to diff comparison pages (which have .diff-header).
 * Darkens the background colors for better contrast with white text.
 */

/* Deleted content - dark red background */
.diff-header ~ del,
.diff-header ~ * del {
  color: #fff;
  background-color: #c43c3c;
}

/* Inserted content - dark green background */
.diff-header ~ ins,
.diff-header ~ * ins {
  color: #fff;
  background-color: #2e7d32;
}

/* Context items filter toolbar: search + cascading scope filters. */
.ai-context-items-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
  margin-block-end: var(--gin-spacing-m, 1rem);
}

.ai-context-items-toolbar .form-item {
  margin-block: 0;
}

.ai-context-items-toolbar .ai-context-items-search {
  min-width: 22ch;
}

/* Context items search input */
#ai-context-items-search {
  max-width: 30ch;
}

/* Consistent spacing for AI Context Item entity view pages only */
.page-ai-context-item-view .field--name-langcode .field__label,
.page-ai-context-item-view .field--name-scope .field__label,
.page-ai-context-item-view .field--name-target-entities .field__label,
.page-ai-context-item-view .field--name-uid .field__label,
.page-ai-context-item-view .field--name-tags .field__label,
.page-ai-context-item-view .field--name-parent .field__label,
.page-ai-context-item-view .field--name-subcontext-type .field__label {
  margin-block-start: 1em;
}

.page-ai-context-item-view .field--name-langcode .field__item,
.page-ai-context-item-view .field--name-scope .field__item,
.page-ai-context-item-view .field--name-target-entities .field__item,
.page-ai-context-item-view .field--name-uid .field__item,
.page-ai-context-item-view .field--name-tags .field__item,
.page-ai-context-item-view .field--name-parent .field__item,
.page-ai-context-item-view .field--name-subcontext-type .field__item {
  margin-block-start: 0.5em;
  margin-block-end: 1em;
}

/* Remove default list margins since we're adding them to field__item */
.page-ai-context-item-view .field--name-scope .field-item > ul,
.page-ai-context-item-view .field--name-target-entities .field-item > ul {
  margin-block: 0;
}

.ai-context-item-list [class*="ai-icon-"] {
  display: inline-block;
  width: 20px;
  height: 20px;
  background-repeat: no-repeat;
  background-size: contain;
}

/* Subcontext-type indicator. Inline SVG inherits this color, which meets
 * the WCAG non-text contrast ratio on the row and hover backgrounds
 * (work item #3586219, point 2). */
.ai-context-item-list .ai-context-subcontext {
  display: inline-flex;
  align-items: center;
  margin-inline-end: 5px;
}

.ai-context-item-list .ai-context-subcontext-ic {
  width: 18px;
  height: 18px;
  color: #44506b;
}

:is(#ai_context, .ai-pill).light {
  color: var(--gin-color-primary-active, var(--color-gray-900));
  background: var(--gin-color-primary-light, #eee);
}

.ai-context-scope-summary {
  margin-block-end: var(--gin-spacing-m, 1rem);
}

.ai-context-item-list tbody .ai-pill {
  overflow: hidden;
  max-width: 17ch;
  margin-inline-start: 8px;
  vertical-align: middle;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.ai-context-scope-row {
  display: flex;
  align-items: center;
  margin-bottom: 0.25rem;
  gap: 0.1rem;
}

:is(.ai-context-scope-row, .ai-context-item-list) .ai-pill:first-child {
  margin-inline-start: 0;
}

.ai-context-scope-label {
  flex: 0 0 130px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  font-size: 0.875rem;
  font-weight: 600;
}

.ai-context-item-list .ai-context-scopes {
  white-space: nowrap;
}

.ai-context-item-list tbody tr {
  border-width: 0;
}

.ai-context-item-list tbody tr:has(+ tr .ai-icon--file),
.ai-context-item-list tbody tr:last-child {
  border-width: 1px;
}

/* Status tag in the context listing. Colors fall back to literals so the
 * tag still reads correctly outside the Gin admin theme. */
.ai-context-status {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 10px;
  white-space: nowrap;
  border-radius: 11px;
  font-size: 12px;
  font-weight: 575;
}

.ai-context-status--published {
  color: var(--gin-status-success-text, #1d6844);
  background: var(--gin-status-success-bg, #26a76930);
}

.ai-context-status--draft {
  color: var(--gin-status-warning-text, #826b1f);
  background: var(--gin-status-warning-bg, rgb(226, 151, 0, 0.15));
}

.ai-context-status--unpublished {
  color: var(--gin-status-danger-text, #cc3d3d);
  background: var(--gin-status-danger-bg, rgb(222, 117, 96, 0.15));
}

.ai-context-status--archived {
  color: var(--gin-status-text, #626262);
  background: var(--gin-status-bg, #eee);
}

/* Token weight badge. Tier colors are contrast-checked literals from the
 * design comp; only the high tier shows a warning icon. */
.ai-context-token-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 10px;
  white-space: nowrap;
  border-radius: 11px;
  font-size: 12px;
  /* cspell:disable-next-line */
  font-variant-numeric: tabular-nums;
  font-weight: 575;
}

.ai-context-token-badge--low {
  color: #5f6a7a;
  background: #eceff3;
}

.ai-context-token-badge--mid {
  color: #92632b;
  background: #fef3c7;
}

.ai-context-token-badge--high {
  color: #9a1f3a;
  background: #fde2e8;
}

.ai-context-token-badge__warn {
  display: inline-flex;
  margin-inline-start: -2px;
}

/* Extensions settings page - align columns across multiple tables. */
table.ai-context-extensions {
  width: 100%;
  table-layout: fixed;
}

table.ai-context-extensions :is(th, td):nth-child(1) {
  width: 23%;
}

table.ai-context-extensions :is(th, td):nth-child(2) {
  width: 47%;
}

table.ai-context-extensions :is(th, td):nth-child(3) {
  width: 20%;
}

table.ai-context-extensions :is(th, td):nth-child(4) {
  width: 10%;
}

/* External-link indicator for module links that open in a new tab. */
.ai-context-new-tab-link::after {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-inline-start: 4px;
  content: "";
  background-color: currentColor;
  mask-image: url("../../../contrib/ai/assets/icons/external.svg");
}

/* Keep the debug/explore action links inline with the agent description. */
.ai-context-inline-links {
  display: inline;
}
