.automation-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.automation-heading h1 {
  font-size: 23px;
  margin: 0 0 5px;
}
.automation-heading p {
  font-size: 12px;
  margin: 0;
}
#automation-create {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  margin: 0;
}
.automation-rule-list {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}
.automation-rule {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
}
.automation-rule > div:first-child {
  min-width: 0;
}
.automation-rule h2 {
  font-size: 14px;
  margin: 0 0 6px;
  overflow-wrap: anywhere;
}
.automation-rule p {
  margin: 0;
  line-height: 1.7;
}
.automation-rule-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: none;
}
.automation-rule-actions button {
  margin: 0;
  font-size: 11px;
  min-height: 32px;
  padding: 4px 0;
}
.automation-state,
.automation-run-status {
  display: inline-block;
  padding: 3px 7px;
  border-radius: 5px;
  font-size: 11px;
  background: var(--surface-soft);
  color: var(--text-secondary);
  white-space: nowrap;
}
.automation-state.on,
.automation-run-status.done {
  background: var(--success-bg);
  color: var(--success);
}
.automation-run-status.failed,
.automation-run-status.expired,
.automation-run-status.unknown {
  background: var(--danger-bg, var(--surface-soft));
  color: var(--danger);
}
.automation-run-status.waiting_callback,
.automation-run-status.responding,
.automation-run-status.response_ready {
  background: var(--brand-soft);
  color: var(--brand);
}
.automation-empty {
  display: flex;
  gap: 10px;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 25px;
}
.automation-empty > i {
  font-size: 24px;
  color: var(--brand);
}
.automation-empty h2 {
  font-size: 15px;
  margin: 0;
}
.automation-empty p {
  font-size: 12px;
  margin: 0;
}
.automation-history {
  padding: 0 !important;
  overflow: hidden;
}
.automation-history > .section-heading {
  padding: 14px 18px;
  margin: 0;
  border-bottom: 1px solid var(--border);
}
.automation-history h2 {
  font-size: 13px;
  margin: 0;
}
.automation-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.automation-table th,
.automation-table td {
  padding: 11px 18px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.automation-table th {
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
  background: var(--surface-soft);
}
.automation-table td:first-child {
  width: 48%;
}
.automation-table td > strong {
  display: block;
  font-size: 12px;
  margin-bottom: 4px;
}
.automation-table td > span.small,
.automation-table td > small {
  display: block;
  margin-top: 4px;
}
.automation-pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 10px 18px;
  font-size: 11px;
  color: var(--text-secondary);
}
.automation-pagination button {
  min-height: 30px;
  margin: 0;
  padding: 4px 10px;
  font-size: 11px;
}
#webhook-rule-form-dialog {
  width: min(780px, calc(100vw - 24px));
}
#webhook-rule-form {
  min-width: 0;
}
.automation-flow {
  padding: 9px 12px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 11px;
  line-height: 1.7;
  border-radius: 6px;
  margin: 0 0 16px;
}
.automation-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.automation-form-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.automation-fieldset {
  min-width: 0;
  padding: 12px 14px 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 12px 0 18px;
}
.automation-fieldset legend {
  padding: 0 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}
#webhook-rule-form .mt-field {
  min-width: 0;
  margin-bottom: 12px;
}
#webhook-rule-form .mt-field input,
#webhook-rule-form .mt-field select,
#webhook-rule-form .mt-field textarea {
  min-width: 0;
  width: 100%;
}
#webhook-rule-form .small {
  font-size: 11px;
  line-height: 1.7;
  margin: 0 0 12px;
}
#webhook-rule-form .check {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  margin: 10px 0;
}
#webhook-rule-form .check input {
  width: 15px;
  height: 15px;
  min-height: 0;
  flex: none;
}
.automation-condition {
  display: grid;
  grid-template-columns: 1fr 1.2fr 1.4fr 30px;
  gap: 8px;
  align-items: center;
}
.automation-remove {
  display: grid;
  place-items: center;
  width: 30px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  margin: 0;
  background: transparent;
  color: var(--text-secondary);
  border: 0;
}
.automation-remove:hover {
  background: var(--surface-hover);
  color: var(--danger);
}
.automation-branch {
  border: 1px solid var(--border);
  padding: 10px 12px 0;
  border-radius: 7px;
  margin-bottom: 12px;
  background: var(--surface-soft);
}
.automation-branch .section-heading {
  margin: 0 0 8px;
}
.automation-branch h3 {
  font-size: 12px;
  margin: 0;
}
.automation-dry-test {
  padding: 12px;
  margin-bottom: 14px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 7px;
}
.automation-dry-test > summary {
  font-size: 12px;
  cursor: pointer;
  line-height: 1.6;
}
.automation-dry-test[open] > summary {
  margin-bottom: 12px;
}
.automation-test-result {
  white-space: pre-wrap;
  font-size: 12px;
  line-height: 1.7;
  margin: 10px 0 0;
  overflow-wrap: anywhere;
  color: var(--brand);
}
@media (max-width: 767px) {
  .automation-heading {
    align-items: flex-start;
    gap: 10px;
  }
  .automation-heading h1 {
    font-size: 21px;
  }
  .automation-heading p {
    font-size: 11px;
  }
  #automation-create {
    padding: 8px;
    font-size: 11px;
    white-space: normal;
    min-height: 38px;
    max-width: 140px;
  }
  .automation-rule {
    padding: 14px 12px;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .automation-rule-actions {
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 8px;
  }
  .automation-rule-actions button {
    min-height: 38px;
  }
  .automation-form-grid,
  .automation-form-grid.three {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }
  .automation-condition {
    grid-template-columns: minmax(0, 1fr) 30px;
    gap: 0 6px;
  }
  .automation-condition > .mt-field {
    grid-column: 1;
  }
  .automation-condition > .automation-remove {
    grid-column: 2;
    grid-row: 1;
  }
  .automation-fieldset {
    padding: 10px 10px 2px;
  }
  .automation-table th,
  .automation-table td {
    padding: 9px 10px;
    font-size: 11px;
    overflow-wrap: anywhere;
  }
  .automation-table td:first-child {
    width: 44%;
  }
  .automation-pagination {
    padding: 10px;
    justify-content: center;
    gap: 8px;
  }
  .automation-pagination button {
    min-height: 36px;
  }
}
/* A single webhook workflow with compact rule management. */
.automation-heading {
  margin-bottom: 16px;
  gap: 12px;
}
.automation-heading h1 {
  font-size: 21px;
  margin-bottom: 4px;
}
.automation-heading p {
  font-size: 12px;
  line-height: 1.5;
}
#automation-create {
  min-height: 36px;
  padding: 8px 12px;
  font-size: 12px;
  max-width: none;
}
.automation-nav {
  display: flex;
  align-items: center;
  gap: 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.automation-nav [role="tab"] {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 40px;
  padding: 9px 0;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  margin: 0;
}
.automation-nav [aria-selected="true"] {
  color: var(--brand);
  border-bottom-color: var(--brand);
}
.automation-nav [role="tab"] span {
  padding: 1px 6px;
  min-width: 20px;
  border-radius: 5px;
  background: var(--surface-soft);
  font-size: 10px;
  text-align: center;
}
.automation-toolbar {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 200px 160px;
  gap: 8px;
  align-items: center;
}
.automation-toolbar :is(input, select) {
  height: 36px;
  min-height: 36px;
  margin: 0;
  font-size: 12px;
  width: 100%;
  min-width: 0;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}
.automation-search {
  position: relative;
  min-width: 0;
}
.automation-search > i {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
  color: var(--text-secondary);
  pointer-events: none;
}
.automation-search input {
  padding-left: 34px;
}
.automation-list-summary {
  margin: 11px 0;
  font-size: 11px;
  color: var(--text-secondary);
}
.automation-rule-list {
  gap: 8px;
  margin: 0;
}
.automation-rule {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  min-width: 0;
}
.automation-rule-symbol {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 18px;
}
.automation-rule-info {
  min-width: 0;
}
.automation-rule-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.automation-rule h2 {
  font-size: 13px;
  line-height: 1.5;
  margin: 0;
  overflow-wrap: anywhere;
}
.automation-rule .automation-state {
  font-size: 9px;
  padding: 2px 5px;
}
.automation-rule-source {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.5 !important;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.automation-rule-facts {
  display: flex;
  gap: 5px 10px;
  flex-wrap: wrap;
  font-size: 10px;
  color: var(--text-secondary);
  margin-top: 5px;
}
.automation-rule-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: flex-end;
  flex-wrap: nowrap;
}
.automation-rule-actions .automation-icon-action {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  min-height: 32px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 16px;
}
.automation-rule-actions .automation-icon-action:hover {
  background: var(--surface-soft);
  color: var(--brand);
}
.automation-rule-actions .automation-switch {
  position: relative;
  display: block;
  width: 36px;
  height: 32px;
  min-height: 32px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  flex-shrink: 0;
  border-radius: 6px;
}
.automation-switch:before {
  content: "";
  position: absolute;
  width: 28px;
  height: 16px;
  left: 4px;
  top: 8px;
  border-radius: 20px;
  background: var(--input, #cbd5e1);
}
.automation-switch:after {
  content: "";
  position: absolute;
  left: 6px;
  top: 10px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px #0002;
  transition: transform 0.15s;
}
.automation-switch[aria-checked="true"]:before {
  background: var(--brand);
}
.automation-switch[aria-checked="true"]:after {
  transform: translateX(12px);
}
.automation-rule-actions button:focus-visible,
.automation-nav button:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}
.automation-empty {
  min-height: 220px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: var(--surface);
  padding: 28px 18px;
  justify-content: center;
  gap: 10px;
}
.automation-empty p {
  max-width: 380px;
  line-height: 1.6;
}
.automation-empty button {
  min-height: 34px;
  font-size: 12px;
  margin: 4px 0 0;
  padding: 7px 12px;
}
.automation-history > .section-heading {
  padding: 12px 14px;
}
.automation-table th,
.automation-table td {
  padding: 10px 14px;
}
.automation-table td:first-child {
  width: 48%;
}
.automation-pagination {
  padding: 10px 14px;
}
@media (max-width: 720px) {
  .automation-toolbar {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
  .automation-search {
    grid-column: 1/-1;
  }
}
@media (max-width: 600px) {
  .automation-heading {
    align-items: flex-start;
    margin-bottom: 12px;
  }
  .automation-heading h1 {
    font-size: 19px;
  }
  .automation-heading p {
    font-size: 11px;
    max-width: 220px;
  }
  .automation-nav {
    margin-bottom: 12px;
    gap: 22px;
  }
  #automation-create {
    font-size: 11px;
    min-height: 36px;
    padding: 7px 10px;
    white-space: nowrap;
    flex-shrink: 0;
  }
  .automation-toolbar {
    gap: 7px;
  }
  .automation-toolbar :is(input, select) {
    font-size: 11px;
    height: 36px;
  }
  .automation-list-summary {
    font-size: 10px;
    margin: 10px 0;
  }
  .automation-rule {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    padding: 11px 12px;
  }
  .automation-rule-symbol {
    display: none;
  }
  .automation-rule h2 {
    font-size: 12px;
  }
  .automation-rule-source {
    font-size: 11px;
  }
  .automation-rule-title {
    gap: 5px;
  }
  .automation-rule-facts {
    font-size: 9px;
    gap: 3px 8px;
  }
  .automation-rule-actions {
    gap: 0;
    justify-content: flex-end;
  }
  .automation-rule-actions .automation-icon-action,
  .automation-rule-actions .automation-switch {
    width: 32px;
    height: 36px;
    min-height: 36px;
  }
  .automation-switch:before {
    left: 2px;
    top: 10px;
  }
  .automation-switch:after {
    left: 4px;
    top: 12px;
  }
  .automation-table thead {
    display: none;
  }
  .automation-table,
  .automation-table tbody {
    display: block;
    width: 100%;
  }
  .automation-table tr {
    display: grid;
    grid-template-columns: 1fr auto;
    padding: 11px 12px;
    gap: 8px;
    border-bottom: 1px solid var(--border);
  }
  .automation-table td {
    padding: 0;
    border: 0;
    font-size: 10px;
  }
  .automation-table td:first-child {
    width: auto;
    grid-column: 1/-1;
  }
  .automation-table td > strong {
    font-size: 12px;
  }
  .automation-table td > span.small {
    font-size: 11px;
    line-height: 1.5;
    margin-top: 3px;
  }
  .automation-table td:last-child {
    white-space: nowrap;
    color: var(--text-secondary);
    align-self: center;
  }
  .automation-pagination {
    padding: 10px;
    font-size: 10px;
    gap: 8px;
  }
}
@media (prefers-reduced-motion: reduce) {
  .automation-switch:after {
    transition: none;
  }
}

.page-heading.automation-heading {
  flex-direction: row;
}
.automation-heading > div {
  min-width: 0;
  flex: 1;
}
/* Balance the history card with the page header and a deliberate empty state. */
.shell main > section[data-page="rules"] {
  width: 100%;
  max-width: 1120px;
  margin-inline: auto;
}
[data-page="rules"] .page-heading.automation-heading {
  margin-bottom: 14px;
  align-items: center;
}
[data-page="rules"] .automation-nav {
  margin-bottom: 16px;
}
.automation-history {
  margin: 0 !important;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: none !important;
}
.automation-history > .section-heading {
  min-height: 54px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 16px;
}
.automation-history-title {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}
.automation-history-title h2 {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.5;
  margin: 0;
}
.automation-history-title > span {
  font-size: 10px;
  white-space: nowrap;
  background: var(--surface-soft);
  color: var(--text-secondary);
  padding: 2px 6px;
  border-radius: 5px;
}
#automation-refresh {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 30px;
  margin: 0;
  padding: 5px 8px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  font-size: 11px;
  color: var(--text-secondary);
}
#automation-refresh i {
  font-size: 14px;
}
.automation-run-empty {
  min-height: 230px;
  padding: 28px 20px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 9px;
}
.automation-empty-symbol {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--surface-soft);
  color: var(--text-secondary);
  font-size: 21px;
  margin-bottom: 3px;
}
.automation-run-empty h3 {
  font-size: 14px;
  line-height: 1.5;
  font-weight: 600;
  margin: 0;
  color: var(--text);
}
.automation-run-empty p {
  font-size: 12px;
  line-height: 1.65;
  color: var(--text-secondary);
  max-width: 330px;
  margin: 0;
}
.automation-run-empty button {
  font-size: 11px;
  min-height: 30px;
  padding: 5px 9px;
  margin: 2px 0 0;
  background: transparent;
  border: 0;
  color: var(--brand);
}
.automation-pagination {
  border-top: 1px solid var(--border);
  margin: 0;
}
@media (max-width: 600px) {
  [data-page="rules"] .page-heading.automation-heading {
    align-items: flex-start;
    margin-bottom: 12px;
  }
  .automation-history > .section-heading {
    padding: 10px 12px;
    min-height: 50px;
    gap: 8px;
  }
  .automation-history-title {
    gap: 6px;
  }
  .automation-history-title h2 {
    font-size: 12px;
  }
  .automation-run-empty {
    min-height: 240px;
    padding: 26px 18px;
  }
  .automation-run-empty p {
    max-width: 250px;
    font-size: 12px;
  }
  .automation-run-empty h3 {
    font-size: 14px;
  }
  #automation-refresh {
    font-size: 10px;
    padding: 5px 7px;
  }
}
/* One searchable source selector; the native hidden select stays the submitted value. */
.automation-source-picker {
  position: relative;
  min-width: 0;
  margin-bottom: 16px;
}
#automation-source-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  padding: 10px 12px;
  font-size: 13px;
  text-align: left;
  border: 1px solid var(--input, #dbdfe9);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
#automation-source-trigger > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#automation-source-trigger > i {
  flex-shrink: 0;
  font-size: 16px;
  color: var(--text-secondary);
}
#automation-source-trigger[aria-expanded="true"] {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 10%, transparent);
}
.automation-source-panel {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 5px);
  z-index: 10;
  border: 1px solid var(--input, #dbdfe9);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 8px 24px #07143718;
  padding: 6px;
}
.automation-source-search {
  position: relative;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
  margin-bottom: 4px;
}
.automation-source-search > i {
  position: absolute;
  top: 10px;
  left: 10px;
  font-size: 18px;
  color: var(--text-secondary);
}
#webhook-rule-form .automation-source-search input {
  margin: 0;
  width: 100%;
  min-height: 38px;
  height: 38px;
  padding: 8px 12px 8px 36px;
  font-size: 13px;
  background: var(--surface-soft);
  border-color: transparent;
  border-radius: 7px;
}
#automation-source-options {
  max-height: 220px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
#automation-source-options .automation-source-option {
  display: flex;
  align-items: center;
  gap: 9px;
  border: 0;
  box-shadow: none;
  padding: 9px 10px;
  width: 100%;
  min-height: 38px;
  background: transparent;
  text-align: left;
  border-radius: 6px;
  font-size: 12px;
  color: var(--text);
}
.automation-source-option > span {
  flex: 1;
  overflow-wrap: anywhere;
}
.automation-source-option > i {
  color: var(--text-secondary);
  font-size: 17px;
  flex-shrink: 0;
}
#automation-source-options .automation-source-option:hover,
#automation-source-options .automation-source-option:focus-visible {
  background: var(--surface-soft);
  outline: 0;
}
#automation-source-options .automation-source-option[aria-selected="true"] {
  background: var(--brand-soft);
  color: var(--brand);
}
#automation-source-status {
  color: var(--text-secondary);
  font-size: 11px;
  line-height: 1.5;
  margin: 4px 4px 0;
  padding: 6px 4px 2px;
  border-top: 1px solid var(--border);
}
@media (max-width: 600px) {
  #automation-source-options {
    max-height: 180px;
  }
  .automation-source-panel {
    box-shadow: 0 5px 18px #07143714;
  }
}
.automation-source-search > i {
  z-index: 1;
  pointer-events: none;
}
