/* Permanent owner: Automation rules, editors, flags, blocks, dry-run, and audit-mobile presentation. */

/* ── Automations ──────────────────────────────────────────
   Page, rule cards, status chips, editor sticky footer, and
   the dashboard widget. Reuses .card / .btn / .form-* tokens
   from the rest of the file — keep new state on these classes
   only; do not re-style .card or .btn-sm globally here.
   ─────────────────────────────────────────────────────────── */

.page {
    display: block;
}

.automations-page {
    display: grid;
    gap: 16px;
}

.automation-empty-state {
    width: min(760px, 100%);
    margin: 28px auto 0;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 18px;
    padding: 20px;
    border: 1px solid var(--color-line);
    border-radius: var(--radius-lg);
    background: linear-gradient(135deg, rgba(var(--color-water-rgb), 0.10), rgba(var(--color-heatpump-rgb), 0.08));
    box-shadow: var(--shadow-soft);
}

.automation-empty-icon {
    width: 48px;
    height: 48px;
    display: inline-grid;
    place-items: center;
    border-radius: var(--radius-md);
    border: 1px solid rgba(var(--color-water-rgb), 0.24);
    background: color-mix(in srgb, var(--color-bg-soft) 55%, var(--color-surface));
    color: var(--color-water);
}

.automation-empty-icon svg {
    width: 24px;
    height: 24px;
}

.automation-empty-copy {
    min-width: 0;
}

.automation-empty-title {
    margin: 0;
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-text);
}

.automation-empty-text {
    margin: 5px 0 0;
    color: var(--color-text-muted);
    font-size: 0.9rem;
    line-height: 1.45;
}

.automation-empty-action {
    white-space: nowrap;
}

.automations-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--automation-side-rail-width);
    gap: 20px;
    align-items: start;
}

.automations-rules-col {
    display: grid;
    gap: 14px;
}

.automations-sidebar {
    position: sticky;
    top: 18px;
}

.automation-recipe-cta {
    padding: 16px;
    border: 1px solid var(--color-line);
    border-radius: var(--radius-lg);
    background: var(--color-card);
    box-shadow: var(--shadow-soft);
}

.automation-recipe-title {
    margin: 0 0 6px;
    font-family: var(--font-display);
    color: var(--color-text);
    font-size: 0.98rem;
    font-weight: 800;
}

.automation-recipe-text {
    margin: 0 0 12px;
    font-size: 0.84rem;
    line-height: 1.45;
}

.automation-category {
    border: 1px solid var(--color-line);
    border-radius: var(--radius-lg);
    background: var(--color-card);
    box-shadow: var(--shadow-soft);
    overflow: hidden;
}

.automation-category-header {
    width: 100%;
    min-height: 54px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border: 0;
    background: transparent;
    color: var(--color-text);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.automation-category-header:hover,
.automation-category-header:focus-visible {
    background: var(--color-bg-soft);
    outline: none;
}

.automation-category-chevron {
    color: var(--color-text-muted);
    font-size: 1.2rem;
    line-height: 1;
    transform: rotate(90deg);
    transition: transform var(--automation-transition-fast);
}

.automation-category--folded .automation-category-chevron {
    transform: rotate(0deg);
}

.automation-category-title {
    min-width: 0;
    flex: 1;
    font-family: var(--font-display);
    font-size: 0.98rem;
    font-weight: 800;
}

.automation-category-meta {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 7px;
    min-width: 0;
    margin-left: auto;
}

.automation-category-count,
.automation-category-active {
    white-space: nowrap;
    font-size: 0.8rem;
}

.automation-category-active {
    padding: 3px 8px;
    border-radius: 999px;
    background: var(--color-energy-soft);
    color: var(--color-energy);
    font-weight: 800;
}

.automation-category-body {
    display: grid;
    gap: 14px;
    padding: 0 16px 16px;
}

.rule-card-v2 {
    display: grid;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid var(--color-line);
    border-radius: var(--radius-md);
    background: var(--color-card);
    box-shadow: var(--shadow-soft);
    cursor: default;
    transition: background var(--automation-transition-fast), border-color var(--automation-transition-fast), opacity var(--automation-transition-fast);
}

.rule-card-v2:hover,
.rule-card-v2:focus-visible {
    border-color: var(--color-line-strong);
    background: var(--color-bg-soft);
    outline: none;
}

.rule-card--disabled {
    opacity: 0.62;
}

.rule-card-header,
.rule-card-footer {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

/* Two-tier card layout: row 1 = identity left, status + controls right;
   row 2 = WANNEER/ALS/DAN summary indented under the name. */
.rule-card-titlerow {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.rule-card-titlerow-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
}

.rule-card-edit-button {
    padding: 3px 4px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.rule-card-edit-button:focus-visible {
    outline: 2px solid var(--color-focus-outline);
    outline-offset: 2px;
}

.rule-card-titlerow-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.rule-card-name {
    min-width: 0;
    flex: 1;
    color: var(--color-text);
    font-size: 0.92rem;
    font-weight: 800;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rule-card-dot {
    width: 8px;
    height: 8px;
    flex-shrink: 0;
    border-radius: 999px;
    background: var(--color-text-muted);
}

.dot-green { background: var(--color-energy); }
.dot-amber { background: var(--color-warning); }
.dot-solar { background: var(--color-solar); }
.dot-red { background: var(--color-error); }
.dot-gray { background: var(--color-text-muted); }

/* Row 2: WANNEER/ALS/DAN summary with colored eyebrows that mirror the
   editor's three-column color language. Indented under the name (8px dot
   + 10px gap) so name + summary read as a grouped unit. */
.rule-card-summary {
    margin-left: 18px;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 14px;
    font-size: 0.82rem;
    line-height: 1.45;
}

.rule-card-action-error {
    margin-left: 18px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid color-mix(in srgb, var(--color-error) 26%, transparent);
    background: color-mix(in srgb, var(--color-error) 10%, transparent);
    color: var(--color-error);
    font-size: 0.8rem;
}

.rule-card-segment {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    min-width: 0;
}

.rule-card-eyebrow {
    font-size: 0.62rem;
    font-weight: 900;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--color-text-muted);
    flex-shrink: 0;
}

.rule-card-eyebrow--trigger   { color: var(--automation-node-trigger); }
.rule-card-eyebrow--condition { color: var(--automation-node-condition); }
.rule-card-eyebrow--action    { color: var(--automation-node-action); }

.rule-card-segment-text {
    color: var(--color-text-soft);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

/* Category list — flat list per category (priority sub-grouping removed). */
.automation-category-list {
    display: grid;
    gap: 8px;
}

.automation-category-disabled {
    display: grid;
    gap: 8px;
    margin-top: 6px;
    padding-top: 10px;
    border-top: 1px dashed var(--color-line);
}

.automation-category-disabled-header {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
}

.rule-card-footer {
    justify-content: flex-end;
}

.rule-card-toggle,
.rule-card-menu-btn {
    border: 0;
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
}

.rule-card-toggle {
    width: 42px;
    height: 28px;
    display: inline-grid;
    place-items: center;
}

.rule-card-toggle-track {
    width: 34px;
    height: 20px;
    position: relative;
    display: block;
    border-radius: 999px;
    background: var(--color-line-strong);
}

.rule-card-toggle-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--color-surface);
    box-shadow: var(--shadow-soft);
    transition: transform var(--automation-transition-fast);
}

.rule-card-toggle--on .rule-card-toggle-track {
    background: var(--color-energy);
}

.rule-card-toggle--on .rule-card-toggle-thumb {
    transform: translateX(14px);
}

.rule-card-menu-wrap {
    position: relative;
}

.rule-card-menu-btn {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-sm);
    font-size: 1.1rem;
}

.rule-card-menu-btn:hover,
.rule-card-menu-btn:focus-visible {
    background: var(--color-bg-soft);
    color: var(--color-text);
    outline: none;
}

.rule-card-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    z-index: 20;
    min-width: 160px;
    display: grid;
    gap: 4px;
    padding: 6px;
    border: 1px solid var(--color-line);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    box-shadow: var(--shadow-card);
}

.rule-card-menu-item {
    padding: 8px 10px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text);
    font: inherit;
    font-size: 0.84rem;
    text-align: left;
    cursor: pointer;
}

.rule-card-menu-item:hover,
.rule-card-menu-item:focus-visible {
    background: var(--color-bg-soft);
    outline: none;
}

.rule-card-menu-item--danger {
    color: var(--color-error);
}

.rules-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.rule-card {
    padding: 18px 20px;
    border: 1px solid var(--color-line);
    border-radius: 22px;
    background: var(--color-card);
    box-shadow: var(--shadow-soft);
    display: grid;
    gap: 14px;
    transition: border-color 180ms ease, opacity 180ms ease;
}

.rule-card.rule-disabled {
    opacity: 0.6;
    border-style: dashed;
}

.rule-card.rule-flap-disabled {
    opacity: 1;
    border-style: solid;
    border-color: rgba(var(--color-error-light-rgb), 0.7);
    background: linear-gradient(180deg, rgba(var(--color-error-light-rgb), 0.08), var(--color-bg-alt) 42%);
}

.rule-safety-alert {
    display: grid;
    gap: 6px;
    padding: 14px 16px;
    border: 1px solid rgba(var(--color-error-light-rgb), 0.58);
    border-radius: 14px;
    background: var(--color-error-soft);
    color: var(--color-error-text);
}

.rule-safety-alert strong {
    font-family: var(--font-display);
    font-size: 0.95rem;
}

.rule-safety-alert p {
    margin: 0;
    color: var(--color-text);
    line-height: 1.45;
}

.rule-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.rule-title-row {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex-wrap: wrap;
}

.rule-name {
    font-family: var(--font-display);
    font-size: 1.02rem;
    font-weight: 700;
    letter-spacing: 0;
    color: var(--color-text);
}

.rule-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 8px;
    font-size: 0.82rem;
    margin-top: 4px;
}

.rule-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

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

.form-error {
    color: var(--color-error-text);
    font-size: 0.86rem;
    margin: 4px 0 0;
}

/* Status chip — inline pill rendered next to the rule name. */
.automation-chip {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1.4;
    white-space: nowrap;
    letter-spacing: 0.01em;
}

.chip-green {
    background: rgba(var(--color-success-rgb), 0.15);
    color: var(--color-success-text);
}

.chip-amber {
    background: rgba(var(--color-warning-rgb), 0.15);
    color: var(--color-warning-text);
}

/* Benign automation phases (condition_met / cooldown) — brand amber, not the
   caution-orange the de-overload split out (--color-warning). */
.chip-solar {
    background: rgba(var(--color-solar-rgb), 0.15);
    color: var(--color-solar-text);
}

.chip-gray {
    background: var(--color-bg-soft);
    color: var(--color-text-muted);
}

.chip-red {
    background: rgba(var(--color-error-rgb), 0.15);
    color: var(--color-error-text);
}

/* Editor — wraps the form inside the bottom sheet. */
.rule-editor {
    display: flex;
    flex-direction: column;
    gap: 18px;
    min-height: 100%;
}

.rule-editor-intro {
    display: grid;
    gap: 6px;
    padding: 14px 16px;
    border: 1px solid rgba(var(--color-water-rgb), 0.18);
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, rgba(var(--color-water-rgb), 0.08), rgba(var(--color-heatpump-rgb), 0.06));
}

.rule-editor-eyebrow {
    margin: 0;
    color: var(--color-water);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.rule-editor-lede {
    margin: 0;
    color: var(--color-text-soft);
    font-size: 0.9rem;
    line-height: 1.45;
}

.rule-editor-presets {
    display: grid;
    gap: 12px;
    padding: 14px;
    border: 1px solid var(--color-line);
    border-radius: var(--radius-md);
    background: color-mix(in srgb, var(--color-bg-soft) 45%, transparent);
}

.rule-editor-presets-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.rule-editor-presets-head strong {
    color: var(--color-text);
    font-family: var(--font-display);
    font-size: 0.9rem;
}

.rule-editor-presets-head span {
    color: var(--color-text-muted);
    font-size: 0.78rem;
    line-height: 1.35;
    text-align: right;
}

.rule-editor-preset-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.rule-editor-preset {
    min-height: 74px;
    display: grid;
    gap: 5px;
    align-content: start;
    padding: 12px;
    border: 1px solid rgba(var(--color-water-rgb), 0.20);
    border-radius: var(--radius-sm);
    background: rgba(var(--color-water-rgb), 0.07);
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color 160ms ease, background-color 160ms ease, transform 160ms ease;
}

.rule-editor-preset:hover,
.rule-editor-preset:focus-visible {
    border-color: rgba(var(--color-water-rgb), 0.48);
    background: rgba(var(--color-water-rgb), 0.12);
    outline: none;
}

.rule-editor-preset:active {
    transform: translateY(1px);
}

.rule-editor-preset strong {
    color: var(--color-text);
    font-size: 0.86rem;
}

.rule-editor-preset span {
    color: var(--color-text-muted);
    font-size: 0.78rem;
    line-height: 1.35;
}

.rule-editor-layout {
    display: grid;
    gap: 16px;
}

.rule-editor-main {
    display: grid;
    gap: 14px;
    min-width: 0;
}

.rule-editor-section {
    display: grid;
    gap: 14px;
    padding: 16px;
    border: 1px solid var(--color-line);
    border-radius: var(--radius-md);
    background: color-mix(in srgb, var(--color-bg-soft) 40%, transparent);
}

.rule-editor-section-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.rule-editor-section-kicker {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.rule-editor-step {
    width: 28px;
    height: 28px;
    flex: 0 0 auto;
    display: inline-grid;
    place-items: center;
    border: 1px solid rgba(var(--color-water-rgb), 0.32);
    border-radius: 999px;
    background: rgba(var(--color-water-rgb), 0.10);
    color: var(--color-water);
    font-size: 0.8rem;
    font-weight: 800;
}

.rule-editor-section-title {
    margin: 0;
    font-family: var(--font-display);
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--color-text);
}

.rule-editor-section-note {
    margin: 0;
    color: var(--color-text-muted);
    font-size: 0.78rem;
    line-height: 1.4;
    text-align: right;
    max-width: 260px;
}

.rule-editor-section-body {
    display: grid;
    gap: 14px;
}

.rule-editor-section--compact {
    background: color-mix(in srgb, var(--color-bg-soft) 35%, transparent);
}

.rule-editor-switch-row {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
    gap: 12px;
    align-items: stretch;
}

.rule-editor-switch {
    min-height: 58px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 12px;
    border: 1px solid var(--color-line-strong);
    border-radius: var(--radius-sm);
    background: var(--color-bg-soft);
    cursor: pointer;
}

.rule-editor-switch input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.rule-editor-switch-control {
    width: 46px;
    height: 26px;
    position: relative;
    flex: 0 0 auto;
    border-radius: 999px;
    background: var(--color-line-strong);
    border: 1px solid var(--color-line-strong);
    transition: background-color 160ms ease, border-color 160ms ease;
}

.rule-editor-switch-control::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 999px;
    background: var(--color-text-muted);
    transition: transform 160ms ease, background-color 160ms ease;
}

.rule-editor-switch input:checked + .rule-editor-switch-control {
    background: rgba(var(--color-success-rgb), 0.18);
    border-color: rgba(var(--color-success-rgb), 0.45);
}

.rule-editor-switch input:checked + .rule-editor-switch-control::after {
    transform: translateX(20px);
    background: var(--color-success-text);
}

.rule-editor-switch input:focus-visible + .rule-editor-switch-control {
    box-shadow: 0 0 0 3px rgba(var(--color-water-rgb), 0.20);
}

.rule-editor-switch-copy {
    min-width: 0;
    display: grid;
    gap: 2px;
}

.rule-editor-switch-copy strong {
    color: var(--color-text);
    font-size: 0.9rem;
}

.rule-editor-switch-copy small {
    color: var(--color-text-muted);
    font-size: 0.76rem;
    line-height: 1.35;
}

.rule-editor-summary {
    display: grid;
    gap: 14px;
    align-content: start;
    padding: 16px;
    border: 1px solid rgba(var(--color-water-rgb), 0.18);
    border-radius: var(--radius-md);
    background: color-mix(in srgb, var(--color-bg-soft) 68%, var(--color-surface));
}

.rule-editor-summary-head {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.rule-editor-summary-head strong {
    min-width: 0;
    color: var(--color-text);
    font-family: var(--font-display);
    font-size: 0.94rem;
    overflow-wrap: anywhere;
}

.rule-editor-summary-status {
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 800;
}

.rule-editor-summary-status.is-on {
    background: rgba(var(--color-success-rgb), 0.14);
    color: var(--color-success-text);
}

.rule-editor-summary-status.is-off {
    background: color-mix(in srgb, var(--color-text-muted) 14%, transparent);
    color: var(--color-text-muted);
}

.rule-editor-summary-list {
    display: grid;
    gap: 12px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.rule-editor-summary-list li {
    display: grid;
    gap: 4px;
    padding-left: 12px;
    border-left: 2px solid rgba(var(--color-water-rgb), 0.32);
}

.rule-editor-summary-list span {
    color: var(--color-water);
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.rule-editor-summary-list p {
    margin: 0;
    color: var(--color-text-soft);
    font-size: 0.82rem;
    line-height: 1.45;
}

.rule-editor-summary-warning,
.rule-editor-summary-ok {
    margin: 0;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    line-height: 1.4;
}

.rule-editor-summary-warning {
    background: rgba(var(--color-warning-rgb), 0.11);
    color: var(--color-warning-text);
}

.rule-editor-summary-ok {
    background: rgba(var(--color-success-rgb), 0.11);
    color: var(--color-success-text);
}

.rule-editor-test {
    display: grid;
    gap: 12px;
    padding: 12px;
    border: 1px solid var(--color-line);
    border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--color-bg-soft) 42%, transparent);
}

.rule-editor-test-copy {
    display: grid;
    gap: 4px;
}

.rule-editor-test-copy strong {
    color: var(--color-text);
    font-size: 0.86rem;
}

.rule-editor-test-copy p {
    margin: 0;
    color: var(--color-text-muted);
    font-size: 0.78rem;
    line-height: 1.4;
}

.rule-editor-test-error {
    color: var(--color-error-text) !important;
}

.rule-editor-test .btn {
    justify-self: start;
}

.rule-editor .form-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-top: 0;
}

.rule-editor .form-group {
    gap: 7px;
}

.rule-editor .form-group label {
    color: var(--color-text-soft);
    font-size: 0.78rem;
    font-weight: 700;
    line-height: 1.25;
}

.rule-editor .form-control {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid var(--color-line-strong);
    border-radius: var(--radius-sm);
    background: var(--color-bg-soft);
    color: var(--color-text);
    font: inherit;
    font-size: 0.94rem;
    outline: none;
    transition: border-color 160ms ease, background-color 160ms ease, box-shadow 160ms ease;
}

.rule-editor .form-control::placeholder {
    color: var(--color-text-faint);
}

.rule-editor .form-control:focus {
    border-color: rgba(var(--color-water-rgb), 0.65);
    background: var(--color-bg-deep);
    box-shadow: 0 0 0 3px rgba(var(--color-water-rgb), 0.16);
}

.rule-editor select.form-control {
    appearance: none;
    padding-right: 36px;
    background-image:
        linear-gradient(45deg, transparent 50%, var(--color-text-soft) 50%),
        linear-gradient(135deg, var(--color-text-soft) 50%, transparent 50%);
    background-position:
        calc(100% - 18px) 19px,
        calc(100% - 12px) 19px;
    background-size: 6px 6px, 6px 6px;
    background-repeat: no-repeat;
}

.rule-editor select.form-control option {
    background: var(--color-bg-alt);
    color: var(--color-text);
}

.rule-editor .form-hint {
    margin: -4px 0 0;
    color: var(--color-text-muted);
    font-size: 0.82rem;
    line-height: 1.45;
}

/* Sticky footer — keeps Save/Cancel visible above the iOS keyboard
   inside the BottomSheet's scroll container (Issue 17). */
.rule-editor .form-actions {
    position: sticky;
    bottom: 0;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 0 0;
    margin-top: auto;
    background: var(--color-bg-alt);
    border-top: 1px solid var(--color-line);
}

.automation-editor-modal {
    display: none;
}

@media (min-width: 1101px) {
    .automation-editor-modal {
        position: fixed;
        inset: 0;
        z-index: 55;
        display: none;
        place-items: center;
        padding: 32px;
    }

    .automation-editor-modal--open {
        display: grid;
    }

    .automation-editor-modal-scrim {
        position: absolute;
        inset: 0;
        border: 0;
        background: var(--color-shell-scrim);
        cursor: pointer;
    }

    .automation-editor-modal-panel {
        position: relative;
        z-index: 1;
        width: min(1080px, calc(100vw - 64px));
        max-height: min(820px, calc(100vh - 64px));
        display: grid;
        grid-template-rows: auto minmax(0, 1fr);
        gap: 0;
        padding: 0;
        border: 1px solid var(--color-line);
        border-radius: var(--radius-lg);
        background: var(--color-bg-alt);
        box-shadow: 0 28px 80px rgba(0, 0, 0, 0.38);
        overflow: hidden;
    }

    .automation-editor-modal-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 16px;
        padding: 22px 24px 18px;
        border-bottom: 1px solid var(--color-line);
    }

    .automation-editor-modal-title {
        margin: 0;
        font-family: var(--font-display);
        font-size: 1.24rem;
        font-weight: 700;
        color: var(--color-text);
    }

    .automation-editor-modal-close {
        width: 40px;
        height: 40px;
        flex-shrink: 0;
        border: 1px solid var(--color-line);
        border-radius: 10px;
        background: transparent;
        color: var(--color-text);
        font-size: 1.3rem;
        line-height: 1;
        cursor: pointer;
        display: inline-grid;
        place-items: center;
    }

    .automation-editor-modal .rule-editor {
        min-height: 0;
        overflow-y: auto;
        padding: 20px 24px 24px;
        scrollbar-width: thin;
    }

    .automation-editor-modal .rule-editor-layout {
        grid-template-columns: minmax(0, 1fr) 310px;
        align-items: start;
    }

    .automation-editor-modal .rule-editor-summary {
        position: sticky;
        top: 0;
    }

    .automation-editor-modal .rule-editor .form-actions {
        margin: 2px -24px -24px;
        padding: 16px 24px;
        background: color-mix(in srgb, var(--color-bg-deep) 72%, transparent);
    }
}

/* ── AutomationRuleEditor — simplified UX additions ───────────────────── */

/* Direction chip pair */
.re-dir-chips {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.re-dir-chip {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 44px;
    padding: 10px 14px;
    border: 1px solid var(--color-line-strong);
    border-radius: var(--radius-sm);
    background: var(--color-bg-soft);
    color: var(--color-text-soft);
    font: inherit;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 160ms ease;
    text-align: center;
}
.re-dir-chip--active {
    border-color: rgba(var(--color-water-rgb), 0.75);
    background: rgba(var(--color-water-rgb), 0.12);
    color: var(--color-text);
}

/* Input with unit suffix */
.re-input-with-unit {
    display: flex;
    align-items: stretch;
    border: 1px solid var(--color-line-strong);
    border-radius: var(--radius-sm);
    background: var(--color-bg-soft);
    overflow: hidden;
    transition: border-color 160ms ease, box-shadow 160ms ease;
}
.re-input-with-unit:focus-within {
    border-color: rgba(var(--color-water-rgb), 0.65);
    box-shadow: 0 0 0 3px rgba(var(--color-water-rgb), 0.16);
}
.re-input-with-unit input {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    padding: 10px 12px;
    border: 0;
    background: transparent;
    color: var(--color-text);
    font: inherit;
    font-size: 0.94rem;
    outline: none;
}
.re-unit-badge {
    display: flex;
    align-items: center;
    padding: 0 12px;
    border-left: 1px solid var(--color-line-strong);
    background: color-mix(in srgb, var(--color-bg-soft) 70%, var(--color-surface));
    color: var(--color-text-muted);
    font-size: 0.82rem;
    font-weight: 600;
    white-space: nowrap;
    pointer-events: none;
}

/* Trigger preview: compact source/on/off explanation inside the trigger section. */
.re-trigger-preview {
    margin: -4px 0 0;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: rgba(var(--color-water-rgb), 0.07);
    border: 1px solid rgba(var(--color-water-rgb), 0.18);
    color: var(--color-text-soft);
    font-size: 0.82rem;
    line-height: 1.45;
}

.re-trigger-preview-row {
    display: grid;
    grid-template-columns: 54px minmax(0, 1fr);
    gap: 10px;
    align-items: baseline;
}

.re-trigger-preview-row + .re-trigger-preview-row {
    margin-top: 4px;
}

.re-trigger-preview-row span {
    color: var(--color-water);
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.re-trigger-preview strong {
    color: var(--color-text);
    font-weight: 700;
}

/* Advanced toggle */
.re-advanced-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    border: 0;
    background: transparent;
    color: var(--color-text-muted);
    font: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: color 160ms ease;
}
.re-advanced-toggle:hover { color: var(--color-text-soft); }
.re-advanced-toggle svg { transition: transform 160ms ease; }
.re-advanced-toggle--open svg { transform: rotate(180deg); }
.re-advanced-section {
    display: grid;
    gap: 14px;
    padding: 14px;
    border: 1px dashed var(--color-line);
    border-radius: var(--radius-sm);
    margin-top: -4px;
}

/* Deactivation hint for power/boost */
.re-deactivate-hint {
    font-size: 0.78rem;
    color: var(--color-text-muted);
    margin: 6px 0 0;
}

@media (max-width: 720px) {
    .automation-empty-state {
        grid-template-columns: minmax(0, 1fr);
        justify-items: start;
        padding: 18px;
    }

    .automation-empty-action {
        width: 100%;
    }

    .rule-editor-section-head {
        display: grid;
        gap: 4px;
    }

    .rule-editor-section-note {
        text-align: left;
        max-width: none;
    }

    .rule-editor-section-kicker {
        align-items: flex-start;
    }

    .rule-editor-switch-row {
        grid-template-columns: minmax(0, 1fr);
    }

    .rule-editor-presets-head {
        display: grid;
        gap: 4px;
    }

    .rule-editor-presets-head span {
        text-align: left;
    }

    .rule-editor-preset-list {
        grid-template-columns: minmax(0, 1fr);
    }

    .rule-editor .form-row {
        grid-template-columns: minmax(0, 1fr);
    }

    .rule-editor-summary {
        order: -1;
    }
}

/* Automation v2 modal/editor styles live in app.css because production CSP
   blocks inline <style> nodes generated from Vue string templates. */
.automation-editor-modal {
    position: fixed;
    inset: 0;
    z-index: 55;
    display: none;
    place-items: center;
    padding: 32px;
}

.automation-editor-modal--open {
    display: grid;
}

.automation-editor-modal-scrim {
    position: absolute;
    inset: 0;
    border: 0;
    background: var(--color-shell-scrim);
    cursor: pointer;
}

.automation-editor-modal-panel {
    position: relative;
    z-index: 1;
    width: min(1280px, calc(100vw - 64px));
    max-height: min(880px, calc(100vh - 64px));
    border: 1px solid var(--color-line);
    border-radius: var(--radius-lg);
    background: var(--color-surface);
    box-shadow: var(--shadow-card), 0 28px 80px rgba(0, 0, 0, 0.28);
    overflow: hidden;
}

.automation-editor {
    min-height: min(var(--automation-editor-min-height), calc(100vh - 64px));
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    max-height: 90vh;
    background: var(--color-surface);
    border-radius: inherit;
}

.automation-editor__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-line);
}

.automation-editor__header-left,
.automation-editor__header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.automation-editor__header-left {
    flex: 1;
    min-width: 0;
}

.automation-editor__header-right {
    flex-shrink: 0;
}

.automation-editor__back {
    background: none;
    border: 0;
    color: var(--color-text-muted);
    font: inherit;
    font-size: 0.875rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    white-space: nowrap;
}

.automation-editor__back:hover {
    color: var(--color-text);
    background: var(--color-bg-soft);
}

.automation-editor__name-input {
    flex: 1;
    min-width: 120px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--color-text);
    font-family: var(--font-display);
    font-size: 1.05rem;
    font-weight: 600;
    padding: 4px 8px;
}

.automation-editor__name-input:focus {
    border-color: var(--color-solar);
    outline: none;
    background: var(--color-bg-soft);
}

.automation-editor__status {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 2px 8px;
    border-radius: 10px;
    white-space: nowrap;
}

.automation-editor__status--idle { color: var(--automation-status-idle); background: color-mix(in srgb, var(--color-text-muted) 10%, transparent); }
.automation-editor__status--active { color: var(--automation-status-active); background: rgba(var(--color-success-rgb), 0.12); }
.automation-editor__status--cooldown { color: var(--automation-status-cooldown); background: rgba(var(--color-warning-rgb), 0.12); }
.automation-editor__status--blocked { color: var(--automation-status-blocked); background: rgba(var(--color-error-rgb), 0.12); }

.automation-editor__toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

.automation-editor__toggle input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.automation-editor__toggle-track {
    width: 36px;
    height: 20px;
    border-radius: 10px;
    background: var(--color-bg-soft);
    position: relative;
    transition: background 150ms ease;
}

.automation-editor__toggle-track::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--color-text-muted);
    transition: transform 150ms ease, background 150ms ease;
}

.automation-editor__toggle input:checked + .automation-editor__toggle-track {
    background: var(--color-energy);
}

.automation-editor__toggle input:checked + .automation-editor__toggle-track::after {
    transform: translateX(16px);
    background: var(--color-on-accent);
}

.automation-editor__toggle-label {
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.automation-editor__save-btn {
    background: var(--color-solar) !important;
    border-color: var(--color-solar) !important;
    color: var(--color-on-accent) !important;
}

.automation-editor__save-btn:disabled {
    opacity: 0.5;
}

.automation-editor__tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--color-line);
    padding: 0 20px;
}

.automation-editor__meta {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px 0;
}

.automation-editor__meta-field {
    width: min(360px, 100%);
    display: grid;
    gap: 6px;
}

.automation-editor__meta-field span {
    color: var(--color-text-muted);
    font-size: 0.76rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.automation-editor__meta-field input {
    background: var(--color-bg-soft);
    border: 1px solid var(--color-line);
    border-radius: 6px;
    color: var(--color-text);
    font: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    padding: 4px 8px;
    outline: none;
    transition: border-color 160ms ease, background-color 160ms ease;
}

.automation-editor__meta-field input:hover {
    border-color: var(--color-line-strong);
}

.automation-editor__meta-field input:focus {
    border-color: var(--color-solar);
    background: var(--color-bg-soft);
}

.automation-editor__tab {
    background: none;
    border: 0;
    color: var(--color-text-muted);
    font: inherit;
    font-size: 0.85rem;
    padding: 10px 16px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color var(--automation-transition-fast), border-color var(--automation-transition-fast);
}

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

.automation-editor__tab--active {
    color: var(--color-solar);
    border-bottom-color: var(--color-solar);
}

.automation-editor__flow-placeholder {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.automation-editor__step-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--color-line);
    padding: 0 12px;
    overflow-x: auto;
}

.automation-editor__step-tab {
    position: relative;
    background: none;
    border: 0;
    color: var(--color-text-muted);
    font: inherit;
    font-size: 0.8rem;
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    transition: color var(--automation-transition-fast);
}

.automation-editor__step-tab:hover { color: var(--color-text); }

.automation-editor__step-tab--active {
    color: var(--color-text);
    border-bottom-color: var(--color-solar);
}

.automation-editor__step-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    font-size: 0.7rem;
    font-weight: 700;
    border-radius: 9px;
    padding: 0 5px;
    margin-left: 4px;
    vertical-align: middle;
}

.automation-editor__step-badge--count {
    background: var(--color-bg-soft);
    color: var(--color-text-muted);
}

.automation-editor__step-badge--warn {
    background: rgba(var(--color-warning-rgb), 0.18);
    color: var(--automation-status-cooldown);
}

.automation-editor__columns {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--automation-column-gap);
    padding: 20px;
    align-items: stretch;
}

.automation-editor__column {
    display: flex;
    flex-direction: column;
    gap: var(--automation-block-gap);
    min-width: 0;
    min-height: 260px;
    padding: 14px;
    border: 1px solid var(--color-line);
    border-radius: var(--radius-md);
    background: color-mix(in srgb, var(--color-bg-soft) 52%, var(--color-surface));
}

.automation-editor__column-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 36px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--color-line);
    flex-wrap: wrap;
}

.automation-editor__column-header--trigger { box-shadow: inset 0 -2px 0 var(--automation-node-trigger); }
.automation-editor__column-header--condition { box-shadow: inset 0 -2px 0 var(--automation-node-condition); }
.automation-editor__column-header--action { box-shadow: inset 0 -2px 0 var(--automation-node-action); }

.automation-editor__column-label {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.automation-editor__column-header--trigger .automation-editor__column-label { color: var(--automation-node-trigger); }
.automation-editor__column-header--condition .automation-editor__column-label { color: var(--automation-node-condition); }
.automation-editor__column-header--action .automation-editor__column-label { color: var(--automation-node-action); }

.automation-editor__logic-toggle {
    display: flex;
    gap: 2px;
    background: var(--color-bg-soft);
    border-radius: 6px;
    padding: 2px;
}

.automation-editor__logic-btn {
    background: transparent;
    border: 0;
    color: var(--color-text-muted);
    font: inherit;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 3px 10px;
    border-radius: 4px;
    cursor: pointer;
    transition: background var(--automation-transition-fast), color var(--automation-transition-fast);
}

.automation-editor__logic-btn:hover {
    color: var(--color-text);
}

.automation-editor__logic-btn--active {
    background: var(--color-surface);
    color: var(--color-text);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.automation-editor__block-list {
    display: flex;
    flex-direction: column;
    gap: var(--automation-block-gap);
    min-height: 56px;
}

.automation-editor__below {
    padding: 0 20px 20px;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
}

.automation-editor__deactivation {
    margin: 0;
    font-size: 0.85rem;
    color: var(--color-text-muted);
    background: var(--color-bg-soft);
    padding: 10px 14px;
    border-radius: 8px;
    border-left: 3px solid var(--automation-node-rollback);
}

.automation-editor__knobs {
    padding: 16px;
    background: color-mix(in srgb, var(--color-bg-soft) 70%, var(--color-surface));
    border: 1px solid var(--color-line);
    border-radius: var(--radius-md);
}

.automation-editor__knobs-title {
    margin: 0 0 4px;
    font-size: 0.9rem;
    font-weight: 600;
}

.automation-editor__knob-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 8px;
}

.automation-editor__knob-row .form-control {
    flex: 1;
    min-width: 0;
}

.automation-editor__dry-run {
    padding: 12px 20px;
    background: var(--color-bg-soft);
    border-radius: 8px;
    margin: 0 20px;
    font-size: 0.85rem;
}

.automation-editor__error {
    color: var(--color-error-text);
    padding: 0 20px;
    font-size: 0.85rem;
}

.automation-editor__validation-hint {
    color: var(--automation-status-cooldown);
    padding: 0 20px;
    font-size: 0.8rem;
}

.automation-editor__validation-hint--top {
    margin: 0 20px 12px;
    padding: 10px 12px;
    border: 1px solid rgba(var(--color-warning-rgb), 0.34);
    border-radius: var(--radius-sm);
    background: rgba(var(--color-warning-rgb), 0.10);
}

.automation-editor__footer {
    position: sticky;
    bottom: 0;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 12px 16px;
    background: var(--color-surface);
    border-top: 1px solid var(--color-line);
    z-index: 10;
}

.form-control--inline {
    display: inline-block;
    width: auto;
}

.flag-strip {
    display: grid;
    gap: 12px;
    margin: 18px 0 24px;
    padding: 16px;
    border: 1px solid var(--color-line);
    border-radius: var(--radius-lg);
    background: var(--color-card);
    box-shadow: var(--shadow-soft);
}

.flag-strip--empty {
    max-width: 760px;
}

.flag-strip__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.flag-strip__title-group {
    display: grid;
    gap: 3px;
}

.flag-strip__title {
    margin: 0;
    font-family: var(--font-display);
    color: var(--color-text);
    font-size: 0.94rem;
    font-weight: 800;
}

.flag-strip__text {
    margin: 0;
    max-width: 620px;
    color: var(--color-text-muted);
    font-size: 0.84rem;
    line-height: 1.45;
}

.flag-strip__chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.flag-chip-wrap {
    display: grid;
    gap: 4px;
}

.flag-chip-error {
    max-width: 280px;
    color: var(--color-error);
    font-size: 0.76rem;
    line-height: 1.35;
}

.flag-chip,
.flag-strip__add {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 5px 7px 5px 12px;
    border: 1px solid var(--color-line);
    border-radius: var(--radius-sm);
    background: var(--color-bg-soft);
    color: var(--color-text-soft);
    font: inherit;
    font-size: 0.86rem;
}

.flag-strip__add {
    min-height: 38px;
    gap: 8px;
    padding: 7px 10px;
    cursor: pointer;
}

.flag-strip__add:hover,
.flag-strip__add:focus-visible {
    border-color: var(--color-line-strong);
    background: var(--color-bg-deep);
    color: var(--color-text);
    outline: none;
}

.flag-chip--active {
    border-color: color-mix(in srgb, var(--color-energy) 38%, var(--color-line));
    background: color-mix(in srgb, var(--color-energy) 10%, var(--color-surface));
    color: var(--color-text);
    box-shadow: inset 3px 0 0 color-mix(in srgb, var(--color-energy) 82%, transparent);
}

.flag-chip-main {
    min-height: 28px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    color: inherit;
}

.flag-chip-label {
    font-weight: 700;
}

.flag-chip--active .flag-chip-label {
    color: var(--color-energy);
}

.flag-chip-schedule {
    color: var(--color-text-muted);
    font-size: 0.76rem;
}

.flag-chip-edit {
    width: 28px;
    height: 28px;
    display: inline-grid;
    place-items: center;
    flex-shrink: 0;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text-muted);
    font: inherit;
    font-size: 0.82rem;
    cursor: pointer;
}

.flag-chip-edit:hover,
.flag-chip-edit:focus-visible {
    background: var(--color-bg-deep);
    color: var(--color-text);
    outline: none;
}

.flag-chip-toggle {
    min-height: 30px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    flex-shrink: 0;
    border: 1px solid var(--color-line);
    background: color-mix(in srgb, var(--color-bg-deep) 68%, transparent);
    color: var(--color-text-muted);
    padding: 3px 5px 3px 9px;
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition:
        background-color var(--automation-transition-fast),
        border-color var(--automation-transition-fast),
        color var(--automation-transition-fast);
}

.flag-chip-toggle:hover,
.flag-chip-toggle:focus-visible {
    border-color: var(--color-line-strong);
    background: var(--color-bg-deep);
    color: var(--color-text-soft);
    outline: none;
}

.flag-chip-toggle:focus-visible {
    box-shadow: 0 0 0 3px var(--color-focus-ring);
}

.flag-chip-toggle-status {
    min-width: 22px;
    font-family: var(--font-display);
    font-size: 0.68rem;
    font-weight: 800;
    line-height: 1;
    text-align: center;
}

.flag-chip-toggle-track {
    width: 28px;
    height: 16px;
    display: block;
    position: relative;
    border-radius: 999px;
    background: var(--color-line-strong);
    transition: background var(--automation-transition-fast);
}

.flag-chip-toggle-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--color-surface);
    box-shadow: var(--shadow-soft);
    transition: transform var(--automation-transition-fast);
}

.flag-chip-toggle--on {
    border-color: color-mix(in srgb, var(--color-energy) 44%, var(--color-line));
    background: color-mix(in srgb, var(--color-energy) 14%, transparent);
    color: var(--color-energy);
}

.flag-chip-toggle--on .flag-chip-toggle-track {
    background: var(--color-energy);
}

.flag-chip-toggle--on .flag-chip-toggle-thumb {
    transform: translateX(12px);
}

.flag-strip__add {
    border-style: dashed;
    background: transparent;
    color: var(--color-text-muted);
    font-weight: 800;
}

.flag-strip__add-icon {
    width: 20px;
    height: 20px;
    display: inline-grid;
    place-items: center;
    border-radius: 999px;
    background: var(--color-bg-soft);
    color: var(--color-text-soft);
    font-size: 0.9rem;
}

/* ── Flag editor modal ─────────────────────────────────────────────────── */

.flag-editor-modal {
    position: fixed;
    inset: 0;
    z-index: 55;
    display: grid;
    place-items: center;
    padding: 24px;
}

.flag-editor-modal-scrim {
    position: absolute;
    inset: 0;
    border: 0;
    background: var(--color-shell-scrim);
    cursor: pointer;
}

.flag-editor-modal-panel {
    position: relative;
    z-index: 1;
    width: min(480px, calc(100vw - 32px));
    max-height: min(680px, calc(100vh - 48px));
    display: flex;
    flex-direction: column;
    border: 1px solid var(--color-line);
    border-radius: var(--radius-lg);
    background: var(--color-bg-alt);
    box-shadow: 0 28px 80px rgba(0, 0, 0, 0.38);
    overflow: hidden;
}

.flag-editor-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 20px 14px;
    border-bottom: 1px solid var(--color-line);
    flex-shrink: 0;
}

.flag-editor-modal-title {
    margin: 0;
    font-family: var(--font-display);
    font-size: 1.08rem;
    font-weight: 700;
    letter-spacing: 0;
    color: var(--color-text);
}

.flag-editor-modal-close {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border: 1px solid var(--color-line);
    border-radius: 10px;
    background: transparent;
    color: var(--color-text);
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    display: inline-grid;
    place-items: center;
}

.flag-editor-modal-close:hover {
    background: var(--color-bg-soft);
}

.flag-editor-modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1 1 auto;
}

/* ── Flag editor form ──────────────────────────────────────────────────── */

.flag-editor {
    display: grid;
    gap: 16px;
}

.flag-editor-field {
    display: grid;
    gap: 6px;
}

.flag-editor-row {
    grid-template-columns: 1fr auto;
    align-items: center;
}

.flag-editor-label {
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--color-text-soft);
    letter-spacing: 0.01em;
}

.flag-editor-input {
    width: 100%;
    height: 40px;
    padding: 0 12px;
    border: 1px solid var(--color-line);
    border-radius: var(--radius-sm);
    background: var(--color-bg-soft);
    color: var(--color-text);
    font: inherit;
    font-size: 0.9rem;
    box-sizing: border-box;
}

.flag-editor-input:focus {
    outline: none;
    border-color: var(--color-energy);
    background: var(--color-bg);
}

.flag-editor-input[readonly] {
    opacity: 0.6;
    cursor: not-allowed;
}

.flag-editor-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 0;
    background: transparent;
    padding: 0;
    cursor: pointer;
}

.flag-editor-toggle-track {
    width: 38px;
    height: 22px;
    display: block;
    position: relative;
    border-radius: 999px;
    background: var(--color-line-strong);
    transition: background var(--automation-transition-fast);
    flex-shrink: 0;
}

.flag-editor-toggle-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--color-surface);
    box-shadow: var(--shadow-soft);
    transition: transform var(--automation-transition-fast);
}

.flag-editor-toggle--on .flag-editor-toggle-track {
    background: var(--color-energy);
}

.flag-editor-toggle--on .flag-editor-toggle-thumb {
    transform: translateX(16px);
}

.flag-editor-toggle-label {
    font-size: 0.86rem;
    color: var(--color-text-soft);
    width: 2.2ch;
    text-align: right;
}

.flag-editor-slug-hint {
    font-size: 0.76rem;
    color: var(--color-text-muted);
    font-family: var(--font-mono);
    letter-spacing: 0.01em;
}

.flag-editor-section {
    display: grid;
    gap: 12px;
    border-top: 1px solid var(--color-line);
    padding-top: 14px;
}

.flag-editor-section-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 0;
    background: transparent;
    padding: 0;
    cursor: pointer;
    font: inherit;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--color-text-soft);
}

.flag-editor-section-arrow {
    display: inline-block;
    font-size: 0.6rem;
    transition: transform 180ms ease;
}

.flag-editor-section-arrow--open {
    transform: rotate(90deg);
}

.flag-editor-section-body {
    display: grid;
    gap: 12px;
}

.flag-editor-dates {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.flag-editor-error {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--color-error) 12%, transparent);
    border: 1px solid color-mix(in srgb, var(--color-error) 30%, transparent);
    color: var(--color-error);
    font-size: 0.84rem;
}

.flag-editor-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    padding-top: 4px;
    border-top: 1px solid var(--color-line);
}

@media (max-width: 600px) {
    .flag-editor-modal {
        padding: 0;
        place-items: end center;
    }

    .flag-editor-modal-panel {
        width: 100%;
        max-height: 90dvh;
        border-radius: 20px 20px 0 0;
        border-bottom-width: 0;
    }
}

/* ── Block picker ──────────────────────────────────────────────────────── */

.block-picker {
    position: relative;
}

.block-picker__trigger {
    width: 100%;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px dashed var(--color-line-strong);
    border-radius: var(--radius-lg);
    background: transparent;
    color: var(--color-text-muted);
    font: inherit;
    font-size: 0.86rem;
    font-weight: 700;
    cursor: pointer;
    transition: background var(--automation-transition-fast), border-color var(--automation-transition-fast), color var(--automation-transition-fast);
}

.block-picker__trigger:hover,
.block-picker__trigger:focus-visible {
    background: var(--color-bg-soft);
    border-color: var(--color-line-strong);
    color: var(--color-text);
    outline: none;
}

.block-picker__popover {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 8px);
    z-index: 20;
    display: grid;
    gap: 4px;
    padding: 10px;
    max-height: min(60vh, 480px);
    overflow-y: auto;
    border: 1px solid var(--color-line);
    border-radius: var(--radius-xl);
    background: var(--color-surface);
    box-shadow: var(--shadow-card);
}

.block-picker__option {
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr);
    gap: 12px;
    align-items: start;
    width: 100%;
    padding: 12px 14px;
    border: 0;
    border-radius: var(--radius-lg);
    background: transparent;
    color: var(--color-text);
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: background-color 120ms ease, transform 120ms ease;
}

.block-picker__option:active {
    transform: scale(0.99);
}

.block-picker__option:hover,
.block-picker__option:focus-visible {
    background: var(--color-bg-soft);
    outline: none;
}

.block-picker__option-icon {
    font-size: 1rem;
    line-height: 1.25;
}

.block-picker__option-text {
    display: grid;
    gap: 2px;
}

.block-picker__option-text strong {
    font-size: 0.86rem;
    font-weight: 700;
}

.block-picker__option-text small {
    color: var(--color-text-muted);
    font-size: 0.76rem;
    line-height: 1.35;
}

.automation-block {
    border: 1px solid var(--color-line);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    box-shadow: var(--shadow-soft);
    overflow: hidden;
}

.automation-block--trigger { border-left: 3px solid var(--automation-node-trigger); }
.automation-block--condition { border-left: 3px solid var(--automation-node-condition); }
.automation-block--action { border-left: 3px solid var(--automation-node-action); }

.automation-block__header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--color-line);
}

.automation-block__icon {
    width: 22px;
    height: 22px;
    display: inline-grid;
    place-items: center;
    border-radius: 7px;
    background: var(--color-bg-soft);
    font-size: 0.86rem;
}

/* Inline wrapper for SVG icons injected via v-html into the automation
   editor/flow/recipes (replaced the old decorative emoji). Self-sizing in `em`
   so it scales with the parent and renders identically regardless of the parent
   span's own font-size. Colour inherits, so accent classes still tint it. */
.auto-glyph {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: -0.15em;
    color: inherit;
}
/* Size the SVG child, NOT the host — so .auto-glyph layered onto an already-
   sized element (a 28px .flag-chip-edit button, a 22px .automation-block__icon
   box) keeps that element's box and just normalises the glyph. A bare wrapper
   span shrink-wraps to the 1.05em glyph. */
.auto-glyph svg {
    width: 1.05em;
    height: 1.05em;
    flex: none;
    display: block;
}

.automation-block__order-badge {
    width: 22px;
    height: 22px;
    display: inline-grid;
    place-items: center;
    border-radius: 999px;
    background: var(--color-energy-soft);
    color: var(--color-energy);
    font-size: 0.75rem;
    font-weight: 800;
}

.automation-block__title {
    min-width: 0;
    flex: 1;
    color: var(--color-text);
    font-size: 0.9rem;
    font-weight: 800;
}

.automation-block__remove {
    width: 28px;
    height: 28px;
    display: inline-grid;
    place-items: center;
    flex-shrink: 0;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text-muted);
    font-size: 1.15rem;
    line-height: 1;
    cursor: pointer;
}

.automation-block__remove:hover,
.automation-block__remove:focus-visible {
    border-color: var(--color-error-soft);
    background: var(--color-error-soft);
    color: var(--color-error);
    outline: none;
}

.automation-block__reorder {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.automation-block__move {
    width: 28px;
    height: 28px;
    display: inline-grid;
    place-items: center;
    border: 1px solid var(--color-line);
    border-radius: var(--radius-sm);
    background: var(--color-bg-soft);
    color: var(--color-text-soft);
    font-size: 0.82rem;
    font-weight: 800;
    line-height: 1;
    cursor: pointer;
    transition:
        border-color var(--automation-transition-fast),
        background var(--automation-transition-fast),
        color var(--automation-transition-fast);
}

.automation-block__move:hover:not(:disabled),
.automation-block__move:focus-visible:not(:disabled) {
    border-color: var(--automation-node-action);
    background: var(--color-energy-soft);
    color: var(--automation-node-action);
    outline: none;
}

.automation-block__move:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.automation-block__body {
    display: grid;
    gap: 12px;
    padding: 12px;
}

.automation-block .form-group,
.automation-safety .form-group {
    display: grid;
    gap: 7px;
}

.automation-block .form-group label,
.automation-block .form-group .form-label,
.automation-safety .form-group label {
    color: var(--color-text-soft);
    font-size: 0.78rem;
    font-weight: 700;
    line-height: 1.25;
}

.automation-block .form-control,
.automation-safety .form-control,
.automation-editor__meta-field input,
.automation-editor__knob-row .form-control {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid var(--color-line-strong);
    border-radius: var(--radius-sm);
    background: var(--color-bg-soft);
    color: var(--color-text);
    font: inherit;
    font-size: 0.94rem;
    outline: none;
    transition: border-color 160ms ease, background-color 160ms ease, box-shadow 160ms ease;
}

.automation-block .form-control:focus,
.automation-safety .form-control:focus,
.automation-editor__meta-field input:focus,
.automation-editor__knob-row .form-control:focus {
    border-color: rgba(var(--color-water-rgb), 0.65);
    background: var(--color-bg-deep);
    box-shadow: 0 0 0 3px rgba(var(--color-water-rgb), 0.16);
}

.automation-block select.form-control,
.automation-safety select.form-control {
    appearance: none;
    padding-right: 36px;
    background-image:
        linear-gradient(45deg, transparent 50%, var(--color-text-soft) 50%),
        linear-gradient(135deg, var(--color-text-soft) 50%, transparent 50%);
    background-position:
        calc(100% - 18px) 19px,
        calc(100% - 12px) 19px;
    background-size: 6px 6px, 6px 6px;
    background-repeat: no-repeat;
}

.automation-block select.form-control option,
.automation-safety select.form-control option {
    background: var(--color-bg-alt);
    color: var(--color-text);
}

.automation-block__summary {
    margin: 0;
    color: var(--color-text-muted);
    font-size: 0.84rem;
    line-height: 1.45;
}

.automation-block__input-unit {
    display: flex;
    align-items: stretch;
}

.automation-block__input-unit .form-control {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.automation-block__unit {
    display: inline-flex;
    align-items: center;
    min-width: 44px;
    padding: 0 10px;
    border: 1px solid var(--color-line);
    border-left: 0;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    background: var(--color-bg-soft);
    color: var(--color-text-muted);
    font-size: 0.8rem;
    font-weight: 700;
}

.automation-block__days {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.automation-block__day-chip {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    min-height: 32px;
    padding: 0 10px;
    border: 1px solid var(--color-line);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-text-muted);
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
}

.automation-block__day-chip input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.automation-block__day-chip--active {
    border-color: var(--color-info);
    background: var(--color-info-soft);
    color: var(--color-info);
}

.automation-block__rollback {
    border-top: 1px solid var(--color-line);
    padding-top: 10px;
}

.automation-block__rollback-toggle {
    color: var(--color-text-soft);
    cursor: pointer;
    font-size: 0.84rem;
    font-weight: 700;
}

.automation-block__rollback-body {
    display: grid;
    gap: 12px;
    padding-top: 10px;
}

/* Automation v2 — mode chip picker (mode_active trigger / mode_is condition) */
.automation-choice-chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.automation-choice-chip {
    border: 1px solid var(--color-line);
    background: var(--color-bg-soft);
    color: var(--color-text);
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 13px;
    cursor: pointer;
    transition: background-color 120ms ease, border-color 120ms ease;
}
.automation-choice-chip:hover { border-color: var(--color-info); }
.automation-choice-chip--active {
    background: var(--color-info-soft);
    border-color: var(--color-info);
    color: var(--color-info);
}
.form-group--empty .form-help { color: var(--color-text-soft); font-style: italic; }

.automation-safety {
    border: 1px solid var(--color-line);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    overflow: hidden;
}

.automation-safety__toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 48px;
    padding: 12px 14px;
    cursor: pointer;
    list-style: none;
}

.automation-safety__toggle::-webkit-details-marker {
    display: none;
}

.automation-safety__toggle::before {
    content: "";
    width: 7px;
    height: 7px;
    border-right: 2px solid var(--color-text-muted);
    border-bottom: 2px solid var(--color-text-muted);
    transform: rotate(-45deg);
    transition: transform var(--automation-transition-fast);
}

.automation-safety[open] .automation-safety__toggle::before {
    transform: rotate(45deg);
}

.automation-safety__icon {
    width: 28px;
    height: 28px;
    display: inline-grid;
    place-items: center;
    border-radius: var(--radius-sm);
    background: var(--color-bg-soft);
    font-size: 0.95rem;
}

.automation-safety__title {
    color: var(--color-text);
    font-size: 0.92rem;
    font-weight: 800;
}

.automation-safety__cooldown-badge {
    margin-left: auto;
    padding: 4px 8px;
    border-radius: 999px;
    background: var(--color-bg-soft);
    color: var(--color-text-muted);
    font-size: 0.78rem;
    font-weight: 700;
    white-space: nowrap;
}

.automation-safety__body {
    display: grid;
    gap: 14px;
    padding: 0 14px 14px;
}

.automation-safety__hint {
    display: block;
    margin-top: 6px;
    color: var(--color-text-muted);
    font-size: 0.78rem;
    line-height: 1.45;
}

.automation-safety__explanation,
.automation-safety__constraints {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--color-bg-soft);
}

.automation-safety__explanation p,
.automation-safety__constraints p {
    margin: 0;
}

.automation-flow {
    position: relative;
    background: var(--color-content-surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    min-height: 300px;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
}

.automation-flow__svg {
    display: block;
}

.automation-flow__node {
    cursor: pointer;
    transition: opacity 0.15s ease;
}

.automation-flow__node:hover,
.automation-flow__node:focus-visible {
    opacity: 0.85;
}

.automation-flow__node:focus-visible rect,
.automation-flow__node:focus-visible circle {
    stroke-width: 2.5;
}

.automation-flow__edge--animated {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    animation: automation-flow-dash 1.5s ease forwards;
}

@keyframes automation-flow-dash {
    to { stroke-dashoffset: 0; }
}

.automation-flow__inspector {
    position: absolute;
    bottom: 16px;
    right: 16px;
    background: var(--color-card);
    border: 1px solid var(--color-line-strong);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    min-width: 180px;
    max-width: 280px;
    z-index: 10;
    box-shadow: var(--shadow-panel);
}

.automation-flow__inspector-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text);
    gap: 8px;
}

.automation-flow__inspector-close {
    background: none;
    border: 0;
    color: var(--color-text-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 0 2px;
    line-height: 1;
}

.automation-flow__inspector-detail {
    margin: 6px 0 0;
    font-size: 12px;
    color: var(--color-text-muted);
    line-height: 1.4;
}

.dryrun-panel {
    margin: 0 20px 12px;
    padding: 14px 16px;
    background: var(--color-bg-soft);
    border-radius: 10px;
    font-size: 0.84rem;
    border: 1px solid var(--color-line);
}

.dryrun-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.dryrun-panel__title {
    font-weight: 600;
    font-size: 0.88rem;
    color: var(--color-text);
}

.dryrun-panel__close {
    background: none;
    border: 0;
    color: var(--color-text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    line-height: 1;
}

.dryrun-panel__close:hover {
    color: var(--color-text);
    background: var(--color-line);
}

.dryrun-panel__loading,
.dryrun-panel__no-data {
    color: var(--color-text-muted);
    padding: 4px 0;
}

.dryrun-panel__loading {
    font-style: italic;
}

.dryrun-panel__section {
    margin-bottom: 10px;
}

.dryrun-panel__section-label {
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.dryrun-panel__logic-chip {
    font-weight: 400;
    font-size: 0.72rem;
    text-transform: none;
    letter-spacing: 0;
    background: var(--color-line);
    padding: 1px 6px;
    border-radius: 4px;
    color: var(--color-text-soft);
}

.dryrun-panel__row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px 0;
}

.dryrun-check,
.dryrun-cross {
    font-weight: 700;
    min-width: 16px;
    text-align: center;
}

.dryrun-check { color: var(--color-success); }
.dryrun-cross { color: var(--color-text-faint); }

.dryrun-panel__row-label {
    color: var(--color-text-soft);
}

.dryrun-panel__row-value {
    color: var(--color-text-muted);
    font-size: 0.8rem;
    margin-left: auto;
    font-variant-numeric: tabular-nums;
}

.dryrun-panel__row-detail {
    color: var(--color-text-faint);
    font-size: 0.78rem;
}

.dryrun-panel__row-error {
    color: var(--color-error-text);
    font-size: 0.78rem;
}

.dryrun-panel__verdict {
    margin-top: 10px;
    padding: 8px 14px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.85rem;
    text-align: center;
}

.dryrun-panel__verdict--activate {
    background: var(--color-success-soft);
    color: var(--color-success-text);
}

.dryrun-panel__verdict--block {
    background: var(--color-line);
    color: var(--color-text-muted);
}

.dryrun-panel__verdict-reason {
    font-weight: 400;
    font-size: 0.8rem;
}

.dryrun-slide-enter-active,
.dryrun-slide-leave-active {
    transition: opacity 180ms ease-out, max-height 180ms ease-out;
    overflow: hidden;
}

.dryrun-slide-enter-from,
.dryrun-slide-leave-to {
    opacity: 0;
    max-height: 0;
}

.dryrun-slide-enter-to,
.dryrun-slide-leave-from {
    opacity: 1;
    max-height: 400px;
}

@media (prefers-reduced-motion: reduce) {
    .automation-flow__edge--animated {
        animation: none;
        stroke-dasharray: none;
        stroke-dashoffset: 0;
    }
}

@media (max-width: 768px) {
    .automation-editor-modal {
        place-items: stretch;
        padding: 0;
    }

    .automation-editor-modal-panel {
        width: 100vw;
        max-height: 100dvh;
        border-radius: 0;
        border-width: 0;
    }

    .automation-editor {
        min-height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
    }

    .automation-editor__columns {
        display: flex;
        flex-direction: column;
        gap: 12px;
        padding: 12px;
    }

    .automation-editor__column {
        min-height: 0;
    }

    .automation-editor__header {
        padding: 12px 14px;
    }

    .automation-editor__header-right {
        display: none;
    }

    .automation-editor__below {
        padding: 0 12px 12px;
    }

    .automations-layout {
        grid-template-columns: minmax(0, 1fr);
    }

    .automations-sidebar {
        position: static;
    }

    .automation-category-header {
        flex-wrap: wrap;
    }

    .automation-category-title {
        flex-basis: calc(100% - 32px);
    }

    .automation-category-meta {
        justify-content: flex-start;
        width: 100%;
        margin-left: 28px;
    }

    .automation-editor__meta {
        padding: 12px 12px 0;
    }

    .automation-editor__knob-row,
    .dryrun-panel__row {
        flex-wrap: wrap;
    }
}

.btn-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    border: 0;
    background: transparent;
    padding: 4px 6px;
    font: inherit;
    font-weight: 700;
    color: var(--color-water-text);
    cursor: pointer;
    border-radius: 8px;
}

.btn-link:hover { text-decoration: underline; }

.btn-outline {
    border-color: var(--color-line-strong);
    background: transparent;
    color: var(--color-text);
}

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

.btn-ghost:hover:not(:disabled) {
    color: var(--color-text);
    background: var(--color-bg-soft);
}

.btn-ghost.btn-danger {
    color: var(--color-error);
    border-color: var(--color-error-soft);
}

.btn-ghost.btn-danger:hover:not(:disabled) {
    color: var(--color-error);
    background: var(--color-error-soft);
}

/* Mobile: bigger touch targets for the per-rule action row + the
   "+ Nieuwe regel" trigger in the SectionHeader (Issue 16). The base
   .btn-sm renders ~40px which is borderline on phones with three
   adjacent controls per card.                                       */
@media (max-width: 640px) {
    .rule-actions .btn-sm,
    .automations-page .btn-sm {
        min-height: 44px;
        padding: 10px 14px;
    }

    .rule-actions {
        width: 100%;
    }

    .rule-actions .btn-sm {
        flex: 1 1 auto;
    }
}

/* ─── Automation Rule Summary ─── */
.automation-rule-summary {
    color: var(--color-text-muted);
    font-size: 0.85rem;
    line-height: 1.5;
}

/* ─── Knob Control ─── */
.knob-control {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.knob-control__label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text-soft);
}

.knob-control__desc {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    line-height: 1.4;
}

/* ─── Comfort desktop grid ─── */
.comfort-desktop-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
    margin-top: 8px;
}

/* ─── Audit mobile layout ─── */
.audit-mobile-brief {
    margin: 10px 16px 0;
    padding: 13px 14px;
    border: 1px solid var(--color-line);
    border-radius: var(--radius-sm);
    background:
        linear-gradient(180deg, color-mix(in srgb, var(--color-surface) 72%, transparent), transparent),
        var(--color-card);
}
.audit-mobile-brief-main {
    min-width: 0;
}
.audit-mobile-brief-main span,
.audit-mobile-brief-stat span {
    color: var(--color-text-faint);
    font-size: 0.66rem;
    font-weight: 750;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.audit-mobile-brief-main strong {
    display: block;
    min-width: 0;
    overflow: hidden;
    margin-top: 4px;
    color: var(--color-text);
    font-size: 0.96rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.audit-mobile-brief-main p {
    margin: 4px 0 0;
    color: var(--color-text-muted);
    font-size: 0.78rem;
}
.audit-mobile-brief-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--color-line);
}
.audit-mobile-brief-stat {
    min-width: 0;
}
.audit-mobile-brief-stat strong {
    display: block;
    margin-top: 4px;
    color: var(--color-text);
    font-size: 1rem;
    line-height: 1.1;
}
.audit-mobile-brief-stat em {
    display: block;
    overflow: hidden;
    margin-top: 2px;
    color: var(--color-text-muted);
    font-size: 0.7rem;
    font-style: normal;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.audit-mobile-brief-stat--attention strong {
    color: var(--color-warning-text);
}
.audit-tabs--mobile {
    width: auto;
    margin: 12px 16px 0;
}

.audit-mobile-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    padding: 12px 16px 4px;
}

.audit-mobile-toolbar > span {
    min-width: 0;
    overflow: hidden;
    color: var(--color-text-muted);
    font-size: 0.78rem;
    font-weight: 650;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.audit-mobile-toolbar > div {
    display: flex;
    gap: 8px;
    flex: none;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.audit-mobile-filters {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 4px 16px 0;
    padding: 12px 0 4px;
    border-top: 1px solid var(--color-line);
}

.audit-mobile-filters .audit-filter-select,
.audit-mobile-filters .audit-filter-input {
    width: 100%;
    min-width: 0;
    font-size: 1rem; /* prevent iOS auto-zoom */
}

.audit-mobile-filter-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.audit-mobile-filter-row .audit-filter-input {
    flex: 1;
}

.audit-mobile-card {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    padding: 12px 16px;
}

.audit-mobile-card-top {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.audit-mobile-ts {
    font-size: 0.72rem;
    color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
    margin-left: auto;
    white-space: nowrap;
}

.audit-mobile-card-context {
    overflow: hidden;
    color: var(--color-text-soft);
    font-size: 0.74rem;
    font-weight: 650;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.audit-mobile-sep {
    color: var(--color-text-muted);
}

.audit-pagination--mobile {
    margin: 12px 16px 20px;
}

.audit-pagination--mobile .audit-page-btn {
    min-width: 44px;
    min-height: 44px;
}


