.automation-rule-guide {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  color: var(--muted);
}

.automation-rule-guide strong { color: var(--ink); }
.automation-rule-panel { overflow: hidden; }
.automation-rule-count { color: var(--muted); }
.automation-rule-table { min-width: 1180px; }
.automation-rule-table th:first-child,
.automation-rule-table td:first-child { width: 74px; }
.automation-rule-table th:nth-last-child(-n+2),
.automation-rule-table td:nth-last-child(-n+2) { width: 96px; }
.automation-rule-table td small { display: block; margin-top: 3px; color: var(--muted); }
.automation-rule-table tr.is-inactive { opacity: .6; }
.automation-rule-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.automation-rule-actions form { margin: 0; }

.accounting-rule-link {
  max-width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  text-align: left;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 3px;
  cursor: pointer;
}
.accounting-rule-link:hover,
.accounting-rule-link:focus-visible {
  color: #1769aa;
  text-decoration-color: currentColor;
}

.automation-rule-summary { min-width: 230px; }
.automation-rule-summary span {
  display: block;
  margin: 2px 0;
  color: var(--muted);
}
.automation-rule-summary b { color: var(--ink); font-weight: 600; }

.automation-rule-dialog { width: min(920px, calc(100vw - 32px)); }
.automation-rule-dialog > form { padding: 0; }
.automation-rule-dialog .management-dialog-heading,
.automation-rule-dialog .management-dialog-actions { padding: 20px 24px; }
.automation-rule-dialog .management-dialog-heading { border-bottom: 1px solid var(--line); }
.automation-rule-dialog .management-dialog-actions { border-top: 1px solid var(--line); }
.automation-rule-form-section { padding: 20px 24px; }
.automation-rule-form-section + .automation-rule-form-section { border-top: 1px solid var(--line); }
.automation-rule-form-section h3 { margin: 0 0 6px; font-size: 18px; }
.automation-rule-form-section > p { margin: 0 0 14px; color: var(--muted); }
.automation-rule-meta-grid,
.automation-action-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.automation-rule-meta-grid label,
.automation-action-grid label { display: grid; gap: 6px; font-weight: 600; }
.automation-action-grid label.is-disabled {
  color: var(--muted);
  opacity: .56;
}
.automation-rule-meta-grid input,
.automation-rule-meta-grid select,
.automation-action-grid input,
.automation-action-grid select,
.automation-condition-row input,
.automation-condition-row select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 0 11px;
  font: inherit;
}
.automation-condition-list { display: grid; gap: 8px; margin: 16px 0 10px; }
.automation-condition-row {
  display: grid;
  grid-template-columns: 170px 170px minmax(180px, 1fr) minmax(150px, .7fr) 36px;
  gap: 8px;
  align-items: center;
}
.automation-condition-remove {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: var(--surface);
  font-size: 20px;
  cursor: pointer;
}
.automation-action-memo { grid-column: 1 / -1; }
.field-error { color: var(--danger); font-weight: 700; }

.automation-preview-panel { overflow: hidden; scroll-margin-top: 18px; }
.automation-preview-heading {
  align-items: flex-end;
  gap: 18px;
}
.automation-preview-heading p:not(.eyebrow) {
  max-width: 780px;
  margin: 6px 0 0;
  color: var(--muted);
}
.automation-preview-period {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-left: auto;
}
.automation-preview-period label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.automation-preview-period select {
  min-width: 128px;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 0 10px;
  font: inherit;
}
.automation-preview-summary {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 12px 18px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}
.automation-preview-summary strong { color: var(--ink); font-size: 18px; }
.automation-preview-periods {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: #fafafa;
}
.automation-preview-periods span {
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
}
.automation-preview-periods b { color: var(--ink); }
.automation-preview-table { min-width: 760px; }
.automation-preview-table th:first-child,
.automation-preview-table td:first-child { width: 90px; }
.automation-preview-table th:nth-child(2),
.automation-preview-table td:nth-child(2) { width: 120px; }
.automation-preview-table th:nth-child(3),
.automation-preview-table td:nth-child(3) { width: 110px; }
.automation-preview-table th:last-child,
.automation-preview-table td:last-child { width: 150px; }
.automation-preview-scroll {
  max-height: min(480px, calc(100vh - 280px));
  overflow: auto;
  overscroll-behavior-x: contain;
  overscroll-behavior-y: auto;
}
.automation-preview-scroll .ui-table-viewport__inner { min-height: 0; }
.automation-preview-result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 18px;
  border-top: 1px solid var(--line);
  background: #fafafa;
}
.automation-preview-result--top {
  position: sticky;
  top: 0;
  z-index: 4;
  border-top: 0;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 4px 10px rgba(16, 24, 40, 0.04);
}
.automation-preview-result > div {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
}
.automation-preview-result span { color: var(--muted); }
.automation-preview-result b { color: var(--ink); }

@media (max-width: 760px) {
  .automation-rule-guide { align-items: flex-start; flex-direction: column; gap: 5px; }
  .automation-rule-meta-grid,
  .automation-action-grid { grid-template-columns: 1fr; }
  .automation-condition-row { grid-template-columns: 1fr; }
  .automation-condition-remove { justify-self: end; }
  .automation-preview-heading,
  .automation-preview-result { align-items: stretch; flex-direction: column; }
  .automation-preview-period { width: 100%; margin-left: 0; }
  .automation-preview-scroll { max-height: min(420px, calc(100vh - 220px)); }
}
