/* Records use a shared column baseline. Dialogs keep their own inset. */
:is(.history-panel, .activity-panel, .record-dialog) {
  --record-padding: clamp(17px, 1.8vw, 25px);
  --row-inset: clamp(12px, 1.4vw, 20px);
  --record-hover: color-mix(in srgb, var(--control-fill) 72%, var(--surface));
  --record-background: var(--surface);
  --record-border: var(--line-soft);
}

.history-panel {
  container-type: inline-size;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--raised-shadow);
  overflow: hidden;
}
.history-panel .section-top h2 {
  margin: 0;
  font: 500 clamp(25px, 2.1vw, 31px)/1.1 var(--font-display);
  letter-spacing: -.03em;
}
.history-panel .section-top .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 33px;
  padding: 5px 12px;
  color: var(--text);
  background: var(--control-fill);
  border: 1px solid var(--line);
  border-radius: var(--control-radius);
  font: 450 13px/1.4 var(--font);
}
.history-panel .section-top .button:hover { border-color: var(--faint); color: var(--text); }
.history-panel .section-top .button svg { width: 14px; height: 14px; color: var(--teal); }
#catalog-runs:not(:has(*)) { padding-block: 18px; }

.history-panel {
  --history-grid: minmax(0, 1fr) minmax(100px, .42fr) 106px 115px 14px;
  --action-space: 32px;
  padding: clamp(16px, 2vw, 24px) var(--row-inset) 3px;
  display: grid;
  grid-template-columns: auto minmax(140px, 1fr) auto;
  align-items: center;
  column-gap: 16px;
}
.history-panel .section-top { display: contents; }
.history-heading, .record-identity { display: flex; align-items: center; min-width: 0; }
.history-heading { grid-area: 1 / 1; flex-wrap: wrap; gap: 3px 10px; }
.history-panel .section-top #history-total { color: var(--faint); font: 12px/1.4 var(--font); font-variant-numeric: tabular-nums; }
.history-panel .section-top > .button { grid-area: 1 / 3; justify-self: end; padding-inline: 13px; }
.history-panel .history-tools { grid-area: 1 / 2; justify-self: end; width: min(100%, 245px); color: var(--muted); }
.history-columns, #history-list { grid-column: 1 / -1; }
.history-search-field { display: block; position: relative; }
.history-search-field:focus-within .search-glyph { color: var(--text); }
.history-tools .history-search-field input {
  width: 100%; min-height: 38px; padding: 6px 12px 6px 34px;
  color-scheme: dark; background: var(--bg); color: var(--text);
  border: 1px solid #626262; border-radius: var(--control-radius);
  font: 400 16px/1.4 var(--font);
}
.history-tools .history-search-field input::placeholder { color: var(--faint); opacity: 1; }
.search-glyph {
  position: absolute; left: 12px; top: 50%; translate: 0 -60%;
  width: 11px; height: 11px; border: 1.25px solid currentColor;
  border-radius: 50%; pointer-events: none;
}
.search-glyph::after { content: ''; position: absolute; width: 5px; right: -4px; bottom: -2px; height: 1px; transform: rotate(45deg); background: currentColor; }

.record-identity { gap: 11px; }
.record-icon { display: inline-grid; flex: none; place-items: center; width: 18px; color: var(--faint); }
.record-icon svg { width: 15px; height: 15px; }
.record-copy { display: grid; gap: 2px; min-width: 0; }
.record-copy .history-name, .record-copy .history-target { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.record-copy .history-name { color: var(--text); font: 550 16px/1.35 var(--font); }
.record-copy .history-target { margin: 0; color: var(--faint); font: 400 12px/1.45 var(--font); }
.record-date, .history-panel .history-row time { color: var(--muted); font: 400 12px/1.5 var(--font); font-variant-numeric: tabular-nums; }
.record-arrow { justify-self: end; color: var(--faint); }
.record-arrow svg { width: 14px; height: 14px; }
.history-panel .history-entry .history-row {
  display: grid; align-items: center; width: 100%; min-width: 0;
  min-height: 59px; padding: 10px 6px; gap: 14px;
  text-align: left; color: var(--text);
}
.history-panel .history-entry:hover { background: var(--record-hover); }
.history-panel .history-entry:has(.history-row[aria-current="true"]) {
  --faint: var(--muted);
  background: var(--petrol);
  box-shadow: inset 3px 0 var(--teal);
}
.history-row:hover .record-arrow { color: var(--text); }
.history-panel .history-row:focus-visible { outline-offset: -2px; }
:is(.history-row, .catalog-entry) > .run-status {
  justify-self: start;
  padding: 0; border: 0; background: none;
  font: 500 11px/1.4 var(--font); letter-spacing: .025em;
}
#history-list {
  min-width: 0;
  margin-top: 14px;
}
.history-panel:has(.history-entry) #history-list { margin: 0; }
.history-panel .history-entry { display: grid; align-items: center; grid-template-columns: minmax(0, 1fr) var(--action-space); border-bottom: 1px solid var(--line-soft); }
.history-panel .history-entry:last-child { border: 0; }
.history-panel .history-entry .history-row, .history-columns { grid-template-columns: var(--history-grid); }
.history-columns {
  display: none; align-items: center; gap: 14px;
  margin-top: 15px;
  padding: 10px calc(6px + var(--action-space)) 10px 6px;
  border-block: 1px solid var(--record-border);
  color: var(--muted);
  font: 500 11px/1.4 var(--font);
  letter-spacing: .035em;
}
:where(.history-panel:has(.history-entry)) .history-columns { display: grid; }
.history-columns .record-date { font: inherit; color: inherit; }
.history-panel .history-entry .history-mode { color: var(--muted); font-size: 13px; }
.history-delete-slot { margin: 0; justify-self: start; }
.history-panel .history-delete {
  position: relative; width: 32px; height: 32px; min-height: 32px; padding: 0;
  color: var(--faint); background: transparent; border: 0; border-radius: 50%;
}
.history-panel .history-delete svg { width: 14px; height: 14px; }
.history-panel .history-delete:hover:not(:disabled) { background: var(--control-fill); color: var(--coral); }
.history-panel .history-delete:has(span) svg { color: var(--coral); }
.history-panel .history-delete span {
  position: absolute; right: 100%; padding: 2px 5px; border-radius: 3px;
  background: var(--record-background); color: var(--text); font-size: 10px;
}
.history-panel .history-delete:disabled { opacity: 1; color: var(--faint); }

.audit-empty { display: flex; align-items: center; gap: 12px; padding: 22px var(--row-inset); color: var(--text); }
.history-panel .audit-empty, .history-panel .history-no-match { min-height: 120px; }
.audit-empty strong { color: var(--text); font-size: 16px; font-weight: 500; }
.audit-empty p { margin-top: 3px; color: var(--muted); font-size: 16px; }
.history-no-match { display: grid; align-content: center; padding: 20px var(--row-inset); color: var(--muted); }

@container (max-width: 780px) {
  .history-panel .history-entry .history-row, .history-columns { grid-template-columns: minmax(0, 1fr) 95px 110px 14px; }
  .history-panel .history-entry .history-mode, .history-columns .history-mode { display: none; }
}
@container (max-width: 610px) {
  .history-panel .history-entry .history-row, .history-columns { grid-template-columns: minmax(0, 1fr) auto; gap: 6px; }
  .history-panel .history-columns, .history-panel .record-arrow { display: none; }
  .history-panel .history-entry .history-row { row-gap: 2px; }
  .history-panel:has(.history-entry) #history-list { border-top: 1px solid var(--record-border); }
  .history-panel .history-row .record-identity { grid-row: 1 / 3; }
  .history-panel .history-row > .run-status, .history-panel .history-row .record-date { justify-self: end; }
  .history-panel .history-row .record-date { grid-column: 2; }
  .history-panel .history-row time { font-size: 10px; }
  .record-identity { gap: 7px; }
  .history-panel .history-delete span { display: none; }
}
@container (max-width: 420px) {
  .history-panel .record-identity .record-icon { display: none; }
}
@media (max-width: 850px) {
  .history-panel { grid-template-columns: minmax(0, 1fr) auto; gap: 0 8px; }
  .history-panel .section-top > .button { grid-area: 1 / 2; }
  .history-panel .history-tools { grid-area: 2 / 1 / 3 / -1; width: min(100%, 350px); justify-self: start; padding-block: 10px; }
  .history-columns { margin-top: 0; }
}
@media (max-width: 600px) {
  .history-panel .history-tools { width: 100%; }
  #history-list { margin-top: 0; }
  .history-panel .section-top h2 { font-size: 24px; }
  .history-heading { gap: 0 8px; }
  .history-panel .section-top .button { gap: 4px; padding-inline: 9px; font-size: 12px; }
  .history-panel { padding-block-start: 15px; }
}

/* Keep titles and confirmation actions within reach as longer details scroll. */
.record-dialog {
  width: min(536px, calc(100% - 24px));
  max-width: none;
  max-height: min(86dvh, 830px);
  padding: 0;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

.record-dialog[open] { display: flex; flex-direction: column; }

.record-dialog .dialog-heading {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin: 0;
  padding: 22px var(--record-padding) 17px;
  border-bottom: 1px solid var(--record-border);
}

.record-dialog .dialog-heading h2 {
  margin: 0;
  color: var(--text);
  font: 500 clamp(32px, 3vw, 40px)/1.04 var(--font-display);
  letter-spacing: -.035em;
  word-break: normal;
  overflow-wrap: anywhere;
}

.record-dialog .icon-button { flex: none; }
.record-dialog-body { overflow-y: auto; overscroll-behavior: contain; padding: 16px var(--record-padding) 20px; }

.record-dialog .dialog-actions {
  flex: none;
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 12px var(--record-padding);
  background: color-mix(in srgb, var(--bg) 56%, var(--record-background));
  border-top: 1px solid var(--record-border);
}

.record-dialog .dialog-actions .button { min-height: 36px; padding: 7px 16px; border-radius: var(--control-radius); font: 500 13px/1.35 var(--font); }
.record-dialog .dialog-actions .secondary { background: transparent; color: var(--muted); }
.record-dialog .dialog-actions .secondary:hover { color: var(--text); border-color: var(--faint); }

.record-dialog .dialog-intro, .record-dialog .help-copy p {
  color: var(--muted);
  font: 400 16px/1.55 var(--font);
  overflow-wrap: anywhere;
}

.record-dialog .dialog-intro { margin: 0 0 16px; }
.record-dialog .help-copy p { margin: 8px 0 12px; }
.record-dialog .help-copy pre {
  max-height: 40dvh;
  margin: 10px 0;
  overflow: auto;
  white-space: pre-wrap;
  padding: 9px 12px;
  border-inline-start: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: 400 13px/1.65 var(--font);
  overflow-wrap: anywhere;
}

#health-details, #catalog-runs, .delete-reference {
  min-width: 0;
}

#health-details:not(:has(*)) { padding-block: 9px; color: var(--muted); }
.health-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 1px;
  border-bottom: 1px solid var(--record-border);
  font-size: 16px;
}
.health-item:last-child { border: 0; }
.health-item b {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px;
  border-radius: var(--control-radius); background: var(--petrol); color: var(--text);
  font: 400 12px/1.4 var(--font);
}
.health-item b::before { content: ''; flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--teal); }
.health-item b.missing { background: var(--control-fill); box-shadow: inset 0 0 0 1px var(--coral); }
.health-item b.missing::before { background: var(--coral); }
.help-copy { margin-top: 16px; }

.help-copy details { border-top: 1px solid var(--record-border); }
.help-copy details:last-child { border-bottom: 1px solid var(--record-border); }

.help-copy summary,
.activity-panel > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  list-style: none;
  font: 500 16px/1.45 var(--font);
  color: var(--text);
}
.help-copy summary { padding: 10px 1px; }
:is(.help-copy, .activity-panel) summary::-webkit-details-marker { display: none; }

.help-copy summary::after,
.activity-panel > summary::after {
  content: '';
  flex: none;
  width: 7px;
  height: 7px;
  margin-inline: auto 4px;
  border-right: 1px solid var(--muted);
  border-bottom: 1px solid var(--muted);
  transform: rotate(45deg);
}
.help-copy details[open] > summary::after,
.activity-panel[open] > summary::after { transform: rotate(225deg); border-color: var(--teal); }

#catalog-runs { color: var(--muted); border-block-start: 1px solid var(--line-soft); }
.catalog-entry {
  display: grid;
  width: 100%;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px 15px;
  padding: 10px 3px;
  border-bottom: 1px solid var(--record-border);
  text-align: left;
  overflow-wrap: anywhere;
}
.catalog-entry:last-child { border: 0; }
.catalog-entry strong { color: var(--text); font: 500 16px/1.45 var(--font); }
.catalog-entry small { color: var(--muted); font: 400 12px/1.5 var(--font); }
.catalog-entry .record-date { text-align: right; }
.catalog-entry:hover { background: var(--record-hover); }
.catalog-entry:focus-visible { outline-offset: -3px; }

.delete-reference { display: flex; align-items: center; gap: 10px; padding: 1px 0; }
.delete-reference .record-icon { color: var(--coral); }
.delete-reference > div { min-width: 0; overflow-wrap: anywhere; }
.delete-reference .delete-run-name { margin: 0; color: var(--text); font-size: 16px; font-weight: 550; }
.delete-reference #delete-run-id { display: block; margin: 2px 0 0; color: var(--muted); font: 400 12px/1.4 var(--font); }
#delete-dialog #delete-description { margin: 14px 0 0; }

.activity-panel {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--raised-shadow); padding: 0 var(--row-inset);
}
.activity-panel > summary { padding: 14px 1px; }
.activity-panel > summary:focus-visible { outline-offset: -4px; }
.activity-panel[open] > summary { border-bottom: 1px solid var(--record-border); }
.activity-panel .activity-controls { display: flex; justify-content: flex-end; align-items: center; gap: 8px; padding: 9px 0; }
.activity-controls select, .activity-controls .icon-button {
  height: 34px;
  color: var(--text);
  font-size: 13px;
  border: 1px solid var(--record-border);
  border-radius: var(--control-radius);
  background: var(--control-fill);
}
.activity-controls .icon-button { width: 34px; }
.activity-list { height: 230px; overflow-y: auto; padding: 0 0 10px; }
.activity-list .event-row {
  display: grid;
  grid-template-columns: 60px 94px minmax(0, 1fr);
  align-items: baseline;
  gap: 12px;
  padding: 8px 3px;
  border-bottom: 1px solid var(--line-soft);
  font: 400 12px/1.5 var(--font);
  cursor: pointer;
}
.activity-list :is(.event-kind, .event-description) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.activity-list .event-kind { color: var(--muted); }
.activity-list .event-row:hover { background: var(--record-hover); }
.activity-list .event-time, .activity-empty small, .activity-empty .terminal-prompt { color: var(--muted); }
.activity-list .event-description { color: var(--text); font-size: 16px; }
.activity-list :is(.event-time, .event-kind) { font-size: 12px; }
.activity-empty { display: flex; justify-content: center; align-items: center; height: 100%; gap: 14px; color: var(--text); }
.activity-empty small { display: block; }
.activity-empty { font-size: 16px; }
.activity-empty small { font-size: 13px; }

@media (max-width: 560px) {
  .record-dialog { max-height: calc(100dvh - 24px); }
  .record-dialog .dialog-heading { padding-block: 13px 10px; }
  .record-dialog .dialog-heading h2 { font-size: 31px; }
  .record-dialog .dialog-actions .button { min-height: 38px; }
  .record-dialog .dialog-actions { padding-block: 12px; }
  .catalog-entry { grid-template-columns: minmax(0, 1fr); }
  .catalog-entry > .run-status { grid-row: 3; }
  .catalog-entry .record-date { text-align: left; }
  .activity-list .event-row { grid-template-columns: 45px 65px minmax(0, 1fr); gap: 5px; }
  .activity-list .event-row .event-kind { display: block; }
}
