/* ==========================================================================
   GPTun — Automations modal
   Self-contained theme tokens so the modal keeps one look in light and dark
   without inheriting white form fields from the browser defaults.
   ========================================================================== */

.aichat-auto {
    --auto-text: #1c2333;
    --auto-text-soft: #5a6479;
    --auto-muted: #8b93a6;
    --auto-border: #e4e8f1;
    --auto-border-strong: #cdd4e3;
    --auto-surface: #ffffff;
    --auto-panel: #f7f8fc;
    --auto-field: #fcfdff;
    --auto-track: #eef0f8;
    --auto-accent: #5b57f5;
    --auto-accent-strong: #4a46e6;
    --auto-accent-soft: rgba(91, 87, 245, 0.09);
    --auto-accent-ring: rgba(91, 87, 245, 0.26);
    --auto-ok: #0f9d63;
    --auto-ok-soft: rgba(15, 157, 99, 0.1);
    --auto-warn: #b45309;
    --auto-warn-soft: rgba(180, 83, 9, 0.1);
    --auto-danger: #d13b46;
    --auto-danger-soft: rgba(209, 59, 70, 0.09);
    --auto-radius: 16px;
    --auto-radius-sm: 12px;

    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
    color: var(--auto-text);
    color-scheme: light;
}

.dark .aichat-auto {
    --auto-text: #e9edf5;
    --auto-text-soft: #a9b2c6;
    --auto-muted: #7f889c;
    --auto-border: #333b4d;
    --auto-border-strong: #414b60;
    --auto-surface: #242c3b;
    --auto-panel: #1b2230;
    --auto-field: #161d29;
    --auto-track: #242c3b;
    --auto-accent: #8b87ff;
    --auto-accent-strong: #a7a4ff;
    --auto-accent-soft: rgba(139, 135, 255, 0.15);
    --auto-accent-ring: rgba(139, 135, 255, 0.32);
    --auto-ok: #34d399;
    --auto-ok-soft: rgba(52, 211, 153, 0.13);
    --auto-warn: #fbbf24;
    --auto-warn-soft: rgba(251, 191, 36, 0.12);
    --auto-danger: #f87171;
    --auto-danger-soft: rgba(248, 113, 113, 0.12);
    color-scheme: dark;
}

/* ── Toolbar: tabs + primary action ─────────────────────────────────────── */

.aichat-auto__toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 14px;
}

.aichat-auto__tabs {
    display: inline-flex;
    gap: 3px;
    padding: 3px;
    border-radius: var(--auto-radius-sm);
    background: var(--auto-track);
}

.aichat-auto__tab {
    min-height: 36px;
    padding: 0 14px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--auto-text-soft);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: color 140ms ease, background-color 140ms ease, box-shadow 140ms ease;
}

.aichat-auto__tab:hover { color: var(--auto-text); }

.aichat-auto__tab.is-active {
    background: var(--auto-surface);
    color: var(--auto-text);
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.12);
}

.dark .aichat-auto__tab.is-active { box-shadow: 0 1px 2px rgba(0, 0, 0, 0.45); }

/* ── Buttons ────────────────────────────────────────────────────────────── */

.aichat-auto__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 40px;
    padding: 0 16px;
    border: 1px solid transparent;
    border-radius: var(--auto-radius-sm);
    font-size: 13.5px;
    font-weight: 650;
    line-height: 1;
    cursor: pointer;
    transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease;
}

.aichat-auto__btn--primary {
    background: var(--auto-accent);
    color: #ffffff;
}

.aichat-auto__btn--primary:hover { background: var(--auto-accent-strong); }
.dark .aichat-auto__btn--primary { color: #101426; }
.aichat-auto__btn .aichat-auto__spinner { color: currentColor; }

.aichat-auto__btn--ghost {
    border-color: var(--auto-border-strong);
    background: var(--auto-surface);
    color: var(--auto-text);
}

.aichat-auto__btn--ghost:hover { background: var(--auto-panel); }

.aichat-auto__btn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.aichat-auto__btn--compact {
    min-height: 36px;
    padding: 0 13px;
    font-size: 12.5px;
}

.aichat-auto__link {
    margin-left: auto;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font-size: inherit;
    font-weight: 650;
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
}

/* ── Panels ─────────────────────────────────────────────────────────────── */

.aichat-auto__panel {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-right: 2px;
}

.aichat-auto__loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 56px 0;
    color: var(--auto-muted);
    font-size: 13px;
}

.aichat-auto__spinner {
    width: 18px;
    height: 18px;
    color: var(--auto-accent);
    animation: aichat-auto-spin 900ms linear infinite;
}

@keyframes aichat-auto-spin { to { transform: rotate(360deg); } }

/* ── Banners ────────────────────────────────────────────────────────────── */

.aichat-auto__banner {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 12px;
    padding: 11px 13px;
    border: 1px solid transparent;
    border-radius: var(--auto-radius-sm);
    font-size: 13px;
    line-height: 1.45;
}

.aichat-auto__banner--error {
    border-color: color-mix(in srgb, var(--auto-danger) 34%, transparent);
    background: var(--auto-danger-soft);
    color: var(--auto-danger);
}

.aichat-auto__banner--success {
    border-color: color-mix(in srgb, var(--auto-ok) 34%, transparent);
    background: var(--auto-ok-soft);
    color: var(--auto-ok);
}

.aichat-auto__banner--warn {
    border-color: color-mix(in srgb, var(--auto-warn) 34%, transparent);
    background: var(--auto-warn-soft);
    color: var(--auto-warn);
}

/* ── Empty state ────────────────────────────────────────────────────────── */

.aichat-auto__empty {
    padding: 48px 24px;
    border: 1px dashed var(--auto-border-strong);
    border-radius: var(--auto-radius);
    background: var(--auto-panel);
    text-align: center;
}

.aichat-auto__empty-icon {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    margin: 0 auto 12px;
    border-radius: 14px;
    background: var(--auto-accent-soft);
    font-size: 20px;
    line-height: 1;
}

.aichat-auto__empty-title {
    margin: 0;
    color: var(--auto-text);
    font-size: 14.5px;
    font-weight: 650;
}

.aichat-auto__empty-text {
    max-width: 34ch;
    margin: 6px auto 0;
    color: var(--auto-text-soft);
    font-size: 12.5px;
    line-height: 1.5;
}

.aichat-auto__empty .aichat-auto__btn { margin-top: 18px; }

/* ── List ───────────────────────────────────────────────────────────────── */

.aichat-auto__list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.aichat-auto__card {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 13px 14px;
    border: 1px solid var(--auto-border);
    border-radius: var(--auto-radius);
    background: var(--auto-surface);
    transition: border-color 140ms ease, background-color 140ms ease;
}

.aichat-auto__card:hover { border-color: var(--auto-border-strong); }

.aichat-auto__card[data-state="on"] {
    box-shadow: inset 3px 0 0 var(--auto-ok);
}

.aichat-auto__card-body { flex: 1 1 auto; min-width: 0; }

.aichat-auto__card-top {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.aichat-auto__name {
    overflow: hidden;
    margin: 0;
    color: var(--auto-text);
    font-size: 13.5px;
    font-weight: 650;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.aichat-auto__badge {
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 650;
    line-height: 1.5;
    white-space: nowrap;
}

.aichat-auto__badge.is-on { background: var(--auto-ok-soft); color: var(--auto-ok); }

.aichat-auto__badge.is-off {
    background: var(--auto-track);
    color: var(--auto-muted);
}

.aichat-auto__meta {
    overflow-wrap: anywhere;
    margin: 5px 0 0;
    color: var(--auto-muted);
    font-size: 11.5px;
    line-height: 1.45;
}

.aichat-auto__notice {
    margin: 7px 0 0;
    color: var(--auto-warn);
    font-size: 12px;
    line-height: 1.45;
}

.aichat-auto__actions {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 2px;
}

.aichat-auto__icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--auto-text-soft);
    cursor: pointer;
    transition: background-color 140ms ease, color 140ms ease;
}

.aichat-auto__icon-btn:hover {
    background: var(--auto-accent-soft);
    color: var(--auto-accent);
}

.aichat-auto__icon-btn.is-on { color: var(--auto-ok); }

.aichat-auto__icon-btn.is-on:hover {
    background: var(--auto-ok-soft);
    color: var(--auto-ok);
}

.aichat-auto__icon-btn--accent:hover {
    background: var(--auto-accent-soft);
    color: var(--auto-accent);
}

.aichat-auto__icon-btn--danger:hover {
    background: var(--auto-danger-soft);
    color: var(--auto-danger);
}

/* ── Create form ────────────────────────────────────────────────────────── */

.aichat-auto__form {
    padding: 18px;
    border: 1px solid var(--auto-border);
    border-radius: var(--auto-radius);
    background: var(--auto-panel);
}

.aichat-auto__field + .aichat-auto__field,
.aichat-auto__field + .aichat-auto__grid,
.aichat-auto__grid + .aichat-auto__banner,
.aichat-auto__field + .aichat-auto__banner { margin-top: 16px; }

.aichat-auto__banner + .aichat-auto__banner { margin-top: 10px; }

.aichat-auto__label {
    display: block;
    margin-bottom: 7px;
    color: var(--auto-text);
    font-size: 12.5px;
    font-weight: 650;
}

.aichat-auto__input,
.aichat-auto__textarea,
.aichat-auto__select {
    display: block;
    width: 100%;
    border: 1px solid var(--auto-border-strong);
    border-radius: var(--auto-radius-sm);
    background: var(--auto-field);
    padding: 10px 12px;
    color: var(--auto-text);
    font-family: inherit;
    font-size: 13px;
    line-height: 1.5;
    outline: none;
    transition: border-color 140ms ease, box-shadow 140ms ease;
}

.aichat-auto__textarea {
    min-height: 120px;
    resize: vertical;
}

.aichat-auto__input::placeholder,
.aichat-auto__textarea::placeholder { color: var(--auto-muted); }

.aichat-auto__input:focus,
.aichat-auto__textarea:focus,
.aichat-auto__select:focus {
    border-color: var(--auto-accent);
    box-shadow: 0 0 0 3px var(--auto-accent-ring);
}

.aichat-auto__select {
    appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
        linear-gradient(135deg, currentColor 50%, transparent 50%);
    background-position: calc(100% - 18px) calc(50% + 1px), calc(100% - 13px) calc(50% + 1px);
    background-repeat: no-repeat;
    background-size: 5px 5px, 5px 5px;
    padding-right: 34px;
}

.aichat-auto__hint {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 6px;
    margin-top: 6px;
    color: var(--auto-muted);
    font-size: 11.5px;
}

.aichat-auto__grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.aichat-auto__checks {
    display: flex;
    flex-direction: column;
    gap: 9px;
    padding-top: 2px;
}

.aichat-auto__check {
    display: flex;
    align-items: center;
    gap: 9px;
    color: var(--auto-text-soft);
    font-size: 12.5px;
    cursor: pointer;
}

.aichat-auto__checkbox {
    display: grid;
    place-items: center;
    width: 16px;
    height: 16px;
    flex: 0 0 auto;
    margin: 0;
    appearance: none;
    border: 1px solid var(--auto-border-strong);
    border-radius: 5px;
    background: var(--auto-field);
    accent-color: var(--auto-accent);
    cursor: pointer;
    transition: background-color 120ms ease, border-color 120ms ease;
}

.aichat-auto__checkbox::after {
    content: '';
    width: 8px;
    height: 4px;
    margin-top: -2px;
    border-left: 2px solid var(--auto-surface);
    border-bottom: 2px solid var(--auto-surface);
    transform: rotate(-45deg) scale(0);
    transition: transform 120ms ease;
}

.aichat-auto__checkbox:checked {
    border-color: var(--auto-accent);
    background: var(--auto-accent);
}

.aichat-auto__checkbox:checked::after { transform: rotate(-45deg) scale(1); }

.aichat-auto__checkbox:focus-visible {
    outline: 2px solid var(--auto-accent-ring);
    outline-offset: 2px;
}

.aichat-auto__footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--auto-border);
}

/* ── Focus + motion ─────────────────────────────────────────────────────── */

.aichat-auto :is(button, a, input, select, textarea, [tabindex]):focus-visible {
    outline: 2px solid var(--auto-accent);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .aichat-auto *,
    .aichat-auto *::before,
    .aichat-auto *::after {
        animation-duration: 0.001ms !important;
        transition-duration: 0.001ms !important;
    }
}

/* ── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 639px) {
    .aichat-auto__toolbar { gap: 8px; }

    .aichat-auto__tabs { flex: 1 1 100%; }

    .aichat-auto__tab { flex: 1 1 0; padding: 0 10px; }

    .aichat-auto__toolbar .aichat-auto__btn--compact { width: 100%; }

    .aichat-auto__card {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .aichat-auto__actions {
        justify-content: flex-end;
        padding-top: 8px;
        border-top: 1px solid var(--auto-border);
    }

    .aichat-auto__icon-btn { width: 38px; height: 38px; }

    .aichat-auto__form { padding: 14px; }

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

    .aichat-auto__footer { flex-direction: column-reverse; }

    .aichat-auto__footer .aichat-auto__btn { width: 100%; }
}
