.automation-rules {
    width: 100%;
    min-height: calc(100vh - 170px);
    background: #f5f6f8;
    color: #0f172a;
    font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.automation-rules__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #d8dee8;
    background: #fff;
}

.automation-rules__header div {
    display: grid;
    gap: 0.15rem;
}

.automation-rules__header span,
.automation-rules__panel-heading p,
.automation-rules__rule-card > div:first-child span {
    color: #64748b;
    font-size: 0.75rem;
}

.automation-rules__header strong {
    font-size: 1.15rem;
}

.automation-rules__primary-button,
.automation-rules__ghost-button,
.automation-rules__save-button,
.automation-rules__link-button {
    min-height: 2.65rem;
    padding: 0.55rem 1rem;
    border-radius: 0.45rem;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.automation-rules__primary-button {
    border: 1px solid #0f4c75;
    background: #0f4c75;
    color: #fff;
}

.automation-rules__save-button {
    border: 1px solid #14b8a6;
    background: #14b8a6;
    color: #fff;
}

.automation-rules__ghost-button {
    border: 1px solid #b8c0cc;
    background: #fff;
    color: #0f172a;
}

.automation-rules__link-button {
    justify-self: center;
    border: 0;
    background: transparent;
    color: #64748b;
}

.automation-rules__primary-button:disabled,
.automation-rules__save-button:disabled {
    border-color: #cbd5e1;
    background: #cbd5e1;
    cursor: not-allowed;
}

.automation-rules__steps {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.75rem;
    padding: 1rem 1.25rem 0;
}

.automation-rules__step {
    display: grid;
    justify-items: center;
    gap: 0.3rem;
    color: #94a3b8;
    font-size: 0.75rem;
}

.automation-rules__step span {
    width: 1.8rem;
    height: 1.8rem;
    display: grid;
    place-items: center;
    border: 2px solid #cbd5e1;
    border-radius: 999px;
    background: #fff;
    font-weight: 800;
}

.automation-rules__step.is-current span {
    border-color: #0f4c75;
    background: #0f4c75;
    color: #fff;
}

.automation-rules__step.is-done span {
    border-color: #14b8a6;
    background: #14b8a6;
    color: #fff;
}

.automation-rules__panel,
.automation-rules__list-shell {
    display: grid;
    gap: 1rem;
    margin: 1rem 1.25rem;
    padding: 1rem;
    border: 1px solid #d8dee8;
    border-radius: 0.65rem;
    background: #fff;
}

.automation-rules__panel-heading h2 {
    margin: 0 0 0.35rem;
    font-size: 1rem;
}

.automation-rules__panel-heading p {
    margin: 0;
}

.automation-rules__entity-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.65rem;
}

.automation-rules__entity {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 0.2rem 0.65rem;
    min-height: 5.4rem;
    padding: 0.8rem;
    border: 1px solid var(--rule-color, #b8c0cc);
    border-radius: 0.55rem;
    background: #fff;
    color: #0f172a;
    text-align: left;
    cursor: pointer;
}

.automation-rules__entity.is-selected {
    border-color: var(--rule-color, #0f4c75);
    background: var(--rule-bg, #eef6fb);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--rule-color, #0f4c75) 18%, transparent);
}

.automation-rules__entity:disabled {
    cursor: default;
    opacity: 1;
}

.automation-rules__entity span {
    grid-row: span 2;
    width: 2rem;
    height: 2rem;
    display: grid;
    place-items: center;
    border-radius: 0.45rem;
    background: var(--rule-bg, #e2e8f0);
    color: var(--rule-color, #0f4c75);
    font-weight: 800;
}

.automation-rules__entity small {
    color: #64748b;
}

.automation-rules__filter-builder {
    padding: 0.75rem;
    border-radius: 0.55rem;
    background: #f8fafc;
}

.automation-rules__action-picker,
.automation-rules__rule-actions,
.automation-rules__rule-badges,
.automation-rules__type-pills,
.automation-rules__flow {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.automation-rules__action-chip,
.automation-rules__type-pills button,
.automation-rules__rule-actions span,
.automation-rules__flow span {
    min-height: 2rem;
    padding: 0.35rem 0.75rem;
    border: 1px solid var(--rule-color, #b8c0cc);
    border-radius: 999px;
    background: #fff;
    color: var(--rule-color, #334155);
    font: inherit;
    font-size: 0.8rem;
    font-weight: 700;
}

.automation-rules__action-chip.is-selected,
.automation-rules__type-pills button.is-selected {
    border-color: var(--rule-color, #14b8a6);
    background: var(--rule-bg, #ecfeff);
    color: var(--rule-color, #0f766e);
}

.automation-rules__action-editors,
.automation-rules__rule-list {
    display: grid;
    gap: 0.65rem;
}

.automation-rules__validation {
    display: grid;
    gap: 0.35rem;
    padding: 0.75rem;
    border: 1px solid #fbbf24;
    border-radius: 0.45rem;
    background: #fffbeb;
    color: #92400e;
    font-size: 0.82rem;
    font-weight: 700;
}

.automation-rules__action-card,
.automation-rules__rule-card {
    display: grid;
    gap: 0.75rem;
    padding: 0.85rem;
    border-radius: 0.55rem;
    background: #f8fafc;
}

.automation-rules__action-card {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.automation-rules__action-card header,
.automation-rules__wide-field {
    grid-column: 1 / -1;
}

.automation-rules__action-card header {
    display: grid;
    gap: 0.15rem;
}

.automation-rules__action-card header span {
    color: #64748b;
    font-size: 0.75rem;
}

.automation-rules label {
    display: grid;
    gap: 0.3rem;
    color: #475569;
    font-size: 0.8rem;
    font-weight: 700;
}

.automation-rules input,
.automation-rules select,
.automation-rules textarea {
    width: 100%;
    min-height: 2.35rem;
    padding: 0.45rem 0.55rem;
    border: 1px solid #b8c0cc;
    border-radius: 0.4rem;
    background: #fff;
    color: #0f172a;
    font: inherit;
    font-weight: 500;
}

.automation-rules__recipient-tagbox {
    width: 100%;
}

.automation-rules textarea {
    resize: vertical;
}

.automation-rules__settings-form,
.automation-rules__summary-form {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem;
}

.automation-rules__automatic-row {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: end;
    gap: 0.75rem;
}

.automation-rules__interval-create {
    display: flex;
    align-items: end;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.automation-rules__interval-create label {
    min-width: 9rem;
}

.automation-rules__check {
    grid-template-columns: auto 1fr;
    align-items: center;
}

.automation-rules__check input {
    width: 1rem;
    min-height: 1rem;
}

.automation-rules__summary {
    display: grid;
    gap: 0.65rem;
    margin: 0;
}

.automation-rules__summary div {
    display: grid;
    grid-template-columns: 8rem minmax(0, 1fr);
    gap: 1rem;
    padding-bottom: 0.65rem;
    border-bottom: 1px solid #e2e8f0;
}

.automation-rules__summary dt {
    color: #64748b;
    font-size: 0.75rem;
    font-weight: 800;
    text-transform: uppercase;
}

.automation-rules__summary dd {
    margin: 0;
    min-width: 0;
    overflow-wrap: anywhere;
}

.automation-rules__summary dd span {
    display: inline-flex;
    margin: 0 0.35rem 0.35rem 0;
}

.automation-rules__flow {
    padding: 0.75rem;
    border-radius: 0.55rem;
    background: #f8fafc;
}

.automation-rules__flow span + span::before {
    content: "→";
    margin-right: 0.5rem;
    color: #64748b;
}

.automation-rules__filters {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.automation-rules__filters label {
    min-width: 12rem;
}

.automation-rules__rule-card {
    grid-template-columns: minmax(0, 1fr) auto;
    border-color: var(--rule-color, #d8dee8);
    border-left-width: 0.35rem;
    background: linear-gradient(90deg, var(--rule-bg, #f8fafc) 0, var(--rule-bg, #f8fafc) 14rem, #f8fafc 34rem);
}

.automation-rules__rule-badges {
    align-self: start;
    align-items: flex-start;
    justify-content: flex-end;
    flex-wrap: nowrap;
}

.automation-rules__rule-badges span {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 1.75rem;
    padding: 0.3rem 0.7rem;
    border: 1px solid #b8c0cc;
    border-radius: 999px;
    background: #fff;
    color: #334155;
    font-size: 0.78rem;
    font-weight: 800;
    line-height: 1;
    white-space: nowrap;
}

.automation-rules__edit-button {
    flex: 0 0 auto;
    min-height: 1.75rem;
    padding: 0.3rem 0.7rem;
    border: 1px solid var(--rule-color, #0f4c75);
    border-radius: 999px;
    background: #fff;
    color: var(--rule-color, #0f4c75);
    cursor: pointer;
    font: inherit;
    font-size: 0.78rem;
    font-weight: 800;
    line-height: 1;
    white-space: nowrap;
}

.automation-rules__edit-button:hover,
.automation-rules__edit-button:focus-visible {
    background: var(--rule-bg, #eef6fb);
    outline: 2px solid color-mix(in srgb, var(--rule-color, #0f4c75) 18%, transparent);
    outline-offset: 1px;
}

.automation-rules__rule-card strong {
    display: block;
    margin-top: 0.15rem;
}

.automation-rules__rule-card p {
    margin: 0.25rem 0 0;
    color: #64748b;
    font-size: 0.85rem;
}

.automation-rules__criteria-chips,
.automation-rules__rule-actions {
    grid-column: 1 / -1;
}

.automation-rules__criteria-chips {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
    padding: 0.25rem 0;
    border-radius: 0.45rem;
    background: transparent;
}

.automation-rules__criteria-chip,
.automation-rules__criteria-empty {
    display: inline-flex;
    align-items: center;
    min-height: 1.75rem;
    max-width: 100%;
    padding: 0.3rem 0.65rem;
    border: 1px solid color-mix(in srgb, var(--rule-color, #94a3b8) 35%, #d8dee8);
    border-radius: 999px;
    background: #fff;
    color: #334155;
    font-size: 0.78rem;
    font-weight: 700;
    overflow-wrap: anywhere;
}

.automation-rules__criteria-join {
    color: var(--rule-color, #64748b);
    font-size: 0.72rem;
    font-weight: 900;
    letter-spacing: 0.04em;
}

.automation-rules__rule-badges span.is-on {
    border-color: #86efac;
    background: #f0fdf4;
    color: #15803d;
}

.automation-rules__rule-badges span.is-off {
    border-color: #fecaca;
    background: #fef2f2;
    color: #b91c1c;
}

.automation-rules__empty {
    padding: 2rem 1rem;
    color: #64748b;
    text-align: center;
}

.automation-rules__actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
    gap: 0.65rem;
}

@media (max-width: 760px) {
    .automation-rules__header,
    .automation-rules__actions,
    .automation-rules__rule-card {
        grid-template-columns: 1fr;
    }

    .automation-rules__header {
        display: grid;
    }

    .automation-rules__steps,
    .automation-rules__entity-grid,
    .automation-rules__action-card,
    .automation-rules__settings-form,
    .automation-rules__summary-form,
    .automation-rules__automatic-row {
        grid-template-columns: 1fr;
    }

    .automation-rules__summary div {
        grid-template-columns: 1fr;
        gap: 0.25rem;
    }
}
