/* WizBoard — Automations Page */

/* ── Header ── */

.auto-header {
    flex-shrink: 0;
    padding: 16px 20px 8px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.auto-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.auto-title {
    font-size: 20px;
    font-weight: 800;
    background: linear-gradient(135deg, #6366f1, #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.auto-create-btn {
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    border: none;
    background: linear-gradient(135deg, #6366f1, #7c3aed);
    color: white;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.auto-create-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.3);
}

/* ── Category Tabs ── */

.auto-category-bar {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.auto-cat-chip {
    padding: 5px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
    flex-shrink: 0;
}

.auto-cat-chip:hover {
    border-color: var(--text-muted);
    color: var(--text);
}

.auto-cat-chip.active {
    background: #6366f1;
    border-color: #6366f1;
    color: white;
}

.auto-cat-count {
    font-size: 10px;
    opacity: 0.7;
    margin-left: 4px;
}

/* ── Grid ── */

.auto-grid {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 12px;
    align-content: start;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

/* ── Automation Card ── */

.auto-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.auto-card:hover {
    background: var(--bg-card-hover);
    border-color: #2a2a44;
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}

.auto-card.disabled {
    opacity: 0.4;
}

.auto-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 8px;
}

.auto-card-name {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.3;
    flex: 1;
    margin-right: 8px;
}

.auto-card-toggle {
    flex-shrink: 0;
}

.auto-card-schedule {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.auto-card-schedule::before {
    content: '';
    display: inline-block;
    width: 14px;
    height: 14px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236b6b8a' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 6v6l4 2'/%3E%3C/svg%3E") no-repeat center;
    flex-shrink: 0;
}

.auto-card-next {
    font-size: 11px;
    color: var(--text-dim);
    margin-bottom: 10px;
}

.auto-card-next.due {
    color: #fbbf24;
}

.auto-card-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.auto-card-type {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 2px 6px;
    border-radius: 3px;
    text-transform: uppercase;
}

.auto-card-type[data-type="prompt"] {
    background: rgba(99, 102, 241, 0.12);
    color: #818cf8;
}

.auto-card-type[data-type="script"] {
    background: rgba(34, 197, 94, 0.12);
    color: #4ade80;
}

.auto-card-category {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 3px;
    background: rgba(255,255,255,0.05);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.auto-card-status {
    font-size: 11px;
    color: var(--text-dim);
    margin-left: auto;
}

.auto-card-status.success {
    color: #4ade80;
}

.auto-card-status.failed {
    color: var(--critical);
}

.auto-card-status.timeout {
    color: var(--high, #f59e0b);
}

.auto-card-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(255,255,255,0.03);
}

.auto-card-runs {
    font-size: 11px;
    color: var(--text-dim);
}

.auto-card-actions {
    margin-left: auto;
    display: flex;
    gap: 6px;
}

.auto-card-btn {
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.auto-card-btn:hover {
    background: rgba(255,255,255,0.05);
    color: var(--text);
    border-color: var(--text-muted);
}

.auto-card-btn.run-btn:hover {
    background: rgba(34, 197, 94, 0.1);
    border-color: #4ade80;
    color: #4ade80;
}

.auto-card-btn.run-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* ── Toggle Switch ── */

.auto-switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
}

.auto-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.auto-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--border);
    border-radius: 20px;
    transition: 0.2s;
}

.auto-slider::before {
    content: '';
    position: absolute;
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: 0.2s;
}

.auto-switch input:checked + .auto-slider {
    background: #6366f1;
}

.auto-switch input:checked + .auto-slider::before {
    transform: translateX(16px);
    background: white;
}

/* ── Modal Form ── */

.auto-modal {
    max-width: 620px;
}

.auto-modal-title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 16px;
}

.auto-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
}

.auto-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.auto-field label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-muted);
}

.auto-field input,
.auto-field select,
.auto-field textarea {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 8px 12px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
}

.auto-field input:focus,
.auto-field select:focus,
.auto-field textarea:focus {
    border-color: var(--border-focus);
}

.auto-field textarea {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 13px;
    resize: vertical;
}

.auto-field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.auto-toggle-field {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
}

/* Quick schedule buttons */
.auto-quick-schedule {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.auto-quick-schedule button {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
}

.auto-quick-schedule button:hover {
    border-color: #6366f1;
    color: #6366f1;
    background: rgba(99, 102, 241, 0.06);
}

.auto-schedule-hint {
    margin-top: -2px;
    font-size: 11px;
    color: var(--text-dim);
}

.auto-schedule-preview {
    margin-top: 2px;
    font-size: 12px;
    color: var(--text-muted);
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    border: 1px dashed var(--border);
    background: rgba(255, 255, 255, 0.02);
}

.auto-schedule-preview.error {
    border-color: rgba(239, 68, 68, 0.35);
    color: #fca5a5;
}

/* ── Run History ── */

.auto-runs {
    border-top: 1px solid var(--border);
    padding-top: 12px;
    margin-bottom: 12px;
}

.auto-runs-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.auto-runs-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 160px;
    overflow-y: auto;
}

.auto-run-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    background: rgba(255,255,255,0.02);
    font-size: 12px;
}

.auto-run-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

.auto-run-dot.success { background: #4ade80; }
.auto-run-dot.failed { background: var(--critical); }
.auto-run-dot.running { background: var(--review-amber); animation: badge-glow 2s ease-in-out infinite; }
.auto-run-dot.timeout { background: var(--high); }

.auto-run-time {
    color: var(--text-dim);
    font-size: 11px;
}

.auto-run-summary {
    color: var(--text-muted);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Delete Button ── */

.btn-delete-auto {
    background: transparent;
    color: var(--critical);
    border: 1px solid rgba(239,68,68,0.3) !important;
    margin-right: auto;
}

.btn-delete-auto:hover {
    background: rgba(239,68,68,0.1);
}

/* ── Empty State ── */

.auto-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: var(--text-dim);
    font-size: 14px;
}

/* ── Mobile ── */

@media (max-width: 768px) {
    .auto-header {
        padding: 12px 16px 8px;
    }

    .auto-grid {
        grid-template-columns: 1fr;
        padding: 12px 16px;
    }

    .auto-field-row {
        grid-template-columns: 1fr;
    }

    .auto-modal {
        width: 100vw;
        max-width: 100vw;
        border-radius: var(--radius) var(--radius) 0 0;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        max-height: 90vh;
        max-height: 90dvh;
    }
}
