.automation-page-stack {
  height: 100%;
  display: flex;
  min-height: 0;
}

.automation-page {
  flex: 1;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
  border-radius: 18px;
}

.automation-page-body {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
  min-height: 0;
  padding: 0;
  overflow: hidden;
}

.automation-header,
.automation-header-actions,
.automation-detail-actions,
.automation-form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.automation-header-actions,
.automation-detail-actions,
.automation-form-actions {
  flex-wrap: wrap;
}

.automation-detail-actions {
  justify-content: flex-end;
}

.automation-action-button,
.automation-delete-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  min-width: 0;
}

.automation-action-button svg,
.automation-delete-button svg {
  width: 15px;
  height: 15px;
}

.automation-button-spinner {
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
  border: 2px solid rgba(255, 255, 255, 0.46);
  border-top-color: #ffffff;
  border-radius: 999px;
  animation: automation-spin 0.8s linear infinite;
}

@keyframes automation-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .automation-button-spinner {
    animation: none;
  }
}

.automation-button-primary {
  border: 1px solid rgba(37, 99, 235, 0.22);
  background: #2563eb;
  color: #ffffff;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.16);
}

.automation-button-primary:hover:not(:disabled),
.automation-button-primary:focus-visible {
  background: #1d4ed8;
}

.automation-button-secondary {
  border: 1px solid rgba(203, 213, 225, 0.92);
  background: #ffffff;
  color: #1f2937;
}

.automation-button-secondary:hover:not(:disabled),
.automation-button-secondary:focus-visible {
  border-color: rgba(147, 197, 253, 0.95);
  background: #eff6ff;
  color: #1d4ed8;
}

.automation-action-button:disabled,
.automation-delete-button:disabled,
.automation-filter-row button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.automation-form-actions .automation-form-button-secondary {
  border: 1px solid rgba(203, 213, 225, 0.92);
  background: #ffffff;
  color: #1f2937;
  box-shadow: none;
}

.automation-form-actions .automation-form-button-secondary:hover:not(:disabled),
.automation-form-actions .automation-form-button-secondary:focus-visible {
  border-color: rgba(147, 197, 253, 0.95);
  background: #eff6ff;
  color: #1d4ed8;
}

.automation-form-actions .automation-form-button-primary {
  border: 1px solid #1677FF;
  background: #1677FF;
  color: #ffffff;
  box-shadow: 0 8px 18px rgba(22, 119, 255, 0.18);
}

.automation-form-actions .automation-form-button-primary:hover:not(:disabled),
.automation-form-actions .automation-form-button-primary:focus-visible {
  border-color: #0F63D8;
  background: #0F63D8;
  color: #ffffff;
}

.automation-button-accent {
  border: 1px solid rgba(7, 193, 96, 0.42);
  background: #07C160;
  color: #ffffff;
  box-shadow: 0 6px 14px rgba(7, 193, 96, 0.18);
}

.automation-button-accent:hover:not(:disabled),
.automation-button-accent:focus-visible {
  border-color: rgba(6, 174, 86, 0.54);
  background: #06AD56;
  color: #ffffff;
}

.automation-delete-button {
  border: 1px solid rgba(248, 113, 113, 0.42);
  background: rgba(254, 242, 242, 0.96);
  color: #dc2626;
  cursor: pointer;
}

.automation-delete-button:hover:not(:disabled),
.automation-delete-button:focus-visible {
  border-color: rgba(220, 38, 38, 0.52);
  background: #fee2e2;
}

.automation-header h1,
.automation-detail-head h2,
.automation-runs h3 {
  margin: 0;
  color: #111827;
  letter-spacing: 0;
}

.automation-header h1 {
  font-size: 20px;
  line-height: 1.2;
}

.automation-header p,
.automation-detail-head p,
.automation-run-item p {
  margin: 5px 0 0;
  color: #64748b;
  font-size: 13px;
  line-height: 1.5;
}

.automation-layout {
  display: grid;
  grid-template-columns: minmax(260px, 0.72fr) minmax(0, 1.7fr);
  gap: 14px;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.automation-list-pane,
.automation-detail-pane,
.automation-form {
  min-width: 0;
  min-height: 0;
  border: 1px solid rgba(203, 213, 225, 0.86);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.82);
}

.automation-list-pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
  padding: 12px;
}

.automation-filter-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.automation-filter-row button {
  min-height: 32px;
  border: 1px solid rgba(203, 213, 225, 0.88);
  border-radius: 8px;
  background: #ffffff;
  color: #475569;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.automation-filter-row button.active {
  border-color: #93c5fd;
  background: #eff6ff;
  color: #1d4ed8;
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.12);
}

.automation-list-scroll {
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.automation-list-scroll .scroll-area-content {
  height: 100%;
  min-height: 0;
  overflow-y: auto;
}

.automation-task-list,
.automation-run-list {
  display: grid;
  gap: 7px;
}

.automation-task-row {
  height: 78px;
  overflow: hidden;
  padding: 10px;
  border: 1px solid rgba(226, 232, 240, 0.9);
  border-radius: 12px;
  background: #ffffff;
  color: inherit;
  text-align: left;
}

.automation-task-row.active {
  border-color: #60a5fa;
  background: linear-gradient(180deg, #eff6ff, #ffffff);
  box-shadow: inset 3px 0 0 #2563eb;
}

.automation-task-select {
  display: grid;
  gap: 5px;
  width: 100%;
  height: 100%;
  min-width: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.automation-task-select:focus-visible {
  outline: 2px solid rgba(37, 99, 235, 0.45);
  outline-offset: 3px;
}

.automation-task-select strong,
.automation-task-select small {
  overflow: hidden;
}

.automation-task-select strong {
  color: #0f172a;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.automation-task-select small {
  color: #64748b;
  font-size: 12px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.automation-detail-pane {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 10px;
  padding: 14px;
  overflow: hidden;
}

.automation-detail-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
}

.automation-detail-head h2 {
  margin-top: 6px;
  font-size: 20px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.automation-detail-prompt {
  display: -webkit-box;
  max-width: 100%;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow-wrap: anywhere;
}

.automation-kicker {
  display: inline-flex;
  max-width: 100%;
  min-height: 24px;
  align-items: center;
  padding: 0 9px;
  border-radius: 999px;
  background: #fef3c7;
  color: #92400e;
  font-size: 12px;
  font-weight: 800;
}

.automation-meta-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.automation-meta-grid div {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 12px;
  border-radius: 12px;
  background: #f8fafc;
  border: 1px solid rgba(226, 232, 240, 0.9);
}

.automation-meta-grid span {
  color: #64748b;
  font-size: 12px;
  font-weight: 700;
}

.automation-meta-grid strong {
  overflow: hidden;
  color: #1f2937;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.automation-runs {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
  min-height: 0;
}

.automation-runs h3 {
  font-size: 15px;
}

.automation-run-list {
  overflow: auto;
  min-height: 0;
  padding-right: 2px;
}

.automation-run-item {
  padding: 10px 12px;
  border: 1px solid rgba(226, 232, 240, 0.9);
  border-radius: 12px;
  background: #ffffff;
}

.automation-run-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: #64748b;
  font-size: 12px;
}

.automation-run-error {
  color: #b45309 !important;
}

.automation-run-markdown {
  margin-top: 8px;
  color: #334155;
  font-size: 13px;
  line-height: 1.5;
}

.automation-run-markdown > * {
  margin-top: 6px;
  margin-bottom: 0;
}

.automation-run-markdown > :first-child {
  margin-top: 0;
}

.automation-run-markdown .markdown-code-block {
  margin-top: 8px;
}

.automation-empty {
  display: grid;
  min-height: 120px;
  place-items: center;
  color: #64748b;
  font-size: 13px;
  font-weight: 700;
}

.automation-form {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 12px;
  overflow: hidden;
}

.automation-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  min-width: 0;
  overflow: auto;
}

.automation-form-grid label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.automation-form-grid label > span,
.automation-weekdays > label span,
.automation-enabled-toggle span {
  color: #475569;
  font-size: 12px;
  font-weight: 750;
}

.automation-form-grid input,
.automation-form-grid select,
.automation-form-grid textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid rgba(203, 213, 225, 0.95);
  border-radius: 10px;
  background: #ffffff;
  color: #111827;
  font: inherit;
  font-size: 13px;
}

.automation-form-grid input,
.automation-form-grid select {
  height: 38px;
  padding: 0 10px;
}

.automation-form-grid textarea {
  resize: vertical;
  min-height: 104px;
  padding: 10px;
  line-height: 1.5;
}

.automation-form-full {
  grid-column: 1 / -1;
}

.automation-weekdays {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.automation-weekdays label,
.automation-enabled-toggle {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 8px;
  border: 1px solid rgba(203, 213, 225, 0.9);
  border-radius: 10px;
  background: #ffffff;
}

.automation-weekdays input,
.automation-enabled-toggle input {
  width: 14px;
  height: 14px;
}

.automation-enabled-toggle {
  justify-content: flex-start;
  gap: 8px !important;
}

@media (max-width: 980px) {
  .automation-layout,
  .automation-detail-head {
    grid-template-columns: 1fr;
  }

  .automation-meta-grid,
  .automation-form-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .automation-header,
  .automation-detail-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .automation-header-actions,
  .automation-detail-actions,
  .automation-form-actions {
    align-items: stretch;
  }

  .automation-action-button,
  .automation-delete-button {
    width: 100%;
  }

  .automation-task-row {
    grid-template-columns: 1fr;
  }

  .automation-weekdays {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}
