/* =============================================================================
   AM - Automations (20 Oct 2026)

   One look for every automation screen, taken from Domains > Settings >
   Automations: the status board pages (Domains and Email hosting, Finance,
   Tickets, Bookings), the pipeline / workflow boards of Projects and Tasks
   (in their slide-over and in a project's Automations tab), and every rule
   editor (the rule panel, and the email, task and event rule editors, which
   all wear the shared Run / Conditions block).

   Flat trays with a 1px border, a coloured dot per column, a dashed
   "+ Create Rule", flat rule cards, AM notched fields, text-only record tabs.
   Colours are theme tokens only, so Wood and every other theme reach it.
   Loaded after kudio-field.css and before theme-layer.css (index.html).
   ============================================================================= */

/* ---- Page ------------------------------------------------------------------ */
.automation-page .automation-page__header {
    border-bottom: 0;
    padding: 22px var(--gutter) 4px;
}

.automation-page .automation-page__header .page-header__title {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text-primary);
}

.automation-page .automation-page__header .page-header__description {
    margin-top: 4px;
    font-size: 13.5px;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* AM record tabs, text only. The line starts 12px before the title so the first
   tab's words line up with it once the tab's own padding takes them in. */
.record-tabs.automation-page__tabs {
    flex: none;
    margin: 14px calc(var(--gutter) - 12px) 0;
    padding: 0;
}

.record-tabs.automation-page__tabs .record-tab:focus-visible {
    outline: none;
    box-shadow: var(--am-focus);
    border-radius: 4px;
}

.record-tabs.automation-page__tabs .record-tab--active {
    color: var(--am-blue);
    border-bottom-color: var(--am-blue);
    font-weight: 600;
}

/* .page-surface is a fixed-height column that clips, so the body takes the
   leftover height and scrolls. Below 900px the page grows instead (see the
   media query at the end). */
.automation-page .automation-page__body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: var(--content-gap-top) var(--gutter) 32px;
}

/* The Projects / Tasks list pages are a full-bleed AM data table, so the body
   adds only the air under the header. */
.automation-page--list .automation-page__body {
    padding: var(--content-gap-top) 0 0;
}

/* ---- The board --------------------------------------------------------------
   As many columns across as the width allows, each at least 240px: four fill a
   laptop exactly as the Domains board does, a long status list wraps onto a
   second row instead of scrolling sideways, and a phone gets one column. */
.automation-board {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr));
    align-items: start;
    gap: 16px;
    flex: none;
    min-height: 0;
    padding: 0;
    background: none;
    overflow: visible;
}

/* The board name (pipeline / workflow) sits above the columns. */
.automation-board__name {
    max-width: 420px;
    margin-bottom: 18px;
}

.automation-column {
    display: flex;
    flex-direction: column;
    gap: 0;
    width: auto;
    min-width: 0;
    padding: 12px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-medium);
    background: var(--am-blue-tint);
    box-shadow: none;
}

/* Head: a coloured dot, the name, the rule count in a pill. */
.automation-column__head,
.automation-column__head--neutral,
.automation-column__head--info,
.automation-column__head--violet,
.automation-column__head--warning,
.automation-column__head--danger,
.automation-column__head--success {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    min-width: 0;
    margin: 0 0 12px;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: none;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text-primary);
    text-align: left;
}

.automation-column__head::before {
    content: '';
    flex: 0 0 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--status-neutral);
}

.automation-column__head--info::before { background: var(--status-info); }
.automation-column__head--violet::before { background: var(--accent); }
.automation-column__head--warning::before { background: var(--status-warning); }
.automation-column__head--danger::before { background: var(--status-danger); }
.automation-column__head--success::before { background: var(--status-success); }

.automation-column__head > span:first-of-type {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.automation-column__count {
    margin-left: auto;
    padding: 0 7px;
    border-radius: var(--radius-pill);
    background: var(--am-blue-soft);
    font-size: 11.5px;
    line-height: 18px;
    color: var(--am-blue);
}

.automation-column__count:empty { display: none; }

/* "+ Create Rule": dashed until hovered, the one call to action per column. */
.automation-create {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    min-height: 36px;
    padding: 0 12px;
    border: 1px dashed var(--accent-border);
    border-radius: var(--radius-medium);
    background: var(--surface-panel);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    color: var(--am-blue);
    cursor: pointer;
    transition: border-color var(--duration-instant) var(--easing-standard),
        background var(--duration-instant) var(--easing-standard);
}

.automation-create::before { content: '+'; font-size: 15px; line-height: 1; }

.automation-create:hover {
    border-style: solid;
    border-color: var(--am-blue);
    background: var(--am-blue-tint);
}

.automation-create:focus-visible { outline: none; box-shadow: var(--am-focus); }

.automation-column__cards {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.automation-column__empty {
    margin: 4px 0 0;
    padding: 10px 4px 2px;
    font-size: 12.5px;
    color: var(--text-muted);
    text-align: center;
}

/* ---- Rule cards ------------------------------------------------------------ */
.automation-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px 12px 0;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-medium);
    background: var(--surface-panel);
    box-shadow: none;
    transition: border-color var(--duration-instant) var(--easing-standard);
}

.automation-card:hover { border-color: var(--border-strong); }

.automation-card--off { opacity: 0.6; }

.automation-card__timing {
    padding-right: 22px;
    font-size: 11.5px;
    color: var(--text-muted);
    line-height: 1.4;
}

.automation-card__name {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text-primary);
    overflow-wrap: anywhere;
}

/* The action's icon in a small soft tile, like the icon tiles on Bookings. */
.automation-card__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 24px;
    height: 24px;
    border-radius: var(--radius-small);
    background: var(--am-blue-soft);
    color: var(--am-blue);
}

.automation-card__status--ok { color: var(--status-success); }
.automation-card__status--fail { color: var(--status-danger); }
.automation-card__status--wait { color: var(--status-warning); }
.automation-card__status--idle { color: var(--text-muted); opacity: 0.75; }

.automation-card__paused {
    padding: 6px 8px;
    border-radius: var(--radius-small);
    background: var(--status-warning-tint);
    color: var(--status-warning);
    font-size: 12px;
    line-height: 1.4;
}

.automation-card__foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 4px;
    border-top: 1px solid var(--border-subtle);
}

.automation-card__actions { display: inline-flex; align-items: center; gap: 4px; margin-left: -6px; }

.automation-card__edit {
    min-height: 32px;
    padding: 0 6px;
    border: 0;
    border-radius: var(--radius-small);
    background: none;
    font: inherit;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
}

.automation-card__edit:hover { background: var(--am-blue-tint); color: var(--am-blue); }
.automation-card__edit:focus-visible { outline: none; box-shadow: var(--am-focus); }

/* ---- Create Rule menu (an overlay, so it keeps its shadow) ----------------- */
.automation-menu {
    display: flex;
    flex-direction: column;
    margin-top: 6px;
    padding: 6px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-medium);
    background: var(--surface-panel);
    box-shadow: var(--shadow-dropdown);
}

.automation-menu__item {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 36px;
    padding: 0 10px;
    border: 0;
    border-radius: var(--radius-small);
    background: none;
    font: inherit;
    font-size: 13.5px;
    color: var(--text-primary);
    text-align: left;
    cursor: pointer;
}

.automation-menu__item .icon { color: var(--am-blue); }
.automation-menu__item:hover { background: var(--am-blue-tint); }
.automation-menu__item:focus-visible { outline: none; box-shadow: var(--am-focus); }

/* ---- Pipeline / workflow boards (Projects, Tasks) ---------------------------
   The same tray, with the phase's own colour on the dot (the colour is the
   phase's data, picked from the swatches below), its name editable in place,
   and the move / remove tools at the end of the head. */
/* The head wraps: when a long phase name ("Web Development") and the move and
   remove tools do not fit on one line in a 240px column, the tools drop to a
   second line on the right and the name keeps the full width, rather than
   being cut off. The name box is sized to its words where the browser can. */
.pipeline-column__head {
    flex-wrap: wrap;
    gap: 4px 6px;
    border-left: 0;
}

.pipeline-column__head::before {
    background: var(--phase-colour, var(--status-neutral));
}

.pipeline-column__name {
    flex: 1 1 auto;
    field-sizing: content;
    min-width: 6ch;
    max-width: calc(100% - 14px);
    height: 30px;
    padding: 0 6px;
    margin-left: -2px;
    border: 1px solid transparent;
    border-radius: var(--radius-tiny);
    background: none;
    font: inherit;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text-primary);
}

.pipeline-column__name:hover:not(:disabled) {
    border-color: var(--border-strong);
    background: var(--surface-panel);
}

.pipeline-column__name:focus {
    outline: 0;
    border-color: var(--accent);
    box-shadow: inset 0 0 0 1px var(--accent);
    background: var(--surface-panel);
}

.pipeline-column__moves { flex: none; display: flex; align-items: center; gap: 2px; margin-left: auto; }

.pipeline-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 0 12px;
}

.pipeline-swatch {
    width: 18px;
    height: 18px;
    padding: 0;
    border: 2px solid var(--surface-panel);
    border-radius: var(--radius-pill);
    box-shadow: 0 0 0 1px var(--border-default);
    cursor: pointer;
}

.pipeline-swatch:hover { transform: scale(1.1); }
.pipeline-swatch:focus-visible { outline: none; box-shadow: var(--am-focus); }

.pipeline-swatch--chosen { box-shadow: 0 0 0 2px var(--text-primary); }

/* "Counts as" is a notched field now (the sweep wraps it); it only needs room. */
.pipeline-stage-status {
    display: block;
    padding: 0;
    margin: 0 0 12px;
}

.pipeline-stage-status .kudio-field { background: var(--surface-panel); }

.pipeline-stage-status__select {
    padding-top: 0;
    padding-bottom: 0;
    font-size: var(--font-size-base);
}

.automation-column.pipeline-column--add {
    align-self: stretch;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 140px;
    border: 1px dashed var(--accent-border);
    background: none;
}

.pipeline-add-phase {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 36px;
    padding: 0 14px;
    border: 0;
    border-radius: var(--radius-medium);
    background: none;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    color: var(--am-blue);
    cursor: pointer;
}

.pipeline-add-phase:hover { background: var(--am-blue-tint); }
.pipeline-add-phase:focus-visible { outline: none; box-shadow: var(--am-focus); }

/* The board in its own slide-over (Projects / Tasks > Automation > open one)
   and in a project's Automations tab. */
.pipeline-board-panel { display: flex; flex-direction: column; min-width: 0; }

/* ---- Projects / Tasks automation lists --------------------------------------- */
.automation-page--list .pipeline-action:hover {
    background: var(--am-blue-tint);
    color: var(--am-blue);
}

.automation-page--list .pipeline-action--danger:hover {
    background: var(--status-danger-tint);
    color: var(--status-danger);
}

.automation-page--list .pipeline-action:focus-visible {
    opacity: 1;
    outline: none;
    box-shadow: var(--am-focus);
}

@media (hover: none) {
    .automation-page--list .pipeline-action { opacity: 1; }
}

/* =============================================================================
   RULE EDITORS

   The rule panel (comment, stage, push, notification) and the email, task and
   event rule editors all carry the same Run / Conditions block, so every rule
   reads the same: a flat card of timing choices, a card of condition rows, then
   the action as a step card.
   ============================================================================= */

/* Scrolls with the panel. Pinned to the top it covered the rule's name and the
   fields above it as soon as the panel scrolled. */
.automation-sticky,
.slide-over--automation .automation-sticky {
    position: static;
    top: auto;
    z-index: auto;
    gap: 0;
    padding: 0;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-medium);
    background: var(--surface-panel);
    box-shadow: none;
}

/* Each block is a section of the card, split by a hairline. */
.automation-sticky__block,
.slide-over--automation .automation-sticky__block {
    gap: 10px;
    padding: 16px;
}

.automation-sticky__block + .automation-sticky__block {
    border-top: 1px solid var(--border-default);
}

/* "Run" and "Conditions": section titles, not field labels. */
.automation-sticky__block > .form-field__label {
    margin: 0;
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.automation-sticky__block > .task-muted,
.automation-sticky__block > .form-field__hint {
    margin: 0;
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-muted);
}

/* ---- Run choices: one bordered row per choice, the chosen one in the accent - */
.rule-run__option,
.slide-over--automation .rule-run__option {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 44px;
    padding: 6px 12px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-medium);
    background: var(--surface-panel);
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: border-color var(--duration-instant) var(--easing-standard),
        background var(--duration-instant) var(--easing-standard);
}

.rule-run__option:hover { border-color: var(--border-strong); }

.rule-run__option:has(input[type="radio"]:checked) {
    border-color: var(--am-blue);
    background: var(--am-blue-tint);
    color: var(--text-primary);
}

.rule-run__option input[type="radio"] {
    flex: none;
    width: 16px;
    height: 16px;
    margin: 0 2px 0 0;
    accent-color: var(--am-blue);
    cursor: pointer;
}

/* The number, unit and anchor inside a run sentence, and the three controls of
   a condition row: compact AM controls (square corner, strong hairline, 2px
   accent on focus) so they read as the same family as the notched fields. */
.rule-run__num,
.rule-run__unit,
.rule-run__anchor,
.rule-condition__field,
.rule-condition__op,
.rule-condition__value {
    min-width: 0;
    height: 32px;
    padding: 0 8px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-tiny);
    background: var(--surface-panel);
    font: inherit;
    font-size: 13px;
    color: var(--text-primary);
    box-shadow: none;
    transition: border-color var(--duration-instant) var(--easing-standard);
}

.rule-run__num { width: 64px; }

.rule-run__unit,
.rule-run__anchor,
.rule-condition__field,
.rule-condition__op {
    appearance: none;
    padding-right: 24px;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238b929b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 6px center;
    cursor: pointer;
}

.rule-run__num:hover,
.rule-run__unit:hover,
.rule-run__anchor:hover,
.rule-condition__field:hover,
.rule-condition__op:hover,
.rule-condition__value:hover { border-color: var(--text-muted); }

.rule-run__num:focus,
.rule-run__unit:focus,
.rule-run__anchor:focus,
.rule-condition__field:focus,
.rule-condition__op:focus,
.rule-condition__value:focus {
    outline: 0;
    border-color: var(--accent);
    box-shadow: inset 0 0 0 1px var(--accent);
}

.rule-condition__value::placeholder { color: var(--text-muted); }

/* ---- Conditions: one row each, field / operator / value / remove ------------ */
.rule-conditions,
.slide-over--automation .rule-conditions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.rule-conditions:empty { display: none; }

.rule-condition,
.slide-over--automation .rule-condition {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1.1fr) minmax(0, 1fr) 32px;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-medium);
    background: var(--surface-subtle);
}

/* "is empty" hides the value box; the operator then takes its place. */
.rule-condition__value[hidden] { display: none; }

.rule-condition:has(.rule-condition__value[hidden]) {
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 2.1fr) 32px;
}

.rule-condition__field,
.rule-condition__op,
.rule-condition__value { width: 100%; }

.rule-condition__remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 0;
    border-radius: var(--radius-small);
    background: none;
    font-size: 18px;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
}

.rule-condition__remove:hover {
    background: var(--status-danger-tint);
    color: var(--status-danger);
}

.rule-condition__remove:focus-visible { outline: none; box-shadow: var(--am-focus); }

/* "Add condition": the dashed add row, the same shape as "+ Create Rule". */
.automation-sticky #ruleAddCondition {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    height: auto;
    min-height: 38px;
    padding: 0 12px;
    border: 1px dashed var(--accent-border);
    border-radius: var(--radius-medium);
    background: var(--surface-panel);
    box-shadow: none;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    color: var(--am-blue);
}

.automation-sticky #ruleAddCondition::before { content: '+'; font-size: 15px; line-height: 1; }

.automation-sticky #ruleAddCondition:hover {
    border-style: solid;
    border-color: var(--am-blue);
    background: var(--am-blue-tint);
}

.automation-sticky #ruleAddCondition:focus-visible { outline: none; box-shadow: var(--am-focus); }

/* ---- The action, as a step card --------------------------------------------- */
.slide-over--automation .form-section.automation-step,
.form-section.automation-step {
    margin: 4px 0 22px;
    padding: 0;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-medium);
    background: var(--surface-panel);
    box-shadow: none;
}

.automation-step__head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-default);
}

.automation-step__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: var(--am-blue-soft);
    color: var(--am-blue);
}

.automation-step__titles { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

.automation-step__eyebrow {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.automation-step__title { font-size: 15px; font-weight: 700; color: var(--text-primary); }

.automation-step__body {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 16px;
}

.automation-step__body > .invoice-hint,
.automation-step__body > .task-muted {
    margin: -6px 2px 0;
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-muted);
}

/* The rule's name and Active switch sit above the card, with the same air. */
.slide-over--automation .form-section > .form-checkbox { min-height: 32px; }

/* ---- A rule's Runs ----------------------------------------------------------- */
.rule-runs__list {
    border: 1px solid var(--border-default);
    border-radius: var(--radius-medium);
    background: var(--surface-panel);
}

.rule-runs__item { padding: 12px 14px; border-bottom: 1px solid var(--border-subtle); }
.rule-runs__item:last-child { border-bottom: 0; }

.rule-runs__empty {
    padding: 24px 16px;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-medium);
    text-align: center;
    font-size: 13px;
    color: var(--text-secondary);
}

/* The automation editors' `.form-section > * + *` rhythm would push the step's
   body 16px off its own head. */
.form-section.automation-step > .automation-step__body { margin-top: 0; }

/* ---- Touch and phones --------------------------------------------------------
   44px targets wherever a finger is the pointer, 16px controls on phones so iOS
   does not zoom, and the board's tools always visible (there is no hover). */
@media (hover: none) {
    .automation-card__edit,
    .automation-menu__item,
    .automation-create,
    .pipeline-add-phase { min-height: 44px; }

    .automation-card__moves .field-move__button,
    .pipeline-column__moves .field-move__button,
    .pipeline-column__moves .field-row__delete,
    .rule-condition__remove { min-width: 44px; min-height: 44px; }

    .pipeline-swatch { width: 28px; height: 28px; }
}

@media (max-width: 900px) {
    .automation-page .automation-page__body { flex: none; overflow-y: visible; padding-bottom: 24px; }
}

@media (max-width: 560px) {
    .automation-page .automation-page__header { padding-top: 16px; }

    .automation-page .automation-page__header .page-header__title { font-size: 19px; }

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

    .automation-board__name { max-width: none; }

    .automation-create,
    .automation-card__edit,
    .automation-menu__item,
    .pipeline-add-phase,
    .automation-sticky #ruleAddCondition { min-height: 44px; }

    .rule-run__num,
    .rule-run__unit,
    .rule-run__anchor,
    .rule-condition__field,
    .rule-condition__op,
    .rule-condition__value,
    .pipeline-column__name {
        height: 40px;
        font-size: 16px;
    }

    .rule-run__option { padding: 8px 10px; }

    /* Field and operator side by side, the value under them, remove on the end. */
    .rule-condition,
    .slide-over--automation .rule-condition,
    .rule-condition:has(.rule-condition__value[hidden]) {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 44px;
    }

    .rule-condition__value { grid-column: 1 / 3; grid-row: 2; }

    .rule-condition__remove { grid-column: 3; grid-row: 1; width: 44px; height: 44px; }

    .automation-sticky__block,
    .slide-over--automation .automation-sticky__block,
    .automation-step__body { padding: 14px 12px; }

    .automation-step__head { padding: 12px; }
}
