:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  color: #111;
  background: #fff;
  --muted: #5a5a5a;
  --line: #ddd;
  --blue: #005ec5;
  --blue-tint: #edf4ff;
  --control-size: 2.25rem;
  --destination-gap: .45rem;
  --column-width-1: 31%;
  --column-width-2: 35%;
  --column-width-3: 10%;
  --column-width-4: 15%;
  --column-width-5: 9%;
}

* { box-sizing: border-box; }
body { margin: 0; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .5; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }

main { width: min(100% - 3rem, 70rem); margin: 0 auto; padding-block: 2.75rem 4.5rem; }
.page-heading, .toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .85rem;
}
.page-heading { margin-bottom: 1.5rem; }
.page-actions { display: flex; align-items: center; gap: .5rem; }
h1 { margin: 0; font-size: clamp(1.85rem, 4vw, 2.45rem); line-height: 1.1; letter-spacing: -.04em; }

.button, .filters button {
  min-height: var(--control-size);
  padding: .375rem .7rem;
  border: 1px solid transparent;
  border-radius: .4rem;
  background: #fff;
  color: inherit;
  white-space: nowrap;
  font-size: .875rem;
  font-weight: 600;
}
.secondary { border-color: var(--line); }
.secondary:hover:not(:disabled) { background: #f5f5f5; }
.primary { color: #fff; background: var(--blue); }
.primary:hover:not(:disabled) { background: #004f9f; }
.icon-symbols { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon {
  flex: none;
  width: 1.05rem;
  height: 1.05rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-button { display: inline-grid; place-items: center; flex: none; width: var(--control-size); padding: 0; }
.icon-shackle { transform-origin: 33% 46%; }

.toolbar { padding-bottom: .75rem; }
.filters { display: flex; gap: .2rem; }
.filters button:hover { background: #f5f5f5; }
.filters button[aria-pressed="true"] { color: var(--blue); background: var(--blue-tint); }
.count { font-variant-numeric: tabular-nums; margin-left: .2rem; }
.search { position: relative; width: min(100%, 16rem); }
.search .icon { position: absolute; inset: 50% auto auto .65rem; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input, textarea {
  width: 100%;
  padding: .45rem .65rem;
  border: 1px solid #bcbcbc;
  border-radius: .4rem;
  background: #fff;
  color: inherit;
}
.search input { min-height: var(--control-size); padding-inline-start: 2rem; font-size: .875rem; }

table { width: 100%; border-collapse: collapse; table-layout: fixed; text-align: left; }
th, td { padding: .65rem .75rem; border-bottom: 1px solid var(--line); }
th { position: relative; color: var(--muted); border-top: 1px solid var(--line); font-size: .875rem; font-weight: 650; }
th:first-child { padding-inline-start: 2.45rem; }
:is(th, .row-lift > td):nth-child(1) { width: var(--column-width-1); }
:is(th, .row-lift > td):nth-child(2) { width: var(--column-width-2); }
:is(th, .row-lift > td):nth-child(3) { width: var(--column-width-3); }
:is(th, .row-lift > td):nth-child(4) { width: var(--column-width-4); }
:is(th, .row-lift > td):nth-child(5) { width: var(--column-width-5); }
.column-resize {
  position: absolute;
  z-index: 1;
  inset: 0 -.5rem 0 auto;
  width: 1rem;
  cursor: col-resize;
  touch-action: none;
  user-select: none;
}
.column-resize::after {
  content: "";
  position: absolute;
  inset: .65rem auto .65rem calc(50% - 1px);
  width: 2px;
  border-radius: 1px;
  background: var(--line);
}
.column-resize:is(:hover, :focus-visible, [data-resizing])::after { background: var(--blue); }
td { vertical-align: top; font-size: .875rem; line-height: 1.5; overflow-wrap: anywhere; }
td:first-child { font-weight: 600; }
td:last-child { text-align: right; }
.row-line { display: flex; align-items: center; min-height: var(--control-size); }
.recipient-line { gap: .35rem; }
.recipient-line > span { min-width: 0; }
.row-grip { width: 1.35rem; touch-action: none; user-select: none; color: var(--muted); cursor: grab; background: transparent; }
.row-grip:hover, .row-grip:focus-visible { color: var(--blue); background: var(--blue-tint); }
.row-grip:active { cursor: grabbing; }
.row-gap { background: #f4f7fb; }
.row-gap > td > * { visibility: hidden; }
.row-lift {
  display: table;
  table-layout: fixed;
  border-collapse: collapse;
  border-radius: .5rem;
  background: #fff;
  box-shadow: 0 .55rem 1.65rem #10244126, 0 0 0 1px #dbe4f1;
  opacity: 1 !important;
}
.row-lift > td { border: 0; }
.subscription-value { font-weight: 700; font-variant-numeric: tabular-nums; }
.destination {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--control-size);
  align-items: start;
  gap: var(--destination-gap);
  width: min(100%, calc(17rem + var(--control-size) + var(--destination-gap)));
}
.destination .icon-button { color: var(--blue); }
.destination > *, .destination-first { min-width: 0; }
.destination-summary { width: fit-content; gap: .35rem; cursor: pointer; list-style: none; }
.destination-summary::-webkit-details-marker { display: none; }
.destination-summary .icon { width: .85rem; height: .85rem; color: var(--blue); transform: rotate(var(--chevron-angle, 0deg)); }
.destination-details[open] { --chevron-angle: 180deg; }
.destination-count { flex: none; color: var(--blue); font-size: .8125rem; font-weight: 600; }
.destination-list { list-style: none; padding: 0 0 .15rem; margin: 0; }
.destination-list li + li { margin-top: .15rem; }
.missing-destination { color: var(--muted); }
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .15rem .45rem;
  border-radius: 1rem;
  background: #f1f1f1;
  color: var(--muted);
  font-size: .8125rem;
  font-weight: 600;
  white-space: nowrap;
}
.status-badge .icon { width: .85rem; height: .85rem; }
.status-badge.is-active { color: var(--blue); background: var(--blue-tint); }
.empty { padding: 1.5rem 0; color: var(--muted); text-align: center; }
.notice { padding: .6rem .75rem; border: 1px solid var(--line); border-radius: .4rem; font-size: .875rem; }
.notice[data-error="true"], #confirm-error { border-color: #111; font-weight: 600; }

.skeleton-row td { height: calc(var(--control-size) + 1.3rem); vertical-align: middle; }
.skeleton { display: block; height: .8rem; width: 72%; border-radius: .3rem; background: #e8edf4; }
.skeleton-row:nth-child(even) td:first-child .skeleton { width: 57%; }
.skeleton-row td:nth-child(2) .skeleton { width: 54%; }
.skeleton-row:nth-child(even) td:nth-child(2) .skeleton { width: 62%; }
.skeleton-row td:nth-child(3) .skeleton { width: min(100%, 3rem); }
.skeleton-row td:nth-child(4) .skeleton { width: min(100%, 4rem); height: 1.35rem; border-radius: 1rem; }
.skeleton-row td:last-child .skeleton { width: var(--control-size); height: var(--control-size); margin-inline-start: auto; }

.help-toggle[aria-expanded="true"] { background: var(--blue-tint); color: var(--blue); border-color: #c8ddfa; }
.help-panel {
  margin-bottom: 1.25rem;
  padding: .9rem 1rem;
  border: 1px solid #d9e6f7;
  border-radius: .6rem;
  background: #f6f9fd;
  font-size: .875rem;
  line-height: 1.5;
}
.help-panel h2 { margin: 0; font-size: 1rem; }
.help-panel ol {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .55rem 2rem;
  margin: .45rem 0 0;
  padding-inline-start: 1.2rem;
}
.help-panel li::marker { color: var(--blue); font-weight: 700; }
.help-panel a { color: var(--blue); }

dialog {
  width: min(26rem, 100% - 2rem);
  max-height: calc(100dvh - 2rem);
  overflow: hidden;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: .75rem;
  background: #fff;
  color: inherit;
  box-shadow: 0 .75rem 2rem #0002;
}
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: #0004; }
.dialog-content { min-height: 0; overflow-y: auto; padding: 1.25rem; }
dialog h2 { margin: 0; font-size: 1.25rem; line-height: 1.25; letter-spacing: -.02em; }
dialog p { margin: .75rem 0 0; line-height: 1.5; overflow-wrap: anywhere; }
.dialog-recipient { margin-top: .25rem; color: var(--muted); font-size: .875rem; }
.destination-editor { margin-top: 1rem; }
.destination-editor label { display: block; margin-bottom: .35rem; font-size: .875rem; font-weight: 600; }
textarea { display: block; resize: vertical; line-height: 1.5; }
textarea:focus-visible { outline-offset: -1px; }
#destination-hint { margin-top: .4rem; color: var(--muted); font-size: .8125rem; }
.dialog-actions {
  display: flex;
  flex: none;
  justify-content: flex-end;
  gap: .5rem;
  padding: .75rem 1.25rem;
  border-top: 1px solid #e8e8e8;
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

@media (prefers-reduced-motion: no-preference) {
  dialog[open] { animation: dialog-appear 150ms ease-out; }
  .skeleton { animation: skeleton-pulse 1s ease-in-out infinite alternate; }
}

@keyframes dialog-appear {
  from { opacity: 0; transform: translateY(4px) scale(.985); }
  to { opacity: 1; transform: none; }
}

@keyframes skeleton-pulse { from { opacity: .55; } to { opacity: 1; } }

@media (hover: hover) and (prefers-reduced-motion: no-preference) {
  .icon, .icon-shackle { transition: transform 280ms cubic-bezier(.22, 1.45, .4, 1); }
  #refresh:is(:hover, :focus-visible):not(:disabled) .icon { transform: rotate(45deg); }
  .edit-destinations:is(:hover, :focus-visible):not(:disabled) .icon { transform: translateY(-2px) rotate(-12deg); }
  .mapping-action-lock:is(:hover, :focus-visible):not(:disabled) .icon-shackle { transform: translateY(1px); }
  .mapping-action-unlock:is(:hover, :focus-visible):not(:disabled) .icon-shackle { transform: translateY(-2px) rotate(-14deg); }
  .status-badge:hover .icon { transform: scale(1.2); }
  .search:is(:hover, :focus-within) .icon { transform: translate(2px, -50%); }
  .destination-summary:is(:hover, :focus-visible) .icon { transform: translateY(2px) rotate(var(--chevron-angle, 0deg)); }
  .row-grip:is(:hover, :focus-visible) .icon { transform: scale(1.12); }
}

@media (max-width: 48rem) {
  :root { --control-size: 2.75rem; }
  main { width: calc(100% - 2rem); padding-top: 1.5rem; }
  .page-heading { flex-wrap: wrap; }
  .help-panel ol { grid-template-columns: 1fr; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .search { width: 100%; }
  .destination { width: 100%; }
  table, tbody, td { display: block; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .column-resize { display: none; }
  tbody tr, .row-lift { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: .25rem .75rem; padding: .75rem 0; }
  tbody tr { border-top: 1px solid var(--line); }
  .row-lift > td:nth-child(n) { width: auto; }
  tbody tr:last-child { border-bottom: 1px solid var(--line); }
  td { padding: 0; border: 0; }
  td:first-child, td:nth-child(2) { grid-column: 1 / -1; }
  td:first-child .row-line { min-height: 1.75rem; }
  .row-grip { width: 2rem; }
  td:nth-child(2)::before { content: "Destinations"; display: block; color: var(--muted); font-size: .8125rem; }
  .subscription-value::before { content: "Sub"; color: var(--muted); margin-inline-end: .35rem; }
  .skeleton-row td { display: flex; align-items: center; height: var(--control-size); }
  .skeleton-row td:nth-child(2)::before { content: none; }
}
