/* ── Header ─────────────────────────────────────────────────────────────── */

dialog[data-type] {
  --exl-dialog-header-height: 48px;
}

.exl-dialog-header {
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--exl-dialog-header-height);
  padding: 5px 20px;
  border-bottom: 1px solid var(--spectrum-gray-200);
  background: #fff;
  flex-shrink: 0;
}

.exl-dialog-header .icon {
  display: flex;
  align-items: center;
  line-height: 0;

  /* Pull “Ask” closer than flex gap allows without tightening Ask–BETA */
  margin-inline-end: -4px;
}

.exl-dialog-header img {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

/* Match ExL heading scale (.h3): bold, stands out; compact line-height for the 48px header bar */
.exl-dialog-header .exl-dialog-header-title {
  flex: 1;
  margin: 0;
  font-family: var(--body-font-family);
  font-size: var(--exlm-font-size-h3);
  font-weight: var(--font-weight-bold);
  font-style: normal;
  line-height: 1.2;
  color: var(--spectrum-gray-800);
}

.exl-dialog-header-title-with-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.exl-dialog-header-title-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 9px;
  border-radius: 5px;
  background-color: #ebebef;
  color: #9d59b7;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 1;
}

.message-content .citation-number a {
  font-size: 12px;
}

.exl-dialog-header-expand,
.exl-dialog-header-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  min-width: 28px;
  padding: 0;
  background: none;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  color: var(--spectrum-gray-700);
  box-shadow: none;
  transition: background-color 0.15s ease;
}

/* Text control (e.g. Clear) — secondary outline button, distinct from icon-only controls */
.exl-dialog-header-clear {
  display: flex;
  align-items: center;
  justify-content: center;
  width: auto;
  min-width: auto;
  height: 30px;
  padding: 0 12px;
  border-radius: 6px;
  border: 1px solid var(--spectrum-gray-300);
  background: var(--spectrum-gray-50);
  box-shadow: 0 1px 2px rgb(0 0 0 / 6%);
  font-family: var(--body-font-family);
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  color: var(--spectrum-gray-800);
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.exl-dialog-header-clear:hover {
  background: var(--spectrum-gray-100);
  border-color: var(--spectrum-gray-400);
  box-shadow: 0 1px 3px rgb(0 0 0 / 8%);
}

.exl-dialog-header-clear:active {
  background: var(--spectrum-gray-200);
  border-color: var(--spectrum-gray-500);
  box-shadow: none;
}

/* styles.css declares `button:focus { background-color: var(--link-hover-color) }` without
 * a :focus-visible guard, which bleeds the brand blue onto these buttons on programmatic
 * focus (e.g. showModal()). Reset here, then restore the outline for keyboard-only. */
.exl-dialog-header-expand:focus,
.exl-dialog-header-close:focus {
  background: none;
  outline: none;
}

.exl-dialog-header-clear:focus {
  background: var(--spectrum-gray-50);
  border-color: var(--spectrum-gray-300);
  outline: none;
}

.exl-dialog-header-expand .icon,
.exl-dialog-header-close .icon {
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}

.exl-dialog-header-expand img,
.exl-dialog-header-close img {
  width: 16px;
  height: 16px;
  display: block;
}

.exl-dialog-header-expand:hover,
.exl-dialog-header-close:hover {
  background: var(--spectrum-gray-100);
}

.exl-dialog-header-expand:focus-visible,
.exl-dialog-header-close:focus-visible,
.exl-dialog-header-clear:focus-visible {
  outline: 2px solid var(--non-spectrum-navy-blue);
  outline-offset: 2px;
}

/* ── Body / Footer ───────────────────────────────────────────────────────── */

.exl-dialog-body {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  position: relative;
}

.exl-dialog-footer {
  flex-shrink: 0;
  border-top: 1px solid var(--spectrum-gray-200);
  background: #fff;
}

/* ── Drawer ──────────────────────────────────────────────────────────────── */

dialog[data-type='drawer'] {
  position: fixed;
  inset: 0 0 0 auto;
  margin: 0;
  width: 420px;
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh; /* UA default is calc(100% - 6px - 2em); override to fill viewport */
  padding: 0;
  border: none;
  border-radius: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 24px rgb(0 0 0 / 15%);
  opacity: 0;
  transform: translateX(100%);
  transition:
    opacity 0.25s ease,
    transform 0.25s ease;
}

dialog[data-type='drawer'][open] {
  opacity: 1;
  transform: translateX(0);
}

/* Expand re-positions the drawer as a centred modal. */
dialog[data-type='drawer'].exl-dialog-expanded {
  inset: 0;
  margin: auto;
  width: 80vw;
  height: 90dvh;
  border-radius: 12px;
  transform: none;
  box-shadow: 0 8px 40px rgb(0 0 0 / 25%);
}

/* Keep the page scrollable behind the drawer; the backdrop is semi-transparent by design. */
body:has(dialog[data-type='drawer'][open]) {
  overflow: auto;
}

dialog[data-type='drawer']::backdrop {
  background: transparent;
}

dialog[data-type='drawer'].exl-dialog-expanded::backdrop {
  background: rgb(0 0 0 / 60%);
}

dialog[data-type='drawer'] .exl-dialog-body {
  overflow: hidden;
}

/* ── Modal ───────────────────────────────────────────────────────────────── */

dialog[data-type='modal'] {
  position: fixed;
  inset: 0;
  margin: auto;
  width: clamp(320px, 90vw, 800px);
  max-height: 90dvh;
  padding: 0;
  border: none;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 40px rgb(0 0 0 / 25%);
  opacity: 0;
  scale: 0.96;
  transition:
    opacity 0.2s ease,
    scale 0.2s ease;
}

dialog[data-type='modal'][open] {
  opacity: 1;
  scale: 1;
}

dialog[data-type='modal']::backdrop {
  background: rgb(0 0 0 / 60%);
}
