.rules-main {
  max-width: 1540px;
}

.rules-header {
  margin-bottom: 28px;
}

.rules-overview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 28px;
  margin-bottom: 18px;
  padding: 27px 29px;
  border: 1px solid rgba(var(--brand-accent-rgb), 0.15);
  border-radius: 20px;
  background:
    radial-gradient(circle at 100% 0%, rgba(151, 107, 220, 0.15), transparent 20rem),
    linear-gradient(120deg, #fff, var(--brand-paper));
  box-shadow: 0 12px 34px rgba(var(--brand-ink-rgb), 0.045);
}

.automation-manager { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(300px, 0.75fr); gap: 18px; margin-bottom: 18px; }
.rule-command-card, .calendar-automation-card { padding: 24px 26px; border: 1px solid var(--line); border-radius: 20px; background: rgba(255, 255, 255, 0.96); box-shadow: 0 12px 34px rgba(var(--brand-ink-rgb), 0.045); }
.rule-command-card h2, .calendar-automation-card h2 { margin: 0; color: var(--ink); font-size: 1.22rem; }
.rule-command-card > div > p:last-child, .calendar-automation-card > div > p:last-child { margin: 8px 0 0; color: var(--ink-soft); font-size: var(--type-small); line-height: 1.5; }
#rule-command-form { display: grid; gap: 10px; margin-top: 18px; }
#rule-command-form label { color: var(--ink); font-size: var(--type-small); font-weight: 700; }
#rule-command { width: 100%; resize: vertical; padding: 12px 13px; border: 1px solid var(--brand-line); border-radius: 11px; color: var(--ink); background: #fff; font: inherit; line-height: 1.45; }
#rule-command:focus { border-color: var(--blue); outline: 3px solid var(--brand-accent-hover); }
.command-examples { display: flex; flex-wrap: wrap; gap: 7px; }
.command-examples button { padding: 6px 9px; border: 1px solid var(--brand-line); border-radius: 999px; color: var(--brand-muted); background: var(--brand-paper); font: inherit; font-size: var(--type-small); cursor: pointer; }
.primary-rule-action { display: inline-flex; width: fit-content; min-height: 40px; align-items: center; justify-content: center; padding: 0 14px; border: 1px solid var(--blue); border-radius: 10px; color: #fff; background: var(--blue); font: inherit; font-size: var(--type-small); font-weight: 700; cursor: pointer; }
.primary-rule-action:disabled { cursor: wait; opacity: 0.65; }
.rule-command-status { margin-top: 12px; padding: 10px 12px; border-radius: 10px; color: #087f66; background: #e5f7f1; font-size: var(--type-caption); white-space: pre-line; }
.rule-command-status.is-error { color: #9c3d10; background: rgba(224, 112, 61, 0.1); }
.calendar-automation-card { display: flex; flex-direction: column; }
.calendar-automation-card dl { display: grid; gap: 8px; margin: 18px 0; }
.calendar-automation-card dl div { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--brand-paper); }
.calendar-automation-card dt { color: var(--ink-soft); font-size: var(--type-caption); }
.calendar-automation-card dd { margin: 0; color: var(--ink); font-size: var(--type-small); font-weight: 700; text-align: right; }
.automation-link { margin-top: auto; text-decoration: none; }
.rule-detail-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 22px 26px 26px; padding-top: 18px; border-top: 1px solid var(--line); }
.rule-detail-actions button, .rule-confirm-actions button { min-height: 38px; padding: 0 12px; border: 1px solid var(--brand-line); border-radius: 10px; color: var(--ink); background: #fff; font: inherit; font-size: var(--type-small); font-weight: 700; cursor: pointer; }
.rule-detail-actions .danger-rule-action { border-color: rgba(190, 52, 40, 0.3); color: #a2342a; }
.rule-confirm-dialog { width: min(520px, calc(100% - 32px)); padding: 0; border: 0; border-radius: 18px; color: var(--ink); box-shadow: 0 24px 80px rgba(var(--brand-ink-rgb), 0.24); }
.rule-confirm-dialog::backdrop { background: rgba(var(--brand-ink-rgb), 0.46); }
.rule-confirm-dialog form { padding: 26px; }
.rule-confirm-dialog h2 { margin: 5px 0 10px; }
.rule-confirm-dialog p:not(.card-kicker) { color: var(--ink-soft); line-height: 1.55; white-space: pre-line; }
.rule-confirm-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 22px; }
.rule-confirm-actions .primary-rule-action { color: #fff; background: var(--blue); }

.rules-overview h2,
.rule-directory-heading h2,
.rule-detail-heading h2 {
  margin: 0;
  color: var(--ink);
  letter-spacing: -0.035em;
}

.rules-overview h2 {
  max-width: 620px;
  font-size: clamp(1.45rem, 2.4vw, 2.1rem);
}

.rules-overview > div > p:last-child {
  margin: 8px 0 0;
  color: var(--brand-muted);
  font-size: var(--type-small);
}

.rule-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(84px, 1fr));
  gap: 9px;
  min-width: 420px;
  margin: 0;
}

.rule-summary > div {
  padding: 13px 15px;
  border: 1px solid rgba(var(--brand-accent-rgb), 0.1);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.78);
}

.rule-summary dt,
.selected-rule-metadata dt {
  color: var(--brand-muted);
  font-size: var(--type-caption);
}

.rule-summary dd {
  margin: 6px 0 0;
  color: var(--ink);
  font-size: 1.45rem;
  font-weight: 700;
}

.rule-summary .is-enabled dd {
  color: #087f66;
}

.rule-summary .is-disabled dd {
  color: var(--brand-muted);
}

.rule-summary .is-matches dd {
  color: #6b46b3;
}

.rules-workspace {
  display: grid;
  grid-template-columns: minmax(400px, 0.9fr) minmax(460px, 1.1fr);
  gap: 18px;
  align-items: start;
}

.rule-directory,
.rule-detail-panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 12px 34px rgba(var(--brand-ink-rgb), 0.045);
}

.rule-directory-heading,
.rule-detail-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.rule-directory-heading {
  padding: 24px 26px 18px;
}

.rule-directory-heading h2,
.rule-detail-heading h2 {
  font-size: 1.22rem;
}

.rule-filters {
  display: flex;
  gap: 8px;
  padding: 0 26px 18px;
  border-bottom: 1px solid var(--line);
}

.rule-filters button {
  min-height: 34px;
  padding: 0 13px;
  border: 1px solid var(--brand-line);
  border-radius: 999px;
  color: var(--brand-muted);
  font-size: var(--type-small);
  font-weight: 700;
  background: var(--brand-paper);
  cursor: pointer;
}

.rule-filters button:hover,
.rule-filters button:focus-visible,
.rule-filters button.is-active {
  border-color: rgba(var(--brand-accent-rgb), 0.36);
  color: var(--blue-dark);
  background: var(--brand-paper);
}

.rule-filters button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.rule-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.rule-list-item + .rule-list-item {
  border-top: 1px solid var(--brand-paper);
}

.rule-select-button {
  display: grid;
  width: 100%;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px 18px;
  padding: 19px 25px;
  border: 0;
  border-left: 3px solid transparent;
  color: inherit;
  text-align: left;
  background: #fff;
  cursor: pointer;
}

.rule-select-button:hover,
.rule-select-button:focus-visible,
.rule-select-button.is-selected {
  border-left-color: var(--mint);
  background: linear-gradient(90deg, rgba(var(--brand-accent-rgb), 0.12), #fff 35%);
}

.rule-select-button h3 {
  overflow: hidden;
  margin: 0;
  color: var(--ink);
  font-size: 0.9rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rule-select-button p {
  margin: 7px 0 0;
  color: var(--ink-soft);
  font-size: var(--type-body);
}

.rule-list-stats {
  display: flex;
  grid-column: 1 / -1;
  flex-wrap: wrap;
  gap: 7px;
}

.rule-list-stats span,
.rule-list-state,
.rule-status {
  display: inline-flex;
  padding: 5px 8px;
  border-radius: 999px;
  color: var(--brand-muted);
  font-size: var(--type-caption);
  font-weight: 700;
  background: var(--brand-paper);
}

.rule-list-state {
  align-self: start;
  white-space: nowrap;
}

.rule-list-stats .rule-action {
  color: #6b46b3;
  background: #f1eaff;
}

.rule-list-state,
.rule-status {
  color: #087f66;
  background: #e5f7f1;
}

.rule-list-state.is-disabled,
.rule-status.is-disabled {
  color: var(--brand-muted);
  background: var(--brand-paper);
}

.rule-detail-panel {
  min-height: 460px;
}

.rule-detail-placeholder,
.rule-detail-loading,
.rule-detail-error {
  display: grid;
  place-items: center;
  min-height: 458px;
  padding: 42px;
  text-align: center;
}

.rule-detail-placeholder > span {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 17px;
  color: var(--blue);
  font-size: 1.35rem;
  background: var(--brand-paper);
}

.rule-detail-placeholder h2 {
  margin: 16px 0 0;
  color: var(--ink);
  font-size: 1.35rem;
}

.rule-detail-placeholder p,
.rule-detail-error p,
.rule-detail-loading p {
  max-width: 360px;
  margin: 8px 0 0;
  color: var(--ink-soft);
  font-size: var(--type-small);
}

.rule-detail {
  padding: 26px;
}

.rule-detail-heading {
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.selected-rule-metadata {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 20px 0 25px;
}

.selected-rule-metadata div {
  min-width: 0;
  padding: 12px;
  border-radius: 12px;
  background: var(--brand-paper);
}

.selected-rule-metadata dd {
  overflow: hidden;
  margin: 6px 0 0;
  color: var(--brand-muted);
  font-size: var(--type-small);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.condition-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 11px;
}

.condition-heading h3 {
  margin: 0;
  color: var(--ink);
  font-size: 0.9rem;
}

.condition-heading span {
  color: var(--brand-muted);
  font-size: var(--type-small);
}

.condition-list {
  display: grid;
  gap: 9px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: conditions;
}

.condition-list li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 11px;
  padding: 13px;
  border: 1px solid var(--brand-line);
  border-radius: 12px;
  background: var(--brand-paper);
  counter-increment: conditions;
}

.condition-list li::before {
  display: grid;
  place-items: center;
  width: 25px;
  height: 25px;
  border-radius: 8px;
  color: var(--blue-dark);
  font-size: var(--type-small);
  font-weight: 700;
  background: var(--brand-paper);
  content: counter(conditions);
}

.condition-expression {
  overflow-wrap: anywhere;
  color: var(--brand-muted);
  font-size: var(--type-small);
  line-height: 1.55;
}

.condition-expression strong {
  color: var(--ink);
}

.condition-note {
  display: block;
  margin-top: 4px;
  color: var(--brand-muted);
  font-size: var(--type-small);
}

.rules-empty {
  display: flex;
  align-items: center;
  gap: 15px;
  margin: 24px;
  padding: 27px;
  border: 1px dashed var(--brand-line);
  border-radius: 15px;
  background: var(--brand-paper);
}

.rules-empty > span {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  color: #087f66;
  background: #e7f7f2;
}

.rules-empty h3,
.rules-empty p {
  margin: 0;
}

.rules-empty h3 {
  color: var(--ink);
  font-size: 0.9rem;
}

.rules-empty p {
  margin-top: 5px;
  color: var(--ink-soft);
  font-size: var(--type-small);
}

.rules-footer {
  margin-top: 22px;
}

@media (max-width: 1120px) {
  .rules-workspace {
    grid-template-columns: 1fr;
  }

  .rule-detail-panel {
    min-height: 0;
  }

  .rule-detail-placeholder,
  .rule-detail-loading,
  .rule-detail-error {
    min-height: 280px;
  }
}

@media (max-width: 860px) {
  .rules-overview {
    align-items: stretch;
    flex-direction: column;
  }

  .rule-summary {
    min-width: 0;
  }
}

@media (max-width: 760px) {
  .automation-manager { grid-template-columns: 1fr; }
  .rule-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .selected-rule-metadata {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .rule-filters {
    overflow-x: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rule-select-button,
  .rule-filters button {
    transition: none;
  }
}
