:root {
  --automation-bg: #f0f2f5;
  --automation-card: #ffffff;
  --automation-card-soft: #f7f8fa;
  --automation-border: #e4e6eb;
  --automation-muted: #6b7280;
  --automation-text: #0f172a;
  --automation-accent: #1877f2;
  --automation-accent-2: #2563eb;
  --automation-danger: #dc2626;
  --automation-success: #059669;
  --automation-shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.08);
  --automation-shadow-md: 0 14px 45px rgba(15, 23, 42, 0.12);
}

.automation-view * {
  box-sizing: border-box;
}

.automation-view {
  color: var(--automation-text);
}

.automation-view .auto-shell {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-bottom: 32px;
}

.automation-view .auto-hero {
  position: relative;
  overflow: hidden;
  background: var(--automation-card);
  border: 1px solid var(--automation-border);
  border-radius: 14px;
  padding: 18px 20px;
  box-shadow: var(--automation-shadow-sm);
  margin: 0;
}

.automation-view .auto-hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, rgba(24, 119, 242, 0.08), rgba(37, 99, 235, 0.05));
  pointer-events: none;
}

.automation-view .auto-hero > * {
  position: relative;
  z-index: 1;
}

.automation-view .hero-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.automation-view .hero-text h1 {
  margin: 4px 0;
  font-size: 24px;
  letter-spacing: -0.01em;
  color: var(--automation-text);
}

.automation-view .eyebrow {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--automation-accent-2);
  margin: 0;
  font-weight: 700;
}

.automation-view .back-link {
  color: var(--automation-accent);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
}

.automation-view .back-link:hover {
  text-decoration: underline;
}

.automation-view .hero-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.automation-view .hero-stats {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.automation-view .stat {
  background: var(--automation-card-soft);
  border: 1px solid var(--automation-border);
  border-radius: 12px;
  padding: 12px;
  box-shadow: var(--automation-shadow-sm);
}

.automation-view .stat-label {
  color: var(--automation-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0 0 4px;
}

.automation-view .stat-value {
  font-size: 22px;
  font-weight: 700;
  margin: 0;
}

.automation-view .panel {
  background: var(--automation-card);
  border: 1px solid var(--automation-border);
  border-radius: 12px;
  padding: 18px 18px 16px;
  box-shadow: var(--automation-shadow-sm);
}

.automation-view .panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.automation-view .panel-eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 12px;
  color: var(--automation-muted);
  margin: 0;
  font-weight: 700;
}

.automation-view .panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

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

.automation-view .field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.automation-view .field.inline {
  min-width: 0;
}

.automation-view .field[data-section] {
  display: grid;
}

.automation-view label {
  font-weight: 600;
  color: var(--automation-text);
}

.automation-view input,
.automation-view textarea,
.automation-view select {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--automation-border);
  padding: 10px 12px;
  background: #fff;
  color: var(--automation-text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.automation-view input:focus,
.automation-view textarea:focus,
.automation-view select:focus {
  border-color: var(--automation-accent-2);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.automation-view textarea {
  resize: vertical;
}

.automation-view small {
  color: var(--automation-muted);
}

.automation-view .template-hint {
  border: 1px dashed var(--automation-border);
  background: #f8fafc;
  border-radius: 12px;
  padding: 10px 12px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  color: var(--automation-muted);
}

.automation-view .template-title {
  margin: 0 0 6px;
  color: var(--automation-text);
  font-weight: 700;
}

.automation-view .template-copy {
  margin: 0;
  word-break: break-all;
}

.automation-view .form-status {
  min-height: 22px;
  color: var(--automation-muted);
}

.automation-view .form-status.error {
  color: var(--automation-danger);
}

.automation-view .form-status.success {
  color: var(--automation-success);
}

.automation-view .table-wrap {
  overflow-x: auto;
}

.automation-view .auto-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

.automation-view .auto-table th,
.automation-view .auto-table td {
  padding: 10px 8px;
  text-align: left;
  border-bottom: 1px solid var(--automation-border);
  font-size: 14px;
  white-space: nowrap;
}

.automation-view .auto-table th {
  color: var(--automation-muted);
  font-weight: 700;
  background: var(--automation-card-soft);
}

.automation-view .auto-table th[data-sort-column="runs"],
.automation-view .auto-table td.runs-count {
  width: 1%;
  white-space: nowrap;
  text-align: right;
}

.automation-view .auto-table .sort-indicator {
  display: inline-block;
  margin-left: 6px;
  width: 18px;
  height: 18px;
  background-color: var(--automation-muted);
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path fill='black' d='M4 6l4 4 4-4z'/></svg>") no-repeat center / contain;
  mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path fill='black' d='M4 6l4 4 4-4z'/></svg>") no-repeat center / contain;
  opacity: 0.35;
}

.automation-view .auto-table th.sort-asc .sort-indicator {
  background-color: var(--automation-accent-2);
  transform: rotate(180deg);
  opacity: 0.9;
}

.automation-view .auto-table th.sort-desc .sort-indicator {
  background-color: var(--automation-accent-2);
  transform: rotate(0deg);
  opacity: 0.9;
}

.automation-view .table-filter-row th {
  background: var(--automation-card);
}

.automation-view .table-filter-row input,
.automation-view .table-filter-row select {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--automation-border);
  padding: 8px 10px;
  background: #fff;
  color: var(--automation-text);
  font-size: 13px;
}

.automation-view .auto-table tr.is-selected td {
  background: #eef2ff;
}

.automation-view .row-title {
  font-weight: 700;
  color: var(--automation-text);
}

.automation-view .row-sub {
  color: var(--automation-muted);
  font-size: 13px;
  word-break: break-all;
}

.automation-view .badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  background: #eef2ff;
  color: var(--automation-accent-2);
  border: 1px solid rgba(37, 99, 235, 0.28);
}

.automation-view .badge.success {
  background: rgba(5, 150, 105, 0.12);
  color: var(--automation-success);
  border-color: rgba(5, 150, 105, 0.35);
}

.automation-view .badge.error {
  background: rgba(220, 38, 38, 0.12);
  color: var(--automation-danger);
  border-color: rgba(220, 38, 38, 0.35);
}

.automation-view .row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
}

.automation-view .hidden-value {
  display: none;
}

.automation-view .icon-btn {
  border: 1px solid var(--automation-border);
  background: var(--automation-card-soft);
  color: var(--automation-text);
  border-radius: 8px;
  padding: 6px 8px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  transition: transform 0.15s ease, opacity 0.15s ease, border-color 0.15s ease, box-shadow 0.2s ease;
}

.automation-view .icon-btn:hover {
  transform: translateY(-1px);
  opacity: 0.95;
  border-color: #d1d5db;
  box-shadow: var(--automation-shadow-sm);
}

.automation-view .icon-btn.danger {
  color: var(--automation-danger);
  border-color: rgba(220, 38, 38, 0.35);
}

.automation-view .primary-btn,
.automation-view .secondary-btn,
.automation-view .ghost-btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
  font-size: 14px;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.automation-view .primary-btn {
  background: linear-gradient(135deg, var(--automation-accent-2), var(--automation-accent));
  color: #fff;
  box-shadow: 0 10px 30px rgba(24, 119, 242, 0.25);
  border: none;
}

.automation-view .secondary-btn {
  background: #e4e6eb;
  color: var(--automation-text);
  border-color: #d1d5db;
}

.automation-view .ghost-btn {
  background: transparent;
  color: var(--automation-text);
  border-color: var(--automation-border);
}

.automation-view .primary-btn:hover,
.automation-view .secondary-btn:hover,
.automation-view .ghost-btn:hover {
  transform: translateY(-1px);
  opacity: 0.95;
}

.automation-view .list-status,
.automation-view .runs-status,
.automation-view .import-status {
  min-height: 20px;
  color: var(--automation-muted);
  margin-bottom: 8px;
}

.automation-view .filter-input {
  border-radius: 10px;
  border: 1px solid var(--automation-border);
  padding: 8px 10px;
  background: #fff;
  color: var(--automation-text);
  min-width: 200px;
}

.automation-view .runs-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 10px;
}

.automation-view .run-item {
  border: 1px solid var(--automation-border);
  border-radius: 12px;
  padding: 12px;
  background: var(--automation-card-soft);
  box-shadow: var(--automation-shadow-sm);
}

.automation-view .run-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.automation-view .run-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--automation-muted);
  font-size: 13px;
}

.automation-view .run-body {
  margin: 8px 0 0;
  color: var(--automation-text);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-all;
}

.automation-view .runs-hint {
  color: var(--automation-muted);
  margin: 0;
}

.automation-view .import-hint {
  color: var(--automation-muted);
  margin: 0 0 8px;
}

.automation-view .switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 600;
  color: var(--automation-text);
}

.automation-view .switch input {
  display: none;
}

.automation-view .switch-slider {
  width: 42px;
  height: 22px;
  background: #d1d5db;
  border-radius: 999px;
  position: relative;
  transition: background 0.2s ease;
}

.automation-view .switch-slider::after {
  content: "";
  width: 18px;
  height: 18px;
  background: #fff;
  border-radius: 50%;
  position: absolute;
  top: 2px;
  left: 2px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.25);
  transition: transform 0.2s ease;
}

.automation-view .switch input:checked + .switch-slider {
  background: var(--automation-accent);
}

.automation-view .switch input:checked + .switch-slider::after {
  transform: translateX(20px);
}

.automation-view .switch-label {
  color: var(--automation-muted);
  font-weight: 600;
}

.automation-view .exclusion-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.automation-view .exclusion-controls input[type="time"] {
  width: 140px;
}

.automation-view .exclusion-sep {
  color: var(--automation-muted);
  font-size: 13px;
}

.automation-view .exclusion-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.automation-view .exclusion-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--automation-border);
  color: var(--automation-text);
  font-size: 13px;
}

.automation-view .exclusion-chip button {
  border: none;
  background: transparent;
  color: var(--automation-muted);
  cursor: pointer;
  padding: 0;
  font-size: 14px;
}

.automation-view .exclusion-chip button:hover {
  color: var(--automation-danger);
}

.automation-view .modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.55);
  z-index: 900;
}

.automation-view .modal__backdrop {
  position: absolute;
  inset: 0;
}

.automation-view .modal__content {
  position: relative;
  background: var(--automation-card);
  border: 1px solid var(--automation-border);
  border-radius: 14px;
  padding: 20px 20px 16px;
  width: min(1100px, 96vw);
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: var(--automation-shadow-md);
}

.automation-view .modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.automation-view .modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.automation-view .modal[hidden] {
  display: none;
}

.automation-view .preview-panel {
  border: 1px solid var(--automation-border);
  border-radius: 12px;
  padding: 12px;
  background: var(--automation-card-soft);
}

.automation-view .preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.automation-view .preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
}

.automation-view .preview-block {
  border: 1px dashed var(--automation-border);
  border-radius: 10px;
  padding: 8px;
  background: #fff;
}

.automation-view .preview-label {
  margin: 0 0 4px;
  color: var(--automation-muted);
  font-size: 13px;
}

.automation-view .preview-value {
  margin: 0;
  color: var(--automation-text);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 180px;
  overflow: auto;
}

.automation-view .preview-hint {
  color: var(--automation-muted);
  margin: 8px 0 0;
  font-size: 13px;
}

.automation-view .placeholder-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 6px;
}

.automation-view .placeholder-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--automation-border);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  color: var(--automation-text);
  vertical-align: top;
}

.automation-view .placeholder-table td.placeholder-key {
  width: 30%;
  color: var(--automation-muted);
}

.automation-view .placeholder-hint {
  color: var(--automation-muted);
  font-size: 12px;
  margin: 6px 0 0;
}

@media (max-width: 1050px) {
  .automation-view .form-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .automation-view .auto-shell {
    gap: 12px;
  }

  .automation-view .panel-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .automation-view .panel-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .automation-view .hero-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .automation-view .modal {
    padding: 12px;
  }
}
